git-svn-id: file:///svnroot/family-shop-mgr@32 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / ShoppingTreeModel.h
index 8535e62..92ef5c7 100644 (file)
 #include <QAbstractItemModel>\r
 #include <QDomDocument>\r
 #include <QModelIndex>\r
-#include <QVector>\r
 #include <QVariant>\r
-#include <QHash>\r
 \r
-class ShoppingTreeItem;\r
+class DomItem;\r
 \r
-class ShoppingTreeModel : public QAbstractItemModel\r
+class DomModel : public QAbstractItemModel\r
 {\r
-Q_OBJECT\r
+    Q_OBJECT\r
 \r
 public:\r
-    ShoppingTreeModel(const QString &xmlFileName, QObject *parent = 0);\r
-    ~ShoppingTreeModel();\r
-\r
-    bool addCategory(QString name);\r
-    bool addSubCategory(QString name, int position,\r
-                        const QModelIndex &parent = QModelIndex());\r
-    bool addItem(QString name, int position,\r
-                 const QModelIndex &parent = QModelIndex());\r
-    bool removeCategoryOrItem(const QModelIndex &index = QModelIndex());\r
+    DomModel(QDomDocument document, QObject *parent = 0);\r
+    ~DomModel();\r
 \r
     QVariant data(const QModelIndex &index, int role) const;\r
+    Qt::ItemFlags flags(const QModelIndex &index) const;\r
     QVariant headerData(int section, Qt::Orientation orientation,\r
                         int role = Qt::DisplayRole) const;\r
     QModelIndex index(int row, int column,\r
                       const QModelIndex &parent = QModelIndex()) const;\r
-    QModelIndex parent(const QModelIndex &index) const;\r
-\r
+    QModelIndex parent(const QModelIndex &child) const;\r
     int rowCount(const QModelIndex &parent = QModelIndex()) const;\r
     int columnCount(const QModelIndex &parent = QModelIndex()) const;\r
 \r
-    Qt::ItemFlags flags(const QModelIndex &index) const;\r
-    bool setData(const QModelIndex &index, const QVariant &value,\r
-                 int role = Qt::EditRole);\r
-    bool setHeaderData(int section, Qt::Orientation orientation,\r
-                       const QVariant &value, int role = Qt::EditRole);\r
-    void sort(int column, Qt::SortOrder order);\r
-\r
 private:\r
-    bool insertColumns(int position, int columns,\r
-                           const QModelIndex &parent = QModelIndex());\r
-    bool removeColumns(int position, int columns,\r
-                           const QModelIndex &parent = QModelIndex());\r
-    bool insertRows(int position, int rows,\r
-                    const QModelIndex &parent = QModelIndex());\r
-    bool removeRows(int position, int rows,\r
-                    const QModelIndex &parent = QModelIndex());\r
-\r
-signals:\r
-    void xmlParseError(QString error, int line, int column);\r
-    void invalidDocument();\r
-\r
-public slots:\r
-    void registerInsertedChild(ShoppingTreeItem *item);\r
-    void deleteRemovedChild(ShoppingTreeItem *item);\r
-\r
-protected:\r
-    void parseCategoryElement(const QDomElement &element,\r
-                              ShoppingTreeItem *parentItem = 0);\r
-    QVector<QVariant> getColumnsFromItemElement(const QDomElement &element);\r
-    bool updateDomElement(ShoppingTreeItem *item, int column);\r
-    void updateXmlFile() const;\r
-\r
-private:\r
-    ShoppingTreeItem *getItem(const QModelIndex &index) const;\r
-\r
-    ShoppingTreeItem *rootItem;\r
-    QString m_xmlFileName;\r
-    QDomDocument m_document;\r
-    QHash<ShoppingTreeItem *, QDomElement> m_domElementForItem;\r
+    QDomDocument domDocument;\r
+    QDomNode rootItemNode;\r
+    DomItem *rootItem;\r
 };\r
 \r
 #endif // SHOPPINGTREEMODEL_H\r