git-svn-id: file:///svnroot/family-shop-mgr@31 26eb2498-383b-47a6-be48-5d6f36779e85
[family-shop-mgr] / code / family-shop-mgr / ShoppingTreeModel.h
index 278edfa..8535e62 100644 (file)
@@ -27,6 +27,7 @@
 #include <QModelIndex>\r
 #include <QVector>\r
 #include <QVariant>\r
+#include <QHash>\r
 \r
 class ShoppingTreeItem;\r
 \r
@@ -38,6 +39,13 @@ public:
     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
+\r
     QVariant data(const QModelIndex &index, int role) const;\r
     QVariant headerData(int section, Qt::Orientation orientation,\r
                         int role = Qt::DisplayRole) const;\r
@@ -53,11 +61,13 @@ public:
                  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
+                           const QModelIndex &parent = QModelIndex());\r
     bool removeColumns(int position, int columns,\r
-                       const QModelIndex &parent = QModelIndex());\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
@@ -67,15 +77,22 @@ signals:
     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
 };\r