2026-10-18 10:29:24 +02:00
|
|
|
#ifndef DATAGRIDWIDGET_H
|
|
|
|
|
#define DATAGRIDWIDGET_H
|
|
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
|
|
class QAbstractItemModel;
|
2026-10-18 11:34:00 +02:00
|
|
|
class QAction;
|
2026-10-18 10:29:24 +02:00
|
|
|
class QSortFilterProxyModel;
|
|
|
|
|
class QTableView;
|
2026-10-18 11:34:00 +02:00
|
|
|
class QToolBar;
|
2026-10-18 10:29:24 +02:00
|
|
|
|
|
|
|
|
/** 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; }
|
|
|
|
|
|
2026-10-18 11:34:00 +02:00
|
|
|
private slots:
|
|
|
|
|
void onPendingChangesChanged(bool hasChanges);
|
|
|
|
|
void onSave();
|
|
|
|
|
void onRevert();
|
|
|
|
|
|
2026-10-18 10:29:24 +02:00
|
|
|
private:
|
2026-10-18 11:34:00 +02:00
|
|
|
/// Closes an open cell editor so its value is written to the model before saving or reverting
|
|
|
|
|
void commitOpenEditor();
|
|
|
|
|
|
2026-10-18 10:29:24 +02:00
|
|
|
QTableView *m_view = nullptr;
|
|
|
|
|
QSortFilterProxyModel *m_proxy = nullptr;
|
2026-10-18 11:34:00 +02:00
|
|
|
QToolBar *m_toolbar = nullptr;
|
|
|
|
|
QAction *m_actSave = nullptr;
|
|
|
|
|
QAction *m_actRevert = nullptr;
|
|
|
|
|
QMetaObject::Connection m_pendingChangesConnection;
|
2026-10-18 10:29:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // DATAGRIDWIDGET_H
|