Editing an item is now undo/redo-able.
This commit is contained in:
@ -13,10 +13,12 @@ class TableModel : public QAbstractTableModel {
|
||||
|
||||
friend class InsertRowsCommand;
|
||||
friend class RemoveRowsCommand;
|
||||
friend class EditItemCommand;
|
||||
|
||||
public:
|
||||
enum UserRoles { NameRole = Qt::UserRole + 1, DescriptionRole, InfoRole, AmountRole, FactorRole };
|
||||
static QHash<int, QByteArray> ROLE_NAMES;
|
||||
static QList<QString> intColumns;
|
||||
|
||||
explicit TableModel(QUndoStack* undoStack, QObject* parent = nullptr);
|
||||
|
||||
@ -30,7 +32,7 @@ class TableModel : public QAbstractTableModel {
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
|
||||
|
||||
bool setData(const QModelIndex& index, const QVariant& value, int role) override;
|
||||
// bool setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles) override;
|
||||
bool setItemData(const QModelIndex& index, const QMap<int, QVariant>& roles) override;
|
||||
|
||||
public slots:
|
||||
// bool insertRows(int position, int rows, const QModelIndex& parentIndex = QModelIndex())
|
||||
@ -48,9 +50,13 @@ class TableModel : public QAbstractTableModel {
|
||||
/// undo/redo functions
|
||||
void execInsertItems(const int firstRow, const QList<QHash<int, QVariant>> valueList);
|
||||
void execRemoveItems(const int firstRow, const int nRows);
|
||||
void execEditItemData(const int row, const QMap<int, QVariant>& changedValues);
|
||||
|
||||
/// misc functions
|
||||
int getRoleForColumn(const int column) const;
|
||||
QMap<int, QVariant> onlyChangedValues(const QModelIndex& index,
|
||||
const QMap<int, QVariant>& roleValueMap) const;
|
||||
bool isEmptyValueEqualToZero(const int role) const;
|
||||
};
|
||||
|
||||
#endif // TABLEMODEL_H
|
||||
|
||||
Reference in New Issue
Block a user