MagicSmoke
$VERSION$
|
This is a specialized model type that shows and allows to manipulate a DOM tree. More...
#include <dommodel.h>
Public Slots | |
void | addShowNodeType (QDomNode::NodeType) |
changes the settings of what kinds of nodes are shown in the model, all model indexes become invalid after a call to this method More... | |
void | addShowNodeTypes (const QSet< QDomNode::NodeType > &) |
changes the settings of what kinds of nodes are shown in the model, all model indexes become invalid after a call to this method More... | |
virtual void | clear () |
resets the model to an invalid/empty QDomDocument More... | |
virtual void | insertNode (const QDomNode &newnode, const QModelIndex &parent, int row=-1) |
insert a node into the parent at given position (if no position is given: append) More... | |
virtual void | insertNodes (const QDomNodeList &newnodes, const QModelIndex &parent, int row=-1) |
insert a list of nodes into the parent at given position (if no position is given: append) More... | |
virtual void | insertNodes (const QList< QDomNode > &newnodes, const QModelIndex &parent, int row=-1) |
insert a list of nodes into the parent at given position (if no position is given: append) More... | |
virtual void | removeNode (const QModelIndex &) |
removes the node at the given position and its child nodes More... | |
virtual bool | removeRows (int row, int count, const QModelIndex &parent=QModelIndex()) |
removes the nodes at the given position and their child nodes More... | |
void | setContentFromNodeCall (int role, MDomModelFunctor callback) |
Customize the way the model returns data to the view, per default the model only has code to generate a text representation for Qt::DisplayRole. More... | |
virtual void | setDomDocument (const QDomDocument &) |
sets the document represented by this model; the model makes a deep copy of the document, so that the original stays intact even if the model changes. More... | |
virtual void | setNode (const QModelIndex &index, const QDomNode &) |
replaces the node at the index, you cannot replace the entire document with this function - use setDomDocument for this More... | |
void | showAllNodeTypes () |
changes the settings of what kinds of nodes are shown in the model, all model indexes become invalid after a call to this method More... | |
void | showElementProperties (int maxattr, int maxtext) |
changes the way element nodes are displayed, this method has no effect if you customize Qt::DisplayRole through setContentFromNodeCall(...) More... | |
void | showNodeTypes (const QSet< QDomNode::NodeType > &) |
changes the settings of what kinds of nodes are shown in the model, element nodes cannot be switched off, all model indexes become invalid after a call to this method More... | |
void | showTypeLabel (bool show=true) |
if true the default display routine will show a node type label More... | |
Public Member Functions | |
MDomItemModel (QObject *parent=0) | |
instantiate an empty DOM model More... | |
MDomItemModel (const QDomDocument &xml, QObject *parent=0) | |
instantiate a DOM model with an initial DOM tree More... | |
virtual int | columnCount (const QModelIndex &parent=QModelIndex()) const |
always returns 1 - the DOM tree has only one column corresponding to the node More... | |
virtual QVariant | data (const QModelIndex &index, int role=Qt::DisplayRole) const |
returns data corresponding to the node represented by index; this method can be customized through setContentFromNodeCall(...) More... | |
virtual QDomDocument | domDocument () const |
returns a copy of the DOM tree represented by this model, you can safely manipulate this copy without influencing the model. More... | |
QVariant | headerData (int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const |
returns the header data for a specific header position and role More... | |
virtual QModelIndex | index (int row, int column, const QModelIndex &parent=QModelIndex()) const |
returns an index corresponding to the row, column, and parent node More... | |
virtual QDomNode | node (const QModelIndex &index) const |
returns the QDomNode corresponding to index, for the invalid index the QDomDocument is returned More... | |
virtual QModelIndex | parent (const QModelIndex &index) const |
returns the parent index of a node - if it has a parent More... | |
virtual int | rowCount (const QModelIndex &parent=QModelIndex()) const |
returns the amount of visible nodes beneith parent More... | |
bool | setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) |
sets header data - it is currently possible to set any header for any role, although only few are actually shown in views More... | |
virtual QSet< QDomNode::NodeType > | shownNodeTypes () const |
returns a set of node types that are configured to be visible in this model More... | |
Static Public Attributes | |
static const int | DomNodeRole =Qt::UserRole |
alias for Qt::UserRole that is used to retrieve the DOM node of an index. More... | |
This is a specialized model type that shows and allows to manipulate a DOM tree.
The model holds a copy of the DOM tree, so the original is not changed even if the model changes. You can retrieve a current copy of the model's DOM tree by calling domDocument(). This model can not carry application specific user data. It is only editable through its specialized node methods.
MDomItemModel::MDomItemModel | ( | QObject * | parent = 0 | ) |
instantiate an empty DOM model
MDomItemModel::MDomItemModel | ( | const QDomDocument & | xml, |
QObject * | parent = 0 |
||
) |
instantiate a DOM model with an initial DOM tree
xml | the model will be fed with a copy of this DOM tree |
References setDomDocument().
|
slot |
changes the settings of what kinds of nodes are shown in the model, all model indexes become invalid after a call to this method
References mDebug().
|
slot |
changes the settings of what kinds of nodes are shown in the model, all model indexes become invalid after a call to this method
References mDebug().
|
inlinevirtualslot |
resets the model to an invalid/empty QDomDocument
|
virtual |
always returns 1 - the DOM tree has only one column corresponding to the node
|
virtual |
returns data corresponding to the node represented by index; this method can be customized through setContentFromNodeCall(...)
References DomNodeRole, and node().
|
virtual |
returns a copy of the DOM tree represented by this model, you can safely manipulate this copy without influencing the model.
If you want to change the model's content use the node methods provided here.
QVariant MDomItemModel::headerData | ( | int | section, |
Qt::Orientation | orientation, | ||
int | role = Qt::DisplayRole |
||
) | const |
returns the header data for a specific header position and role
|
virtual |
returns an index corresponding to the row, column, and parent node
row | the row beneith the parent node - the row number depends on which node types are shown, only visible node types are counted |
column | must be 0, otherwise an invalid index is returned |
parent | an invalid node for the root node (QDomDocument) or any valid index returned through index(...) |
References mDebug().
Referenced by insertNodes().
|
virtualslot |
insert a node into the parent at given position (if no position is given: append)
References insertNodes().
|
virtualslot |
insert a list of nodes into the parent at given position (if no position is given: append)
Referenced by insertNode().
|
virtualslot |
insert a list of nodes into the parent at given position (if no position is given: append)
References index(), node(), and rowCount().
|
virtual |
returns the QDomNode corresponding to index, for the invalid index the QDomDocument is returned
Referenced by data(), and insertNodes().
|
virtual |
returns the parent index of a node - if it has a parent
References mDebug().
Referenced by removeNode().
|
virtualslot |
removes the node at the given position and its child nodes
References parent().
|
virtualslot |
removes the nodes at the given position and their child nodes
References rowCount().
|
virtual |
returns the amount of visible nodes beneith parent
References mDebug().
Referenced by insertNodes(), and removeRows().
|
slot |
Customize the way the model returns data to the view, per default the model only has code to generate a text representation for Qt::DisplayRole.
You can override any role, including Qt::DisplayRole, except for DomNodeRole. The callback takes a const reference to QDomNode as argument and should convert it to a QVariant appropriate for the role.
role | the role to be customized |
callback | a static function, functor or lambda that takes a node as argument and returns a variant as result, use nullptr to delete a customization |
References DomNodeRole.
|
virtualslot |
sets the document represented by this model; the model makes a deep copy of the document, so that the original stays intact even if the model changes.
Use domDocument() to retrieve a fresh copy of the models version of the document.
References mDebug().
Referenced by MDomItemModel().
bool MDomItemModel::setHeaderData | ( | int | section, |
Qt::Orientation | orientation, | ||
const QVariant & | value, | ||
int | role = Qt::EditRole |
||
) |
sets header data - it is currently possible to set any header for any role, although only few are actually shown in views
|
virtualslot |
replaces the node at the index, you cannot replace the entire document with this function - use setDomDocument for this
|
slot |
changes the settings of what kinds of nodes are shown in the model, all model indexes become invalid after a call to this method
References showNodeTypes().
|
slot |
changes the way element nodes are displayed, this method has no effect if you customize Qt::DisplayRole through setContentFromNodeCall(...)
maxattr | the amount of characters shown for attributes, if this is 0 the model will just show "..." if the element has attributes, if this is <0 the model will ignore attributes |
maxtext | the amount of characters shown for character data (QDomText and QDomCDATASection), if this is 0 the model will just show "..." if the element has text, if this is <0 the model will ignore any text |
|
virtual |
returns a set of node types that are configured to be visible in this model
|
slot |
changes the settings of what kinds of nodes are shown in the model, element nodes cannot be switched off, all model indexes become invalid after a call to this method
References mDebug().
Referenced by showAllNodeTypes().
|
slot |
if true the default display routine will show a node type label
|
static |
alias for Qt::UserRole that is used to retrieve the DOM node of an index.
Referenced by data(), and setContentFromNodeCall().