From c0ffa34363ff71d148d723e7566fc765529d1c22 Mon Sep 17 00:00:00 2001 From: sfb Date: Wed, 20 Jul 2011 12:54:30 -0500 Subject: [PATCH] Update: Completed settings page, loading and saving of settings and preferences (checked publish servers.) Changed namespace from 'Plugin' to 'MissionCompiler'. --- .../mission_compiler_main_window.cpp | 88 +++++++++++++++++-- .../mission_compiler_main_window.h | 4 +- .../mission_compiler_plugin.cpp | 4 +- .../mission_compiler_plugin.h | 4 +- .../mission_compiler_plugin_constants.h | 17 ++++ .../mission_compiler_settings_page.cpp | 74 ++++++++++------ .../mission_compiler_settings_page.h | 4 +- .../mission_compiler/server_entry_dialog.cpp | 4 +- .../mission_compiler/server_entry_dialog.h | 4 +- 9 files changed, 155 insertions(+), 48 deletions(-) create mode 100644 code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin_constants.h diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp index 9bab135d4..56cc791c7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.cpp @@ -2,6 +2,7 @@ #include "ui_mission_compiler_main_window.h" #include "validation_file.h" #include "mission_compiler.h" +#include "mission_compiler_plugin_constants.h" #include #include @@ -11,6 +12,8 @@ #include #include #include +#include +#include #include "../core/icore.h" #include "../core/imenu_manager.h" @@ -23,6 +26,8 @@ #include #include +using namespace MissionCompiler::Constants; + MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MissionCompilerMainWindow) @@ -70,6 +75,9 @@ MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) : connect(ui->filterEdit, SIGNAL(textEdited(const QString&)), this, SLOT(handleFilterChanged(const QString&))); connect(ui->resetFiltersButton, SIGNAL(clicked()), this, SLOT(handleResetFiltersButton())); + // Connect for settings changes. + connect(Core::ICore::instance(), SIGNAL(changeSettings()), this, SLOT(handleChangedSettings())); + // Set the default data dir to the primitives path. QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup(Core::Constants::DATA_PATH_SECTION); @@ -365,26 +373,88 @@ void MissionCompilerMainWindow::updateCompileLog() } void MissionCompilerMainWindow::loadConfig() { - QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup("MissionCompiler"); - - //QColor color; - //color = settings->value("BackgroundColor", QColor(80, 80, 80)).value(); - //m_nelWidget->setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue(), color.alpha())); + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(MISSION_COMPILER_SECTION); + + // Retrieve the local text path. + QString localPath = settings->value(SETTING_LOCAL_TEXT_PATH).toString(); + QListWidgetItem *item = new QListWidgetItem("Local"); + item->setForeground(Qt::blue); + item->setCheckState(Qt::Unchecked); + ui->publishServersList->addItem(item); + + QStringList items = settings->value(SETTING_SERVERS_TABLE_ITEMS).toStringList(); + int column = 0; + int row = 0; + Q_FOREACH(QString var, items) + { + // Check to see if we're starting a new row. + if(column > 2) + { + column = 0; + row++; + } + if(column == 0) + { + item = new QListWidgetItem(var); + item->setCheckState(Qt::Unchecked); + ui->publishServersList->addItem(item); + } + + column++; + } + + // Reapply the checkboxes for servers we had checked previously. + QStringList servers = settings->value(SETTING_PUBLISH_SERVER_CHECKS).toStringList(); + applyCheckboxes(servers); + + settings->endGroup(); } void MissionCompilerMainWindow::saveConfig() { QSettings *settings = Core::ICore::instance()->settings(); - settings->beginGroup("MissionCompiler" ); + settings->beginGroup(MISSION_COMPILER_SECTION); - //QColor color(m_nelWidget->backgroundColor().R, m_nelWidget->backgroundColor().G, m_nelWidget->backgroundColor().B, m_nelWidget->backgroundColor().A); - //settings->setValue("BackgroundColor", color); + QStringList servers; + for(int row = 0; row < ui->publishServersList->count(); row++) + { + QListWidgetItem *item = ui->publishServersList->item(row); + if(item->checkState() == Qt::Checked) + servers << item->text(); + } + + settings->setValue(SETTING_PUBLISH_SERVER_CHECKS, servers); settings->endGroup(); settings->sync(); } +void MissionCompilerMainWindow::handleChangedSettings() +{ + QStringList servers; + for(int row = 0; row < ui->publishServersList->count(); row++) + { + QListWidgetItem *item = ui->publishServersList->item(row); + if(item->checkState() == Qt::Checked) + servers << item->text(); + } + ui->publishServersList->clear(); + loadConfig(); + + applyCheckboxes(servers); +} + +void MissionCompilerMainWindow::applyCheckboxes(const QStringList &servers) +{ + Q_FOREACH(QString server, servers) + { + QList items = ui->publishServersList->findItems(server, Qt::MatchExactly); + items.at(0)->setCheckState(Qt::Checked); + } +} + MissionCompilerMainWindow::~MissionCompilerMainWindow() { + saveConfig(); delete ui; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.h index 7ea2e1f81..1451b2613 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_main_window.h @@ -47,6 +47,7 @@ public Q_SLOTS: void handleDataDirButton(); void handleDataDirChanged(const QString &text); void handleResetFiltersButton(); + void handleChangedSettings(); private: Ui::MissionCompilerMainWindow *ui; @@ -56,7 +57,8 @@ private: bool parsePrimForMissions(NLLIGO::IPrimitive const *prim, TMissionContainer &missions); void compileMission(bool publish=false); void moveSelectedItem(const QModelIndex &index, QStringListModel *from, QStringListModel *to); - + void applyCheckboxes(const QStringList &servers); + QMenu *_toolModeMenu; QUndoStack *m_undoStack; QStringListModel *m_allPrimitivesModel; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.cpp index d67128a50..3b9eb3ead 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.cpp @@ -19,7 +19,7 @@ #include "mission_compiler_settings_page.h" -namespace Plugin +namespace MissionCompiler { MissionCompilerPlugin::~MissionCompilerPlugin() @@ -128,4 +128,4 @@ ExtensionSystem::IPluginSpec *MissionCompilerPlugin::pluginByName(const QString } -Q_EXPORT_PLUGIN(Plugin::MissionCompilerPlugin) \ No newline at end of file +Q_EXPORT_PLUGIN(MissionCompiler::MissionCompilerPlugin) \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.h index 773c984ea..7f64465e7 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin.h @@ -24,7 +24,7 @@ namespace ExtensionSystem class IPluginSpec; } -namespace Plugin +namespace MissionCompiler { class MissionCompilerPlugin : public QObject, public ExtensionSystem::IPlugin @@ -96,6 +96,6 @@ public: MissionCompilerMainWindow *m_missionCompilerMainWindow; }; -} // namespace Plugin +} // namespace MissionCompiler #endif // MISSION_COMPILER_PLUGIN_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin_constants.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin_constants.h new file mode 100644 index 000000000..bfa71ceb1 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_plugin_constants.h @@ -0,0 +1,17 @@ +#ifndef MISSION_COMPILER_PLUGIN_CONSTANTS_H +#define MISSION_COMPILER_PLUGIN_CONSTANTS_H + +namespace MissionCompiler +{ +namespace Constants +{ +//settings +const char * const MISSION_COMPILER_SECTION = "MissionCompiler"; +const char * const SETTING_LOCAL_TEXT_PATH = "LocalTextPath"; +const char * const SETTING_SERVERS_TABLE_ITEMS = "ServersTableItems"; +const char * const SETTING_PUBLISH_SERVER_CHECKS = "PublishServerChecks"; + +} // namespace Constants +} // namespace MissionCompiler + +#endif // MISSION_COMPILER_PLUGIN_CONSTANTS_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.cpp index 028ac51db..2f75aa4ab 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.cpp @@ -17,6 +17,7 @@ // Project includes #include "mission_compiler_settings_page.h" +#include "mission_compiler_plugin_constants.h" #include "../core/core_constants.h" #include "../core/icore.h" @@ -31,7 +32,7 @@ #include #include -namespace Plugin +namespace MissionCompiler { QString lastDir = "."; @@ -149,37 +150,54 @@ void MissionCompilerSettingsPage::delServer() void MissionCompilerSettingsPage::readSettings() { - //QStringList paths; - //QSettings *settings = Core::ICore::instance()->settings(); - //settings->beginGroup(Core::Constants::DATA_PATH_SECTION); - //if (m_recurse) - // paths = settings->value(Core::Constants::RECURSIVE_SEARCH_PATHS).toStringList(); - //else - // paths = settings->value(Core::Constants::SEARCH_PATHS).toStringList(); - //settings->endGroup(); - //Q_FOREACH(QString path, paths) - //{ - // QListWidgetItem *newItem = new QListWidgetItem; - // newItem->setText(path); - // newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); - // m_ui.serversTreeWidget->addItem(newItem); - //} + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(Constants::MISSION_COMPILER_SECTION); + + // Retrieve the local text path. + m_ui.localPathEdit->setText(settings->value(Constants::SETTING_LOCAL_TEXT_PATH).toString()); + + QStringList items = settings->value(Constants::SETTING_SERVERS_TABLE_ITEMS).toStringList(); + int column = 0; + int row = 0; + m_ui.serversTableWidget->insertRow(row); + Q_FOREACH(QString var, items) + { + // Check to see if we're starting a new row. + if(column > 2) + { + column = 0; + row++; + m_ui.serversTableWidget->insertRow(row); + } + + QTableWidgetItem *item = new QTableWidgetItem(var); + m_ui.serversTableWidget->setItem(row, column, item); + + column++; + } + settings->endGroup(); } void MissionCompilerSettingsPage::writeSettings() { - //QStringList paths; - //for (int i = 0; i < m_ui.serversTreeWidget->count(); ++i) - // paths << m_ui.serversTreeWidget->item(i)->text(); + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup(Constants::MISSION_COMPILER_SECTION); + + // Save the local text path. + settings->setValue(Constants::SETTING_LOCAL_TEXT_PATH, m_ui.localPathEdit->text()); - //QSettings *settings = Core::ICore::instance()->settings(); - //settings->beginGroup(Core::Constants::DATA_PATH_SECTION); - //if (m_recurse) - // settings->setValue(Core::Constants::RECURSIVE_SEARCH_PATHS, paths); - //else - // settings->setValue(Core::Constants::SEARCH_PATHS, paths); - //settings->endGroup(); - //settings->sync(); + QStringList items; + for(int row = 0; row < m_ui.serversTableWidget->rowCount(); row++) + { + for(int column = 0; column < m_ui.serversTableWidget->columnCount(); column++) + { + items << m_ui.serversTableWidget->item(row, column)->text(); + } + } + + settings->setValue(Constants::SETTING_SERVERS_TABLE_ITEMS, items); + settings->endGroup(); + settings->sync(); } -} /* namespace Plugin */ \ No newline at end of file +} /* namespace MissionCompiler */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.h index 32b59e050..71996e442 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/mission_compiler_settings_page.h @@ -27,7 +27,7 @@ class QWidget; -namespace Plugin +namespace MissionCompiler { /** @class MissionCompilerSettingsPage @@ -63,6 +63,6 @@ private: Ui::MissionCompilerSettingsPage m_ui; }; -} // namespace Plugin +} // namespace MissionCompiler #endif // MISSION_COMPILER_SETTINGS_PAGE_H diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.cpp index b930eb5ec..a9ef08f50 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.cpp @@ -25,7 +25,7 @@ // Qt includes #include -namespace Plugin +namespace MissionCompiler { ServerEntryDialog::ServerEntryDialog(QWidget *parent) @@ -86,4 +86,4 @@ void ServerEntryDialog::lookupPrimPath() QString path = QFileDialog::getExistingDirectory(this, "", curPath); m_ui->serverPrimPathEdit->setText(path); } -} /* namespace Plugin */ \ No newline at end of file +} /* namespace MissionCompiler */ \ No newline at end of file diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.h index e2a1d5016..98a086cd0 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/mission_compiler/server_entry_dialog.h @@ -25,7 +25,7 @@ namespace Ui { class ServerEntryDialog; } -namespace Plugin +namespace MissionCompiler { /** @class ServerEntryDialog @@ -54,6 +54,6 @@ private: Ui::ServerEntryDialog *m_ui; }; -} // namespace Plugin +} // namespace MissionCompiler #endif // SERVER_ENTRY_DIALOG_H