StatechartEditorParameterEditor.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
25 
26 #include <QAction>
27 #include <QCompleter>
28 #include <QDialogButtonBox>
29 #include <QLineEdit>
30 #include <QMenu>
31 #include <QMessageBox>
32 #include <QPushButton>
33 #include <QTableWidgetItem>
34 #include <QToolButton>
35 #include <QVBoxLayout>
36 #include <QComboBox>
37 #include <QDialog>
38 #include <QTextEdit>
39 #include <QInputDialog>
40 #include <QLabel>
41 #include <QStyledItemDelegate>
42 #include <QPropertyAnimation>
43 
46 
47 //#include <ArmarXCore/statechart/StateParameter.h>
52 
54 //#include <ArmarXCore/statechart/StateParameter.h>
56 
57 #include <Ice/ObjectFactory.h>
59 
60 #include <memory>
63 
64 namespace armarx
65 {
67  {
68  this->state = state;
69  }
70 
72  QTableWidget(parent),
73  // currentProfile(currentProfile),
74  state(state),
75  defaultValueState(Qt::Unchecked)
76  {
77 
78  // For jsonobject double/float serilization on german/spanish pcs....
79  setlocale(LC_ALL, "C");
80 
81  setColumnCount(6);
82  qRegisterMetaType<statechartmodel::StateParameterMap>("statechartmodel::StateParameterMap");
83  // qRegisterMetaType<QVector<QString>>("QVector<QString>");
84  connect(this, SIGNAL(buildRequested(statechartmodel::StateParameterMap)), this, SLOT(__buildFromMap(statechartmodel::StateParameterMap)), Qt::QueuedConnection);
85 
86  setHeaders();
87 
88  if (params.size() == 0)
89  {
91  }
92  else
93  {
94  buildFromMap(params);
95  }
96 
97 
98 
99  setItemDelegateForColumn(eKey, &delegate);
100 
101  // horizontalHeaderItem(eAddtoParent)->setT;
102  connect(this, SIGNAL(rowAdded(int)), this, SLOT(addCustomColumn(int)));
103  connect(this, SIGNAL(rowFilled(int, QString)), this, SLOT(fillCustomColumn(int, QString)));
104 
106  }
107 
108 
109 
111  {
112 
113 
114  AnimatedToolButton* showHelpButton = new AnimatedToolButton(this);
115 
116 
117  QIcon icon;
118  icon.addFile(QString::fromUtf8(":/icons/help-about.ico"), QSize(), QIcon::Normal, QIcon::Off);
119  showHelpButton->setIcon(icon);
120  showHelpButton->setToolTip("Show or edit help to this parameter.");
121  connect(showHelpButton, SIGNAL(clicked()), this, SLOT(showHelpDialog()));
122 
123  if (state && state->getParent())
124  {
125 
126  QAction* addInputToParentAction = new QAction(showHelpButton);
127  QIcon icon;
128  icon.addFile(QString::fromUtf8(":/icons/add.png"), QSize(), QIcon::Normal, QIcon::Off);
129  addInputToParentAction->setIcon(icon);
130  addInputToParentAction->setIconVisibleInMenu(true);
131  addInputToParentAction->setText("Add to parent's input");
132  addInputToParentAction->setToolTip("Add this parameter to parent's input. This applies immediatly.");
133  addInputToParentAction->setData(row);
134  connect(addInputToParentAction, SIGNAL(triggered()), this, SLOT(addInputToParent()));
135 
136  QMenu* subMenu = new QMenu(showHelpButton);
137  subMenu->addAction(addInputToParentAction);
138  showHelpButton->setMenu(subMenu);
139  }
140 
141  setCellWidget(row, eAdditionalButtons, showHelpButton);
142  }
143 
144  void StatechartEditorParameterEditor::fillCustomColumn(int row, const QString& key)
145  {
146  QToolButton* showHelpButton = qobject_cast<QToolButton*>(cellWidget(row, eAdditionalButtons));
147 
148  if (showHelpButton)
149  {
150  auto it = originalParamMap.find(key);
151 
152  if (it != originalParamMap.end())
153  {
154  statechartmodel::StateParameterPtr pm = it.value();
155 
156  if (pm)
157  {
158  showHelpButton->setProperty("MarkdownDocText", pm->description);
159  QColor color = pm->description.isEmpty() ? QColor {250, 0, 0}:
160  QColor {0, 0, 250};
161 
162  QPalette pal = showHelpButton->palette();
163  showHelpButton->setAutoFillBackground(true);
164  QPropertyAnimation* animation = new QPropertyAnimation(showHelpButton, "color", this);
165  animation->setDuration(3000);
166  float t = 0;
167  while (t < 1)
168  {
169  animation->setKeyValueAt(t, color);
170  t += 0.1f;
171  animation->setKeyValueAt(t, pal.color(QPalette::Button));
172  t += 0.1f;
173  }
174  animation->setKeyValueAt(1, pal.color(QPalette::Button));
175  animation->setEasingCurve(QEasingCurve::InOutQuad);
176  animation->start();
177 
178  }
179 
180  originalParamMap.erase(it);
181  }
182 
183  }
184  }
185 
187  {
188 
189  QDialog editDefaultDialog;
190  editDefaultDialog.setWindowTitle("Statechart Parameter Documentation Editor");
191  editDefaultDialog.resize(QSize(600, 400));
192  MarkdownEditor* dialogTextEdit = new MarkdownEditor(this);
193  dialogTextEdit->setPlainText(sender()->property("MarkdownDocText").toString());
194 
195  QVBoxLayout* layout = new QVBoxLayout;
196  layout->addWidget(dialogTextEdit);
197  QDialogButtonBox* buttonBox = new QDialogButtonBox(dialogTextEdit);
198  buttonBox->setOrientation(Qt::Horizontal);
199  buttonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
200  layout->addWidget(buttonBox);
201  editDefaultDialog.setLayout(layout);
202 
203  connect(buttonBox, SIGNAL(accepted()), &editDefaultDialog, SLOT(accept()));
204  connect(buttonBox, SIGNAL(rejected()), &editDefaultDialog, SLOT(reject()));
205 
206  if (editDefaultDialog.exec() == QDialog::Accepted)
207  {
208  sender()->setProperty("MarkdownDocText", dialogTextEdit->toPlainText());
209  }
210 
211  }
212 
214  {
215 
216  int row;
217  QAction* action = qobject_cast<QAction*>(sender());
218  row = action->data().toInt();
219  QString keyName = item(row, eKey)->text();
221  auto parent = state->getParent();
222  ARMARX_CHECK_EXPRESSION(parent);
223  ARMARX_CHECK_EXPRESSION(keyName.length() > 0);
224  auto inputAndLocal = parent->getInputAndLocalParameters();
225 
226  if (inputAndLocal.count(keyName) > 0)
227  {
228  QMessageBox::warning(this, "State Editing Error", "The key '" + keyName + "' already exists");
229  return;
230  }
231 
232  statechartmodel::StateParameterMap input = parent->getInputParameters();
233  input.insert(keyName, getStateParameter(row));
234  state->getParent()->setInputParameters(input);
235  }
236 
238  {
239  auto profileNames = getRelevantProfiles();
240  int columnCount = eEditableValue + profileNames.size();
241 
242  setColumnCount(columnCount);
243  setColumnWidth(eAdditionalButtons, 35);
244 
245  if (!horizontalHeaderItem(eAdditionalButtons))
246  {
247  setHorizontalHeaderItem(eAdditionalButtons, new QTableWidgetItem(""));
248  }
249 
250  for (int i = 0; i < profileNames.size(); ++i)
251  {
252  setColumnWidth(eEditableValue + i, 200);
253  setHorizontalHeaderItem(eEditableValue + i, new QTableWidgetItem(profileNames[i]));
254  }
255 
256 
257  if (state && state->getParent())
258  {
259  // horizontalHeaderItem(eAddtoParent)->setText();
260  }
261  }
262 
263  void StatechartEditorParameterEditor::setKeyBlackList(const QSet<QString>& keyBlackList)
264  {
265  this->keyBlackList = keyBlackList;
266  }
267 
269  {
270  QSet<QString> result;
271 
272  for (int row = 0; row < rowCount(); row++)
273  {
274  if (item(row, eKey) && !item(row, eKey)->text().isEmpty())
275  {
276  result.insert(item(row, eKey)->text());
277  }
278  }
279 
280  return result;
281  }
282 
284  {
285  QSet<QString> types;
286  for (int i = 0; i < rowCount(); ++i)
287  {
288  types.insert(getType(i));
289  }
290  return types;
291  }
292 
294  {
295  if (getKey(row).isEmpty())
296  {
298  }
299 
300  statechartmodel::StateParameterPtr p = std::make_shared<statechartmodel::StateParameter>();
301  p->type = getType(getKey(row));
302  p->optional = getIsOptional(row);
303 
304  if (auto descriptionWidget = cellWidget(row, StatechartEditorParameterEditor::eAdditionalButtons))
305  {
306  p->description = descriptionWidget->property("MarkdownDocText").toString();
307  }
308 
309  auto jsonValues = getProfileJsonMap(getKey(row));
310  auto variants = getProfileVariantContainerMap(row);
311 
312  for (const auto& profileName : getRelevantProfiles())
313  {
314  p->profileDefaultValues[profileName] = {variants[profileName], jsonValues[profileName]};
315  }
316 
317  return p;
318  }
319 
321  {
323 
324  for (int row = 0; row < rowCount(); ++row)
325  {
326  if (auto param = getStateParameter(row))
327  {
328  result[getKey(row)] = param;
329  }
330  }
331 
332  return result;
333  }
334 
335  //StateParameterMap StatechartEditorParameterEditor::getStateParametersWithoutValue()
336  //{
337  // StateParameterMap result;
338  // for (int row = 0; row < rowCount(); ++row) {
339  // StateParameterIceBasePtr param = new StateParameterIceBase();
340  //if(getKey(row).length() == 0)
341  // continue;
342 
343  // }
344  //}
345 
346  QMap<QString, QString> StatechartEditorParameterEditor::getValuesAsString(int row) const
347  {
348  if (row >= rowCount() || row < 0)
349  {
350  throw LocalException("row index out of range: ") << row;
351  }
352 
353  QMap<QString, QString> result;
354 
355  auto profileNames = getRelevantProfiles();
356 
357  for (int i = 0; i < profileNames.size(); ++i)
358  {
359  auto widget = qobject_cast<ProfileDefaultValueEditWidget*>(cellWidget(row, eEditableValue + i));
360 
361  if (auto value = widget->getValueAsString())
362  {
363  result[profileNames[i]] = *value;
364  }
365  }
366 
367  return result;
368  }
369 
370  QMap<QString, QString> StatechartEditorParameterEditor::getProfileJsonMap(QString key) const
371  {
372  int row = -1;
373 
374  for (int i = 0; i < rowCount(); i++)
375  {
376  if (getKey(i) == key)
377  {
378  row = i;
379  break;
380  }
381  }
382 
383  if (row >= rowCount() || row < 0)
384  {
385  throw LocalException("row index out of range: ") << row;
386  }
387 
388  QMap<QString, QString> result;
389 
390  auto profileNames = getRelevantProfiles();
391 
392  for (int i = 0; i < profileNames.size(); ++i)
393  {
394  auto widget = qobject_cast<ProfileDefaultValueEditWidget*>(cellWidget(row, eEditableValue + i));
395 
396  if (auto value = widget->getValueAsJson())
397  {
398  result[profileNames[i]] = *value;
399  }
400  }
401 
402  return result;
403  }
404 
405 
406  QMap<QString, VariantContainerBasePtr> StatechartEditorParameterEditor::getProfileVariantContainerMap(int row) const
407  {
408  if (row >= rowCount() || row < 0)
409  {
410  throw LocalException("row index out of range: ") << row;
411  }
412 
413  QMap<QString, VariantContainerBasePtr> result;
414 
415  auto profileNames = getRelevantProfiles();
416 
417  for (int i = 0; i < profileNames.size(); ++i)
418  {
419  auto widget = qobject_cast<ProfileDefaultValueEditWidget*>(cellWidget(row, eEditableValue + i));
420  result[profileNames[i]] = widget->getVariantContainer();
421  }
422 
423  return result;
424  }
425 
427  {
428  if (row >= rowCount())
429  {
430  throw LocalException("row index out of range: ") << row;
431  }
432 
433  if (!item(row, eKey))
434  {
435  return "";
436  }
437 
438  return item(row, eKey)->text();
439  }
440 
442  {
443  if (row >= rowCount())
444  {
445  throw LocalException("row index out of range: ") << row;
446  }
447 
448  QComboBox* CBvalueType = qobject_cast<QComboBox*>(cellWidget(row, 1));
449 
450  if (!CBvalueType)
451  {
452  return "";
453  }
454 
455  QString type = getBaseNameFromHumanName(CBvalueType->currentText()); //@@@
456  return type;
457 
458  }
459 
460  QString StatechartEditorParameterEditor::getType(QString key) const
461  {
462  int row = getRow(key);
463  return getType(row);
464  }
465 
466  int StatechartEditorParameterEditor::getRow(const QString& key) const
467  {
468  int row = -1;
469 
470  for (int i = 0; i < rowCount(); i++)
471  {
472  if (getKey(i) == key)
473  {
474  row = i;
475  break;
476  }
477  }
478 
479  if (row == -1)
480  {
481  throw LocalException("could not find key ") << key.toStdString();
482  }
483 
484  return row;
485  }
486 
488  {
489  if (row >= rowCount())
490  {
491  throw LocalException("row index out of range: ") << row;
492  }
493 
494  QComboBox* cbOptional = qobject_cast<QComboBox*>(cellWidget(row, eOptional));
495  return cbOptional->currentText() == "true";
496  }
497 
498 
500  {
501  // ARMARX_IMPORTANT_S << "Adding row";
502  int row = rowCount();
503  insertRow(row);
504  setItem(row, eKey, new QTableWidgetItem());
505 
506  // setItem(row, eProvideDefaultValue, new QTableWidgetItem());
507  // item(row, eProvideDefaultValue)->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
508  // item(row, eProvideDefaultValue)->setCheckState(defaultValueState);
509 
510  QComboBox* valueTypebox = new QComboBox;
511  valueTypebox->setEditable(true);
512  // valueTypebox->setInsertPolicy(QComboBox::InsertAlphabetically);
513  // valueTypebox->setValidator(new QIntValidator(this));
514  setCellWidget(row, eType, valueTypebox);
515  QStringList types = addVariantTypesToComboBox(valueTypebox);
516  InfixCompleter* fullCompleter = new InfixCompleter(types, this);
517  fullCompleter->setCompletionMode(QCompleter::PopupCompletion);
518  fullCompleter->setCaseSensitivity(Qt::CaseInsensitive);
519  valueTypebox->setCompleter(fullCompleter);
520  valueTypebox->setEditText("string");
521  connect(valueTypebox, SIGNAL(editTextChanged(QString)), this, SLOT(typeCbChanged(QString)));
522  connect(valueTypebox->lineEdit(), SIGNAL(textEdited(QString)), fullCompleter, SLOT(setCompletionInfix(QString)));
523  //valueTypebox->model()->sort(0);
524  QComboBox* cbOptional;
525  cbOptional = new QComboBox();
526  cbOptional->addItems(QString("true;false").split(";"));
527  cbOptional->setCurrentIndex(1);
528  setCellWidget(row, eOptional, cbOptional);
529 
530 
531  QIcon icon;
532  icon.addFile(QString::fromUtf8(":/icons/dialog-close.ico"), QSize(), QIcon::Normal, QIcon::Off);
533  QToolButton* deleteButton = new QToolButton(this);
534  deleteButton->setIcon(icon);
535  deleteButton->setToolTip("Add this parameter to parent's input");
536  deleteButton->setToolTip("Delete this row");
537  setCellWidget(row, eDeleteButton, deleteButton);
538  connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteRow()));
539 
540  auto profileNames = getRelevantProfiles();
541 
542  for (int i = 0; i < profileNames.size(); ++i)
543  {
544  ProfileDefaultValueEditWidget* valueWidget = new ProfileDefaultValueEditWidget(getBaseNameFromHumanName(valueTypebox->currentText()), QString(), communicator);
545  setCellWidget(row, eEditableValue + i, valueWidget);
546  }
547 
548  emit rowAdded(row);
549  return row;
550  }
551 
552 
553  void StatechartEditorParameterEditor::addParameterRow(QString key, QString variantIdStr, QVector<QString> values, bool optional)
554  {
555  int row = addParameterRow();
556 
557  item(row, eKey)->setText(key);
558 
559  QComboBox* valueTypeBox = qobject_cast<QComboBox*>(cellWidget(row, eType));
560  // ARMARX_INFO_S << "type id: " << variantIdStr.toStdString() << " size: " << valueTypeBox->count();
561  valueTypeBox->setEditText(getHumanNameFromBaseName(variantIdStr));
562 
563  QComboBox* optionalBox = qobject_cast<QComboBox*>(cellWidget(row, eOptional));
564  optionalBox->setCurrentIndex(optional ? 0 : 1);
565 
566  for (int i = 0; i < values.size(); ++i)
567  {
568  ProfileDefaultValueEditWidget* valueWidget = new ProfileDefaultValueEditWidget(variantIdStr, values[i], communicator);
569  setCellWidget(row, eEditableValue + i, valueWidget);
570  }
571 
572  emit rowFilled(row, key);
573  }
574 
576  {
577  QWidget* wid = qobject_cast<QWidget*>(sender());
578 
579  /*QModelIndex mIndex =*/ indexAt(wid->pos()); // Some strange bug happens here: If this is used, it will deliver on table creation zero
580  // If indexAt is not called, wid->pos() delivers a 0,0 Point and then rowAt() also return wrong index
581  // ARMARX_INFO_S << VAROUT(wid->pos()) << VAROUT(rowAt(wid->pos().y()));
582 
583  int row = rowAt(wid->pos().y());
584 
585  QComboBox* typeBox = qobject_cast<QComboBox*>(cellWidget(row, eType));
586  QString typeStr = getBaseNameFromHumanName(typeBox->currentText()); //@@@
587 
588  for (int i = eEditableValue; i < columnCount(); ++i)
589  {
590  if (ProfileDefaultValueEditWidget* valueWidget = qobject_cast<ProfileDefaultValueEditWidget*>(cellWidget(row, i)))
591  {
592  if (typeStr != valueWidget->getType())
593  {
594  auto newWidget = new ProfileDefaultValueEditWidget(typeStr, QString(), communicator);
595  setCellWidget(row, i, newWidget);
596  }
597 
598  // valueWidget->setType(typeStr);
599  }
600  }
601  emit typeChanged(row, typeStr);
602  }
603 
604 
606  {
607  int row;
608  QWidget* wid = qobject_cast<QWidget*>(sender());
609  QModelIndex mIndex = indexAt(wid->pos());
610  row = mIndex.row();
611 
612  disconnect(this);
613  removeRow(row);
614 
615  if (rowCount() == 0)
616  {
617  addParameterRow();
618  }
619 
620  connectUserEditSlots();
621  }
622 
624  {
625  // ARMARX_IMPORTANT_S << "checking row: " << row << ", " << column;
626 
627  // if(column == eProvideDefaultValue)
628  // {
629  // if(item(row,eProvideDefaultValue)->checkState() == Qt::Unchecked)
630  // {
631  // QWidget* valueWidget = cellWidget(row, eValue);
632  // QWidget* valueLineEdit = qobject_cast<QWidget*>(valueWidget);
633  // if(valueLineEdit){
634  // valueLineEdit->setEnabled(false);
635  // }
636  // }
637  // else
638  // {
639  // QWidget* valueWidget = cellWidget(row, eValue);
640  // QWidget* valueLineEdit = qobject_cast<QWidget*>(valueWidget);
641  // if(valueLineEdit){
642  // valueLineEdit->setEnabled(true);
643  // }
644  // }
645  // }
646  if (column == eKey)
647  {
648  auto keyitem = item(row, eKey);
649 
650  if (keyitem)
651  {
652  if ((keyBlackList.find(keyitem->text()) != keyBlackList.end() || findItems(keyitem->text(), Qt::MatchExactly).size() > 1))
653  {
654  keyitem->setText(item(row, eKey)->text() + "_2");
655  ARMARX_WARNING_S << "Keys must be unique (input and local parameters share the same key pool)";
656  }
657  }
658  }
659 
660  if (row >= rowCount() - 1 && item(rowCount() - 1, 0) && !item(rowCount() - 1, 0)->text().isEmpty())
661  {
662  addParameterRow();
663  }
664  }
665 
667  {
668  for (int row = 0; row < rowCount(); row++)
669  {
670  QComboBox* valueTypeBox = qobject_cast<QComboBox*>(cellWidget(row, eType));
671  addVariantTypesToComboBox(valueTypeBox);
672  // valueTypeBox->model()->sort(0);
673  }
674 
675  }
676 
677  void StatechartEditorParameterEditor::connectUserEditSlots()
678  {
679  connect(this, SIGNAL(cellEntered(int, int)), this, SLOT(checkAndUpdateRowCount(int, int)), Qt::UniqueConnection);
680  connect(this, SIGNAL(cellPressed(int, int)), this, SLOT(checkAndUpdateRowCount(int, int)), Qt::UniqueConnection);
681  connect(this, SIGNAL(cellChanged(int, int)), this, SLOT(checkAndUpdateRowCount(int, int)), Qt::UniqueConnection);
682  }
683 
684  QStringList StatechartEditorParameterEditor::addVariantTypesToComboBox(QComboBox* combo)
685  {
686  if (!combo)
687  {
688  return QStringList();
689  }
690 
691  combo->clear();
692 
693 
694  auto types = Variant::getTypes();
695  QStringList list;
696  for (std::pair<VariantTypeId, std::string> pair : types)
697  {
698  QString typeName = tr(pair.second.c_str());
699  //QString humanName = tr(Variant::getHumanName(pair->first).c_str());
700 
701  if (typeName.contains("Invalid"))
702  {
703  continue;
704  }
705 
706  list.append(getHumanNameFromBaseName(typeName));
707  /*if(combo->findText(typeName) == -1)
708  {
709  combo->addItem(getHumanNameFromBaseName(typeName));
710  }*/
711  }
712 
713  std::vector<VariantContainerType> containers;
714  containers.push_back(VariantType::List);
715  containers.push_back(VariantType::Map);
716 
717  for (VariantContainerType c : containers)
718  {
719  for (auto it : types)
720  {
721  QString typeName = tr(it.second.c_str());
722 
723 
724  if (typeName.contains("Invalid"))
725  {
726  continue;
727  }
728 
729  std::string typeStr = VariantContainerType::allTypesToString(c(it.first).clone());
730  typeName = QString::fromStdString(typeStr);
731  list.append(getHumanNameFromBaseName(typeName));
732  /*if(combo->findText(typeName) == -1)
733  {
734  combo->addItem(getHumanNameFromBaseName(typeName));
735  }*/
736  }
737  }
738 
739  qSort(list.begin(), list.end(), compareVariantNames);
740  combo->addItems(list);
741  return list;
742  }
743 
744  QString StatechartEditorParameterEditor::getHumanNameFromBaseName(QString variantBaseTypeName) const
745  {
746  if (!variantInfo)
747  {
748  return variantBaseTypeName;
749  }
750 
751  std::string humanName = variantInfo->getNestedHumanNameFromBaseName(variantBaseTypeName.toUtf8().data());
752 
753  if (humanName.empty())
754  {
755  return variantBaseTypeName;
756  }
757 
758  return QString::fromUtf8(humanName.c_str());
759  }
760 
761  QString StatechartEditorParameterEditor::getBaseNameFromHumanName(QString humanName) const
762  {
763  if (!variantInfo)
764  {
765  return humanName;
766  }
767 
768  std::string variantBaseTypeName = variantInfo->getNestedBaseNameFromHumanName(humanName.toUtf8().data());
769 
770  if (variantBaseTypeName.empty())
771  {
772  return humanName;
773  }
774 
775  return QString::fromUtf8(variantBaseTypeName.c_str());
776  }
777 
778  bool StatechartEditorParameterEditor::compareVariantNames(const QString& a, const QString& b)
779  {
780  bool pa, pb;
781 
782  // list nested types after basic ones
783  pa = a.contains("(");
784  pb = b.contains("(");
785 
786  if (pa != pb)
787  {
788  return pb;
789  }
790 
791  // list human types before non resolved ones
792  pa = a.contains(":");
793  pb = b.contains(":");
794 
795  if (pa != pb)
796  {
797  return pb;
798  }
799 
800  // nested lower case (basic types) first
801  int ia = a.indexOf("(");
802  int ib = b.indexOf("(");
803  pa = ia > 0 && a.count() > ia + 1 && a[ia + 1].isLower();
804  pb = ib > 0 && b.count() > ib + 1 && b[ib + 1].isLower();
805  if (pa != pb && a.left(ia) == b.left(ib))
806  {
807  return !pb;
808  }
809 
810  // lower case (basic types) first
811  pa = a.count() > 0 && a[0].isLower();
812  pb = b.count() > 0 && b[0].isLower();
813 
814  if (pa != pb)
815  {
816  return pa;
817  }
818 
819  return a.compare(b) < 0;
820  }
822  {
823  return defaultValueState;
824  }
825 
827  {
828  defaultValueState = value;
829  }
830 
832  {
833  const auto& relevantProfiles = getRelevantProfiles();
834 
835  for (int i = 0; i < relevantProfiles.size(); ++i)
836  {
837  hideColumn(eEditableValue + i);
838  }
839  }
840 
842  {
843  QStringList headerLabels {"Key", "Type", "Optional", "Del"};
844  setColumnWidth(eKey, 180);
845  setColumnWidth(eType, 225);
846  setColumnWidth(eOptional, 70);
847  setColumnWidth(eDeleteButton, 25);
848  // setColumnWidth(eAdditionalButtons, 25);
849 
850  auto profileNames = getRelevantProfiles();
851  int col = eEditableValue;
852 
853  for (int i = 0; i < profileNames.size(); ++i)
854  {
855  setColumnWidth(col + i, 200);
856  headerLabels.push_back(profileNames[i]);
857  }
858 
859  setHorizontalHeaderLabels(headerLabels);
860  }
861 
863  {
864  originalParamMap = map;
865  emit buildRequested(map);
866  }
867 
868  void StatechartEditorParameterEditor::__buildFromMap(const statechartmodel::StateParameterMap& map)
869  {
870  clearContents();
871  QWidget* tempW = new QLabel("mylabel", this);
872  tempW->deleteLater();
873  setRowCount(0);
874  // disconnect(this);
875  disconnect(this, SIGNAL(cellEntered(int, int)));
876  disconnect(this, SIGNAL(cellPressed(int, int)));
877  disconnect(this, SIGNAL(cellChanged(int, int)));
878 
879  auto relevantProfiles = getRelevantProfiles();
880 
881  for (const auto& entry : map.toStdMap())
882  {
883  const QString& name = entry.first;
884  const statechartmodel::StateParameterPtr& param = entry.second;
885 
886  //JSONObjectPtr json = new JSONObject(communicator);
887  QVector<QString> jsonStrs;
888  QString typeStr = param->type;
889 
890  for (const QString& profile : relevantProfiles)
891  {
892  QString jsonStr = param->profileDefaultValues[profile].second;
893  jsonStrs.push_back(jsonStr);
894  }
895 
896  addParameterRow(name, typeStr, jsonStrs, param->optional);
897 
898  }
899 
900  addParameterRow();
901  connectUserEditSlots();
902  // setHeaders();
903 
904  }
905 
906  QVector<QString> StatechartEditorParameterEditor::getRelevantProfiles() const
907  {
908  if (!currentProfile)
909  {
910  return QVector<QString>();
911  }
912 
913  QVector<QString> result {QString::fromUtf8(currentProfile->getName().c_str())};
914  auto profile = currentProfile;
915 
916  while ((profile = profile->getParent()))
917  {
918  result.push_back(QString::fromUtf8(profile->getName().c_str()));
919  }
920 
921  return result;
922  }
923 
924  QWidget* StatechartEditorParameterEditor::LineEditDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const
925  {
926  QLineEdit* lineEdit = new QLineEdit(parent);
927  QString regExpStr("(|([a-z_]{1})([a-z_0-9]*))");
928  QRegExp reg(regExpStr, Qt::CaseInsensitive);
929  lineEdit->setValidator(new QRegExpValidator(reg, lineEdit));
930  return lineEdit;
931  }
932 
933 
934 
935 
936  void AnimatedToolButton::setColor(QColor color)
937  {
938  QString val = QString("background-color: rgb(%1, %2, %3);").arg(color.red()).arg(color.green()).arg(color.blue());
939  // ARMARX_INFO << "Setting value to " << val.toStdString();
940  setStyleSheet(val);
941  }
942 }
armarx::StatechartEditorParameterEditor::getIsOptional
bool getIsOptional(int row) const
Definition: StatechartEditorParameterEditor.cpp:487
armarx::ProfileDefaultValueEditWidget
Definition: ProfileDefaultValueEditWidget.h:42
armarx::StatechartEditorParameterEditor::getKey
QString getKey(int row) const
Definition: StatechartEditorParameterEditor.cpp:426
SingleTypeVariantList.h
armarx::StatechartEditorParameterEditor::state
statechartmodel::StateInstancePtr state
Definition: StatechartEditorParameterEditor.h:70
armarx::StatechartEditorParameterEditor::getProfileVariantContainerMap
QMap< QString, VariantContainerBasePtr > getProfileVariantContainerMap(int row) const
Definition: StatechartEditorParameterEditor.cpp:406
armarx::VariantType::List
const VariantContainerType List
Definition: SingleTypeVariantList.h:191
armarx::StatechartEditorParameterEditor::fillCustomColumn
void fillCustomColumn(int row, const QString &key)
Definition: StatechartEditorParameterEditor.cpp:144
JSONObject.h
armarx::AnimatedToolButton::setColor
void setColor(QColor color)
Definition: StatechartEditorParameterEditor.cpp:936
index
uint8_t index
Definition: EtherCATFrame.h:59
StateParameter.cpp
armarx::StatechartEditorParameterEditor::originalParamMap
statechartmodel::StateParameterMap originalParamMap
Definition: StatechartEditorParameterEditor.h:71
armarx::StatechartEditorParameterEditor::getProfileJsonMap
QMap< QString, QString > getProfileJsonMap(QString key) const
Definition: StatechartEditorParameterEditor.cpp:370
MarkdownEditor.h
VariantContainer.h
list
list(APPEND SOURCES ${QT_RESOURCES}) set(COMPONENT_LIBS ArmarXGui ArmarXCoreObservers ArmarXCoreEigen3Variants PlotterController $
Definition: CMakeLists.txt:49
armarx::VariantType::Map
const VariantContainerType Map
Definition: StringValueMap.h:247
armarx::StatechartEditorParameterEditor::eEditableValue
@ eEditableValue
Definition: StatechartEditorParameterEditor.h:83
armarx::StatechartEditorParameterEditor::setDefaultValueState
void setDefaultValueState(const Qt::CheckState &value)
Definition: StatechartEditorParameterEditor.cpp:826
armarx::StatechartEditorParameterEditor::getDefaultValueState
Qt::CheckState getDefaultValueState() const
Definition: StatechartEditorParameterEditor.cpp:821
StructuralJsonParser.h
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::StatechartEditorParameterEditor::buildRequested
void buildRequested(const statechartmodel::StateParameterMap &map)
armarx::StatechartEditorParameterEditor::rowAdded
void rowAdded(int rowId)
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::Variant::getTypes
static const std::map< VariantTypeId, std::string > & getTypes()
Returns the mapping of currently registered types.
Definition: Variant.cpp:746
armarx::StatechartEditorParameterEditor::setStateInstance
void setStateInstance(statechartmodel::StateInstancePtr state)
Definition: StatechartEditorParameterEditor.cpp:66
StatechartEditorParameterEditor.h
armarx::AnimatedToolButton::color
QColor color
Definition: StatechartEditorParameterEditor.h:41
armarx::StatechartEditorParameterEditor::getKeys
QSet< QString > getKeys() const
Definition: StatechartEditorParameterEditor.cpp:268
armarx::StatechartEditorParameterEditor::eKey
@ eKey
Definition: StatechartEditorParameterEditor.h:78
armarx::statechartmodel::StateInstancePtr
std::shared_ptr< StateInstance > StateInstancePtr
Definition: StateInstance.h:138
armarx::StatechartEditorParameterEditor::checkAndUpdateRowCount
void checkAndUpdateRowCount(int row, int column)
Definition: StatechartEditorParameterEditor.cpp:623
armarx::StatechartEditorParameterEditor::addCustomColumn
void addCustomColumn(int row)
Definition: StatechartEditorParameterEditor.cpp:110
armarx::StatechartEditorParameterEditor::setKeyBlackList
void setKeyBlackList(const QSet< QString > &keyBlackList)
Definition: StatechartEditorParameterEditor.cpp:263
armarx::InfixCompleter
This class changes the standard QCompleter to an infix match completer.
Definition: InfixCompleter.h:15
StringValueMap.h
armarx::ctrlutil::a
double a(double t, double a0, double j)
Definition: CtrlUtil.h:45
armarx::StatechartEditorParameterEditor::hideValueColumns
void hideValueColumns()
Definition: StatechartEditorParameterEditor.cpp:831
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::StatechartEditorParameterEditor::typeChanged
void typeChanged(int row, const QString &newType)
armarx::StatechartEditorParameterEditor::getStateParameters
statechartmodel::StateParameterMap getStateParameters() const
Definition: StatechartEditorParameterEditor.cpp:320
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
JPathNavigator.h
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::StatechartEditorParameterEditor::deleteRow
void deleteRow()
Definition: StatechartEditorParameterEditor.cpp:605
armarx::StatechartEditorParameterEditor::showHelpDialog
void showHelpDialog()
Definition: StatechartEditorParameterEditor.cpp:186
InfixCompleter.h
armarx::StatechartEditorParameterEditor::eDeleteButton
@ eDeleteButton
Definition: StatechartEditorParameterEditor.h:81
ProfileDefaultValueEditWidget.h
armarx::MarkdownEditor::setPlainText
void setPlainText(const QString &plainText)
Definition: MarkdownEditor.cpp:65
armarx::statechartmodel::StateParameterPtr
std::shared_ptr< StateParameter > StateParameterPtr
Definition: StateParameter.h:45
armarx::StatechartEditorParameterEditor::eAdditionalButtons
@ eAdditionalButtons
Definition: StatechartEditorParameterEditor.h:82
armarx::StatechartEditorParameterEditor::getRow
int getRow(const QString &key) const
Definition: StatechartEditorParameterEditor.cpp:466
armarx::StatechartEditorParameterEditor::addInputToParent
void addInputToParent()
Definition: StatechartEditorParameterEditor.cpp:213
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::StatechartEditorParameterEditor::buildFromMap
void buildFromMap(const statechartmodel::StateParameterMap &map)
Definition: StatechartEditorParameterEditor.cpp:862
armarx::StatechartEditorParameterEditor::getStateParameter
statechartmodel::StateParameterPtr getStateParameter(int row) const
Definition: StatechartEditorParameterEditor.cpp:293
GfxTL::Off
OnOff< false > Off
Definition: OnOff.h:11
option
#define option(type, fn)
ARMARX_CHECK_EXPRESSION
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
Definition: ExpressionException.h:73
armarx::StatechartEditorParameterEditor::eOptional
@ eOptional
Definition: StatechartEditorParameterEditor.h:80
armarx::StatechartEditorParameterEditor::addParameterRow
int addParameterRow()
Definition: StatechartEditorParameterEditor.cpp:499
armarx::StatechartEditorParameterEditor::getValuesAsString
QMap< QString, QString > getValuesAsString(int row) const
Definition: StatechartEditorParameterEditor.cpp:346
armarx::StatechartEditorParameterEditor::getType
QString getType(int row) const
Definition: StatechartEditorParameterEditor.cpp:441
armarx::viz::toString
const char * toString(InteractionFeedbackType type)
Definition: Interaction.h:27
armarx::StatechartEditorParameterEditor::getTypes
QSet< QString > getTypes() const
Definition: StatechartEditorParameterEditor.cpp:283
armarx::StatechartEditorParameterEditor::eType
@ eType
Definition: StatechartEditorParameterEditor.h:79
armarx::StatechartEditorParameterEditor::rowFilled
void rowFilled(int rowId, const QString &key)
armarx::StatechartEditorParameterEditor::StatechartEditorParameterEditor
StatechartEditorParameterEditor(QWidget *parent=0, statechartmodel::StateInstancePtr state=statechartmodel::StateInstancePtr(), const statechartmodel::StateParameterMap &params=statechartmodel::StateParameterMap())
Definition: StatechartEditorParameterEditor.cpp:71
armarx::StatechartEditorParameterEditor::refreshVariantTypes
void refreshVariantTypes()
Definition: StatechartEditorParameterEditor.cpp:666
armarx::StatechartEditorParameterEditor::setHeaders
void setHeaders()
Definition: StatechartEditorParameterEditor.cpp:841
armarx::StatechartEditorParameterEditor::init
void init(const statechartmodel::StateParameterMap &params)
Definition: StatechartEditorParameterEditor.cpp:237
Variant.h
armarx::MarkdownEditor::toPlainText
QString toPlainText() const
Definition: MarkdownEditor.cpp:53
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::AnimatedToolButton
Definition: StatechartEditorParameterEditor.h:37
armarx::VariantContainerType::allTypesToString
static std::string allTypesToString(const ContainerTypePtr &type)
Definition: VariantContainer.cpp:232
armarx::split
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
Definition: StringHelpers.cpp:36
armarx::MarkdownEditor
The MarkdownEditor is a widget that provides editing of raw text and viewing of processed markdown te...
Definition: MarkdownEditor.h:45
armarx::StatechartEditorParameterEditor::typeCbChanged
void typeCbChanged(const QString &)
Definition: StatechartEditorParameterEditor.cpp:575