- refactored config code

Mon, 23 Dec 2013 16:10:36 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 23 Dec 2013 16:10:36 +0200
changeset 590
7aec744ce97b
parent 589
1417828920e6
child 591
5c8437249177

- refactored config code

src/config.cc file | annotate | diff | comparison | revisions
src/config.h file | annotate | diff | comparison | revisions
src/configDialog.cc file | annotate | diff | comparison | revisions
src/configDialog.h file | annotate | diff | comparison | revisions
src/dialogs.cc file | annotate | diff | comparison | revisions
src/document.cc file | annotate | diff | comparison | revisions
src/extprogs.cc file | annotate | diff | comparison | revisions
src/gldraw.cc file | annotate | diff | comparison | revisions
src/gui.cc file | annotate | diff | comparison | revisions
src/gui.h file | annotate | diff | comparison | revisions
src/gui_actions.cc file | annotate | diff | comparison | revisions
src/gui_editactions.cc file | annotate | diff | comparison | revisions
src/misc.cc file | annotate | diff | comparison | revisions
src/misc.h file | annotate | diff | comparison | revisions
src/misc/documentPointer.cc file | annotate | diff | comparison | revisions
src/primitives.cc file | annotate | diff | comparison | revisions
src/types.cc file | annotate | diff | comparison | revisions
src/types.h file | annotate | diff | comparison | revisions
--- a/src/config.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/config.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -38,8 +38,10 @@
 # define EXTENSION ".cfg"
 #endif // _WIN32
 
-Config* g_configPointers[MAX_CONFIG];
-static int g_cfgPointerCursor = 0;
+Config*							g_configPointers[MAX_CONFIG];
+static int						g_cfgPointerCursor = 0;
+static QMap<str, Config*>	g_configsByName;
+static QList<Config*>		g_configs;
 
 // =============================================================================
 // Get the QSettings object.
@@ -48,8 +50,8 @@
 {	return new QSettings (UNIXNAME EXTENSION, QSettings::IniFormat);
 }
 
-Config::Config (const char* name, const char* defstring) :
-	name (name), m_defstring (defstring) {}
+Config::Config (str name) :
+	m_Name (name) {}
 
 // =============================================================================
 // Load the configuration from file
@@ -62,8 +64,10 @@
 	{	if (!cfg)
 			break;
 
-		QVariant val = settings->value (cfg->name, cfg->defaultVariant());
+		QVariant val = settings->value (cfg->getName(), cfg->getDefaultAsVariant());
 		cfg->loadFromVariant (val);
+		g_configsByName[cfg->getName()] = cfg;
+		g_configs << cfg;
 	}
 
 	settings->deleteLater();
@@ -77,15 +81,9 @@
 {	QSettings* settings = getSettingsObject();
 	log ("Saving configuration to %1...\n", settings->fileName());
 
-	for (Config* cfg : g_configPointers)
-	{	if (!cfg)
-			break;
-
-		if (cfg->isDefault())
-			continue;
-
-		settings->setValue (cfg->name, cfg->toVariant());
-	}
+	for (Config* cfg : g_configs)
+		if (!cfg->isDefault())
+			settings->setValue (cfg->getName(), cfg->toVariant());
 
 	settings->sync();
 	settings->deleteLater();
@@ -93,15 +91,11 @@
 }
 
 // =============================================================================
-// Reset configuration defaults.
+// Reset configuration to defaults.
 // -----------------------------------------------------------------------------
 void Config::reset()
-{	for (Config * cfg : g_configPointers)
-	{	if (!cfg)
-			break;
-
+{	for (Config* cfg : g_configs)
 		cfg->resetValue();
-	}
 }
 
 // =============================================================================
@@ -122,7 +116,7 @@
 // =============================================================================
 // We cannot just add config objects to a list or vector because that would rely
 // on the vector's c-tor being called before the configs' c-tors. With global
-// variables we cannot assume that!! Therefore we need to use a C-style array here.
+// variables we cannot assume that, therefore we need to use a C-style array here.
 // -----------------------------------------------------------------------------
 void Config::addToArray (Config* ptr)
 {	if (g_cfgPointerCursor == 0)
@@ -134,32 +128,33 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-template<class T> T& getConfigByName (str name, Config::Type type)
-{	for (Config* cfg : g_configPointers)
-	{	if (!cfg)
-			break;
+template<class T> T* getConfigByName (str name, Config::Type type)
+{	auto it = g_configsByName.find (name);
+
+	if (it == g_configsByName.end())
+		return null;
 
-		if (cfg->name == name)
-		{	if (cfg->getType() == type)
-				return *reinterpret_cast<T*> (cfg);
-			else
-			{	fprint (stderr, "type of %1 is %2, not %3\n", name, cfg->getType(), type);
-				abort();
-			}
-		}
+	Config* cfg = it.value();
+
+	if (cfg->getType() != type)
+	{	fprint (stderr, "type of %1 is %2, not %3\n", name, cfg->getType(), type);
+		abort();
 	}
 
-	fprint (stderr, "couldn't find a configuration element with name %1", name);
-	abort();
+	return reinterpret_cast<T*> (cfg);
 }
 
+// =============================================================================
+// -----------------------------------------------------------------------------
 #undef IMPLEMENT_CONFIG
 #define IMPLEMENT_CONFIG(NAME) \
-	NAME##Config& NAME##Config::getByName (str name) { return getConfigByName<NAME##Config> (name, NAME); }
+	NAME##Config* NAME##Config::getByName (str name)		\
+	{	return getConfigByName<NAME##Config> (name, NAME);	\
+	}
 
 IMPLEMENT_CONFIG (Int)
 IMPLEMENT_CONFIG (String)
 IMPLEMENT_CONFIG (Bool)
 IMPLEMENT_CONFIG (Float)
 IMPLEMENT_CONFIG (List)
-IMPLEMENT_CONFIG (KeySequence)
\ No newline at end of file
+IMPLEMENT_CONFIG (KeySequence)
--- a/src/config.h	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/config.h	Mon Dec 23 16:10:36 2013 +0200
@@ -19,6 +19,8 @@
 #ifndef LDFORGE_CONFIG_H
 #define LDFORGE_CONFIG_H
 
+#include "property.h"
+
 // =============================================================================
 #include <QString>
 #include <QVariant>
@@ -31,12 +33,17 @@
 #define MAX_INI_LINE 512
 #define MAX_CONFIG 512
 
-#define cfg(T, NAME, DEFAULT) T##Config NAME (DEFAULT, #NAME, #DEFAULT)
-#define extern_cfg(T, NAME)   extern T##Config NAME
+#define cfg(T, NAME, DEFAULT) \
+	Config::T##Type NAME; \
+	T##Config config_##NAME (&NAME, #NAME, DEFAULT);
+
+#define extern_cfg(T, NAME) extern Config::T##Type NAME;
 
 // =========================================================
 class Config
-{	public:
+{	PROPERTY (private, str, Name, STR_OPS, STOCK_WRITE)
+
+	public:
 		enum Type
 		{	Int,
 			String,
@@ -46,29 +53,21 @@
 			List,
 		};
 
-		Config (const char* name, const char* defstring);
-		const char* name;
-
-		virtual Type getType() const
-		{	return (Type) 0;
-		}
-
-		virtual void resetValue() {}
-		virtual void loadFromVariant (const QVariant& val)
-		{	(void) val;
-		}
+		using IntType = int;
+		using StringType = QString;
+		using FloatType = float;
+		using BoolType = bool;
+		using KeySequenceType = QKeySequence;
+		using ListType = QList<QVariant>;
 
-		virtual bool isDefault() const
-		{	return false;
-		}
+		Config (str name);
 
-		virtual QVariant toVariant() const
-		{	return QVariant();
-		}
-
-		virtual QVariant defaultVariant() const
-		{	return QVariant();
-		}
+		virtual QVariant	getDefaultAsVariant() const = 0;
+		virtual Type		getType() const = 0;
+		virtual bool		isDefault() const = 0;
+		virtual void		loadFromVariant (const QVariant& val) = 0;
+		virtual void		resetValue() = 0;
+		virtual QVariant	toVariant() const = 0;
 
 		// ------------------------------------------
 		static bool load();
@@ -79,167 +78,91 @@
 
 	protected:
 		static void addToArray (Config* ptr);
-
-	private:
-		const char* m_defstring;
 };
 
 // =============================================================================
-#define IMPLEMENT_CONFIG(NAME, T) \
-	T value, defval; \
-	NAME##Config (T defval, const char* name, const char* defstring) : \
-		Config (name, defstring), value (defval), defval (defval) \
-		{ Config::addToArray (this); } \
-	\
-	operator const T&() const { return value; } \
-	Config::Type getType() const override { return Config::NAME; } \
-	virtual void resetValue() override { value = defval; } \
-	virtual bool isDefault() const override { return value == defval; } \
-	virtual QVariant toVariant() const override { return QVariant::fromValue<T> (value); } \
-	virtual QVariant defaultVariant() const override { return QVariant::fromValue<T> (defval); } \
-	virtual void loadFromVariant (const QVariant& val) override { value = val.value<T>(); } \
-	static NAME##Config& getByName (str name);
-
-#define DEFINE_UNARY_OPERATOR(T, OP) \
-	T operator OP() { \
-		return OP value; \
-	}
-
-#define DEFINE_BINARY_OPERATOR(T, OP) \
-	T operator OP (const T other) { \
-		return value OP other; \
-	}
-
-#define DEFINE_ASSIGN_OPERATOR(T, OP) \
-	T& operator OP (const T other) { \
-		return value OP other; \
-	}
-
-#define DEFINE_COMPARE_OPERATOR(T, OP) \
-	bool operator OP (const T other) { \
-		return value OP other; \
-	}
-
-#define DEFINE_CAST_OPERATOR(T) \
-	operator T() { \
-		return (T) value; \
-	}
-
-#define DEFINE_ALL_COMPARE_OPERATORS(T) \
-	DEFINE_COMPARE_OPERATOR (T, ==) \
-	DEFINE_COMPARE_OPERATOR (T, !=) \
-	DEFINE_COMPARE_OPERATOR (T, >) \
-	DEFINE_COMPARE_OPERATOR (T, <) \
-	DEFINE_COMPARE_OPERATOR (T, >=) \
-	DEFINE_COMPARE_OPERATOR (T, <=) \
-
-#define DEFINE_INCREMENT_OPERATORS(T) \
-	T operator++() { return ++value; } \
-	T operator++(int) { return value++; } \
-	T operator--() { return --value; } \
-	T operator--(int) { return value--; }
+#define IMPLEMENT_CONFIG(NAME)												\
+public:																				\
+	using ValueType = Config::NAME##Type;									\
+																						\
+	NAME##Config (ValueType* valueptr, str name, ValueType def) :	\
+		Config (name),																\
+		m_valueptr (valueptr),													\
+		m_default (def)															\
+	{	Config::addToArray (this);												\
+		*m_valueptr = def;														\
+	}																					\
+																						\
+	inline ValueType getValue() const										\
+	{	return *m_valueptr;														\
+	}																					\
+																						\
+	inline void setValue (ValueType val)									\
+	{	*m_valueptr = val;														\
+	}																					\
+																						\
+	virtual Config::Type getType() const									\
+	{	return Config::NAME;														\
+	}																					\
+																						\
+	virtual void resetValue()													\
+	{	*m_valueptr = m_default;												\
+	}																					\
+																						\
+	virtual const ValueType& getDefault() const							\
+	{	return m_default;															\
+	}																					\
+																						\
+	virtual bool isDefault() const											\
+	{	return *m_valueptr == m_default;										\
+	}																					\
+																						\
+	virtual void loadFromVariant (const QVariant& val)					\
+	{	*m_valueptr = val.value<ValueType>();								\
+	}																					\
+																						\
+	virtual QVariant toVariant() const										\
+	{	return QVariant::fromValue<ValueType> (*m_valueptr);			\
+	}																					\
+																						\
+	virtual QVariant getDefaultAsVariant() const							\
+	{	return QVariant::fromValue<ValueType> (m_default);				\
+	}																					\
+																						\
+	static NAME##Config* getByName (str name);							\
+																						\
+private:																				\
+	ValueType*	m_valueptr;														\
+	ValueType	m_default;
 
 // =============================================================================
 class IntConfig : public Config
-{	public:
-		IMPLEMENT_CONFIG (Int, int)
-		DEFINE_ALL_COMPARE_OPERATORS (int)
-		DEFINE_INCREMENT_OPERATORS (int)
-		DEFINE_BINARY_OPERATOR (int, +)
-		DEFINE_BINARY_OPERATOR (int, -)
-		DEFINE_BINARY_OPERATOR (int, *)
-		DEFINE_BINARY_OPERATOR (int, /)
-		DEFINE_BINARY_OPERATOR (int, %)
-		DEFINE_BINARY_OPERATOR (int, ^)
-		DEFINE_BINARY_OPERATOR (int, |)
-		DEFINE_BINARY_OPERATOR (int, &)
-		DEFINE_BINARY_OPERATOR (int, >>)
-		DEFINE_BINARY_OPERATOR (int, <<)
-		DEFINE_UNARY_OPERATOR (int, !)
-		DEFINE_UNARY_OPERATOR (int, ~)
-		DEFINE_UNARY_OPERATOR (int, -)
-		DEFINE_UNARY_OPERATOR (int, +)
-		DEFINE_ASSIGN_OPERATOR (int, =)
-		DEFINE_ASSIGN_OPERATOR (int, +=)
-		DEFINE_ASSIGN_OPERATOR (int, -=)
-		DEFINE_ASSIGN_OPERATOR (int, *=)
-		DEFINE_ASSIGN_OPERATOR (int, /=)
-		DEFINE_ASSIGN_OPERATOR (int, %=)
-		DEFINE_ASSIGN_OPERATOR (int, >>=)
-		DEFINE_ASSIGN_OPERATOR (int, <<=)
+{	IMPLEMENT_CONFIG (Int)
 };
 
 // =============================================================================
 class StringConfig : public Config
-{	public:
-		IMPLEMENT_CONFIG (String, str)
-
-		DEFINE_COMPARE_OPERATOR (str, ==)
-		DEFINE_COMPARE_OPERATOR (str, !=)
-		DEFINE_ASSIGN_OPERATOR (str, =)
-		DEFINE_ASSIGN_OPERATOR (str, +=)
-
-		QChar operator[] (int n)
-		{	return value[n];
-		}
+{	IMPLEMENT_CONFIG (String)
 };
 
 // =============================================================================
 class FloatConfig : public Config
-{	public:
-		IMPLEMENT_CONFIG (Float, float)
-		DEFINE_ALL_COMPARE_OPERATORS (float)
-		DEFINE_INCREMENT_OPERATORS (float)
-		DEFINE_BINARY_OPERATOR (float, +)
-		DEFINE_BINARY_OPERATOR (float, -)
-		DEFINE_BINARY_OPERATOR (float, *)
-		DEFINE_UNARY_OPERATOR (float, !)
-		DEFINE_ASSIGN_OPERATOR (float, =)
-		DEFINE_ASSIGN_OPERATOR (float, +=)
-		DEFINE_ASSIGN_OPERATOR (float, -=)
-		DEFINE_ASSIGN_OPERATOR (float, *=)
+{	IMPLEMENT_CONFIG (Float)
 };
 
 // =============================================================================
 class BoolConfig : public Config
-{	public:
-		IMPLEMENT_CONFIG (Bool, bool)
-		DEFINE_ALL_COMPARE_OPERATORS (bool)
-		DEFINE_ASSIGN_OPERATOR (bool, =)
+{	IMPLEMENT_CONFIG (Bool)
 };
 
 // =============================================================================
 class KeySequenceConfig : public Config
-{	public:
-		IMPLEMENT_CONFIG (KeySequence, QKeySequence)
-		DEFINE_ALL_COMPARE_OPERATORS (QKeySequence)
-		DEFINE_ASSIGN_OPERATOR (QKeySequence, =)
+{	IMPLEMENT_CONFIG (KeySequence)
 };
 
 // =============================================================================
 class ListConfig : public Config
-{	public:
-		IMPLEMENT_CONFIG (List, QList<QVariant>)
-		DEFINE_ASSIGN_OPERATOR (QList<QVariant>, =)
-
-		typedef QList<QVariant>::iterator it;
-		typedef QList<QVariant>::const_iterator c_it;
-
-		it begin()
-		{	return value.begin();
-		}
-
-		c_it begin() const
-		{	return value.constBegin();
-		}
-
-		it end()
-		{	return value.end();
-		}
-
-		c_it end() const
-		{	return value.constEnd();
-		}
+{	IMPLEMENT_CONFIG (List)
 };
 
 #endif // LDFORGE_CONFIG_H
--- a/src/configDialog.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/configDialog.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -110,8 +110,11 @@
 	int i = 0;
 
 	for (QAction* act : g_win->findChildren<QAction*>())
-		if (!act->objectName().isEmpty())
-			addShortcut (g_win->shortcutForAction (act), act, i);
+	{	KeySequenceConfig* cfg = g_win->shortcutForAction (act);
+
+		if (cfg)
+			addShortcut (*cfg, act, i);
+	}
 
 	ui->shortcutsList->setSortingEnabled (true);
 	ui->shortcutsList->sortItems();
@@ -222,7 +225,7 @@
 			if (j == 3)
 				dsb_gridData[i][j]->setMaximum (360);
 
-			dsb_gridData[i][j]->setValue (g_GridInfo[i].confs[j]->value);
+			dsb_gridData[i][j]->setValue (*g_GridInfo[i].confs[j]);
 			gridlayout->addWidget (dsb_gridData[i][j], i + 1, j + 1);
 		}
 	}
@@ -232,14 +235,15 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-static const struct LDExtProgInfo
-{	const str name, iconname;
-	StringConfig* const path;
-	mutable QLineEdit* input;
-	mutable QPushButton* setPathButton;
+static struct LDExtProgInfo
+{	const str		name,
+						iconname;
+	str* const		path;
+	QLineEdit*		input;
+	QPushButton*	setPathButton;
 #ifndef _WIN32
-	BoolConfig* const wine;
-	mutable QCheckBox* wineBox;
+	bool* const		wine;
+	QCheckBox*		wineBox;
 #endif // _WIN32
 } g_LDExtProgInfo[] =
 {
@@ -264,14 +268,14 @@
 {	QGridLayout* pathsLayout = new QGridLayout;
 	int row = 0;
 
-	for (const LDExtProgInfo& info : g_LDExtProgInfo)
+	for (LDExtProgInfo& info : g_LDExtProgInfo)
 	{	QLabel* icon = new QLabel,
 		*progLabel = new QLabel (info.name);
 		QLineEdit* input = new QLineEdit;
 		QPushButton* setPathButton = new QPushButton;
 
 		icon->setPixmap (getIcon (info.iconname));
-		input->setText (info.path->value);
+		input->setText (*info.path);
 		setPathButton->setIcon (getIcon ("folder"));
 		info.input = input;
 		info.setPathButton = setPathButton;
@@ -324,7 +328,7 @@
 	// Set the grid settings
 	for (int i = 0; i < g_NumGrids; ++i)
 		for (int j = 0; j < 4; ++j)
-			g_GridInfo[i].confs[j]->value = dsb_gridData[i][j]->value();
+			*g_GridInfo[i].confs[j] = dsb_gridData[i][j]->value();
 
 	// Apply key shortcuts
 	g_win->updateActionShortcuts();
@@ -500,15 +504,18 @@
 // =============================================================================
 // Pick a color and set the appropriate configuration option.
 // -----------------------------------------------------------------------------
-void ConfigDialog::pickColor (StringConfig& conf, QPushButton* button)
+void ConfigDialog::pickColor (str& conf, QPushButton* button)
 {	QColor col = QColorDialog::getColor (QColor (conf));
 
 	if (col.isValid())
-	{	uchar r = col.red(),
-				  g = col.green(),
-				  b = col.blue();
-		conf.value.sprintf ("#%.2X%.2X%.2X", r, g, b);
-		setButtonBackground (button, conf.value);
+	{	int r = col.red(),
+			g = col.green(),
+			b = col.blue();
+
+		str colname;
+		colname.sprintf ("#%.2X%.2X%.2X", r, g, b);
+		conf = colname;
+		setButtonBackground (button, colname);
 	}
 }
 
@@ -605,7 +612,7 @@
 {	QList<ShortcutListItem*> sel = getShortcutSelection();
 
 	for (ShortcutListItem* item : sel)
-	{	item->getKeyConfig()->value = QKeySequence();
+	{	item->getKeyConfig()->setValue (QKeySequence());
 		setShortcutText (item);
 	}
 }
@@ -646,7 +653,7 @@
 void ConfigDialog::setShortcutText (ShortcutListItem* item)
 {	QAction* act = item->getAction();
 	str label = act->iconText();
-	str keybind = item->getKeyConfig()->value.toString();
+	str keybind = item->getKeyConfig()->getValue().toString();
 	item->setText (fmt ("%1 (%2)", label, keybind));
 }
 
@@ -696,12 +703,12 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 bool KeySequenceDialog::staticDialog (KeySequenceConfig* cfg, QWidget* parent)
-{	KeySequenceDialog dlg (cfg->value, parent);
+{	KeySequenceDialog dlg (cfg->getValue(), parent);
 
 	if (dlg.exec() == false)
 		return false;
 
-	cfg->value = dlg.seq;
+	cfg->setValue (dlg.seq);
 	return true;
 }
 
--- a/src/configDialog.h	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/configDialog.h	Mon Dec 23 16:10:36 2013 +0200
@@ -67,7 +67,7 @@
 		void applySettings();
 		void addShortcut (KeySequenceConfig& cfg, QAction* act, int& i);
 		void setButtonBackground (QPushButton* button, str value);
-		void pickColor (StringConfig& cfg, QPushButton* button);
+		void pickColor (str& conf, QPushButton* button);
 		void updateQuickColorList (LDQuickColor* sel = null);
 		void setShortcutText (ShortcutListItem* item);
 		int getItemRow (QListWidgetItem* item, QList<QListWidgetItem*>& haystack);
--- a/src/dialogs.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/dialogs.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -324,7 +324,7 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 void AboutDialog::slot_mail()
-{	QDesktopServices::openUrl (QUrl ("mailto:Santeri Piippo <slatenails64@gmail.com>?subject=LDForge"));
+{	QDesktopServices::openUrl (QUrl ("mailto:Santeri Piippo <arezey@gmail.com>?subject=LDForge"));
 }
 
 // =============================================================================
--- a/src/document.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/document.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -544,7 +544,7 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 void addRecentFile (str path)
-{	auto& rfiles = io_recentfiles.value;
+{	auto& rfiles = io_recentfiles;
 	int idx = rfiles.indexOf (path);
 
 	// If this file already is in the list, pop it out.
--- a/src/extprogs.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/extprogs.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -57,7 +57,7 @@
 cfg (String, prog_rectifier, "");
 cfg (String, prog_edger2, "");
 
-StringConfig* const g_extProgPaths[] =
+str* const g_extProgPaths[] =
 {	&prog_isecalc,
 	&prog_intersector,
 	&prog_coverer,
@@ -74,7 +74,7 @@
 cfg (Bool, prog_rectifier_wine, false);
 cfg (Bool, prog_edger2_wine, false);
 
-BoolConfig* const g_extProgWine[] =
+bool* const g_extProgWine[] =
 {	&prog_isecalc_wine,
 	&prog_intersector_wine,
 	&prog_coverer_wine,
@@ -96,7 +96,7 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 static bool checkProgPath (const extprog prog)
-{	alias path = g_extProgPaths[prog]->value;
+{	str& path = *g_extProgPaths[prog];
 
 	if (path.length() > 0)
 		return true;
@@ -119,7 +119,7 @@
 		{	str wineblurb;
 
 #ifndef _WIN32
-			if (g_extProgWine[prog])
+			if (*g_extProgWine[prog])
 				wineblurb = "make sure Wine is installed and ";
 #endif
 
--- a/src/gldraw.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/gldraw.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -56,19 +56,19 @@
 	{ 0, 1, 0, 2, 0, 0, 0, 0, 2 },
 };
 
-cfg (String,	gl_bgcolor,				"#CCCCD9");
-cfg (String,	gl_maincolor,			"#707078");
-cfg (Float,		gl_maincolor_alpha,	1.0);
-cfg (Int,		gl_linethickness,		2);
-cfg (Bool,		gl_colorbfc,			false);
-cfg (Int,		gl_camera,				GLRenderer::EFreeCamera);
-cfg (Bool,		gl_blackedges,			false);
-cfg (Bool,		gl_axes,					false);
-cfg (Bool,		gl_wireframe,			false);
-cfg (Bool,		gl_logostuds,			false);
-cfg (Bool,		gl_aa,					true);
-cfg (Bool,		gl_linelengths,		true);
-cfg (Bool,		gl_drawangles,			false);
+cfg (String,	gl_bgcolor,				"#FFFFFF")
+cfg (String,	gl_maincolor,			"#A0A0A0")
+cfg (Float,		gl_maincolor_alpha,	1.0)
+cfg (Int,		gl_linethickness,		2)
+cfg (Bool,		gl_colorbfc,			false)
+cfg (Int,		gl_camera,				GLRenderer::EFreeCamera)
+cfg (Bool,		gl_blackedges,			false)
+cfg (Bool,		gl_axes,					false)
+cfg (Bool,		gl_wireframe,			false)
+cfg (Bool,		gl_logostuds,			false)
+cfg (Bool,		gl_aa,					true)
+cfg (Bool,		gl_linelengths,		true)
+cfg (Bool,		gl_drawangles,			false)
 
 // argh
 const char* g_CameraNames[7] =
@@ -108,7 +108,7 @@
 // -----------------------------------------------------------------------------
 GLRenderer::GLRenderer (QWidget* parent) : QGLWidget (parent)
 {	m_Picking = m_rangepick = false;
-	m_camera = (GL::EFixedCamera) gl_camera.value;
+	m_camera = (GL::EFixedCamera) gl_camera;
 	m_drawToolTip = false;
 	m_EditMode = ESelectMode;
 	m_rectdraw = false;
--- a/src/gui.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/gui.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -121,7 +121,7 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-KeySequenceConfig& ForgeWindow::shortcutForAction (QAction* act)
+KeySequenceConfig* ForgeWindow::shortcutForAction (QAction* act)
 {	str keycfgname = fmt ("key_%1", act->objectName());
 	return KeySequenceConfig::getByName (keycfgname);
 }
@@ -130,8 +130,11 @@
 // -----------------------------------------------------------------------------
 void ForgeWindow::updateActionShortcuts()
 {	for (QAction* act : findChildren<QAction*>())
-		if (!act->objectName().isEmpty())
-			act->setShortcut (shortcutForAction (act));
+	{	KeySequenceConfig* cfg = shortcutForAction (act);
+
+		if (cfg)
+			act->setShortcut (cfg->getValue());
+	}
 }
 
 // =============================================================================
@@ -194,7 +197,7 @@
 QList<LDQuickColor> quickColorsFromConfig()
 {	QList<LDQuickColor> colors;
 
-	for (str colorname : gui_colortoolbar.value.split (":"))
+	for (str colorname : gui_colortoolbar.split (":"))
 	{	if (colorname == "|")
 			colors << LDQuickColor::getSeparator();
 		else
@@ -795,7 +798,7 @@
 
 	if (colinfo->index == maincolor)
 	{	// Use the user preferences for main color here
-		col = gl_maincolor.value;
+		col = gl_maincolor;
 		col.setAlphaF (gl_maincolor_alpha);
 	}
 
--- a/src/gui.h	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/gui.h	Mon Dec 23 16:10:36 2013 +0200
@@ -130,7 +130,7 @@
 		Ui_LDForgeUI* getInterface() const;
 		void refreshObjectList();
 		void updateActionShortcuts();
-		KeySequenceConfig& shortcutForAction (QAction* act);
+		KeySequenceConfig* shortcutForAction (QAction* act);
 		void endAction();
 
 	public slots:
--- a/src/gui_actions.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/gui_actions.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -53,7 +53,7 @@
 
 	str authortext = ld_defaultname;
 
-	if (!ld_defaultuser.value.isEmpty())
+	if (!ld_defaultuser.isEmpty())
 		authortext.append (fmt (" [%1]", ld_defaultuser));
 
 	ui.le_author->setText (authortext);
--- a/src/gui_editactions.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/gui_editactions.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -358,9 +358,9 @@
 // -----------------------------------------------------------------------------
 void doMoveObjects (vertex vect)
 {	// Apply the grid values
-	vect[X] *= currentGrid().confs[Grid::X]->value;
-	vect[Y] *= currentGrid().confs[Grid::Y]->value;
-	vect[Z] *= currentGrid().confs[Grid::Z]->value;
+	vect[X] *= *currentGrid().confs[Grid::X];
+	vect[Y] *= *currentGrid().confs[Grid::Y];
+	vect[Z] *= *currentGrid().confs[Grid::Z];
 
 	for (LDObject* obj : selection())
 	{	obj->move (vect);
@@ -423,7 +423,7 @@
 {	QList<LDObject*> sel = selection();
 	QList<vertex*> queue;
 	const vertex rotpoint = rotPoint (sel);
-	const double angle = (pi * currentGrid().confs[Grid::Angle]->value) / 180,
+	const double angle = (pi * *currentGrid().confs[Grid::Angle]) / 180,
 				 cosangle = cos (angle),
 				 sinangle = sin (angle);
 
--- a/src/misc.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/misc.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -101,24 +101,23 @@
 // =============================================================================
 // -----------------------------------------------------------------------------
 // Grid stuff
-cfg (Int, grid, Grid::Medium);
-
-cfg (Float, grid_coarse_x,			5.0f);
-cfg (Float, grid_coarse_y,			5.0f);
-cfg (Float, grid_coarse_z,			5.0f);
-cfg (Float, grid_coarse_angle,	45.0f);
+cfg (Int,	grid,						Grid::Medium);
+cfg (Float,	grid_coarse_x,			5.0f);
+cfg (Float,	grid_coarse_y,			5.0f);
+cfg (Float,	grid_coarse_z,			5.0f);
+cfg (Float,	grid_coarse_angle,	45.0f);
 cfg (Float, grid_medium_x,			1.0f);
-cfg (Float, grid_medium_y,			1.0f);
-cfg (Float, grid_medium_z,			1.0f);
-cfg (Float, grid_medium_angle,	22.5f);
-cfg (Float, grid_fine_x,			0.1f);
-cfg (Float, grid_fine_y,			0.1f);
-cfg (Float, grid_fine_z,			0.1f);
-cfg (Float, grid_fine_angle,		7.5f);
-cfg (Int, edit_rotpoint, 0);
-cfg (Float, edit_rotpoint_x, 0.0f); // TODO: make a VertexConfig and use it here
-cfg (Float, edit_rotpoint_y, 0.0f);
-cfg (Float, edit_rotpoint_z, 0.0f);
+cfg (Float,	grid_medium_y,			1.0f);
+cfg (Float,	grid_medium_z,			1.0f);
+cfg (Float,	grid_medium_angle,	22.5f);
+cfg (Float,	grid_fine_x,			0.1f);
+cfg (Float,	grid_fine_y,			0.1f);
+cfg (Float,	grid_fine_z,			0.1f);
+cfg (Float,	grid_fine_angle,		7.5f);
+cfg (Int,	edit_rotpoint,			0);
+cfg (Float,	edit_rotpoint_x,		0.0f); // TODO: make a VertexConfig and use it here
+cfg (Float,	edit_rotpoint_y,		0.0f);
+cfg (Float,	edit_rotpoint_z, 		0.0f);
 
 const gridinfo g_GridInfo[3] =
 {	{ "Coarse", { &grid_coarse_x, &grid_coarse_y, &grid_coarse_z, &grid_coarse_angle }},
@@ -130,7 +129,7 @@
 // Snap the given coordinate value on the current grid's given axis.
 // -----------------------------------------------------------------------------
 double Grid::snap (double in, const Grid::Config axis)
-{	const double gridval = currentGrid().confs[axis]->value;
+{	const double gridval = *currentGrid().confs[axis];
 	const long mult = abs (in / gridval);
 	const bool neg = (in < 0);
 	double out = mult * gridval;
--- a/src/misc.h	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/misc.h	Mon Dec 23 16:10:36 2013 +0200
@@ -46,7 +46,7 @@
 // Grid stuff
 struct gridinfo
 {	const char* const name;
-	FloatConfig* const confs[4];
+	float* const confs[4];
 };
 
 extern_cfg (Int, grid);
--- a/src/misc/documentPointer.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/misc/documentPointer.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -64,4 +64,6 @@
 		setPointer (ptr);
 		addReference();
 	}
+
+	return *this;
 }
\ No newline at end of file
--- a/src/primitives.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/primitives.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -548,7 +548,7 @@
 	str author = APPNAME;
 	str license = "";
 
-	if (ld_defaultname.value.isEmpty() == false)
+	if (ld_defaultname.isEmpty() == false)
 	{	license = getLicenseText (ld_defaultlicense);
 		author = fmt ("%1 [%2]", ld_defaultname, ld_defaultuser);
 	}
--- a/src/types.cc	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/types.cc	Mon Dec 23 16:10:36 2013 +0200
@@ -320,18 +320,6 @@
 {	m_val = v;
 }
 
-StringFormatArg::StringFormatArg (const StringConfig& v)
-{	m_val = v.value;
-}
-
-StringFormatArg::StringFormatArg (const IntConfig& v)
-{	m_val.number (v.value);
-}
-
-StringFormatArg::StringFormatArg (const FloatConfig& v)
-{	m_val.number (v.value);
-}
-
 StringFormatArg::StringFormatArg (const void* v)
 {	m_val.sprintf ("%p", v);
 }
--- a/src/types.h	Mon Dec 23 11:57:32 2013 +0200
+++ b/src/types.h	Mon Dec 23 16:10:36 2013 +0200
@@ -26,10 +26,6 @@
 #include "main.h"
 
 class LDObject;
-
-class StringConfig;
-class IntConfig;
-class FloatConfig;
 class QFile;
 class QTextStream;
 
@@ -204,9 +200,6 @@
 		StringFormatArg (const vertex& v);
 		StringFormatArg (const matrix& v);
 		StringFormatArg (const char* v);
-		StringFormatArg (const StringConfig& v);
-		StringFormatArg (const IntConfig& v);
-		StringFormatArg (const FloatConfig& v);
 		StringFormatArg (const void* v);
 
 		template<class T> StringFormatArg (const QList<T>& v)

mercurial