RoboDK Plug-In Interface
Loading...
Searching...
No Matches
stationtreeeventmonitor.h
1/****************************************************************************
2**
3** Copyright (c) 2015-2026 RoboDK Global.
4** Contact: https://robodk.com/
5**
6** This file is part of the RoboDK API.
7**
8** Permission is hereby granted, free of charge, to any person obtaining a copy
9** of this software and associated documentation files (the "Software"), to deal
10** in the Software without restriction, including without limitation the rights
11** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12** copies of the Software, and to permit persons to whom the Software is
13** furnished to do so, subject to the following conditions:
14**
15** The above copyright notice and this permission notice shall be included in all
16** copies or substantial portions of the Software.
17**
18** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24** SOFTWARE.
25**
26** RoboDK is a registered trademark of RoboDK Global.
27**
28****************************************************************************/
29
30#ifndef ROBODK_STATIONTREEEVENTMONITOR_H
31#define ROBODK_STATIONTREEEVENTMONITOR_H
32
33#include <cstdint>
34#include <unordered_map>
35#include <list>
36#include <functional>
37
38#include <QObject>
39#include <QVector>
40#include <QHash>
41#include <QModelIndex>
42
43
44class QIcon;
45class QTreeWidget;
46class QTreeWidgetItem;
47class IRoboDK;
48class IItem;
49
50
51namespace robodk
52{
53
54class StationTreeEventMonitor : public QObject
55{
56 Q_OBJECT
57
58public:
59 enum Filter : uint32_t
60 {
61 NoFilter = 0x00000000,
62 IgnoreInactiveStations = 0x00000001,
63 IgnoreNameChange = 0x00000002,
64 IgnoreIconChange = 0x00000004,
65 IgnoreAdd = 0x00000008,
66 IgnoreRemove = 0x00000010,
67 IgnoreChildren = 0x00000020,
68 };
69
70 enum SubmitPolicy
71 {
72 AutoSubmit,
73 ManualSubmit
74 };
75
76public:
77 explicit StationTreeEventMonitor(IRoboDK* rdk, QObject* parent = nullptr);
78
79 uint32_t filter() const;
80 uint32_t setFilter(uint32_t filter);
81 uint32_t setFilterFlag(uint32_t flag, bool on = true);
82
83 void setSubmitPolicy(SubmitPolicy policy);
84
85signals:
86 void itemNameChanged(IItem* item, const QString& name);
87 void itemIconChanged(IItem* item, const QIcon& icon);
88 void itemAdded(IItem* item);
89 void itemRemoved(IItem* item);
90
91public slots:
92 void refresh();
93 void submit();
94
95private slots:
96 void onModelDataChanged(
97 const QModelIndex& topLeft,
98 const QModelIndex& bottomRight,
99 const QVector<int>& roles = QVector<int>());
100 void onModelRowsInserted(const QModelIndex& parent, int first, int last);
101 void onModelRowsRemoved(const QModelIndex& parent, int first, int last);
102
103private:
105 {
106 inline size_t operator()(const QString& s) const { return qHash(s); };
107 };
108
109 using TreeCallback = std::function<void(const QModelIndex&)>;
110
111private:
112 void iterateOverTree(
113 const QModelIndex& parent,
114 const TreeCallback& callback,
115 bool reverse = false);
116 IItem* itemFromIndex(const QModelIndex& index) const;
117 bool isActiveStationItem(const QModelIndex& index) const;
118
119private:
120 IRoboDK* _rdk = nullptr;
121 QTreeWidget* _tree = nullptr;
122
123 uint32_t _filter = IgnoreInactiveStations;
124 SubmitPolicy _policy = AutoSubmit;
125
126 std::unordered_multimap<QString, IItem*, QStringHash> _nameTable;
127 std::unordered_map<IItem*, QString> _nameCache;
128
129 std::list<QModelIndex> _addedIndices;
130};
131
132
133inline uint32_t StationTreeEventMonitor::filter() const
134{
135 return _filter;
136}
137
138inline uint32_t StationTreeEventMonitor::setFilter(uint32_t filter)
139{
140 auto result = _filter;
141 _filter = filter;
142 return result;
143}
144
145inline uint32_t StationTreeEventMonitor::setFilterFlag(uint32_t flag, bool on)
146{
147 auto result = _filter;
148 if (on)
149 {
150 _filter |= flag;
151 }
152 else
153 {
154 _filter &= ~flag;
155 }
156 return result;
157}
158
159inline void StationTreeEventMonitor::setSubmitPolicy(SubmitPolicy policy)
160{
161 _policy = policy;
162}
163
164} // namespace robodk
165
166#endif // STATIONTREEEVENTMONITOR_H
The Item class represents an item in RoboDK station. An item can be a robot, a frame,...
Definition iitem.h:14
This class is the iterface to the RoboDK API. With the RoboDK API you can automate certain tasks and ...
Definition irobodk.h:14