DebugDrawerConfigWidget.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package RobotAPI::ArmarXObjects::DebugDrawerConfigWidget
17  * @author Adrian Knobloch ( adrian dot knobloch at student dot kit dot edu )
18  * @date 2019
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
24 #include <QInputDialog>
25 
26 namespace armarx
27 {
28 
30  : QWidget(parent),
31  debugDrawer(debugDrawer)
32  {
33  ui.setupUi(this);
34  refresh();
35 
36  connect(ui.pushButtonRefresh, &QPushButton::released, this, &DebugDrawerConfigWidget::refresh);
37  connect(ui.listWidgetLayerVisibility, &QListWidget::itemChanged, this, &DebugDrawerConfigWidget::onVisibilityChanged);
38  connect(ui.checkBoxDefaultLayerVisibility, &QCheckBox::stateChanged, this, &DebugDrawerConfigWidget::onDefaultLayerVisibilityChanged);
39  connect(ui.listWidgetDefaultLayerVisibility, &QListWidget::itemChanged, this, &DebugDrawerConfigWidget::onDefaultLayerVisibilityPerLayerChanged);
40  connect(ui.pushButtonDefaultLayerVisibilityAdd, &QPushButton::released, this, &DebugDrawerConfigWidget::onAddDefaultLayerVisibility);
41  connect(ui.pushButtonDefaultLayerVisibilityRemove, &QPushButton::released, this, &DebugDrawerConfigWidget::onRemoveDefaultLayerVisibility);
42  }
43 
44  void DebugDrawerConfigWidget::loadSettings(QSettings* settings)
45  {
46  ui.checkBoxDefaultLayerVisibility->setCheckState(settings->value(QString::fromStdString("DefaultLayerVisibility")).toBool() ? Qt::Checked : Qt::Unchecked);
47  settings->beginGroup("layer");
48  for (const auto& key : settings->allKeys())
49  {
50  QListWidgetItem* item = new QListWidgetItem(key, ui.listWidgetDefaultLayerVisibility);
51  item->setCheckState(settings->value(key).toBool() ? Qt::Checked : Qt::Unchecked);
52  ui.listWidgetDefaultLayerVisibility->addItem(item);
53  }
54  settings->endGroup();
55  }
56 
57  void DebugDrawerConfigWidget::saveSettings(QSettings* settings)
58  {
59  settings->setValue(QString::fromStdString("DefaultLayerVisibility"), ui.checkBoxDefaultLayerVisibility->checkState() == Qt::Checked);
60  settings->beginGroup("layer");
61  for (const auto& layerInfo : debugDrawer->getAllDefaultLayerVisibilities())
62  {
63  settings->setValue(QString::fromStdString(layerInfo.first), layerInfo.second);
64  }
65  settings->endGroup();
66  }
67 
69  {
70  this->debugDrawer = debugDrawer;
71  onDefaultLayerVisibilityChanged(ui.checkBoxDefaultLayerVisibility->checkState());
72  for (int i = 0; i < ui.listWidgetDefaultLayerVisibility->count(); ++i)
73  {
74  onDefaultLayerVisibilityPerLayerChanged(ui.listWidgetDefaultLayerVisibility->item(i));
75  }
76  refresh();
77  }
78 
80  {
81  return debugDrawer;
82  }
83 
85  {
86  if (!debugDrawer)
87  {
88  return;
89  }
90  ui.listWidgetLayerVisibility->clear();
91  for (const auto& layerInfo : debugDrawer->layerInformation())
92  {
93  QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(layerInfo.layerName), ui.listWidgetLayerVisibility);
94  item->setCheckState(layerInfo.visible ? Qt::Checked : Qt::Unchecked);
95  ui.listWidgetLayerVisibility->addItem(item);
96  }
97  ui.checkBoxDefaultLayerVisibility->setCheckState(debugDrawer->getDefaultLayerVisibility() ? Qt::Checked : Qt::Unchecked);
98  ui.listWidgetDefaultLayerVisibility->clear();
99  for (const auto& layerInfo : debugDrawer->getAllDefaultLayerVisibilities())
100  {
101  QListWidgetItem* item = new QListWidgetItem(QString::fromStdString(layerInfo.first), ui.listWidgetDefaultLayerVisibility);
102  item->setCheckState(layerInfo.second ? Qt::Checked : Qt::Unchecked);
103  ui.listWidgetDefaultLayerVisibility->addItem(item);
104  }
105  }
106 
108  {
109  if (!debugDrawer)
110  {
111  return;
112  }
113  debugDrawer->enableLayerVisu(item->text().toStdString(), item->checkState() == Qt::Checked);
114  }
115 
117  {
118  if (!debugDrawer)
119  {
120  return;
121  }
122  debugDrawer->setDefaultLayerVisibility(checkState != Qt::Unchecked);
123  }
124 
126  {
127  if (!debugDrawer)
128  {
129  return;
130  }
131  debugDrawer->setDefaultLayerVisibility(item->text().toStdString(), item->checkState() == Qt::Checked);
132  }
133 
135  {
136  bool ok;
137  QString text = QInputDialog::getText(this, "Layer name",
138  "Layer name:", QLineEdit::Normal,
139  ui.listWidgetLayerVisibility->selectedItems().empty() ? "" : ui.listWidgetLayerVisibility->selectedItems().front()->text(), &ok);
140  if (ok && !text.isEmpty())
141  {
142  QListWidgetItem* item = new QListWidgetItem(text, ui.listWidgetDefaultLayerVisibility);
143  item->setCheckState(debugDrawer->getDefaultLayerVisibility() ? Qt::Checked : Qt::Unchecked);
144  ui.listWidgetDefaultLayerVisibility->addItem(item);
145  }
146  }
147 
149  {
150  for (const auto& selected : ui.listWidgetDefaultLayerVisibility->selectedItems())
151  {
152  if (debugDrawer)
153  {
154  debugDrawer->removeDefaultLayerVisibility(selected->text().toStdString());
155  }
156  ui.listWidgetDefaultLayerVisibility->takeItem(ui.listWidgetDefaultLayerVisibility->row(selected));
157  }
158  }
159 
160 }
armarx::DebugDrawerConfigWidget::onAddDefaultLayerVisibility
void onAddDefaultLayerVisibility()
Definition: DebugDrawerConfigWidget.cpp:134
armarx::DebugDrawerConfigWidget::getDebugDrawer
DebugDrawerComponentPtr getDebugDrawer() const
Definition: DebugDrawerConfigWidget.cpp:79
armarx::DebugDrawerConfigWidget::onDefaultLayerVisibilityChanged
void onDefaultLayerVisibilityChanged(int checkState)
Definition: DebugDrawerConfigWidget.cpp:116
armarx::DebugDrawerConfigWidget::refresh
void refresh()
Definition: DebugDrawerConfigWidget.cpp:84
armarx::DebugDrawerConfigWidget::saveSettings
void saveSettings(QSettings *settings)
Definition: DebugDrawerConfigWidget.cpp:57
armarx::DebugDrawerConfigWidget::onDefaultLayerVisibilityPerLayerChanged
void onDefaultLayerVisibilityPerLayerChanged(QListWidgetItem *item)
Definition: DebugDrawerConfigWidget.cpp:125
armarx::DebugDrawerConfigWidget::loadSettings
void loadSettings(QSettings *settings)
Definition: DebugDrawerConfigWidget.cpp:44
armarx::DebugDrawerConfigWidget::setDebugDrawer
void setDebugDrawer(const DebugDrawerComponentPtr &debugDrawer)
Definition: DebugDrawerConfigWidget.cpp:68
armarx::DebugDrawerConfigWidget::onRemoveDefaultLayerVisibility
void onRemoveDefaultLayerVisibility()
Definition: DebugDrawerConfigWidget.cpp:148
visionx::imrecman::ok
@ ok
Definition: ImageRecordingManagerInterface.ice:46
DebugDrawerConfigWidget.h
IceInternal::Handle< DebugDrawerComponent >
armarx::DebugDrawerConfigWidget::ui
Ui::DebugDrawerConfigWidget ui
Definition: DebugDrawerConfigWidget.h:70
armarx::DebugDrawerConfigWidget::debugDrawer
DebugDrawerComponentPtr debugDrawer
Definition: DebugDrawerConfigWidget.h:69
armarx::DebugDrawerConfigWidget::DebugDrawerConfigWidget
DebugDrawerConfigWidget(const DebugDrawerComponentPtr &debugDrawer, QWidget *parent=nullptr)
Definition: DebugDrawerConfigWidget.cpp:29
armarx::DebugDrawerConfigWidget::onVisibilityChanged
void onVisibilityChanged(QListWidgetItem *item)
Definition: DebugDrawerConfigWidget.cpp:107
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28