Fix alert sorting by using new TimePointRole for active filtering

This commit is contained in:
Dan Paulat 2022-11-12 00:03:05 -06:00
parent 43409b128a
commit d19656f0f1
3 changed files with 32 additions and 13 deletions

View file

@ -34,6 +34,8 @@ public:
static std::string GetCounties(const types::TextEventKey& key); static std::string GetCounties(const types::TextEventKey& key);
static std::string GetState(const types::TextEventKey& key); static std::string GetState(const types::TextEventKey& key);
static std::chrono::system_clock::time_point
GetStartTime(const types::TextEventKey& key);
static std::string GetStartTimeString(const types::TextEventKey& key); static std::string GetStartTimeString(const types::TextEventKey& key);
static std::chrono::system_clock::time_point static std::chrono::system_clock::time_point
GetEndTime(const types::TextEventKey& key); GetEndTime(const types::TextEventKey& key);
@ -96,7 +98,10 @@ QVariant AlertModel::data(const QModelIndex& index, int role) const
{ {
if (index.isValid() && index.row() >= 0 && if (index.isValid() && index.row() >= 0 &&
index.row() < p->textEventKeys_.size() && index.row() < p->textEventKeys_.size() &&
(role == Qt::DisplayRole || role == types::SortRole)) (role == Qt::DisplayRole || role == types::SortRole ||
(role == types::TimePointRole &&
(index.column() == static_cast<int>(Column::StartTime) ||
index.column() == static_cast<int>(Column::EndTime)))))
{ {
const auto& textEventKey = p->textEventKeys_.at(index.row()); const auto& textEventKey = p->textEventKeys_.at(index.row());
@ -124,20 +129,28 @@ QVariant AlertModel::data(const QModelIndex& index, int role) const
AlertModelImpl::GetCounties(textEventKey)); AlertModelImpl::GetCounties(textEventKey));
case static_cast<int>(Column::StartTime): case static_cast<int>(Column::StartTime):
return QString::fromStdString( if (role == types::TimePointRole)
AlertModelImpl::GetStartTimeString(textEventKey));
case static_cast<int>(Column::EndTime):
if (role == Qt::DisplayRole)
{ {
return QString::fromStdString( return QVariant::fromValue(
AlertModelImpl::GetEndTimeString(textEventKey)); AlertModelImpl::GetStartTime(textEventKey));
} }
else else
{
return QString::fromStdString(
AlertModelImpl::GetStartTimeString(textEventKey));
}
case static_cast<int>(Column::EndTime):
if (role == types::TimePointRole)
{ {
return QVariant::fromValue( return QVariant::fromValue(
AlertModelImpl::GetEndTime(textEventKey)); AlertModelImpl::GetEndTime(textEventKey));
} }
else
{
return QString::fromStdString(
AlertModelImpl::GetEndTimeString(textEventKey));
}
case static_cast<int>(Column::Distance): case static_cast<int>(Column::Distance):
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
@ -333,13 +346,18 @@ std::string AlertModelImpl::GetState(const types::TextEventKey& key)
return util::ToString(lastSegment->header_->ugc_.states()); return util::ToString(lastSegment->header_->ugc_.states());
} }
std::string AlertModelImpl::GetStartTimeString(const types::TextEventKey& key) std::chrono::system_clock::time_point
AlertModelImpl::GetStartTime(const types::TextEventKey& key)
{ {
auto messageList = manager::TextEventManager::Instance()->message_list(key); auto messageList = manager::TextEventManager::Instance()->message_list(key);
auto& firstMessage = messageList.front(); auto& firstMessage = messageList.front();
auto firstSegment = firstMessage->segment(0); auto firstSegment = firstMessage->segment(0);
return util::TimeString( return firstSegment->header_->vtecString_[0].pVtec_.event_begin();
firstSegment->header_->vtecString_[0].pVtec_.event_begin()); }
std::string AlertModelImpl::GetStartTimeString(const types::TextEventKey& key)
{
return util::TimeString(GetStartTime(key));
} }
std::chrono::system_clock::time_point std::chrono::system_clock::time_point

View file

@ -49,7 +49,7 @@ bool AlertProxyModel::filterAcceptsRow(int sourceRow,
// Get source end time // Get source end time
auto endTime = sourceModel() auto endTime = sourceModel()
->data(endTimeIndex, qt::types::SortRole) ->data(endTimeIndex, types::TimePointRole)
.value<std::chrono::system_clock::time_point>(); .value<std::chrono::system_clock::time_point>();
// Compare end time to current // Compare end time to current

View file

@ -11,7 +11,8 @@ namespace types
enum ItemDataRole enum ItemDataRole
{ {
SortRole = Qt::UserRole SortRole = Qt::UserRole,
TimePointRole
}; };
} // namespace types } // namespace types