From e82af6117dfcf4ccbebb712caaf1b8f9c68599ba Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 24 Feb 2012 06:49:19 +0100 Subject: First shot at MappingTreeModel MappingTreeModel is a generic approach at mappings files to generic data, eg atttributes, actors or themes. It compiles, but nothing more. So expect many exciting bugs and SegFaults. --- mappingtreemodel.h | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 mappingtreemodel.h (limited to 'mappingtreemodel.h') 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 + +#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 -- cgit v1.2.3-70-g09d2