diff options
author | John Thacker <johnthacker@gmail.com> | 2023-02-20 06:49:51 -0500 |
---|---|---|
committer | John Thacker <johnthacker@gmail.com> | 2023-02-23 12:59:50 +0000 |
commit | 5948274adbc6022bf9530d44b69d671949d58a44 (patch) | |
tree | ad6fb717dbaebd1131060fc62880a2f9d528c115 /ui | |
parent | 0bd4d9b13218ffadd94ba40fc8af052febf293b3 (diff) |
Qt: Show date for abs time for long captures in Conversations
Display the date with the absolute time if a conversation in the
conversation table is over 24 hours long. Parse user entered filter
strings for date times as both date times and dates.
Fix #16092
Diffstat (limited to 'ui')
-rw-r--r-- | ui/qt/models/atap_data_model.cpp | 19 | ||||
-rw-r--r-- | ui/qt/widgets/traffic_tree.cpp | 53 |
2 files changed, 49 insertions, 23 deletions
diff --git a/ui/qt/models/atap_data_model.cpp b/ui/qt/models/atap_data_model.cpp index 5751b60b5b..635821bba8 100644 --- a/ui/qt/models/atap_data_model.cpp +++ b/ui/qt/models/atap_data_model.cpp @@ -738,12 +738,21 @@ QVariant ConversationDataModel::data(const QModelIndex &idx, int role) const if (_absoluteTime) { nstime_t *abs_time = &conv_item->start_abs_time; - QDateTime abs_dt = QDateTime::fromMSecsSinceEpoch(nstime_to_msec(abs_time)); - /* XXX: Should the display include the date as well? More - * clutter, but captures can span midnight. It's probably - * fine so long as the capture isn't more than 24 hours. + /* XXX: QDateTime only supports millisecond resolution, + * and we have microseconds or nanoseconds. + * Should we use something else, particularly for exporting + * raw data? GDateTime handles microseconds. */ - return role == Qt::DisplayRole ? abs_dt.time().toString(Qt::ISODateWithMs) : QVariant(abs_dt); + QDateTime abs_dt = QDateTime::fromMSecsSinceEpoch(nstime_to_msec(abs_time)); + if (role == Qt::DisplayRole) { + if (_maxRelStopTime >= 24*60*60) { + return abs_dt.toString(Qt::ISODateWithMs); + } else { + return abs_dt.time().toString(Qt::ISODateWithMs); + } + } else { + return QVariant(abs_dt); + } } else { return role == Qt::DisplayRole ? QString::number(nstime_to_sec(&conv_item->start_time), 'f', width) : diff --git a/ui/qt/widgets/traffic_tree.cpp b/ui/qt/widgets/traffic_tree.cpp index adff561e6d..be154d7d42 100644 --- a/ui/qt/widgets/traffic_tree.cpp +++ b/ui/qt/widgets/traffic_tree.cpp @@ -44,6 +44,7 @@ #include <QWidgetAction> #include <QLineEdit> #include <QActionGroup> +#include <QDateTime> #include <QTime> MenuEditAction::MenuEditAction(QString text, QString hintText, QObject * parent) : @@ -337,20 +338,21 @@ bool TrafficDataFilterProxy::filterAcceptsRow(int source_row, const QModelIndex */ QVariant rhs = QVariant(_filterText); if (data.userType() == QMetaType::QDateTime) { - /* When we display start time in absolute format, we only - * display the time portion, so users will expect to enter - * time-only filters. Convert to QTime instead of QDateTime. - * (Sorting in the table will use the date as well, but it's - * unreasonable to expect users to type in a date that they - * can't see when filtering.) + /* Try to parse with a date included in the filter, and + * fallback to time only if that fails. */ - QTime filterTime = QTime::fromString(_filterText, Qt::ISODateWithMs); - if (filterTime.isValid()) { - rhs.setValue(filterTime); + QDateTime filter_dt = QDateTime::fromString(_filterText, Qt::ISODateWithMs); + if (filter_dt.isValid()) { + rhs.setValue(filter_dt); } else { - rhs = QVariant(); + QTime filterTime = QTime::fromString(_filterText, Qt::ISODateWithMs); + if (filterTime.isValid()) { + rhs.setValue(filterTime); + data.setValue(data.toTime()); + } else { + rhs = QVariant(); + } } - data.setValue(data.toTime()); } QPartialOrdering result = QVariant::compare(data, rhs); if (_filterOn == TrafficDataFilterProxy::TRAFFIC_DATA_LESS) @@ -390,18 +392,33 @@ bool TrafficDataFilterProxy::filterAcceptsRow(int source_row, const QModelIndex filtered = data.toDouble() == _filterText.toDouble(); break; case QMetaType::QDateTime: - case QMetaType::QTime: - /* When we display start time in absolute format, we only - * display the time portion, so users will expect to enter - * time-only filters. Convert to QTime instead of QDateTime. + { + /* Try to parse with a date included, and fall back to time + * only if that fails. */ + QDateTime filter_dt = QDateTime::fromString(_filterText, Qt::ISODateWithMs); + if (filter_dt.isValid()) { + if (_filterOn == TrafficDataFilterProxy::TRAFFIC_DATA_LESS) + filtered = data.toDateTime() < filter_dt; + else if (_filterOn == TrafficDataFilterProxy::TRAFFIC_DATA_GREATER) + filtered = data.toDateTime() > filter_dt; + else if (_filterOn == TrafficDataFilterProxy::TRAFFIC_DATA_EQUAL) + filtered = data.toDateTime() == filter_dt; + break; + } + } + /* FALLTHROUGH */ + case QMetaType::QTime: + { + QTime filter_t = QTime::fromString(_filterText, Qt::ISODateWithMs); if (_filterOn == TrafficDataFilterProxy::TRAFFIC_DATA_LESS) - filtered = data.toTime() < QTime::fromString(_filterText, Qt::ISODateWithMs); + filtered = data.toTime() < filter_t; else if (_filterOn == TrafficDataFilterProxy::TRAFFIC_DATA_GREATER) - filtered = data.toTime() > QTime::fromString(_filterText, Qt::ISODateWithMs); + filtered = data.toTime() > filter_t; else if (_filterOn == TrafficDataFilterProxy::TRAFFIC_DATA_EQUAL) - filtered = data.toTime() == QTime::fromString(_filterText, Qt::ISODateWithMs); + filtered = data.toTime() == filter_t; break; + } case QMetaType::QString: default: /* XXX: We don't do UTF-8 aware coallating in Packet List |