MagicSmoke  $VERSION$
MDomItemModel Class Reference

This is a specialized model type that shows and allows to manipulate a DOM tree. More...

#include <dommodel.h>

Inheritance diagram for MDomItemModel:

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...
 

Detailed Description

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.

Constructor & Destructor Documentation

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

Parameters
xmlthe model will be fed with a copy of this DOM tree

References setDomDocument().

Member Function Documentation

void MDomItemModel::addShowNodeType ( QDomNode::NodeType  nt)
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().

void MDomItemModel::addShowNodeTypes ( const QSet< QDomNode::NodeType > &  nt)
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().

virtual void MDomItemModel::clear ( )
inlinevirtualslot

resets the model to an invalid/empty QDomDocument

int MDomItemModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

always returns 1 - the DOM tree has only one column corresponding to the node

QVariant MDomItemModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const
virtual

returns data corresponding to the node represented by index; this method can be customized through setContentFromNodeCall(...)

References DomNodeRole, and node().

QDomDocument MDomItemModel::domDocument ( ) const
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

QModelIndex MDomItemModel::index ( int  row,
int  column,
const QModelIndex &  parent = QModelIndex() 
) const
virtual

returns an index corresponding to the row, column, and parent node

Parameters
rowthe row beneith the parent node - the row number depends on which node types are shown, only visible node types are counted
columnmust be 0, otherwise an invalid index is returned
parentan invalid node for the root node (QDomDocument) or any valid index returned through index(...)

References mDebug().

Referenced by insertNodes().

void MDomItemModel::insertNode ( const QDomNode &  newnode,
const QModelIndex &  parent,
int  row = -1 
)
virtualslot

insert a node into the parent at given position (if no position is given: append)

References insertNodes().

void MDomItemModel::insertNodes ( const QDomNodeList &  newnodes,
const QModelIndex &  parent,
int  row = -1 
)
virtualslot

insert a list of nodes into the parent at given position (if no position is given: append)

Referenced by insertNode().

void MDomItemModel::insertNodes ( const QList< QDomNode > &  newnodes,
const QModelIndex &  parent,
int  row = -1 
)
virtualslot

insert a list of nodes into the parent at given position (if no position is given: append)

References index(), node(), and rowCount().

QDomNode MDomItemModel::node ( const QModelIndex &  index) const
virtual

returns the QDomNode corresponding to index, for the invalid index the QDomDocument is returned

Referenced by data(), and insertNodes().

QModelIndex MDomItemModel::parent ( const QModelIndex &  index) const
virtual

returns the parent index of a node - if it has a parent

References mDebug().

Referenced by removeNode().

void MDomItemModel::removeNode ( const QModelIndex &  index)
virtualslot

removes the node at the given position and its child nodes

References parent().

bool MDomItemModel::removeRows ( int  row,
int  count,
const QModelIndex &  parent = QModelIndex() 
)
virtualslot

removes the nodes at the given position and their child nodes

References rowCount().

int MDomItemModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const
virtual

returns the amount of visible nodes beneith parent

References mDebug().

Referenced by insertNodes(), and removeRows().

void MDomItemModel::setContentFromNodeCall ( int  role,
MDomModelFunctor  callback 
)
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.

Parameters
rolethe role to be customized
callbacka 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.

void MDomItemModel::setDomDocument ( const QDomDocument &  doc)
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

void MDomItemModel::setNode ( const QModelIndex &  index,
const QDomNode &  node 
)
virtualslot

replaces the node at the index, you cannot replace the entire document with this function - use setDomDocument for this

void MDomItemModel::showAllNodeTypes ( )
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().

void MDomItemModel::showElementProperties ( int  maxattr,
int  maxtext 
)
slot

changes the way element nodes are displayed, this method has no effect if you customize Qt::DisplayRole through setContentFromNodeCall(...)

Parameters
maxattrthe 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
maxtextthe 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
QSet< QDomNode::NodeType > MDomItemModel::shownNodeTypes ( ) const
virtual

returns a set of node types that are configured to be visible in this model

void MDomItemModel::showNodeTypes ( const QSet< QDomNode::NodeType > &  nt)
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().

void MDomItemModel::showTypeLabel ( bool  show = true)
slot

if true the default display routine will show a node type label

Member Data Documentation

const int MDomItemModel::DomNodeRole =Qt::UserRole
static

alias for Qt::UserRole that is used to retrieve the DOM node of an index.

Referenced by data(), and setContentFromNodeCall().


The documentation for this class was generated from the following files: