Showing the changes to interface/src/scripting/ToolbarScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -8,58 +8,11 @@ · 7 unmodified lines | ||
| 8 | 8 | |
| 9 | 9 | #include "ToolbarScriptingInterface.h" |
| 10 | 10 | |
| 11 | + | |
| 11 | 12 | #include <QtCore/QThread> |
| 12 | 13 | |
| 13 | 14 | #include <OffscreenUi.h> |
| 14 | − | |
| 15 | −class QmlWrapper : public QObject { | |
| 16 | − Q_OBJECT | |
| 17 | −public: | |
| 18 | − QmlWrapper(QObject* qmlObject, QObject* parent = nullptr) | |
| 19 | − : QObject(parent), _qmlObject(qmlObject) { | |
| 20 | − } | |
| 21 | − | |
| 22 | − Q_INVOKABLE void writeProperty(QString propertyName, QVariant propertyValue) { | |
| 23 | − auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 24 | − offscreenUi->executeOnUiThread([=] { | |
| 25 | − _qmlObject->setProperty(propertyName.toStdString().c_str(), propertyValue); | |
| 26 | − }); | |
| 27 | − } | |
| 28 | − | |
| 29 | − Q_INVOKABLE void writeProperties(QVariant propertyMap) { | |
| 30 | − auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 31 | − offscreenUi->executeOnUiThread([=] { | |
| 32 | − QVariantMap map = propertyMap.toMap(); | |
| 33 | − for (const QString& key : map.keys()) { | |
| 34 | − _qmlObject->setProperty(key.toStdString().c_str(), map[key]); | |
| 35 | − } | |
| 36 | − }); | |
| 37 | − } | |
| 38 | − | |
| 39 | − Q_INVOKABLE QVariant readProperty(const QString& propertyName) { | |
| 40 | − auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 41 | − return offscreenUi->returnFromUiThread([&]()->QVariant { | |
| 42 | − return _qmlObject->property(propertyName.toStdString().c_str()); | |
| 43 | − }); | |
| 44 | − } | |
| 45 | − | |
| 46 | − Q_INVOKABLE QVariant readProperties(const QVariant& propertyList) { | |
| 47 | − auto offscreenUi = DependencyManager::get<OffscreenUi>(); | |
| 48 | − return offscreenUi->returnFromUiThread([&]()->QVariant { | |
| 49 | − QVariantMap result; | |
| 50 | − for (const QVariant& property : propertyList.toList()) { | |
| 51 | − QString propertyString = property.toString(); | |
| 52 | − result.insert(propertyString, _qmlObject->property(propertyString.toStdString().c_str())); | |
| 53 | − } | |
| 54 | − return result; | |
| 55 | − }); | |
| 56 | − } | |
| 57 | − | |
| 58 | − | |
| 59 | −protected: | |
| 60 | − QObject* _qmlObject{ nullptr }; | |
| 61 | −}; | |
| 62 | − | |
| 15 | +#include "QmlWrapper.h" | |
| 63 | 16 | |
| 64 | 17 | class ToolbarButtonProxy : public QmlWrapper { |
| 65 | 18 | Q_OBJECT |