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
37namespace armarx
38{
39 using LogMarkerId = std::uint64_t;
40
41 //! A single pinned log line: a snapshot of the message plus the color assigned to it.
42 struct LogMarker
43 {
45 LogMessage snapshot;
46 QColor color;
47 };
48
49 /*!
50 * \brief Shared, session-only store of pinned ("labeled") log lines.
51 *
52 * Owned by the LogViewer and shared by (non-owning) pointer with every LogTableModel, so
53 * a line pinned in one filter becomes visible (injected) in all of them. Colors are drawn
54 * from the Glasbey lookup table (maximally distinct) by an increasing color index.
55 *
56 * All mutating methods emit markersChanged() so the Labels panel and every model can
57 * refresh. Access is GUI-thread only in practice, but a mutex guards the container.
58 */
59 class LogMarkerRegistry : public QObject
60 {
61 Q_OBJECT
62 public:
63 explicit LogMarkerRegistry(QObject* parent = nullptr);
64
65 //! Pin the given message. If an equal message is already pinned, its existing marker
66 //! is returned unchanged (no duplicate). Assigns the next Glasbey color otherwise.
67 const LogMarker* add(const LogMessage& snapshot);
68
69 //! Remove the marker with the given id (no-op if unknown).
70 void remove(LogMarkerId id);
71
72 //! Reassign a marker's color (no-op if unknown).
73 void recolor(LogMarkerId id, const QColor& color);
74
75 //! Drop all markers.
76 void clear();
77
78 //! Ordered (insertion-order) view of all markers.
79 std::vector<LogMarker> markers() const;
80
81 //! Marker for a message identical to \p message, or nullptr. Identity is
82 //! (time, who, what); see LogMarkerRegistry.cpp.
83 const LogMarker* markerForMessage(const LogMessage& message) const;
84
85 //! Whether any marker's snapshot is identical to \p message.
86 bool isMarked(const LogMessage& message) const;
87
88 signals:
90
91 private:
92 //! Whole-line identity used to detect duplicates and to match snapshots against live
93 //! entries. Same-microsecond collisions with identical text/component are an accepted
94 //! limitation (see the concept).
95 static bool sameLine(const LogMessage& a, const LogMessage& b);
96
97 mutable std::mutex mutex;
98 std::vector<LogMarker> entries;
99 LogMarkerId nextId = 1;
100 std::size_t colorIndex = 0;
101 };
102} // 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.