Gazebo Gazebo

API Reference

3.15.1
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_GAZEBO_GUI_ENTITYTREE_HH_
19 #define GZ_GAZEBO_GUI_ENTITYTREE_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <vector>
24 
25 #include <gz/sim/gui/GuiSystem.hh>
26 
27 namespace ignition
28 {
29 namespace gazebo
30 {
31  class EntityTreePrivate;
32 
34  class TreeModel : public QStandardItemModel
35  {
36  Q_OBJECT
37 
39  public: explicit TreeModel();
40 
42  public: ~TreeModel() override = default;
43 
44  // Documentation inherited
45  public: QHash<int, QByteArray> roleNames() const override;
46 
53  public slots: void AddEntity(unsigned int _entity,
54  const QString &_entityName,
55  unsigned int _parentEntity = kNullEntity,
56  const QString &_type = QString());
57 
60  public slots: void RemoveEntity(unsigned int _entity);
61 
65  public: Q_INVOKABLE QString EntityType(const QModelIndex &_index) const;
66 
70  public: Q_INVOKABLE QString ScopedName(const QModelIndex &_index) const;
71 
75  public: Q_INVOKABLE unsigned int EntityId(const QModelIndex &_index) const;
76 
78  private: std::map<Entity, QStandardItem *> entityItems;
79 
81  struct EntityInfo
82  {
84  // cppcheck-suppress unusedStructMember
85  unsigned int entity;
86 
88  QString name;
89 
91  // cppcheck-suppress unusedStructMember
92  unsigned int parentEntity;
93 
95  QString type;
96  };
97 
100  private: std::vector<EntityInfo> pendingEntities;
101  };
102 
108  {
109  Q_OBJECT
110 
112  public: EntityTree();
113 
115  public: ~EntityTree() override;
116 
117  // Documentation inherited
118  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
119 
120  // Documentation inherited
121  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
122 
126  public: Q_INVOKABLE void OnEntitySelectedFromQml(unsigned int _entity);
127 
130  public: Q_INVOKABLE void DeselectAllEntities();
131 
132  // Documentation inherited
133  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
134 
137  private: std::unique_ptr<EntityTreePrivate> dataPtr;
138  };
139 }
140 }
141 
142 #endif
Base class for a GUI System.
Definition: gz/sim/gui/GuiSystem.hh:44
This library is part of the Ignition Robotics project.
The EntityComponentManager constructs, deletes, and returns components and entities....
Definition: gz/sim/EntityComponentManager.hh:65
void Update(const UpdateInfo &, EntityComponentManager &) override
Update callback called every time the system is stepped. This is called at an Ignition transport thre...
Q_INVOKABLE unsigned int EntityId(const QModelIndex &_index) const
Get the entity ID of a tree item at specified index.
QHash< int, QByteArray > roleNames() const override
Q_INVOKABLE void DeselectAllEntities()
Callback when all entities have been deselected. This should be called from QML.
Q_INVOKABLE QString ScopedName(const QModelIndex &_index) const
Get the scoped name of a tree item at specified index.
~TreeModel() override=default
Destructor.
Q_INVOKABLE QString EntityType(const QModelIndex &_index) const
Get the entity type of a tree item at specified index.
bool eventFilter(QObject *_obj, QEvent *_event) override
Information passed to systems on the update callback.
Definition: include/gz/sim/Types.hh:37
TODO.
Definition: EntityTree.hh:34
const Entity kNullEntity
Indicates a non-existant or invalid Entity.
Definition: gz/sim/Entity.hh:62
void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override
Displays a tree view with all the entities in the world.
Definition: EntityTree.hh:107
~EntityTree() override
Destructor.
void AddEntity(unsigned int _entity, const QString &_entityName, unsigned int _parentEntity=kNullEntity, const QString &_type=QString())
Add an entity to the tree.
void RemoveEntity(unsigned int _entity)
Remove an entity from the tree.
Q_INVOKABLE void OnEntitySelectedFromQml(unsigned int _entity)
Callback when an entity has been selected. This should be called from QML.