/* 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 #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 mMappingTypes; int mType; }; #endif // MAPPINGTREEMODEL_H