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
This commit is contained in:
John Thacker 2023-02-20 06:49:51 -05:00
parent 0bd4d9b132
commit 5948274adb
2 changed files with 49 additions and 23 deletions

View File

@ -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) :

View File

@ -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