QmlDesigner: Edit ChooseTexturePropertyDialog to accept any type

When creating a new component by dropping it to a component in the
navigator, check the parent if it contains properties that are the
same or sub type as the new created component. Those properties are
shown in a list that the created component can be binded to.

This edits the dialog that was for textures only and uses it for any
component on creation.

Task-number: QDS-4969
Change-Id: I3f1ecc6a82254f77a9bb170406ef79740359a889
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tony Leinonen
2021-08-31 08:54:21 +03:00
parent 0061555213
commit 9891f3b268
7 changed files with 56 additions and 34 deletions

View File

@@ -344,8 +344,8 @@ extend_qtc_plugin(QmlDesigner
navigatortreeview.cpp navigatortreeview.h
navigatorview.cpp navigatorview.h
navigatorwidget.cpp navigatorwidget.h
choosetexturepropertydialog.cpp choosetexturepropertydialog.h
choosetexturepropertydialog.ui
choosefrompropertylistdialog.cpp choosefrompropertylistdialog.h
choosefrompropertylistdialog.ui
previewtooltip.cpp previewtooltip.h
previewtooltip.ui
)

View File

@@ -23,20 +23,22 @@
**
****************************************************************************/
#include "choosetexturepropertydialog.h"
#include "choosefrompropertylistdialog.h"
#include "nodemetainfo.h"
#include "ui_choosetexturepropertydialog.h"
#include "ui_choosefrompropertylistdialog.h"
namespace QmlDesigner {
// This dialog displays all texture properties of an object and allows the user to choose one
ChooseTexturePropertyDialog::ChooseTexturePropertyDialog(const ModelNode &node, QWidget *parent)
// This dialog displays all given type properties of an object and allows the user to choose one
ChooseFromPropertyListDialog::ChooseFromPropertyListDialog(const ModelNode &node, TypeName type, QWidget *parent)
: QDialog(parent)
, m_ui(new Ui::ChooseTexturePropertyDialog)
, m_ui(new Ui::ChooseFromPropertyListDialog)
{
m_propertyTypeName = type;
m_ui->setupUi(this);
setWindowTitle(tr("Select Texture Property"));
m_ui->label->setText(tr("Set texture to property:"));
setWindowTitle(tr("Select property"));
m_ui->label->setText(tr("Bind to property:"));
m_ui->label->setToolTip(tr("Binds this component to the parent's selected property."));
setFixedSize(size());
connect(m_ui->listProps, &QListWidget::itemClicked, this, [this](QListWidgetItem *item) {
@@ -51,25 +53,25 @@ ChooseTexturePropertyDialog::ChooseTexturePropertyDialog(const ModelNode &node,
fillList(node);
}
ChooseTexturePropertyDialog::~ChooseTexturePropertyDialog()
ChooseFromPropertyListDialog::~ChooseFromPropertyListDialog()
{
delete m_ui;
}
TypeName ChooseTexturePropertyDialog::selectedProperty() const
TypeName ChooseFromPropertyListDialog::selectedProperty() const
{
return m_selectedProperty;
}
void ChooseTexturePropertyDialog::fillList(const ModelNode &node)
void ChooseFromPropertyListDialog::fillList(const ModelNode &node)
{
// Fill the list with all properties of type Texture
// Fill the list with all properties of given type
const auto metaInfo = node.metaInfo();
const auto propNames = metaInfo.propertyNames();
const TypeName textureProp("QtQuick3D.Texture");
const TypeName property(m_propertyTypeName);
QStringList nameList;
for (const auto &propName : propNames) {
if (metaInfo.propertyTypeName(propName) == textureProp)
if (metaInfo.propertyTypeName(propName) == property)
nameList.append(QString::fromLatin1(propName));
}

View File

@@ -32,23 +32,24 @@
namespace QmlDesigner {
namespace Ui {
class ChooseTexturePropertyDialog;
class ChooseFromPropertyListDialog;
}
class ChooseTexturePropertyDialog : public QDialog
class ChooseFromPropertyListDialog : public QDialog
{
Q_OBJECT
public:
explicit ChooseTexturePropertyDialog(const ModelNode &node, QWidget *parent = 0);
~ChooseTexturePropertyDialog();
explicit ChooseFromPropertyListDialog(const ModelNode &node, TypeName type, QWidget *parent = 0);
~ChooseFromPropertyListDialog();
TypeName selectedProperty() const;
private:
void fillList(const ModelNode &node);
Ui::ChooseTexturePropertyDialog *m_ui;
Ui::ChooseFromPropertyListDialog *m_ui;
TypeName m_selectedProperty;
TypeName m_propertyTypeName;
};
}

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QmlDesigner::ChooseTexturePropertyDialog</class>
<widget class="QDialog" name="QmlDesigner::ChooseTexturePropertyDialog">
<class>QmlDesigner::ChooseFromPropertyListDialog</class>
<widget class="QDialog" name="QmlDesigner::ChooseFromPropertyListDialog">
<property name="geometry">
<rect>
<x>0</x>
@@ -77,7 +77,7 @@
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>QmlDesigner::ChooseTexturePropertyDialog</receiver>
<receiver>QmlDesigner::ChooseFromPropertyListDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
@@ -93,7 +93,7 @@
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QmlDesigner::ChooseTexturePropertyDialog</receiver>
<receiver>QmlDesigner::ChooseFromPropertyListDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">

View File

@@ -6,7 +6,7 @@ SOURCES += navigatorview.cpp \
nameitemdelegate.cpp \
iconcheckboxitemdelegate.cpp \
navigatortreeview.cpp \
choosetexturepropertydialog.cpp \
choosefrompropertylistdialog.cpp \
previewtooltip.cpp
HEADERS += navigatorview.h \
@@ -16,10 +16,10 @@ HEADERS += navigatorview.h \
iconcheckboxitemdelegate.h \
navigatortreeview.h \
navigatormodelinterface.h \
choosetexturepropertydialog.h \
choosefrompropertylistdialog.h \
previewtooltip.h
RESOURCES += navigator.qrc
FORMS += choosetexturepropertydialog.ui \
FORMS += choosefrompropertylistdialog.ui \
previewtooltip.ui

View File

@@ -25,7 +25,7 @@
#include "navigatortreemodel.h"
#include "navigatorview.h"
#include "choosetexturepropertydialog.h"
#include "choosefrompropertylistdialog.h"
#include "qmldesignerplugin.h"
#include "itemlibrarywidget.h"
@@ -700,7 +700,8 @@ void NavigatorTreeModel::handleItemLibraryItemDrop(const QMimeData *mimeData, in
// notify user with a helpful messagebox that suggests the correct action.
showMatToCompInfo = true;
}
} else {
} else if (newModelNode.isSubclassOf("QtQuick3D.Shader")
|| newModelNode.isSubclassOf("QtQuick3D.Command")) {
const bool isShader = newModelNode.isSubclassOf("QtQuick3D.Shader");
if (isShader || newModelNode.isSubclassOf("QtQuick3D.Command")) {
if (targetProperty.parentModelNode().isSubclassOf("QtQuick3D.Pass")) {
@@ -727,7 +728,25 @@ void NavigatorTreeModel::handleItemLibraryItemDrop(const QMimeData *mimeData, in
}
}
}
} else {
ModelNode targetNode = targetProperty.parentModelNode();
NodeMetaInfo metaInfo = targetNode.metaInfo();
TypeName typeName = newModelNode.type();
const PropertyNameList nameList = targetNode.metaInfo().directPropertyNames();
for (const auto &propertyName : nameList) {
auto testType = metaInfo.propertyTypeName(propertyName);
if (testType == typeName || newModelNode.isSubclassOf(testType)) {
ChooseFromPropertyListDialog *dialog = nullptr;
dialog = new ChooseFromPropertyListDialog(targetNode, testType, Core::ICore::dialogParent());
dialog->exec();
if (!dialog || dialog->result() == QDialog::Accepted)
targetNode.bindingProperty(dialog->selectedProperty()).setExpression(newModelNode.validId());
delete dialog;
break;
}
}
}
if (!validContainer) {
if (!showMatToCompInfo)
validContainer = NodeHints::fromModelNode(targetProperty.parentModelNode()).canBeContainerFor(newModelNode);
@@ -982,10 +1001,10 @@ bool NavigatorTreeModel::dropAsImage3dTexture(const ModelNode &targetNode,
{
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
// if dropping an image on a default material, create a texture instead of image
ChooseTexturePropertyDialog *dialog = nullptr;
ChooseFromPropertyListDialog *dialog = nullptr;
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial") || targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial")) {
// Show texture property selection dialog
dialog = new ChooseTexturePropertyDialog(targetNode, Core::ICore::dialogParent());
dialog = new ChooseFromPropertyListDialog(targetNode, "QtQuick3D.Texture", Core::ICore::dialogParent());
dialog->exec();
}
if (!dialog || dialog->result() == QDialog::Accepted) {

View File

@@ -669,9 +669,9 @@ Project {
"navigator/navigatorview.h",
"navigator/navigatorwidget.cpp",
"navigator/navigatorwidget.h",
"navigator/choosetexturepropertydialog.cpp",
"navigator/choosetexturepropertydialog.h",
"navigator/choosetexturepropertydialog.ui",
"navigator/choosefrompropertylistdialog.cpp",
"navigator/choosefrompropertylistdialog.h",
"navigator/choosefrompropertylistdialog.ui",
"navigator/previewtooltip.cpp",
"navigator/previewtooltip.h",
"navigator/previewtooltip.ui",