diff --git a/src/plugins/qmldesigner/components/bindingeditor/actioneditor.cpp b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.cpp index 256bfac1e9f..5336f6b4dd4 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/actioneditor.cpp +++ b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.cpp @@ -49,12 +49,10 @@ void ActionEditor::prepareDialog() s_lastActionEditor = this; - m_dialog = new ActionEditorDialog(Core::ICore::dialogParent()); + m_dialog = Utils::makeUniqueObjectPtr(Core::ICore::dialogParent()); - QObject::connect(m_dialog, &AbstractEditorDialog::accepted, - this, &ActionEditor::accepted); - QObject::connect(m_dialog, &AbstractEditorDialog::rejected, - this, &ActionEditor::rejected); + QObject::connect(m_dialog.get(), &AbstractEditorDialog::accepted, this, &ActionEditor::accepted); + QObject::connect(m_dialog.get(), &AbstractEditorDialog::rejected, this, &ActionEditor::rejected); m_dialog->setAttribute(Qt::WA_DeleteOnClose); } @@ -327,13 +325,13 @@ void ActionEditor::prepareConnections() for (const QmlModelState &state : QmlItemNode(m_modelNode.view()->rootModelNode()).states().allStates()) states.append(state.name()); - if (!connections.isEmpty() && !m_dialog.isNull()) + if (!connections.isEmpty() && m_dialog) m_dialog->setAllConnections(connections, singletons, states); } void ActionEditor::updateWindowName(const QString &targetName) { - if (!m_dialog.isNull()) { + if (m_dialog) { if (targetName.isEmpty()) m_dialog->setWindowTitle(m_dialog->defaultTitle()); else diff --git a/src/plugins/qmldesigner/components/bindingeditor/actioneditor.h b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.h index 9a14ad2117c..5cdee3e428c 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/actioneditor.h +++ b/src/plugins/qmldesigner/components/bindingeditor/actioneditor.h @@ -9,6 +9,8 @@ #include #include +#include + #include #include #include @@ -63,7 +65,7 @@ private: void prepareDialog(); private: - QPointer m_dialog; + Utils::UniqueObjectPtr m_dialog; QModelIndex m_index; QmlDesigner::ModelNode m_modelNode; }; diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp index b605a77191b..c03c31208fc 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp @@ -37,12 +37,10 @@ void BindingEditor::prepareDialog() { QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_BINDINGEDITOR_OPENED); - m_dialog = new BindingEditorDialog(Core::ICore::dialogParent()); + m_dialog = Utils::makeUniqueObjectPtr(Core::ICore::dialogParent()); - QObject::connect(m_dialog, &AbstractEditorDialog::accepted, - this, &BindingEditor::accepted); - QObject::connect(m_dialog, &AbstractEditorDialog::rejected, - this, &BindingEditor::rejected); + QObject::connect(m_dialog.get(), &AbstractEditorDialog::accepted, this, &BindingEditor::accepted); + QObject::connect(m_dialog.get(), &AbstractEditorDialog::rejected, this, &BindingEditor::rejected); m_dialog->setAttribute(Qt::WA_DeleteOnClose); } @@ -273,13 +271,13 @@ void BindingEditor::prepareBindings() } } - if (!bindings.isEmpty() && !m_dialog.isNull()) + if (!bindings.isEmpty() && m_dialog) m_dialog->setAllBindings(bindings, m_backendValueType); } void BindingEditor::updateWindowName() { - if (!m_dialog.isNull() && m_backendValueType) { + if (m_dialog && m_backendValueType) { QString targetString; if constexpr (useProjectStorage()) { auto exportedTypeNames = m_backendValueType.exportedTypeNamesForSourceId( diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h index 52aa0884f69..8ed49b2eb6f 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h @@ -8,6 +8,8 @@ #include #include +#include + #include #include #include @@ -72,7 +74,7 @@ private: void prepareDialog(); private: - QPointer m_dialog; + Utils::UniqueObjectPtr m_dialog; QVariant m_backendValue; QVariant m_modelNodeBackend; QVariant m_stateModelNode; diff --git a/src/plugins/qmldesigner/components/bindingeditor/signallist.cpp b/src/plugins/qmldesigner/components/bindingeditor/signallist.cpp index a4538b56c31..46470682519 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/signallist.cpp +++ b/src/plugins/qmldesigner/components/bindingeditor/signallist.cpp @@ -54,12 +54,8 @@ bool SignalListFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s || sourceModel()->data(signalIndex).toString().contains(filterRegularExpression())); } - - - SignalList::SignalList(QObject *) - : m_dialog(QPointer()) - , m_model(new SignalListModel(this)) + : m_model(Utils::makeUniqueObjectPtr(this)) , m_modelNode() { } @@ -71,9 +67,9 @@ SignalList::~SignalList() void SignalList::prepareDialog() { - m_dialog = new SignalListDialog(Core::ICore::dialogParent()); + m_dialog = Utils::makeUniqueObjectPtr(Core::ICore::dialogParent()); m_dialog->setAttribute(Qt::WA_DeleteOnClose); - m_dialog->initialize(m_model); + m_dialog->initialize(m_model.get()); m_dialog->setWindowTitle(::QmlDesigner::SignalList::tr("Signal List for %1") .arg(m_modelNode.validId())); @@ -98,13 +94,14 @@ void SignalList::hideWidget() SignalList* SignalList::showWidget(const ModelNode &modelNode) { - auto signalList = new SignalList(); + auto signalList = new SignalList; signalList->setModelNode(modelNode); signalList->prepareSignals(); signalList->showWidget(); - connect(signalList->m_dialog, &QDialog::destroyed, - [signalList]() { signalList->deleteLater(); } ); + connect(signalList->m_dialog.get(), &QDialog::destroyed, [signalList]() { + signalList->deleteLater(); + }); return signalList; } @@ -265,20 +262,24 @@ void SignalList::removeConnection(const QModelIndex &modelIndex) ModelNode node = targetSignal.parentModelNode(); if (node.isValid()) { - view->executeInTransaction("ConnectionModel::removeConnection", - [this, modelIndex, buttonModelIndex, targetSignal, &node] { - QList allSignals = node.signalProperties(); - if (allSignals.size() > 1) { - const auto targetSignalWithPrefix = SignalHandlerProperty::prefixAdded(targetSignal.name()); - for (const SignalHandlerProperty &signal : allSignals) - if (signal.name() == targetSignalWithPrefix) - node.removeProperty(targetSignalWithPrefix); - } else { - node.destroy(); - } - m_model->setConnected(modelIndex.row(), false); - m_model->setData(buttonModelIndex, QVariant(), SignalListModel::ConnectionsInternalIdRole); - }); + view->executeInTransaction( + "ConnectionModel::removeConnection", + [this, modelIndex, buttonModelIndex, targetSignal, &node] { + const QList allSignals = node.signalProperties(); + if (allSignals.size() > 1) { + const auto targetSignalWithPrefix = SignalHandlerProperty::prefixAdded( + targetSignal.name()); + for (const SignalHandlerProperty &signal : allSignals) + if (signal.name() == targetSignalWithPrefix) + node.removeProperty(targetSignalWithPrefix); + } else { + node.destroy(); + } + m_model->setConnected(modelIndex.row(), false); + m_model->setData(buttonModelIndex, + QVariant(), + SignalListModel::ConnectionsInternalIdRole); + }); } } diff --git a/src/plugins/qmldesigner/components/bindingeditor/signallist.h b/src/plugins/qmldesigner/components/bindingeditor/signallist.h index 228cb0e85ad..5842d445bb6 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/signallist.h +++ b/src/plugins/qmldesigner/components/bindingeditor/signallist.h @@ -8,6 +8,8 @@ #include #include +#include + #include #include #include @@ -74,8 +76,8 @@ private: void removeConnection(const QModelIndex &modelIndex); private: - QPointer m_dialog; - SignalListModel *m_model; + Utils::UniqueObjectPtr m_dialog; + Utils::UniqueObjectPtr m_model; ModelNode m_modelNode; };