From cfc7d5e25070a491d27ff0eaa8da83188195ea8e Mon Sep 17 00:00:00 2001 From: cemycc Date: Fri, 1 Jul 2011 21:51:41 +0300 Subject: [PATCH] Changed: #1307 New structure for subwindows from QMdiArea --- .../translation_manager/CMakeLists.txt | 4 +- .../translation_manager/editor_worksheet.cpp | 353 +++++++++++++++++ .../translation_manager/editor_worksheet.h | 48 +++ .../translation_manager_editor.h | 35 ++ .../translation_manager_main_window.cpp | 371 +++++++----------- .../translation_manager_main_window.h | 52 ++- .../translation_manager_main_window.ui | 26 +- .../translation_manager_plugin.cpp | 2 +- 8 files changed, 606 insertions(+), 285 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt index ec3980f05..edc0a60e5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/CMakeLists.txt @@ -11,7 +11,9 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin. SET(OVQT_PLUG_TRANSLATION_MANAGER_HDR translation_manager_plugin.h translation_manager_main_window.h - translation_manager_settings_page.h) + translation_manager_settings_page.h + translation_manager_editor.h + editor_worksheet.h) SET(OVQT_PLUG_TRANSLATION_MANAGER_UIS translation_manager_settings_page.ui translation_manager_main_window.ui) 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 new file mode 100644 index 000000000..ee32e3979 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -0,0 +1,353 @@ +// Object Viewer Qt - MMORPG Framework +// Copyright (C) 2010 Winch Gate Property Limited +// Copyright (C) 2011 Dzmitry Kamiahin +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// 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 +#include +#include +#include + +using namespace std; + +struct TEntryInfo +{ + string SheetName; +}; + +set getGenericNames(); +void cleanGenericNames(); +map getSimpleNames(); +void cleanSimpleNames(); +void setPathsForPrimitives(map > config_paths, string ligo_class_file); +void extractBotNamesFromPrimitives(); +string cleanupName(const std::string &name); +ucstring cleanupUcName(const ucstring &name); + +namespace Plugin { + + + +void CEditorWorksheet::open(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + bool hasHashValue = false; + table_editor = new QTableWidget(); + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + table_editor->setColumnCount(wk_file.ColCount - 1); + hasHashValue = true; + } else { + table_editor->setColumnCount(wk_file.ColCount); + } + table_editor->setRowCount(wk_file.size() - 1); + + // read columns name + for(unsigned int i = 0; i < wk_file.ColCount; i++) + { + if(hasHashValue && i == 0) + { + // we don't show the column with hash value + } else { + QTableWidgetItem *col = new QTableWidgetItem(); + ucstring col_name = wk_file.getData(0, i); + col->setText(tr(col_name.toString().c_str())); + if(hasHashValue) + { + table_editor->setHorizontalHeaderItem(i - 1, col); + } else { + table_editor->setHorizontalHeaderItem(i, col); + } + } + } + + // read rows + for(unsigned int i = 1; i < wk_file.size(); i++) + { + for(unsigned int j = 0; j < wk_file.ColCount; j++) + { + if(hasHashValue && j == 0) + { + // we don't show the column with hash value + } else { + QTableWidgetItem *row = new QTableWidgetItem(); + ucstring row_value = wk_file.getData(i, j); + row->setText(tr(row_value.toString().c_str())); + if(hasHashValue) + { + table_editor->setItem(i - 1, j - 1, row); + } else { + table_editor->setItem(i - 1, j, row); + } + } + } + } + setCurrentFile(filename); + setAttribute(Qt::WA_DeleteOnClose); + setWidget(table_editor); + table_editor->resizeColumnsToContents(); + table_editor->resizeRowsToContents(); + // set editor signals + connect(table_editor, SIGNAL(cellChanged(int,int) ), this, SLOT(worksheetEditorChanged(int,int))); + } else { + QErrorMessage error; + error.showMessage("This file is not a worksheet file."); + error.exec(); + } + +} + +void CEditorWorksheet::activateWindow() +{ + showMaximized(); + +} + +void CEditorWorksheet::save() +{ + STRING_MANAGER::TWorksheet wk_file; + loadExcelSheet(current_file.toStdString(), wk_file, true); + uint rowIdx; + uint colIdx = 0; + bool hasHashValue = false; + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + hasHashValue = true; + colIdx = 1; + } + for(int i = 0; i < table_editor->rowCount(); i++) + { + // maybe extra rows ? + if((unsigned)table_editor->rowCount() > (wk_file.size() - 1)) + { + rowIdx = wk_file.size(); + wk_file.resize(rowIdx + table_editor->rowCount() - wk_file.size() + 1); + } + for(int j = 0; j < table_editor->columnCount(); j++) + { + ucstring tvalue; + ucstring colname; + uint rowIdf; + QString tvalueQt = table_editor->item(i, j)->text(); + tvalue = ucstring(tvalueQt.toStdString()); + colname = wk_file.getData(0, j + colIdx); + + rowIdf = uint(i + 1); + if(wk_file.findRow(j + colIdx, colname, rowIdf)) + { + if(wk_file.getData(i + 1, j + colIdx) != tvalue) + { + wk_file.setData(i + 1, j + colIdx, tvalue); + } + } else { + wk_file.setData(i + 1, j + colIdx, tvalue); + } + } + } + if(hasHashValue) + { + // rewrite the hash codes + makeHashCode(wk_file, true); + } + // write to file + ucstring s = prepareExcelSheet(wk_file); + NLMISC::CI18N::writeTextFile(current_file.toStdString(), s, false); + setCurrentFile(current_file); +} + +void CEditorWorksheet::saveAs(QString filename) +{ + STRING_MANAGER::TWorksheet new_file, wk_file; + loadExcelSheet(current_file.toStdString(), wk_file, true); + // set columns + new_file.resize(new_file.size() + 1); + for(unsigned int i = 0; i < wk_file.ColCount; i++) + { + ucstring col_name = wk_file.getData(0, i); + new_file.insertColumn(new_file.ColCount); + new_file.setData(0, new_file.ColCount - 1, col_name); + } + // read all the rows from table + uint rowIdx; + uint colIdx = 0; + bool hasHashValue = false; + if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) + { + hasHashValue = true; + colIdx = 1; + } + for(int i = 0; i < table_editor->rowCount(); i++) + { + rowIdx = new_file.size(); + new_file.resize(new_file.size() + 1); + for(int j = 0; j < table_editor->columnCount(); j++) + { + QTableWidgetItem* item = table_editor->item(i, j); + new_file.setData(rowIdx, j + colIdx, ucstring(item->text().toStdString())); + } + } + if(hasHashValue) + { + // rewrite the hash codes + makeHashCode(wk_file, true); + } + ucstring s = prepareExcelSheet(new_file); + NLMISC::CI18N::writeTextFile(filename.toStdString(), s, false); + setCurrentFile(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(); + //item->setText(QString(" ")); + table_editor->setItem(last_row, j, item); + } +} + +void CEditorWorksheet::deleteRow() +{ + int selected_row = table_editor->currentRow(); + QMessageBox msgBox; + msgBox.setText("The row will be deleted."); + msgBox.setInformativeText("Do you want to delete the selected row ?"); + msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); + msgBox.setDefaultButton(QMessageBox::No); + int ret = msgBox.exec(); + + if(ret == QMessageBox::Yes) + { + table_editor->removeRow(selected_row); + } + + table_editor->clearFocus(); + table_editor->clearSelection(); + return; +} + +void CEditorWorksheet::worksheetEditorChanged(int row, int column) +{ + +} + +void CEditorWorksheet::extractBotNames() +{ + bool modified = false; +// get SimpleNames + { + map SimpleNames = getSimpleNames(); + map::iterator it(SimpleNames.begin()), last(SimpleNames.end()); + + for (; it != last; ++it) + { + QList search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + 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); + QTableWidgetItem *translation_name_row = new QTableWidgetItem(); + translation_name_row->setBackgroundColor(QColor("#F75D59")); + translation_name_row->setText(tr(it->first.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(tr(it->second.SheetName.c_str())); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + if(!modified) modified = true; + } + } + cleanSimpleNames(); + } + // get GenericNames + { + set GenericNames = getGenericNames(); + set::iterator it(GenericNames.begin()), last(GenericNames.end()); + for (; it != last; ++it) + { + string gnName = "gn_" + cleanupName(*it); + QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); + if(search_results.size() == 0) + { + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + QTableWidgetItem *bot_name_row = new QTableWidgetItem(); + bot_name_row->setText(tr((*it).c_str())); + bot_name_row->setBackgroundColor(QColor("#F75D59")); + 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(gnName.c_str())); + table_editor ->setItem(currentRow , 1, translation_name_row); + QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); + sheet_name_row->setText(" "); + sheet_name_row->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, 2, sheet_name_row); + if(!modified) modified = true; + } + } + cleanGenericNames(); + } + if(modified) + { + setWindowModified(true); + } + +} + +void CEditorWorksheet::setCurrentFile(QString filename) +{ + QFileInfo *file = new QFileInfo(filename); + current_file = file->canonicalFilePath(); + setWindowModified(false); + setWindowTitle(file->fileName() + "[*]"); + setWindowFilePath(current_file); +} + +void CEditorWorksheet::closeEvent(QCloseEvent *event) +{ + close(); + event->accept(); + +} + +bool CEditorWorksheet::isBotNamesTable() +{ + bool status = true; + if(table_editor->horizontalHeaderItem(0)->text() != "bot name" + || table_editor->horizontalHeaderItem(1)->text() != "translated name" + || table_editor->horizontalHeaderItem(2)->text() != "sheet_name") + { + status = false; + } + + return status; +} + +} + + 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 new file mode 100644 index 000000000..71e86af84 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h @@ -0,0 +1,48 @@ + +#ifndef EDITOR_WORKSHEET_H +#define EDITOR_WORKSHEET_H + +// Nel includes +#include "nel/misc/types_nl.h" +#include "nel/misc/sheet_id.h" +#include "nel/misc/path.h" +#include "nel/misc/diff_tool.h" + +// Qt includes +#include +#include +#include +#include +#include + +#include "translation_manager_editor.h" + +namespace Plugin { + +class CEditorWorksheet : public CEditor +{ + Q_OBJECT +private: + QTableWidget* table_editor; +public: + CEditorWorksheet(QMdiArea* parent) : CEditor(parent) {} + CEditorWorksheet() : CEditor() {} + void open(QString filename); + void save(); + void saveAs(QString filename); + void activateWindow(); + void extractBotNames(); + bool isBotNamesTable(); + void closeEvent(QCloseEvent *event); +private Q_SLOTS: + void worksheetEditorChanged(int,int); + void insertRow(); + void deleteRow(); +private: + void setCurrentFile(QString filename); + +}; + +}; +#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 new file mode 100644 index 000000000..605d11d6e --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_editor.h @@ -0,0 +1,35 @@ + +#ifndef TRANSLATION_MANAGER_EDITOR_H +#define TRANSLATION_MANAGER_EDITOR_H + +#include +#include +#include +#include + +namespace Plugin { + +class CEditor : public QMdiSubWindow { +Q_OBJECT +protected: + QString current_file; + int editor_type; +public: + CEditor(QMdiArea* parent) : QMdiSubWindow(parent) {} + CEditor() : QMdiSubWindow() {} + virtual void open(QString filename) =0; + virtual void save() =0; + virtual void saveAs(QString filename) =0; + virtual void activateWindow() =0; +public: + QString subWindowFilePath() + { + return current_file; + } +}; + +} + + +#endif /* TRANSLATION_MANAGER_EDITOR_H */ + 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 946ed78fe..8b8c50a22 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 @@ -16,6 +16,8 @@ // along with this program. If not, see . #include "translation_manager_main_window.h" +#include "editor_worksheet.h" + // Project system includes #include "../core/icore.h" #include "../core/core_constants.h" @@ -40,6 +42,9 @@ #include #include #include +#include +#include + struct TEntryInfo @@ -63,9 +68,12 @@ CMainWindow::CMainWindow(QWidget *parent) : QMainWindow(parent) { _ui.setupUi(this); + _ui.mdiArea->closeAllSubWindows(); connect(_ui.mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)),this, SLOT(activeSubWindowChanged())); - + windowMapper = new QSignalMapper(this); + connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); + // set extraction scripts counters execution_count["extract_bot_names"] = 0; @@ -96,26 +104,52 @@ void CMainWindow::createToolbar() connect(extractBotNamesAct, SIGNAL(triggered()), this, SLOT(extractBotNames())); // Windows menu - windowMapper = new QSignalMapper(this); - connect(windowMapper, SIGNAL(mapped(QWidget*)), this, SLOT(setActiveSubWindow(QWidget*))); windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); - windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); + windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); + updateWindowsList(); _ui.toolBar->addAction(windowMenu->menuAction()); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); } +void CMainWindow::updateToolbar(QMdiSubWindow *window) +{ + if(_ui.mdiArea->subWindowList().size() > 0) + if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + { + QAction *insertRowAct = windowMenu->addAction("Insert new row"); + connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); + QAction *deleteRowAct = windowMenu->addAction("Delete row"); + connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); + + } +} + +void CMainWindow::setActiveSubWindow(QWidget* window) +{ + if (!window) + { + return; + } + QMdiSubWindow *cwindow = qobject_cast(window); + _ui.mdiArea->setActiveSubWindow(cwindow); +} + void CMainWindow::activeSubWindowChanged() { - updateWindowsList(); + } void CMainWindow::updateWindowsList() { - int i = 0; windowMenu->clear(); - QList windows = _ui.mdiArea->subWindowList(); - for (QList::iterator it = windows.begin(); it != windows.end(); ++it) { - QString window_file = QFileInfo((*it)->widget()->windowFilePath()).fileName(); + QMdiSubWindow *current_window = _ui.mdiArea->activeSubWindow(); + QList subWindows = _ui.mdiArea->subWindowList(); + + updateToolbar(current_window); + + for(int i = 0; i < subWindows.size(); ++i) + { + QString window_file = QFileInfo(subWindows.at(i)->windowFilePath()).fileName(); QString action_text; if (i < 9) { action_text = tr("&%1 %2").arg(i + 1).arg(window_file); @@ -124,149 +158,49 @@ void CMainWindow::updateWindowsList() } QAction *action = windowMenu->addAction(action_text); action->setCheckable(true); - action->setChecked((*it) == _ui.mdiArea->activeSubWindow()); - connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); - windowMapper->setMapping(action, windows.at(i)); - i++; + action->setChecked(subWindows.at(i) == current_window); + connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); + windowMapper->setMapping(action, subWindows.at(i)); } } void CMainWindow::open() { QString file_name = QFileDialog::getOpenFileName(this); - if (!file_name.isEmpty()) - { - STRING_MANAGER::TWorksheet wk_file; - if(loadExcelSheet(file_name.toStdString(), wk_file, true) == true) - { - bool hasHashValue = false; - QTableWidget *wk_table = new QTableWidget(); - wk_table->setToolTip(file_name); - wk_table->setWindowFilePath(file_name); - if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) - { - wk_table->setColumnCount(wk_file.ColCount - 1); - hasHashValue = true; - } else { - wk_table->setColumnCount(wk_file.ColCount); - } - wk_table->setRowCount(wk_file.size() - 1); - // read columns name - - for(unsigned int i = 0; i < wk_file.ColCount; i++) - { - if(hasHashValue && i == 0) - { - // we don't show the column with hash value - } else { - QTableWidgetItem *col = new QTableWidgetItem(); - ucstring col_name = wk_file.getData(0, i); - col->setText(tr(col_name.toString().c_str())); - if(hasHashValue) - { - wk_table->setHorizontalHeaderItem(i - 1, col); - } else { - wk_table->setHorizontalHeaderItem(i, col); - } - } - } - // read rows - - for(unsigned int i = 1; i < wk_file.size(); i++) - { - for(unsigned int j = 0; j < wk_file.ColCount; j++) - { - if(hasHashValue && j == 0) - { - // we don't show the column with hash value - } else { - QTableWidgetItem *row = new QTableWidgetItem(); - ucstring row_value = wk_file.getData(i, j); - row->setText(tr(row_value.toString().c_str())); - if(hasHashValue) - { - wk_table->setItem(i - 1, j - 1, row); - } else { - wk_table->setItem(i - 1, j, row); - } - } + if(!file_name.isEmpty()) + { + list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); + list::iterator it = subWindows.begin(); + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + for(; it != subWindows.end(); ++it) + { + QString sw_file = (*it)->subWindowFilePath(); + if(file_name == sw_file) + { + if((*it) != current_window) + { + (*it)->activateWindow(); } + return; } - - QMdiSubWindow *sub_window = new QMdiSubWindow(_ui.mdiArea); - sub_window->setWidget(wk_table); - wk_table->resizeColumnsToContents(); - wk_table->resizeRowsToContents(); - wk_table->showMaximized(); - sub_window->activateWindow(); - // set editor signals - connect(wk_table, SIGNAL(cellChanged(int,int) ), this, SLOT(sheetEditorChanged(int,int))); - updateWindowsList(); - } else { - QErrorMessage error_settings; - error_settings.showMessage("This file is not a worksheet file."); - error_settings.exec(); + } + if(isWorksheetEditor(file_name)) + { + CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); + new_window->open(file_name); + new_window->activateWindow(); } } } -void CMainWindow::sheetEditorChanged(int row, int column) -{ - saveAct->setEnabled(true); - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); - if(modifiedCells.find(current_window) != modifiedCells.end()) // founded - { - list cells = modifiedCells[current_window]; - bool overwriteResult = false; - for(list::iterator it = cells.begin(); it != cells.end(); ++it) - { - if((*it).row == row && (*it).col == column ) - overwriteResult = true; - } - if(overwriteResult == false) - { - CCelPos v; - v.row = row; - v.col = column; - cells.push_back(v); - } - } else { // not found - list cells; - CCelPos v; - v.row = row; - v.col = column; - cells.push_back(v); - modifiedCells[current_window] = cells; - } -} - void CMainWindow::save() { - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { - QWidget *subwindow_widget = current_window->widget(); - QTableWidget *table_editor = qobject_cast(subwindow_widget); - QString file_path = table_editor->windowFilePath(); - - if(modifiedCells.find(current_window) != modifiedCells.end()) - { - STRING_MANAGER::TWorksheet wk_file; - loadExcelSheet(file_path.toStdString(), wk_file, true); - list cells = modifiedCells[current_window]; - for(list::iterator it = cells.begin(); it != cells.end(); ++it) - { - QTableWidgetItem* edited_item = table_editor->item((*it).row, (*it).col); - wk_file.setData((*it).row + 1, (*it).col, ucstring(edited_item->text().toStdString())); - cells.erase(it); - } - ucstring s = prepareExcelSheet(wk_file); - NLMISC::CI18N::writeTextFile(file_path.toStdString(), s, false); - if(cells.size() == 0) - modifiedCells.erase(current_window); - } + current_window->save(); } } @@ -280,37 +214,10 @@ void CMainWindow::saveAs() if (!file_name.isEmpty()) { - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); - + CEditor* current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { - QWidget *subwindow_widget = current_window->widget(); - QTableWidget *table_editor = qobject_cast(subwindow_widget); - QString orig_file_path = table_editor->windowFilePath(); - STRING_MANAGER::TWorksheet new_file, wk_file; - loadExcelSheet(orig_file_path.toStdString(), wk_file, true); - // set columns - new_file.resize(new_file.size() + 1); - for(unsigned int i = 0; i < wk_file.ColCount; i++) - { - ucstring col_name = wk_file.getData(0, i); - new_file.insertColumn(new_file.ColCount); - new_file.setData(0, new_file.ColCount - 1, col_name); - } - // read all the rows from table - uint rowIdx; - for(int i = 0; i < table_editor->rowCount(); i++) - { - rowIdx = new_file.size(); - new_file.resize(new_file.size() + 1); - for(int j = 0; j < table_editor->columnCount(); j++) - { - QTableWidgetItem* item = table_editor->item(i, j); - new_file.setData(rowIdx, j, ucstring(item->text().toStdString())); - } - } - ucstring s = prepareExcelSheet(new_file); - NLMISC::CI18N::writeTextFile(file_name.toStdString(), s, false); + current_window->saveAs(file_name); } } @@ -320,72 +227,43 @@ void CMainWindow::extractBotNames() { if(verifySettings() == true) { - QMdiSubWindow *current_window = _ui.mdiArea->currentSubWindow(); - if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor + CEditor* editor_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { + CEditorWorksheet* current_window = qobject_cast(editor_window); + QString file_path = current_window->subWindowFilePath(); + if(!current_window->isBotNamesTable()) + { + list subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); + list::iterator it = subWindows.begin(); + bool finded = false; + for(; it != subWindows.end(), finded != true; ++it) + { + current_window = qobject_cast((*it)); + file_path = current_window->subWindowFilePath(); + if(current_window->isBotNamesTable()) + { + finded = true; + current_window->activateWindow(); + } + } + if(!finded) + { + open(); + current_window = qobject_cast(_ui.mdiArea->currentSubWindow()); + file_path = current_window->windowFilePath(); + } + } if(execution_count["extract_bot_names"] == 0) setPathsForPrimitives(config_paths, ligo_path); extractBotNamesFromPrimitives(); execution_count["extract_bot_names"] = execution_count["extract_bot_names"] + 1; - - QWidget *subwindow_widget = current_window->widget(); - QTableWidget *table_editor = qobject_cast(subwindow_widget); - // get SimpleNames - { - map SimpleNames = getSimpleNames(); - map::iterator it(SimpleNames.begin()), last(SimpleNames.end()); - - for (; it != last; ++it) - { - QList search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly); - if(search_results.size() == 0) - { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - 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); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(it->first.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(tr(it->second.SheetName.c_str())); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - } - } - cleanSimpleNames(); - } - // get GenericNames - { - set GenericNames = getGenericNames(); - set::iterator it(GenericNames.begin()), last(GenericNames.end()); - for (; it != last; ++it) - { - string gnName = "gn_" + cleanupName(*it); - QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); - if(search_results.size() == 0) - { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr((*it).c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - 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(gnName.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(" "); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - } - } - cleanGenericNames(); - } + + current_window->extractBotNames(); + // if(current_window->isWindowModified()) + // { + + // } } } @@ -413,6 +291,13 @@ 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; @@ -436,14 +321,7 @@ bool CMainWindow::verifySettings() return !count_errors; } - - void CMainWindow::setActiveSubWindow(QWidget *window) - { - if (!window) - return; - _ui.mdiArea->setActiveSubWindow(qobject_cast(window)); - } - + list CMainWindow::convertQStringList(QStringList listq) { std::list stdlist; @@ -456,9 +334,36 @@ list CMainWindow::convertQStringList(QStringList listq) return stdlist; } +list CMainWindow::convertSubWindowList(QList listq) +{ + list subwindows; + QList::iterator it = listq.begin(); + + for(; it != listq.end(); ++it) + { + CEditor* current_window = qobject_cast((*it)); + subwindows.push_back(current_window); + } + + return subwindows; +} + +bool CMainWindow::isWorksheetEditor(QString filename) +{ + STRING_MANAGER::TWorksheet wk_file; + if(loadExcelSheet(filename.toStdString(), wk_file, true) == true) + { + return true; + } else { + return false; + } +} + bool CCoreListener::closeMainWindow() const { return true; } -} /* namespace Plugin */ \ No newline at end of file +} /* namespace Plugin */ + + 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 4df21fa0b..13a3ead97 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 @@ -33,29 +33,31 @@ #include #include #include -#include +#include #include #include #include - +#include "translation_manager_editor.h" #include "ui_translation_manager_main_window.h" #include class QWidget; + using namespace std; namespace Plugin { - -struct CCelPos -{ - int col; - int row; -}; +class CMdiSubWindow; + +struct WStatus +{ + bool modified; +}; + class CMainWindow : public QMainWindow { Q_OBJECT @@ -64,9 +66,8 @@ public: virtual ~CMainWindow() {} QUndoStack *m_undoStack; private: - Ui::CMainWindow _ui; - - map > modifiedCells; + + Ui::CMainWindow _ui; // actions QAction *openAct; QAction *saveAct; @@ -86,17 +87,22 @@ private Q_SLOTS: void open(); void save(); void saveAs(); - void sheetEditorChanged(int, int); - void setActiveSubWindow(QWidget *window); void activeSubWindowChanged(); + void setActiveSubWindow(QWidget *window); + void updateWindowsList(); + + void debug(QString text); // TODO private: - void compareBotNames(); + void updateToolbar(QMdiSubWindow *window); bool verifySettings(); void readSettings(); void createMenus(); void createToolbar(); - void updateWindowsList(); + list convertQStringList(QStringList listq); + list convertSubWindowList(QList listq); + bool isWorksheetEditor(QString filename); + }; @@ -111,21 +117,9 @@ public: virtual bool closeMainWindow() const; }; -class CMdiSubWindow : public QMdiSubWindow -{ - private: - int window_type; - public: - int getWType() - { - return window_type; - } - void setWType(int nType) - { - window_type = nType; - } -}; } // namespace Plugin + + #endif // SIMPLE_VIEWER_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui index 395574415..71c139e0a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.ui @@ -16,27 +16,11 @@ - - - - 0 - 0 - - - - Qt::Horizontal - - - - true - - - - - - - - + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp index 91e7686d5..890c589e9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_plugin.cpp @@ -92,7 +92,7 @@ QStringList TranslationManagerPlugin::dependencies() const { QStringList list; list.append(Core::Constants::OVQT_CORE_PLUGIN); - list.append("ObjectViewer"); + //list.append("ObjectViewer"); return list; }