refs #314, new propertyBy methods (nested indexes)

This commit is contained in:
Klaus Basan
2014-08-15 18:17:15 +02:00
parent d797d76a60
commit e109d73ba2
54 changed files with 1016 additions and 754 deletions

View File

@@ -8,6 +8,7 @@
*/
#include "blackmisc/aviotransponder.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/blackmiscfreefunctions.h"
namespace BlackMisc
@@ -222,5 +223,67 @@ namespace BlackMisc
{
BlackMisc::deserializeJson(json, CTransponder::jsonMembers(), TupleConverter<CTransponder>::toTuple(*this));
}
/*
* Property
*/
QVariant CTransponder::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return this->toQVariant(); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexMode:
return QVariant(this->getTransponderMode());
case IndexModeAsString:
return QVariant(this->getModeAsString());
case IndexTransponderCode:
return QVariant(this->getTransponderCode());
case IndexTransponderCodeFormatted:
return QVariant(this->getTransponderCodeFormatted());
case IndexTransponderCodeAndModeFormatted:
return QVariant(this->getTransponderCodeAndModeFormatted());
default:
break;
}
Q_ASSERT_X(false, "CTransponder", "index unknown");
QString m = QString("no property, index ").append(index.toQString());
return QVariant::fromValue(m);
}
void CTransponder::setPropertyByIndex(const QVariant &variant, const CPropertyIndex &index)
{
if (index.isMyself())
{
this->fromQVariant(variant);
return;
}
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexMode:
this->setTransponderMode(static_cast<TransponderMode>(variant.toInt()));
break;
case IndexModeAsString:
this->setTransponderMode(modeFromString(variant.toString()));
break;
case IndexTransponderCode:
case IndexTransponderCodeFormatted:
if (variant.canConvert<int>())
{
this->setTransponderCode(variant.toInt());
}
else
{
this->setTransponderCode(variant.toString());
}
break;
case IndexTransponderCodeAndModeFormatted:
default:
Q_ASSERT_X(false, "CTransponder", "index unknown");
break;
}
}
} // namespace
} // namespace