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;
}
bool IOrderable::isAnyOrderIndex(int index)
{
return (index >= static_cast<int>(IndexOrder)) && (index <= static_cast<int>(IndexOrderString));
}
bool IOrderable::canHandleIndex(const CPropertyIndex &index)
{
if (index.isEmpty()) { return false; }
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

View File

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

View File

@@ -175,11 +175,16 @@ namespace BlackMisc
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)
{
if (index.isEmpty()) { return false; }
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
@@ -189,15 +194,15 @@ namespace BlackMisc
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexUtcTimestamp: return CVariant::fromValue(this->getUtcTimestamp());
case IndexMSecsSinceEpoch: return CVariant::fromValue(this->getMSecsSinceEpoch());
case IndexUtcTimestampFormattedDhms: return CVariant::fromValue(this->getFormattedUtcTimestampDhms());
case IndexUtcTimestampFormattedHm: return CVariant::fromValue(this->getFormattedUtcTimestampHm());
case IndexUtcTimestampFormattedHms: return CVariant::fromValue(this->getFormattedUtcTimestampHms());
case IndexUtcTimestampFormattedYmdhms: return CVariant::fromValue(this->getFormattedUtcTimestampYmdhms());
case IndexUtcTimestamp: return CVariant::fromValue(this->getUtcTimestamp());
case IndexMSecsSinceEpoch: return CVariant::fromValue(this->getMSecsSinceEpoch());
case IndexUtcTimestampFormattedDhms: return CVariant::fromValue(this->getFormattedUtcTimestampDhms());
case IndexUtcTimestampFormattedHm: return CVariant::fromValue(this->getFormattedUtcTimestampHm());
case IndexUtcTimestampFormattedHms: return CVariant::fromValue(this->getFormattedUtcTimestampHms());
case IndexUtcTimestampFormattedYmdhms: return CVariant::fromValue(this->getFormattedUtcTimestampYmdhms());
case IndexUtcTimestampFormattedYmdhmsz: return CVariant::fromValue(this->getFormattedUtcTimestampYmdhmsz());
case IndexUtcTimestampFormattedMdhms: return CVariant::fromValue(this->getFormattedUtcTimestampMdhms());
case IndexUtcTimestampFormattedMdhmsz: return CVariant::fromValue(this->getFormattedUtcTimestampMdhmsz());
case IndexUtcTimestampFormattedMdhms: return CVariant::fromValue(this->getFormattedUtcTimestampMdhms());
case IndexUtcTimestampFormattedMdhmsz: return CVariant::fromValue(this->getFormattedUtcTimestampMdhmsz());
default: break;
}
}

View File

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