mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
CValueMap generic representation of a value object as a map of QVariants
refs #81
This commit is contained in:
committed by
Mathew Sutcliffe
parent
a280d239e6
commit
bf1837b414
@@ -43,6 +43,35 @@ namespace BlackMisc
|
||||
return this->convertToQString();
|
||||
}
|
||||
|
||||
/*
|
||||
* Setter for property by index
|
||||
*/
|
||||
void CValueObject::setPropertyByIndex(const QVariant & /** variant **/, int /** index **/)
|
||||
{
|
||||
// not all classes have to implement this
|
||||
qFatal("Property by index setter not implemented");
|
||||
}
|
||||
|
||||
/*
|
||||
* By index
|
||||
*/
|
||||
QVariant CValueObject::propertyByIndex(int /** index **/) const
|
||||
{
|
||||
// not all classes have to implement this
|
||||
qFatal("Property by index not implemented");
|
||||
return QVariant("boom"); // avoid compiler warning
|
||||
}
|
||||
|
||||
/*
|
||||
* By index as string
|
||||
*/
|
||||
QString CValueObject::propertyByIndexAsString(int /** index **/, bool /** i18n **/) const
|
||||
{
|
||||
// not all classes have to implement this
|
||||
qFatal("Property by index as string not implemented");
|
||||
return QString("boom"); // avoid compiler warning
|
||||
}
|
||||
|
||||
/*
|
||||
* Return backing streamable object (if any)
|
||||
*/
|
||||
@@ -70,6 +99,65 @@ namespace BlackMisc
|
||||
return -1; // avoid compiler warning
|
||||
}
|
||||
|
||||
/*!
|
||||
* Variant map
|
||||
*/
|
||||
int CValueObject::apply(const BlackMisc::CValueMap &valueMap)
|
||||
{
|
||||
if (valueMap.isEmpty()) return 0;
|
||||
int c = 0;
|
||||
|
||||
QMap<int, QVariant>::const_iterator it;
|
||||
const QMap<int, QVariant> &map = valueMap.map();
|
||||
for (it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
this->setPropertyByIndex(it.value(), it.key());
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare with value map
|
||||
*/
|
||||
bool operator==(const CValueMap &valueMap, const CValueObject &uc)
|
||||
{
|
||||
if (valueMap.isEmpty()) return valueMap.isWildcard();
|
||||
QMap<int, QVariant>::const_iterator it;
|
||||
const QMap<int, QVariant> &map = valueMap.map();
|
||||
for (it = map.begin(); it != map.end(); ++it)
|
||||
{
|
||||
// QVariant cannot be compared directly
|
||||
QVariant p = uc.propertyByIndex(it.key()); // from value object
|
||||
QVariant v = it.value(); // from map
|
||||
if (!BlackMisc::equalQVariants(p, v)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare with value map
|
||||
*/
|
||||
bool operator!=(const CValueMap &valueMap, const CValueObject &uc)
|
||||
{
|
||||
return !(valueMap == uc);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare with value map
|
||||
*/
|
||||
bool operator==(const CValueObject &uc, const CValueMap &valueMap)
|
||||
{
|
||||
return valueMap == uc;
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare with value map
|
||||
*/
|
||||
bool operator!=(const CValueObject &uc, const CValueMap &valueMap)
|
||||
{
|
||||
return !(valueMap == uc);
|
||||
}
|
||||
|
||||
/*
|
||||
* from DBus
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user