diff options
Diffstat (limited to 'mappingtreemodel.h')
-rw-r--r-- | mappingtreemodel.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/mappingtreemodel.h b/mappingtreemodel.h new file mode 100644 index 0000000..a18ce57 --- /dev/null +++ b/mappingtreemodel.h @@ -0,0 +1,72 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#ifndef MAPPINGTREEMODEL_H +#define MAPPINGTREEMODEL_H + +#include <QSqlDatabase> + +#include "smtreemodel.h" + +class QSqlQuery; +class SmTreeItem; + +class MappingTreeModel : public SmTreeModel { + Q_OBJECT + public: + enum Roles { NameRole = Qt::UserRole + 1, IdRole = Qt::UserRole + 2, AddedRole = Qt::UserRole + 3 }; + enum Fields { Name = 0, Id = 1, Added = 2 }; + enum { NumFields = 3 }; + MappingTreeModel(QStringList &headers, QObject *parent = 0); + ~MappingTreeModel(); + + //model type convenience functions + int type() const { return mType; } + QStringList mappingTypeNames() const; + int mappingTypeIdFromName(const QVariant &name) const; + QString mappingTypeNameFromId(int id) const; + + //data + QVariant data(const QModelIndex &index, int role) const; + bool setData(const QModelIndex &index, const QVariant &value, int role); + bool addMappingType(const QString &type); + bool deleteMappingType(int typeId); + bool addChild(const QVariant &name, const QModelIndex &parent); + bool deleteChild(const QModelIndex &idx); + + public slots: + void populate(); + void setType(int type) { mType = type; } + + signals: + void mappingTypesChanged(); + + private: + struct mappingType { + QVariant id; + QVariant name; + }; + void getMappingTypes(); + void getChildrenRecursive(SmTreeItem *item); + QSqlDatabase mDb; + QSqlQuery *mTypesQ; + QSqlQuery *mTypeParentsQ; + QSqlQuery *mChildrenQ; + QSqlQuery *mUpdateTypeQ; + QSqlQuery *mUpdateChildQ; + QSqlQuery *mAddMappingTypeQ; + QSqlQuery *mDeleteMappingTypeQ; + QSqlQuery *mAddChildQ; + QSqlQuery *mSelectChildQ; + QSqlQuery *mAddParentQ; + QSqlQuery *mDeleteChildQ; + QList<mappingType> mMappingTypes; + int mType; + +}; + +#endif // MAPPINGTREEMODEL_H |