/* 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 MAPPINGTABLEEDITOR_H #define MAPPINGTABLEEDITOR_H #include #include #include "smdialog.h" #include "smtreemodel.h" #include "smtreeitem.h" class QSqlQuery; class QContextMenuEvent; class QPushButton; class QLineEdit; class QAction; class MappingTableEditorView; class MappingTableEditorModel; class MappingTableEditor : public SmDialog { Q_OBJECT public: explicit MappingTableEditor(const QString &table, QWidget *parent = 0); private slots: void selectionChanged(const QModelIndex &cur, const QModelIndex &prev); void removeItem(); void renameItem(); void editItem(); private: const QString mTable; QPushButton *mClose; QPushButton *mDelete; QPushButton *mRename; QLineEdit *mDataEdit; QAction *mDeleteA; QAction *mEditA; MappingTableEditorView *mView; MappingTableEditorModel *mModel; }; class MappingTableEditorView : public QTreeView { Q_OBJECT public: explicit MappingTableEditorView(QWidget *parent = 0); protected: virtual void contextMenuEvent(QContextMenuEvent *e); }; class MappingTableEditorModel : public SmTreeModel { Q_OBJECT public: enum Roles { NameRole = Qt::UserRole + 1, CountRole = Qt::UserRole +2, IdRole = Qt::UserRole + 3 }; enum Fields { Name = 0, Count = 1, Id = 2 }; explicit MappingTableEditorModel(const QString &table, const QStringList &headers, QObject *parent = 0); virtual ~MappingTableEditorModel(); virtual Qt::ItemFlags flags(const QModelIndex &idx) const; virtual QVariant data(const QModelIndex &index, int role) const; virtual bool setData(const QModelIndex &idx, const QVariant &value, int role); virtual bool removeData(const QModelIndex &idx); private: void populate(); const QString mTable; QSqlDatabase mDb; QSqlQuery *mDataQuery; }; #endif // MAPPINGTABLEEDITOR_H