diff options
4 files changed, 86 insertions, 5 deletions
diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir index 10f92a578a..40241fe958 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/HelperWidgets/qmldir @@ -39,3 +39,4 @@ TabView 2.0 TabView.qml ToolTipArea 2.0 ToolTipArea.qml UrlChooser 2.0 UrlChooser.qml PaddingSection 2.0 PaddingSection.qml +RoundedPanel 2.0 RoundedPanel.qml diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml index 073364685b..92d2b8b10d 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml @@ -53,9 +53,50 @@ Rectangle { SecondColumnLayout { - Label { - text: backendValues.className.value - width: lineEdit.width + RoundedPanel { + Layout.fillWidth: true + height: 24 + + Label { + x: 6 + anchors.fill: parent + anchors.leftMargin: 16 + + text: backendValues.className.value + verticalAlignment: Text.AlignVCenter + } + ToolTipArea { + anchors.fill: parent + onDoubleClicked: { + typeLineEdit.visible = ! typeLineEdit.visible + typeLineEdit.forceActiveFocus() + } + tooltip: qsTr("Change the type of this item.") + } + + LineEdit { + id: typeLineEdit + + anchors.fill: parent + + visible: false + + backendValue: className.id + + text: backendValues.className.value + + showTranslateCheckBox: false + showExtendedFunctionButton: false + onEditingFinished: { + visible = false + changeTypeName(typeLineEdit.text) + } + } + + } + Item { + Layout.preferredWidth: 16 + Layout.preferredHeight: 16 } } diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp index 12d716c410..fd82dacc2f 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp @@ -26,12 +26,15 @@ #include "propertyeditorcontextobject.h" #include <abstractview.h> - -#include <QQmlContext> +#include <nodemetainfo.h> #include <qmldesignerplugin.h> #include <qmlobjectnode.h> #include <rewritingexception.h> +#include <coreplugin/messagebox.h> + +#include <QQmlContext> + static uchar fromHex(const uchar c, const uchar c2) { uchar rv = 0; @@ -156,6 +159,40 @@ void PropertyEditorContextObject::toogleExportAlias() } +void PropertyEditorContextObject::changeTypeName(const QString &typeName) +{ + + if (!m_model || !m_model->rewriterView()) + return; + + /* Ideally we should not missuse the rewriterView + * If we add more code here we have to forward the property editor view */ + RewriterView *rewriterView = m_model->rewriterView(); + + if (rewriterView->selectedModelNodes().isEmpty()) + return; + + ModelNode selectedNode = rewriterView->selectedModelNodes().first(); + + try { + RewriterTransaction transaction = + rewriterView->beginRewriterTransaction(QByteArrayLiteral("PropertyEditorContextObject:changeTypeName")); + + NodeMetaInfo metaInfo = m_model->metaInfo(typeName.toLatin1()); + if (!metaInfo.isValid()) { + Core::AsynchronousMessageBox::warning(tr("Invalid Type"), tr("%1 is an invalid type.").arg(typeName)); + return; + } + selectedNode.changeType(metaInfo.typeName(), metaInfo.majorVersion(), metaInfo.minorVersion()); + + transaction.commit(); + } catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail + exception.showException(); + } + + +} + int PropertyEditorContextObject::majorVersion() const { return m_majorVersion; diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h index ae79d9bd86..004f653ac7 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h @@ -80,6 +80,8 @@ public: Q_INVOKABLE void toogleExportAlias(); + Q_INVOKABLE void changeTypeName(const QString &typeName); + int majorVersion() const; int majorQtQuickVersion() const; int minorQtQuickVersion() const; |