/* 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 MAPPINGTABLEMODEL_H #define MAPPINGTABLEMODEL_H #include #include #include "smtreemodel.h" class QString; class QSqlQuery; class QStringList; class MappingTableModel : public SmTreeModel{ Q_OBJECT public: enum CustomRoles { ItemNameRole = Qt::UserRole + 1, ItemIdRole = Qt::UserRole + 2 }; enum Fields { ItemName = 0, ItemId = 1 }; explicit MappingTableModel(QStringList &headers, const QString &table, QObject *parent = 0); virtual ~MappingTableModel(); //data + flags virtual Qt::ItemFlags flags(const QModelIndex &index) const; virtual QVariant data(const QModelIndex &index, int role) const; virtual bool setData(const QModelIndex &index, const QVariant &value, int role); bool contains(const QString &value) const; void setMappings(const QStringList &itemNames, int seriesPartId = -1); QStringList findPartialName(const QString &value) const; //add and remove items bool addItem(const QVariant &name); bool removeItem(const QModelIndex &idx); //mappings bool addMapping(int seriesPartId, int itemId); bool removeMapping(int seriesId, int itemId); QList mappings(int seriesId); //database maintenance QHash zeroUsers(); void deleteItems(const QList &ids); signals: void needResort(); private: void populate(); QSqlDatabase mDb; QString mTable; QString mMappingTable; QString mIdColumnName; QString mNameColumnName; QString mSequenceName; QStringList mItemNames; //queries QSqlQuery *mUpdateItemNameQuery; QSqlQuery *mInsertItemQuery; QSqlQuery *mDeleteItemQuery; QSqlQuery *mAddMappingQuery; QSqlQuery *mRemoveMappingQuery; QSqlQuery *mMappingQuery; QSqlQuery *mAllItemsQuery; QSqlQuery *mItemCountQuery; }; #endif // MAPPINGTABLEMODEL_H