From 1a976e1ec94183023e3b330368f2860a504fe403 Mon Sep 17 00:00:00 2001 From: Arno Date: Fri, 25 Jun 2010 21:17:37 +0200 Subject: New model: MappingTableModel Implemented new Model for Mapping tables. This model is intended to replace the old ListModel and Singleton. MappingTableModel is derived from SmTreeModel and can be accessed using SmModelSingleton. It's quite dynamic building its queries, and has yet to be tested. Hopefully I got it right the first time :) --- mappingtablemodel.h | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 mappingtablemodel.h (limited to 'mappingtablemodel.h') diff --git a/mappingtablemodel.h b/mappingtablemodel.h new file mode 100644 index 0000000..f624bff --- /dev/null +++ b/mappingtablemodel.h @@ -0,0 +1,62 @@ +/* + 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); + + //add and remove items + bool addItem(const QVariant &name); + bool removeItem(const QModelIndex &idx); + + //mappings + bool addMapping(int seriesId, const QList &itemIds); + QList mappings(int seriesId); + + 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 *mMappingQuery; +}; + +#endif // MAPPINGTABLEMODEL_H -- cgit v1.2.3-70-g09d2