Ref T529, check for timestamp/orderable index

This commit is contained in:
Klaus Basan
2019-02-05 15:27:04 +01:00
committed by Mat Sutcliffe
parent b2ec28e3cd
commit 4d0f8b9fa0
4 changed files with 27 additions and 11 deletions

View File

@@ -34,11 +34,16 @@ namespace BlackMisc
return this->getOrder() >= 0; return this->getOrder() >= 0;
} }
bool IOrderable::isAnyOrderIndex(int index)
{
return (index >= static_cast<int>(IndexOrder)) && (index <= static_cast<int>(IndexOrderString));
}
bool IOrderable::canHandleIndex(const CPropertyIndex &index) bool IOrderable::canHandleIndex(const CPropertyIndex &index)
{ {
if (index.isEmpty()) { return false; } if (index.isEmpty()) { return false; }
const int i = index.frontCasted<int>(); const int i = index.frontCasted<int>();
return (i >= static_cast<int>(IndexOrder)) && (i <= static_cast<int>(IndexOrderString)); return isAnyOrderIndex(i);
} }
CVariant IOrderable::propertyByIndex(const CPropertyIndex &index) const CVariant IOrderable::propertyByIndex(const CPropertyIndex &index) const

View File

@@ -43,10 +43,13 @@ namespace BlackMisc
//! Valid order set? //! Valid order set?
bool hasValidOrder() const; bool hasValidOrder() const;
//! Any order index
static bool isAnyOrderIndex(int index);
protected:
//! Can given index be handled //! Can given index be handled
static bool canHandleIndex(const CPropertyIndex &index); static bool canHandleIndex(const CPropertyIndex &index);
protected:
//! Constructor //! Constructor
IOrderable(); IOrderable();

View File

@@ -175,11 +175,16 @@ namespace BlackMisc
return m_timestampMSecsSinceEpoch >= 0; return m_timestampMSecsSinceEpoch >= 0;
} }
bool ITimestampBased::isAnyTimestampIndex(int index)
{
return (index >= static_cast<int>(IndexUtcTimestamp)) && (index <= static_cast<int>(IndexMSecsSinceEpoch));
}
bool ITimestampBased::canHandleIndex(const CPropertyIndex &index) bool ITimestampBased::canHandleIndex(const CPropertyIndex &index)
{ {
if (index.isEmpty()) { return false; } if (index.isEmpty()) { return false; }
const int i = index.frontCasted<int>(); const int i = index.frontCasted<int>();
return (i >= static_cast<int>(IndexUtcTimestamp)) && (i <= static_cast<int>(IndexMSecsSinceEpoch)); return isAnyTimestampIndex(i);
} }
CVariant ITimestampBased::propertyByIndex(const CPropertyIndex &index) const CVariant ITimestampBased::propertyByIndex(const CPropertyIndex &index) const
@@ -189,15 +194,15 @@ namespace BlackMisc
const ColumnIndex i = index.frontCasted<ColumnIndex>(); const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i) switch (i)
{ {
case IndexUtcTimestamp: return CVariant::fromValue(this->getUtcTimestamp()); case IndexUtcTimestamp: return CVariant::fromValue(this->getUtcTimestamp());
case IndexMSecsSinceEpoch: return CVariant::fromValue(this->getMSecsSinceEpoch()); case IndexMSecsSinceEpoch: return CVariant::fromValue(this->getMSecsSinceEpoch());
case IndexUtcTimestampFormattedDhms: return CVariant::fromValue(this->getFormattedUtcTimestampDhms()); case IndexUtcTimestampFormattedDhms: return CVariant::fromValue(this->getFormattedUtcTimestampDhms());
case IndexUtcTimestampFormattedHm: return CVariant::fromValue(this->getFormattedUtcTimestampHm()); case IndexUtcTimestampFormattedHm: return CVariant::fromValue(this->getFormattedUtcTimestampHm());
case IndexUtcTimestampFormattedHms: return CVariant::fromValue(this->getFormattedUtcTimestampHms()); case IndexUtcTimestampFormattedHms: return CVariant::fromValue(this->getFormattedUtcTimestampHms());
case IndexUtcTimestampFormattedYmdhms: return CVariant::fromValue(this->getFormattedUtcTimestampYmdhms()); case IndexUtcTimestampFormattedYmdhms: return CVariant::fromValue(this->getFormattedUtcTimestampYmdhms());
case IndexUtcTimestampFormattedYmdhmsz: return CVariant::fromValue(this->getFormattedUtcTimestampYmdhmsz()); case IndexUtcTimestampFormattedYmdhmsz: return CVariant::fromValue(this->getFormattedUtcTimestampYmdhmsz());
case IndexUtcTimestampFormattedMdhms: return CVariant::fromValue(this->getFormattedUtcTimestampMdhms()); case IndexUtcTimestampFormattedMdhms: return CVariant::fromValue(this->getFormattedUtcTimestampMdhms());
case IndexUtcTimestampFormattedMdhmsz: return CVariant::fromValue(this->getFormattedUtcTimestampMdhmsz()); case IndexUtcTimestampFormattedMdhmsz: return CVariant::fromValue(this->getFormattedUtcTimestampMdhmsz());
default: break; default: break;
} }
} }

View File

@@ -133,6 +133,9 @@ namespace BlackMisc
//! Valid timestamp? //! Valid timestamp?
bool hasValidTimestamp() const; bool hasValidTimestamp() const;
//! Any of the timestamp indexes
static bool isAnyTimestampIndex(int index);
protected: protected:
//! Can given index be handled //! Can given index be handled
static bool canHandleIndex(const CPropertyIndex &index); static bool canHandleIndex(const CPropertyIndex &index);