aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/ApiExtractor/propertyspec.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken6/ApiExtractor/propertyspec.cpp')
-rw-r--r--sources/shiboken6/ApiExtractor/propertyspec.cpp115
1 files changed, 66 insertions, 49 deletions
diff --git a/sources/shiboken6/ApiExtractor/propertyspec.cpp b/sources/shiboken6/ApiExtractor/propertyspec.cpp
index f66eeeaf6..32b756fad 100644
--- a/sources/shiboken6/ApiExtractor/propertyspec.cpp
+++ b/sources/shiboken6/ApiExtractor/propertyspec.cpp
@@ -1,38 +1,16 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of Qt for Python.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** 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.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "propertyspec.h"
#include "abstractmetalang.h"
#include "abstractmetabuilder_p.h"
#include "abstractmetatype.h"
-#include "codemodel.h"
+#include "documentation.h"
#include "messages.h"
-#include "typesystem.h"
+#include "complextypeentry.h"
+#include "typeinfo.h"
+
+#include "qtcompat.h"
#include <QtCore/QHash>
@@ -42,6 +20,8 @@
#include <algorithm>
+using namespace Qt::StringLiterals;
+
class QPropertySpecData : public QSharedData
{
public:
@@ -52,6 +32,7 @@ public:
m_write(ts.write),
m_designable(ts.designable),
m_reset(ts.reset),
+ m_notify(ts.notify),
m_type(type),
m_generateGetSetDef(ts.generateGetSetDef)
{
@@ -62,6 +43,8 @@ public:
QString m_write;
QString m_designable;
QString m_reset;
+ QString m_notify;
+ Documentation m_documentation;
AbstractMetaType m_type;
int m_index = -1;
// Indicates whether actual code is generated instead of relying on libpyside.
@@ -76,8 +59,8 @@ QPropertySpec::QPropertySpec(const TypeSystemProperty &ts,
QPropertySpec::QPropertySpec(const QPropertySpec &) = default;
QPropertySpec &QPropertySpec::operator=(const QPropertySpec &) = default;
-QPropertySpec::QPropertySpec(QPropertySpec &&) = default;
-QPropertySpec &QPropertySpec::operator=(QPropertySpec &&) = default;
+QPropertySpec::QPropertySpec(QPropertySpec &&) noexcept = default;
+QPropertySpec &QPropertySpec::operator=(QPropertySpec &&) noexcept = default;
QPropertySpec::~QPropertySpec() = default;
const AbstractMetaType &QPropertySpec::type() const
@@ -91,7 +74,7 @@ void QPropertySpec::setType(const AbstractMetaType &t)
d->m_type = t;
}
-const TypeEntry *QPropertySpec::typeEntry() const
+TypeEntryCPtr QPropertySpec::typeEntry() const
{
return d->m_type.typeEntry();
}
@@ -107,6 +90,17 @@ void QPropertySpec::setName(const QString &name)
d->m_name = name;
}
+Documentation QPropertySpec::documentation() const
+{
+ return d->m_documentation;
+}
+
+void QPropertySpec::setDocumentation(const Documentation &doc)
+{
+ if (d->m_documentation != doc)
+ d->m_documentation = doc;
+}
+
QString QPropertySpec::read() const
{
return d->m_read;
@@ -156,6 +150,17 @@ void QPropertySpec::setReset(const QString &reset)
d->m_reset = reset;
}
+QString QPropertySpec::notify() const
+{
+ return d->m_notify;
+}
+
+void QPropertySpec::setNotify(const QString &notify)
+{
+ if (d->m_notify != notify)
+ d->m_notify = notify;
+}
+
int QPropertySpec::index() const
{
return d->m_index;
@@ -184,13 +189,15 @@ void QPropertySpec::setGenerateGetSetDef(bool generateGetSetDef)
TypeSystemProperty QPropertySpec::typeSystemPropertyFromQ_Property(const QString &declarationIn,
QString *errorMessage)
{
- enum class PropertyToken { None, Read, Write, Designable, Reset };
+ enum class PropertyToken { None, Read, Write, Designable, Reset, Notify, Member };
static const QHash<QString, PropertyToken> tokenLookup = {
- {QStringLiteral("READ"), PropertyToken::Read},
- {QStringLiteral("WRITE"), PropertyToken::Write},
- {QStringLiteral("DESIGNABLE"), PropertyToken::Designable},
- {QStringLiteral("RESET"), PropertyToken::Reset}
+ {"READ"_L1, PropertyToken::Read},
+ {"WRITE"_L1, PropertyToken::Write},
+ {"DESIGNABLE"_L1, PropertyToken::Designable},
+ {"RESET"_L1, PropertyToken::Reset},
+ {"NOTIFY"_L1, PropertyToken::Notify},
+ {"MEMBER"_L1, PropertyToken::Member}
};
errorMessage->clear();
@@ -200,7 +207,7 @@ TypeSystemProperty QPropertySpec::typeSystemPropertyFromQ_Property(const QString
// Q_PROPERTY(QString objectName READ objectName WRITE setObjectName NOTIFY objectNameChanged)
const QString declaration = declarationIn.simplified();
- auto propertyTokens = declaration.split(QLatin1Char(' '), Qt::SkipEmptyParts);
+ auto propertyTokens = declaration.split(u' ', Qt::SkipEmptyParts);
// To properly parse complicated type declarations like
// "Q_PROPERTY(const QList<QString > *objectName READ objectName ..."
@@ -209,17 +216,17 @@ TypeSystemProperty QPropertySpec::typeSystemPropertyFromQ_Property(const QString
const auto it = std::find_if(propertyTokens.cbegin(), propertyTokens.cend(),
[](const QString &t) { return tokenLookup.contains(t); });
if (it == propertyTokens.cend()) {
- *errorMessage = QLatin1String("Invalid property specification, READ missing");
+ *errorMessage = u"Invalid property specification, READ missing"_s;
return result;
}
- const int firstToken = int(it - propertyTokens.cbegin());
+ const auto firstToken = qsizetype(it - propertyTokens.cbegin());
if (firstToken < 2) {
- *errorMessage = QLatin1String("Insufficient number of tokens in property specification");
+ *errorMessage = u"Insufficient number of tokens in property specification"_s;
return result;
}
- for (int pos = firstToken; pos + 1 < propertyTokens.size(); pos += 2) {
+ for (qsizetype pos = firstToken; pos + 1 < propertyTokens.size(); pos += 2) {
switch (tokenLookup.value(propertyTokens.at(pos))) {
case PropertyToken::Read:
result.read = propertyTokens.at(pos + 1);
@@ -233,17 +240,25 @@ TypeSystemProperty QPropertySpec::typeSystemPropertyFromQ_Property(const QString
case PropertyToken::Designable:
result.designable = propertyTokens.at(pos + 1);
break;
+ case PropertyToken::Notify:
+ result.notify = propertyTokens.at(pos + 1);
+ break;
+ case PropertyToken::Member:
+ // Ignore MEMBER tokens introduced by QTBUG-16852 as Python
+ // properties are anyways generated for fields.
+ return {};
+
case PropertyToken::None:
break;
}
}
- const int namePos = firstToken - 1;
+ const auto namePos = firstToken - 1;
result.name = propertyTokens.at(namePos);
result.type = propertyTokens.constFirst();
- for (int pos = 1; pos < namePos; ++pos)
- result.type += QLatin1Char(' ') + propertyTokens.at(pos);
+ for (qsizetype pos = 1; pos < namePos; ++pos)
+ result.type += u' ' + propertyTokens.at(pos);
// Fix errors like "Q_PROPERTY(QXYSeries *series .." to be of type "QXYSeries*"
while (!result.name.isEmpty() && !result.name.at(0).isLetter()) {
@@ -251,7 +266,7 @@ TypeSystemProperty QPropertySpec::typeSystemPropertyFromQ_Property(const QString
result.name.remove(0, 1);
}
if (!result.isValid())
- *errorMessage = QLatin1String("Incomplete property specification");
+ *errorMessage = u"Incomplete property specification"_s;
return result;
}
@@ -259,7 +274,7 @@ TypeSystemProperty QPropertySpec::typeSystemPropertyFromQ_Property(const QString
// the AbstractMetaType from the type string.
std::optional<QPropertySpec>
QPropertySpec::fromTypeSystemProperty(AbstractMetaBuilderPrivate *b,
- AbstractMetaClass *metaClass,
+ const AbstractMetaClassPtr &metaClass,
const TypeSystemProperty &ts,
const QStringList &scopes,
QString *errorMessage)
@@ -275,7 +290,7 @@ std::optional<QPropertySpec>
auto type = b->translateType(info, metaClass, {}, &typeError);
if (!type.has_value()) {
const QStringList qualifiedName = info.qualifiedName();
- for (int j = scopes.size(); j >= 0 && !type; --j) {
+ for (auto j = scopes.size(); j >= 0 && !type; --j) {
info.setQualifiedName(scopes.mid(0, j) + qualifiedName);
type = b->translateType(info, metaClass, {}, &typeError);
}
@@ -292,7 +307,7 @@ std::optional<QPropertySpec>
// via TypeSystemProperty.
std::optional<QPropertySpec>
QPropertySpec::parseQ_Property(AbstractMetaBuilderPrivate *b,
- AbstractMetaClass *metaClass,
+ const AbstractMetaClassPtr &metaClass,
const QString &declarationIn,
const QStringList &scopes,
QString *errorMessage)
@@ -315,6 +330,8 @@ void QPropertySpec::formatDebug(QDebug &debug) const
debug << ", reset=" << d->m_reset;
if (!d->m_designable.isEmpty())
debug << ", designable=" << d->m_designable;
+ if (!d->m_documentation.isEmpty())
+ debug << ", doc=\"" << d->m_documentation << '"';
}
QDebug operator<<(QDebug d, const QPropertySpec &p)