diff options
Diffstat (limited to 'SQLiteStudio3/guiSQLiteStudio/common/datawidgetmapper.h')
| -rw-r--r-- | SQLiteStudio3/guiSQLiteStudio/common/datawidgetmapper.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/SQLiteStudio3/guiSQLiteStudio/common/datawidgetmapper.h b/SQLiteStudio3/guiSQLiteStudio/common/datawidgetmapper.h new file mode 100644 index 0000000..4df7d5e --- /dev/null +++ b/SQLiteStudio3/guiSQLiteStudio/common/datawidgetmapper.h @@ -0,0 +1,54 @@ +#ifndef DATAWIDGETMAPPER_H +#define DATAWIDGETMAPPER_H + +#include <QObject> +#include <QHash> + +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 |
