Ignition Gazebo

API Reference

3.3.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  unsigned int entity;
85 
87  QString name;
88 
90  unsigned int parentEntity;
91 
93  QString type;
94  };
95 
98  private: std::vector<EntityInfo> pendingEntities;
99  };
100 
106  {
107  Q_OBJECT
108 
110  public: EntityTree();
111 
113  public: ~EntityTree() override;
114 
115  // Documentation inherited
116  public: void LoadConfig(const tinyxml2::XMLElement *_pluginElem) override;
117 
118  // Documentation inherited
119  public: void Update(const UpdateInfo &, EntityComponentManager &) override;
120 
124  public: Q_INVOKABLE void OnEntitySelectedFromQml(unsigned int _entity);
125 
128  public: Q_INVOKABLE void DeselectAllEntities();
129 
130  // Documentation inherited
131  protected: bool eventFilter(QObject *_obj, QEvent *_event) override;
132 
135  private: std::unique_ptr<EntityTreePrivate> dataPtr;
136  };
137 }
138 }
139 
140 #endif
~TreeModel() override=default
Destructor.
STL class.
Information passed to systems on the update callback.
Definition: Types.hh:37
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:64
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:105
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.