Cleanup QPropertyBindingError

Remove location(). The method would always return an empty value. If you need the location,
the binding itself has it.

Remove setDescription() and require that the description gets passed
in the constructor. Never create a d pointer if type is NoError, so we
can quickly check for it inline.

Change-Id: I7eb8a94786281069d6ea2d82567c09aa50c52ef6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Lars Knoll 2020-07-07 21:34:57 +02:00
parent 4e400369c0
commit 0d1208f0f0
4 changed files with 11 additions and 21 deletions

View File

@ -384,11 +384,16 @@ void QPropertyObserverPointer::observeProperty(QPropertyBasePointer property)
property.addObserver(ptr); property.addObserver(ptr);
} }
QPropertyBindingError::QPropertyBindingError(Type type) QPropertyBindingError::QPropertyBindingError()
{
}
QPropertyBindingError::QPropertyBindingError(Type type, const QString &description)
{ {
if (type != NoError) { if (type != NoError) {
d = new QPropertyBindingErrorPrivate; d = new QPropertyBindingErrorPrivate;
d->type = type; d->type = type;
d->description = description;
} }
} }
@ -425,13 +430,6 @@ QPropertyBindingError::Type QPropertyBindingError::type() const
return d->type; return d->type;
} }
void QPropertyBindingError::setDescription(const QString &description)
{
if (!d)
d = new QPropertyBindingErrorPrivate;
d->description = description;
}
QString QPropertyBindingError::description() const QString QPropertyBindingError::description() const
{ {
if (!d) if (!d)
@ -439,13 +437,6 @@ QString QPropertyBindingError::description() const
return d->description; return d->description;
} }
QPropertyBindingSourceLocation QPropertyBindingError::location() const
{
if (!d)
return QPropertyBindingSourceLocation();
return d->location;
}
/*! /*!
\class QProperty \class QProperty
\inmodule QtCore \inmodule QtCore

View File

@ -99,17 +99,18 @@ public:
UnknownError UnknownError
}; };
QPropertyBindingError(Type type = NoError); QPropertyBindingError();
QPropertyBindingError(Type type, const QString &description = QString());
QPropertyBindingError(const QPropertyBindingError &other); QPropertyBindingError(const QPropertyBindingError &other);
QPropertyBindingError &operator=(const QPropertyBindingError &other); QPropertyBindingError &operator=(const QPropertyBindingError &other);
QPropertyBindingError(QPropertyBindingError &&other); QPropertyBindingError(QPropertyBindingError &&other);
QPropertyBindingError &operator=(QPropertyBindingError &&other); QPropertyBindingError &operator=(QPropertyBindingError &&other);
~QPropertyBindingError(); ~QPropertyBindingError();
bool hasError() const { return d.get() != nullptr; }
Type type() const; Type type() const;
void setDescription(const QString &description);
QString description() const; QString description() const;
QPropertyBindingSourceLocation location() const;
private: private:
QSharedDataPointer<QPropertyBindingErrorPrivate> d; QSharedDataPointer<QPropertyBindingErrorPrivate> d;

View File

@ -103,7 +103,6 @@ class QPropertyBindingErrorPrivate : public QSharedData
public: public:
QPropertyBindingError::Type type = QPropertyBindingError::NoError; QPropertyBindingError::Type type = QPropertyBindingError::NoError;
QString description; QString description;
QPropertyBindingSourceLocation location;
}; };
struct BindingEvaluationState struct BindingEvaluationState

View File

@ -506,8 +506,7 @@ void tst_QProperty::bindingSourceLocation()
void tst_QProperty::bindingError() void tst_QProperty::bindingError()
{ {
QProperty<int> prop = Qt::makePropertyBinding([]() -> std::variant<int, QPropertyBindingError> { QProperty<int> prop = Qt::makePropertyBinding([]() -> std::variant<int, QPropertyBindingError> {
QPropertyBindingError error(QPropertyBindingError::UnknownError); QPropertyBindingError error(QPropertyBindingError::UnknownError, QLatin1String("my error"));
error.setDescription(QLatin1String("my error"));
return error; return error;
}); });
QCOMPARE(prop.value(), 0); QCOMPARE(prop.value(), 0);