config_item.cpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2014, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 //
28 // *****************************************************************************
29 
30 #include <mapviz/config_item.h>
31 #include <QMenu>
32 #include <QAction>
33 #include <QInputDialog>
34 
35 namespace mapviz
36 {
37  ConfigItem::ConfigItem(QWidget *parent, Qt::WindowFlags flags) :
38  QWidget(parent, flags),
39  item_(0),
40  visible_(true)
41  {
42  ui_.setupUi(this);
43 
44  edit_name_action_ = new QAction("Edit Name", this);
45  remove_item_action_ = new QAction("Remove", this);
46  remove_item_action_->setIcon(QIcon(":/images/remove-icon-th.png"));
47 
48  connect(edit_name_action_, SIGNAL(triggered()), this, SLOT(EditName()));
49  connect(remove_item_action_, SIGNAL(triggered()), this, SLOT(Remove()));
50  }
51 
53  {
54  }
55 
56  void ConfigItem::ToggleDraw(bool toggled)
57  {
58  if (visible_ != toggled)
59  {
60  visible_ = toggled;
61  if (ui_.show->isChecked() != toggled)
62  {
63  ui_.show->setChecked(toggled);
64  }
65 
66  Q_EMIT ToggledDraw(item_, toggled);
67  }
68  }
69 
70  void ConfigItem::contextMenuEvent(QContextMenuEvent* event)
71  {
72  QMenu menu(this);
73  menu.addAction(edit_name_action_);
74  menu.addAction(remove_item_action_);
75  menu.exec(event->globalPos());
76  }
77 
78  void ConfigItem::SetName(QString name)
79  {
80  name_ = name;
81  ui_.namelabel->setText(type_ + " (" + name_ + ")");
82  }
83 
84  void ConfigItem::SetType(QString type)
85  {
86  type_ = type;
87  ui_.namelabel->setText(type_ + " (" + name_ + ")");
88  }
89 
90  void ConfigItem::SetWidget(QWidget* widget)
91  {
92  ui_.label->hide();
93  ui_.content_layout->addWidget(widget);
94  }
95 
97  {
98  bool ok;
99  QString text = QInputDialog::getText(
100  this,
101  tr("Set Display name"),
102  tr(""),
103  QLineEdit::Normal,
104  name_, &ok);
105 
106  if (ok && !text.isEmpty())
107  {
108  SetName(text);
109  }
110  }
111 
113  {
114  Q_EMIT RemoveRequest(item_);
115  }
116 
118  {
119  if (!ui_.content->isHidden())
120  {
121  ui_.content->hide();
122  ui_.signlabel->setText(" + ");
123  }
124  else
125  {
126  ui_.content->show();
127  ui_.signlabel->setText(" - ");
128  }
129 
130  Q_EMIT UpdateSizeHint();
131  }
132 }
void RemoveRequest(QListWidgetItem *plugin)
void SetWidget(QWidget *widget)
Definition: config_item.cpp:90
Ui::configitem ui_
Definition: config_item.h:64
QAction * edit_name_action_
Definition: config_item.h:84
void ToggleDraw(bool toggled)
Definition: config_item.cpp:56
void SetName(QString name)
Definition: config_item.cpp:78
void ToggledDraw(QListWidgetItem *plugin, bool visible)
void SetType(QString type)
Definition: config_item.cpp:84
ConfigItem(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: config_item.cpp:37
QAction * remove_item_action_
Definition: config_item.h:85
virtual void contextMenuEvent(QContextMenuEvent *event) override
Definition: config_item.cpp:70
QListWidgetItem * item_
Definition: config_item.h:81


mapviz
Author(s): Marc Alban
autogenerated on Thu Jun 6 2019 19:25:08