Commit cde0a882 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.PropertyEditor: fix combobox for anchor targets

Change-Id: Ib66e19ad2d70cb8c5fd295288a625af06104d40e
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent 92baa15e
......@@ -9,6 +9,7 @@ TabView 2.0 TabView.qml
Tab 2.0 Tab.qml
ScrollView 2.0 ScrollView.qml
ComboBox 2.0 ComboBox.qml
CustomComboBoxStyle 2.0 CustomComboBoxStyle.qml
SectionLayout 2.0 SectionLayout.qml
SecondColumnLayout 2.0 SecondColumnLayout.qml
ExpandingSpacer 2.0 ExpandingSpacer.qml
......
......@@ -41,6 +41,7 @@
import QtQuick 2.0
import HelperWidgets 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0 as Controls
Section {
anchors.left: parent.left
......@@ -79,8 +80,11 @@ Section {
elide: Text.ElideRight
}
ComboBox {
TargetComboBox {
targetName: anchorBackend.topTarget
onCurrentTextChanged: {
anchorBackend.topTarget = currentText
}
}
......@@ -137,8 +141,11 @@ Section {
elide: Text.ElideRight
}
ComboBox {
TargetComboBox {
targetName: anchorBackend.bottomTarget
onCurrentTextChanged: {
anchorBackend.bottomTarget = currentText
}
}
......@@ -196,8 +203,11 @@ Section {
}
ComboBox {
TargetComboBox {
targetName: anchorBackend.leftTarget
onCurrentTextChanged: {
anchorBackend.leftTarget = currentText
}
}
......@@ -256,8 +266,11 @@ Section {
}
ComboBox {
TargetComboBox {
targetName: anchorBackend.rightTarget
onCurrentTextChanged: {
anchorBackend.rightTarget = currentText
}
}
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
import QtQuick 2.0
import HelperWidgets 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.0 as Controls
Controls.ComboBox {
property string targetName: anchorBackend.topTarget
id: targetComboBox
Connections {
target: anchorBackend
onInvalidated: {
targetComboBox.currentIndex =
anchorBackend.indexOfPossibleTargetItem(targetComboBox.targetName)
}
}
onTargetNameChanged: {
targetComboBox.currentIndex =
anchorBackend.indexOfPossibleTargetItem(targetComboBox.targetName)
}
model: anchorBackend.possibleTargetItems
style: CustomComboBoxStyle {
}
}
......@@ -64,7 +64,7 @@ static inline void restoreProperty(ModelNode node, const PropertyName &propertyN
namespace Internal {
QmlAnchorBindingProxy::QmlAnchorBindingProxy(QObject *parent) :
QObject(parent), m_locked(false)
QObject(parent), m_locked(false), m_ignoreQml(false)
{
}
......@@ -76,6 +76,8 @@ void QmlAnchorBindingProxy::setup(const QmlItemNode &fxItemNode)
{
m_qmlItemNode = fxItemNode;
m_ignoreQml = true;
if (m_qmlItemNode.modelNode().hasParentProperty()) {
setDefaultAnchorTarget(m_qmlItemNode.modelNode().parentProperty().parentModelNode());
} else {
......@@ -137,6 +139,10 @@ void QmlAnchorBindingProxy::setup(const QmlItemNode &fxItemNode)
emit verticalTargetChanged();
emit horizontalTargetChanged();
}
emit invalidated();
m_ignoreQml = false;
}
void QmlAnchorBindingProxy::invalidate(const QmlItemNode &fxItemNode)
......@@ -146,6 +152,8 @@ void QmlAnchorBindingProxy::invalidate(const QmlItemNode &fxItemNode)
m_qmlItemNode = fxItemNode;
m_ignoreQml = true;
m_verticalTarget = m_horizontalTarget = m_topTarget = m_bottomTarget = m_leftTarget = m_rightTarget = m_qmlItemNode.modelNode().parentProperty().parentModelNode();
if (topAnchored()) {
......@@ -201,6 +209,10 @@ void QmlAnchorBindingProxy::invalidate(const QmlItemNode &fxItemNode)
emit verticalTargetChanged();
emit horizontalTargetChanged();
}
emit invalidated();
m_ignoreQml = false;
}
bool QmlAnchorBindingProxy::hasParent()
......@@ -243,13 +255,20 @@ bool QmlAnchorBindingProxy::hasAnchors()
}
void QmlAnchorBindingProxy::setTopTarget(const QVariant &target)
void QmlAnchorBindingProxy::setTopTarget(const QString &target)
{
QmlItemNode newTarget(target.value<ModelNode>());
if (m_ignoreQml)
return;
QmlItemNode newTarget(targetIdToNode(target));
if (newTarget == m_topTarget)
return;
if (!newTarget.isValid())
return;
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction();
m_topTarget = newTarget;
......@@ -259,13 +278,22 @@ void QmlAnchorBindingProxy::setTopTarget(const QVariant &target)
}
void QmlAnchorBindingProxy::setBottomTarget(const QVariant &target)
void QmlAnchorBindingProxy::setBottomTarget(const QString &target)
{
QmlItemNode newTarget(target.value<ModelNode>());
if (m_ignoreQml)
return;
if (m_ignoreQml)
return;
QmlItemNode newTarget(targetIdToNode(target));
if (newTarget == m_bottomTarget)
return;
if (!newTarget.isValid())
return;
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction();
m_bottomTarget = newTarget;
......@@ -274,13 +302,19 @@ void QmlAnchorBindingProxy::setBottomTarget(const QVariant &target)
emit bottomTargetChanged();
}
void QmlAnchorBindingProxy::setLeftTarget(const QVariant &target)
void QmlAnchorBindingProxy::setLeftTarget(const QString &target)
{
QmlItemNode newTarget(target.value<ModelNode>());
if (m_ignoreQml)
return;
QmlItemNode newTarget(targetIdToNode(target));
if (newTarget == m_leftTarget)
return;
if (!newTarget.isValid())
return;
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction();
m_leftTarget = newTarget;
......@@ -289,13 +323,19 @@ void QmlAnchorBindingProxy::setLeftTarget(const QVariant &target)
emit leftTargetChanged();
}
void QmlAnchorBindingProxy::setRightTarget(const QVariant &target)
void QmlAnchorBindingProxy::setRightTarget(const QString &target)
{
QmlItemNode newTarget(target.value<ModelNode>());
if (m_ignoreQml)
return;
QmlItemNode newTarget(targetIdToNode(target));
if (newTarget == m_rightTarget)
return;
if (!newTarget.isValid())
return;
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction();
m_rightTarget = newTarget;
......@@ -304,13 +344,19 @@ void QmlAnchorBindingProxy::setRightTarget(const QVariant &target)
emit rightTargetChanged();
}
void QmlAnchorBindingProxy::setVerticalTarget(const QVariant &target)
void QmlAnchorBindingProxy::setVerticalTarget(const QString &target)
{
QmlItemNode newTarget(target.value<ModelNode>());
if (m_ignoreQml)
return;
QmlItemNode newTarget(targetIdToNode(target));
if (newTarget == m_verticalTarget)
return;
if (!newTarget.isValid())
return;
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction();
m_verticalTarget = newTarget;
......@@ -319,13 +365,19 @@ void QmlAnchorBindingProxy::setVerticalTarget(const QVariant &target)
emit verticalTargetChanged();
}
void QmlAnchorBindingProxy::setHorizontalTarget(const QVariant &target)
void QmlAnchorBindingProxy::setHorizontalTarget(const QString &target)
{
QmlItemNode newTarget(target.value<ModelNode>());
if (m_ignoreQml)
return;
QmlItemNode newTarget(targetIdToNode(target));
if (newTarget == m_horizontalTarget)
return;
if (!newTarget.isValid())
return;
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction();
m_horizontalTarget = newTarget;
......@@ -334,6 +386,43 @@ void QmlAnchorBindingProxy::setHorizontalTarget(const QVariant &target)
emit horizontalTargetChanged();
}
QStringList QmlAnchorBindingProxy::possibleTargetItems() const
{
QStringList stringList;
if (!m_qmlItemNode.isValid())
return stringList;
QList<QmlItemNode> itemList;
if (m_qmlItemNode.instanceParent().modelNode().isValid())
itemList = toQmlItemNodeList(m_qmlItemNode.instanceParent().modelNode().allDirectSubModelNodes());
itemList.removeOne(m_qmlItemNode);
//We currently have no instanceChildren().
//So we double check here if the instanceParents are equal.
foreach (const QmlItemNode &node, itemList)
if (node.isValid() && (node.instanceParent().modelNode() != m_qmlItemNode.instanceParent().modelNode()))
itemList.removeAll(node);
foreach (const QmlItemNode &itemNode, itemList) {
if (itemNode.isValid() && !itemNode.id().isEmpty()) {
stringList.append(itemNode.id());
}
}
QmlItemNode parent(m_qmlItemNode.instanceParent().toQmlItemNode());
if (parent.isValid()) {
stringList.append(QLatin1String("parent"));
}
return stringList;
}
int QmlAnchorBindingProxy::indexOfPossibleTargetItem(const QString &targetName) const
{
return possibleTargetItems().indexOf(targetName);
}
void QmlAnchorBindingProxy::resetLayout() {
RewriterTransaction transaction = m_qmlItemNode.modelNode().view()->beginRewriterTransaction();
......@@ -512,6 +601,29 @@ void QmlAnchorBindingProxy::calcRightMargin()
m_locked = false;
}
QmlItemNode QmlAnchorBindingProxy::targetIdToNode(const QString &id) const
{
QmlItemNode itemNode;
if (m_qmlItemNode.isValid() && m_qmlItemNode.view()) {
itemNode = m_qmlItemNode.view()->modelNodeForId(id);
if (id == QLatin1String("parent"))
itemNode = m_qmlItemNode.instanceParent().modelNode();
}
return itemNode;
}
QString QmlAnchorBindingProxy::idForNode(const QmlItemNode &qmlItemNode) const
{
if (m_qmlItemNode.instanceParent().modelNode() == qmlItemNode)
return QLatin1String("parent");
return qmlItemNode.id();
}
ModelNode QmlAnchorBindingProxy::modelNode() const
{
return m_qmlItemNode.modelNode();
......@@ -633,6 +745,37 @@ bool QmlAnchorBindingProxy::verticalCentered()
return m_qmlItemNode.isValid() && m_qmlItemNode.anchors().instanceHasAnchor(AnchorLine::VerticalCenter);
}
QString QmlAnchorBindingProxy::topTarget() const
{
qDebug() << "top node" << idForNode(m_topTarget);
return idForNode(m_topTarget);
}
QString QmlAnchorBindingProxy::bottomTarget() const
{
return idForNode(m_bottomTarget);
}
QString QmlAnchorBindingProxy::leftTarget() const
{
return idForNode(m_leftTarget);
}
QString QmlAnchorBindingProxy::rightTarget() const
{
return idForNode(m_rightTarget);
}
QString QmlAnchorBindingProxy::verticalTarget() const
{
return idForNode(m_verticalTarget);
}
QString QmlAnchorBindingProxy::horizontalTarget() const
{
return idForNode(m_horizontalTarget);
}
bool QmlAnchorBindingProxy::horizontalCentered()
{
return m_qmlItemNode.isValid() && m_qmlItemNode.anchors().instanceHasAnchor(AnchorLine::HorizontalCenter);
......
......@@ -52,13 +52,13 @@ class QmlAnchorBindingProxy : public QObject
Q_PROPERTY(bool rightAnchored READ rightAnchored WRITE setRightAnchor NOTIFY rightAnchorChanged)
Q_PROPERTY(bool hasParent READ hasParent NOTIFY parentChanged)
Q_PROPERTY(QVariant topTarget READ topTarget WRITE setTopTarget NOTIFY topTargetChanged)
Q_PROPERTY(QVariant bottomTarget READ bottomTarget WRITE setBottomTarget NOTIFY bottomTargetChanged)
Q_PROPERTY(QVariant leftTarget READ leftTarget WRITE setLeftTarget NOTIFY leftTargetChanged)
Q_PROPERTY(QVariant rightTarget READ rightTarget WRITE setRightTarget NOTIFY rightTargetChanged)
Q_PROPERTY(QString topTarget READ topTarget WRITE setTopTarget NOTIFY topTargetChanged)
Q_PROPERTY(QString bottomTarget READ bottomTarget WRITE setBottomTarget NOTIFY bottomTargetChanged)
Q_PROPERTY(QString leftTarget READ leftTarget WRITE setLeftTarget NOTIFY leftTargetChanged)
Q_PROPERTY(QString rightTarget READ rightTarget WRITE setRightTarget NOTIFY rightTargetChanged)
Q_PROPERTY(QVariant verticalTarget READ verticalTarget WRITE setVerticalTarget NOTIFY verticalTargetChanged)
Q_PROPERTY(QVariant horizontalTarget READ horizontalTarget WRITE setHorizontalTarget NOTIFY horizontalTargetChanged)
Q_PROPERTY(QString verticalTarget READ verticalTarget WRITE setVerticalTarget NOTIFY verticalTargetChanged)
Q_PROPERTY(QString horizontalTarget READ horizontalTarget WRITE setHorizontalTarget NOTIFY horizontalTargetChanged)
Q_PROPERTY(bool hasAnchors READ hasAnchors NOTIFY anchorsChanged)
Q_PROPERTY(bool isFilled READ isFilled NOTIFY anchorsChanged)
......@@ -67,6 +67,8 @@ class QmlAnchorBindingProxy : public QObject
Q_PROPERTY(bool verticalCentered READ verticalCentered WRITE setVerticalCentered NOTIFY centeredVChanged)
Q_PROPERTY(QVariant itemNode READ itemNode NOTIFY itemNodeChanged)
Q_PROPERTY(QStringList possibleTargetItems READ possibleTargetItems NOTIFY itemNodeChanged)
public:
//only enable if node has parent
......@@ -92,23 +94,26 @@ public:
bool horizontalCentered();
bool verticalCentered();
QVariant itemNode() const { return QVariant::fromValue(m_qmlItemNode.modelNode()); }
QVariant itemNode() const { return QVariant::fromValue(m_qmlItemNode.modelNode().id()); }
QVariant topTarget() const { return QVariant::fromValue(m_topTarget.modelNode()); }
QVariant bottomTarget() const { return QVariant::fromValue(m_bottomTarget.modelNode()); }
QVariant leftTarget() const { return QVariant::fromValue(m_leftTarget.modelNode()); }
QVariant rightTarget() const { return QVariant::fromValue(m_rightTarget.modelNode()); }
QString topTarget() const;
QString bottomTarget() const;
QString leftTarget() const;
QString rightTarget() const;
QVariant verticalTarget() const { return QVariant::fromValue(m_verticalTarget.modelNode()); }
QVariant horizontalTarget() const { return QVariant::fromValue(m_horizontalTarget.modelNode()); }
QString verticalTarget() const;
QString horizontalTarget() const;
public:
void setTopTarget(const QVariant &target);
void setBottomTarget(const QVariant &target);
void setLeftTarget(const QVariant &target);
void setRightTarget(const QVariant &target);
void setVerticalTarget(const QVariant &target);
void setHorizontalTarget(const QVariant &target);
void setTopTarget(const QString &target);
void setBottomTarget(const QString &target);
void setLeftTarget(const QString &target);
void setRightTarget(const QString &target);
void setVerticalTarget(const QString &target);
void setHorizontalTarget(const QString &target);
QStringList possibleTargetItems() const;
Q_INVOKABLE int indexOfPossibleTargetItem(const QString &targetName) const;
public slots:
......@@ -142,12 +147,16 @@ signals:
void verticalTargetChanged();
void horizontalTargetChanged();
void invalidated();
private:
void setDefaultAnchorTarget(const ModelNode &modelNode);
void calcTopMargin();
void calcBottomMargin();
void calcLeftMargin();
void calcRightMargin();
QmlItemNode targetIdToNode(const QString &id) const;
QString idForNode(const QmlItemNode &qmlItemNode) const;
ModelNode modelNode() const;
......@@ -168,6 +177,7 @@ private:
QmlItemNode m_horizontalTarget;
bool m_locked;
bool m_ignoreQml;
};
} // namespace Internal
......
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