src/config.h

changeset 467
59549731151a
parent 465
0f67ff766458
child 468
7b3159f1a9e2
--- a/src/config.h	Tue Aug 20 21:23:56 2013 +0300
+++ b/src/config.h	Wed Aug 21 01:13:52 2013 +0300
@@ -23,6 +23,7 @@
 
 // =============================================================================
 #include <QString>
+#include <QVariant>
 #include <QKeySequence>
 class QSettings;
 
@@ -44,6 +45,7 @@
 		Float,
 		Bool,
 		KeySequence,
+		List,
 	};
 
 	Config (const char* name, const char* defstring);
@@ -53,11 +55,11 @@
 		return (Type) 0;
 	}
 	
-	str toString() const;
 	str defaultString() const;
 	virtual void resetValue() {}
 	virtual void loadFromConfig (const QSettings* cfg) { (void) cfg; }
 	virtual bool isDefault() const { return false; }
+	virtual QVariant toVariant() const { return QVariant(); }
 	
 	// ------------------------------------------
 	static bool load();
@@ -84,7 +86,8 @@
 	Config::Type getType() const override { return Config::NAME; } \
 	virtual void resetValue() { value = defval; } \
 	virtual bool isDefault() const { return value == defval; } \
-	virtual void loadFromConfig (const QSettings* cfg) override;
+	virtual void loadFromConfig (const QSettings* cfg) override; \
+	virtual QVariant toVariant() const { return QVariant::fromValue<T> (value); }
 	
 #define DEFINE_UNARY_OPERATOR(T, OP) \
 	T operator OP() { \
@@ -202,4 +205,30 @@
 	DEFINE_ASSIGN_OPERATOR (QKeySequence, =)
 };
 
+// =============================================================================
+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();
+	}
+};
+
 #endif // CONFIG_H
\ No newline at end of file

mercurial