Changed: #1307 New structure for subwindows from QMdiArea

--HG--
branch : gsoc2011-translationovqt
hg/feature/gsoc2012-fabien
cemycc 14 years ago
parent f19ebefbe6
commit e55bbed5b4

@ -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)

@ -0,0 +1,353 @@
// Object Viewer Qt - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Dzmitry Kamiahin <dnk-88@tut.by>
//
// 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 <http://www.gnu.org/licenses/>.
#include "editor_worksheet.h"
#include <set>
// Qt includes
#include <QtGui/QErrorMessage>
#include <QtGui/QTableWidgetItem>
#include <QtCore/qfileinfo.h>
#include <QtGui/QMessageBox>
#include <QtGui/QCloseEvent>
using namespace std;
struct TEntryInfo
{
string SheetName;
};
set<string> getGenericNames();
void cleanGenericNames();
map<string, TEntryInfo> getSimpleNames();
void cleanSimpleNames();
void setPathsForPrimitives(map<string,list<string> > 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<string, TEntryInfo> SimpleNames = getSimpleNames();
map<string, TEntryInfo>::iterator it(SimpleNames.begin()), last(SimpleNames.end());
for (; it != last; ++it)
{
QList<QTableWidgetItem*> 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<string> GenericNames = getGenericNames();
set<string>::iterator it(GenericNames.begin()), last(GenericNames.end());
for (; it != last; ++it)
{
string gnName = "gn_" + cleanupName(*it);
QList<QTableWidgetItem*> 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;
}
}

@ -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 <QtCore/QObject>
#include <QtGui/QWidget>
#include <QtGui/QMdiArea>
#include <QtGui/QTableWidget>
#include <QtGui/QMdiSubWindow>
#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 */

@ -0,0 +1,35 @@
#ifndef TRANSLATION_MANAGER_EDITOR_H
#define TRANSLATION_MANAGER_EDITOR_H
#include <QtCore/QObject>
#include <QtGui/QWidget>
#include <QtGui/QMdiArea>
#include <QtGui/QMdiSubWindow>
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 */

@ -16,6 +16,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#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 <QtCore/QResource>
#include <QtGui/QMenuBar>
#include <QtCore/QFileInfo>
#include <QtCore/QEvent>
#include <QtGui/QCloseEvent>
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<QMdiSubWindow *>(window);
_ui.mdiArea->setActiveSubWindow(cwindow);
}
void CMainWindow::activeSubWindowChanged()
{
updateWindowsList();
}
void CMainWindow::updateWindowsList()
{
int i = 0;
windowMenu->clear();
QList<QMdiSubWindow *> windows = _ui.mdiArea->subWindowList();
for (QList<QMdiSubWindow*>::iterator it = windows.begin(); it != windows.end(); ++it) {
QString window_file = QFileInfo((*it)->widget()->windowFilePath()).fileName();
QMdiSubWindow *current_window = _ui.mdiArea->activeSubWindow();
QList<QMdiSubWindow*> 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<CEditor*> subWindows = convertSubWindowList(_ui.mdiArea->subWindowList());
list<CEditor*>::iterator it = subWindows.begin();
CEditor* current_window = qobject_cast<CEditor*>(_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<CCelPos> cells = modifiedCells[current_window];
bool overwriteResult = false;
for(list<CCelPos>::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<CCelPos> 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<CEditor*>(_ui.mdiArea->currentSubWindow());
if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
{
QWidget *subwindow_widget = current_window->widget();
QTableWidget *table_editor = qobject_cast<QTableWidget*>(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<CCelPos> cells = modifiedCells[current_window];
for(list<CCelPos>::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<CEditor*>(_ui.mdiArea->currentSubWindow());
if(QString(current_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
{
QWidget *subwindow_widget = current_window->widget();
QTableWidget *table_editor = qobject_cast<QTableWidget*>(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<CEditor*>(_ui.mdiArea->currentSubWindow());
if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
{
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<QTableWidget*>(subwindow_widget);
// get SimpleNames
{
map<string, TEntryInfo> SimpleNames = getSimpleNames();
map<string, TEntryInfo>::iterator it(SimpleNames.begin()), last(SimpleNames.end());
for (; it != last; ++it)
{
QList<QTableWidgetItem*> search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly);
if(search_results.size() == 0)
CEditorWorksheet* current_window = qobject_cast<CEditorWorksheet*>(editor_window);
QString file_path = current_window->subWindowFilePath();
if(!current_window->isBotNamesTable())
{
list<CEditor*> subWindows = convertSubWindowList(_ui.mdiArea->subWindowList());
list<CEditor*>::iterator it = subWindows.begin();
bool finded = false;
for(; it != subWindows.end(), finded != true; ++it)
{
current_window = qobject_cast<CEditorWorksheet*>((*it));
file_path = current_window->subWindowFilePath();
if(current_window->isBotNamesTable())
{
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);
finded = true;
current_window->activateWindow();
}
}
cleanSimpleNames();
}
// get GenericNames
{
set<string> GenericNames = getGenericNames();
set<string>::iterator it(GenericNames.begin()), last(GenericNames.end());
for (; it != last; ++it)
}
if(!finded)
{
string gnName = "gn_" + cleanupName(*it);
QList<QTableWidgetItem*> 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);
}
open();
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow());
file_path = current_window->windowFilePath();
}
cleanGenericNames();
}
if(execution_count["extract_bot_names"] == 0)
setPathsForPrimitives(config_paths, ligo_path);
extractBotNamesFromPrimitives();
execution_count["extract_bot_names"] = execution_count["extract_bot_names"] + 1;
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<QMdiSubWindow *>(window));
}
list<string> CMainWindow::convertQStringList(QStringList listq)
{
std::list<std::string> stdlist;
@ -456,9 +334,36 @@ list<string> CMainWindow::convertQStringList(QStringList listq)
return stdlist;
}
list<CEditor*> CMainWindow::convertSubWindowList(QList<QMdiSubWindow*> listq)
{
list<CEditor*> subwindows;
QList<QMdiSubWindow*>::iterator it = listq.begin();
for(; it != listq.end(); ++it)
{
CEditor* current_window = qobject_cast<CEditor*>((*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 */
} /* namespace Plugin */

@ -33,29 +33,31 @@
#include <QtGui/QUndoStack>
#include <QtGui/QMainWindow>
#include <QtGui/QGridLayout>
#include <QtGui/QTabWidget>
#include <QtGui/QTableWidget>
#include <QtGui/QMenu>
#include <QtGui/QMdiSubWindow>
#include <QtCore/QSignalMapper>
#include "translation_manager_editor.h"
#include "ui_translation_manager_main_window.h"
#include <set>
class QWidget;
using namespace std;
namespace Plugin
{
struct CCelPos
class CMdiSubWindow;
struct WStatus
{
int col;
int row;
bool modified;
};
class CMainWindow : public QMainWindow
{
Q_OBJECT
@ -64,9 +66,8 @@ public:
virtual ~CMainWindow() {}
QUndoStack *m_undoStack;
private:
Ui::CMainWindow _ui;
map<QMdiSubWindow*, list<CCelPos> > 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<string> convertQStringList(QStringList listq);
list<CEditor*> convertSubWindowList(QList<QMdiSubWindow*> 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

@ -16,27 +16,11 @@
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QMdiArea" name="mdiArea">
<property name="documentMode">
<bool>true</bool>
</property>
<widget class="QWidget" name="sheetEditor">
<property name="windowTitle">
<string/>
</property>
</widget>
</widget>
</widget>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QMdiArea" name="mdiArea"/>
</item>
</layout>
</item>
</layout>
</widget>

@ -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;
}

Loading…
Cancel
Save