LogMarkerRegistry.cpp
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#include "LogMarkerRegistry.h"
24
25#include <algorithm>
26
27#include <SimoxUtility/color/Color.h>
28#include <SimoxUtility/color/GlasbeyLUT.h>
29
30namespace armarx
31{
32 LogMarkerRegistry::LogMarkerRegistry(QObject* parent) : QObject(parent)
33 {
34 }
35
36 void
38 {
39 {
40 std::unique_lock lock(mutex);
41
42 for (const LogMarker& marker : entries)
43 {
44 if (marker.seq == seq)
45 {
46 // Already pinned: do not duplicate or recolor.
47 return;
48 }
49 }
50
51 // Draw the next maximally-distinct color from the Glasbey LUT.
52 const simox::color::Color color = simox::color::GlasbeyLUT::at(colorIndex++);
53
54 LogMarker marker;
55 marker.id = nextId++;
56 marker.seq = seq;
57 marker.color = QColor(color.r, color.g, color.b);
58 entries.push_back(std::move(marker));
59 }
60
61 emit markersChanged();
62 }
63
64 void
66 {
67 bool changed = false;
68 {
69 std::unique_lock lock(mutex);
70 for (auto it = entries.begin(); it != entries.end(); ++it)
71 {
72 if (it->id == id)
73 {
74 entries.erase(it);
75 changed = true;
76 break;
77 }
78 }
79 }
80 if (changed)
81 {
82 emit markersChanged();
83 }
84 }
85
86 bool
88 {
89 bool changed = false;
90 {
91 std::unique_lock lock(mutex);
92 const auto newEnd = std::remove_if(entries.begin(),
93 entries.end(),
94 [firstSeq](const LogMarker& marker)
95 { return marker.seq < firstSeq; });
96 changed = newEnd != entries.end();
97 entries.erase(newEnd, entries.end());
98 }
99 if (changed)
100 {
101 emit markersChanged();
102 }
103 return changed;
104 }
105
106 void
108 {
109 bool changed = false;
110 {
111 std::unique_lock lock(mutex);
112 for (LogMarker& marker : entries)
113 {
114 if (marker.id == id)
115 {
116 marker.color = color;
117 changed = true;
118 break;
119 }
120 }
121 }
122 if (changed)
123 {
124 emit markersChanged();
125 }
126 }
127
128 void
130 {
131 bool changed = false;
132 {
133 std::unique_lock lock(mutex);
134 changed = !entries.empty();
135 entries.clear();
136 }
137 if (changed)
138 {
139 emit markersChanged();
140 }
141 }
142
143 bool
145 {
146 std::unique_lock lock(mutex);
147 return entries.empty();
148 }
149
150 std::vector<LogMarker>
152 {
153 std::unique_lock lock(mutex);
154 return entries;
155 }
156
157 QColor
159 {
160 std::unique_lock lock(mutex);
161 for (const LogMarker& marker : entries)
162 {
163 if (marker.seq == seq)
164 {
165 return marker.color;
166 }
167 }
168 return QColor();
169 }
170
173 {
174 std::unique_lock lock(mutex);
175 for (const LogMarker& marker : entries)
176 {
177 if (marker.seq == seq)
178 {
179 return marker.id;
180 }
181 }
182 return 0;
183 }
184
185 bool
187 {
188 return colorForSeq(seq).isValid();
189 }
190} // 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.