Adding new items to the model can now be made undone/redone.
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class QUndoStack;
|
||||
class ModelItem;
|
||||
|
||||
using namespace std;
|
||||
@ -10,11 +11,13 @@ using namespace std;
|
||||
class TableModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
|
||||
friend class InsertRowsCommand;
|
||||
|
||||
public:
|
||||
enum UserRoles { NameRole = Qt::UserRole + 1, DescriptionRole, InfoRole, AmountRole, FactorRole };
|
||||
static QHash<int, QByteArray> ROLE_NAMES;
|
||||
|
||||
explicit TableModel(QObject* parent = nullptr);
|
||||
explicit TableModel(QUndoStack* undoStack, QObject* parent = nullptr);
|
||||
|
||||
/// QAbstractItemModel interface
|
||||
Qt::ItemFlags flags(const QModelIndex& index) const override;
|
||||
@ -36,10 +39,16 @@ class TableModel : public QAbstractTableModel {
|
||||
void insertItems(int startPosition, const QByteArray& jsonDoc, const QModelIndex& parentIndex);
|
||||
|
||||
private:
|
||||
/// members
|
||||
/// *** members ***
|
||||
QList<shared_ptr<ModelItem>> m_items;
|
||||
QUndoStack* m_undoStack;
|
||||
|
||||
/// functions
|
||||
/// *** functions ***
|
||||
/// undo/redo functions
|
||||
void execInsertItems(const int firstRow, const QList<QHash<int, QVariant>> valueList);
|
||||
void execRemoveItems(const int firstRow, const int nRows);
|
||||
|
||||
/// misc functions
|
||||
int getRoleForColumn(const int column) const;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user