summaryrefslogtreecommitdiffstats
path: root/mappingtableeditor.h
blob: d372d0b0d600a9aac6aa610d84bc6e7e1a561f6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
  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 <QTreeView>
#include <QSqlDatabase>

#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