mirror of https://github.com/qt/qtgrpc.git
QProtobufMessage: Extract Methods Private::metaType()
One overload each for string and field-info lookup. These will be used in a subsequent commit to add rvalue-QVariant overloads, but commit this separately to avoid introducing unnecessary differences to our LTS branch, by picking to 6.5. Task-number: QTBUG-112762 Pick-to: 6.5 Change-Id: I87951851f32a1fa44caa48baa0bdaf0068154781 Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
This commit is contained in:
parent
aeda214b91
commit
dc69102f4f
|
|
@ -61,6 +61,25 @@ void QProtobufMessagePrivate::storeUnknownEntry(QByteArrayView entry)
|
|||
++unknownEntries[entry.toByteArray()];
|
||||
}
|
||||
|
||||
std::optional<QMetaProperty> QProtobufMessagePrivate::metaProperty(QAnyStringView name) const
|
||||
{
|
||||
const int index = getPropertyIndex(name);
|
||||
const QMetaProperty property = metaObject->property(index);
|
||||
if (property.isValid())
|
||||
return property;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<QMetaProperty>
|
||||
QProtobufMessagePrivate::metaProperty(QtProtobufPrivate::QProtobufPropertyOrderingInfo info) const
|
||||
{
|
||||
const int propertyIndex = info.getPropertyIndex() + metaObject->propertyOffset();
|
||||
const QMetaProperty metaProperty = metaObject->property(propertyIndex);
|
||||
if (metaProperty.isValid())
|
||||
return metaProperty;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/*!
|
||||
Set the property \a propertyName to the value stored in \a value.
|
||||
|
||||
|
|
@ -74,11 +93,10 @@ bool QProtobufMessage::setProperty(QAnyStringView propertyName, const QVariant &
|
|||
{
|
||||
Q_D(QProtobufMessage);
|
||||
|
||||
int index = d->getPropertyIndex(propertyName);
|
||||
const QMetaProperty &property = d->metaObject->property(index);
|
||||
if (!property.isValid())
|
||||
if (auto mp = d->metaProperty(propertyName))
|
||||
return mp->writeOnGadget(this, value);
|
||||
|
||||
return false;
|
||||
return property.writeOnGadget(this, value);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -90,9 +108,9 @@ QVariant QProtobufMessage::property(QAnyStringView propertyName) const
|
|||
{
|
||||
Q_D(const QProtobufMessage);
|
||||
|
||||
int index = d->getPropertyIndex(propertyName);
|
||||
const QMetaProperty &property = d->metaObject->property(index);
|
||||
return property.readOnGadget(this);
|
||||
if (const auto mp = d->metaProperty(propertyName))
|
||||
return mp->readOnGadget(this);
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
@ -214,13 +232,11 @@ QProtobufMessage::property(const QtProtobufPrivate::QProtobufPropertyOrderingInf
|
|||
bool QProtobufMessage::setProperty(
|
||||
const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo, const QVariant &value)
|
||||
{
|
||||
int propertyIndex = fieldInfo.getPropertyIndex() + metaObject()->propertyOffset();
|
||||
QMetaProperty metaProperty = metaObject()->property(propertyIndex);
|
||||
|
||||
if (!metaProperty.isValid())
|
||||
Q_D(QProtobufMessage);
|
||||
const auto mp = d->metaProperty(fieldInfo);
|
||||
if (!mp)
|
||||
return false;
|
||||
|
||||
return metaProperty.writeOnGadget(this, value);
|
||||
return mp->writeOnGadget(this, value);
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
|
|
|||
|
|
@ -23,8 +23,12 @@
|
|||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/private/qglobal_p.h>
|
||||
|
||||
#include <optional>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class QMetaProperty;
|
||||
|
||||
class QProtobufMessagePrivate
|
||||
{
|
||||
public:
|
||||
|
|
@ -38,6 +42,10 @@ public:
|
|||
int getPropertyIndex(QAnyStringView propertyName) const;
|
||||
void storeUnknownEntry(QByteArrayView entry);
|
||||
|
||||
std::optional<QMetaProperty> metaProperty(QAnyStringView name) const;
|
||||
std::optional<QMetaProperty>
|
||||
metaProperty(QtProtobufPrivate::QProtobufPropertyOrderingInfo ord) const;
|
||||
|
||||
static QProtobufMessagePrivate *get(QProtobufMessage *message) { return message->d_func(); }
|
||||
static const QProtobufMessagePrivate *get(const QProtobufMessage *message)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue