Changed: #1150 added progress dialog to show CPath progress and changed config behaviour

This commit is contained in:
aquiles 2010-11-21 17:40:58 +01:00
parent 7ca0e7e4cc
commit 2d590ee7cc
10 changed files with 109 additions and 507 deletions

View file

@ -3,7 +3,7 @@ INCLUDE( ${QT_USE_FILE} )
FILE(GLOB GEORGES_EDITOR_SRC *.cpp *.h)
SET(GEORGES_EDITOR_HDR georges_dirtree_dialog.h georges_treeview_dialog.h main_window.h
objectviewer_dialog.h settings_dialog.h)
objectviewer_dialog.h settings_dialog.h progress_dialog.h)
SET(GEORGES_EDITOR_UIS settings_form.ui objectviewer_form.ui log_form.ui georges_treeview_form.ui georges_dirtree_form.ui)
SET(GEORGES_EDITOR_RCS georges_editor_qt.qrc)

View file

@ -1,27 +0,0 @@
/*
* Copyright (C) 2010 by authors
*
* This file is part of NEL QT.
* NEL QT is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* NEL QT 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NEL QT; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <nel/misc/types_nl.h>
#include "callback.h"
namespace NLQT {
} /* namespace NLQT */
/* end of file */

View file

@ -1,326 +0,0 @@
/*
* Copyright (C) 2010 by authors
*
* This file is part of NEL QT.
* NEL QT is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* NEL QT 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
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NEL QT; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*/
#ifndef NLQT_CALLBACK_H
#define NLQT_CALLBACK_H
#include <nel/misc/types_nl.h>
// STL includes
// NeL includes
#ifdef NL_COMP_GCC
// temporary fix for GCC 4.4 segmentation fault
# undef nlassert
# define nlassert(x)
#else
# include <nel/misc/debug.h>
#endif // NL_COMP_GCC
// Project includes
namespace NLQT {
#define NLQT_CALLBACK_TEMPLATE \
/** \
* \brief NLQT_CALLBACK_ARGS_CLASS \
* \date 2009-03-03 18:09GMT \
* \author Jan Boon (Kaetemi) \
* Awesome callback template \
*/ \
template<typename TReturn NLQT_CALLBACK_ARGS_TYPENAME> \
class NLQT_CALLBACK_ARGS_CLASS \
{ \
/* Very simple reference counting callback base */ \
class CCallbackBase \
{ \
public: \
CCallbackBase() : m_RefCount(0) \
{ \
\
} \
\
virtual ~CCallbackBase() \
{ \
nlassert(!m_RefCount); \
} \
\
void refAdd() \
{ \
++m_RefCount; \
} \
\
void refRemove() \
{ \
--m_RefCount; \
if (!m_RefCount) \
delete this; \
} \
\
virtual TReturn callback(NLQT_CALLBACK_ARGS_DECL) = 0; \
\
virtual bool equals(const CCallbackBase *callbackBase) = 0; \
\
/* disable copy */ \
CCallbackBase(const CCallbackBase &); \
CCallbackBase &operator=(const CCallbackBase &); \
\
private: \
uint m_RefCount; \
}; \
\
typedef TReturn TCallbackFunction(NLQT_CALLBACK_ARGS_DECL); \
class CCallbackFunction : public CCallbackBase \
{ \
public: \
CCallbackFunction(TCallbackFunction *callbackFunction) : m_CallbackFunction(callbackFunction) \
{ \
nlassert(m_CallbackFunction); \
} \
\
virtual ~CCallbackFunction() \
{ \
m_CallbackFunction = NULL; \
} \
\
virtual TReturn callback(NLQT_CALLBACK_ARGS_DECL) \
{ \
return m_CallbackFunction(NLQT_CALLBACK_ARGS_IMPL); \
} \
\
virtual bool equals(const CCallbackBase *callbackBase) \
{ \
const CCallbackFunction *callbackFunction = \
dynamic_cast<const CCallbackFunction *>(callbackBase); \
if (!callbackFunction) return false; \
return m_CallbackFunction == callbackFunction->m_CallbackFunction; \
} \
\
private: \
TCallbackFunction *m_CallbackFunction; \
}; \
\
template<typename TClass> \
class CCallbackMethod : public CCallbackBase \
{ \
typedef TReturn (TClass::*TCallbackMethod)(NLQT_CALLBACK_ARGS_DECL); \
public: \
CCallbackMethod(TClass *callbackObject, TCallbackMethod callbackMethod) : m_CallbackObject(callbackObject), m_CallbackMethod(callbackMethod) \
{ \
nlassert(m_CallbackObject); \
nlassert(m_CallbackMethod); \
} \
\
virtual ~CCallbackMethod() \
{ \
m_CallbackObject = NULL; \
m_CallbackMethod = NULL; \
} \
\
virtual TReturn callback(NLQT_CALLBACK_ARGS_DECL) \
{ \
return (m_CallbackObject->*m_CallbackMethod)(NLQT_CALLBACK_ARGS_IMPL); \
} \
\
virtual bool equals(const CCallbackBase *callbackBase) \
{ \
const CCallbackMethod *callbackMethod = \
dynamic_cast<const CCallbackMethod *>(callbackBase); \
if (!callbackMethod) return false; \
return m_CallbackObject == callbackMethod->m_CallbackObject \
&& m_CallbackMethod == callbackMethod->m_CallbackMethod; \
} \
\
private: \
TClass *m_CallbackObject; \
TCallbackMethod m_CallbackMethod; \
}; \
\
public: \
CCallback() : m_CallbackBase(NULL) \
{ \
\
} \
\
CCallback(TCallbackFunction *callbackFunction) : m_CallbackBase(new CCallbackFunction(callbackFunction)) \
{ \
nlassert(m_CallbackBase); \
m_CallbackBase->refAdd(); \
} \
\
template<typename TClass> \
CCallback(TClass *callbackObject, TReturn (TClass::*callbackMethod)(NLQT_CALLBACK_ARGS_DECL)) : m_CallbackBase(new CCallbackMethod<TClass>(callbackObject, callbackMethod)) \
{ \
nlassert(m_CallbackBase); \
m_CallbackBase->refAdd(); \
} \
\
CCallback(const CCallback &callback) \
{ \
m_CallbackBase = callback.m_CallbackBase; \
if (m_CallbackBase) \
m_CallbackBase->refAdd(); \
} \
\
CCallback &operator=(const CCallback &callback) \
{ \
if (m_CallbackBase != callback.m_CallbackBase) \
{ \
if (m_CallbackBase) \
m_CallbackBase->refRemove(); \
m_CallbackBase = callback.m_CallbackBase; \
if (m_CallbackBase) \
m_CallbackBase->refAdd(); \
} \
return *this; \
} \
\
~CCallback() \
{ \
if (m_CallbackBase) \
{ \
m_CallbackBase->refRemove(); \
m_CallbackBase = NULL; \
} \
} \
\
TReturn callback(NLQT_CALLBACK_ARGS_DECL) \
{ \
nlassert(m_CallbackBase); \
return m_CallbackBase->callback(NLQT_CALLBACK_ARGS_IMPL); \
} \
\
TReturn operator()(NLQT_CALLBACK_ARGS_DECL) \
{ \
nlassert(m_CallbackBase); \
return m_CallbackBase->callback(NLQT_CALLBACK_ARGS_IMPL); \
} \
\
bool valid() const \
{ \
return m_CallbackBase != NULL; \
} \
\
operator bool() const \
{ \
return m_CallbackBase != NULL; \
} \
\
bool operator==(const CCallback &callback) \
{ \
return m_CallbackBase->equals(callback.m_CallbackBase); \
} \
\
private: \
CCallbackBase *m_CallbackBase; \
\
}; /* class CCallback */ \
template<typename TReturn, typename TArgsA = void, typename TArgsB = void, typename TArgsC = void, typename TArgsD = void, typename TArgsE = void, typename TArgsF = void, typename TArgsG = void, typename TDummy = void>
class CCallback;
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, void, void, void, void, void, void, void, void>
#define NLQT_CALLBACK_ARGS_TYPENAME
#define NLQT_CALLBACK_ARGS_DECL
#define NLQT_CALLBACK_ARGS_IMPL
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, TArgsA, void, void, void, void, void, void, void>
#define NLQT_CALLBACK_ARGS_TYPENAME , typename TArgsA
#define NLQT_CALLBACK_ARGS_DECL TArgsA argsA
#define NLQT_CALLBACK_ARGS_IMPL argsA
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, TArgsA, TArgsB, void, void, void, void, void, void>
#define NLQT_CALLBACK_ARGS_TYPENAME , typename TArgsA, typename TArgsB
#define NLQT_CALLBACK_ARGS_DECL TArgsA argsA, TArgsB argsB
#define NLQT_CALLBACK_ARGS_IMPL argsA, argsB
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, TArgsA, TArgsB, TArgsC, void, void, void, void, void>
#define NLQT_CALLBACK_ARGS_TYPENAME , typename TArgsA, typename TArgsB, typename TArgsC
#define NLQT_CALLBACK_ARGS_DECL TArgsA argsA, TArgsB argsB, TArgsC argsC
#define NLQT_CALLBACK_ARGS_IMPL argsA, argsB, argsC
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, TArgsA, TArgsB, TArgsC, TArgsD, void, void, void, void>
#define NLQT_CALLBACK_ARGS_TYPENAME , typename TArgsA, typename TArgsB, typename TArgsC, typename TArgsD
#define NLQT_CALLBACK_ARGS_DECL TArgsA argsA, TArgsB argsB, TArgsC argsC, TArgsD argsD
#define NLQT_CALLBACK_ARGS_IMPL argsA, argsB, argsC, argsD
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, TArgsA, TArgsB, TArgsC, TArgsD, TArgsE, void, void, void>
#define NLQT_CALLBACK_ARGS_TYPENAME , typename TArgsA, typename TArgsB, typename TArgsC, typename TArgsD, typename TArgsE
#define NLQT_CALLBACK_ARGS_DECL TArgsA argsA, TArgsB argsB, TArgsC argsC, TArgsD argsD, TArgsE argsE
#define NLQT_CALLBACK_ARGS_IMPL argsA, argsB, argsC, argsD, argsE
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, TArgsA, TArgsB, TArgsC, TArgsD, TArgsE, TArgsF, void, void>
#define NLQT_CALLBACK_ARGS_TYPENAME , typename TArgsA, typename TArgsB, typename TArgsC, typename TArgsD, typename TArgsE, typename TArgsF
#define NLQT_CALLBACK_ARGS_DECL TArgsA argsA, TArgsB argsB, TArgsC argsC, TArgsD argsD, TArgsE argsE, TArgsF argsF
#define NLQT_CALLBACK_ARGS_IMPL argsA, argsB, argsC, argsD, argsE, argsF
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#define NLQT_CALLBACK_ARGS_CLASS CCallback<TReturn, TArgsA, TArgsB, TArgsC, TArgsD, TArgsE, TArgsF, TArgsG, void>
#define NLQT_CALLBACK_ARGS_TYPENAME , typename TArgsA, typename TArgsB, typename TArgsC, typename TArgsD, typename TArgsE, typename TArgsF, typename TArgsG
#define NLQT_CALLBACK_ARGS_DECL TArgsA argsA, TArgsB argsB, TArgsC argsC, TArgsD argsD, TArgsE argsE, TArgsF argsF, TArgsG argsG
#define NLQT_CALLBACK_ARGS_IMPL argsA, argsB, argsC, argsD, argsE, argsF, argsG
NLQT_CALLBACK_TEMPLATE
#undef NLQT_CALLBACK_ARGS_CLASS
#undef NLQT_CALLBACK_ARGS_TYPENAME
#undef NLQT_CALLBACK_ARGS_DECL
#undef NLQT_CALLBACK_ARGS_IMPL
#undef NLQT_CALLBACK_ARGS_CLASSNAME
#undef NLQT_CALLBACK_TEMPLATE
typedef CCallback<void> CEmptyCallback;
} /* namespace NLQT */
#endif /* #ifndef NLQT_CALLBACK_H */
/* end of file */

View file

@ -30,9 +30,9 @@
#include <nel/misc/config_file.h>
#include <nel/misc/path.h>
// Project includes
#include "modules.h"
#include <QFile>
#include "progress_dialog.h"
using namespace std;
using namespace NLMISC;
@ -51,9 +51,6 @@ CConfiguration::~CConfiguration()
void CConfiguration::init()
{
// verify data
nlassert(!ConfigCallbacks.size());
// load config
QFile file(NLQT_CONFIG_FILE);
if (!file.exists()) {
@ -62,8 +59,8 @@ void CConfiguration::init()
file.write("\nSearchPaths = {\"\"};");
file.write("\nRemapExtensions = { \"png\", \"tga\" };");
file.write("\nBackgroundColor = { 0, 0, 0 };");
file.write("\nQtStyle = \"\";");
file.write("\nQtPalette = \"\";");
//file.write("\nQtStyle = \"\";");
//file.write("\nQtPalette = \"\";");
file.close();
}
@ -72,14 +69,14 @@ void CConfiguration::init()
} catch(...) {
}
// setup config file callback
Modules::config().setAndCallback("SearchPaths", CConfigCallback(this, &CConfiguration::cfcbSearchPaths));
addLeveldesignPath();
addSearchPaths();
configRemapExtensions();
}
void CConfiguration::release()
{
Modules::config().dropCallback("SearchPaths");
//Modules::config().dropCallback("SearchPaths");
// save and release the config file
if (ConfigFile.exists("SaveConfig") && ConfigFile.getVarPtr("SaveConfig")->asBool())
@ -90,9 +87,6 @@ void CConfiguration::release()
// release the search paths etc
CPath::releaseInstance();
// verify data
nlassert(!ConfigCallbacks.size());
}
void CConfiguration::updateUtilities()
@ -101,17 +95,11 @@ void CConfiguration::updateUtilities()
CConfigFile::checkConfigFiles();
}
void CConfiguration::configSearchPaths()
void CConfiguration::addLeveldesignPath()
{
cfcbSearchPaths(Modules::config().getConfigFile().getVar("SearchPaths"));
}
std::string CConfiguration::configLeveldesignPath()
{
std::string path = Modules::config().getValue("LeveldesignPath", QString("").toStdString());
cfcbSearchPaths(Modules::config().getConfigFile().getVar("LeveldesignPath"));
return path;
std::vector<std::string> list;
list.push_back(Modules::config().getValue("LeveldesignPath", QString("").toStdString()));
addSearchPaths(&list);
}
void CConfiguration::configRemapExtensions()
@ -123,25 +111,6 @@ void CConfiguration::configRemapExtensions()
CPath::remapExtension(var->asString(i), var->asString(i + 1), true);
}
void CConfiguration::setAndCallback(const std::string &varName, CConfigCallback configCallback)
{
ConfigCallbacks[varName] = configCallback;
ConfigFile.setCallback(varName, cbConfigCallback);
configCallback(*ConfigFile.getVarPtr(varName));
}
void CConfiguration::setCallback(const std::string &varName, CConfigCallback configCallback)
{
ConfigCallbacks[varName] = configCallback;
ConfigFile.setCallback(varName, cbConfigCallback);
}
void CConfiguration::dropCallback(const std::string &varName)
{
ConfigFile.setCallback(varName, NULL);
ConfigCallbacks.erase(varName);
}
float CConfiguration::getValue(const string &varName, float defaultValue)
{
if (ConfigFile.exists(varName)) return ConfigFile.getVar(varName).asFloat();
@ -226,17 +195,31 @@ CRGBA CConfiguration::getValue(const CConfigFile::CVar &var, const CRGBA &defaul
return defaultValue;
}
void CConfiguration::cbConfigCallback(NLMISC::CConfigFile::CVar &var)
void CConfiguration::addSearchPaths(std::vector<std::string>* list)
{
Modules::config().ConfigCallbacks[var.Name](var);
}
//Modules::config().getConfigFile().getVar("SearchPaths");
void CConfiguration::cfcbSearchPaths(NLMISC::CConfigFile::CVar &var)
{
uint varsize = var.size();
//CPath::clearMap();
for (uint i = 0; i < varsize; ++i)
CPath::addSearchPath(var.asString(i), true, false);
std::vector<std::string> *tmpList = list;
if (!tmpList)
{
NLMISC::CConfigFile::CVar v = getConfigFile().getVar("SearchPaths");
tmpList = new std::vector<std::string>();
for (uint i = 0; i < v.size(); ++i)
{
tmpList->push_back(v.asString(i));
}
}
uint listsize = tmpList->size();
for (uint i = 0; i < listsize; ++i)
{
CProgressDialog pcb;
pcb.DisplayString = tmpList->at(i);
pcb.show();
CPath::addSearchPath(tmpList->at(i), true, false, &pcb);
}
if (!list)
delete tmpList;
}
} /* namespace NLQT */

View file

@ -31,14 +31,11 @@
#include <nel/misc/ucstring.h>
// Project includes
#include "callback.h"
#define NLQT_CONFIG_FILE "georges_editor.cfg"
namespace NLQT {
typedef CCallback<void, NLMISC::CConfigFile::CVar &> CConfigCallback;
/**
* CConfiguration
* \brief CConfiguration
@ -55,13 +52,9 @@ public:
void release();
void updateUtilities();
void configSearchPaths();
std::string configLeveldesignPath();
void configRemapExtensions();
void setAndCallback(const std::string &varName, CConfigCallback configCallback);
void setCallback(const std::string &varName, CConfigCallback configCallback);
void dropCallback(const std::string &varName);
void addSearchPaths(std::vector<std::string>* list = 0);
void addLeveldesignPath();
float getValue(const std::string &varName, float defaultValue);
double getValue(const std::string &varName, double defaultValue);
@ -75,15 +68,10 @@ public:
inline NLMISC::CConfigFile &getConfigFile() { return ConfigFile; }
private:
static void cbConfigCallback(NLMISC::CConfigFile::CVar &var);
void cfcbSearchPaths(NLMISC::CConfigFile::CVar &var);
CConfiguration(const CConfiguration &);
CConfiguration &operator=(const CConfiguration &);
NLMISC::CConfigFile ConfigFile;
std::map<std::string, CConfigCallback> ConfigCallbacks;
};/* class CConfiguration */

View file

@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "objectviewer_dialog.h"
#include "georges_dirtree_dialog.h"
#include "georges_treeview_dialog.h"
#include "progress_dialog.h"
using namespace std;
using namespace NLMISC;
@ -59,7 +60,8 @@ namespace NLQT
_currentView = 0;
// load and set leveldesign path from config
QString ldPath = Modules::config().configLeveldesignPath().c_str();
QString ldPath = Modules::config().
getValue("LeveldesignPath", QString("").toStdString()).c_str();
QFileInfo info(ldPath);
if (!info.isDir())
ldPath = "";
@ -113,7 +115,7 @@ namespace NLQT
delete _ObjectViewerDialog;
delete _GeorgesDirTreeDialog;
delete _GeorgesLogDialog;
delete _emptyView;
//delete _emptyView;
}
void CMainWindow::closeEvent(QCloseEvent *event)

View file

@ -86,10 +86,20 @@ namespace NLQT
//Modules::config().configSearchPaths();
// set background color from config
Modules::config().setAndCallback("BackgroundColor", CConfigCallback(this, &CObjectViewer::cfcbBackgroundColor));
NLMISC::CConfigFile::CVar v = Modules::config().getConfigFile().getVar("BackgroundColor");
_BackgroundColor = CRGBA(v.asInt(0), v.asInt(1), v.asInt(2));
// set graphics driver from config
Modules::config().setAndCallback("GraphicsDriver",CConfigCallback(this,&CObjectViewer::cfcbGraphicsDriver));
NLMISC::CConfigFile::CVar v2 = Modules::config().getConfigFile().getVar("GraphicsDriver");
// Choose driver opengl to work correctly under Linux example
_Direct3D = false; //_Driver = OpenGL;
#ifdef NL_OS_WINDOWS
std::string driver = v2.asString();
if (driver == "Direct3D") _Direct3D = true; //m_Driver = Direct3D;
else if (driver == "OpenGL") _Direct3D = false; //m_Driver = OpenGL;
else nlwarning("Invalid driver specified, defaulting to OpenGL");
#endif
// create the driver
nlassert(!_Driver);
@ -146,9 +156,6 @@ namespace NLQT
//H_AUTO2
nldebug("CObjectViewer::release");
Modules::config().dropCallback("BackgroundColor");
Modules::config().dropCallback("GraphicsDriver");
_Driver->delete3dMouseListener(_MouseListener);
// delete all entities
@ -390,23 +397,4 @@ namespace NLQT
_Entities.clear();
}
void CObjectViewer::cfcbBackgroundColor(NLMISC::CConfigFile::CVar &var)
{
// read variable from config file
_BackgroundColor = CRGBA(var.asInt(0), var.asInt(1), var.asInt(2));
}
void CObjectViewer::cfcbGraphicsDriver(NLMISC::CConfigFile::CVar &var)
{
// Choose driver opengl to work correctly under Linux example
_Direct3D = false; //_Driver = OpenGL;
#ifdef NL_OS_WINDOWS
std::string driver = var.asString();
if (driver == "Direct3D") _Direct3D = true; //m_Driver = Direct3D;
else if (driver == "OpenGL") _Direct3D = false; //m_Driver = OpenGL;
else nlwarning("Invalid driver specified, defaulting to OpenGL");
#endif
}
} /* namespace NLQT */

View file

@ -161,10 +161,6 @@ namespace NLQT
/// Delete all entities
void deleteEntities();
/// Load background color from config file, intended for CConfiguration.
void cfcbBackgroundColor(NLMISC::CConfigFile::CVar &var);
void cfcbGraphicsDriver(NLMISC::CConfigFile::CVar &var);
NLMISC::CRGBA _BackgroundColor;
NL3D::UDriver *_Driver;

View file

@ -39,12 +39,38 @@ namespace NLQT
{
ui.setupUi(this);
// setup config file callbacks and initialize values
Modules::config().setAndCallback("GraphicsDrivers", CConfigCallback(this, &CSettingsDialog::cfcbGraphicsDrivers));
Modules::config().setAndCallback("SearchPaths", CConfigCallback(this, &CSettingsDialog::cfcbSearchPaths));
Modules::config().setAndCallback("LeveldesignPath", CConfigCallback(this, &CSettingsDialog::cfcbLeveldesignPath));
while (ui.driverGraphComboBox->count())
ui.driverGraphComboBox->removeItem(0);
// load settings from the config file
// load types graphics driver from the config file
NLMISC::CConfigFile::CVar v = Modules::config().getConfigFile().getVar("GraphicsDrivers");
for (uint i = 0; i < v.size(); ++i)
ui.driverGraphComboBox->addItem(v.asString(i).c_str());
// set graphics driver from the config file
QString value = Modules::config().getValue("GraphicsDriver",std::string("OpenGL")).c_str();
QString dn = value.toLower();
for (sint i = 0; i < ui.driverGraphComboBox->count(); ++i)
{
if (dn == ui.driverGraphComboBox->itemText(i).toLower())
{
ui.driverGraphComboBox->setCurrentIndex(i);
}
}
// load leveldesign path from the config file
NLMISC::CConfigFile::CVar v2 = Modules::config().getConfigFile().getVar("LeveldesignPath");
ui.leveldesignPath->setText(v2.asString().c_str());
// load search paths from the config file
NLMISC::CConfigFile::CVar v3 = Modules::config().getConfigFile().getVar("SearchPaths");
ui.pathsListWidget->clear();
for (uint i = 0; i < v3.size(); ++i)
{
ui.pathsListWidget->addItem(v3.asString(i).c_str());
ui.pathsListWidget->item(i)->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
connect(ui.addToolButton, SIGNAL(clicked()), this, SLOT(addPath()));
connect(ui.removeToolButton, SIGNAL(clicked()), this, SLOT(removePath()));
@ -62,9 +88,6 @@ namespace NLQT
CSettingsDialog::~CSettingsDialog()
{
Modules::config().dropCallback("GraphicsDrivers");
Modules::config().dropCallback("SearchPaths");
Modules::config().dropCallback("LeveldesignPath");
}
void CSettingsDialog::addPath()
@ -126,17 +149,37 @@ namespace NLQT
Modules::config().getConfigFile().getVar("GraphicsDriver").setAsString(ui.driverGraphComboBox->currentText().toStdString());
// save leveldesign path to config file
std::string ldPath = ui.leveldesignPath->text().toStdString();
Modules::config().getConfigFile().getVar("LeveldesignPath").forceAsString(ldPath);
Q_EMIT ldPathChanged(ldPath.c_str());
QString oldLdPath = Modules::config().getValue("LeveldesignPath", std::string("")).c_str();
if (oldLdPath != ui.leveldesignPath->text())
{
std::string ldPath = ui.leveldesignPath->text().toStdString();
Modules::config().getConfigFile().getVar("LeveldesignPath").forceAsString(ldPath);
Q_EMIT ldPathChanged(ldPath.c_str());
// TODO: remove old Path from CPath
Modules::config().addLeveldesignPath();
}
// save search paths to config file
NLMISC::CConfigFile::CVar v = Modules::config().getConfigFile().getVar("SearchPaths");
QStringList sl;
for (uint i = 0; i < v.size(); ++i)
{
sl.append(v.asString(i).c_str());
}
std::vector<std::string> list;
std::vector<std::string> addList;
for (sint i = 0; i < ui.pathsListWidget->count(); ++i)
{
std::string str = ui.pathsListWidget->item(i)->text().toStdString();
if (str != "")
{
list.push_back(str);
if (!sl.contains(str.c_str()))
{
addList.push_back(str);
}
}
}
if (list.empty())
@ -153,48 +196,7 @@ namespace NLQT
Modules::config().getConfigFile().save();
// reload search paths
Modules::config().configSearchPaths();
Modules::config().configLeveldesignPath();
}
void CSettingsDialog::cfcbGraphicsDrivers(NLMISC::CConfigFile::CVar &var)
{
while (ui.driverGraphComboBox->count())
ui.driverGraphComboBox->removeItem(0);
// load types graphics driver from the config file
for (uint i = 0; i < var.size(); ++i)
ui.driverGraphComboBox->addItem(var.asString(i).c_str());
// set graphics driver from the config file
QString value = Modules::config().getValue("GraphicsDriver",std::string("OpenGL")).c_str();
QString dn = value.toLower();
for (sint i = 0; i < ui.driverGraphComboBox->count(); ++i)
{
if (dn == ui.driverGraphComboBox->itemText(i).toLower())
{
ui.driverGraphComboBox->setCurrentIndex(i);
return;
}
}
}
void CSettingsDialog::cfcbSearchPaths(NLMISC::CConfigFile::CVar &var)
{
ui.pathsListWidget->clear();
// load search paths from the config file
for (uint i = 0; i < var.size(); ++i)
{
ui.pathsListWidget->addItem(var.asString(i).c_str());
ui.pathsListWidget->item(i)->setFlags(Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
}
void CSettingsDialog::cfcbLeveldesignPath(NLMISC::CConfigFile::CVar &var)
{
// load leveldesign path from the config file
ui.leveldesignPath->setText(var.asString().c_str());
Modules::config().addSearchPaths(&addList);
}
void CSettingsDialog::browseLeveldesignPath()

View file

@ -52,10 +52,6 @@ namespace NLQT
void browseLeveldesignPath();
private:
void cfcbGraphicsDrivers(NLMISC::CConfigFile::CVar &var);
void cfcbSoundDrivers(NLMISC::CConfigFile::CVar &var);
void cfcbSearchPaths(NLMISC::CConfigFile::CVar &var);
void cfcbLeveldesignPath(NLMISC::CConfigFile::CVar &var);
Ui::CSettingsDialog ui;