Ignition Gazebo

API Reference

5.1.0
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 IGNITION_GAZEBO_GUI_ENTITYTREE_HH_
19 #define IGNITION_GAZEBO_GUI_ENTITYTREE_HH_
20 
21 #include <map>
22 #include <memory>
23 #include <vector>
24 
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
~TreeModel() override=default
Destructor.
STL class.
Information passed to systems on the update callback.
Definition: Types.hh:36
Q_INVOKABLE unsigned int EntityId(const QModelIndex &_index) const
Get the entity ID of a tree item at specified index.
TODO.
Definition: EntityTree.hh:34
void RemoveEntity(unsigned int _entity)
Remove an entity from the tree.
The EntityComponentManager constructs, deletes, and returns components and entities. A component can be of any class which inherits from components::BaseComponent.
Definition: EntityComponentManager.hh:65
Q_INVOKABLE QString EntityType(const QModelIndex &_index) const
Get the entity type of a tree item at specified index.
QHash< int, QByteArray > roleNames() const override
const Entity kNullEntity
Indicates a non-existant or invalid Entity.
Definition: Entity.hh:62
void AddEntity(unsigned int _entity, const QString &_entityName, unsigned int _parentEntity=kNullEntity, const QString &_type=QString())
Add an entity to the tree.
Displays a tree view with all the entities in the world.
Definition: EntityTree.hh:107
This library is part of the Ignition Robotics project.
Base class for a GUI System.
Definition: GuiSystem.hh:44
Q_INVOKABLE QString ScopedName(const QModelIndex &_index) const
Get the scoped name of a tree item at specified index.