From 4d0f8b9fa0681ea1b0da6a3a33509ddf8e2137ac Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 5 Feb 2019 15:27:04 +0100 Subject: [PATCH] Ref T529, check for timestamp/orderable index --- src/blackmisc/orderable.cpp | 7 ++++++- src/blackmisc/orderable.h | 5 ++++- src/blackmisc/timestampbased.cpp | 23 ++++++++++++++--------- src/blackmisc/timestampbased.h | 3 +++ 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/blackmisc/orderable.cpp b/src/blackmisc/orderable.cpp index 107867566..e22de14b3 100644 --- a/src/blackmisc/orderable.cpp +++ b/src/blackmisc/orderable.cpp @@ -34,11 +34,16 @@ namespace BlackMisc return this->getOrder() >= 0; } + bool IOrderable::isAnyOrderIndex(int index) + { + return (index >= static_cast(IndexOrder)) && (index <= static_cast(IndexOrderString)); + } + bool IOrderable::canHandleIndex(const CPropertyIndex &index) { if (index.isEmpty()) { return false; } const int i = index.frontCasted(); - return (i >= static_cast(IndexOrder)) && (i <= static_cast(IndexOrderString)); + return isAnyOrderIndex(i); } CVariant IOrderable::propertyByIndex(const CPropertyIndex &index) const diff --git a/src/blackmisc/orderable.h b/src/blackmisc/orderable.h index b6660428b..f456bd626 100644 --- a/src/blackmisc/orderable.h +++ b/src/blackmisc/orderable.h @@ -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(); diff --git a/src/blackmisc/timestampbased.cpp b/src/blackmisc/timestampbased.cpp index 9322edfda..b350dc7d6 100644 --- a/src/blackmisc/timestampbased.cpp +++ b/src/blackmisc/timestampbased.cpp @@ -175,11 +175,16 @@ namespace BlackMisc return m_timestampMSecsSinceEpoch >= 0; } + bool ITimestampBased::isAnyTimestampIndex(int index) + { + return (index >= static_cast(IndexUtcTimestamp)) && (index <= static_cast(IndexMSecsSinceEpoch)); + } + bool ITimestampBased::canHandleIndex(const CPropertyIndex &index) { if (index.isEmpty()) { return false; } const int i = index.frontCasted(); - return (i >= static_cast(IndexUtcTimestamp)) && (i <= static_cast(IndexMSecsSinceEpoch)); + return isAnyTimestampIndex(i); } CVariant ITimestampBased::propertyByIndex(const CPropertyIndex &index) const @@ -189,15 +194,15 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); 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; } } diff --git a/src/blackmisc/timestampbased.h b/src/blackmisc/timestampbased.h index 293fb7716..a9b185919 100644 --- a/src/blackmisc/timestampbased.h +++ b/src/blackmisc/timestampbased.h @@ -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);