diff --git a/src/ui/linechart/LinechartWidget.cc b/src/ui/linechart/LinechartWidget.cc index 39f68c8f2e1e5fec2b942bbef55d895b3257805f..fd3821422101c970f3610c3cc0931226fb2bd719 100644 --- a/src/ui/linechart/LinechartWidget.cc +++ b/src/ui/linechart/LinechartWidget.cc @@ -26,7 +26,7 @@ This file is part of the PIXHAWK project * @brief Line chart plot widget * * @author Lorenz Meier - * + * @author Thomas Gubler */ #include @@ -105,6 +105,7 @@ LinechartWidget::LinechartWidget(int systemid, QWidget *parent) : QWidget(parent connect(ui.recolorButton, SIGNAL(clicked()), this, SLOT(recolor())); connect(ui.shortNameCheckBox, SIGNAL(clicked(bool)), this, SLOT(setShortNames(bool))); + connect(ui.plotFilterLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(filterCurves(const QString&))); int labelRow = curvesWidgetLayout->rowCount(); @@ -564,6 +565,7 @@ void LinechartWidget::addCurve(const QString& curve, const QString& unit) checkBox->setObjectName(curve+unit); checkBox->setToolTip(tr("Enable the curve in the graph window")); checkBox->setWhatsThis(tr("Enable the curve in the graph window")); + checkBoxes.insert(curve+unit, checkBox); curvesWidgetLayout->addWidget(checkBox, labelRow, 0); // Icon @@ -593,6 +595,7 @@ void LinechartWidget::addCurve(const QString& curve, const QString& unit) unitLabel->setText(unit); unitLabel->setToolTip(tr("Unit of ") + curve); unitLabel->setWhatsThis(tr("Unit of ") + curve); + curveUnits.insert(curve+unit, unitLabel); curvesWidgetLayout->addWidget(unitLabel, labelRow, 4); unitLabel->setVisible(ui.showUnitsCheckBox->isChecked()); connect(ui.showUnitsCheckBox, SIGNAL(clicked(bool)), unitLabel, SLOT(setVisible(bool))); @@ -691,6 +694,47 @@ void LinechartWidget::recolor() } } +void LinechartWidget::filterCurve(const QString &key, bool match) +{ + colorIcons[key]->setVisible(match); + curveNameLabels[key]->setVisible(match); + (*curveLabels)[key]->setVisible(match); + (*curveMeans)[key]->setVisible(match); + (*curveVariances)[key]->setVisible(match); + curveUnits[key]->setVisible(match); + checkBoxes[key]->setVisible(match); +} + +void LinechartWidget::filterCurves(const QString &filter) +{ + //qDebug() << "filterCurves: filter: " << filter; + + if (filter != "") + { + /* Hide Elements which do not match the filter pattern */ + QStringMatcher stringMatcher(filter, Qt::CaseInsensitive); + foreach (QString key, colorIcons.keys()) + { + if (stringMatcher.indexIn(key) < 0) + { + filterCurve(key, false); + } + else + { + filterCurve(key, true); + } + } + } + else + { + /* Show all Elements */ + foreach (QString key, colorIcons.keys()) + { + filterCurve(key, true); + } + } +} + QString LinechartWidget::getCurveName(const QString& key, bool shortEnabled) { if (shortEnabled) diff --git a/src/ui/linechart/LinechartWidget.h b/src/ui/linechart/LinechartWidget.h index 4640f2c191fa6ab77afb9adb782cc930248e906d..e7fcf7048d92a479f21298b0ff04345d6ca6d73d 100644 --- a/src/ui/linechart/LinechartWidget.h +++ b/src/ui/linechart/LinechartWidget.h @@ -26,7 +26,7 @@ This file is part of the PIXHAWK project * @brief Definition of Line chart plot widget * * @author Lorenz Meier - * + * @author Thomas Gubler */ #ifndef LINECHARTWIDGET_H #define LINECHARTWIDGET_H @@ -79,6 +79,8 @@ public slots: void setShortNames(bool enable); /** @brief Append data to the given curve. */ void appendData(int uasId, const QString& curve, const QString& unit, const QVariant& value, quint64 usec); + /** @brief Hide curves which do not match the filter pattern */ + void filterCurves(const QString &filter); void toggleLogarithmicScaling(bool toggled); void takeButtonClick(bool checked); @@ -110,6 +112,8 @@ public slots: private slots: /** Called when the user changes the time scale combobox. */ void timeScaleChanged(int index); + /** @brief Applies action on curve corresponding to key based on the bool match. I used to filter curves */ + void filterCurve(const QString &key, bool match); protected: void addCurveToList(QString curve); @@ -132,9 +136,11 @@ protected: QMap curveNames; ///< Full curve names QMap* curveMeans; ///< References to the curve means QMap* curveMedians; ///< References to the curve medians + QMap curveUnits; ///< References to the curve units QMap* curveVariances; ///< References to the curve variances QMap intData; ///< Current values for integer-valued curves QMap colorIcons; ///< Reference to color icons + QMap checkBoxes; ///< Reference to checkboxes QWidget* curvesWidget; ///< The QWidget containing the curve selection button QGridLayout* curvesWidgetLayout; ///< The layout for the curvesWidget QWidget