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 <SimoxUtility/color/Color.h>
26#include <SimoxUtility/color/GlasbeyLUT.h>
27
28namespace armarx
29{
30 LogMarkerRegistry::LogMarkerRegistry(QObject* parent) : QObject(parent)
31 {
32 }
33
34 bool
35 LogMarkerRegistry::sameLine(const LogMessage& a, const LogMessage& b)
36 {
37 return a.time == b.time && a.who == b.who && a.what == b.what;
38 }
39
40 const LogMarker*
41 LogMarkerRegistry::add(const LogMessage& snapshot)
42 {
43 {
44 std::unique_lock lock(mutex);
45
46 for (const LogMarker& marker : entries)
47 {
48 if (sameLine(marker.snapshot, snapshot))
49 {
50 // Already pinned: return the existing marker, do not duplicate or recolor.
51 return &marker;
52 }
53 }
54
55 // Draw the next maximally-distinct color from the Glasbey LUT.
56 const simox::color::Color color = simox::color::GlasbeyLUT::at(colorIndex++);
57
58 LogMarker marker;
59 marker.id = nextId++;
60 marker.snapshot = snapshot;
61 marker.color = QColor(color.r, color.g, color.b);
62 entries.push_back(std::move(marker));
63 }
64
65 emit markersChanged();
66
67 // add() is GUI-thread only, so the just-inserted marker is still present here.
68 return markerForMessage(snapshot);
69 }
70
71 void
73 {
74 bool changed = false;
75 {
76 std::unique_lock lock(mutex);
77 for (auto it = entries.begin(); it != entries.end(); ++it)
78 {
79 if (it->id == id)
80 {
81 entries.erase(it);
82 changed = true;
83 break;
84 }
85 }
86 }
87 if (changed)
88 {
89 emit markersChanged();
90 }
91 }
92
93 void
94 LogMarkerRegistry::recolor(LogMarkerId id, const QColor& color)
95 {
96 bool changed = false;
97 {
98 std::unique_lock lock(mutex);
99 for (LogMarker& marker : entries)
100 {
101 if (marker.id == id)
102 {
103 marker.color = color;
104 changed = true;
105 break;
106 }
107 }
108 }
109 if (changed)
110 {
111 emit markersChanged();
112 }
113 }
114
115 void
117 {
118 bool changed = false;
119 {
120 std::unique_lock lock(mutex);
121 changed = !entries.empty();
122 entries.clear();
123 }
124 if (changed)
125 {
126 emit markersChanged();
127 }
128 }
129
130 std::vector<LogMarker>
132 {
133 std::unique_lock lock(mutex);
134 return entries;
135 }
136
137 const LogMarker*
138 LogMarkerRegistry::markerForMessage(const LogMessage& message) const
139 {
140 std::unique_lock lock(mutex);
141 for (const LogMarker& marker : entries)
142 {
143 if (sameLine(marker.snapshot, message))
144 {
145 return &marker;
146 }
147 }
148 return nullptr;
149 }
150
151 bool
152 LogMarkerRegistry::isMarked(const LogMessage& message) const
153 {
154 return markerForMessage(message) != nullptr;
155 }
156} // namespace armarx
const LogMarker * markerForMessage(const LogMessage &message) const
Marker for a message identical to message, or nullptr.
void recolor(LogMarkerId id, const QColor &color)
Reassign a marker's color (no-op if unknown).
LogMarkerRegistry(QObject *parent=nullptr)
bool isMarked(const LogMessage &message) const
Whether any marker's snapshot is identical to message.
const LogMarker * add(const LogMessage &snapshot)
Pin the given message.
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
A single pinned log line: a snapshot of the message plus the color assigned to it.