Changed: #1307 Minor fix on QMainWindow reported here: http://ryzomcore.etherpad.opennel.org/12

This commit is contained in:
cemycc 2011-07-13 01:43:42 +03:00
parent 5b234330aa
commit 6d9feeccac
6 changed files with 220 additions and 260 deletions

View file

@ -91,7 +91,7 @@ const char * const DATA_PATH_SECTION = "DataPath";
const char * const SEARCH_PATHS = "SearchPaths"; const char * const SEARCH_PATHS = "SearchPaths";
const char * const RECURSIVE_SEARCH_PATHS = "RecursiveSearchPathes"; const char * const RECURSIVE_SEARCH_PATHS = "RecursiveSearchPathes";
const char * const LEVELDESIGN_PATH = "LevelDesignPath"; const char * const LEVELDESIGN_PATH = "LevelDesignPath";
const char * const PRIMITIVES_PATH = "/home/cemycc/Ryzom/work/ryzom/code/ryzom/common/data_leveldesign/primitives"; const char * const PRIMITIVES_PATH = "D:/Ryzom/ryzom/code/ryzom/common/data_leveldesign/primitives";
const char * const ASSETS_PATH = "AssetsPath"; const char * const ASSETS_PATH = "AssetsPath";
const char * const REMAP_EXTENSIONS = "RemapExtensions"; const char * const REMAP_EXTENSIONS = "RemapExtensions";

View file

@ -243,8 +243,7 @@ void CEditorWorksheet::worksheetEditorChanged(QTableWidgetItem * item)
{ {
if(temp_content != item->text()) if(temp_content != item->text())
{ {
QString i_text = item->text(); current_stack->push(new CUndoWorksheetCommand(table_editor, item, temp_content));
current_stack->push(new CUndoWorksheetCommand(item, temp_content, i_text));
} }
if(!isWindowModified()) if(!isWindowModified())

View file

@ -73,23 +73,26 @@ private:
class CUndoWorksheetCommand : public QUndoCommand class CUndoWorksheetCommand : public QUndoCommand
{ {
public: public:
CUndoWorksheetCommand(QTableWidgetItem* item, const QString &ocontent, QString ccontent) : QUndoCommand("Insert characters in cells"), m_item(item), m_ocontent(ocontent), m_ccontent(ccontent) { } 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)
virtual void redo()
{ {
m_ccontent = m_item->text();
//m_ccontent = m_item->text();
m_item->setText(m_ccontent);
} }
virtual void undo()
void redo()
{
m_item->setText(m_ccontent);
}
void undo()
{ {
m_item->setText(m_ocontent); m_item->setText(m_ocontent);
} }
private: private:
QTableWidget* m_table;
QTableWidgetItem* m_item; QTableWidgetItem* m_item;
QString m_ocontent;
QString m_ccontent; QString m_ccontent;
QString m_ocontent;
}; };
} }

View file

@ -17,7 +17,6 @@
#include "translation_manager_main_window.h" #include "translation_manager_main_window.h"
#include "translation_manager_constants.h" #include "translation_manager_constants.h"
#include "editor_worksheet.h"
#include "ftp_selection.h" #include "ftp_selection.h"
// Project system includes // Project system includes
@ -63,11 +62,12 @@ CMainWindow::CMainWindow(QWidget *parent)
initialize_settings["georges"] = false; initialize_settings["georges"] = false;
initialize_settings["ligo"] = false; initialize_settings["ligo"] = false;
connect(Core::ICore::instance(), SIGNAL(changeSettings()), this, SLOT(readSettings()));
readSettings(); readSettings();
createToolbar(); 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() void CMainWindow::createToolbar()
@ -132,6 +132,18 @@ void CMainWindow::createToolbar()
updateWindowsList(); updateWindowsList();
_ui.toolBar->addAction(windowMenu->menuAction()); _ui.toolBar->addAction(windowMenu->menuAction());
connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList()));
// Undo, Redo actions
// -----------------------------
Core::ICore *core = Core::ICore::instance();
Core::IMenuManager *menuManager = core->menuManager();
QAction* undoAction = menuManager->action(Core::Constants::UNDO);
if (undoAction != 0)
_ui.toolBar->addAction(undoAction);
QAction* redoAction = menuManager->action(Core::Constants::REDO);
if (redoAction != 0)
_ui.toolBar->addAction(redoAction);
} }
void CMainWindow::updateToolbar(QMdiSubWindow *window) void CMainWindow::updateToolbar(QMdiSubWindow *window)
@ -159,7 +171,7 @@ void CMainWindow::setActiveSubWindow(QWidget* window)
void CMainWindow::activeSubWindowChanged() void CMainWindow::activeSubWindowChanged()
{ {
//TODO: nothing to be done here atm
} }
void CMainWindow::updateWindowsList() void CMainWindow::updateWindowsList()
@ -192,21 +204,12 @@ void CMainWindow::open()
QString file_name = QFileDialog::getOpenFileName(this); QString file_name = QFileDialog::getOpenFileName(this);
if(!file_name.isEmpty()) if(!file_name.isEmpty())
{ {
list<CEditor*> subWindows = convertSubWindowList(_ui.mdiArea->subWindowList()); CEditor *editor = getEditorByWindowFilePath(file_name);
list<CEditor*>::iterator it = subWindows.begin(); if(editor != NULL)
CEditor* current_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow());
for(; it != subWindows.end(); ++it)
{ {
QString sw_file = (*it)->subWindowFilePath(); editor->activateWindow();
if(file_name == sw_file)
{
if((*it) != current_window)
{
(*it)->activateWindow();
}
return; return;
} }
}
if(isWorksheetEditor(file_name)) if(isWorksheetEditor(file_name))
{ {
CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea); CEditorWorksheet *new_window = new CEditorWorksheet(_ui.mdiArea);
@ -220,7 +223,7 @@ void CMainWindow::open()
void CMainWindow::openWorkFile(QString file) void CMainWindow::openWorkFile(QString file)
{ {
QFileInfo* file_path = new QFileInfo(QString("%1/%2").arg(QString(work_path.c_str())).arg(file)); QFileInfo* file_path = new QFileInfo(QString("%1/%2").arg(work_path).arg(file));
if(file_path->exists()) if(file_path->exists())
{ {
if(isWorksheetEditor(file_path->filePath())) if(isWorksheetEditor(file_path->filePath()))
@ -273,8 +276,8 @@ void CMainWindow::initializeSettings(bool georges = false)
{ {
if(georges == true && initialize_settings["georges"] == false) if(georges == true && initialize_settings["georges"] == false)
{ {
CPath::addSearchPath(level_design_path + "/DFN", true, false); CPath::addSearchPath(level_design_path.toStdString() + "/DFN", true, false);
CPath::addSearchPath(level_design_path + "/Game_elem/Creature", true, false); CPath::addSearchPath(level_design_path.toStdString() + "/Game_elem/Creature", true, false);
initialize_settings["georges"] = true; initialize_settings["georges"] = true;
} }
@ -294,54 +297,21 @@ void CMainWindow::extractWords(QString typeq)
{ {
if(verifySettings() == true) if(verifySettings() == true)
{ {
CEditorWorksheet* current_window; CEditorWorksheet* editor_window = getEditorByWorksheetType(typeq);
if(_ui.mdiArea->subWindowList().size() > 0) if(editor_window != NULL)
{ {
CEditor* editor_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow()); editor_window->activateWindow();
if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor QString file_path = editor_window->windowFilePath();
{
current_window = qobject_cast<CEditorWorksheet*>(editor_window);
QString file_path = current_window->subWindowFilePath();
if(!current_window->isSheetTable(typeq))
{
list<CEditor*> subWindows = convertSubWindowList(_ui.mdiArea->subWindowList());
list<CEditor*>::iterator it = subWindows.begin();
bool finded = false;
for(; it != subWindows.end(); ++it)
{
current_window = qobject_cast<CEditorWorksheet*>((*it));
file_path = current_window->subWindowFilePath();
if(current_window->isSheetTable(typeq))
{
finded = true;
current_window->activateWindow();
}
}
if(!finded)
{
openWorkFile(typeq);
if(_ui.mdiArea->subWindowList().size() > 0)
{
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow());
QString file_path = current_window->windowFilePath();
} else {
return;
}
}
}
}
} else { } else {
openWorkFile(typeq); openWorkFile(typeq);
if(_ui.mdiArea->subWindowList().size() > 0) editor_window = getEditorByWorksheetType(typeq);
if(editor_window != NULL)
{ {
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow()); editor_window->activateWindow();
QString file_path = current_window->windowFilePath(); QString file_path = editor_window->windowFilePath();
} else { } else return;
return;
} }
}
QString column_name; QString column_name;
// Sheet extraction // Sheet extraction
CSheetWordListBuilder builderS; CSheetWordListBuilder builderS;
@ -351,26 +321,26 @@ void CMainWindow::extractWords(QString typeq)
if(typeq.toAscii() == Constants::WK_ITEM) { if(typeq.toAscii() == Constants::WK_ITEM) {
column_name = "item ID"; column_name = "item ID";
builderS.SheetExt = "sitem"; builderS.SheetExt = "sitem";
builderS.SheetPath = level_design_path + "/game_element/sitem"; builderS.SheetPath = level_design_path.append("/game_element/sitem").toStdString();
isSheet = true; isSheet = true;
} else if(typeq.toAscii() == Constants::WK_CREATURE) { } else if(typeq.toAscii() == Constants::WK_CREATURE) {
column_name = "creature ID"; column_name = "creature ID";
builderS.SheetExt = "creature"; builderS.SheetExt = "creature";
builderS.SheetPath = level_design_path + "/Game_elem/Creature/fauna"; builderS.SheetPath = level_design_path.append("/Game_elem/Creature/fauna").toStdString();
isSheet = true; isSheet = true;
} else if(typeq.toAscii() == Constants::WK_SBRICK) { } else if(typeq.toAscii() == Constants::WK_SBRICK) {
column_name = "sbrick ID"; column_name = "sbrick ID";
builderS.SheetExt = "sbrick"; builderS.SheetExt = "sbrick";
builderS.SheetPath = level_design_path + "/game_element/sbrick"; builderS.SheetPath = level_design_path.append("/game_element/sbrick").toStdString();
isSheet = true; isSheet = true;
} else if(typeq.toAscii() == Constants::WK_SPHRASE) { } else if(typeq.toAscii() == Constants::WK_SPHRASE) {
column_name = "sphrase ID"; column_name = "sphrase ID";
builderS.SheetExt = "sphrase"; builderS.SheetExt = "sphrase";
builderS.SheetPath = level_design_path + "/game_element/sphrase"; builderS.SheetPath = level_design_path.append("/game_element/sphrase").toStdString();
isSheet = true; isSheet = true;
} else if(typeq.toAscii() == Constants::WK_PLACE) { } else if(typeq.toAscii() == Constants::WK_PLACE) {
column_name = "placeId"; column_name = "placeId";
builderP.PrimPath = primitives_path; builderP.PrimPath = primitives_path.toStdString();
builderP.PrimFilter.push_back("region_*.primitive"); builderP.PrimFilter.push_back("region_*.primitive");
builderP.PrimFilter.push_back("indoors_*.primitive"); builderP.PrimFilter.push_back("indoors_*.primitive");
isSheet = false; isSheet = false;
@ -378,10 +348,10 @@ void CMainWindow::extractWords(QString typeq)
if(isSheet) if(isSheet)
{ {
current_window->extractWords(current_window->windowFilePath(), column_name, builderS); editor_window->extractWords(editor_window->windowFilePath(), column_name, builderS);
} else { } else {
initializeSettings(false); initializeSettings(false);
current_window->extractWords(current_window->windowFilePath(), column_name, builderP); editor_window->extractWords(editor_window->windowFilePath(), column_name, builderP);
} }
} }
@ -391,55 +361,22 @@ void CMainWindow::extractBotNames()
{ {
if(verifySettings() == true) if(verifySettings() == true)
{ {
CEditorWorksheet* current_window; CEditorWorksheet* editor_window = getEditorByWorksheetType(NULL);
if(_ui.mdiArea->subWindowList().size() > 0) if(editor_window != NULL)
{ {
CEditor* editor_window = qobject_cast<CEditor*>(_ui.mdiArea->currentSubWindow()); editor_window->activateWindow();
if(QString(editor_window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor QString file_path = editor_window->windowFilePath();
{
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(); ++it)
{
current_window = qobject_cast<CEditorWorksheet*>((*it));
file_path = current_window->subWindowFilePath();
if(current_window->isBotNamesTable())
{
finded = true;
current_window->activateWindow();
}
}
if(!finded)
{
openWorkFile(tr(Constants::WK_BOTNAMES));
if(_ui.mdiArea->subWindowList().size() > 0)
{
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow());
QString file_path = current_window->windowFilePath();
} else { } else {
return; openWorkFile(Constants::WK_BOTNAMES);
} editor_window = getEditorByWorksheetType(NULL);
} if(editor_window != NULL)
}
}
} else {
openWorkFile(tr(Constants::WK_BOTNAMES));
if(_ui.mdiArea->subWindowList().size() > 0)
{ {
current_window = qobject_cast<CEditorWorksheet*>(_ui.mdiArea->currentSubWindow()); editor_window->activateWindow();
QString file_path = current_window->windowFilePath(); QString file_path = editor_window->windowFilePath();
} else { } else return;
return;
}
} }
initializeSettings(true); initializeSettings(true);
current_window->extractBotNames(filters, level_design_path, ligoConfig); editor_window->extractBotNames(convertQStringList(filters), level_design_path.toStdString(), ligoConfig);
} }
} }
@ -498,15 +435,17 @@ void CMainWindow::mergeSingleFile()
void CMainWindow::readSettings() void CMainWindow::readSettings()
{ {
QSettings *settings = Core::ICore::instance()->settings(); QSettings *settings = Core::ICore::instance()->settings();
// translation manager settings
settings->beginGroup("translationmanager"); settings->beginGroup("translationmanager");
filters = convertQStringList(settings->value("filters").toStringList()); /* filters */ filters = settings->value("filters").toStringList();
languages = convertQStringList(settings->value("trlanguages").toStringList()); /* languages */ languages = settings->value("trlanguages").toStringList();
translation_path = settings->value("translation").toString().toStdString(); translation_path = settings->value("translation").toString();
work_path = settings->value("work").toString().toStdString(); work_path = settings->value("work").toString();
settings->endGroup(); settings->endGroup();
// core settings
settings->beginGroup(Core::Constants::DATA_PATH_SECTION); settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString().toStdString(); level_design_path = settings->value(Core::Constants::LEVELDESIGN_PATH).toString();
primitives_path = QString(Core::Constants::PRIMITIVES_PATH).toStdString(); primitives_path = QString(Core::Constants::PRIMITIVES_PATH); //TODO
settings->endGroup(); settings->endGroup();
} }
@ -521,10 +460,7 @@ bool CMainWindow::verifySettings()
{ {
bool count_errors = false; bool count_errors = false;
QSettings *settings = Core::ICore::instance()->settings(); if(level_design_path.isNull() || primitives_path.isNull() || work_path.isNull())
settings->beginGroup("translationmanager");
if(settings->value("filters").toList().count() == 0)
{ {
QErrorMessage error_settings; QErrorMessage error_settings;
error_settings.showMessage("Please write all the paths on the settings dialog."); error_settings.showMessage("Please write all the paths on the settings dialog.");
@ -532,12 +468,45 @@ bool CMainWindow::verifySettings()
count_errors = true; count_errors = true;
} }
settings->endGroup();
return !count_errors; return !count_errors;
} }
CEditor *CMainWindow::getEditorByWindowFilePath(const QString &fileName)
{
Q_FOREACH(QMdiSubWindow *subWindow, _ui.mdiArea->subWindowList())
{
CEditor *currentEditor = qobject_cast<CEditor *>(subWindow);
if(currentEditor->subWindowFilePath() == fileName)
return currentEditor;
}
return NULL;
}
CEditorWorksheet *CMainWindow::getEditorByWorksheetType(const QString &type = NULL)
{
Q_FOREACH(QMdiSubWindow *subWindow, _ui.mdiArea->subWindowList())
{
CEditor *currentEditor = qobject_cast<CEditor*>(subWindow);
if(QString(currentEditor->widget()->metaObject()->className()) == "QTableWidget")
{
CEditorWorksheet *editor = qobject_cast<CEditorWorksheet *>(currentEditor);
if(!type.isNull())
if(editor->isSheetTable(type))
{
return editor;
}
else
if(editor->isBotNamesTable())
{
return editor;
}
}
}
return NULL;
}
list<string> CMainWindow::convertQStringList(QStringList listq) list<string> CMainWindow::convertQStringList(QStringList listq)
{ {
std::list<std::string> stdlist; std::list<std::string> stdlist;
@ -550,20 +519,6 @@ list<string> CMainWindow::convertQStringList(QStringList listq)
return stdlist; 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) bool CMainWindow::isWorksheetEditor(QString filename)
{ {
STRING_MANAGER::TWorksheet wk_file; STRING_MANAGER::TWorksheet wk_file;

View file

@ -45,6 +45,7 @@
#include "source_selection.h" #include "source_selection.h"
#include "ui_translation_manager_main_window.h" #include "ui_translation_manager_main_window.h"
#include <set> #include <set>
#include "editor_worksheet.h"
class QWidget; class QWidget;
@ -72,12 +73,12 @@ private:
QSignalMapper *windowMapper; QSignalMapper *windowMapper;
// config // config
map<string,bool> initialize_settings; map<string,bool> initialize_settings;
list<string> filters; QList<QString> filters;
list<string> languages; QList<QString> languages;
string level_design_path; QString level_design_path;
string primitives_path; QString primitives_path;
string translation_path; QString translation_path;
string work_path; QString work_path;
NLLIGO::CLigoConfig ligoConfig; NLLIGO::CLigoConfig ligoConfig;
private Q_SLOTS: private Q_SLOTS:
void extractBotNames(); void extractBotNames();
@ -99,7 +100,9 @@ private:
void createToolbar(); void createToolbar();
void initializeSettings(bool georges); void initializeSettings(bool georges);
list<string> convertQStringList(QStringList listq); list<string> convertQStringList(QStringList listq);
list<CEditor*> convertSubWindowList(QList<QMdiSubWindow*> listq); CEditor* getEditorByWindowFilePath(const QString &fileName);
// Worksheet specific functions
CEditorWorksheet* getEditorByWorksheetType(const QString &type);
bool isWorksheetEditor(QString filename); bool isWorksheetEditor(QString filename);

View file

@ -46,17 +46,17 @@ QString CTranslationManagerSettingsPage::id() const
QString CTranslationManagerSettingsPage::trName() const QString CTranslationManagerSettingsPage::trName() const
{ {
return tr("Translation Manager page"); return tr("Translation Manager");
} }
QString CTranslationManagerSettingsPage::category() const QString CTranslationManagerSettingsPage::category() const
{ {
return QLatin1String("General"); return QLatin1String("Translation Manager");
} }
QString CTranslationManagerSettingsPage::trCategory() const QString CTranslationManagerSettingsPage::trCategory() const
{ {
return tr("General"); return tr("Translation Manager");
} }
QIcon CTranslationManagerSettingsPage::categoryIcon() const QIcon CTranslationManagerSettingsPage::categoryIcon() const