LogMarkerRegistry.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Fabian Reister ( fabian dot reister at kit dot edu )
18* @date 2026
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25// ArmarX
26#include <ArmarXCore/interface/core/Log.h>
27
28// Qt
29#include <QColor>
30#include <QObject>
31
32// C++
33#include <cstdint>
34#include <mutex>
35#include <vector>
36
37#include "LogStore.h"
38
39namespace armarx
40{
41 using LogMarkerId = std::uint64_t;
42
43 //! A single pinned log line: the store entry it refers to plus the color assigned to
44 //! it.
45 struct LogMarker
46 {
48 //! The pinned line, as a sequence number into the shared LogStore. A pin lives
49 //! exactly as long as its entry is retained there.
51 QColor color;
52 };
53
54 /*!
55 * \brief Shared, session-only store of pinned ("labeled") log lines.
56 *
57 * Owned by the LogViewer and shared by (non-owning) pointer with every LogTableModel, so
58 * a line pinned in one filter becomes visible (injected) in all of them. Colors are drawn
59 * from the Glasbey lookup table (maximally distinct) by an increasing color index.
60 *
61 * Pins identify their line by LogStore sequence number. That is exact (no same-timestamp
62 * ambiguity), makes lookups O(1) instead of a message-text comparison against every
63 * retained row, and makes expiry a single range check against the store's oldest
64 * sequence number.
65 *
66 * All mutating methods emit markersChanged() so the Labels panel and every model can
67 * refresh. Access is GUI-thread only in practice, but a mutex guards the container.
68 */
69 class LogMarkerRegistry : public QObject
70 {
71 Q_OBJECT
72 public:
73 explicit LogMarkerRegistry(QObject* parent = nullptr);
74
75 //! Pin the store entry \p seq, assigning it the next Glasbey color. No-op if it is
76 //! already pinned.
77 void add(LogSeq seq);
78
79 //! Remove the marker with the given id (no-op if unknown).
80 void remove(LogMarkerId id);
81
82 //! Remove every marker whose line has been dropped from the store, i.e. whose
83 //! sequence number is below \p firstSeq. Returns true if anything was removed.
84 bool expireBefore(LogSeq firstSeq);
85
86 //! Reassign a marker's color (no-op if unknown).
87 void recolor(LogMarkerId id, const QColor& color);
88
89 //! Drop all markers.
90 void clear();
91
92 bool empty() const;
93
94 //! Ordered (insertion-order) view of all markers.
95 std::vector<LogMarker> markers() const;
96
97 //! Color of the marker pinning \p seq, or an invalid QColor if it is not pinned.
98 QColor colorForSeq(LogSeq seq) const;
99
100 //! Id of the marker pinning \p seq, or 0 if it is not pinned.
102
103 //! Whether \p seq is pinned.
104 bool isMarked(LogSeq seq) const;
105
106 signals:
108
109 private:
110 mutable std::mutex mutex;
111 std::vector<LogMarker> entries;
112 LogMarkerId nextId = 1;
113 std::size_t colorIndex = 0;
114 };
115} // namespace armarx
bool expireBefore(LogSeq firstSeq)
Remove every marker whose line has been dropped from the store, i.e.
LogMarkerId markerIdForSeq(LogSeq seq) const
Id of the marker pinning seq, or 0 if it is not pinned.
void recolor(LogMarkerId id, const QColor &color)
Reassign a marker's color (no-op if unknown).
bool isMarked(LogSeq seq) const
Whether seq is pinned.
LogMarkerRegistry(QObject *parent=nullptr)
QColor colorForSeq(LogSeq seq) const
Color of the marker pinning seq, or an invalid QColor if it is not pinned.
void add(LogSeq seq)
Pin the store entry seq, assigning it the next Glasbey color.
void clear()
Drop all markers.
std::vector< LogMarker > markers() const
Ordered (insertion-order) view of all markers.
void remove(LogMarkerId id)
Remove the marker with the given id (no-op if unknown).
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::uint64_t LogMarkerId
quint64 LogSeq
Identifies a stored log entry for as long as it is retained.
Definition LogStore.h:37
A single pinned log line: the store entry it refers to plus the color assigned to it.
LogSeq seq
The pinned line, as a sequence number into the shared LogStore.