#ifndef DATAGRIDWIDGET_H #define DATAGRIDWIDGET_H #include class QAbstractItemModel; class QAction; class QSortFilterProxyModel; class QTableView; class QToolBar; /** Sortable and editable grid shared by the CRUD tab and the query result tab. */ class DataGridWidget : public QWidget { Q_OBJECT public: explicit DataGridWidget(QWidget *parent = nullptr); /// Sets the model to show, sorting is done by a proxy that uses CustomSortRole void setSourceModel(QAbstractItemModel *model); QTableView *view() const { return m_view; } QSortFilterProxyModel *proxy() const { return m_proxy; } private slots: void onPendingChangesChanged(bool hasChanges); void onSave(); void onRevert(); private: /// Closes an open cell editor so its value is written to the model before saving or reverting void commitOpenEditor(); QTableView *m_view = nullptr; QSortFilterProxyModel *m_proxy = nullptr; QToolBar *m_toolbar = nullptr; QAction *m_actSave = nullptr; QAction *m_actRevert = nullptr; QMetaObject::Connection m_pendingChangesConnection; }; #endif // DATAGRIDWIDGET_H