![]() |
XML Mill
1.0.0
A GUI based XML editor with a memory.
|
Specialist tree widget class consisting of GCTreeWidgetItems. More...
#include <gcdomtreewidget.h>
Public Slots | |
void | setCurrentItemFromIndex (int index) |
Finds the item with index matching "index" and sets it as the current tree item ("index" is the item's position relative to the first active XML element, i.e. | |
Signals | |
void | gcCurrentItemSelected (GCTreeWidgetItem *item, int column) |
Emitted when the current active item changes. | |
void | gcCurrentItemChanged (GCTreeWidgetItem *item, int column) |
Emitted when the current item's content changes. | |
Public Member Functions | |
GCDomTreeWidget (QWidget *parent=0) | |
Constructor. | |
~GCDomTreeWidget () | |
Destructor. | |
GCTreeWidgetItem * | gcCurrentItem () const |
Returns the current item as a GCTreeWidgetItem. | |
QList< GCTreeWidgetItem * > | includedTreeWidgetItems () const |
Returns a list of all the included. | |
const QList< GCTreeWidgetItem * > & | allTreeWidgetItems () const |
Returns a list of ALL the GCTreeWidgetItems currently in the tree. | |
int | itemPositionRelativeToIdenticalSiblings (const QString &nodeText, int itemIndex) const |
Returns the position of "itemIndex" relative to that of ALL items matching "nodeText" (this is is not as odd as it sounds, it is possible that a DOM document may have multiple elements of the same name with matching attributes and attribute values). | |
QDomNode | cloneDocument () const |
Returns a deep copy of the underlying DOM document. | |
QString | toString () const |
Returns the DOM content as string. | |
QString | rootName () const |
Returns the name of the DOM document's root. | |
QString | activeCommentValue () const |
Returns the comment associated with the current element (if any). | |
void | setActiveCommentValue (const QString &value) |
Sets the value of the active comment node to "value". | |
bool | setContent (const QString &text, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0) |
Sets the underlying DOM document's content. | |
bool | empty () const |
Returns true if the widget and DOM is currently empty. | |
bool | currentItemIsRoot () const |
Returns true if the current item is the one corresponding to the DOM document's root element. | |
bool | matchesRootName (const QString &elementName) const |
Returns true if "elementName" matches that of the DOM document's root. | |
bool | documentCompatible () const |
Returns true if the underlying DOM document is compatible with the active DB session. | |
bool | batchProcessSuccess () const |
Returns true if batch processing of DOM content to the active DB was successful. | |
void | rebuildTreeWidget () |
Rebuild the tree to conform to updated DOM content. | |
void | appendSnippet (GCTreeWidgetItem *parentItem, QDomElement childElement) |
Creates and adds tree widget items for each element in the parameter element hierarchy. | |
void | replaceItemsWithComment (const QList< int > &indices, const QString &comment) |
Removes the items with indices matching those in the parameter list from the tree as well as from the DOM document and replaces them with a new QDomComment node representing "comment". | |
void | updateItemNames (const QString &oldName, const QString &newName) |
Update all the tree widget items with text "oldName" to text "newName". | |
void | populateFromDatabase (const QString &baseElementName=QString()) |
This function starts the recursive process of populating the tree widget with items consisting of the element hierarchy starting at "baseElementName". | |
void | addItem (const QString &element, bool toParent=false) |
Adds a new item and corresponding DOM element node named "element". | |
void | insertItem (const QString &elementName, int index, bool toParent=false) |
Adds a new item and corresponding DOM element node named "elementName" to the tree and DOM document and inserts the new tree widget item into position "index" of the current item. | |
void | setAllCheckStates (Qt::CheckState state) |
Iterates through the tree and sets all items' check states to "state". | |
void | setShowTreeItemsVerbose (bool verbose) |
Iterates through the tree and set all items' "verbose" flags to "show". | |
void | clearAndReset () |
Clears and resets the tree as well as the underlying DOM document. | |
Protected Member Functions | |
void | dropEvent (QDropEvent *event) |
Re-implemented from QTreeWidget. | |
void | keyPressEvent (QKeyEvent *event) |
Re-implemented from QTreeWidget. | |
Private Slots | |
void | currentGcItemChanged (QTreeWidgetItem *current, QTreeWidgetItem *previous) |
Connected to QTreeWidget::currentItemChanged(), sets the active GCTreeWidgetItem. | |
void | emitGcCurrentItemSelected (QTreeWidgetItem *item, int column) |
Connected to "itemClicked" and "itemActivated". | |
void | emitGcCurrentItemChanged (QTreeWidgetItem *item, int column) |
Connected to "itemChanged". | |
void | renameItem () |
Connected to a context menu action. | |
void | removeItem () |
Connected to a context menu action. | |
void | stepUp () |
Connected to a context menu action. | |
void | stepDown () |
Connected to a context menu action. | |
void | expand () |
Connected to a context menu action. | |
void | collapse () |
Connected to a context menu action. | |
Private Member Functions | |
void | processElement (GCTreeWidgetItem *parentItem, QDomElement element) |
Creates a new GCTreeWidgetItem item with corresponding "element" and adds it as a child to "parentItem". | |
void | processElementFromDatabase (const QString &element) |
Processes individual elements. | |
bool | parentTreeAlreadyContainsElement (const GCTreeWidgetItem *item, const QString &element) |
Used in "processElementFromDatabase" to prevent infinite recursion. | |
void | populateCommentList (QDomNode node) |
Populates the comments list with all the comment nodes in the document. | |
void | updateIndices () |
Iterates through the tree and updates all items' indices (useful when new items are added or items removed) to ensure that indices correspond roughly to "row numbers" in the accompanying plain text representation of the document's content. | |
GCTreeWidgetItem * | gcItemFromNode (QDomNode element) |
Finds and returns the GCTreeWidget item that is linked to "element". | |
void | removeFromList (GCTreeWidgetItem *item) |
Recursively removes item and its children from the internal GCTreeWidgetItem list. | |
Private Attributes | |
GCTreeWidgetItem * | m_activeItem |
QDomDocument * | m_domDoc |
QDomComment | m_commentNode |
bool | m_isEmpty |
bool | m_busyIterating |
bool | m_itemBeingManipulated |
QList< GCTreeWidgetItem * > | m_items |
QList< QDomComment > | m_comments |
Specialist tree widget class consisting of GCTreeWidgetItems.
This class wraps an underlying DOM document and manages its items (GCTreeWidgetItems) based on changes to the DOM, but also manages the DOM based on changes made to its items. Perhaps a better way of describing this relationship is to say that this class is, in effect, a non-textual visual representation of a DOM document.
Definition at line 49 of file gcdomtreewidget.h.
GCDomTreeWidget::GCDomTreeWidget | ( | QWidget * | parent = 0 | ) |
Constructor.
Definition at line 44 of file gcdomtreewidget.cpp.
Destructor.
Definition at line 101 of file gcdomtreewidget.cpp.
QString GCDomTreeWidget::activeCommentValue | ( | ) | const |
Returns the comment associated with the current element (if any).
If no comment precedes the current element, an empty string is returned.
Definition at line 136 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::addItem | ( | const QString & | element, |
bool | toParent = false |
||
) |
Adds a new item and corresponding DOM element node named "element".
If the tree is empty, the new item will be added to the invisible root (i.e. as header item), otherwise it will be added as a child of the current item (the new item also becomes the current item). If "toParent" is true, the new item will be added as a child of the current item's parent (i.e. as a sibling to the current item).
Definition at line 514 of file gcdomtreewidget.cpp.
const QList< GCTreeWidgetItem * > & GCDomTreeWidget::allTreeWidgetItems | ( | ) | const |
Returns a list of ALL the GCTreeWidgetItems currently in the tree.
Definition at line 205 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::appendSnippet | ( | GCTreeWidgetItem * | parentItem, |
QDomElement | childElement | ||
) |
Creates and adds tree widget items for each element in the parameter element hierarchy.
The process starts by appending "childElement" to "parentItem's" corresponding element and then recursively creates and adds items with associated elements corresponding to "childElement's" element hierarchy.
Definition at line 336 of file gcdomtreewidget.cpp.
bool GCDomTreeWidget::batchProcessSuccess | ( | ) | const |
Returns true if batch processing of DOM content to the active DB was successful.
Definition at line 294 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::clearAndReset | ( | ) |
Clears and resets the tree as well as the underlying DOM document.
Definition at line 1021 of file gcdomtreewidget.cpp.
QDomNode GCDomTreeWidget::cloneDocument | ( | ) | const |
Returns a deep copy of the underlying DOM document.
Definition at line 115 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::collapse | ( | ) | [private, slot] |
Connected to a context menu action.
Collapses the active (selected) item.
Definition at line 1014 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::currentGcItemChanged | ( | QTreeWidgetItem * | current, |
QTreeWidgetItem * | previous | ||
) | [private, slot] |
Connected to QTreeWidget::currentItemChanged(), sets the active GCTreeWidgetItem.
Definition at line 800 of file gcdomtreewidget.cpp.
bool GCDomTreeWidget::currentItemIsRoot | ( | ) | const |
Returns true if the current item is the one corresponding to the DOM document's root element.
Definition at line 268 of file gcdomtreewidget.cpp.
bool GCDomTreeWidget::documentCompatible | ( | ) | const |
Returns true if the underlying DOM document is compatible with the active DB session.
Definition at line 287 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::dropEvent | ( | QDropEvent * | event | ) | [protected] |
Re-implemented from QTreeWidget.
Definition at line 702 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::emitGcCurrentItemChanged | ( | QTreeWidgetItem * | item, |
int | column | ||
) | [private, slot] |
Connected to "itemChanged".
Re-emits the changed item as a GCTreeWidgetItem.
Definition at line 830 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::emitGcCurrentItemSelected | ( | QTreeWidgetItem * | item, |
int | column | ||
) | [private, slot] |
Connected to "itemClicked" and "itemActivated".
Re-emits the clicked item as a GCTreeWidgetItem.
Definition at line 812 of file gcdomtreewidget.cpp.
bool GCDomTreeWidget::empty | ( | ) | const |
Returns true if the widget and DOM is currently empty.
Definition at line 261 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::expand | ( | ) | [private, slot] |
Connected to a context menu action.
Expands active (selected) item.
Definition at line 1007 of file gcdomtreewidget.cpp.
GCTreeWidgetItem * GCDomTreeWidget::gcCurrentItem | ( | ) | const |
Returns the current item as a GCTreeWidgetItem.
Definition at line 108 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::gcCurrentItemChanged | ( | GCTreeWidgetItem * | item, |
int | column | ||
) | [signal] |
Emitted when the current item's content changes.
void GCDomTreeWidget::gcCurrentItemSelected | ( | GCTreeWidgetItem * | item, |
int | column | ||
) | [signal] |
Emitted when the current active item changes.
GCTreeWidgetItem * GCDomTreeWidget::gcItemFromNode | ( | QDomNode | element | ) | [private] |
Finds and returns the GCTreeWidget item that is linked to "element".
Definition at line 650 of file gcdomtreewidget.cpp.
QList< GCTreeWidgetItem * > GCDomTreeWidget::includedTreeWidgetItems | ( | ) | const |
Returns a list of all the included.
Definition at line 186 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::insertItem | ( | const QString & | elementName, |
int | index, | ||
bool | toParent = false |
||
) |
Adds a new item and corresponding DOM element node named "elementName" to the tree and DOM document and inserts the new tree widget item into position "index" of the current item.
If the tree is empty, the new item will be added to the invisible root (the new item also becomes the current item). If "toParent" is true, the new item will be added as a child to the current item's parent (i.e. as a sibling to the current item).
Definition at line 535 of file gcdomtreewidget.cpp.
int GCDomTreeWidget::itemPositionRelativeToIdenticalSiblings | ( | const QString & | nodeText, |
int | itemIndex | ||
) | const |
Returns the position of "itemIndex" relative to that of ALL items matching "nodeText" (this is is not as odd as it sounds, it is possible that a DOM document may have multiple elements of the same name with matching attributes and attribute values).
Definition at line 212 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::keyPressEvent | ( | QKeyEvent * | event | ) | [protected] |
Re-implemented from QTreeWidget.
Definition at line 781 of file gcdomtreewidget.cpp.
bool GCDomTreeWidget::matchesRootName | ( | const QString & | elementName | ) | const |
Returns true if "elementName" matches that of the DOM document's root.
Definition at line 280 of file gcdomtreewidget.cpp.
bool GCDomTreeWidget::parentTreeAlreadyContainsElement | ( | const GCTreeWidgetItem * | item, |
const QString & | element | ||
) | [private] |
Used in "processElementFromDatabase" to prevent infinite recursion.
Returns true when an element is part of a hierarchy containing itself (oddly allowed in XML).
Definition at line 496 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::populateCommentList | ( | QDomNode | node | ) | [private] |
Populates the comments list with all the comment nodes in the document.
Definition at line 684 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::populateFromDatabase | ( | const QString & | baseElementName = QString() | ) |
This function starts the recursive process of populating the tree widget with items consisting of the element hierarchy starting at "baseElementName".
If "baseElementName" is empty, a complete hierarchy of the current active profile will be constructed. This method also automatically clears and resets GCDomTreeWidget's state, expands the entire tree, sets the first top level item as current and emits the "gcCurrentItemSelected" signal.
Definition at line 441 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::processElement | ( | GCTreeWidgetItem * | parentItem, |
QDomElement | element | ||
) | [private] |
Creates a new GCTreeWidgetItem item with corresponding "element" and adds it as a child to "parentItem".
Definition at line 421 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::processElementFromDatabase | ( | const QString & | element | ) | [private] |
Processes individual elements.
This function is called recursively from within "populateFromDatabase", creating a representative tree widget item (and corresponding DOM element) named "element" and adding it (the item) to the correct parent.
element | - the name of the element for which a tree widget item must be created. |
Definition at line 467 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::rebuildTreeWidget | ( | ) |
Rebuild the tree to conform to updated DOM content.
Definition at line 315 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::removeFromList | ( | GCTreeWidgetItem * | item | ) | [private] |
Recursively removes item and its children from the internal GCTreeWidgetItem list.
Definition at line 671 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::removeItem | ( | ) | [private, slot] |
Connected to a context menu action.
Removes the item (and it's corresponding element) on which the context menu action was invoked from the tree and underlying DOM. This function will furthermore remove all comment nodes directly above the element node.
Definition at line 888 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::renameItem | ( | ) | [private, slot] |
Connected to a context menu action.
Renames the element on which the context menu action was invoked. An element with the new name will be added to the DB (if it doesn't yet exist) with the same associated attributes and attribute values as the element name it is replacing (the "old" element will not be removed from the DB). All occurrences of the old name throughout the current DOM will be replaced with the new name and the tree widget will be updated accordingly.
Definition at line 848 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::replaceItemsWithComment | ( | const QList< int > & | indices, |
const QString & | comment | ||
) |
Removes the items with indices matching those in the parameter list from the tree as well as from the DOM document and replaces them with a new QDomComment node representing "comment".
Definition at line 347 of file gcdomtreewidget.cpp.
QString GCDomTreeWidget::rootName | ( | ) | const |
Returns the name of the DOM document's root.
Definition at line 129 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::setActiveCommentValue | ( | const QString & | value | ) |
Sets the value of the active comment node to "value".
If the active element doesn't have an associated comment, a comment node is created.
Definition at line 155 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::setAllCheckStates | ( | Qt::CheckState | state | ) |
Iterates through the tree and sets all items' check states to "state".
Definition at line 595 of file gcdomtreewidget.cpp.
bool GCDomTreeWidget::setContent | ( | const QString & | text, |
QString * | errorMsg = 0 , |
||
int * | errorLine = 0 , |
||
int * | errorColumn = 0 |
||
) |
Sets the underlying DOM document's content.
If successful, a recursive DOM tree traversal is kicked off in order to populate the tree widget with the information contained in the active DOM document.
Definition at line 242 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::setCurrentItemFromIndex | ( | int | index | ) | [slot] |
Finds the item with index matching "index" and sets it as the current tree item ("index" is the item's position relative to the first active XML element, i.e.
excluding "non-active" comment nodes).
Definition at line 579 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::setShowTreeItemsVerbose | ( | bool | verbose | ) |
Iterates through the tree and set all items' "verbose" flags to "show".
Definition at line 612 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::stepDown | ( | ) | [private, slot] |
Connected to a context menu action.
Moves the active (selected) item to the level of its children.
Definition at line 973 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::stepUp | ( | ) | [private, slot] |
Connected to a context menu action.
Moves the active (selected) item to the level of its parent.
Definition at line 941 of file gcdomtreewidget.cpp.
QString GCDomTreeWidget::toString | ( | ) | const |
Returns the DOM content as string.
Definition at line 122 of file gcdomtreewidget.cpp.
void GCDomTreeWidget::updateIndices | ( | ) | [private] |
Iterates through the tree and updates all items' indices (useful when new items are added or items removed) to ensure that indices correspond roughly to "row numbers" in the accompanying plain text representation of the document's content.
Definition at line 630 of file gcdomtreewidget.cpp.