forked from qt-creator/qt-creator
QmlDesigner: Refactor enumeration handling
Change-Id: I0e163147a0303741af52127ece6f6afd0d2aa658 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
This commit is contained in:
@@ -63,6 +63,8 @@
|
||||
#include "endpuppetcommand.h"
|
||||
#include "debugoutputcommand.h"
|
||||
|
||||
#include <enumeration.h>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
static bool isRegistered=false;
|
||||
@@ -181,6 +183,9 @@ void NodeInstanceServerInterface::registerCommands()
|
||||
|
||||
qRegisterMetaType<DebugOutputCommand>("DebugOutputCommand");
|
||||
qRegisterMetaTypeStreamOperators<DebugOutputCommand>("DebugOutputCommand");
|
||||
|
||||
qRegisterMetaType<Enumeration>("Enumeration");
|
||||
qRegisterMetaTypeStreamOperators<Enumeration>("Enumeration");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "objectnodeinstance.h"
|
||||
|
||||
|
||||
#include <enumeration.h>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QQmlContext>
|
||||
@@ -472,6 +472,9 @@ void ObjectNodeInstance::setPropertyVariant(const PropertyName &name, const QVar
|
||||
|
||||
QVariant fixedValue = fixResourcePaths(value);
|
||||
|
||||
if (value.canConvert<Enumeration>())
|
||||
fixedValue = QVariant::fromValue(value.value<Enumeration>().nameToString());
|
||||
|
||||
QVariant oldValue = property.read();
|
||||
if (oldValue.type() == QVariant::Url) {
|
||||
QUrl url = oldValue.toUrl();
|
||||
|
||||
@@ -26,6 +26,7 @@ include (instances/instances.pri)
|
||||
include (../commands/commands.pri)
|
||||
include (../container/container.pri)
|
||||
include (../interfaces/interfaces.pri)
|
||||
include (../types/types.pri)
|
||||
|
||||
QT_BREAKPAD_ROOT_PATH = $$(QT_BREAKPAD_ROOT_PATH)
|
||||
!isEmpty(QT_BREAKPAD_ROOT_PATH) {
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "objectnodeinstance.h"
|
||||
|
||||
|
||||
#include <enumeration.h>
|
||||
|
||||
#include <QEvent>
|
||||
#include <QGraphicsScene>
|
||||
@@ -443,6 +443,9 @@ void ObjectNodeInstance::setPropertyVariant(const PropertyName &name, const QVar
|
||||
|
||||
QVariant fixedValue = fixResourcePaths(value);
|
||||
|
||||
if (value.canConvert<Enumeration>())
|
||||
fixedValue = QVariant::fromValue(value.value<Enumeration>().nameToString());
|
||||
|
||||
QVariant oldValue = property.read();
|
||||
if (oldValue.type() == QVariant::Url) {
|
||||
QUrl url = oldValue.toUrl();
|
||||
|
||||
@@ -16,6 +16,7 @@ include (instances/instances.pri)
|
||||
include (../commands/commands.pri)
|
||||
include (../container/container.pri)
|
||||
include (../interfaces/interfaces.pri)
|
||||
include (../types/types.pri)
|
||||
|
||||
SOURCES += $$PWD/qmlpuppetmain.cpp
|
||||
RESOURCES += $$PWD/../qmlpuppet.qrc
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "enumeration.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QtDebug>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
Enumeration::Enumeration()
|
||||
{
|
||||
}
|
||||
|
||||
Enumeration::Enumeration(const EnumerationName &enumerationName)
|
||||
: m_enumerationName(enumerationName)
|
||||
{
|
||||
}
|
||||
|
||||
Enumeration::Enumeration(const QString &enumerationName)
|
||||
: m_enumerationName(enumerationName.toUtf8())
|
||||
{
|
||||
}
|
||||
|
||||
Enumeration::Enumeration(const QString &scope, const QString &name)
|
||||
{
|
||||
QString enumerationString = scope + QStringLiteral(".") + name;
|
||||
|
||||
m_enumerationName = enumerationString.toUtf8();
|
||||
}
|
||||
|
||||
QmlDesigner::EnumerationName QmlDesigner::Enumeration::scope() const
|
||||
{
|
||||
return m_enumerationName.split('.').first();
|
||||
}
|
||||
|
||||
EnumerationName Enumeration::name() const
|
||||
{
|
||||
return m_enumerationName.split('.').last();
|
||||
}
|
||||
|
||||
EnumerationName Enumeration::toEnumerationName() const
|
||||
{
|
||||
return m_enumerationName;
|
||||
}
|
||||
|
||||
QString Enumeration::toString() const
|
||||
{
|
||||
return QString::fromUtf8(m_enumerationName);
|
||||
}
|
||||
|
||||
QString Enumeration::nameToString()
|
||||
{
|
||||
return QString::fromUtf8(name());
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const Enumeration &enumeration)
|
||||
{
|
||||
out << enumeration.toEnumerationName();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, Enumeration &enumeration)
|
||||
{
|
||||
in >> enumeration.m_enumerationName;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
bool operator ==(const Enumeration &first, const Enumeration &second)
|
||||
{
|
||||
return first.m_enumerationName == second.m_enumerationName;
|
||||
}
|
||||
|
||||
bool operator <(const Enumeration &first, const Enumeration &second)
|
||||
{
|
||||
return first.m_enumerationName < second.m_enumerationName;
|
||||
}
|
||||
|
||||
QDebug operator <<(QDebug debug, const Enumeration &enumeration)
|
||||
{
|
||||
debug.nospace() << "Enumeration("
|
||||
<< enumeration.toString()
|
||||
<< ")";
|
||||
|
||||
return debug;
|
||||
}
|
||||
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef QMLDESIGNER_ENUMERATION_H
|
||||
#define QMLDESIGNER_ENUMERATION_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QDataStream>
|
||||
#include <QMetaType>
|
||||
#include <QVariant>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
typedef QByteArray EnumerationName;
|
||||
|
||||
class Enumeration
|
||||
{
|
||||
friend bool operator ==(const Enumeration &first, const Enumeration &second);
|
||||
friend bool operator <(const Enumeration &first, const Enumeration &second);
|
||||
friend QDataStream &operator>>(QDataStream &in, Enumeration &enumeration);
|
||||
|
||||
public:
|
||||
Enumeration();
|
||||
Enumeration(const EnumerationName &enumerationName);
|
||||
Enumeration(const QString &enumerationName);
|
||||
Enumeration(const QString &scope, const QString &name);
|
||||
|
||||
EnumerationName scope() const;
|
||||
EnumerationName name() const;
|
||||
EnumerationName toEnumerationName() const;
|
||||
QString toString() const;
|
||||
QString nameToString();
|
||||
|
||||
private:
|
||||
EnumerationName m_enumerationName;
|
||||
};
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const Enumeration &enumeration);
|
||||
QDataStream &operator>>(QDataStream &in, Enumeration &enumeration);
|
||||
|
||||
bool operator ==(const Enumeration &first, const Enumeration &second);
|
||||
bool operator <(const Enumeration &first, const Enumeration &second);
|
||||
|
||||
QDebug operator <<(QDebug debug, const Enumeration &enumeration);
|
||||
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
Q_DECLARE_METATYPE(QmlDesigner::Enumeration)
|
||||
|
||||
#endif // QMLDESIGNER_ENUMERATION_H
|
||||
@@ -0,0 +1,5 @@
|
||||
INCLUDEPATH += $$PWD/
|
||||
|
||||
HEADERS += $$PWD/enumeration.h
|
||||
|
||||
SOURCES += $$PWD/enumeration.cpp
|
||||
@@ -37,12 +37,13 @@ Controls.ComboBox {
|
||||
property variant backendValue
|
||||
|
||||
property color textColor: colorLogic.textColor
|
||||
property string scope: "Qt"
|
||||
|
||||
ColorLogic {
|
||||
id: colorLogic
|
||||
backendValue: comboBox.backendValue
|
||||
onValueFromBackendChanged: {
|
||||
comboBox.currentIndex = comboBox.find(comboBox.backendValue.valueToString);
|
||||
comboBox.currentIndex = comboBox.find(comboBox.backendValue.enumeration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,8 +51,7 @@ Controls.ComboBox {
|
||||
if (backendValue === undefined)
|
||||
return;
|
||||
|
||||
if (backendValue.value !== currentText)
|
||||
backendValue.value = currentText;
|
||||
backendValue.setEnumeration(comboBox.scope, comboBox.currentText)
|
||||
}
|
||||
|
||||
onFocusChanged: {
|
||||
|
||||
+1
@@ -72,6 +72,7 @@ Section {
|
||||
visible: showVerticalAlignment
|
||||
Layout.fillWidth: true
|
||||
backendValue: backendValues.wrapMode
|
||||
scope: "Text"
|
||||
model: ["NoWrap", "WordWrap", "WrapAnywhere", "WrapAtWordBoundaryOrAnywhere"]
|
||||
}
|
||||
|
||||
|
||||
@@ -137,6 +137,7 @@ Column {
|
||||
backendValue: backendValues.horizontalTileMode
|
||||
implicitWidth: 180
|
||||
Layout.fillWidth: true
|
||||
scope: "BorderImage"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +151,7 @@ Column {
|
||||
backendValue: backendValues.verticalTileMode
|
||||
implicitWidth: 180
|
||||
Layout.fillWidth: true
|
||||
scope: "BorderImage"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ Column {
|
||||
ComboBox {
|
||||
model: ["LeftToRight", "TopToBottom"]
|
||||
backendValue: backendValues.flow
|
||||
scope: "Qt"
|
||||
}
|
||||
|
||||
ExpandingSpacer {
|
||||
@@ -65,6 +66,7 @@ Column {
|
||||
model: ["LeftToRight", "RightToLeft"]
|
||||
backendValue: backendValues.layoutDirection
|
||||
Layout.fillWidth: true
|
||||
scope: "Qt"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ Column {
|
||||
model: ["LeftToRight", "TopToBottom"]
|
||||
backendValue: backendValues.flow
|
||||
Layout.fillWidth: true
|
||||
scope: "Qt"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +97,7 @@ Column {
|
||||
model: ["LeftToRight", "RightToLeft"]
|
||||
backendValue: backendValues.layoutDirection
|
||||
Layout.fillWidth: true
|
||||
scope: "Qt"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ Column {
|
||||
backendValue: backendValues.fillMode
|
||||
implicitWidth: 180
|
||||
Layout.fillWidth: true
|
||||
scope: "Image"
|
||||
}
|
||||
|
||||
ExpandingSpacer {
|
||||
|
||||
@@ -50,6 +50,7 @@ Column {
|
||||
model: ["LeftToRight", "RightToLeft"]
|
||||
backendValue: backendValues.layoutDirection
|
||||
Layout.fillWidth: true
|
||||
scope: "Qt"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ Section {
|
||||
visible: showVerticalAlignment
|
||||
Layout.fillWidth: true
|
||||
backendValue: backendValues.echoMode
|
||||
scope: "TextInput"
|
||||
model: ["Normal", "Password", "PasswordEchoOnEdit", "NoEcho"]
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,11 @@ void PropertyEditorValue::setValue(const QVariant &value)
|
||||
if (m_value.isValid())
|
||||
emit valueChangedQml();
|
||||
emit isBoundChanged();
|
||||
}
|
||||
|
||||
QString PropertyEditorValue::enumeration() const
|
||||
{
|
||||
return m_value.value<QmlDesigner::Enumeration>().nameToString();
|
||||
}
|
||||
|
||||
QString PropertyEditorValue::expression() const
|
||||
@@ -262,6 +266,13 @@ void PropertyEditorValue::resetValue()
|
||||
}
|
||||
}
|
||||
|
||||
void PropertyEditorValue::setEnumeration(const QString &scope, const QString &name)
|
||||
{
|
||||
QmlDesigner::Enumeration newEnumeration(scope, name);
|
||||
|
||||
setValueWithEmit(QVariant::fromValue(newEnumeration));
|
||||
}
|
||||
|
||||
void PropertyEditorValue::registerDeclarativeTypes()
|
||||
{
|
||||
qmlRegisterType<PropertyEditorValue>("HelperWidgets",2,0,"PropertyEditorValue");
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <QQmlPropertyMap>
|
||||
#include <QtQml>
|
||||
#include <modelnode.h>
|
||||
#include <enumeration.h>
|
||||
|
||||
class PropertyEditorValue;
|
||||
|
||||
@@ -78,6 +79,7 @@ class PropertyEditorValue : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QVariant value READ value WRITE setValueWithEmit NOTIFY valueChangedQml)
|
||||
Q_PROPERTY(QVariant enumeration READ enumeration NOTIFY valueChangedQml)
|
||||
Q_PROPERTY(QString expression READ expression WRITE setExpressionWithEmit NOTIFY expressionChanged FINAL)
|
||||
Q_PROPERTY(QString valueToString READ valueToString NOTIFY valueChangedQml FINAL)
|
||||
Q_PROPERTY(bool isInModel READ isInModel NOTIFY valueChangedQml FINAL)
|
||||
@@ -96,6 +98,8 @@ public:
|
||||
void setValueWithEmit(const QVariant &value);
|
||||
void setValue(const QVariant &value);
|
||||
|
||||
QString enumeration() const;
|
||||
|
||||
QString expression() const;
|
||||
void setExpressionWithEmit(const QString &expression);
|
||||
void setExpression(const QString &expression);
|
||||
@@ -125,6 +129,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void resetValue();
|
||||
void setEnumeration(const QString &scope, const QString &name);
|
||||
|
||||
signals:
|
||||
void valueChanged(const QString &name, const QVariant&);
|
||||
|
||||
@@ -13,6 +13,7 @@ include (instances/instances.pri)
|
||||
include (../../../../share/qtcreator/qml/qmlpuppet/interfaces/interfaces.pri)
|
||||
include (../../../../share/qtcreator/qml/qmlpuppet/commands/commands.pri)
|
||||
include (../../../../share/qtcreator/qml/qmlpuppet/container/container.pri)
|
||||
include (../../../../share/qtcreator/qml/qmlpuppet/types/types.pri)
|
||||
|
||||
SOURCES += $$PWD/model/abstractview.cpp \
|
||||
$$PWD/model/rewriterview.cpp \
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
|
||||
#include "qmldesignercorelib_global.h"
|
||||
#include "abstractproperty.h"
|
||||
#include "enumeration.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QTextStream;
|
||||
@@ -55,7 +56,12 @@ public:
|
||||
void setValue(const QVariant &value);
|
||||
QVariant value() const;
|
||||
|
||||
void setEnumeration(const EnumerationName &enumerationName);
|
||||
Enumeration enumeration() const;
|
||||
bool holdsEnumeration() const;
|
||||
|
||||
void setDynamicTypeNameAndValue(const TypeName &type, const QVariant &value);
|
||||
void setDynamicTypeNameAndEnumeration(const TypeName &type, const EnumerationName &enumerationName);
|
||||
|
||||
VariantProperty();
|
||||
VariantProperty(const VariantProperty &property, AbstractView *view);
|
||||
|
||||
@@ -113,9 +113,8 @@ QString QmlTextGenerator::toQml(const AbstractProperty &property, int indentDept
|
||||
|
||||
if (false) {
|
||||
}
|
||||
if (variantProperty.parentModelNode().metaInfo().isValid() &&
|
||||
variantProperty.parentModelNode().metaInfo().propertyIsEnumType(variantProperty.name())) {
|
||||
return variantProperty.parentModelNode().metaInfo().propertyEnumScope(variantProperty.name()) + '.' + stringValue;
|
||||
if (variantProperty.holdsEnumeration()) {
|
||||
return variantProperty.enumeration().toString();
|
||||
} else {
|
||||
|
||||
switch (value.type()) {
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "variantproperty.h"
|
||||
#include "signalhandlerproperty.h"
|
||||
#include "nodemetainfo.h"
|
||||
#include "enumeration.h"
|
||||
|
||||
#include <qmljs/qmljsevaluate.h>
|
||||
#include <qmljs/qmljslink.h>
|
||||
@@ -565,7 +566,7 @@ public:
|
||||
if (astValueList.count() == 2 //Check for global Qt enums
|
||||
&& astValueList.first() == QLatin1String("Qt")
|
||||
&& globalQtEnums().contains(astValueList.last()))
|
||||
return QVariant(astValueList.last());
|
||||
return QVariant::fromValue(Enumeration(astValue));
|
||||
|
||||
ExpressionStatement *eStmt = cast<ExpressionStatement *>(rhs);
|
||||
if (!eStmt || !eStmt->expression)
|
||||
@@ -607,7 +608,7 @@ public:
|
||||
return QVariant();
|
||||
|
||||
if (rhsCppComponentValue->getEnum(lhsPropertyTypeName).hasKey(rhsValueName))
|
||||
return QVariant(rhsValueName);
|
||||
return QVariant::fromValue(Enumeration(astValue));
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
@@ -89,6 +89,21 @@ QVariant VariantProperty::value() const
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void VariantProperty::setEnumeration(const EnumerationName &enumerationName)
|
||||
{
|
||||
setValue(QVariant::fromValue(Enumeration(enumerationName)));
|
||||
}
|
||||
|
||||
Enumeration VariantProperty::enumeration() const
|
||||
{
|
||||
return value().value<Enumeration>();
|
||||
}
|
||||
|
||||
bool VariantProperty::holdsEnumeration() const
|
||||
{
|
||||
return value().canConvert<Enumeration>();
|
||||
}
|
||||
|
||||
void VariantProperty::setDynamicTypeNameAndValue(const TypeName &type, const QVariant &value)
|
||||
{
|
||||
Internal::WriteLocker locker(model());
|
||||
@@ -111,7 +126,12 @@ void VariantProperty::setDynamicTypeNameAndValue(const TypeName &type, const QVa
|
||||
if (internalNode()->hasProperty(name()) && !internalNode()->property(name())->isVariantProperty())
|
||||
model()->d->removeProperty(internalNode()->property(name()));
|
||||
|
||||
model()->d->setDynamicVariantProperty(internalNode(), name(), type, value);
|
||||
model()->d->setDynamicVariantProperty(internalNode(), name(), type, value);
|
||||
}
|
||||
|
||||
void VariantProperty::setDynamicTypeNameAndEnumeration(const TypeName &type, const EnumerationName &enumerationName)
|
||||
{
|
||||
setDynamicTypeNameAndValue(type, QVariant::fromValue(Enumeration(enumerationName)));
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const VariantProperty &VariantProperty)
|
||||
|
||||
Reference in New Issue
Block a user