Bug fixes and improvements for PropertyIndex discovered during refs #319, mainly contributing to refs #314

* Start index 10 instead 0 for CValueObject (easier to detect bugs)
* Fixed wrong indexes
* Asserts in CPropertyIndex
* Used Icon instead of QPixpmap with indexes, icons are sortable and have a tooltip
* Removed redundant toQVariant methods
This commit is contained in:
Klaus Basan
2014-08-31 15:04:52 +02:00
parent 674a0b5665
commit a6ebfc0e0b
14 changed files with 64 additions and 59 deletions

View File

@@ -29,6 +29,22 @@ namespace BlackMisc
class CAircraftSituation : public BlackMisc::CValueObject, public BlackMisc::Geo::ICoordinateGeodetic
{
public:
//! Properties by index
enum ColumnIndex
{
IndexPosition = BlackMisc::CPropertyIndex::GlobalIndexCAircraftSituation,
IndexLatitude,
IndexLongitude,
IndexAltitude,
IndexHeading,
IndexBank,
IndexPitch,
IndexGroundspeed,
IndexTimeStamp,
IndexTimeStampFormatted
};
//! Default constructor.
CAircraftSituation() : m_timestamp(QDateTime::currentDateTimeUtc()) {}
@@ -41,21 +57,6 @@ namespace BlackMisc
: m_position(position), m_altitude(altitude), m_heading(heading), m_pitch(pitch),
m_bank(bank), m_groundspeed(gs), m_timestamp(QDateTime::currentDateTimeUtc()) {}
//! Properties by index
enum ColumnIndex
{
IndexPosition,
IndexLatitude,
IndexLongitude,
IndexAltitude,
IndexHeading,
IndexBank,
IndexPitch,
IndexGroundspeed,
IndexTimeStamp,
IndexTimeStampFormatted
};
//! \copydoc CValueObject::propertyByIndex(index)
virtual QVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const override;

View File

@@ -35,8 +35,9 @@ namespace BlackMisc
};
//! Indexes
enum ColumnIndex {
IndexMode,
enum ColumnIndex
{
IndexMode = BlackMisc::CPropertyIndex::GlobalIndexCTransponder,
IndexModeAsString,
IndexTransponderCode,
IndexTransponderCodeFormatted,

View File

@@ -45,9 +45,6 @@ namespace BlackMisc
//! Init by double value
CLatitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CEarthAngle(value, unit) {}
//! \copydoc CValueObject::toQVariant
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
//! Virtual destructor
virtual ~CLatitude() {}
};

View File

@@ -42,9 +42,6 @@ namespace BlackMisc
//! Init by double value
CLongitude(double value, const BlackMisc::PhysicalQuantities::CAngleUnit &unit) : CEarthAngle(value, unit) {}
//! \copydoc CValueObject::toQVariant
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
//! Virtual destructor
virtual ~CLongitude() {}
};

View File

@@ -127,17 +127,13 @@ namespace BlackMisc
return QVariant(this->m_name);
case IndexVariant:
return this->m_variant.toQVariant();
case IndexCallsignIcon:
case IndexIcon:
return this->m_icon.toQVariant();
case IndexPixmap:
return this->m_icon.toPixmap();
default:
break;
return CValueObject::propertyByIndex(index);
}
Q_ASSERT_X(false, "CNameVariantPair", "index unknown");
QString m = QString("no property, index ").append(index.toQString());
return QVariant::fromValue(m);
}
/*
@@ -159,8 +155,8 @@ namespace BlackMisc
case IndexVariant:
this->m_variant = variant;
break;
case IndexCallsignIcon:
if (variant.canConvert<int>())
case IndexIcon:
if (variant.type() == QMetaType::Int)
{
CIcons::IconIndex index = static_cast<CIcons::IconIndex>(variant.toInt());
this->m_icon = CIconList::iconForIndex(index);
@@ -171,7 +167,7 @@ namespace BlackMisc
}
break;
default:
Q_ASSERT_X(false, "CNameVariantPair", "index unknown");
CValueObject::setPropertyByIndex(variant, index);
break;
}
}

View File

@@ -72,9 +72,9 @@ namespace BlackMisc
//! Properties by index
enum ColumnIndex
{
IndexName = 0,
IndexName = BlackMisc::CPropertyIndex::GlobalIndexCNameVariantPair,
IndexVariant,
IndexCallsignIcon,
IndexIcon,
IndexPixmap
};

View File

@@ -197,6 +197,10 @@ namespace BlackMisc
return this->m_voiceCapabilities.propertyByIndex(index.copyFrontRemoved());
case IndexVoiceCapabilitiesPixmap:
return QVariant(this->m_voiceCapabilities.toPixmap());
case IndexVoiceCapabilitiesIcon:
return QVariant(this->m_voiceCapabilities.toIcon().toQVariant());
case IndexVoiceCapabilitiesString:
return QVariant(this->m_voiceCapabilities.toQString(true));
default:
return CValueObject::propertyByIndex(index);
}

View File

@@ -40,13 +40,14 @@ namespace BlackMisc
IndexCallsign,
IndexVoiceCapabilities,
IndexVoiceCapabilitiesString,
IndexVoiceCapabilitiesPixmap
IndexVoiceCapabilitiesPixmap,
IndexVoiceCapabilitiesIcon
};
//! The Capabilities enum
enum Capabilities
{
FsdWithInterimPositions,
FsdWithInterimPositions = BlackMisc::CPropertyIndex::GlobalIndexAbuseMode,
FsdWithModelDescription,
FsdAtisCanBeReceived
};
@@ -60,7 +61,6 @@ namespace BlackMisc
//! Constructor.
CClient(const CUser &user) : m_user(user) {}
//! Equal operator ==
bool operator ==(const CClient &other) const;

View File

@@ -28,7 +28,7 @@ namespace BlackMisc
//! Properties by index
enum ColumnIndex
{
IndexName = 0,
IndexName = BlackMisc::CPropertyIndex::GlobalIndexCServer,
IndexDescription,
IndexAddress,
IndexPort,

View File

@@ -23,6 +23,7 @@ namespace BlackMisc
*/
CPropertyIndex::CPropertyIndex(int singleProperty)
{
Q_ASSERT(singleProperty >= static_cast<int>(GlobalIndexCValueObject));
this->m_indexes.append(singleProperty);
this->listToString();
}
@@ -152,6 +153,7 @@ namespace BlackMisc
QString l;
foreach(int i, this->m_indexes)
{
Q_ASSERT(i >= static_cast<int>(GlobalIndexCValueObject));
if (!l.isEmpty()) { l.append(";"); }
l.append(QString::number(i));
}
@@ -172,6 +174,7 @@ namespace BlackMisc
bool ok;
int i = index.toInt(&ok);
Q_ASSERT(ok);
Q_ASSERT(i >= static_cast<int>(GlobalIndexCValueObject));
this->m_indexes.append(i);
}
}

View File

@@ -33,23 +33,29 @@ namespace BlackMisc
//! Global index, make sure the indexes are unqiue (for using them in class hierarchy)
enum GlobalIndex
{
GlobalIndexCValueObject = 0,
GlobalIndexCPhysicalQuantity = 100,
GlobalIndexCStatusMessage = 200,
GlobalIndexCCallsign = 1000,
GlobalIndexCAircraftIcao = 1100,
GlobalIndexCAircraft = 1200,
GlobalIndexCAtcStation = 1300,
GlobalIndexCAirport = 1400,
GlobalIndexCModulator = 2000,
GlobalIndexICoordinateGeodetic = 3000,
GlobalIndexCCoordinateGeodetic = 3100,
GlobalIndexCClient = 4000,
GlobalIndexCUser = 4100,
GlobalIndexCAircraftModel = 4200,
GlobalIndexCVoiceRoom = 5000,
GlobalIndexCAircraftMapping = 6000,
GlobalIndexCAircraftCfgEntries = 6100
GlobalIndexCValueObject = 10, // GlobalIndexCValueObject needs to be set manually in CValueObject
GlobalIndexCPhysicalQuantity = 100,
GlobalIndexCStatusMessage = 200,
GlobalIndexCNameVariantPair = 300,
GlobalIndexCCallsign = 1000,
GlobalIndexCAircraftIcao = 1100,
GlobalIndexCAircraft = 1200,
GlobalIndexCAircraftSituation = 1300,
GlobalIndexCAtcStation = 1400,
GlobalIndexCAirport = 1500,
GlobalIndexCModulator = 2000,
GlobalIndexCTransponder = 2100,
GlobalIndexICoordinateGeodetic = 3000,
GlobalIndexCCoordinateGeodetic = 3100,
GlobalIndexCClient = 4000,
GlobalIndexCUser = 4100,
GlobalIndexCServer = 4200,
GlobalIndexCAircraftModel = 4300,
GlobalIndexCVoiceRoom = 5000,
GlobalIndexCSettingKeyboardHotkey = 6000,
GlobalIndexCAircraftMapping = 7000,
GlobalIndexCAircraftCfgEntries = 7100,
GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise
};
//! Default constructor.
@@ -64,7 +70,7 @@ namespace BlackMisc
//! Construct from a base class object.
CPropertyIndex(const QList<int> &indexes);
//! From string
//! From string
CPropertyIndex(const QString &indexes);
//! Copy with first element removed

View File

@@ -31,7 +31,7 @@ namespace BlackMisc
//! Properties by index
enum ColumnIndex
{
IndexKey = 0,
IndexKey = BlackMisc::CPropertyIndex::GlobalIndexCSettingKeyboardHotkey,
IndexKeyAsString,
IndexKeyAsStringRepresentation,
IndexModifier1,

View File

@@ -163,7 +163,7 @@ namespace BlackMisc
//! Base class enums
enum ColumnIndex
{
IndexPixmap,
IndexPixmap = 10, // manually set to avoid circular dependencies
IndexIcon,
IndexString
};

View File

@@ -32,7 +32,7 @@ namespace BlackSim
//! Properties by index
enum ColumnIndex
{
IndexEntryIndex = BlackMisc::CPropertyIndex::GlobalIndexCAircraftModel,
IndexEntryIndex = BlackMisc::CPropertyIndex::GlobalIndexCAircraftCfgEntries,
IndexFilePath,
IndexTitle,
IndexAtcType,