Settings class stub and test QML code using it
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 22 Aug 2011 19:52:22 +0000 (22:52 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 22 Aug 2011 19:52:22 +0000 (22:52 +0300)
Does not work yet, even the test.

chessclock.pro
classes/settings.cpp [new file with mode: 0644]
classes/settings.h [new file with mode: 0644]
main.cpp
qml/NewGameDialogPage.qml

index 97deea2..3930fa2 100644 (file)
@@ -43,7 +43,8 @@ SOURCES += main.cpp \
     classes/timecontrol/hourglassclock.cpp \
     classes/timecontrol/hourglasstimecontrol.cpp \
     classes/screenlitkeeper.cpp \
-    classes/wrappedclockswidget.cpp
+    classes/wrappedclockswidget.cpp \
+    classes/settings.cpp
 
 HEADERS  += chessclockwindow.h \
     classes/turninformation.h \
@@ -66,7 +67,8 @@ HEADERS  += chessclockwindow.h \
     classes/timecontrol/hourglasstimecontrol.h \
     classes/timecontrol/hourglassclock.h \
     classes/screenlitkeeper.h \
-    classes/wrappedclockswidget.h
+    classes/wrappedclockswidget.h \
+    classes/settings.h
 
 
 OTHER_FILES += \
diff --git a/classes/settings.cpp b/classes/settings.cpp
new file mode 100644 (file)
index 0000000..1ca779b
--- /dev/null
@@ -0,0 +1,91 @@
+#include "settings.h"
+#include <QSettings>
+
+
+Settings::Settings(QObject *parent) :
+    QObject(parent)
+{
+}
+
+int Settings::value(WrappedClocksWidget::TimeControlType timeControl, QString key)
+{
+
+
+  QSettings settings;
+
+
+
+settings.beginGroup(getGroupName(timeControl));
+
+}
+
+void Settings::setValue()
+{
+
+}
+
+QString Settings::getGroupName(WrappedClocksWidget::TimeControlType timeControl)
+{
+    //Using same groups and keys in QSettings as the maemo version
+    //just in case Maemo version would move to use QML someday
+
+
+   QString groupString;
+
+   switch (timeControl)
+   {
+
+    case WrappedClocksWidget::NormalClock:
+
+       groupString = "Normal clock";
+       break;
+
+    case WrappedClocksWidget::AdditionBefore:
+
+       groupString = "Addition before";
+       break;
+
+    case WrappedClocksWidget::AdditionAfter:
+           groupString = "Addition after";
+           break;
+
+    case WrappedClocksWidget::Delay:
+       groupString = "Delay";
+       break;
+
+   case WrappedClocksWidget::DelayAfter:
+       groupString = "Delay after";
+       break;
+
+
+    case WrappedClocksWidget::HourGlass:
+       groupString = "Hour glass";
+       break;
+
+    default: //If QML sends an invalid value give the value for normal clock
+
+       groupString = "Normal Clock";
+       break;
+
+    }
+return groupString;
+
+}
+
+   int Settings::getTurnsPerAddition(WrappedClocksWidget::TimeControlType timeControl, QString player)
+   {
+
+       QSettings settings;
+       settings.beginGroup(getGroupName(timeControl));
+
+       if (player == "white")
+           return settings.value("WhitePerTurns",1).toInt();
+
+       if (player == "black");
+           return settings.value("BlackPerTurns",1).toInt();
+
+       return 0; //for invalid input
+
+
+   }
+
diff --git a/classes/settings.h b/classes/settings.h
new file mode 100644 (file)
index 0000000..f0b3441
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#include <QObject>
+#include <QVariant>
+#include "classes/wrappedclockswidget.h"
+
+class Settings : public QObject
+{
+    Q_OBJECT
+public:
+    explicit Settings(QObject *parent = 0);
+
+    Q_INVOKABLE int value(WrappedClocksWidget::TimeControlType timeControl, QString key);
+
+    Q_INVOKABLE int getTurnsPerAddition(WrappedClocksWidget::TimeControlType timeControl, QString player);
+
+
+signals:
+
+public slots:
+
+    void setValue();
+
+protected:
+
+    QString getGroupName(WrappedClocksWidget::TimeControlType);
+
+};
+
+#endif // SETTINGS_H
index cda3d95..c40983e 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -22,6 +22,7 @@
 #include <QtGui/QApplication>
 #include <QtDeclarative>
 #include "classes/wrappedclockswidget.h"
+#include "classes/settings.h"
 
 
 int main(int argc, char *argv[])
@@ -30,6 +31,7 @@ int main(int argc, char *argv[])
     app.setStyleSheet("* {color: white}");
 
     qmlRegisterType<WrappedClocksWidget>("ChessClocks", 1, 0, "WrappedClocksWidget");
+    qmlRegisterType<Settings>("ChessClocks", 1, 0, "Settings");
 
     QDeclarativeView view;
     view.setSource(QUrl("qrc:/qml/main.qml"));
index 52d3c3d..42eb744 100644 (file)
@@ -38,6 +38,12 @@ Page
     property bool askAddition
     property bool askTurnsPerAddition
 
+    property int test
+
+    Settings {id: settings}
+    Component.onCompleted:
+    {test = settings.value("test") }
+
     tools: ToolBarLayout
     {
         ToolIcon { iconId: "toolbar-back"; onClicked: pageStack.pop() }