QmlDesigner: reduce enumeration to header only

It is used in some other external qmldesigner plugin and
these are built against current dev packages, which
are not contain this cpp file.
Different solution would be to add:
  r"^share/qtcreator/qml/qmlpuppet/types/enumeration.cpp$",
to scripts/createDevPackage.py which feels not that clean.


Change-Id: Ia1fb5c02f457d98474218689ebf6483706265dde
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Tim Jenssen
2019-08-07 16:00:21 +02:00
parent 6ab4d69440
commit c9b91e7e6b
10 changed files with 72 additions and 139 deletions

View File

@@ -34,7 +34,7 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QWeakPointer> #include <QWeakPointer>
#include "enumeration.h" #include <enumeration.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QQmlContext; class QQmlContext;

View File

@@ -1,116 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** 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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "enumeration.h"
#include <QString>
#include <QList>
#include <QtDebug>
namespace QmlDesigner {
Enumeration::Enumeration() = default;
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 + QLatin1Char('.') + name;
m_enumerationName = enumerationString.toUtf8();
}
QmlDesigner::EnumerationName QmlDesigner::Enumeration::scope() const
{
return m_enumerationName.split('.').constFirst();
}
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() const
{
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

View File

@@ -30,6 +30,10 @@
#include <QMetaType> #include <QMetaType>
#include <QVariant> #include <QVariant>
#include <QString>
#include <QList>
#include <QtDebug>
namespace QmlDesigner { namespace QmlDesigner {
using EnumerationName = QByteArray; using EnumerationName = QByteArray;
@@ -41,29 +45,75 @@ class Enumeration
friend QDataStream &operator>>(QDataStream &in, Enumeration &enumeration); friend QDataStream &operator>>(QDataStream &in, Enumeration &enumeration);
public: public:
Enumeration(); Enumeration() = default;
Enumeration(const EnumerationName &enumerationName); Enumeration(const EnumerationName &enumerationName)
Enumeration(const QString &enumerationName); : m_enumerationName(enumerationName)
Enumeration(const QString &scope, const QString &name); {
}
Enumeration(const QString &enumerationName)
: m_enumerationName(enumerationName.toUtf8())
{
}
Enumeration(const QString &scope, const QString &name)
{
QString enumerationString = scope + QLatin1Char('.') + name;
m_enumerationName = enumerationString.toUtf8();
}
EnumerationName scope() const; EnumerationName scope() const
EnumerationName name() const; {
EnumerationName toEnumerationName() const; return m_enumerationName.split('.').constFirst();
QString toString() const; }
QString nameToString() const; EnumerationName name() const
{
return m_enumerationName.split('.').last();
}
EnumerationName toEnumerationName() const
{
return m_enumerationName;
}
QString toString() const
{
return QString::fromUtf8(m_enumerationName);
}
QString nameToString() const
{
return QString::fromUtf8(name());
}
private: private:
EnumerationName m_enumerationName; EnumerationName m_enumerationName;
}; };
QDataStream &operator<<(QDataStream &out, const Enumeration &enumeration); inline QDataStream &operator<<(QDataStream &out, const Enumeration &enumeration){
QDataStream &operator>>(QDataStream &in, Enumeration &enumeration); out << enumeration.toEnumerationName();
return out;
}
bool operator ==(const Enumeration &first, const Enumeration &second); inline QDataStream &operator>>(QDataStream &in, Enumeration &enumeration)
bool operator <(const Enumeration &first, const Enumeration &second); {
in >> enumeration.m_enumerationName;
return in;
}
QDebug operator <<(QDebug debug, const Enumeration &enumeration);
inline bool operator==(const Enumeration &first, const Enumeration &second)
{
return first.m_enumerationName == second.m_enumerationName;
}
inline bool operator<(const Enumeration &first, const Enumeration &second)
{
return first.m_enumerationName < second.m_enumerationName;
}
inline QDebug operator <<(QDebug debug, const Enumeration &enumeration)
{
debug.nospace() << "Enumeration("
<< enumeration.toString()
<< ")";
return debug;
}
} // namespace QmlDesigner } // namespace QmlDesigner

View File

@@ -1,5 +1,3 @@
INCLUDEPATH += $$PWD/ INCLUDEPATH += $$PWD/
HEADERS += $$PWD/enumeration.h HEADERS += $$PWD/enumeration.h
SOURCES += $$PWD/enumeration.cpp

View File

@@ -27,7 +27,8 @@
#include "qmldesignercorelib_global.h" #include "qmldesignercorelib_global.h"
#include "abstractproperty.h" #include "abstractproperty.h"
#include "enumeration.h"
#include <enumeration.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QTextStream; class QTextStream;

View File

@@ -24,7 +24,8 @@
****************************************************************************/ ****************************************************************************/
#include "propertyparser.h" #include "propertyparser.h"
#include "enumeration.h"
#include <enumeration.h>
#include <modelnode.h> #include <modelnode.h>
#include <metainfo.h> #include <metainfo.h>

View File

@@ -29,7 +29,6 @@
#include "modelnodepositionstorage.h" #include "modelnodepositionstorage.h"
#include "abstractproperty.h" #include "abstractproperty.h"
#include "bindingproperty.h" #include "bindingproperty.h"
#include "enumeration.h"
#include "filemanager/firstdefinitionfinder.h" #include "filemanager/firstdefinitionfinder.h"
#include "filemanager/objectlengthcalculator.h" #include "filemanager/objectlengthcalculator.h"
#include "filemanager/qmlrefactoring.h" #include "filemanager/qmlrefactoring.h"
@@ -42,6 +41,8 @@
#include "rewriterview.h" #include "rewriterview.h"
#include "variantproperty.h" #include "variantproperty.h"
#include <enumeration.h>
#include <qmljs/qmljsevaluate.h> #include <qmljs/qmljsevaluate.h>
#include <qmljs/qmljslink.h> #include <qmljs/qmljslink.h>
#include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsast_p.h>

View File

@@ -192,7 +192,6 @@ Project {
"interfaces/nodeinstanceclientinterface.h", "interfaces/nodeinstanceclientinterface.h",
"interfaces/nodeinstanceserverinterface.cpp", "interfaces/nodeinstanceserverinterface.cpp",
"interfaces/nodeinstanceserverinterface.h", "interfaces/nodeinstanceserverinterface.h",
"types/enumeration.cpp",
"types/enumeration.h", "types/enumeration.h",
] ]
} }

View File

@@ -126,7 +126,7 @@ extend_qtc_executable(qml2puppet
extend_qtc_executable(qml2puppet extend_qtc_executable(qml2puppet
SOURCES_PREFIX "${SRCDIR}/types" SOURCES_PREFIX "${SRCDIR}/types"
SOURCES SOURCES
enumeration.cpp enumeration.h enumeration.h
) )
extend_qtc_executable(qml2puppet extend_qtc_executable(qml2puppet

View File

@@ -121,7 +121,6 @@ QtcTool {
"interfaces/nodeinstanceserverinterface.cpp", "interfaces/nodeinstanceserverinterface.cpp",
"interfaces/nodeinstanceserverinterface.h", "interfaces/nodeinstanceserverinterface.h",
"qmlprivategate/qmlprivategate.h", "qmlprivategate/qmlprivategate.h",
"types/enumeration.cpp",
"types/enumeration.h", "types/enumeration.h",
] ]
} }