forked from qt-creator/qt-creator
QmlDesigner: Add explicit ownership to binding editor
It is much better to desribe the ownership explicitly instead of using the hard to read parent child mechanism. Change-Id: I488a6ca1fb08f4bf3b3a540c0bb7d9ffb03895d0 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -49,12 +49,10 @@ void ActionEditor::prepareDialog()
|
||||
|
||||
s_lastActionEditor = this;
|
||||
|
||||
m_dialog = new ActionEditorDialog(Core::ICore::dialogParent());
|
||||
m_dialog = Utils::makeUniqueObjectPtr<ActionEditorDialog>(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
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
#include <modelnode.h>
|
||||
#include <signalhandlerproperty.h>
|
||||
|
||||
#include <utils/uniqueobjectptr.h>
|
||||
|
||||
#include <QtQml>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
@@ -63,7 +65,7 @@ private:
|
||||
void prepareDialog();
|
||||
|
||||
private:
|
||||
QPointer<ActionEditorDialog> m_dialog;
|
||||
Utils::UniqueObjectPtr<ActionEditorDialog> m_dialog;
|
||||
QModelIndex m_index;
|
||||
QmlDesigner::ModelNode m_modelNode;
|
||||
};
|
||||
|
||||
@@ -37,12 +37,10 @@ void BindingEditor::prepareDialog()
|
||||
{
|
||||
QmlDesignerPlugin::emitUsageStatistics(Constants::EVENT_BINDINGEDITOR_OPENED);
|
||||
|
||||
m_dialog = new BindingEditorDialog(Core::ICore::dialogParent());
|
||||
m_dialog = Utils::makeUniqueObjectPtr<BindingEditorDialog>(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(
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <qmldesignercorelib_global.h>
|
||||
#include <modelnode.h>
|
||||
|
||||
#include <utils/uniqueobjectptr.h>
|
||||
|
||||
#include <QtQml>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
@@ -72,7 +74,7 @@ private:
|
||||
void prepareDialog();
|
||||
|
||||
private:
|
||||
QPointer<BindingEditorDialog> m_dialog;
|
||||
Utils::UniqueObjectPtr<BindingEditorDialog> m_dialog;
|
||||
QVariant m_backendValue;
|
||||
QVariant m_modelNodeBackend;
|
||||
QVariant m_stateModelNode;
|
||||
|
||||
@@ -54,12 +54,8 @@ bool SignalListFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
|
||||
|| sourceModel()->data(signalIndex).toString().contains(filterRegularExpression()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
SignalList::SignalList(QObject *)
|
||||
: m_dialog(QPointer<SignalListDialog>())
|
||||
, m_model(new SignalListModel(this))
|
||||
: m_model(Utils::makeUniqueObjectPtr<SignalListModel>(this))
|
||||
, m_modelNode()
|
||||
{
|
||||
}
|
||||
@@ -71,9 +67,9 @@ SignalList::~SignalList()
|
||||
|
||||
void SignalList::prepareDialog()
|
||||
{
|
||||
m_dialog = new SignalListDialog(Core::ICore::dialogParent());
|
||||
m_dialog = Utils::makeUniqueObjectPtr<SignalListDialog>(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<SignalHandlerProperty> 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<SignalHandlerProperty> 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <modelnode.h>
|
||||
#include <qmlconnections.h>
|
||||
|
||||
#include <utils/uniqueobjectptr.h>
|
||||
|
||||
#include <QtQml>
|
||||
#include <QObject>
|
||||
#include <QPointer>
|
||||
@@ -74,8 +76,8 @@ private:
|
||||
void removeConnection(const QModelIndex &modelIndex);
|
||||
|
||||
private:
|
||||
QPointer<SignalListDialog> m_dialog;
|
||||
SignalListModel *m_model;
|
||||
Utils::UniqueObjectPtr<SignalListDialog> m_dialog;
|
||||
Utils::UniqueObjectPtr<SignalListModel> m_model;
|
||||
ModelNode m_modelNode;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user