mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-14 09:25:49 +08:00
refs #356 Update remaining CValueObject derived classes to use CValueObjectStdTuple instead.
This commit is contained in:
@@ -23,84 +23,6 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
/*
|
||||
* metaTypeId
|
||||
*/
|
||||
int CTestValueObject::getMetaTypeId() const
|
||||
{
|
||||
return qMetaTypeId<CTestValueObject>();
|
||||
}
|
||||
|
||||
/*
|
||||
* is a
|
||||
*/
|
||||
bool CTestValueObject::isA(int metaTypeId) const
|
||||
{
|
||||
if (metaTypeId == qMetaTypeId<CTestValueObject>()) { return true; }
|
||||
|
||||
return this->CValueObject::isA(metaTypeId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare
|
||||
*/
|
||||
int CTestValueObject::compareImpl(const CValueObject &otherBase) const
|
||||
{
|
||||
const auto &other = static_cast<const CTestValueObject &>(otherBase);
|
||||
|
||||
return compare(TupleConverter<CTestValueObject>::toTuple(*this), TupleConverter<CTestValueObject>::toTuple(other));
|
||||
}
|
||||
|
||||
/*
|
||||
* Marshall to DBus
|
||||
*/
|
||||
void CTestValueObject::marshallToDbus(QDBusArgument &argument) const
|
||||
{
|
||||
argument << TupleConverter<CTestValueObject>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unmarshall from DBus
|
||||
*/
|
||||
void CTestValueObject::unmarshallFromDbus(const QDBusArgument &argument)
|
||||
{
|
||||
argument >> TupleConverter<CTestValueObject>::toTuple(*this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal?
|
||||
*/
|
||||
bool CTestValueObject::operator ==(const CTestValueObject &other) const
|
||||
{
|
||||
if (this == &other) return true;
|
||||
return TupleConverter<CTestValueObject>::toTuple(*this) == TupleConverter<CTestValueObject>::toTuple(other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unequal?
|
||||
*/
|
||||
bool CTestValueObject::operator !=(const CTestValueObject &other) const
|
||||
{
|
||||
return !((*this) == other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Less than?
|
||||
*/
|
||||
bool CTestValueObject::operator <(const CTestValueObject &other) const
|
||||
{
|
||||
if (this == &other) return false;
|
||||
return TupleConverter<CTestValueObject>::toTuple(*this) < TupleConverter<CTestValueObject>::toTuple(other);
|
||||
}
|
||||
|
||||
/*
|
||||
* Hash
|
||||
*/
|
||||
uint CTestValueObject::getValueHash() const
|
||||
{
|
||||
return qHash(TupleConverter<CTestValueObject>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* Property by index
|
||||
*/
|
||||
@@ -115,7 +37,7 @@ namespace BlackMisc
|
||||
case IndexName:
|
||||
return CVariant::fromValue(this->m_name);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
return CValueObjectStdTuple::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,42 +61,9 @@ namespace BlackMisc
|
||||
this->setName(variant.value<QString>());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
CValueObjectStdTuple::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Register metadata
|
||||
*/
|
||||
void CTestValueObject::registerMetadata()
|
||||
{
|
||||
qRegisterMetaType<CTestValueObject>();
|
||||
qDBusRegisterMetaType<CTestValueObject>();
|
||||
}
|
||||
|
||||
/*
|
||||
* Members
|
||||
*/
|
||||
const QStringList &CTestValueObject::jsonMembers()
|
||||
{
|
||||
return TupleConverter<CTestValueObject>::jsonMembers();
|
||||
}
|
||||
|
||||
/*
|
||||
* To JSON
|
||||
*/
|
||||
QJsonObject CTestValueObject::toJson() const
|
||||
{
|
||||
return BlackMisc::serializeJson(CTestValueObject::jsonMembers(), TupleConverter<CTestValueObject>::toTuple(*this));
|
||||
}
|
||||
|
||||
/*
|
||||
* From Json
|
||||
*/
|
||||
void CTestValueObject::convertFromJson(const QJsonObject &json)
|
||||
{
|
||||
BlackMisc::deserializeJson(json, CTestValueObject::jsonMembers(), TupleConverter<CTestValueObject>::toTuple(*this));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace BlackMisc
|
||||
/*!
|
||||
* Value object encapsulating information of a server
|
||||
*/
|
||||
class CTestValueObject : public BlackMisc::CValueObject
|
||||
class CTestValueObject : public BlackMisc::CValueObjectStdTuple<CTestValueObject>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
@@ -51,71 +51,16 @@ namespace BlackMisc
|
||||
//! Set description
|
||||
void setDescription(const QString &description) { m_description = description; }
|
||||
|
||||
//! Equal operator ==
|
||||
bool operator ==(const CTestValueObject &other) const;
|
||||
|
||||
//! Unequal operator !=
|
||||
bool operator !=(const CTestValueObject &other) const;
|
||||
|
||||
//! Less than operator <
|
||||
bool operator <(const CTestValueObject &other) const;
|
||||
|
||||
//! \copydoc CValueObject::getValueHash()
|
||||
virtual uint getValueHash() const override;
|
||||
|
||||
//! \copydoc CValueObject::toJson
|
||||
virtual QJsonObject toJson() const override;
|
||||
|
||||
//! \copydoc CValueObject::fromJson
|
||||
void convertFromJson(const QJsonObject &json) override;
|
||||
|
||||
//! Register metadata
|
||||
static void registerMetadata();
|
||||
|
||||
//! \copydoc TupleConverter<>::jsonMembers()
|
||||
static const QStringList &jsonMembers();
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
virtual CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) override;
|
||||
|
||||
//! \copydoc CValueObject::toQVariant
|
||||
virtual QVariant toQVariant() const override
|
||||
{
|
||||
return QVariant::fromValue(*this);
|
||||
}
|
||||
|
||||
//! \copydoc CValueObject::fromQVariant
|
||||
virtual void convertFromQVariant(const QVariant &variant) override
|
||||
{
|
||||
Q_ASSERT(variant.canConvert<CTestValueObject>());
|
||||
if (variant.canConvert<CTestValueObject>())
|
||||
{
|
||||
(*this) = variant.value<CTestValueObject>();
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
//! \copydoc CValueObject::convertToQString()
|
||||
virtual QString convertToQString(bool i18n = false) const override;
|
||||
|
||||
//! \copydoc CValueObject::getMetaTypeId
|
||||
virtual int getMetaTypeId() const override;
|
||||
|
||||
//! \copydoc CValueObject::isA
|
||||
virtual bool isA(int metaTypeId) const override;
|
||||
|
||||
//! \copydoc CValueObject::compareImpl
|
||||
virtual int compareImpl(const CValueObject &other) const override;
|
||||
|
||||
//! \copydoc CValueObject::marshallToDbus
|
||||
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||
|
||||
//! \copydoc CValueObject::unmarshallFromDbus
|
||||
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CTestValueObject)
|
||||
QString m_name;
|
||||
|
||||
Reference in New Issue
Block a user