21 Q_PROPERTY(
int maxEntries READ maxEntries WRITE setMaxEntries NOTIFY
maxEntriesChanged)
22 Q_PROPERTY(QStringList categoriesList READ categoriesList NOTIFY
categoriesChanged)
23 Q_PROPERTY(
int filterLevel READ filterLevel WRITE setFilterLevel NOTIFY
filterLevelChanged)
24 Q_PROPERTY(QString filterCategory READ filterCategory WRITE setFilterCategory NOTIFY
filterCategoryChanged)
25 Q_PROPERTY(QString filterText READ filterText WRITE setFilterText NOTIFY
filterTextChanged)
26 Q_PROPERTY(
bool filterRegex READ filterRegex WRITE setFilterRegex NOTIFY
filterRegexChanged)
30 explicit LogModel(QObject* parent =
nullptr);
32 int rowCount(
const QModelIndex& parent = QModelIndex())
const override;
34 int totalCount()
const {
return static_cast<int>(_entries.size()); }
36 int maxEntries()
const {
return _maxEntries; }
38 void setMaxEntries(
int max);
40 int filterLevel()
const {
return _filterLevel; }
42 void setFilterLevel(
int level);
44 QString filterCategory()
const {
return _filterCategory; }
46 void setFilterCategory(
const QString& category);
48 QString filterText()
const {
return _filterText; }
50 void setFilterText(
const QString& text);
52 bool filterRegex()
const {
return _filterRegex; }
54 bool filterRegexValid()
const {
return !_filterRegex || _compiledRegex.isValid(); }
56 void setFilterRegex(
bool enabled);
58 QStringList categoriesList()
const;
59 Q_INVOKABLE
void setFilterTextDeferred(
const QString& text);
60 Q_INVOKABLE
void clearFilters();
61 Q_INVOKABLE
void clear();
65 QList<LogEntry> allEntriesSnapshot()
const {
return QList<LogEntry>(_entries.begin(), _entries.end()); }
67 QList<LogEntry> filteredEntries()
const;
87 void _rebuildFilteredIndices();
88 bool _passesFilter(
const LogEntry& entry)
const;
89 bool _hasActiveFilter()
const;
90 void _recompileRegex();
91 void _appendToFiltered(
int first,
int last);
92 void _invalidateCategoryCache();
94 std::deque<LogEntry> _entries;
95 std::vector<LogEntry> _pendingEntries;
96 std::vector<int> _filteredIndices;
97 QChronoTimer _batchTimer{std::chrono::milliseconds{kBatchFlushMs}};
98 QTimer _filterTextDebounce;
99 QString _pendingFilterText;
101 int _maxEntries = 100000;
102 int _filterLevel = LogEntry::Debug;
103 QString _filterCategory;
105 bool _filterRegex =
false;
106 bool _filterBypassed =
true;
107 QRegularExpression _compiledRegex;
109 QSet<QString> _categoriesSet;
110 mutable QStringList _categoriesCache;
111 mutable bool _categoriesDirty =
false;
113 static constexpr int kBatchFlushMs = 16;
114 static constexpr int kBatchMaxSize = 200;
115 static constexpr int kFilterDebounceMs = 200;