Fix bad invocation, cleanup signatures

This commit is contained in:
Brad Davis 2017-06-23 09:58:27 -07:00
parent d50c448151
commit 341646c780
2 changed files with 27 additions and 40 deletions

View file

@ -182,7 +182,7 @@ class TabletRootWindow : public QmlWindowClass {
virtual QString qmlSource() const override { return "hifi/tablet/WindowRoot.qml"; } virtual QString qmlSource() const override { return "hifi/tablet/WindowRoot.qml"; }
}; };
TabletProxy::TabletProxy(QObject* parent, QString name) : QObject(parent), _name(name) { TabletProxy::TabletProxy(QObject* parent, const QString& name) : QObject(parent), _name(name) {
if (QThread::currentThread() != qApp->thread()) { if (QThread::currentThread() != qApp->thread()) {
qCWarning(uiLogging) << "Creating tablet proxy on wrong thread " << _name; qCWarning(uiLogging) << "Creating tablet proxy on wrong thread " << _name;
} }
@ -306,7 +306,7 @@ bool TabletProxy::isMessageDialogOpen() {
return result.toBool(); return result.toBool();
} }
void TabletProxy::emitWebEvent(QVariant msg) { void TabletProxy::emitWebEvent(const QVariant& msg) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "emitWebEvent", Q_ARG(QVariant, msg)); QMetaObject::invokeMethod(this, "emitWebEvent", Q_ARG(QVariant, msg));
return; return;
@ -314,7 +314,7 @@ void TabletProxy::emitWebEvent(QVariant msg) {
emit webEventReceived(msg); emit webEventReceived(msg);
} }
bool TabletProxy::isPathLoaded(QVariant path) { bool TabletProxy::isPathLoaded(const QVariant& path) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
bool result = false; bool result = false;
QMetaObject::invokeMethod(this, "isPathLoaded", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, result), Q_ARG(QVariant, path)); QMetaObject::invokeMethod(this, "isPathLoaded", Qt::BlockingQueuedConnection, Q_RETURN_ARG(bool, result), Q_ARG(QVariant, path));
@ -620,8 +620,7 @@ TabletButtonProxy* TabletProxy::addButton(const QVariant& properties) {
qCCritical(uiLogging) << "Could not find tablet in TabletRoot.qml"; qCCritical(uiLogging) << "Could not find tablet in TabletRoot.qml";
} }
} else if (_toolbarMode) { } else if (_toolbarMode) {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); auto toolbarProxy = DependencyManager::get<TabletScriptingInterface>()->getSystemToolbarProxy();
auto toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
if (toolbarProxy) { if (toolbarProxy) {
// copy properties from tablet button proxy to toolbar button proxy. // copy properties from tablet button proxy to toolbar button proxy.
toolbarProxy->addButton(tabletButtonProxy->getProperties()); toolbarProxy->addButton(tabletButtonProxy->getProperties());
@ -668,15 +667,16 @@ void TabletProxy::removeButton(TabletButtonProxy* tabletButtonProxy) {
QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getProperties())); QMetaObject::invokeMethod(tablet, "removeButtonProxy", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getProperties()));
} }
} else if (_toolbarMode) { } else if (_toolbarMode) {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); auto toolbarProxy = DependencyManager::get<TabletScriptingInterface>()->getSystemToolbarProxy();
QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy();
// remove button from toolbarProxy // remove button from toolbarProxy
QMetaObject::invokeMethod(toolbarProxy, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getUuid().toString())); if (toolbarProxy) {
buttonProxy->setToolbarButtonProxy(nullptr); toolbarProxy->removeButton(buttonProxy->getUuid().toString());
buttonProxy->setToolbarButtonProxy(nullptr);
}
} }
} }
void TabletProxy::emitScriptEvent(QVariant msg) { void TabletProxy::emitScriptEvent(const QVariant& msg) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "emitScriptEvent", Q_ARG(QVariant, msg)); QMetaObject::invokeMethod(this, "emitScriptEvent", Q_ARG(QVariant, msg));
return; return;
@ -689,7 +689,7 @@ void TabletProxy::emitScriptEvent(QVariant msg) {
} }
} }
void TabletProxy::sendToQml(QVariant msg) { void TabletProxy::sendToQml(const QVariant& msg) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "sendToQml", Q_ARG(QVariant, msg)); QMetaObject::invokeMethod(this, "sendToQml", Q_ARG(QVariant, msg));
return; return;
@ -707,8 +707,6 @@ void TabletProxy::addButtonsToHomeScreen() {
if (!tablet || _toolbarMode) { if (!tablet || _toolbarMode) {
return; return;
} }
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
for (auto& buttonProxy : _tabletButtonProxies) { for (auto& buttonProxy : _tabletButtonProxies) {
addButtonProxyToQmlTablet(tablet, buttonProxy.data()); addButtonProxyToQmlTablet(tablet, buttonProxy.data());
} }
@ -735,35 +733,23 @@ void TabletProxy::desktopWindowClosed() {
} }
void TabletProxy::addButtonsToToolbar() { void TabletProxy::addButtonsToToolbar() {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); Q_ASSERT(QThread::currentThread() == thread());
QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); ToolbarProxy* toolbarProxy = DependencyManager::get<TabletScriptingInterface>()->getSystemToolbarProxy();
Qt::ConnectionType connectionType = Qt::AutoConnection;
if (QThread::currentThread() != toolbarProxy->thread()) {
connectionType = Qt::BlockingQueuedConnection;
}
for (auto& buttonProxy : _tabletButtonProxies) { for (auto& buttonProxy : _tabletButtonProxies) {
// copy properties from tablet button proxy to toolbar button proxy. // copy properties from tablet button proxy to toolbar button proxy.
QObject* toolbarButtonProxy = nullptr; buttonProxy->setToolbarButtonProxy(toolbarProxy->addButton(buttonProxy->getProperties()));
bool hasResult = QMetaObject::invokeMethod(toolbarProxy, "addButton", connectionType, Q_RETURN_ARG(QObject*, toolbarButtonProxy), Q_ARG(QVariant, buttonProxy->getProperties()));
if (hasResult) {
buttonProxy->setToolbarButtonProxy(toolbarButtonProxy);
} else {
qCWarning(uiLogging) << "ToolbarProxy addButton has no result";
}
} }
// make the toolbar visible // make the toolbar visible
QMetaObject::invokeMethod(toolbarProxy, "writeProperty", Qt::AutoConnection, Q_ARG(QString, "visible"), Q_ARG(QVariant, QVariant(true))); toolbarProxy->writeProperty("visible", QVariant(true));
} }
void TabletProxy::removeButtonsFromToolbar() { void TabletProxy::removeButtonsFromToolbar() {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>(); Q_ASSERT(QThread::currentThread() == thread());
QObject* toolbarProxy = tabletScriptingInterface->getSystemToolbarProxy(); ToolbarProxy* toolbarProxy = DependencyManager::get<TabletScriptingInterface>()->getSystemToolbarProxy();
for (auto& buttonProxy : _tabletButtonProxies) { for (auto& buttonProxy : _tabletButtonProxies) {
// remove button from toolbarProxy // remove button from toolbarProxy
QMetaObject::invokeMethod(toolbarProxy, "removeButton", Qt::AutoConnection, Q_ARG(QVariant, buttonProxy->getUuid().toString())); toolbarProxy->removeButton(buttonProxy->getUuid().toString());
buttonProxy->setToolbarButtonProxy(nullptr); buttonProxy->setToolbarButtonProxy(nullptr);
} }
} }
@ -843,6 +829,7 @@ void TabletButtonProxy::setQmlButton(QQuickItem* qmlButton) {
} }
void TabletButtonProxy::setToolbarButtonProxy(QObject* toolbarButtonProxy) { void TabletButtonProxy::setToolbarButtonProxy(QObject* toolbarButtonProxy) {
Q_ASSERT(QThread::currentThread() == thread());
_toolbarButtonProxy = toolbarButtonProxy; _toolbarButtonProxy = toolbarButtonProxy;
if (_toolbarButtonProxy) { if (_toolbarButtonProxy) {
QObject::connect(_toolbarButtonProxy, SIGNAL(clicked()), this, SLOT(clickedSlot())); QObject::connect(_toolbarButtonProxy, SIGNAL(clicked()), this, SLOT(clickedSlot()));
@ -859,9 +846,9 @@ QVariantMap TabletButtonProxy::getProperties() {
return _properties; return _properties;
} }
void TabletButtonProxy::editProperties(QVariantMap properties) { void TabletButtonProxy::editProperties(const QVariantMap& properties) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "editProperties", Qt::BlockingQueuedConnection, Q_ARG(QVariantMap, properties)); QMetaObject::invokeMethod(this, "editProperties", Q_ARG(QVariantMap, properties));
return; return;
} }

View file

@ -95,7 +95,7 @@ class TabletProxy : public QObject {
Q_PROPERTY(bool landscape READ getLandscape WRITE setLandscape) Q_PROPERTY(bool landscape READ getLandscape WRITE setLandscape)
Q_PROPERTY(bool tabletShown MEMBER _tabletShown NOTIFY tabletShownChanged) Q_PROPERTY(bool tabletShown MEMBER _tabletShown NOTIFY tabletShownChanged)
public: public:
TabletProxy(QObject* parent, QString name); TabletProxy(QObject* parent, const QString& name);
~TabletProxy(); ~TabletProxy();
void setQmlTabletRoot(OffscreenQmlSurface* offscreenQmlSurface); void setQmlTabletRoot(OffscreenQmlSurface* offscreenQmlSurface);
@ -163,14 +163,14 @@ public:
* @function TabletProxy#emitScriptEvent * @function TabletProxy#emitScriptEvent
* @param msg {object|string} * @param msg {object|string}
*/ */
Q_INVOKABLE void emitScriptEvent(QVariant msg); Q_INVOKABLE void emitScriptEvent(const QVariant& msg);
/**jsdoc /**jsdoc
* Used to send an event to the qml embedded in the tablet * Used to send an event to the qml embedded in the tablet
* @function TabletProxy#sendToQml * @function TabletProxy#sendToQml
* @param msg {object|string} * @param msg {object|string}
*/ */
Q_INVOKABLE void sendToQml(QVariant msg); Q_INVOKABLE void sendToQml(const QVariant& msg);
/**jsdoc /**jsdoc
* Check if the tablet is on the homescreen * Check if the tablet is on the homescreen
@ -186,7 +186,7 @@ public:
Q_INVOKABLE void setLandscape(bool landscape) { _landscape = landscape; } Q_INVOKABLE void setLandscape(bool landscape) { _landscape = landscape; }
Q_INVOKABLE bool getLandscape() { return _landscape; } Q_INVOKABLE bool getLandscape() { return _landscape; }
Q_INVOKABLE bool isPathLoaded(QVariant path); Q_INVOKABLE bool isPathLoaded(const QVariant& path);
QQuickItem* getTabletRoot() const { return _qmlTabletRoot; } QQuickItem* getTabletRoot() const { return _qmlTabletRoot; }
@ -231,7 +231,7 @@ signals:
protected slots: protected slots:
void addButtonsToHomeScreen(); void addButtonsToHomeScreen();
void desktopWindowClosed(); void desktopWindowClosed();
void emitWebEvent(QVariant msg); void emitWebEvent(const QVariant& msg);
protected: protected:
void removeButtonsFromHomeScreen(); void removeButtonsFromHomeScreen();
void loadHomeScreen(bool forceOntoHomeScreen); void loadHomeScreen(bool forceOntoHomeScreen);
@ -284,7 +284,7 @@ public:
* @function TabletButtonProxy#editProperties * @function TabletButtonProxy#editProperties
* @param {ButtonProperties} properties - set of properties to change * @param {ButtonProperties} properties - set of properties to change
*/ */
Q_INVOKABLE void editProperties(QVariantMap properties); Q_INVOKABLE void editProperties(const QVariantMap& properties);
public slots: public slots:
void clickedSlot() { emit clicked(); } void clickedSlot() { emit clicked(); }