From 1bade68ee0065831a1f3d30021ee5e6ac55ec42c Mon Sep 17 00:00:00 2001 From: cemycc Date: Tue, 12 Jul 2011 22:02:05 +0300 Subject: [PATCH] Changed: #1307 Added implementation of undo/redo framework partial --- .../translation_manager/editor_worksheet.cpp | 17 ++++++++-- .../translation_manager/editor_worksheet.h | 33 +++++++++++++++++-- .../translation_manager_editor.h | 6 ++++ .../translation_manager_main_window.cpp | 7 ++-- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp index de20db5ec..5f38d29f1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -95,7 +95,8 @@ void CEditorWorksheet::open(QString filename) table_editor->resizeColumnsToContents(); table_editor->resizeRowsToContents(); // set editor signals - connect(table_editor, SIGNAL(cellChanged(int,int) ), this, SLOT(worksheetEditorChanged(int,int))); + connect(table_editor, SIGNAL(itemChanged(QTableWidgetItem*) ), this, SLOT(worksheetEditorChanged(QTableWidgetItem*))); + connect(table_editor, SIGNAL(itemDoubleClicked(QTableWidgetItem*) ), this, SLOT(worksheetEditorCellEntered(QTableWidgetItem*))); } else { QErrorMessage error; error.showMessage("This file is not a worksheet file."); @@ -233,8 +234,19 @@ void CEditorWorksheet::deleteRow() return; } -void CEditorWorksheet::worksheetEditorChanged(int row, int column) +void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item) { + temp_content = item->text(); +} + +void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) +{ + if(temp_content != item->text()) + { + QString i_text = item->text(); + current_stack->push(new CUndoWorksheetCommand(item, temp_content, i_text)); + } + if(!isWindowModified()) setWindowModified(true); } @@ -494,6 +506,7 @@ void CEditorWorksheet::closeEvent(QCloseEvent *event) } } + bool CEditorWorksheet::isBotNamesTable() { bool status = true; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h index 95ee140d1..3723a6b70 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h @@ -31,6 +31,9 @@ #include #include #include +#include +#include + #include "translation_manager_editor.h" #include "extract_new_sheet_names.h" @@ -40,11 +43,12 @@ namespace Plugin { class CEditorWorksheet : public CEditor { Q_OBJECT -private: - QTableWidget* table_editor; +private: + QString temp_content; public: CEditorWorksheet(QMdiArea* parent) : CEditor(parent) {} CEditorWorksheet() : CEditor() {} + QTableWidget* table_editor; void open(QString filename); void save(); void saveAs(QString filename); @@ -57,7 +61,8 @@ public: bool isSheetTable(QString type); void closeEvent(QCloseEvent *event); private Q_SLOTS: - void worksheetEditorChanged(int,int); + void worksheetEditorCellEntered(QTableWidgetItem * item); + void worksheetEditorChanged(QTableWidgetItem * item); void insertRow(); void deleteRow(); private: @@ -65,6 +70,28 @@ private: }; +class CUndoWorksheetCommand : public QUndoCommand +{ +public: + CUndoWorksheetCommand(QTableWidgetItem* item, const QString &ocontent, QString ccontent) : QUndoCommand("Insert characters in cells"), m_item(item), m_ocontent(ocontent), m_ccontent(ccontent) { } + + virtual void redo() + { + + //m_ccontent = m_item->text(); + m_item->setText(m_ccontent); + + } + virtual void undo() + { + m_item->setText(m_ocontent); + } +private: + QTableWidgetItem* m_item; + QString m_ocontent; + QString m_ccontent; }; + +} #endif /* EDITOR_WORKSHEET_H */ diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h index 7af2b061d..ff947b1d1 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h @@ -22,12 +22,14 @@ #include #include #include +#include namespace Plugin { class CEditor : public QMdiSubWindow { Q_OBJECT protected: + QUndoStack* current_stack; QString current_file; int editor_type; public: @@ -42,6 +44,10 @@ public: { return current_file; } + void setUndoStack(QUndoStack* stack) + { + current_stack = stack; + } }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp index 548aa4b37..6cf9c3f1d 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp @@ -65,7 +65,9 @@ CMainWindow::CMainWindow(QWidget *parent) initialize_settings["ligo"] = false; readSettings(); createToolbar(); - m_undoStack = new QUndoStack(this); + m_undoStack = new QUndoStack(this); + _ui.toolBar->addAction(m_undoStack->createUndoAction(this)); + _ui.toolBar->addAction(m_undoStack->createRedoAction(this)); } void CMainWindow::createToolbar() @@ -207,7 +209,8 @@ void CMainWindow::open() } if(isWorksheetEditor(file_name)) { - CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + new_window->setUndoStack(m_undoStack); new_window->open(file_name); new_window->activateWindow(); }