Update: Completed settings page, loading and saving of settings and preferences (checked publish servers.) Changed namespace from 'Plugin' to 'MissionCompiler'.

This commit is contained in:
sfb 2011-07-20 12:54:30 -05:00
parent 446fcd44a1
commit c0ffa34363
9 changed files with 155 additions and 48 deletions

View file

@ -2,6 +2,7 @@
#include "ui_mission_compiler_main_window.h" #include "ui_mission_compiler_main_window.h"
#include "validation_file.h" #include "validation_file.h"
#include "mission_compiler.h" #include "mission_compiler.h"
#include "mission_compiler_plugin_constants.h"
#include <QMenu> #include <QMenu>
#include <QSignalMapper> #include <QSignalMapper>
@ -11,6 +12,8 @@
#include <QTextStream> #include <QTextStream>
#include <QFileDialog> #include <QFileDialog>
#include <QDirIterator> #include <QDirIterator>
#include <QTableWidget>
#include <QTableWidgetItem>
#include "../core/icore.h" #include "../core/icore.h"
#include "../core/imenu_manager.h" #include "../core/imenu_manager.h"
@ -23,6 +26,8 @@
#include <nel/ligo/primitive.h> #include <nel/ligo/primitive.h>
#include <nel/ligo/ligo_config.h> #include <nel/ligo/ligo_config.h>
using namespace MissionCompiler::Constants;
MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) : MissionCompilerMainWindow::MissionCompilerMainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MissionCompilerMainWindow) 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->filterEdit, SIGNAL(textEdited(const QString&)), this, SLOT(handleFilterChanged(const QString&)));
connect(ui->resetFiltersButton, SIGNAL(clicked()), this, SLOT(handleResetFiltersButton())); 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. // Set the default data dir to the primitives path.
QSettings *settings = Core::ICore::instance()->settings(); QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup(Core::Constants::DATA_PATH_SECTION); settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
@ -365,26 +373,88 @@ void MissionCompilerMainWindow::updateCompileLog()
} }
void MissionCompilerMainWindow::loadConfig() { void MissionCompilerMainWindow::loadConfig() {
QSettings *settings = Core::ICore::instance()->settings(); QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup("MissionCompiler"); settings->beginGroup(MISSION_COMPILER_SECTION);
//QColor color; // Retrieve the local text path.
//color = settings->value("BackgroundColor", QColor(80, 80, 80)).value<QColor>(); QString localPath = settings->value(SETTING_LOCAL_TEXT_PATH).toString();
//m_nelWidget->setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue(), color.alpha())); 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() { void MissionCompilerMainWindow::saveConfig() {
QSettings *settings = Core::ICore::instance()->settings(); 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); QStringList servers;
//settings->setValue("BackgroundColor", color); 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->endGroup();
settings->sync(); 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<QListWidgetItem*> items = ui->publishServersList->findItems(server, Qt::MatchExactly);
items.at(0)->setCheckState(Qt::Checked);
}
}
MissionCompilerMainWindow::~MissionCompilerMainWindow() MissionCompilerMainWindow::~MissionCompilerMainWindow()
{ {
saveConfig();
delete ui; delete ui;
} }

View file

@ -47,6 +47,7 @@ public Q_SLOTS:
void handleDataDirButton(); void handleDataDirButton();
void handleDataDirChanged(const QString &text); void handleDataDirChanged(const QString &text);
void handleResetFiltersButton(); void handleResetFiltersButton();
void handleChangedSettings();
private: private:
Ui::MissionCompilerMainWindow *ui; Ui::MissionCompilerMainWindow *ui;
@ -56,7 +57,8 @@ private:
bool parsePrimForMissions(NLLIGO::IPrimitive const *prim, TMissionContainer &missions); bool parsePrimForMissions(NLLIGO::IPrimitive const *prim, TMissionContainer &missions);
void compileMission(bool publish=false); void compileMission(bool publish=false);
void moveSelectedItem(const QModelIndex &index, QStringListModel *from, QStringListModel *to); void moveSelectedItem(const QModelIndex &index, QStringListModel *from, QStringListModel *to);
void applyCheckboxes(const QStringList &servers);
QMenu *_toolModeMenu; QMenu *_toolModeMenu;
QUndoStack *m_undoStack; QUndoStack *m_undoStack;
QStringListModel *m_allPrimitivesModel; QStringListModel *m_allPrimitivesModel;

View file

@ -19,7 +19,7 @@
#include "mission_compiler_settings_page.h" #include "mission_compiler_settings_page.h"
namespace Plugin namespace MissionCompiler
{ {
MissionCompilerPlugin::~MissionCompilerPlugin() MissionCompilerPlugin::~MissionCompilerPlugin()
@ -128,4 +128,4 @@ ExtensionSystem::IPluginSpec *MissionCompilerPlugin::pluginByName(const QString
} }
Q_EXPORT_PLUGIN(Plugin::MissionCompilerPlugin) Q_EXPORT_PLUGIN(MissionCompiler::MissionCompilerPlugin)

View file

@ -24,7 +24,7 @@ namespace ExtensionSystem
class IPluginSpec; class IPluginSpec;
} }
namespace Plugin namespace MissionCompiler
{ {
class MissionCompilerPlugin : public QObject, public ExtensionSystem::IPlugin class MissionCompilerPlugin : public QObject, public ExtensionSystem::IPlugin
@ -96,6 +96,6 @@ public:
MissionCompilerMainWindow *m_missionCompilerMainWindow; MissionCompilerMainWindow *m_missionCompilerMainWindow;
}; };
} // namespace Plugin } // namespace MissionCompiler
#endif // MISSION_COMPILER_PLUGIN_H #endif // MISSION_COMPILER_PLUGIN_H

View file

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

View file

@ -17,6 +17,7 @@
// Project includes // Project includes
#include "mission_compiler_settings_page.h" #include "mission_compiler_settings_page.h"
#include "mission_compiler_plugin_constants.h"
#include "../core/core_constants.h" #include "../core/core_constants.h"
#include "../core/icore.h" #include "../core/icore.h"
@ -31,7 +32,7 @@
#include <QtGui/QFileDialog> #include <QtGui/QFileDialog>
#include <QtGui/QTreeWidgetItem> #include <QtGui/QTreeWidgetItem>
namespace Plugin namespace MissionCompiler
{ {
QString lastDir = "."; QString lastDir = ".";
@ -149,37 +150,54 @@ void MissionCompilerSettingsPage::delServer()
void MissionCompilerSettingsPage::readSettings() void MissionCompilerSettingsPage::readSettings()
{ {
//QStringList paths; QSettings *settings = Core::ICore::instance()->settings();
//QSettings *settings = Core::ICore::instance()->settings(); settings->beginGroup(Constants::MISSION_COMPILER_SECTION);
//settings->beginGroup(Core::Constants::DATA_PATH_SECTION);
//if (m_recurse) // Retrieve the local text path.
// paths = settings->value(Core::Constants::RECURSIVE_SEARCH_PATHS).toStringList(); m_ui.localPathEdit->setText(settings->value(Constants::SETTING_LOCAL_TEXT_PATH).toString());
//else
// paths = settings->value(Core::Constants::SEARCH_PATHS).toStringList(); QStringList items = settings->value(Constants::SETTING_SERVERS_TABLE_ITEMS).toStringList();
//settings->endGroup(); int column = 0;
//Q_FOREACH(QString path, paths) int row = 0;
//{ m_ui.serversTableWidget->insertRow(row);
// QListWidgetItem *newItem = new QListWidgetItem; Q_FOREACH(QString var, items)
// newItem->setText(path); {
// newItem->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable); // Check to see if we're starting a new row.
// m_ui.serversTreeWidget->addItem(newItem); 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() void MissionCompilerSettingsPage::writeSettings()
{ {
//QStringList paths; QSettings *settings = Core::ICore::instance()->settings();
//for (int i = 0; i < m_ui.serversTreeWidget->count(); ++i) settings->beginGroup(Constants::MISSION_COMPILER_SECTION);
// paths << m_ui.serversTreeWidget->item(i)->text();
// Save the local text path.
settings->setValue(Constants::SETTING_LOCAL_TEXT_PATH, m_ui.localPathEdit->text());
//QSettings *settings = Core::ICore::instance()->settings(); QStringList items;
//settings->beginGroup(Core::Constants::DATA_PATH_SECTION); for(int row = 0; row < m_ui.serversTableWidget->rowCount(); row++)
//if (m_recurse) {
// settings->setValue(Core::Constants::RECURSIVE_SEARCH_PATHS, paths); for(int column = 0; column < m_ui.serversTableWidget->columnCount(); column++)
//else {
// settings->setValue(Core::Constants::SEARCH_PATHS, paths); items << m_ui.serversTableWidget->item(row, column)->text();
//settings->endGroup(); }
//settings->sync(); }
settings->setValue(Constants::SETTING_SERVERS_TABLE_ITEMS, items);
settings->endGroup();
settings->sync();
} }
} /* namespace Plugin */ } /* namespace MissionCompiler */

View file

@ -27,7 +27,7 @@
class QWidget; class QWidget;
namespace Plugin namespace MissionCompiler
{ {
/** /**
@class MissionCompilerSettingsPage @class MissionCompilerSettingsPage
@ -63,6 +63,6 @@ private:
Ui::MissionCompilerSettingsPage m_ui; Ui::MissionCompilerSettingsPage m_ui;
}; };
} // namespace Plugin } // namespace MissionCompiler
#endif // MISSION_COMPILER_SETTINGS_PAGE_H #endif // MISSION_COMPILER_SETTINGS_PAGE_H

View file

@ -25,7 +25,7 @@
// Qt includes // Qt includes
#include <QFileDialog> #include <QFileDialog>
namespace Plugin namespace MissionCompiler
{ {
ServerEntryDialog::ServerEntryDialog(QWidget *parent) ServerEntryDialog::ServerEntryDialog(QWidget *parent)
@ -86,4 +86,4 @@ void ServerEntryDialog::lookupPrimPath()
QString path = QFileDialog::getExistingDirectory(this, "", curPath); QString path = QFileDialog::getExistingDirectory(this, "", curPath);
m_ui->serverPrimPathEdit->setText(path); m_ui->serverPrimPathEdit->setText(path);
} }
} /* namespace Plugin */ } /* namespace MissionCompiler */

View file

@ -25,7 +25,7 @@ namespace Ui {
class ServerEntryDialog; class ServerEntryDialog;
} }
namespace Plugin namespace MissionCompiler
{ {
/** /**
@class ServerEntryDialog @class ServerEntryDialog
@ -54,6 +54,6 @@ private:
Ui::ServerEntryDialog *m_ui; Ui::ServerEntryDialog *m_ui;
}; };
} // namespace Plugin } // namespace MissionCompiler
#endif // SERVER_ENTRY_DIALOG_H #endif // SERVER_ENTRY_DIALOG_H