From d24f813f3f2a05c112e803e4256b53535895fc98 Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Wed, 14 Jul 2021 11:49:10 +1200 Subject: Initial mirror commit --- src/main-view/UndoCommands.h | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/main-view/UndoCommands.h (limited to 'src/main-view/UndoCommands.h') diff --git a/src/main-view/UndoCommands.h b/src/main-view/UndoCommands.h new file mode 100644 index 0000000..a4affec --- /dev/null +++ b/src/main-view/UndoCommands.h @@ -0,0 +1,109 @@ +#ifndef UNDOCOMMANDS_H +#define UNDOCOMMANDS_H + +#include +#include + +class DicRecord; +class MainWindow; +class DictTableView; +class DictTableModel; +class CardFilterModel; + +class UndoRecordCmd: public QUndoCommand +{ +public: + UndoRecordCmd( const MainWindow* aMainWin ); + +protected: + const DictTableView* getCurView(); + CardFilterModel* getProxyModel( const DictTableView* aCurDictView ); + + void insertRows( QList aRowNumbers ); + void setRecords( QMap aRecords ); + void removeRows( QList aRowNumbers ); + void selectRows( QList aRowNumbers ); + void selectRow( int aRow ); + +protected: + const MainWindow* m_mainWindow; + DictTableModel* m_dictModel; +}; + +class InsertRecordsCmd: public UndoRecordCmd +{ +public: + InsertRecordsCmd(const MainWindow* aMainWin); + + static const int Id = 1; + + void updateText(); + void redo(); + void undo(); + bool mergeWith( const QUndoCommand* command ); + int id() const { return Id; } + +private: + QList m_rowNumbers; +}; + +class RemoveRecordsCmd: public UndoRecordCmd +{ +public: + RemoveRecordsCmd( const MainWindow* aMainWin ); + ~RemoveRecordsCmd(); + + static const int Id = 2; + + void redo(); + void undo(); + bool mergeWith( const QUndoCommand* ) { return false; } + int id() const { return Id; } + +private: + QMap m_records; // row number -> pointer to dic record. Sorted by key: rows + // The first element is the top row +}; + +/// Doesn't inherit UndoRecordCmd! +class EditRecordCmd: public QUndoCommand +{ +public: + EditRecordCmd( QAbstractItemModel* aTableModel, const QModelIndex& aIndex, const QVariant& aValue ); + + static const int Id = 3; + + void redo(); + void undo(); + bool mergeWith( const QUndoCommand* ) { return false; } + int id() const { return Id; } + +private: + static const int MaxMenuEditStrLen = 20; + + QAbstractItemModel* m_dictModel; + int m_row; + int m_col; + QString m_oldStr; + QString m_newStr; + int m_insertedRow; +}; + +class PasteRecordsCmd: public UndoRecordCmd +{ +public: + PasteRecordsCmd( QList aRecords, const MainWindow* aMainWin ); + ~PasteRecordsCmd(); + + static const int Id = 4; + + void redo(); + void undo(); + bool mergeWith( const QUndoCommand* ) { return false; } + int id() const { return Id; } + +private: + QMap m_records; // row number -> pointer to dic record. Sorted by key: rows +}; + +#endif // UNDOCOMMANDS_H -- cgit