#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