Put c++ data to QML the first time: YEAAAAHHHH ;-)
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
#include "qmlconfig.h"
|
||||
#include "configfile.h"
|
||||
|
||||
QmlConfig::QmlConfig(boost::shared_ptr<ConfigFile> c)
|
||||
:QObject(), myConfig(c)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QmlConfig::~QmlConfig() {}
|
||||
QmlConfig::QmlConfig(const QmlConfig&) :QObject() {}
|
||||
|
||||
QString QmlConfig::readConfigString(QString varName) {
|
||||
return QString::fromUtf8(myConfig->readConfigString(varName.toStdString()).c_str());
|
||||
}
|
||||
|
||||
QString QmlConfig::readConfigInt(QString varName) {
|
||||
return QString::number(myConfig->readConfigInt(varName.toStdString()));
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef QMLCONFIG_H
|
||||
#define QMLCONFIG_H
|
||||
#include <QtCore>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class ConfigFile;
|
||||
|
||||
class QmlConfig: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
Q_INVOKABLE QString readConfigString(QString);
|
||||
Q_INVOKABLE QString readConfigInt(QString);
|
||||
|
||||
QmlConfig(boost::shared_ptr<ConfigFile>);
|
||||
~QmlConfig();
|
||||
QmlConfig(const QmlConfig&);
|
||||
|
||||
private:
|
||||
boost::shared_ptr<ConfigFile> myConfig;
|
||||
};
|
||||
|
||||
#endif // QMLCONFIG_H
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "qmlconfigwrapper.h"
|
||||
#include "configfile.h"
|
||||
|
||||
QmlConfigWrapper::QmlConfigWrapper(ConfigFile *c)
|
||||
:QObject(), myConfig(c)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QmlConfigWrapper::~QmlConfigWrapper()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QmlConfigWrapper::QmlConfigWrapper(const QmlConfigWrapper&)
|
||||
:QObject()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
#ifndef QMLCONFIGWRAPPER_H
|
||||
#define QMLCONFIGWRAPPER_H
|
||||
#include <QtCore>
|
||||
|
||||
class ConfigFile;
|
||||
|
||||
class QmlConfigWrapper: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QmlConfigWrapper(ConfigFile *c);
|
||||
~QmlConfigWrapper();
|
||||
QmlConfigWrapper(const QmlConfigWrapper&);
|
||||
|
||||
private:
|
||||
ConfigFile *myConfig;
|
||||
};
|
||||
|
||||
#endif // QMLCONFIGWRAPPER_H
|
||||
@@ -1,18 +1,20 @@
|
||||
#include <QtCore>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <configfile.h>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include "qmlconfig.h"
|
||||
#include "qmlwrapper.h"
|
||||
|
||||
QmlWrapper::QmlWrapper(boost::shared_ptr<ConfigFile> c)
|
||||
:QObject(), myConfig(c)
|
||||
{
|
||||
qDebug("QmlWrapperKonstruktor");
|
||||
myEngine.reset(new QQmlApplicationEngine);
|
||||
myQmlConfig = new QmlConfig(myConfig); //need to be a default pointer because QML doesnt support shared_ptr()
|
||||
|
||||
// Add c++ content here
|
||||
// myEngine.rootContext()->setContextProperty("model1", &model1);
|
||||
myEngine->rootContext()->setContextProperty("Config", myQmlConfig);
|
||||
|
||||
myEngine->load(QUrl(QStringLiteral("qrc:/main.qml")));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
class ConfigFile;
|
||||
class QmlConfig;
|
||||
class QQmlApplicationEngine;
|
||||
|
||||
class QmlWrapper: public QObject
|
||||
@@ -19,6 +20,7 @@ public slots:
|
||||
private:
|
||||
boost::shared_ptr<QQmlApplicationEngine> myEngine;
|
||||
boost::shared_ptr<ConfigFile> myConfig;
|
||||
QmlConfig *myQmlConfig;
|
||||
};
|
||||
|
||||
#endif // QMLWRAPPER_H
|
||||
|
||||
@@ -35,7 +35,7 @@ Rectangle {
|
||||
ListElement { value: "2" }
|
||||
]
|
||||
myValueIsIndex: false
|
||||
myValue: "10"
|
||||
myValue: ""
|
||||
}
|
||||
ListElement {
|
||||
myId: "spinBox_StartCash"
|
||||
@@ -44,7 +44,7 @@ Rectangle {
|
||||
myMaxValue: 1000000
|
||||
myMinValue: 1000
|
||||
myPrefix: "$"
|
||||
myValue: "5000"
|
||||
myValue: ""
|
||||
}
|
||||
ListElement {
|
||||
myId: "comboBox_Blinds"
|
||||
@@ -54,7 +54,7 @@ Rectangle {
|
||||
ListElement { value: qsTr("Use saved blinds settings") },
|
||||
ListElement { value: qsTr("Change blinds settings ...") }
|
||||
]
|
||||
myValue: "0"
|
||||
myValue: ""
|
||||
myValueIsIndex: true
|
||||
}
|
||||
ListElement {
|
||||
@@ -74,7 +74,7 @@ Rectangle {
|
||||
ListElement { value: "2" },
|
||||
ListElement { value: "1" }
|
||||
]
|
||||
myValue: "5"
|
||||
myValue: ""
|
||||
myValueIsIndex: false
|
||||
}
|
||||
ListElement {
|
||||
@@ -94,9 +94,17 @@ Rectangle {
|
||||
ListElement { value: "2" },
|
||||
ListElement { value: "1" }
|
||||
]
|
||||
myValue: "5"
|
||||
myValue: ""
|
||||
myValueIsIndex: false
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
createLocalGameViewModel.setProperty(0, "myValue", Config.readConfigInt("NumberOfPlayers"));
|
||||
createLocalGameViewModel.setProperty(1, "myValue", Config.readConfigInt("StartCash"));
|
||||
createLocalGameViewModel.setProperty(2, "myValue", "0");
|
||||
createLocalGameViewModel.setProperty(3, "myValue", Config.readConfigInt("GameSpeed"));
|
||||
createLocalGameViewModel.setProperty(4, "myValue", Config.readConfigInt("GameSpeed"));
|
||||
}
|
||||
}
|
||||
delegate: MyListViewDelegateFactory {
|
||||
myListViewsHeight: createLocalGameViewList.height
|
||||
|
||||
Reference in New Issue
Block a user