25 #include "../ObserverGuiPlugin.h"
30 #include <QItemSelectionModel>
32 #include "../ObserverWidgetController.h"
34 #include <ArmarXGui/gui-plugins/ObserverPropertiesPlugin/ui_FilterPropertiesDialog.h>
40 #include <boost/regex.hpp>
49 qRegisterMetaType<DatafieldFilterBasePtr>(
"DatafieldFilterBasePtr");
51 ui.propertiesView->setLayout(
new QVBoxLayout());
52 ui.observerTreeView->setSortingEnabled(
true);
57 updateTimer =
new QTimer(
this);
59 connect(ui.observerTreeView, SIGNAL(customContextMenuRequested(
const QPoint&)),
this, SLOT(
treeView_contextMenu(
const QPoint&)));
65 ui.splitter->setSizes(sizes);
67 autoUpdateAction =
new QAction(
"Auto update", ui.observerTreeView);
69 filterExpansionTimer.setSingleShot(
true);
70 connect(&filterExpansionTimer, SIGNAL(timeout()),
this, SLOT(delayedFilterExpansion()));
77 proxyModel->setSourceModel(model);
78 ui.observerTreeView->setModel(proxyModel);
79 proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
81 QItemSelectionModel* selectionModel = ui.observerTreeView->selectionModel();
82 connect(selectionModel, SIGNAL(selectionChanged(
const QItemSelection&,
const QItemSelection&)),
this, SLOT(
treeView_selected(
const QItemSelection&,
const QItemSelection&)));
85 connect(ui.lineEditSearch, SIGNAL(textChanged(QString)), proxyModel, SLOT(setFilterFixedString(QString)));
86 connect(ui.lineEditSearch, SIGNAL(textChanged(QString)),
this, SLOT(expandFilterSelection(QString)), Qt::QueuedConnection);
96 auto selection = ui.observerTreeView->selectionModel()->selectedIndexes();
98 if (selection.size() > 0)
100 if (propertiesWidget)
102 ui.propertiesView->layout()->removeWidget(propertiesWidget);
103 propertiesWidget->deleteLater();
104 propertiesWidget = NULL;
106 auto tempWidgetPtr = model->
getPropertiesWidget(proxyModel->mapToSource(selection.at(0)), ui.propertiesView);
109 propertiesWidget = tempWidgetPtr;
110 ui.propertiesView->layout()->addWidget(propertiesWidget);
111 propertiesWidget->show();
118 if (selected.indexes().size() == 0)
123 if (propertiesWidget)
125 ui.propertiesView->layout()->removeWidget(propertiesWidget);
126 propertiesWidget->deleteLater();
127 propertiesWidget = NULL;
130 QModelIndexList
list = selected.indexes();
132 ui.propertiesView->layout()->addWidget(propertiesWidget);
133 propertiesWidget->show();
140 updateTimer->start(500);
150 QAction* action = qobject_cast<QAction*>(sender());
154 DatafieldFilterBasePtr filter;
155 if (!action->data().isNull())
157 auto filterName = action->data().toString().toStdString();
158 auto valFac =
controller->getIceManager()->getCommunicator()->getValueFactoryManager()->find(filterName);
161 ARMARX_WARNING <<
"Could not find obj factory of type " << filterName;
165 filter = DatafieldFilterBasePtr::dynamicCast(valFac->create(filterName));
174 ARMARX_ERROR <<
"Filter " << action->text().toStdString() <<
" is unknown";
178 Ui::FilterPropertiesDialog dSetup;
180 dSetup.tableWidget->setSortingEnabled(
false);
181 StringFloatDictionary props = filter->getProperties();
183 dSetup.tableWidget->setRowCount(props.size());
184 dSetup.tableWidget->setColumnCount(2);
186 for (
auto& p : props)
188 auto keyItem =
new QTableWidgetItem(p.first.c_str());
189 keyItem->setFlags(Qt::ItemIsEnabled);
190 dSetup.tableWidget->setItem(i, 0, keyItem);
191 auto valueItem =
new QTableWidgetItem(QString::number(p.second));
192 dSetup.tableWidget->setItem(i, 1, valueItem);
195 dSetup.groupBox->setTitle(action->text() +
" properties");
196 if (d.exec() == QDialog::Accepted)
199 for (
int i = 0; i < dSetup.tableWidget->rowCount(); ++i)
202 float value = dSetup.tableWidget->item(i, 1)->text().toFloat(&
ok);
205 props[dSetup.tableWidget->item(i, 0)->text().toStdString()] =
value;
209 filter->setProperties(props);
215 selectedFilterId.clear();
220 if (propertiesWidget)
222 ui.propertiesView->layout()->removeWidget(propertiesWidget);
223 propertiesWidget->deleteLater();
224 propertiesWidget = NULL;
230 QPoint globalPos = ui.observerTreeView->viewport()->mapToGlobal(point);
234 QAction* updateAction =
new QAction(
"Update", ui.observerTreeView);
236 if (autoUpdateAction->isChecked())
238 updateAction->setEnabled(
false);
241 connect(updateAction, SIGNAL(triggered()),
this, SLOT(
updateObservers()));
242 treeViewMenu.addAction(updateAction);
252 auto typeId = widget->
getVariant()->getType();
254 QMenu* filters = treeViewMenu.addMenu(
"Filters");
255 std::map<std::string, bool> filterNames;
262 for (
auto pair : facContainer->getFactories())
265 Ice::ValueFactoryPtr fac = pair.second;
272 auto obj = fac->create(pair.first);
279 DatafieldFilterBasePtr filter = DatafieldFilterBasePtr::dynamicCast(obj);
282 auto supportedTypes = filter->getSupportedTypes();
283 auto typeIt = std::find(supportedTypes.begin(), supportedTypes.end(), typeId);
284 filterNames.insert(std::make_pair(pair.first, typeIt != supportedTypes.end()));
293 for (
auto filter : filterNames)
295 const boost::regex e(
"::armarx::([a-zA-Z0-9_]+)Base");
296 boost::match_results<std::string::const_iterator> what;
297 boost::regex_search(filter.first, what, e);
301 a = filters->addAction(filter.first.c_str(),
this, SLOT(
filterSelected()));
306 std::string filteredName = what[1];
307 a = filters->addAction(filteredName.c_str(),
this, SLOT(
filterSelected()));
310 a->setEnabled(filter.second);
313 a->setToolTip(
"This filter does not support this type");
315 a->setData(filter.first.c_str());
320 QAction* selectedItem = treeViewMenu.exec(globalPos);
334 void ObserverWidget::expandFilterSelection(QString filterStr)
337 if (filterStr.length() == 0)
339 ui.observerTreeView->collapseAll();
344 filterExpansionTimer.start(500);
348 void ObserverWidget::delayedFilterExpansion()