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

--HG--
branch : branch-mission-compiler-qt
This commit is contained in:
sfb 2011-07-20 12:54:30 -05:00
parent 63caf64438
commit a431e62539
9 changed files with 155 additions and 48 deletions

View file

@ -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 <QMenu>
#include <QSignalMapper>
@ -11,6 +12,8 @@
#include <QTextStream>
#include <QFileDialog>
#include <QDirIterator>
#include <QTableWidget>
#include <QTableWidgetItem>
#include "../core/icore.h"
#include "../core/imenu_manager.h"
@ -23,6 +26,8 @@
#include <nel/ligo/primitive.h>
#include <nel/ligo/ligo_config.h>
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);
@ -366,25 +374,87 @@ void MissionCompilerMainWindow::updateCompileLog()
void MissionCompilerMainWindow::loadConfig() {
QSettings *settings = Core::ICore::instance()->settings();
settings->beginGroup("MissionCompiler");
settings->beginGroup(MISSION_COMPILER_SECTION);
//QColor color;
//color = settings->value("BackgroundColor", QColor(80, 80, 80)).value<QColor>();
//m_nelWidget->setBackgroundColor(NLMISC::CRGBA(color.red(), color.green(), color.blue(), color.alpha()));
// 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<QListWidgetItem*> items = ui->publishServersList->findItems(server, Qt::MatchExactly);
items.at(0)->setCheckState(Qt::Checked);
}
}
MissionCompilerMainWindow::~MissionCompilerMainWindow()
{
saveConfig();
delete ui;
}

View file

@ -47,6 +47,7 @@ public Q_SLOTS:
void handleDataDirButton();
void handleDataDirChanged(const QString &text);
void handleResetFiltersButton();
void handleChangedSettings();
private:
Ui::MissionCompilerMainWindow *ui;
@ -56,6 +57,7 @@ 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;

View file

@ -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)
Q_EXPORT_PLUGIN(MissionCompiler::MissionCompilerPlugin)

View file

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

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
#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 <QtGui/QFileDialog>
#include <QtGui/QTreeWidgetItem>
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);
//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();
// Save the local text path.
settings->setValue(Constants::SETTING_LOCAL_TEXT_PATH, m_ui.localPathEdit->text());
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 */
} /* namespace MissionCompiler */

View file

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

View file

@ -25,7 +25,7 @@
// Qt includes
#include <QFileDialog>
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 */
} /* namespace MissionCompiler */

View file

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