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 
26 
27 #include <ArmarXGui/gui-plugins/StatechartEditorPlugin/ui_MultiProfileDefaultValueEditWidget.h>
28 
29 namespace armarx
30 {
31 
33  QString typeString,
34  QStringList profileNames,
35  QMap<QString, QString> values,
36  Ice::CommunicatorPtr communicator,
37  QWidget* parent) :
38  QWidget(parent),
40  typeString(typeString),
41  communicator(communicator)
42  {
43  ui->setupUi(this);
44  ARMARX_DEBUG << "type: " << typeString.toStdString();
45 
46  for (auto it = values.begin(); it != values.end(); it++)
47  {
48  QString jsonString = it.value();
49  if (!jsonString.isEmpty())
50  {
51  defaultEdits[it.key()] =
52  new ProfileDefaultValueEditWidget(typeString, jsonString, communicator, this);
53  ui->splitter->addWidget(defaultEdits[it.key()].data());
54  }
55  }
56  ui->comboBoxProfiles->addItems(profileNames);
57  ui->comboBoxProfiles->setCurrentIndex(ui->comboBoxProfiles->count() - 1);
58 
59  // select first available value
60  int i = 0;
61  for (auto name : profileNames)
62  {
63  if (defaultEdits.contains(name) && !defaultEdits[name].isNull() &&
64  defaultEdits[name]->getValueAsJson())
65  {
66  ARMARX_DEBUG << name.toStdString() << " contains data: "
67  << defaultEdits[name]->getValueAsJson()->toStdString();
68  ui->comboBoxProfiles->setCurrentIndex(i);
69  break;
70  }
71  i++;
72  }
73  delete ui->editWidget; // is only a placeholder -> delete
74  }
75 
77  {
78  delete ui;
79  }
80 
81  QMap<QString, VariantContainerBasePtr>
83  {
84  QMap<QString, VariantContainerBasePtr> result;
85  for (auto it = defaultEdits.begin(); it != defaultEdits.end(); it++)
86  {
87  if (!it->isNull())
88  {
89  auto var = it.value().data()->getVariantContainer();
90  if (var)
91  {
92  result[it.key()] = var;
93  }
94  }
95  }
96  return result;
97  }
98 
99  QMap<QString, QString>
101  {
102  QMap<QString, QString> result;
103  for (auto it = defaultEdits.begin(); it != defaultEdits.end(); it++)
104  {
105  std::optional<QString> json = it.value()->getValueAsJson();
106  if (json)
107  {
108  result[it.key()] = *json;
109  }
110  }
111  return result;
112  }
113 
114  void
115  MultiProfileDefaultValueEditWidget::on_comboBoxProfiles_currentIndexChanged(const QString& arg1)
116  {
117  for (const auto& it : defaultEdits)
118  {
119  if (!it.isNull())
120  {
121  it->hide();
122  }
123  }
124  ARMARX_INFO_S << "profile: " << arg1.toStdString();
125  if (!defaultEdits[arg1].isNull())
126  {
127  ARMARX_INFO_S << "showing: " << arg1.toStdString();
128  defaultEdits[arg1]->show();
129  }
130  else
131  {
132  defaultEdits[arg1] =
133  new ProfileDefaultValueEditWidget(typeString, "", communicator, this);
134  ui->splitter->addWidget(defaultEdits[arg1].data());
135  }
136  }
137 
138 } // namespace armarx
armarx::ProfileDefaultValueEditWidget
Definition: ProfileDefaultValueEditWidget.h:43
JSONObject.h
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::MultiProfileDefaultValueEditWidget::getJsonMap
QMap< QString, QString > getJsonMap() const
Definition: MultiProfileDefaultValueEditWidget.cpp:100
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:184
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:32
ARMARX_INFO_S
#define ARMARX_INFO_S
Definition: Logging.h:202
Logging.h
armarx::MultiProfileDefaultValueEditWidget::~MultiProfileDefaultValueEditWidget
~MultiProfileDefaultValueEditWidget() override
Definition: MultiProfileDefaultValueEditWidget.cpp:76
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::MultiProfileDefaultValueEditWidget::getVariantContainers
QMap< QString, VariantContainerBasePtr > getVariantContainers() const
Definition: MultiProfileDefaultValueEditWidget.cpp:82