MultiProfileDefaultValueEditWidget.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 ArmarX
17 * @author Mirko Waechter( mirko.waechter at kit dot edu)
18 * @date 2016
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
23 
24 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/ui_MultiProfileDefaultValueEditWidget.h>
27 
28 namespace armarx
29 {
30 
31  MultiProfileDefaultValueEditWidget::MultiProfileDefaultValueEditWidget(QString typeString, QStringList profileNames, QMap<QString, QString> values, Ice::CommunicatorPtr communicator, QWidget* parent) :
32  QWidget(parent),
34  typeString(typeString),
35  communicator(communicator)
36  {
37  ui->setupUi(this);
38  ARMARX_DEBUG << "type: " << typeString.toStdString();
39 
40  for (auto it = values.begin(); it != values.end(); it++)
41  {
42  QString jsonString = it.value();
43  if (!jsonString.isEmpty())
44  {
45  defaultEdits[it.key()] = new ProfileDefaultValueEditWidget(typeString, jsonString, communicator, this);
46  ui->splitter->addWidget(defaultEdits[it.key()].data());
47  }
48 
49  }
50  ui->comboBoxProfiles->addItems(profileNames);
51  ui->comboBoxProfiles->setCurrentIndex(ui->comboBoxProfiles->count() - 1);
52 
53  // select first available value
54  int i = 0;
55  for (auto name : profileNames)
56  {
57  if (defaultEdits.contains(name) && !defaultEdits[name].isNull() && defaultEdits[name]->getValueAsJson())
58  {
59  ARMARX_DEBUG << name.toStdString() << " contains data: " << defaultEdits[name]->getValueAsJson()->toStdString();
60  ui->comboBoxProfiles->setCurrentIndex(i);
61  break;
62  }
63  i++;
64  }
65  delete ui->editWidget;// is only a placeholder -> delete
66  }
67 
69  {
70  delete ui;
71  }
72 
73  QMap<QString, VariantContainerBasePtr> MultiProfileDefaultValueEditWidget::getVariantContainers() const
74  {
75  QMap<QString, VariantContainerBasePtr> result;
76  for (auto it = defaultEdits.begin(); it != defaultEdits.end(); it++)
77  {
78  if (!it->isNull())
79  {
80  auto var = it.value().data()->getVariantContainer();
81  if (var)
82  {
83  result[it.key()] = var;
84  }
85  }
86  }
87  return result;
88  }
89 
90  QMap<QString, QString> MultiProfileDefaultValueEditWidget::getJsonMap() const
91  {
92  QMap<QString, QString> result;
93  for (auto it = defaultEdits.begin(); it != defaultEdits.end(); it++)
94  {
95  std::optional<QString> json = it.value()->getValueAsJson();
96  if (json)
97  {
98  result[it.key()] = *json;
99  }
100  }
101  return result;
102  }
103 
104  void MultiProfileDefaultValueEditWidget::on_comboBoxProfiles_currentIndexChanged(const QString& arg1)
105  {
106  for (const auto& it : defaultEdits)
107  {
108  if (!it.isNull())
109  {
110  it->hide();
111  }
112  }
113  ARMARX_INFO_S << "profile: " << arg1.toStdString();
114  if (!defaultEdits[arg1].isNull())
115  {
116  ARMARX_INFO_S << "showing: " << arg1.toStdString();
117  defaultEdits[arg1]->show();
118  }
119  else
120  {
121  defaultEdits[arg1] = new ProfileDefaultValueEditWidget(typeString, "", communicator, this);
122  ui->splitter->addWidget(defaultEdits[arg1].data());
123  }
124  }
125 
126 } // namespace armarx
127 
armarx::ProfileDefaultValueEditWidget
Definition: ProfileDefaultValueEditWidget.h:42
JSONObject.h
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::MultiProfileDefaultValueEditWidget::getJsonMap
QMap< QString, QString > getJsonMap() const
Definition: MultiProfileDefaultValueEditWidget.cpp:90
IceInternal::Handle< ::Ice::Communicator >
Ui
ArmarX Headers.
Definition: ArmarXMainWindow.h:54
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
MultiProfileDefaultValueEditWidget.h
armarx::MultiProfileDefaultValueEditWidget
Definition: MultiProfileDefaultValueEditWidget.h:37
armarx::MultiProfileDefaultValueEditWidget::MultiProfileDefaultValueEditWidget
MultiProfileDefaultValueEditWidget(QString typeString, QStringList profileNames, QMap< QString, QString > values, Ice::CommunicatorPtr communicator, QWidget *parent=0)
Definition: MultiProfileDefaultValueEditWidget.cpp:31
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:195
Logging.h
armarx::MultiProfileDefaultValueEditWidget::~MultiProfileDefaultValueEditWidget
~MultiProfileDefaultValueEditWidget() override
Definition: MultiProfileDefaultValueEditWidget.cpp:68
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::MultiProfileDefaultValueEditWidget::getVariantContainers
QMap< QString, VariantContainerBasePtr > getVariantContainers() const
Definition: MultiProfileDefaultValueEditWidget.cpp:73