37 #include "ui_uavobjectbrowser.h"
38 #include "ui_viewoptions.h"
40 #include <QStringList>
41 #include <QHBoxLayout>
42 #include <QVBoxLayout>
43 #include <QPushButton>
45 #include <QtCore/QDebug>
46 #include <QItemEditorFactory>
50 #define MAXIMUM_UPDATE_PERIOD 200
54 , updatePeriod(MAXIMUM_UPDATE_PERIOD)
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);
68 treeView->setObjectName(QString::fromUtf8(
"treeView"));
69 m_browser->verticalLayout->addWidget(treeView);
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);
84 connect(treeView, &QTreeView::collapsed,
this, &UAVObjectBrowserWidget::onTreeItemCollapsed);
85 connect(treeView, &QTreeView::expanded,
this, &UAVObjectBrowserWidget::onTreeItemExpanded);
87 connect(m_browser->le_searchField, &QLineEdit::textChanged,
this,
88 &UAVObjectBrowserWidget::searchTextChanged);
89 connect(m_browser->bn_clearSearchField, &QAbstractButton::clicked,
this,
90 &UAVObjectBrowserWidget::searchTextCleared);
93 enableUAVOBrowserButtons(
false);
96 void UAVObjectBrowserWidget::onTreeItemExpanded(QModelIndex currentProxyIndex)
98 QModelIndex currentIndex = proxyModel->mapToSource(currentProxyIndex);
117 quint16 tmpUpdatePeriod = MAXIMUM_UPDATE_PERIOD;
120 switch (accessType) {
126 tmpUpdatePeriod = std::min(mdata.gcsTelemetryUpdatePeriod, tmpUpdatePeriod);
133 switch (accessType) {
139 tmpUpdatePeriod = std::min(mdata.flightTelemetryUpdatePeriod, tmpUpdatePeriod);
144 expandedUavoItems.insert(obj->
getName(), tmpUpdatePeriod);
146 if (tmpUpdatePeriod < updatePeriod) {
147 updatePeriod = tmpUpdatePeriod;
154 void UAVObjectBrowserWidget::onTreeItemCollapsed(QModelIndex currentProxyIndex)
156 QModelIndex currentIndex = proxyModel->mapToSource(currentProxyIndex);
175 quint16 tmpUpdatePeriod = expandedUavoItems.value(obj->
getName());
176 expandedUavoItems.take(obj->
getName());
179 if (tmpUpdatePeriod == updatePeriod) {
181 updatePeriod = MAXIMUM_UPDATE_PERIOD;
182 foreach (tmpUpdatePeriod, expandedUavoItems) {
183 if (tmpUpdatePeriod < updatePeriod)
184 updatePeriod = tmpUpdatePeriod;
192 void UAVObjectBrowserWidget::updateThrottlePeriod(
UAVObject *obj)
195 if ((obj->
getObjID() & 0x01) == 1) {
199 Q_ASSERT(objManager);
207 quint16 tmpUpdatePeriod = MAXIMUM_UPDATE_PERIOD;
210 switch (accessType) {
216 tmpUpdatePeriod = std::min(mdata.gcsTelemetryUpdatePeriod, tmpUpdatePeriod);
223 switch (accessType) {
229 tmpUpdatePeriod = std::min(mdata.flightTelemetryUpdatePeriod, tmpUpdatePeriod);
234 expandedUavoItems.insert(obj->
getName(), tmpUpdatePeriod);
236 updatePeriod = MAXIMUM_UPDATE_PERIOD;
237 foreach (tmpUpdatePeriod, expandedUavoItems) {
238 if (tmpUpdatePeriod < updatePeriod)
239 updatePeriod = tmpUpdatePeriod;
257 m_viewoptions->cbMetaData->setChecked(metadata);
258 m_viewoptions->cbScientific->setChecked(scientific);
259 m_viewoptions->cbHideNotPresent->setChecked(hideNotPresent);
272 proxyModel->setSourceModel(m_model);
274 treeView->setColumnWidth(0, 300);
276 treeView->setEditTriggers(QAbstractItemView::AllEditTriggers);
277 treeView->setSelectionBehavior(QAbstractItemView::SelectItems);
278 treeView->setUniformRowHeights(
true);
281 treeView->setItemDelegate(m_delegate);
284 connect(treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this,
285 &UAVObjectBrowserWidget::toggleUAVOButtons);
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,
297 (Qt::ConnectionType)(Qt::UniqueConnection | Qt::QueuedConnection));
306 foreach (QModelIndex modelIndex, indexList) {
307 QModelIndex proxyModelindex = proxyModel->mapFromSource(modelIndex);
311 treeView->setRowHidden(proxyModelindex.row(), proxyModelindex.parent(),
312 m_viewoptions->cbHideNotPresent->isChecked()
323 refreshViewOptions();
325 foreach (QModelIndex modelIndex, metaIndexes) {
326 QModelIndex proxyModelindex = proxyModel->mapFromSource(modelIndex);
328 treeView->setRowHidden(proxyModelindex.row(), proxyModelindex.parent(), !show);
335 void UAVObjectBrowserWidget::refreshViewOptions()
338 m_viewoptions->cbScientific->isChecked(),
339 m_viewoptions->cbMetaData->isChecked(), m_viewoptions->cbHideNotPresent->isChecked());
349 refreshViewOptions();
361 void UAVObjectBrowserWidget::sendUpdate()
367 if (objItem == NULL) {
380 updateThrottlePeriod(obj);
387 void UAVObjectBrowserWidget::requestUpdate()
392 if (objItem == NULL) {
401 updateThrottlePeriod(obj);
409 ObjectTreeItem *UAVObjectBrowserWidget::findCurrentObjectTreeItem()
411 QModelIndex current = proxyModel->mapToSource(treeView->currentIndex());
435 void UAVObjectBrowserWidget::saveObject()
444 if (objItem == NULL) {
453 updateObjectPersistance(ObjectPersistence::OPERATION_SAVE, obj);
456 updateThrottlePeriod(obj);
463 void UAVObjectBrowserWidget::loadObject()
469 if (objItem == NULL) {
475 updateObjectPersistance(ObjectPersistence::OPERATION_LOAD, obj);
480 updateThrottlePeriod(obj);
486 void UAVObjectBrowserWidget::eraseObject()
491 if (objItem == NULL) {
497 updateObjectPersistance(ObjectPersistence::OPERATION_DELETE, obj);
506 void UAVObjectBrowserWidget::updateObjectPersistance(ObjectPersistence::OperationOptions op,
511 ObjectPersistence *objper =
514 ObjectPersistence::DataFields
data;
518 objper->setData(data);
529 void UAVObjectBrowserWidget::toggleUAVOButtons(
const QModelIndex ¤tProxyIndex,
530 const QModelIndex &previousIndex)
532 Q_UNUSED(previousIndex);
534 QModelIndex currentIndex = proxyModel->mapToSource(currentProxyIndex);
539 bool enableState =
true;
542 if (currentIndex == QModelIndex())
546 if (top || (data && !data->
object()))
549 enableUAVOBrowserButtons(enableState);
555 void UAVObjectBrowserWidget::viewSlot()
557 if (m_viewoptionsDialog->isVisible())
558 m_viewoptionsDialog->setVisible(
false);
560 QPoint pos = QCursor::pos();
561 pos.setX(pos.x() - m_viewoptionsDialog->width());
562 m_viewoptionsDialog->move(pos);
563 m_viewoptionsDialog->show();
571 void UAVObjectBrowserWidget::viewOptionsChangedSlot()
574 m_viewoptions->cbScientific->isChecked(),
575 m_viewoptions->cbMetaData->isChecked(), m_viewoptions->cbHideNotPresent);
579 disconnect(treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this,
580 &UAVObjectBrowserWidget::toggleUAVOButtons);
583 proxyModel->setSourceModel(m_model);
585 searchTextChanged(m_browser->le_searchField->text());
586 connect(treeView->selectionModel(), &QItemSelectionModel::currentChanged,
this,
587 &UAVObjectBrowserWidget::toggleUAVOButtons);
597 void UAVObjectBrowserWidget::enableUAVOBrowserButtons(
bool enableState)
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);
611 void UAVObjectBrowserWidget::searchTextChanged(QString searchText)
613 proxyModel->setFilterRegExp(QRegExp(searchText, Qt::CaseInsensitive, QRegExp::FixedString));
616 void UAVObjectBrowserWidget::searchTextCleared()
618 m_browser->le_searchField->clear();
621 void UAVObjectBrowserWidget::keyPressEvent(QKeyEvent *
e)
628 QWidget::keyPressEvent(e);
632 void UAVObjectBrowserWidget::keyReleaseEvent(QKeyEvent *e)
639 QWidget::keyReleaseEvent(e);
650 , m_updateTreeViewFlag(false)
653 m_updateViewTimer.start(updateTimerPeriod);
656 connect(&m_updateViewTimer, &QTimer::timeout,
this, &UAVOBrowserTreeView::onTimeout_updateView);
663 m_updateViewTimer.stop();
669 m_updateViewTimer.start(val);
682 void UAVOBrowserTreeView::onTimeout_updateView()
684 if (m_updateTreeViewFlag ==
true) {
685 QModelIndex topLeftIndex = model()->index(0, 0);
686 QModelIndex bottomRightIndex = model()->index(1, 1);
688 QTreeView::dataChanged(topLeftIndex, bottomRightIndex);
691 m_updateTreeViewFlag =
false;
701 const QModelIndex &bottomRightProxy)
703 Q_UNUSED(bottomRightProxy);
707 QModelIndex topLeftModel = proxyModel->mapToSource(topLeftProxy);
708 TreeItem *treeItemPtr =
static_cast<TreeItem *
>(topLeftModel.internalPointer());
713 if (dataObjectTreeItemPtr == NULL) {
720 m_updateTreeViewFlag =
true;
724 const QVector<int> &roles)
729 if (m_updateViewTimer.isActive()) {
732 QTreeView::dataChanged(topLeft, bottomRight);
739 : QSortFilterProxyModel(p)
756 const QModelIndex &source_parent)
const
762 QModelIndex parent = source_parent;
763 while (parent.isValid()) {
766 parent = parent.parent();
778 const QModelIndex &source_parent)
const
780 return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
784 const QModelIndex &source_parent)
const
786 QModelIndex item = sourceModel()->index(source_row, 0, source_parent);
787 if (!item.isValid()) {
793 int childCount = item.model()->rowCount(item);
797 for (
int i = 0;
i < childCount; ++
i) {
bool hasAcceptedChildren(int source_row, const QModelIndex &source_parent) const
QVector< UAVObject * > getObjectInstancesVector(const QString &name)
~UAVObjectBrowserWidget()
void setViewOptions(bool scientific, bool metadata, bool hideNotPresent)
UAVObjectBrowserWidget::setViewOptions Sets the viewing options.
static UpdateMode GetFlightTelemetryUpdateMode(const Metadata &meta)
Core plugin system that manages the plugins, their life cycle and their registered objects...
static UpdateMode GetGcsTelemetryUpdateMode(const Metadata &meta)
UAVObjectBrowserWidget(QWidget *parent=nullptr)
virtual Metadata getMetadata()=0
void doRefreshHiddenObjects()
QList< QModelIndex > getMetaDataIndexes()
TreeSortFilterProxyModel(QObject *parent)
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()
virtual bool getIsPresentOnHardware() const
void showNotPresent(bool show)
UAVObjectBrowserWidget::showNotPresent Shows or hides object not present on the hardware.
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)
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
dataChanged Reimplements QTreeView::dataChanged signal
void showMetaData(bool show)
UAVObjectBrowserWidget::showMetaData Shows UAVO metadata.
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)
void updateTimerPeriod(unsigned int val)