Gazebo Sim

API Reference

9.0.0~pre1
EntityTree.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17
18#ifndef GZ_SIM_GUI_ENTITYTREE_HH_
19#define GZ_SIM_GUI_ENTITYTREE_HH_
20
21#include <map>
22#include <memory>
23#include <vector>
24
25#include <gz/sim/Entity.hh>
27
28namespace gz
29{
30namespace sim
31{
32 class EntityTreePrivate;
33
35 class TreeModel : public QStandardItemModel
36 {
37 Q_OBJECT
38
40 public: explicit TreeModel();
41
43 public: ~TreeModel() override = default;
44
45 // Documentation inherited
46 public: QHash<int, QByteArray> roleNames() const override;
47
54 public slots: void AddEntity(Entity _entity,
55 const QString &_entityName,
56 Entity _parentEntity = kNullEntity,
57 const QString &_type = QString());
58
61 public slots: void RemoveEntity(Entity _entity);
62
66 public: Q_INVOKABLE QString EntityType(const QModelIndex &_index) const;
67
71 public: Q_INVOKABLE QString ScopedName(const QModelIndex &_index) const;
72
76 public: Q_INVOKABLE Entity EntityId(const QModelIndex &_index) const;
77
79 private: std::map<Entity, QStandardItem *> entityItems;
80
82 struct EntityInfo
83 {
85 // cppcheck-suppress unmatchedSuppression
86 // cppcheck-suppress unusedStructMember
87 Entity entity;
88
90 QString name;
91
93 // cppcheck-suppress unmatchedSuppression
94 // cppcheck-suppress unusedStructMember
95 Entity parentEntity;
96
98 QString type;
99 };
100
103 private: std::vector<EntityInfo> pendingEntities;
104 };
105
111 {
112 Q_OBJECT
113
115 public: EntityTree();
116
118 public: ~EntityTree() override;
119
120 // Documentation inherited
121 public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
122
123 // Documentation inherited
124 public: void Update(const UpdateInfo &, EntityComponentManager &) override;
125
129 public: Q_INVOKABLE void OnEntitySelectedFromQml(Entity _entity);
130
133 public: Q_INVOKABLE void DeselectAllEntities();
134
137 public: Q_INVOKABLE void OnInsertEntity(const QString &_type);
138
141 public: Q_INVOKABLE void OnLoadMesh(const QString &_mesh);
142
143 // Documentation inherited
144 protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
145
148 private: std::unique_ptr<EntityTreePrivate> dataPtr;
149 };
150}
151}
152
153#endif