LibEngsas
exmlitem.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2012 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17  MA 02110-1301 USA.
18 */
19 
20 #ifndef EXMLITEM_H
21 #define EXMLITEM_H
22 
23 #include "eglobal.h"
24 #include <QObject>
25 
26 class EXmlParserItem;
27 
28 #include <QVariant>
29 #include <QDomElement>
30 
48 class E_CORE_EXPORT EXmlItem : public QObject
49 {
50  Q_OBJECT
51  public:
52  EXmlItem(QString tagName, EXmlItem *parent = 0);
53  virtual ~EXmlItem();
54 
69  virtual bool load(const QDomElement element, QMap<QString, EXmlParserItem*> parser) = 0;
78  virtual bool save(QDomElement &useElem);
79 
80  int rowCount() const;
88  virtual QVariant data(int column, int role = Qt::DisplayRole) const = 0;
95  virtual bool setData(int column, QVariant value, int role = Qt::EditRole);
96 
100  virtual void setParent(EXmlItem *parent);
101  EXmlItem *parent() const;
112  virtual bool addChild(int row, EXmlItem *item, bool emitInsertRows = true);
116  virtual bool removeChild(int row, bool emitRemoveRows = true);
117  EXmlItem *child(int row) const;
124  int row(EXmlItem *child) const;
125  void setTagName(QString tagName);
131  QString tagName() const;
132 
148  virtual EXmlItem *copy() const = 0;
149 
150  signals:
151  void changed(EXmlItem *item);
152  void rowsAboutToBeInserted(EXmlItem *parent, int start, int end);
153  void rowsInserted();
154  void rowsAboutToBeRemoved(EXmlItem *parent, int start, int end);
155  void rowsRemoved();
156 
157 
158  protected slots:
164  inline virtual void changedByPass(EXmlItem *item){ emit changed(item); }
170  inline virtual void rowsAboutToBeInsertedByPass(EXmlItem *parent, int start, int end){ emit rowsAboutToBeInserted(parent, start, end); }
176  inline virtual void rowsInsertedByPass(){ emit rowsInserted(); }
182  inline virtual void rowsAboutToBeRemovedByPass(EXmlItem *parent, int start, int end){ emit rowsAboutToBeRemoved(parent, start, end); }
188  inline virtual void rowsRemovedByPass(){ emit rowsRemoved(); }
189 
190  protected:
207  virtual void copyBase(EXmlItem *target) const;
208 
209 
210  private:
212  QList<EXmlItem*> childs;
213  QString myTagName;
214 };
215 
216 Q_DECLARE_METATYPE(EXmlItem*)
217 
218 #endif // EXMLITEM_H