From c2737cbd215866bc1a6b831a1b23e3a9ddbc441a Mon Sep 17 00:00:00 2001 From: cemycc Date: Wed, 13 Jul 2011 19:47:15 +0300 Subject: [PATCH] Changed: #1307 Added Undo Commands for edit, insertand delete items on table and for words extraction --- .../translation_manager/editor_worksheet.cpp | 44 ++++-- .../translation_manager/editor_worksheet.h | 130 ++++++++++++++++-- .../translation_manager/source_selection.cpp | 9 +- .../translation_manager/source_selection.h | 27 ++-- .../translation_manager_main_window.cpp | 23 +--- .../translation_manager_main_window.h | 9 +- 6 files changed, 179 insertions(+), 63 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 f34fdb430..5323ded1a 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 @@ -15,8 +15,6 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -#include "editor_worksheet.h" -#include // Qt includes #include #include @@ -24,8 +22,11 @@ #include #include +// Project includes +#include "editor_worksheet.h" #include "extract_bot_names.h" #include "translation_manager_constants.h" +#include using namespace std; @@ -206,12 +207,7 @@ void CEditorWorksheet::saveAs(QString filename) void CEditorWorksheet::insertRow() { int last_row = table_editor->rowCount(); - table_editor->setRowCount(last_row + 1); - for(int j = 0; j < table_editor->columnCount(); j++) - { - QTableWidgetItem* item = new QTableWidgetItem(); - table_editor->setItem(last_row, j, item); - } + current_stack->push(new CUndoWorksheetNewCommand(table_editor, last_row)); } void CEditorWorksheet::deleteRow() @@ -223,10 +219,9 @@ void CEditorWorksheet::deleteRow() msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); - if(ret == QMessageBox::Yes) { - table_editor->removeRow(selected_row); + current_stack->push(new CUndoWorksheetDeleteCommand(table_editor, selected_row)); } table_editor->clearFocus(); @@ -237,6 +232,7 @@ void CEditorWorksheet::deleteRow() void CEditorWorksheet::worksheetEditorCellEntered(QTableWidgetItem * item) { temp_content = item->text(); + current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content)); } void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) @@ -250,9 +246,12 @@ void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item) setWindowModified(true); } + void CEditorWorksheet::extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig) { bool modified = false; + QList new_items; + ExtractBotNames ebn; ebn.setRequiredSettings(filters, level_design_path); ebn.extractBotNamesFromPrimitives(ligoConfig); @@ -271,7 +270,7 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design QTableWidgetItem *bot_name_row = new QTableWidgetItem(); bot_name_row->setText(tr(it->first.c_str())); bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); + table_editor ->setItem(currentRow, 0, bot_name_row); QTableWidgetItem *translation_name_row = new QTableWidgetItem(); translation_name_row->setBackgroundColor(QColor("#F75D59")); translation_name_row->setText(tr(it->first.c_str())); @@ -281,6 +280,12 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design sheet_name_row->setBackgroundColor(QColor("#F75D59")); table_editor ->setItem(currentRow, 2, sheet_name_row); if(!modified) modified = true; + CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); + new_items.push_back(bot_name_row_s); + CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); + new_items.push_back(translation_name_row_s); + CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); + new_items.push_back(sheet_name_row_s); } } ebn.cleanSimpleNames(); @@ -310,10 +315,18 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design sheet_name_row->setBackgroundColor(QColor("#F75D59")); table_editor ->setItem(currentRow, 2, sheet_name_row); if(!modified) modified = true; + CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); + new_items.push_back(bot_name_row_s); + CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); + new_items.push_back(translation_name_row_s); + CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); + new_items.push_back(sheet_name_row_s); } } ebn.cleanGenericNames(); - } + } + + current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); if(modified) { setWindowModified(true); @@ -355,6 +368,7 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis return; } bool modified = false; + QList new_items; for(i = 0; i < allWords.size(); i++) { string keyName = allWords[i]; @@ -384,8 +398,14 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis name_row->setBackgroundColor(QColor("#F75D59")); table_editor ->setItem(currentRow, nPos, name_row); if(!modified) modified = true; + CTableWidgetItemStore key_name_row_s(key_name_row, currentRow, knPos); + new_items.push_back(key_name_row_s); + CTableWidgetItemStore name_row_s(name_row, currentRow, nPos); + new_items.push_back(name_row_s); + } } + current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); if(modified) { setWindowModified(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 2c8539922..983dba4bc 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 @@ -32,9 +32,9 @@ #include #include #include -#include - +#include +// Project includes #include "translation_manager_editor.h" #include "extract_new_sheet_names.h" @@ -70,29 +70,141 @@ private: }; +struct CTableWidgetItemStore +{ +public: + CTableWidgetItemStore(QTableWidgetItem *item, int row, int column) : + m_item(item), + m_row(row), + m_column(column) { } + QTableWidgetItem *m_item; + int m_row; + int m_column; +}; + class CUndoWorksheetCommand : public QUndoCommand { public: CUndoWorksheetCommand(QTableWidget *table, QTableWidgetItem* item, const QString &ocontent, QUndoCommand *parent = 0) : QUndoCommand("Insert characters in cells", parent), m_table(table), m_item(item), m_ocontent(ocontent) { - m_ccontent = m_item->text(); + m_ccontent = m_ocontent; } void redo() { - //m_item->setText(m_ccontent); + if(m_item->text() == m_ocontent) + { + m_item->setText(m_ccontent); + } } void undo() { - //m_item->setText(m_ocontent); - - } - + if(m_item->text() != m_ocontent) + { + m_ccontent = m_item->text(); + } + m_item->setText(m_ocontent); + } private: QTableWidget* m_table; QTableWidgetItem* m_item; - QString m_ccontent; QString m_ocontent; + QString m_ccontent; +}; + +class CUndoWorksheetNewCommand : public QUndoCommand +{ +public: + CUndoWorksheetNewCommand(QTableWidget *table, int rowID, QUndoCommand *parent = 0) : QUndoCommand("Insert a new row", parent), m_table(table), m_rowID(rowID) + { } + + void redo() + { + m_table->setRowCount(m_rowID + 1); + for(int j = 0; j < m_table->columnCount(); j++) + { + QTableWidgetItem* item = new QTableWidgetItem(); + m_table->setItem(m_rowID, j, item); + } + } + + void undo() + { + m_table->removeRow(m_rowID); + } +private: + QTableWidget* m_table; + int m_rowID; + +}; + +class CUndoWorksheetExtraction : public QUndoCommand +{ +public: + CUndoWorksheetExtraction(QList items, QTableWidget *table, QUndoCommand *parent = 0) : QUndoCommand("Word extraction", parent), + m_items(items), + m_table(table) + { } + + void redo() + { + Q_FOREACH(CTableWidgetItemStore is, m_items) + { + m_table->setItem(is.m_row, is.m_column, is.m_item); + } + + } + + void undo() + { + Q_FOREACH(CTableWidgetItemStore is, m_items) + { + m_table->setItem(is.m_row, is.m_column, is.m_item); + m_table->takeItem(is.m_row, is.m_column); + } + + } + +private: + QList m_items; + QTableWidget* m_table; +}; + +class CUndoWorksheetDeleteCommand : public QUndoCommand +{ +public: + CUndoWorksheetDeleteCommand(QTableWidget *table, int rowID, QUndoCommand *parent = 0) : QUndoCommand("Delete row", parent), m_table(table), m_rowID(rowID) + { } + + void redo() + { + for(int i = 0; i < m_table->columnCount(); i++) + { + QTableWidgetItem* item = new QTableWidgetItem(); + QTableWidgetItem* table_item = m_table->item(m_rowID, i); + item->setText(table_item->text()); + m_deletedItems.push_back(item); + } + m_table->removeRow(m_rowID); + } + + void undo() + { + int lastRow = m_table->rowCount(); + m_table->setRowCount(m_table->rowCount() + 1); + int i = 0; + Q_FOREACH(QTableWidgetItem* item, m_deletedItems) + { + m_table->setItem(lastRow, i, item); + i++; + } + m_deletedItems.clear(); + } + +private: + QList m_deletedItems; + QTableWidget* m_table; + int m_rowID; }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp index 6bc048b0b..cf38ed589 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.cpp @@ -10,12 +10,11 @@ namespace Plugin CSourceDialog::CSourceDialog(QWidget *parent): QDialog(parent) { _ui.setupUi(this); - // Set signal and slot for "OK Button" - + // Set signal and slot for "OK Button" connect(_ui.ok_button, SIGNAL(clicked()), this, SLOT(OkButtonClicked())); - // Set signal and slot for "Cancel Button" - connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject())); - _ui.listWidget->setSortingEnabled(false); + // Set signal and slot for "Cancel Button" + connect(_ui.cancel_button, SIGNAL(clicked()), this, SLOT(reject())); + _ui.listWidget->setSortingEnabled(false); } void CSourceDialog::setSourceOptions(map options) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h index 074ad5b86..f15a8778a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/source_selection.h @@ -14,22 +14,21 @@ using namespace std; namespace Plugin { - class CSourceDialog : public QDialog - { - Q_OBJECT - private: - Ui::SourceSelectionDialog _ui; - - private Q_SLOTS: - void OkButtonClicked(); - public: - CSourceDialog(QWidget *parent = 0); - ~CSourceDialog(){} - void setSourceOptions(map options); - QListWidgetItem *selected_item; +class CSourceDialog : public QDialog +{ + Q_OBJECT +private: + Ui::SourceSelectionDialog _ui; + QListWidgetItem *selected_item; +private Q_SLOTS: + void OkButtonClicked(); +public: + CSourceDialog(QWidget *parent = 0); + ~CSourceDialog(){} + void setSourceOptions(map options); +}; - }; } 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 20d7e57c1..bb4fa27d1 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 @@ -15,29 +15,20 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -#include "translation_manager_main_window.h" -#include "translation_manager_constants.h" -#include "ftp_selection.h" - // Project system includes #include "../core/icore.h" #include "../core/core_constants.h" #include "../core/imenu_manager.h" #include "../../extension_system/iplugin_spec.h" + // Qt includes #include #include -#include -#include #include #include #include #include #include -#include -#include -#include -#include #include #include #include @@ -46,6 +37,11 @@ #include #include +// Plugin includes +#include "translation_manager_main_window.h" +#include "translation_manager_constants.h" +#include "ftp_selection.h" + namespace Plugin { @@ -449,13 +445,6 @@ void CMainWindow::readSettings() settings->endGroup(); } -void CMainWindow::debug(QString text) -{ - QErrorMessage error_settings; - error_settings.showMessage(text); - error_settings.exec(); -} - bool CMainWindow::verifySettings() { bool count_errors = false; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h index ffb87b4b8..63a8934d7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.h @@ -19,7 +19,7 @@ #ifndef MAIN_WINDOW_H #define MAIN_WINDOW_H -// Project includes +// Project system includes #include "../core/icore_listener.h" // Nel includes @@ -33,14 +33,13 @@ #include #include #include -#include #include #include #include #include #include - +// Plugin includes #include "translation_manager_editor.h" #include "source_selection.h" #include "ui_translation_manager_main_window.h" @@ -62,8 +61,7 @@ public: CMainWindow(QWidget *parent = 0); virtual ~CMainWindow() {} QUndoStack *m_undoStack; -private: - +private: Ui::CMainWindow _ui; // actions QAction *openAct; @@ -90,7 +88,6 @@ private Q_SLOTS: void setActiveSubWindow(QWidget *window); void updateWindowsList(); void mergeSingleFile(); - void debug(QString text); // TODO private: void openWorkFile(QString file); void updateToolbar(QMdiSubWindow *window);