Add recordpanel beside datagrid
This commit is contained in:
parent
d178d5191c
commit
04ce099adf
12 changed files with 538 additions and 8 deletions
55
pglab/crud/RecordPanel.h
Normal file
55
pglab/crud/RecordPanel.h
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef RECORDPANEL_H
|
||||
#define RECORDPANEL_H
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QPersistentModelIndex>
|
||||
#include <vector>
|
||||
|
||||
class QAbstractItemModel;
|
||||
class QEvent;
|
||||
class QToolButton;
|
||||
|
||||
/** Shows the values of one row of a model as a scrollable list, one line per column.
|
||||
* Values are edited through the model so the pending change logic of the model is reused.
|
||||
*/
|
||||
class RecordPanel : public QScrollArea {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RecordPanel(QWidget *parent = nullptr);
|
||||
|
||||
/// Sets the model to show, the columns from firstDataColumn on are shown
|
||||
void setModel(QAbstractItemModel *model);
|
||||
/// Columns before this one are skipped, e.g. the row number column of the CRUD model
|
||||
void setFirstDataColumn(int column);
|
||||
/// Shows the values of the given row of the model, -1 shows nothing
|
||||
void setCurrentRow(int row);
|
||||
|
||||
protected:
|
||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
||||
|
||||
private slots:
|
||||
void refresh();
|
||||
void onModelReset();
|
||||
|
||||
private:
|
||||
struct FieldRow {
|
||||
int column = -1;
|
||||
QString original; ///< Text the editor shows, only a different text is written back
|
||||
QWidget *editor = nullptr;
|
||||
QToolButton *expandButton = nullptr;
|
||||
};
|
||||
|
||||
void clearFields();
|
||||
void rebuild();
|
||||
void showValue(FieldRow &field, const QString &text, bool editable);
|
||||
void commitEditor(QWidget *editor);
|
||||
FieldRow *findField(QWidget *editor);
|
||||
|
||||
QAbstractItemModel *m_model = nullptr;
|
||||
int m_firstDataColumn = 0;
|
||||
QPersistentModelIndex m_rowIndex;
|
||||
std::vector<FieldRow> m_fields;
|
||||
bool m_updating = false;
|
||||
};
|
||||
|
||||
#endif // RECORDPANEL_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue