26 #include <boost/regex.hpp>
29 #include <QItemSelectionModel>
38 #include <ArmarXGui/gui-plugins/ObserverPropertiesPlugin/ui_FilterPropertiesDialog.h>
41 #include "../ObserverGuiPlugin.h"
42 #include "../ObserverWidgetController.h"
49 qRegisterMetaType<DatafieldFilterBasePtr>(
"DatafieldFilterBasePtr");
51 ui.propertiesView->setLayout(
new QVBoxLayout());
52 ui.observerTreeView->setSortingEnabled(
true);
57 updateTimer =
new QTimer(
this);
59 connect(ui.observerTreeView,
60 SIGNAL(customContextMenuRequested(
const QPoint&)),
68 ui.splitter->setSizes(sizes);
70 autoUpdateAction =
new QAction(
"Auto update", ui.observerTreeView);
72 filterExpansionTimer.setSingleShot(
true);
73 connect(&filterExpansionTimer, SIGNAL(timeout()),
this, SLOT(delayedFilterExpansion()));
81 proxyModel->setSourceModel(model);
82 ui.observerTreeView->setModel(proxyModel);
83 proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
85 QItemSelectionModel* selectionModel = ui.observerTreeView->selectionModel();
86 connect(selectionModel,
87 SIGNAL(selectionChanged(
const QItemSelection&,
const QItemSelection&)),
92 connect(ui.lineEditSearch,
93 SIGNAL(textChanged(QString)),
95 SLOT(setFilterFixedString(QString)));
96 connect(ui.lineEditSearch,
97 SIGNAL(textChanged(QString)),
99 SLOT(expandFilterSelection(QString)),
100 Qt::QueuedConnection);
111 auto selection = ui.observerTreeView->selectionModel()->selectedIndexes();
113 if (selection.size() > 0)
115 if (propertiesWidget)
117 ui.propertiesView->layout()->removeWidget(propertiesWidget);
118 propertiesWidget->deleteLater();
119 propertiesWidget = NULL;
122 proxyModel->mapToSource(selection.at(0)), ui.propertiesView);
125 propertiesWidget = tempWidgetPtr;
126 ui.propertiesView->layout()->addWidget(propertiesWidget);
127 propertiesWidget->show();
134 const QItemSelection& deselected)
136 if (selected.indexes().size() == 0)
141 if (propertiesWidget)
143 ui.propertiesView->layout()->removeWidget(propertiesWidget);
144 propertiesWidget->deleteLater();
145 propertiesWidget = NULL;
148 QModelIndexList
list = selected.indexes();
151 ui.propertiesView->layout()->addWidget(propertiesWidget);
152 propertiesWidget->show();
160 updateTimer->start(500);
171 QAction* action = qobject_cast<QAction*>(sender());
175 DatafieldFilterBasePtr filter;
176 if (!action->data().isNull())
178 auto filterName = action->data().toString().toStdString();
180 controller->getIceManager()->getCommunicator()->getValueFactoryManager()->find(
184 ARMARX_WARNING <<
"Could not find obj factory of type " << filterName;
188 filter = DatafieldFilterBasePtr::dynamicCast(valFac->create(filterName));
197 ARMARX_ERROR <<
"Filter " << action->text().toStdString() <<
" is unknown";
201 Ui::FilterPropertiesDialog dSetup;
203 dSetup.tableWidget->setSortingEnabled(
false);
204 StringFloatDictionary props = filter->getProperties();
206 dSetup.tableWidget->setRowCount(props.size());
207 dSetup.tableWidget->setColumnCount(2);
209 for (
auto& p : props)
211 auto keyItem =
new QTableWidgetItem(p.first.c_str());
212 keyItem->setFlags(Qt::ItemIsEnabled);
213 dSetup.tableWidget->setItem(i, 0, keyItem);
214 auto valueItem =
new QTableWidgetItem(QString::number(p.second));
215 dSetup.tableWidget->setItem(i, 1, valueItem);
218 dSetup.groupBox->setTitle(action->text() +
" properties");
219 if (d.exec() == QDialog::Accepted)
222 for (
int i = 0; i < dSetup.tableWidget->rowCount(); ++i)
225 float value = dSetup.tableWidget->item(i, 1)->text().toFloat(&
ok);
228 props[dSetup.tableWidget->item(i, 0)->text().toStdString()] =
value;
232 filter->setProperties(props);
236 selectedFilterId.clear();
242 if (propertiesWidget)
244 ui.propertiesView->layout()->removeWidget(propertiesWidget);
245 propertiesWidget->deleteLater();
246 propertiesWidget = NULL;
253 QPoint globalPos = ui.observerTreeView->viewport()->mapToGlobal(point);
257 QAction* updateAction =
new QAction(
"Update", ui.observerTreeView);
259 if (autoUpdateAction->isChecked())
261 updateAction->setEnabled(
false);
264 connect(updateAction, SIGNAL(triggered()),
this, SLOT(
updateObservers()));
265 treeViewMenu.addAction(updateAction);
273 qobject_cast<DataFieldPropertiesWidget*>(propertiesWidget);
276 auto typeId = widget->
getVariant()->getType();
278 QMenu* filters = treeViewMenu.addMenu(
"Filters");
279 std::map<std::string, bool> filterNames;
287 for (
auto pair : facContainer->getFactories())
290 Ice::ValueFactoryPtr fac = pair.second;
297 auto obj = fac->create(pair.first);
304 DatafieldFilterBasePtr filter = DatafieldFilterBasePtr::dynamicCast(obj);
307 auto supportedTypes = filter->getSupportedTypes();
309 std::find(supportedTypes.begin(), supportedTypes.end(), typeId);
311 std::make_pair(pair.first, typeIt != supportedTypes.end()));
319 for (
auto filter : filterNames)
321 const boost::regex e(
"::armarx::([a-zA-Z0-9_]+)Base");
322 boost::match_results<std::string::const_iterator> what;
323 boost::regex_search(filter.first, what, e);
327 a = filters->addAction(filter.first.c_str(),
this, SLOT(
filterSelected()));
331 std::string filteredName = what[1];
332 a = filters->addAction(filteredName.c_str(),
this, SLOT(
filterSelected()));
334 a->setEnabled(filter.second);
337 a->setToolTip(
"This filter does not support this type");
339 a->setData(filter.first.c_str());
344 QAction* selectedItem = treeViewMenu.exec(globalPos);
358 ObserverWidget::expandFilterSelection(QString filterStr)
361 if (filterStr.length() == 0)
363 ui.observerTreeView->collapseAll();
368 filterExpansionTimer.start(500);
373 ObserverWidget::delayedFilterExpansion()