pgLab/pglab/crud/DataGridWidget.h
2026-10-20 19:06:18 +02:00

50 lines
1.3 KiB
C++

#ifndef DATAGRIDWIDGET_H
#define DATAGRIDWIDGET_H
#include <QWidget>
class QAbstractItemModel;
class QAction;
class QModelIndex;
class QSortFilterProxyModel;
class QSplitter;
class QTableView;
class QToolBar;
class RecordPanel;
/** 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();
void onCurrentRowChanged(const QModelIndex &current);
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;
QSplitter *m_splitter = nullptr;
RecordPanel *m_recordPanel = nullptr;
QToolBar *m_toolbar = nullptr;
QAction *m_actSave = nullptr;
QAction *m_actRevert = nullptr;
QAction *m_actRecord = nullptr;
QMetaObject::Connection m_pendingChangesConnection;
QMetaObject::Connection m_currentRowConnection;
};
#endif // DATAGRIDWIDGET_H