summaryrefslogtreecommitdiffstats
path: root/mappingtablewidget.h
blob: 787d7f60728f17873e9d4ce3fe838ec29794ff8f (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
78
79
80
81
82
83
84
85
/*
  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 MAPPINGTABLEWIDGET_H
#define MAPPINGTABLEWIDGET_H

#include <QtWidgets/QWidget>
#include <QStringListModel>
#include <QIcon>

#include "smdialog.h"
#include "smtreeview.h"

class MappingTableItemModel;
class MappingTableModel;

class MappingTableWidget : public QWidget{
	Q_OBJECT
	public:
		explicit MappingTableWidget(const QString &table, QWidget *parent = 0);
		MappingTableItemModel *model() { return mModel; }

	public slots:
		void setStringList(const QStringList &list);
		void setEditEnabled(bool enabled);
		void setCurrentId(int id) { mCurrentId = id; }

	private slots:
		void searchItem();
		void addItem();
		void removeItem();

	private:
        SmTreeView* mView;
		QPushButton *mAddItem;
		QPushButton *mRemoveItem;
		QPushButton *mSearchItem;
		QLineEdit *mItemEdit;
		MappingTableItemModel *mModel;
		MappingTableModel *mMappingModel;
		const QString mTable;
		int mCurrentId;
};

class MappingTableItemModel : public QStringListModel {
	Q_OBJECT
	public:
		explicit MappingTableItemModel(QObject *parent = 0);

		//data + flags
		virtual QVariant data(const QModelIndex &index, int role) const;
		virtual Qt::ItemFlags flags(const QModelIndex &index) const;
		void setDecorationIcon(const QIcon &icon) { mDecorationIcon = icon; }
		const QIcon decorationIcon() const { return mDecorationIcon; }

		//find
		int lowerBound(const QString &value) const;
		QModelIndex find(const QString &value) const;

	private:
		QIcon mDecorationIcon;
};

class MappingTableResultDialog : public SmDialog {
	Q_OBJECT
	public:
		explicit MappingTableResultDialog(const QStringList &results, QWidget *parent = 0, Qt::WindowFlags f = 0);
		QString selectedText() const { return mSelectedText; }

	private slots:
		void accept();

	private:
        SmTreeView *mView;
		QStringListModel *mModel;
		QPushButton *mOk;
		QPushButton *mCancel;
		QString mSelectedText;
};

#endif // MAPPINGTABLEWIDGET_H