forked from qt-creator/qt-creator
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:
@@ -344,8 +344,8 @@ extend_qtc_plugin(QmlDesigner
|
|||||||
navigatortreeview.cpp navigatortreeview.h
|
navigatortreeview.cpp navigatortreeview.h
|
||||||
navigatorview.cpp navigatorview.h
|
navigatorview.cpp navigatorview.h
|
||||||
navigatorwidget.cpp navigatorwidget.h
|
navigatorwidget.cpp navigatorwidget.h
|
||||||
choosetexturepropertydialog.cpp choosetexturepropertydialog.h
|
choosefrompropertylistdialog.cpp choosefrompropertylistdialog.h
|
||||||
choosetexturepropertydialog.ui
|
choosefrompropertylistdialog.ui
|
||||||
previewtooltip.cpp previewtooltip.h
|
previewtooltip.cpp previewtooltip.h
|
||||||
previewtooltip.ui
|
previewtooltip.ui
|
||||||
)
|
)
|
||||||
|
@@ -23,20 +23,22 @@
|
|||||||
**
|
**
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "choosetexturepropertydialog.h"
|
#include "choosefrompropertylistdialog.h"
|
||||||
#include "nodemetainfo.h"
|
#include "nodemetainfo.h"
|
||||||
#include "ui_choosetexturepropertydialog.h"
|
#include "ui_choosefrompropertylistdialog.h"
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
// This dialog displays all texture properties of an object and allows the user to choose one
|
// This dialog displays all given type properties of an object and allows the user to choose one
|
||||||
ChooseTexturePropertyDialog::ChooseTexturePropertyDialog(const ModelNode &node, QWidget *parent)
|
ChooseFromPropertyListDialog::ChooseFromPropertyListDialog(const ModelNode &node, TypeName type, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
, m_ui(new Ui::ChooseTexturePropertyDialog)
|
, m_ui(new Ui::ChooseFromPropertyListDialog)
|
||||||
{
|
{
|
||||||
|
m_propertyTypeName = type;
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
setWindowTitle(tr("Select Texture Property"));
|
setWindowTitle(tr("Select property"));
|
||||||
m_ui->label->setText(tr("Set texture to 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());
|
setFixedSize(size());
|
||||||
|
|
||||||
connect(m_ui->listProps, &QListWidget::itemClicked, this, [this](QListWidgetItem *item) {
|
connect(m_ui->listProps, &QListWidget::itemClicked, this, [this](QListWidgetItem *item) {
|
||||||
@@ -51,25 +53,25 @@ ChooseTexturePropertyDialog::ChooseTexturePropertyDialog(const ModelNode &node,
|
|||||||
fillList(node);
|
fillList(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChooseTexturePropertyDialog::~ChooseTexturePropertyDialog()
|
ChooseFromPropertyListDialog::~ChooseFromPropertyListDialog()
|
||||||
{
|
{
|
||||||
delete m_ui;
|
delete m_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeName ChooseTexturePropertyDialog::selectedProperty() const
|
TypeName ChooseFromPropertyListDialog::selectedProperty() const
|
||||||
{
|
{
|
||||||
return m_selectedProperty;
|
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 metaInfo = node.metaInfo();
|
||||||
const auto propNames = metaInfo.propertyNames();
|
const auto propNames = metaInfo.propertyNames();
|
||||||
const TypeName textureProp("QtQuick3D.Texture");
|
const TypeName property(m_propertyTypeName);
|
||||||
QStringList nameList;
|
QStringList nameList;
|
||||||
for (const auto &propName : propNames) {
|
for (const auto &propName : propNames) {
|
||||||
if (metaInfo.propertyTypeName(propName) == textureProp)
|
if (metaInfo.propertyTypeName(propName) == property)
|
||||||
nameList.append(QString::fromLatin1(propName));
|
nameList.append(QString::fromLatin1(propName));
|
||||||
}
|
}
|
||||||
|
|
@@ -32,23 +32,24 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ChooseTexturePropertyDialog;
|
class ChooseFromPropertyListDialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChooseTexturePropertyDialog : public QDialog
|
class ChooseFromPropertyListDialog : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ChooseTexturePropertyDialog(const ModelNode &node, QWidget *parent = 0);
|
explicit ChooseFromPropertyListDialog(const ModelNode &node, TypeName type, QWidget *parent = 0);
|
||||||
~ChooseTexturePropertyDialog();
|
~ChooseFromPropertyListDialog();
|
||||||
|
|
||||||
TypeName selectedProperty() const;
|
TypeName selectedProperty() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillList(const ModelNode &node);
|
void fillList(const ModelNode &node);
|
||||||
|
|
||||||
Ui::ChooseTexturePropertyDialog *m_ui;
|
Ui::ChooseFromPropertyListDialog *m_ui;
|
||||||
TypeName m_selectedProperty;
|
TypeName m_selectedProperty;
|
||||||
|
TypeName m_propertyTypeName;
|
||||||
};
|
};
|
||||||
}
|
}
|
@@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>QmlDesigner::ChooseTexturePropertyDialog</class>
|
<class>QmlDesigner::ChooseFromPropertyListDialog</class>
|
||||||
<widget class="QDialog" name="QmlDesigner::ChooseTexturePropertyDialog">
|
<widget class="QDialog" name="QmlDesigner::ChooseFromPropertyListDialog">
|
||||||
<property name="geometry">
|
<property name="geometry">
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
@@ -77,7 +77,7 @@
|
|||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>accepted()</signal>
|
<signal>accepted()</signal>
|
||||||
<receiver>QmlDesigner::ChooseTexturePropertyDialog</receiver>
|
<receiver>QmlDesigner::ChooseFromPropertyListDialog</receiver>
|
||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
<connection>
|
<connection>
|
||||||
<sender>buttonBox</sender>
|
<sender>buttonBox</sender>
|
||||||
<signal>rejected()</signal>
|
<signal>rejected()</signal>
|
||||||
<receiver>QmlDesigner::ChooseTexturePropertyDialog</receiver>
|
<receiver>QmlDesigner::ChooseFromPropertyListDialog</receiver>
|
||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
@@ -6,7 +6,7 @@ SOURCES += navigatorview.cpp \
|
|||||||
nameitemdelegate.cpp \
|
nameitemdelegate.cpp \
|
||||||
iconcheckboxitemdelegate.cpp \
|
iconcheckboxitemdelegate.cpp \
|
||||||
navigatortreeview.cpp \
|
navigatortreeview.cpp \
|
||||||
choosetexturepropertydialog.cpp \
|
choosefrompropertylistdialog.cpp \
|
||||||
previewtooltip.cpp
|
previewtooltip.cpp
|
||||||
|
|
||||||
HEADERS += navigatorview.h \
|
HEADERS += navigatorview.h \
|
||||||
@@ -16,10 +16,10 @@ HEADERS += navigatorview.h \
|
|||||||
iconcheckboxitemdelegate.h \
|
iconcheckboxitemdelegate.h \
|
||||||
navigatortreeview.h \
|
navigatortreeview.h \
|
||||||
navigatormodelinterface.h \
|
navigatormodelinterface.h \
|
||||||
choosetexturepropertydialog.h \
|
choosefrompropertylistdialog.h \
|
||||||
previewtooltip.h
|
previewtooltip.h
|
||||||
|
|
||||||
RESOURCES += navigator.qrc
|
RESOURCES += navigator.qrc
|
||||||
|
|
||||||
FORMS += choosetexturepropertydialog.ui \
|
FORMS += choosefrompropertylistdialog.ui \
|
||||||
previewtooltip.ui
|
previewtooltip.ui
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "navigatortreemodel.h"
|
#include "navigatortreemodel.h"
|
||||||
#include "navigatorview.h"
|
#include "navigatorview.h"
|
||||||
#include "choosetexturepropertydialog.h"
|
#include "choosefrompropertylistdialog.h"
|
||||||
#include "qmldesignerplugin.h"
|
#include "qmldesignerplugin.h"
|
||||||
#include "itemlibrarywidget.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.
|
// notify user with a helpful messagebox that suggests the correct action.
|
||||||
showMatToCompInfo = true;
|
showMatToCompInfo = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (newModelNode.isSubclassOf("QtQuick3D.Shader")
|
||||||
|
|| newModelNode.isSubclassOf("QtQuick3D.Command")) {
|
||||||
const bool isShader = newModelNode.isSubclassOf("QtQuick3D.Shader");
|
const bool isShader = newModelNode.isSubclassOf("QtQuick3D.Shader");
|
||||||
if (isShader || newModelNode.isSubclassOf("QtQuick3D.Command")) {
|
if (isShader || newModelNode.isSubclassOf("QtQuick3D.Command")) {
|
||||||
if (targetProperty.parentModelNode().isSubclassOf("QtQuick3D.Pass")) {
|
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 (!validContainer) {
|
||||||
if (!showMatToCompInfo)
|
if (!showMatToCompInfo)
|
||||||
validContainer = NodeHints::fromModelNode(targetProperty.parentModelNode()).canBeContainerFor(newModelNode);
|
validContainer = NodeHints::fromModelNode(targetProperty.parentModelNode()).canBeContainerFor(newModelNode);
|
||||||
@@ -982,10 +1001,10 @@ bool NavigatorTreeModel::dropAsImage3dTexture(const ModelNode &targetNode,
|
|||||||
{
|
{
|
||||||
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
|
if (targetNode.isSubclassOf("QtQuick3D.Material")) {
|
||||||
// if dropping an image on a default material, create a texture instead of image
|
// 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")) {
|
if (targetNode.isSubclassOf("QtQuick3D.DefaultMaterial") || targetNode.isSubclassOf("QtQuick3D.PrincipledMaterial")) {
|
||||||
// Show texture property selection dialog
|
// Show texture property selection dialog
|
||||||
dialog = new ChooseTexturePropertyDialog(targetNode, Core::ICore::dialogParent());
|
dialog = new ChooseFromPropertyListDialog(targetNode, "QtQuick3D.Texture", Core::ICore::dialogParent());
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
}
|
}
|
||||||
if (!dialog || dialog->result() == QDialog::Accepted) {
|
if (!dialog || dialog->result() == QDialog::Accepted) {
|
||||||
|
@@ -669,9 +669,9 @@ Project {
|
|||||||
"navigator/navigatorview.h",
|
"navigator/navigatorview.h",
|
||||||
"navigator/navigatorwidget.cpp",
|
"navigator/navigatorwidget.cpp",
|
||||||
"navigator/navigatorwidget.h",
|
"navigator/navigatorwidget.h",
|
||||||
"navigator/choosetexturepropertydialog.cpp",
|
"navigator/choosefrompropertylistdialog.cpp",
|
||||||
"navigator/choosetexturepropertydialog.h",
|
"navigator/choosefrompropertylistdialog.h",
|
||||||
"navigator/choosetexturepropertydialog.ui",
|
"navigator/choosefrompropertylistdialog.ui",
|
||||||
"navigator/previewtooltip.cpp",
|
"navigator/previewtooltip.cpp",
|
||||||
"navigator/previewtooltip.h",
|
"navigator/previewtooltip.h",
|
||||||
"navigator/previewtooltip.ui",
|
"navigator/previewtooltip.ui",
|
||||||
|
Reference in New Issue
Block a user