VariablePill.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 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 #ifndef GAZEBO_GUI_PLOT_VARIABLE_PILL_HH_
18 #define GAZEBO_GUI_PLOT_VARIABLE_PILL_HH_
19 
20 #include <map>
21 #include <memory>
22 #include <string>
23 
24 #include <ignition/math/Helpers.hh>
25 #include <ignition/math/Vector2.hh>
26 
27 #include "gazebo/gui/qt.h"
28 #include "gazebo/util/system.hh"
29 
30 namespace gazebo
31 {
32  namespace gui
33  {
34  // Forward declare private data class
35  class VariablePillPrivate;
36 
37  class VariablePillContainer;
38 
40  class GZ_GUI_VISIBLE VariablePill : public QWidget
41  {
42  Q_OBJECT
43 
46  public: explicit VariablePill(QWidget *_parent = nullptr);
47 
49  public: virtual ~VariablePill();
50 
53  public: unsigned int Id() const;
54 
57  public: void SetName(const std::string &_name);
58 
61  public: std::string Name() const;
62 
65  public: void SetText(const std::string &_text);
66 
69  public: std::string Text() const;
70 
73  public: void SetParent(VariablePill *_parent);
74 
77  public: VariablePill *Parent() const;
78 
81  public: void SetContainer(VariablePillContainer *_container);
82 
85  public: VariablePillContainer *Container() const;
86 
89  public: void AddVariablePill(VariablePill *_variable);
90 
93  public: void RemoveVariablePill(VariablePill *_variable);
94 
98  public: VariablePill *VariablePillByName(const std::string &_name);
99 
102  public: unsigned int VariablePillCount() const;
103 
106  public: std::map<unsigned int, VariablePill *> &VariablePills() const;
107 
110  public: void SetSelected(const bool _selected);
111 
114  public: bool IsSelected() const;
115 
119  public: bool ContainsPoint(const ignition::math::Vector2i &_pt) const;
120 
123  protected: void dragEnterEvent(QDragEnterEvent *_evt);
124 
127  protected: void dropEvent(QDropEvent *_evt);
128 
131  protected: void mouseMoveEvent(QMouseEvent *_event);
132 
135  protected: void mousePressEvent(QMouseEvent *_event);
136 
139  private: void SetMultiVariableMode(const bool _enable);
140 
142  private: void UpdateStyleSheet();
143 
147  private: bool IsDragValid(QDropEvent *_evt);
148 
152  Q_SIGNALS: void VariableAdded(const unsigned int _id,
153  const std::string &_name);
154 
157  Q_SIGNALS: void VariableRemoved(const unsigned int _id);
158 
162  Q_SIGNALS: void VariableMoved(const unsigned int _id);
163 
166  Q_SIGNALS: void VariableLabelChanged(const std::string &_label);
167 
169  public: static const unsigned int EmptyVariable;
170 
173  private: std::unique_ptr<VariablePillPrivate> dataPtr;
174  };
175  }
176 }
177 #endif
gui
Definition: KeyEventHandler.hh:29
A container for holding variable pills.
Definition: VariablePillContainer.hh:38
A variable pill.
Definition: VariablePill.hh:41
void VariableRemoved(const unsigned int _id)
Qt signal emitted when a child variable pill is removed.
VariablePill(QWidget *_parent=nullptr)
Constructor.
void SetName(const std::string &_name)
Set a unique name for this variable.
bool IsSelected() const
Return the selected state of this variable pill.
void VariableMoved(const unsigned int _id)
Qt signal emitted when an existing variable pill is added as a child of this variable pill.
std::string Name() const
Get the unique name for this variable.
void SetParent(VariablePill *_parent)
Set the parent of this variable pill.
void mousePressEvent(QMouseEvent *_event)
Qt mouse move event.
void SetSelected(const bool _selected)
Set the selected state of this variable pill.
void dropEvent(QDropEvent *_evt)
Used to accept drop events.
virtual ~VariablePill()
Destructor.
void mouseMoveEvent(QMouseEvent *_event)
Qt mouse press event.
void AddVariablePill(VariablePill *_variable)
Add a child variable pill.
bool ContainsPoint(const ignition::math::Vector2i &_pt) const
Check if a point is inside the widget.
std::string Text() const
Get the text label for this variable pill.
void SetText(const std::string &_text)
Set the text label for this variable pill.
std::map< unsigned int, VariablePill * > & VariablePills() const
Get the a child variable pill.
void VariableLabelChanged(const std::string &_label)
Qt signal emitted when the variable pill's text has changed.
void RemoveVariablePill(VariablePill *_variable)
Remove a child variable pill.
VariablePill * VariablePillByName(const std::string &_name)
Get a child variable pill by its unique name.
unsigned int Id() const
Get the unique id of this variable pill.
VariablePill * Parent() const
Get the parent of this variable pill.
static const unsigned int EmptyVariable
Empty variable id used to indicate non-existent variable.
Definition: VariablePill.hh:169
unsigned int VariablePillCount() const
Get the number of child variable pills.
void VariableAdded(const unsigned int _id, const std::string &_name)
Qt signal emitted when a child variable pill is added.
void SetContainer(VariablePillContainer *_container)
Set the container which holds this variable pill.
VariablePillContainer * Container() const
Get the container which holds this variable pill.
void dragEnterEvent(QDragEnterEvent *_evt)
Used to accept drag enter events.
Forward declarations for the common classes.
Definition: Animation.hh:27