LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
PanelUtils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "EventsContainer.hpp"
5
6#include <QDateTime>
7#include <QString>
8
9#include <string>
10#include <vector>
11
13
14inline const std::vector<std::string> kTsFields{
15 "timestamp", "time", "datetime", "@timestamp", "date"};
16
17inline const std::vector<std::string> kMsgFields{
18 "message", "msg", "text", "description", "body"};
19
20inline QDateTime ParseTimestamp(const QString& s)
21{
22 QDateTime dt = QDateTime::fromString(s, Qt::ISODateWithMs);
23 if (dt.isValid()) return dt;
24 dt = QDateTime::fromString(s, Qt::ISODate);
25 if (dt.isValid()) return dt;
26 for (const char* fmt : {"yyyy-MM-dd HH:mm:ss.zzz",
27 "yyyy-MM-dd HH:mm:ss",
28 "dd/MMM/yyyy:HH:mm:ss"})
29 {
30 dt = QDateTime::fromString(s, QString::fromLatin1(fmt));
31 if (dt.isValid()) return dt;
32 }
33 bool ok = false;
34 const qint64 epoch = s.toLongLong(&ok);
35 if (ok) return QDateTime::fromSecsSinceEpoch(epoch);
36 return {};
37}
38
39inline std::vector<unsigned long> VisibleIndices(
40 const EventsTableView* eventsView, const db::EventsContainer& events)
41{
42 // A non-null result means a filter is active — even if it matches zero
43 // events, that must be honored, not treated as "no filter, show all".
44 const std::vector<unsigned long>* f = eventsView->GetFilteredIndices();
45 if (f) return *f;
46 const size_t total = events.Size();
47 std::vector<unsigned long> all;
48 all.reserve(total);
49 for (size_t i = 0; i < total; ++i)
50 all.push_back(static_cast<unsigned long>(i));
51 return all;
52}
53
54} // namespace ui::qt::panel_utils
Container class for managing collections of LogEvent objects.
High-performance, thread-safe container for managing large collections of LogEvent objects.
Definition EventsContainer.hpp:129
size_t Size() const override
Gets the number of events in the container.
Definition EventsContainer.cpp:151
Definition EventsTableView.hpp:29
const std::vector< unsigned long > * GetFilteredIndices() const
Definition EventsTableView.cpp:238
Definition PanelUtils.hpp:12
const std::vector< std::string > kTsFields
Definition PanelUtils.hpp:14
QDateTime ParseTimestamp(const QString &s)
Definition PanelUtils.hpp:20
std::vector< unsigned long > VisibleIndices(const EventsTableView *eventsView, const db::EventsContainer &events)
Definition PanelUtils.hpp:39
const std::vector< std::string > kMsgFields
Definition PanelUtils.hpp:17