dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uavobjectbrowserwidget.cpp
Go to the documentation of this file.
1 
14 /*
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 3 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23  * for more details.
24  *
25  * You should have received a copy of the GNU General Public License along
26  * with this program; if not, see <http://www.gnu.org/licenses/>
27  *
28  * Additional note on redistribution: The copyright and license notices above
29  * must be maintained in each individual source file that is a derivative work
30  * of this source file; otherwise redistribution is prohibited.
31  */
32 
33 #include "uavobjectbrowserwidget.h"
34 #include "uavobjecttreemodel.h"
35 #include "browseritemdelegate.h"
36 #include "treeitem.h"
37 #include "ui_uavobjectbrowser.h"
38 #include "ui_viewoptions.h"
40 #include <QStringList>
41 #include <QHBoxLayout>
42 #include <QVBoxLayout>
43 #include <QPushButton>
44 #include <QComboBox>
45 #include <QtCore/QDebug>
46 #include <QItemEditorFactory>
48 #include <math.h>
49 
50 #define MAXIMUM_UPDATE_PERIOD 200
51 
53  : QWidget(parent)
54  , updatePeriod(MAXIMUM_UPDATE_PERIOD)
55 {
56  // Create browser and configuration GUIs
57  m_browser = new Ui_UAVObjectBrowser();
58  m_viewoptions = new Ui_viewoptions();
59  m_viewoptionsDialog = new QDialog(this);
60  m_viewoptions->setupUi(m_viewoptionsDialog);
61  m_browser->setupUi(this);
62 
63  // Create data model
64  m_model = new UAVObjectTreeModel(this);
65 
66  // Create tree view and add to layout
67  treeView = new UAVOBrowserTreeView(MAXIMUM_UPDATE_PERIOD);
68  treeView->setObjectName(QString::fromUtf8("treeView"));
69  m_browser->verticalLayout->addWidget(treeView);
70 
71  connect(m_browser->saveSDButton, &QAbstractButton::clicked, this,
72  &UAVObjectBrowserWidget::saveObject);
73  connect(m_browser->readSDButton, &QAbstractButton::clicked, this,
74  &UAVObjectBrowserWidget::loadObject);
75  connect(m_browser->eraseSDButton, &QAbstractButton::clicked, this,
76  &UAVObjectBrowserWidget::eraseObject);
77  connect(m_browser->sendButton, &QAbstractButton::clicked, this,
78  &UAVObjectBrowserWidget::sendUpdate);
79  connect(m_browser->requestButton, &QAbstractButton::clicked, this,
80  &UAVObjectBrowserWidget::requestUpdate);
81  connect(m_browser->viewSettingsButton, &QAbstractButton::clicked, this,
82  &UAVObjectBrowserWidget::viewSlot);
83 
84  connect(treeView, &QTreeView::collapsed, this, &UAVObjectBrowserWidget::onTreeItemCollapsed);
85  connect(treeView, &QTreeView::expanded, this, &UAVObjectBrowserWidget::onTreeItemExpanded);
86 
87  connect(m_browser->le_searchField, &QLineEdit::textChanged, this,
88  &UAVObjectBrowserWidget::searchTextChanged);
89  connect(m_browser->bn_clearSearchField, &QAbstractButton::clicked, this,
90  &UAVObjectBrowserWidget::searchTextCleared);
91 
92  // Set browser buttons to disabled
93  enableUAVOBrowserButtons(false);
94 }
95 
96 void UAVObjectBrowserWidget::onTreeItemExpanded(QModelIndex currentProxyIndex)
97 {
98  QModelIndex currentIndex = proxyModel->mapToSource(currentProxyIndex);
99  TreeItem *item = static_cast<TreeItem *>(currentIndex.internalPointer());
100  TopTreeItem *top = dynamic_cast<TopTreeItem *>(item->parent());
101 
102  // Check if current tree index is the child of the top tree item
103  if (top) {
104  ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem *>(item);
105  // If the cast succeeds, then this is a UAVO
106  if (objItem) {
107  UAVObject *obj = objItem->object();
108  // Check for multiple instance UAVO
109  if (!obj) {
110  objItem = dynamic_cast<ObjectTreeItem *>(item->getChild(0));
111  obj = objItem->object();
112  }
113  Q_ASSERT(obj);
114  UAVObject::Metadata mdata = obj->getMetadata();
115 
116  // Determine fastest update
117  quint16 tmpUpdatePeriod = MAXIMUM_UPDATE_PERIOD;
118  int accessType = UAVObject::GetGcsTelemetryUpdateMode(mdata);
119  if (accessType != UAVObject::UPDATEMODE_MANUAL) {
120  switch (accessType) {
122  tmpUpdatePeriod = 0;
123  break;
126  tmpUpdatePeriod = std::min(mdata.gcsTelemetryUpdatePeriod, tmpUpdatePeriod);
127  break;
128  }
129  }
130 
131  accessType = UAVObject::GetFlightTelemetryUpdateMode(mdata);
132  if (accessType != UAVObject::UPDATEMODE_MANUAL) {
133  switch (accessType) {
135  tmpUpdatePeriod = 0;
136  break;
139  tmpUpdatePeriod = std::min(mdata.flightTelemetryUpdatePeriod, tmpUpdatePeriod);
140  break;
141  }
142  }
143 
144  expandedUavoItems.insert(obj->getName(), tmpUpdatePeriod);
145 
146  if (tmpUpdatePeriod < updatePeriod) {
147  updatePeriod = tmpUpdatePeriod;
148  treeView->updateTimerPeriod(updatePeriod);
149  }
150  }
151  }
152 }
153 
154 void UAVObjectBrowserWidget::onTreeItemCollapsed(QModelIndex currentProxyIndex)
155 {
156  QModelIndex currentIndex = proxyModel->mapToSource(currentProxyIndex);
157  TreeItem *item = static_cast<TreeItem *>(currentIndex.internalPointer());
158  TopTreeItem *top = dynamic_cast<TopTreeItem *>(item->parent());
159 
160  // Check if current tree index is the child of the top tree item
161  if (top) {
162  ObjectTreeItem *objItem = dynamic_cast<ObjectTreeItem *>(item);
163  // If the cast succeeds, then this is a UAVO
164  if (objItem) {
165  UAVObject *obj = objItem->object();
166 
167  // Check for multiple instance UAVO
168  if (!obj) {
169  objItem = dynamic_cast<ObjectTreeItem *>(item->getChild(0));
170  obj = objItem->object();
171  }
172  Q_ASSERT(obj);
173 
174  // Remove the UAVO, getting its stored value first.
175  quint16 tmpUpdatePeriod = expandedUavoItems.value(obj->getName());
176  expandedUavoItems.take(obj->getName());
177 
178  // Check if this was the fastest UAVO
179  if (tmpUpdatePeriod == updatePeriod) {
180  // If so, search for the new fastest UAVO
181  updatePeriod = MAXIMUM_UPDATE_PERIOD;
182  foreach (tmpUpdatePeriod, expandedUavoItems) {
183  if (tmpUpdatePeriod < updatePeriod)
184  updatePeriod = tmpUpdatePeriod;
185  }
186  treeView->updateTimerPeriod(updatePeriod);
187  }
188  }
189  }
190 }
191 
192 void UAVObjectBrowserWidget::updateThrottlePeriod(UAVObject *obj)
193 {
194  // Test if this is a metadata object. A UAVO's metadata's object ID is the UAVO's object ID + 1
195  if ((obj->getObjID() & 0x01) == 1) {
196  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
197  Q_ASSERT(pm);
198  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
199  Q_ASSERT(objManager);
200  QVector<UAVObject *> list = objManager->getObjectInstancesVector(obj->getObjID() - 1);
201  obj = list.at(0);
202  }
203 
204  UAVObject::Metadata mdata = obj->getMetadata();
205 
206  // Determine fastest update
207  quint16 tmpUpdatePeriod = MAXIMUM_UPDATE_PERIOD;
208  int accessType = UAVObject::GetGcsTelemetryUpdateMode(mdata);
209  if (accessType != UAVObject::UPDATEMODE_MANUAL) {
210  switch (accessType) {
212  tmpUpdatePeriod = 0;
213  break;
216  tmpUpdatePeriod = std::min(mdata.gcsTelemetryUpdatePeriod, tmpUpdatePeriod);
217  break;
218  }
219  }
220 
221  accessType = UAVObject::GetFlightTelemetryUpdateMode(mdata);
222  if (accessType != UAVObject::UPDATEMODE_MANUAL) {
223  switch (accessType) {
225  tmpUpdatePeriod = 0;
226  break;
229  tmpUpdatePeriod = std::min(mdata.flightTelemetryUpdatePeriod, tmpUpdatePeriod);
230  break;
231  }
232  }
233 
234  expandedUavoItems.insert(obj->getName(), tmpUpdatePeriod);
235 
236  updatePeriod = MAXIMUM_UPDATE_PERIOD;
237  foreach (tmpUpdatePeriod, expandedUavoItems) {
238  if (tmpUpdatePeriod < updatePeriod)
239  updatePeriod = tmpUpdatePeriod;
240  }
241  treeView->updateTimerPeriod(updatePeriod);
242 }
243 
245 {
246  delete m_browser;
247 }
248 
254 void UAVObjectBrowserWidget::setViewOptions(bool scientific, bool metadata,
255  bool hideNotPresent)
256 {
257  m_viewoptions->cbMetaData->setChecked(metadata);
258  m_viewoptions->cbScientific->setChecked(scientific);
259  m_viewoptions->cbHideNotPresent->setChecked(hideNotPresent);
260 }
261 
267 {
268  m_model->initializeModel(m_viewoptions->cbScientific->isChecked());
269 
270  // Create and configure the proxy model
271  proxyModel = new TreeSortFilterProxyModel(this);
272  proxyModel->setSourceModel(m_model);
273  treeView->setModel(proxyModel);
274  treeView->setColumnWidth(0, 300);
275 
276  treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
277  treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
278  treeView->setUniformRowHeights(true);
279 
280  BrowserItemDelegate *m_delegate = new BrowserItemDelegate(proxyModel);
281  treeView->setItemDelegate(m_delegate);
282 
283  // Connect signals
284  connect(treeView->selectionModel(), &QItemSelectionModel::currentChanged, this,
285  &UAVObjectBrowserWidget::toggleUAVOButtons);
286 
287  showMetaData(m_viewoptions->cbMetaData->isChecked());
289  connect(m_viewoptions->cbScientific, &QAbstractButton::toggled, this,
290  &UAVObjectBrowserWidget::viewOptionsChangedSlot);
291  connect(m_viewoptions->cbHideNotPresent, &QAbstractButton::toggled, this,
293  connect(m_viewoptions->cbMetaData, &QAbstractButton::toggled, this,
295  connect(m_model, &UAVObjectTreeModel::presentOnHardwareChanged, this,
297  (Qt::ConnectionType)(Qt::UniqueConnection | Qt::QueuedConnection));
298 }
299 
304 {
305  QList<QModelIndex> indexList = m_model->getDataObjectIndexes();
306  foreach (QModelIndex modelIndex, indexList) {
307  QModelIndex proxyModelindex = proxyModel->mapFromSource(modelIndex);
308 
309  TreeItem *item = static_cast<TreeItem *>(modelIndex.internalPointer());
310  if (item)
311  treeView->setRowHidden(proxyModelindex.row(), proxyModelindex.parent(),
312  m_viewoptions->cbHideNotPresent->isChecked()
313  && !item->getIsPresentOnHardware());
314  }
315 }
316 
322 {
323  refreshViewOptions();
324  QList<QModelIndex> metaIndexes = m_model->getMetaDataIndexes();
325  foreach (QModelIndex modelIndex, metaIndexes) {
326  QModelIndex proxyModelindex = proxyModel->mapFromSource(modelIndex);
327 
328  treeView->setRowHidden(proxyModelindex.row(), proxyModelindex.parent(), !show);
329  }
330 }
331 
335 void UAVObjectBrowserWidget::refreshViewOptions()
336 {
337  emit viewOptionsChanged(
338  m_viewoptions->cbScientific->isChecked(),
339  m_viewoptions->cbMetaData->isChecked(), m_viewoptions->cbHideNotPresent->isChecked());
340 }
341 
347 {
348  Q_UNUSED(show);
349  refreshViewOptions();
351 }
352 
354 {
356 }
357 
361 void UAVObjectBrowserWidget::sendUpdate()
362 {
363  this->setFocus();
364  ObjectTreeItem *objItem = findCurrentObjectTreeItem();
365 
366  // This occurs when the selected item is not inside a UAVObject
367  if (objItem == NULL) {
368  return;
369  }
370 
371  UAVDataObject *dataObj = qobject_cast<UAVDataObject *>(objItem->object());
372  if (dataObj && dataObj->isSettings())
373  objItem->setUpdatedOnly(true);
374  objItem->apply();
375  UAVObject *obj = objItem->object();
376  Q_ASSERT(obj);
377  obj->updated();
378 
379  // Search for the new fastest UAVO
380  updateThrottlePeriod(obj);
381 }
382 
387 void UAVObjectBrowserWidget::requestUpdate()
388 {
389  ObjectTreeItem *objItem = findCurrentObjectTreeItem();
390 
391  // This occurs when the selected item is not inside a UAVObject
392  if (objItem == NULL) {
393  return;
394  }
395 
396  UAVObject *obj = objItem->object();
397  Q_ASSERT(obj);
398  obj->requestUpdate();
399 
400  // Search for the new fastest UAVO
401  updateThrottlePeriod(obj);
402 }
403 
409 ObjectTreeItem *UAVObjectBrowserWidget::findCurrentObjectTreeItem()
410 {
411  QModelIndex current = proxyModel->mapToSource(treeView->currentIndex());
412  TreeItem *item = static_cast<TreeItem *>(current.internalPointer());
413  ObjectTreeItem *objItem = nullptr;
414 
415  // Recursively iterate over child branches until the parent UAVO branch is found
416  while (item) {
417  // Attempt a dynamic cast
418  objItem = dynamic_cast<ObjectTreeItem *>(item);
419 
420  // If the cast succeeds, then this is a UAVO or UAVO metada. Stop the while loop.
421  if (objItem)
422  break;
423 
424  // If it fails, then set item equal to the parent branch, and try again.
425  item = item->parent();
426  }
427 
428  return objItem;
429 }
430 
435 void UAVObjectBrowserWidget::saveObject()
436 {
437  this->setFocus();
438  // Send update so that the latest value is saved
439  sendUpdate();
440  // Save object
441  ObjectTreeItem *objItem = findCurrentObjectTreeItem();
442 
443  // This occurs when the selected item is not inside a UAVObject
444  if (objItem == NULL) {
445  return;
446  }
447 
448  UAVDataObject *dataObj = qobject_cast<UAVDataObject *>(objItem->object());
449  if (dataObj && dataObj->isSettings())
450  objItem->setUpdatedOnly(false);
451  UAVObject *obj = objItem->object();
452  Q_ASSERT(obj);
453  updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
454 
455  // Search for the new fastest UAVO
456  updateThrottlePeriod(obj);
457 }
458 
463 void UAVObjectBrowserWidget::loadObject()
464 {
465  // Load object
466  ObjectTreeItem *objItem = findCurrentObjectTreeItem();
467 
468  // This occurs when the selected item is not inside a UAVObject
469  if (objItem == NULL) {
470  return;
471  }
472 
473  UAVObject *obj = objItem->object();
474  Q_ASSERT(obj);
475  updateObjectPersistance(ObjectPersistence::OPERATION_LOAD, obj);
476  // Retrieve object so that latest value is displayed
477  requestUpdate();
478 
479  // Search for the new fastest UAVO
480  updateThrottlePeriod(obj);
481 }
482 
486 void UAVObjectBrowserWidget::eraseObject()
487 {
488  ObjectTreeItem *objItem = findCurrentObjectTreeItem();
489 
490  // This occurs when the selected item is not inside a UAVObject
491  if (objItem == NULL) {
492  return;
493  }
494 
495  UAVObject *obj = objItem->object();
496  Q_ASSERT(obj);
497  updateObjectPersistance(ObjectPersistence::OPERATION_DELETE, obj);
498 }
499 
506 void UAVObjectBrowserWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op,
507  UAVObject *obj)
508 {
509  ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
510  UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
511  ObjectPersistence *objper =
512  dynamic_cast<ObjectPersistence *>(objManager->getObject(ObjectPersistence::NAME));
513  if (obj != NULL) {
514  ObjectPersistence::DataFields data;
515  data.Operation = op;
516  data.ObjectID = obj->getObjID();
517  data.InstanceID = obj->getInstID();
518  objper->setData(data);
519  objper->updated();
520  }
521 }
522 
529 void UAVObjectBrowserWidget::toggleUAVOButtons(const QModelIndex &currentProxyIndex,
530  const QModelIndex &previousIndex)
531 {
532  Q_UNUSED(previousIndex);
533 
534  QModelIndex currentIndex = proxyModel->mapToSource(currentProxyIndex);
535  TreeItem *item = static_cast<TreeItem *>(currentIndex.internalPointer());
536  TopTreeItem *top = dynamic_cast<TopTreeItem *>(item);
537  ObjectTreeItem *data = dynamic_cast<ObjectTreeItem *>(item);
538 
539  bool enableState = true;
540 
541  // Check if current index refers to an empty index
542  if (currentIndex == QModelIndex())
543  enableState = false;
544 
545  // Check if current tree index is the top tree item
546  if (top || (data && !data->object()))
547  enableState = false;
548 
549  enableUAVOBrowserButtons(enableState);
550 }
551 
555 void UAVObjectBrowserWidget::viewSlot()
556 {
557  if (m_viewoptionsDialog->isVisible())
558  m_viewoptionsDialog->setVisible(false);
559  else {
560  QPoint pos = QCursor::pos();
561  pos.setX(pos.x() - m_viewoptionsDialog->width());
562  m_viewoptionsDialog->move(pos);
563  m_viewoptionsDialog->show();
564  }
565 }
566 
571 void UAVObjectBrowserWidget::viewOptionsChangedSlot()
572 {
573  emit viewOptionsChanged(
574  m_viewoptions->cbScientific->isChecked(),
575  m_viewoptions->cbMetaData->isChecked(), m_viewoptions->cbHideNotPresent);
576  m_model->initializeModel(m_viewoptions->cbScientific->isChecked());
577 
578  // Reset proxy model
579  disconnect(treeView->selectionModel(), &QItemSelectionModel::currentChanged, this,
580  &UAVObjectBrowserWidget::toggleUAVOButtons);
581  delete proxyModel;
582  proxyModel = new TreeSortFilterProxyModel(this);
583  proxyModel->setSourceModel(m_model);
584  treeView->setModel(proxyModel);
585  searchTextChanged(m_browser->le_searchField->text());
586  connect(treeView->selectionModel(), &QItemSelectionModel::currentChanged, this,
587  &UAVObjectBrowserWidget::toggleUAVOButtons);
588 
589  showMetaData(m_viewoptions->cbMetaData->isChecked());
591 }
592 
597 void UAVObjectBrowserWidget::enableUAVOBrowserButtons(bool enableState)
598 {
599  // temporary hack until session management is fixed
600  enableState = true;
601  m_browser->sendButton->setEnabled(enableState);
602  m_browser->requestButton->setEnabled(enableState);
603  m_browser->saveSDButton->setEnabled(enableState);
604  m_browser->readSDButton->setEnabled(enableState);
605  m_browser->eraseSDButton->setEnabled(enableState);
606 }
607 
611 void UAVObjectBrowserWidget::searchTextChanged(QString searchText)
612 {
613  proxyModel->setFilterRegExp(QRegExp(searchText, Qt::CaseInsensitive, QRegExp::FixedString));
614 }
615 
616 void UAVObjectBrowserWidget::searchTextCleared()
617 {
618  m_browser->le_searchField->clear();
619 }
620 
621 void UAVObjectBrowserWidget::keyPressEvent(QKeyEvent *e)
622 {
623  switch (e->key()) {
624  case Qt::Key_Escape:
625  searchTextCleared();
626  Q_FALLTHROUGH();
627  default:
628  QWidget::keyPressEvent(e);
629  }
630 }
631 
632 void UAVObjectBrowserWidget::keyReleaseEvent(QKeyEvent *e)
633 {
634  switch (e->key()) {
635  case Qt::Key_Escape:
636  searchTextCleared();
637  Q_FALLTHROUGH();
638  default:
639  QWidget::keyReleaseEvent(e);
640  }
641 }
642 
643 //============================
644 
648 UAVOBrowserTreeView::UAVOBrowserTreeView(unsigned int updateTimerPeriod)
649  : QTreeView()
650  , m_updateTreeViewFlag(false)
651 {
652  // Start timer at 100ms
653  m_updateViewTimer.start(updateTimerPeriod);
654 
655  // Connect the timer
656  connect(&m_updateViewTimer, &QTimer::timeout, this, &UAVOBrowserTreeView::onTimeout_updateView);
657 }
658 
660 {
661  if (val == 0) {
662  // If val == 0, disable throttling by stopping the timer.
663  m_updateViewTimer.stop();
664  } else {
665  // If the UAVO has a very fast data rate, then don't go the full speed.
666  if (val < 125) {
667  val = 125; // Don't try to draw the browser faster than 8Hz.
668  }
669  m_updateViewTimer.start(val);
670  }
671 }
672 
682 void UAVOBrowserTreeView::onTimeout_updateView()
683 {
684  if (m_updateTreeViewFlag == true) {
685  QModelIndex topLeftIndex = model()->index(0, 0);
686  QModelIndex bottomRightIndex = model()->index(1, 1);
687 
688  QTreeView::dataChanged(topLeftIndex, bottomRightIndex);
689  }
690 
691  m_updateTreeViewFlag = false;
692 }
693 
700 void UAVOBrowserTreeView::updateView(const QModelIndex &topLeftProxy,
701  const QModelIndex &bottomRightProxy)
702 {
703  Q_UNUSED(bottomRightProxy);
704 
705  // First static_cast from *void to a tree item pointer. This is safe because we know all the
706  // indices are tree items
707  QModelIndex topLeftModel = proxyModel->mapToSource(topLeftProxy);
708  TreeItem *treeItemPtr = static_cast<TreeItem *>(topLeftModel.internalPointer());
709 
710  // Second, do a dynamic_cast in order to detect if this tree item is a data object
711  DataObjectTreeItem *dataObjectTreeItemPtr = dynamic_cast<DataObjectTreeItem *>(treeItemPtr);
712 
713  if (dataObjectTreeItemPtr == NULL) {
714  // Do nothing. These QModelIndices are generated by the highlight manager for individual
715  // UAVO fields, which are both updated when updating that UAVO's branch of the settings or
716  // dynamic data tree.
717  return;
718  }
719 
720  m_updateTreeViewFlag = true;
721 }
722 
723 void UAVOBrowserTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
724  const QVector<int> &roles)
725 {
726  Q_UNUSED(roles);
727 
728  // If the timer is active, then throttle updates...
729  if (m_updateViewTimer.isActive()) {
730  updateView(topLeft, bottomRight);
731  } else { // ... otherwise pass them directly on to the treeview.
732  QTreeView::dataChanged(topLeft, bottomRight);
733  }
734 }
735 
736 //============================
737 
739  : QSortFilterProxyModel(p)
740 {
741  Q_ASSERT(p);
742 }
743 
756  const QModelIndex &source_parent) const
757 {
758  if (filterAcceptsRowItself(source_row, source_parent))
759  return true;
760 
761  // accept if any of the parents is accepted on it's own merits
762  QModelIndex parent = source_parent;
763  while (parent.isValid()) {
764  if (filterAcceptsRowItself(parent.row(), parent.parent()))
765  return true;
766  parent = parent.parent();
767  }
768 
769  // accept if any of the children is accepted on it's own merits
770  if (hasAcceptedChildren(source_row, source_parent)) {
771  return true;
772  }
773 
774  return false;
775 }
776 
778  const QModelIndex &source_parent) const
779 {
780  return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
781 }
782 
784  const QModelIndex &source_parent) const
785 {
786  QModelIndex item = sourceModel()->index(source_row, 0, source_parent);
787  if (!item.isValid()) {
788  // qDebug() << "item invalid" << source_parent << source_row;
789  return false;
790  }
791 
792  // check if there are children
793  int childCount = item.model()->rowCount(item);
794  if (childCount == 0)
795  return false;
796 
797  for (int i = 0; i < childCount; ++i) {
798  if (filterAcceptsRowItself(i, item))
799  return true;
800  // recursive call -> NOTICE that this is depth-first searching, you're probably better off
801  // with breadth first search...
802  if (hasAcceptedChildren(i, item))
803  return true;
804  }
805 
806  return false;
807 }
bool hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const
QVector< UAVObject * > getObjectInstancesVector(const QString &name)
void requestUpdate()
Definition: uavobject.cpp:163
void setViewOptions(bool scientific, bool metadata, bool hideNotPresent)
UAVObjectBrowserWidget::setViewOptions Sets the viewing options.
static UpdateMode GetFlightTelemetryUpdateMode(const Metadata &meta)
Definition: uavobject.cpp:457
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
static UpdateMode GetGcsTelemetryUpdateMode(const Metadata &meta)
Definition: uavobject.cpp:479
for i
Definition: OPPlots.m:140
UAVObject * object()
Definition: treeitem.h:271
TreeItem * parent()
Definition: treeitem.h:132
UAVObjectBrowserWidget(QWidget *parent=nullptr)
quint32 getInstID()
Definition: uavobject.cpp:115
DataFields data
virtual void apply()
Definition: treeitem.cpp:184
virtual Metadata getMetadata()=0
QList< QModelIndex > getMetaDataIndexes()
void initialize()
Initializes the model and makes the necessary signal/slot connections.
void updateView(const QModelIndex &topLeft, const QModelIndex &bottomRight)
UAVOBrowserTreeView::updateView Determines if a view updates lies outside the range of updates queued...
QList< QModelIndex > getDataObjectIndexes()
void updated()
Definition: uavobject.cpp:179
virtual bool getIsPresentOnHardware() const
Definition: treeitem.h:143
quint32 getObjID()
Definition: uavobject.cpp:107
void showNotPresent(bool show)
UAVObjectBrowserWidget::showNotPresent Shows or hides object not present on the hardware.
() NAME()
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
TreeSortFilterProxyModel::filterAcceptsRow Taken from http://qt-project.org/forums/viewthread/7782. This proxy model will accept rows:
bool filterAcceptsRowItself(int source_row, const QModelIndex &source_parent) const
virtual void setModel(QAbstractItemModel *model)
TreeItem * getChild(int index)
Definition: treeitem.cpp:145
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
dataChanged Reimplements QTreeView::dataChanged signal
QString getName()
Definition: uavobject.cpp:131
void showMetaData(bool show)
UAVObjectBrowserWidget::showMetaData Shows UAVO metadata.
Definition: icore.h:39
void refreshHiddenObjects()
Refreshes the hidden object display.
void initializeModel(bool useScientificFloatNotation=true)
UAVOBrowserTreeView(unsigned int updateTimerPeriod)
UAVOBrowserTreeView::UAVOBrowserTreeView Constructor for reimplementation of QTreeView.
UAVObject * getObject(const QString &name, quint32 instId=0)
void presentOnHardwareChanged()
void viewOptionsChanged(bool scientific, bool metadata, bool hideNotPresent)
void setUpdatedOnly(bool updated)
Definition: treeitem.cpp:209
void updateTimerPeriod(unsigned int val)
e
Definition: OPPlots.m:99