LibEngsas
exmlmodel.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2010 - 2015 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 EXMLMODEL_H
21 #define EXMLMODEL_H
22 
23 #include "eglobal.h"
24 #include "eabstractitemmodel.h"
25 
26 class EXmlItem;
27 class EXmlParserItem;
28 
29 #include <QModelIndex>
30 #include <QDomDocument>
31 #include <QFile>
32 #include <QStringList>
33 #include <QUrl>
34 
61 {
62  Q_OBJECT
63  public:
69  EXmlModel(QUrl validationUrl, QObject *parent = 0);
70  virtual ~EXmlModel();
71 
72  // own api
78  bool load(QDomElement element);
82  bool load(QDomDocument document);
86  bool load(QFile *file);
90  bool load(QString file);
96  bool load(QByteArray data);
102  bool save(QDomElement &useElem);
106  bool save(QFile *file);
110  bool save(QString file);
117  QDomDocument save();
122  bool isValidXML();
123  EXmlItem *itemFromIndex(QModelIndex index) const;
124  QModelIndex indexFromItem(EXmlItem *item) const;
128  bool removeItem(QModelIndex index);
134  bool removeItem(EXmlItem *item);
135 
143  virtual void setRootItem(EXmlItem* item);
144  EXmlItem *rootItem() const;
145 
157  bool isModified() const;
158 
159 
160  // standard api
161  QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
162  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
163  int columnCount(const QModelIndex& parent = QModelIndex()) const;
164  int rowCount(const QModelIndex& parent = QModelIndex()) const;
165  QModelIndex parent(const QModelIndex& child) const;
166  QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
167  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
168  bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
169 
170  signals:
171  void modified(bool status);
172 
173  protected:
191  bool registerParser(EXmlItem *(*createCallback)(EXmlModel*));
192  void setValidationSchema(QUrl url);
199  virtual inline bool prepareForSaving(){ return true; }
200 
204  QStringList headerList;
205 
206  protected slots:
213  virtual void itemChanged(EXmlItem *item);
219  virtual void itemRowsAboutToBeInserted(EXmlItem *parent, int start, int end);
225  virtual void itemRowsInserted();
231  virtual void itemRowsAboutToBeRemoved(EXmlItem *parent, int start, int end);
237  virtual void itemRowsRemoved();
238 
239  private slots:
240  void setModified(bool status);
241 
242  private:
243  QModelIndex indexFromItem(EXmlItem *find, EXmlItem *parent) const;
244 
246  QMap<QString, EXmlParserItem*> parsers;
249 };
250 
251 #endif // EXMLMODEL_H