MagicSmoke  $VERSION$
dommodel.h
Go to the documentation of this file.
1 //
2 // C++ Interface: odtrender
3 //
4 // Description:
5 //
6 //
7 // Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008-2011
8 //
9 // Copyright: See README/COPYING.GPL files that come with this distribution
10 //
11 //
12 
13 #ifndef MAGICSMOKE_DOMMODEL_H
14 #define MAGICSMOKE_DOMMODEL_H
15 
16 #include <QAbstractItemModel>
17 #include <DPtrBase>
18 #include <QDomNode>
19 
20 #include <functional>
21 
22 #include "commonexport.h"
23 
24 class QDomNode;
25 class QDomDocument;
26 
29 typedef std::function<QVariant(const QDomNode&)> MDomModelFunctor;
30 
35 class MAGICSMOKE_COMMON_EXPORT MDomItemModel:public QAbstractItemModel
36 {
37  Q_OBJECT
38  DECLARE_DPTR(d);
39  public:
41  MDomItemModel(QObject* parent = 0);
44  MDomItemModel(const QDomDocument&xml, QObject* parent = 0);
45 
49  virtual QDomDocument domDocument()const;
50 
52  static const int DomNodeRole=Qt::UserRole;
53 
55  virtual int columnCount(const QModelIndex&parent=QModelIndex())const;
58  virtual QVariant data(const QModelIndex&index, int role=Qt::DisplayRole)const;
59 
64  virtual QModelIndex index(int row, int column, const QModelIndex&parent=QModelIndex())const;
66  virtual QModelIndex parent(const QModelIndex&index)const;
68  virtual int rowCount(const QModelIndex&parent=QModelIndex())const;
69 
71  virtual QSet<QDomNode::NodeType> shownNodeTypes()const;
72 
74  virtual QDomNode node(const QModelIndex&index)const;
75 
77  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole);
79  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole)const;
80 
81  public slots:
84  virtual void setDomDocument(const QDomDocument&);
85 
89  void showNodeTypes(const QSet<QDomNode::NodeType>&);
92  void addShowNodeType(QDomNode::NodeType);
95  void addShowNodeTypes(const QSet<QDomNode::NodeType>&);
98  void showAllNodeTypes();
99 
105  void showElementProperties(int maxattr,int maxtext);
106 
108  void showTypeLabel(bool show=true);
109 
111  virtual void setNode(const QModelIndex&index,const QDomNode&);
113  virtual void insertNode(const QDomNode&newnode,const QModelIndex&parent,int row=-1);
115  virtual void insertNodes(const QDomNodeList&newnodes,const QModelIndex&parent,int row=-1);
117  virtual void insertNodes(const QList<QDomNode>&newnodes,const QModelIndex&parent,int row=-1);
119  virtual bool removeRows(int row, int count, const QModelIndex&parent=QModelIndex());
121  virtual void removeNode(const QModelIndex&);
122 
127  void setContentFromNodeCall(int role,MDomModelFunctor callback);
128 
130  virtual void clear(){setDomDocument(QDomDocument());}
131 
132  private:
134  QVariant displayFromNode(const QDomNode&)const;
135 };
136 
137 Q_DECLARE_METATYPE(QDomNode);
139 
140 #endif
#define MAGICSMOKE_COMMON_EXPORT
Definition: commonexport.h:7
virtual void clear()
resets the model to an invalid/empty QDomDocument
Definition: dommodel.h:130
This is a specialized model type that shows and allows to manipulate a DOM tree.
Definition: dommodel.h:35
Q_DECLARE_METATYPE(QDomNode)
std::function< QVariant(const QDomNode &)> MDomModelFunctor
Special functor that can be used to customize MDomItemModel.
Definition: dommodel.h:25