blob: 8ee4636855efee77cb4d7aa90f4c6c3edbec9ea1 (
plain) (
blame)
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
|
#ifndef DATAWIDGETMAPPER_H
#define DATAWIDGETMAPPER_H
#include <QObject>
#include <QHash>
#include <functional>
class QAbstractItemModel;
class DataWidgetMapper : public QObject
{
Q_OBJECT
public:
typedef std::function<bool(QWidget*)> SubmitFilter;
explicit DataWidgetMapper(QObject *parent = 0);
QAbstractItemModel* getModel() const;
void setModel(QAbstractItemModel* value);
void addMapping(QWidget* widget, int modelColumn, const QString& propertyName);
void clearMapping();
int getCurrentIndex() const;
int mappedSection(QWidget* widget) const;
SubmitFilter getSubmitFilter() const;
void setSubmitFilter(const SubmitFilter& value);
private:
struct MappingEntry
{
QWidget* widget = nullptr;
int columnIndex = 0;
QString propertyName;
};
void loadFromModel();
QAbstractItemModel* model = nullptr;
int currentIndex = -1;
QHash<QWidget*,MappingEntry*> mappings;
SubmitFilter submitFilter = nullptr;
public slots:
void setCurrentIndex(int rowIndex);
void toFirst();
void toLast();
void toNext();
void toPrevious();
void submit();
void revert();
signals:
void currentIndexChanged(int newRowIndex);
};
#endif // DATAWIDGETMAPPER_H
|