Skip to content

Commit 70e9143

Browse files
committed
Highlight timestamp when there is a gap >= 1sec
1 parent b9c3353 commit 70e9143

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

customfilterproxymodel.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "timestamp.h"
44

55
#include <QtCore/QMetaProperty>
6+
#include <QtGui/QColor>
67
#include <QtGui/QGuiApplication>
78
#include <QtGui/QFont>
89

@@ -98,6 +99,41 @@ void CustomFilterProxyModel::setProgress(int progress) const
9899
QVariant CustomFilterProxyModel::data(const QModelIndex &index, int role) const
99100
{
100101
QVariant ret = QSortFilterProxyModel::data(index, role);
102+
if (index.column() == GStreamerLogModel::TimestampColumn) {
103+
auto hasGap = [&](int a, int b) {
104+
const auto previousTimestamp = Timestamp::fromString(index.siblingAtRow(a).data().toString());
105+
const auto currentTimestamp = Timestamp::fromString(index.siblingAtRow(b).data().toString());
106+
return previousTimestamp.secsTo(currentTimestamp) > 0;
107+
};
108+
switch (role) {
109+
case Qt::BackgroundRole: {
110+
const auto row = index.row();
111+
if (row > 0) {
112+
if (hasGap(row - 1, row)) {
113+
ret = QColor(Qt::red);
114+
} else if (row < rowCount() - 1) {
115+
if (hasGap(row, row + 1)) {
116+
ret = QColor(Qt::red);
117+
}
118+
}
119+
}
120+
break; }
121+
case Qt::ForegroundRole: {
122+
const auto row = index.row();
123+
if (row > 0) {
124+
if (hasGap(row - 1, row)) {
125+
ret = QColor(Qt::white);
126+
} else if (row < rowCount() - 1) {
127+
if (hasGap(row, row + 1)) {
128+
ret = QColor(Qt::white);
129+
}
130+
}
131+
}
132+
break; }
133+
default:
134+
break;
135+
}
136+
}
101137
if (role == Qt::FontRole) {
102138
if (!d->filter.isEmpty()) {
103139
static const auto mo = &GStreamerLogLine::staticMetaObject;

0 commit comments

Comments
 (0)