Commit 648a9099 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Allow to toggle alias exporting in property editor

Change-Id: I8d293eb5a5fa7d6f7092f2fc857e19e9c4014c60
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 381bee14
......@@ -76,9 +76,16 @@ Rectangle {
}
// workaround: without this item the lineedit does not shrink to the
// right size after resizing to a wider width
Item {
width: 0
height: 1
Image {
width: 16
height: 16
source: hasAliasExport ? "image://icons/alias-export-checked" : "image://icons/alias-export-unchecked"
ToolTipArea {
anchors.fill: parent
onClicked: toogleExportAlias()
tooltip: qsTr("Toggle if selected item is alias exported.")
}
}
}
}
......
......@@ -24,6 +24,8 @@
****************************************************************************/
#include "qmldesignericonprovider.h"
#include <qmldesignericons.h>
#include <utils/icon.h>
#include <utils/utilsicons.h>
......@@ -171,6 +173,10 @@ QPixmap QmlDesignerIconProvider::requestPixmap(const QString &id, QSize *size, c
else if (id == "style-strikeout-h")
result = Icon({
{ ":/qmldesigner/images/style_strikeout.png", Theme::QmlDesigner_HighlightColor}}, Icon::Tint).pixmap();
else if (id == "alias-export-checked")
result = Icons::EXPORT_CHECKED.pixmap();
else if (id == "alias-export-unchecked")
result = Icons::EXPORT_UNCHECKED.pixmap();
else
qWarning() << Q_FUNC_INFO << "Image not found:" << id;
......
......@@ -218,6 +218,20 @@ void NavigatorView::propertiesAboutToBeRemoved(const QList<AbstractProperty>& pr
}
}
void NavigatorView::propertiesRemoved(const QList<AbstractProperty> &propertyList)
{
for (const AbstractProperty &property : propertyList) {
ModelNode node = property.parentModelNode();
/* Update export alias state if property from root note was removed and the root node was not selected. */
/* The check for the selection is an optimization to reduce updates. */
if (node.isRootNode() && !selectedModelNodes().isEmpty() && !selectedModelNodes().first().isRootNode()) {
foreach (const ModelNode &modelNode, node.allSubModelNodes())
m_treeModel->updateItemRow(modelNode);
}
}
}
void NavigatorView::rootNodeTypeChanged(const QString & /*type*/, int /*majorVersion*/, int /*minorVersion*/)
{
if (m_treeModel->isInTree(rootModelNode()))
......
......@@ -64,6 +64,7 @@ public:
void rootNodeTypeChanged(const QString &type, int majorVersion, int minorVersion) override;
void nodeIdChanged(const ModelNode& node, const QString& newId, const QString& oldId) override;
void propertiesAboutToBeRemoved(const QList<AbstractProperty>& propertyList) override;
void propertiesRemoved(const QList<AbstractProperty>& propertyList) override;
void selectedNodesChanged(const QList<ModelNode> &selectedNodeList ,
const QList<ModelNode> &lastSelectedNodeList) override;
......
......@@ -29,6 +29,8 @@
#include <QQmlContext>
#include <qmldesignerplugin.h>
#include <qmlobjectnode.h>
#include <rewritingexception.h>
static uchar fromHex(const uchar c, const uchar c2)
{
......@@ -121,6 +123,42 @@ QStringList PropertyEditorContextObject::autoComplete(const QString &text, int p
return QStringList();
}
void PropertyEditorContextObject::toogleExportAlias()
{
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();
if (QmlObjectNode::isValidQmlObjectNode(selectedNode)) {
QmlObjectNode objectNode(selectedNode);
PropertyName modelNodeId = selectedNode.id().toUtf8();
ModelNode rootModelNode = rewriterView->rootModelNode();
try {
RewriterTransaction transaction =
rewriterView->beginRewriterTransaction(QByteArrayLiteral("NavigatorTreeModel:exportItem"));
if (!objectNode.isAliasExported())
objectNode.ensureAliasExport();
else
if (rootModelNode.hasProperty(modelNodeId))
rootModelNode.removeProperty(modelNodeId);
} catch (RewritingException &exception) { //better safe than sorry! There always might be cases where we fail
exception.showException();
}
}
}
int PropertyEditorContextObject::majorVersion() const
{
return m_majorVersion;
......@@ -264,4 +302,13 @@ void PropertyEditorContextObject::triggerSelectionChanged()
setSelectionChanged(!m_selectionChanged);
}
void PropertyEditorContextObject::setHasAliasExport(bool hasAliasExport)
{
if (m_aliasExport == hasAliasExport)
return;
m_aliasExport = hasAliasExport;
emit hasAliasExportChanged();
}
} //QmlDesigner
......@@ -52,6 +52,8 @@ class PropertyEditorContextObject : public QObject
Q_PROPERTY(int minorVersion READ minorVersion WRITE setMinorVersion NOTIFY minorVersionChanged)
Q_PROPERTY(int majorQtQuickVersion READ majorQtQuickVersion WRITE setMajorQtQuickVersion NOTIFY majorQtQuickVersionChanged)
Q_PROPERTY(bool hasAliasExport READ hasAliasExport NOTIFY hasAliasExportChanged)
Q_PROPERTY(QQmlPropertyMap* backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged)
Q_PROPERTY(QQmlComponent* specificQmlComponent READ specificQmlComponent NOTIFY specificQmlComponentChanged)
......@@ -75,6 +77,8 @@ public:
Q_INVOKABLE QStringList autoComplete(const QString &text, int pos, bool explicitComplete);
Q_INVOKABLE void toogleExportAlias();
int majorVersion() const;
int majorQtQuickVersion() const;
void setMajorVersion(int majorVersion);
......@@ -85,6 +89,8 @@ public:
void insertInQmlContext(QQmlContext *context);
QQmlComponent *specificQmlComponent();
bool hasAliasExport() const { return m_aliasExport; }
signals:
void globalBaseUrlChanged();
void specificsUrlChanged();
......@@ -97,6 +103,7 @@ signals:
void minorVersionChanged();
void majorQtQuickVersionChanged();
void specificQmlComponentChanged();
void hasAliasExportChanged();
public slots:
void setGlobalBaseUrl(const QUrl &newBaseUrl);
......@@ -115,7 +122,8 @@ public slots:
void setModel(Model *model);
void triggerSelectionChanged();
void triggerSelectionChanged();
void setHasAliasExport(bool hasAliasExport);
private:
QUrl m_globalBaseUrl;
......@@ -136,6 +144,8 @@ private:
QQmlContext *m_qmlContext;
Model *m_model = nullptr;
bool m_aliasExport = false;
};
} //QmlDesigner {
......@@ -312,6 +312,8 @@ void PropertyEditorQmlBackend::setup(const QmlObjectNode &qmlObjectNode, const Q
context()->setContextProperty(QLatin1String("propertyCount"), QVariant(qmlObjectNode.modelNode().properties().count()));
contextObject()->setIsBaseState(qmlObjectNode.isInBaseState());
contextObject()->setHasAliasExport(qmlObjectNode.isAliasExported());
contextObject()->setSelectionChanged(false);
contextObject()->setSelectionChanged(false);
......
......@@ -494,6 +494,10 @@ void PropertyEditorView::propertiesRemoved(const QList<AbstractProperty>& proper
foreach (const AbstractProperty &property, propertyList) {
ModelNode node(property.parentModelNode());
if (node.isRootNode() && !m_selectedNode.isRootNode())
m_qmlBackEndForCurrentType->contextObject()->setHasAliasExport(QmlObjectNode(m_selectedNode).isAliasExported());
if (node == m_selectedNode || QmlObjectNode(m_selectedNode).propertyChangeForCurrentState() == node) {
setValue(m_selectedNode, property.name(), QmlObjectNode(m_selectedNode).instanceValue(property.name()));
......@@ -547,6 +551,9 @@ void PropertyEditorView::bindingPropertiesChanged(const QList<BindingProperty>&
foreach (const BindingProperty &property, propertyList) {
ModelNode node(property.parentModelNode());
if (property.isAliasExport())
m_qmlBackEndForCurrentType->contextObject()->setHasAliasExport(QmlObjectNode(m_selectedNode).isAliasExported());
if (node == m_selectedNode || QmlObjectNode(m_selectedNode).propertyChangeForCurrentState() == node) {
if (property.name().contains("anchor"))
m_qmlBackEndForCurrentType->backendAnchorBinding().invalidate(m_selectedNode);
......@@ -554,6 +561,7 @@ void PropertyEditorView::bindingPropertiesChanged(const QList<BindingProperty>&
setValue(m_selectedNode, property.name(), QmlObjectNode(m_selectedNode).instanceValue(property.name()));
else
setValue(m_selectedNode, property.name(), QmlObjectNode(m_selectedNode).modelValue(property.name()));
}
}
}
......@@ -652,9 +660,9 @@ void PropertyEditorView::rootNodeTypeChanged(const QString &/*type*/, int /*majo
}
void PropertyEditorView::nodeReparented(const ModelNode &node,
const NodeAbstractProperty &newPropertyParent,
const NodeAbstractProperty &oldPropertyParent,
AbstractView::PropertyChangeFlags propertyChange)
const NodeAbstractProperty & /*newPropertyParent*/,
const NodeAbstractProperty & /*oldPropertyParent*/,
AbstractView::PropertyChangeFlags /*propertyChange*/)
{
if (node == m_selectedNode)
m_qmlBackEndForCurrentType->backendAnchorBinding().setup(QmlItemNode(m_selectedNode));
......
......@@ -84,7 +84,7 @@ public:
void nodeReparented(const ModelNode &node,
const NodeAbstractProperty &newPropertyParent,
const NodeAbstractProperty &oldPropertyParent,
AbstractView::PropertyChangeFlags propertyChange);
AbstractView::PropertyChangeFlags propertyChange) override;
public slots:
void changeValue(const QString &name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment