History

Tablet#removeButton now works properly

Anthony J. Thibault committed 9 years ago

Commit 5d1ccfb1 parent 8b99fa95 files · +60 −45Browse files

Showing the changes to libraries/script-engine/src/TabletScriptingInterface.cpp (1 of 5 files). Show all

Unified · Split

libraries/script-engine/src/TabletScriptingInterface.cpp+18−25
@@ -12,7 +12,7 @@ · 11 unmodified lines
1212
1313 QObject* TabletScriptingInterface::getTablet(const QString& tabletId) {
1414
15− std::lock_guard<std::mutex> guard(_tabletProxiesMutex);
15+ std::lock_guard<std::mutex> guard(_mutex);
1616
1717 // look up tabletId in the map.
1818 auto iter = _tabletProxies.find(tabletId);
@@ -36,7 +36,6 @@ void TabletScriptingInterface::setQmlTablet(QString tabletId, QQuickItem* qmlTab · 17 unmodified lines
3636 }
3737 }
3838
39−
4039 //
4140 // TabletProxy
4241 //
@@ -64,24 +63,27 @@ static void addButtonProxyToQmlTablet(QQuickItem* qmlTablet, TabletButtonProxy* · 21 unmodified lines
6463 return;
6564 }
6665 QObject::connect(qmlButton, SIGNAL(clicked()), buttonProxy, SLOT(clickedSlot()));
66+ buttonProxy->setQmlButton(qobject_cast<QQuickItem*>(qmlButton));
6767 }
6868
6969 void TabletProxy::setQmlTablet(QQuickItem* qmlTablet) {
70+ std::lock_guard<std::mutex> guard(_mutex);
7071 if (qmlTablet) {
7172 _qmlTablet = qmlTablet;
72− std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
7373 for (auto& buttonProxy : _tabletButtonProxies) {
7474 addButtonProxyToQmlTablet(_qmlTablet, buttonProxy.data());
7575 }
7676 } else {
77+ for (auto& buttonProxy : _tabletButtonProxies) {
78+ buttonProxy->setQmlButton(nullptr);
79+ }
7780 _qmlTablet = nullptr;
7881 }
79−
8082 }
8183
8284 QObject* TabletProxy::addButton(const QVariant& properties) {
8385 auto tabletButtonProxy = QSharedPointer<TabletButtonProxy>(new TabletButtonProxy(properties.toMap()));
84− std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
86+ std::lock_guard<std::mutex> guard(_mutex);
8587 _tabletButtonProxies.push_back(tabletButtonProxy);
8688 if (_qmlTablet) {
8789 addButtonProxyToQmlTablet(_qmlTablet, tabletButtonProxy.data());
@@ -90,11 +92,12 @@ QObject* TabletProxy::addButton(const QVariant& properties) { · 2 unmodified lines
9092 }
9193
9294 void TabletProxy::removeButton(QObject* tabletButtonProxy) {
93− std::lock_guard<std::mutex> guard(_tabletButtonProxiesMutex);
95+ std::lock_guard<std::mutex> guard(_mutex);
9496 auto iter = std::find(_tabletButtonProxies.begin(), _tabletButtonProxies.end(), tabletButtonProxy);
9597 if (iter != _tabletButtonProxies.end()) {
9698 if (_qmlTablet) {
97− QMetaObject::invokeMethod(_qmlTablet, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
99+ (*iter)->setQmlButton(nullptr);
100+ QMetaObject::invokeMethod(_qmlTablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, (*iter)->getProperties()));
98101 }
99102 _tabletButtonProxies.erase(iter);
100103 } else {
@@ -106,28 +109,18 @@ void TabletProxy::removeButton(QObject* tabletButtonProxy) { · 5 unmodified lines
106109 // TabletButtonProxy
107110 //
108111
109−TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _properties(properties) {
110− ;
111−}
112+const QString UUID_KEY = "uuid";
112113
113−void TabletButtonProxy::setInitRequestHandler(const QScriptValue& handler) {
114− _initRequestHandler = handler;
114+TabletButtonProxy::TabletButtonProxy(const QVariantMap& properties) : _uuid(QUuid::createUuid()), _properties(properties) {
115+ // this is used to uniquely identify this button.
116+ _properties[UUID_KEY] = _uuid;
115117 }
116118
117−// TABLET_UI_HACK remove
118−/*
119−static QString IMAGE_URL_KEY = "imageUrl";
120−static QString IMAGE_URL_DEFAULT = "";
121−
122−QString TabletButtonProxy::getImageUrl() const {
123− std::lock_guard<std::mutex> guard(_propertiesMutex);
124− return _properties.value(IMAGE_URL_KEY, IMAGE_URL_DEFAULT).toString();
119+void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) {
120+ std::lock_guard<std::mutex> guard(_mutex);
121+ _qmlButton = qmlButton;
125122 }
126123
127−void TabletButtonProxy::setImageUrl(QString imageUrl) {
128− std::lock_guard<std::mutex> guard(_propertiesMutex);
129− _properties[IMAGE_URL_KEY] = imageUrl;
130−}
131−*/
124+// TABLET_UI_HACK TODO: add property accessors, and forward property changes to the _qmlButton if present.
132125
133126 #include "TabletScriptingInterface.moc"