mirror of
https://github.com/JulianGro/overte.git
synced 2025-05-08 22:59:31 +02:00
Merge pull request #1502 from daleglass/qt5-fix-userdata
Remove deprecated usage of setUserData.
This commit is contained in:
commit
ec18f7a528
4 changed files with 160 additions and 153 deletions
|
@ -284,7 +284,7 @@ QQuickItem* OffscreenUi::createMessageBox(Icon icon, const QString& title, const
|
|||
map.insert("buttons", buttons.operator int());
|
||||
map.insert("defaultButton", defaultButton);
|
||||
QVariant result;
|
||||
bool invokeResult;
|
||||
bool invokeResult = false;
|
||||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
if (tablet->getToolbarMode() && _desktop) {
|
||||
|
@ -580,7 +580,7 @@ QQuickItem* OffscreenUi::createInputDialog(const Icon icon, const QString& title
|
|||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
|
||||
bool invokeResult;
|
||||
bool invokeResult = false;
|
||||
if (tablet->getToolbarMode() && _desktop) {
|
||||
invokeResult = QMetaObject::invokeMethod(_desktop, "inputDialog",
|
||||
Q_RETURN_ARG(QVariant, result),
|
||||
|
@ -608,7 +608,7 @@ QQuickItem* OffscreenUi::createCustomInputDialog(const Icon icon, const QString&
|
|||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
|
||||
bool invokeResult;
|
||||
bool invokeResult = false;
|
||||
if (tablet->getToolbarMode() && _desktop) {
|
||||
invokeResult = QMetaObject::invokeMethod(_desktop, "inputDialog",
|
||||
Q_RETURN_ARG(QVariant, result),
|
||||
|
@ -754,7 +754,7 @@ private slots:
|
|||
|
||||
QString OffscreenUi::fileDialog(const QVariantMap& properties) {
|
||||
QVariant buildDialogResult;
|
||||
bool invokeResult;
|
||||
bool invokeResult = false;
|
||||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
if (tablet->getToolbarMode() && _desktop) {
|
||||
|
@ -783,7 +783,7 @@ QString OffscreenUi::fileDialog(const QVariantMap& properties) {
|
|||
|
||||
ModalDialogListener* OffscreenUi::fileDialogAsync(const QVariantMap& properties) {
|
||||
QVariant buildDialogResult;
|
||||
bool invokeResult;
|
||||
bool invokeResult = false;
|
||||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
if (tablet->getToolbarMode() && _desktop) {
|
||||
|
@ -1003,7 +1003,7 @@ class AssetDialogListener : public ModalDialogListener {
|
|||
QString OffscreenUi::assetDialog(const QVariantMap& properties) {
|
||||
// ATP equivalent of fileDialog().
|
||||
QVariant buildDialogResult;
|
||||
bool invokeResult;
|
||||
bool invokeResult = false;
|
||||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
if (tablet->getToolbarMode() && _desktop) {
|
||||
|
@ -1033,7 +1033,7 @@ QString OffscreenUi::assetDialog(const QVariantMap& properties) {
|
|||
ModalDialogListener *OffscreenUi::assetDialogAsync(const QVariantMap& properties) {
|
||||
// ATP equivalent of fileDialog().
|
||||
QVariant buildDialogResult;
|
||||
bool invokeResult;
|
||||
bool invokeResult = false;
|
||||
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();
|
||||
TabletProxy* tablet = dynamic_cast<TabletProxy*>(tabletScriptingInterface->getTablet("com.highfidelity.interface.tablet.system"));
|
||||
if (tablet->getToolbarMode() && _desktop) {
|
||||
|
@ -1175,10 +1175,6 @@ bool OffscreenUi::eventFilter(QObject* originalDestination, QEvent* event) {
|
|||
return result;
|
||||
}
|
||||
|
||||
unsigned int OffscreenUi::getMenuUserDataId() const {
|
||||
return _vrMenu->_userDataId;
|
||||
}
|
||||
|
||||
ModalDialogListener::ModalDialogListener(QQuickItem *dialog) : _dialog(dialog) {
|
||||
if (!dialog) {
|
||||
_finished = true;
|
||||
|
|
|
@ -237,7 +237,6 @@ public:
|
|||
static ModalDialogListener* getTextAsync(const Icon icon, const QString & title, const QString & label, const QString & text = QString());
|
||||
static ModalDialogListener* getItemAsync(const Icon icon, const QString & title, const QString & label, const QStringList & items, int current = 0, bool editable = true);
|
||||
|
||||
unsigned int getMenuUserDataId() const;
|
||||
QList<QObject *> &getModalDialogListeners();
|
||||
|
||||
signals:
|
||||
|
|
|
@ -17,25 +17,15 @@
|
|||
#include "OffscreenUi.h"
|
||||
#include "ui/Logging.h"
|
||||
|
||||
static unsigned int USER_DATA_ID = 0;
|
||||
|
||||
// Binds together a Qt Action or Menu with the QML Menu or MenuItem
|
||||
//
|
||||
// TODO On reflection, it may be pointless to use the UUID. Perhaps
|
||||
// simply creating the bidirectional link pointing to both the widget
|
||||
// and qml object and inject the pointer into both objects
|
||||
class MenuUserData : public QObjectUserData {
|
||||
public:
|
||||
MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent) {
|
||||
if (!USER_DATA_ID) {
|
||||
USER_DATA_ID = DependencyManager::get<OffscreenUi>()->getMenuUserDataId();
|
||||
}
|
||||
|
||||
MenuUserData::MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent) {
|
||||
_action = action;
|
||||
_qml = qmlObject;
|
||||
_qmlParent = qmlParent;
|
||||
|
||||
action->setUserData(USER_DATA_ID, this);
|
||||
qmlObject->setUserData(USER_DATA_ID, this);
|
||||
action->setProperty(USER_DATA, QVariant::fromValue(this));
|
||||
qmlObject->setProperty(USER_DATA, QVariant::fromValue(this));
|
||||
qmlObject->setObjectName(uuid.toString());
|
||||
// Make sure we can find it again in the future
|
||||
updateQmlItemFromAction();
|
||||
|
@ -59,8 +49,7 @@ public:
|
|||
virtual bool eventFilter(QObject* o, QEvent* e) override {
|
||||
if (e->type() == QEvent::DynamicPropertyChange) {
|
||||
QDynamicPropertyChangeEvent* dpc = static_cast<QDynamicPropertyChangeEvent*>(e);
|
||||
if (dpc->propertyName() == "exclusionGroup")
|
||||
{
|
||||
if (dpc->propertyName() == "exclusionGroup") {
|
||||
// unfortunately Qt doesn't support passing dynamic properties between C++ / QML, so we have to use this ugly helper function
|
||||
QMetaObject::invokeMethod(_qmlParent,
|
||||
"addExclusionGroup",
|
||||
|
@ -82,14 +71,14 @@ public:
|
|||
new ExclusionGroupSetter(action, qmlObject, qmlParent);
|
||||
}
|
||||
|
||||
~MenuUserData() {
|
||||
MenuUserData::~MenuUserData() {
|
||||
QObject::disconnect(_changedConnection);
|
||||
QObject::disconnect(_shutdownConnection);
|
||||
_action->setUserData(USER_DATA_ID, nullptr);
|
||||
_qml->setUserData(USER_DATA_ID, nullptr);
|
||||
_action->setProperty(USER_DATA, QVariant());
|
||||
_qml->setProperty(USER_DATA, QVariant());
|
||||
}
|
||||
|
||||
void updateQmlItemFromAction() {
|
||||
void MenuUserData::updateQmlItemFromAction() {
|
||||
_qml->setProperty("checkable", _action->isCheckable());
|
||||
_qml->setProperty("enabled", _action->isEnabled());
|
||||
QString text = _action->text();
|
||||
|
@ -99,7 +88,7 @@ public:
|
|||
_qml->setProperty("visible", _action->isVisible());
|
||||
}
|
||||
|
||||
void clear() {
|
||||
void MenuUserData::clear() {
|
||||
_qml->setProperty("checkable", 0);
|
||||
_qml->setProperty("enabled", 0);
|
||||
_qml->setProperty("text", 0);
|
||||
|
@ -107,27 +96,26 @@ public:
|
|||
_qml->setProperty("checked", 0);
|
||||
_qml->setProperty("visible", 0);
|
||||
|
||||
_action->setUserData(USER_DATA_ID, nullptr);
|
||||
_qml->setUserData(USER_DATA_ID, nullptr);
|
||||
_action->setProperty(USER_DATA, QVariant());
|
||||
_qml->setProperty(USER_DATA, QVariant());
|
||||
}
|
||||
|
||||
|
||||
const QUuid uuid{ QUuid::createUuid() };
|
||||
|
||||
static bool hasData(QAction* object) {
|
||||
bool MenuUserData::hasData(QAction* object) {
|
||||
if (!object) {
|
||||
qWarning() << "Attempted to fetch MenuUserData for null object";
|
||||
return false;
|
||||
}
|
||||
return (nullptr != static_cast<MenuUserData*>(object->userData(USER_DATA_ID)));
|
||||
return (nullptr != object->property(USER_DATA).value<MenuUserData*>());
|
||||
}
|
||||
|
||||
static MenuUserData* forObject(QAction* object) {
|
||||
MenuUserData* MenuUserData::forObject(QAction* object) {
|
||||
if (!object) {
|
||||
qWarning() << "Attempted to fetch MenuUserData for null object";
|
||||
return nullptr;
|
||||
}
|
||||
auto result = static_cast<MenuUserData*>(object->userData(USER_DATA_ID));
|
||||
auto result = object->property(USER_DATA).value<MenuUserData*>();
|
||||
if (!result) {
|
||||
qWarning() << "Unable to find MenuUserData for object " << object;
|
||||
if (auto action = dynamic_cast<QAction*>(object)) {
|
||||
|
@ -140,17 +128,6 @@ public:
|
|||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(MenuUserData);
|
||||
|
||||
QMetaObject::Connection _shutdownConnection;
|
||||
QMetaObject::Connection _changedConnection;
|
||||
QAction* _action { nullptr };
|
||||
QObject* _qml { nullptr };
|
||||
QObject* _qmlParent{ nullptr };
|
||||
};
|
||||
|
||||
|
||||
VrMenu::VrMenu(OffscreenUi* parent) : QObject(parent) {
|
||||
_rootMenu = parent->getRootItem()->findChild<QObject*>("rootMenu");
|
||||
parent->getSurfaceContext()->setContextProperty("rootMenu", _rootMenu);
|
||||
|
|
|
@ -18,8 +18,44 @@
|
|||
#include <QSignalMapper>
|
||||
#include <QAction>
|
||||
#include <QMenu>
|
||||
#include <QUuid>
|
||||
#include "OffscreenUi.h"
|
||||
|
||||
|
||||
|
||||
// Binds together a Qt Action or Menu with the QML Menu or MenuItem
|
||||
//
|
||||
// TODO On reflection, it may be pointless to use the UUID. Perhaps
|
||||
// simply creating the bidirectional link pointing to both the widget
|
||||
// and qml object and inject the pointer into both objects
|
||||
class MenuUserData : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent);
|
||||
~MenuUserData();
|
||||
void updateQmlItemFromAction();
|
||||
void clear();
|
||||
|
||||
const QUuid uuid{ QUuid::createUuid() };
|
||||
|
||||
static bool hasData(QAction* object);
|
||||
|
||||
static MenuUserData* forObject(QAction* object);
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(MenuUserData);
|
||||
|
||||
static constexpr const char *USER_DATA{"user_data"};
|
||||
|
||||
QMetaObject::Connection _shutdownConnection;
|
||||
QMetaObject::Connection _changedConnection;
|
||||
QAction* _action { nullptr };
|
||||
QObject* _qml { nullptr };
|
||||
QObject* _qmlParent{ nullptr };
|
||||
};
|
||||
|
||||
|
||||
|
||||
// FIXME break up the rendering code (VrMenu) and the code for mirroring a Widget based menu in QML
|
||||
class VrMenu : public QObject {
|
||||
Q_OBJECT
|
||||
|
@ -37,7 +73,6 @@ protected:
|
|||
|
||||
friend class MenuUserData;
|
||||
friend class OffscreenUi;
|
||||
const unsigned int _userDataId { QObject::registerUserData() };
|
||||
};
|
||||
|
||||
#endif // hifi_VrMenu_h
|
||||
|
|
Loading…
Reference in a new issue