diff options
Diffstat (limited to 'src/main-view/UndoCommands.h')
-rw-r--r-- | src/main-view/UndoCommands.h | 109 |
1 files changed, 109 insertions, 0 deletions
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 <QtCore> +#include <QtWidgets> + +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<int> aRowNumbers ); + void setRecords( QMap<int, DicRecord*> aRecords ); + void removeRows( QList<int> aRowNumbers ); + void selectRows( QList<int> 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<int> 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<int, DicRecord*> 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<DicRecord*> 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<int, DicRecord*> m_records; // row number -> pointer to dic record. Sorted by key: rows +}; + +#endif // UNDOCOMMANDS_H |