Commit bd9e85c9 authored by Thomas Gubler's avatar Thomas Gubler

basic filter functionality

parent 8e3f46f6
......@@ -26,7 +26,7 @@ This file is part of the PIXHAWK project
* @brief Line chart plot widget
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
* @author Thomas Gubler <thomasgubler@student.ethz.ch>
*/
#include <QDebug>
......@@ -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)
......
......@@ -26,7 +26,7 @@ This file is part of the PIXHAWK project
* @brief Definition of Line chart plot widget
*
* @author Lorenz Meier <mavteam@student.ethz.ch>
*
* @author Thomas Gubler <thomasgubler@student.ethz.ch>
*/
#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<QString, QString> curveNames; ///< Full curve names
QMap<QString, QLabel*>* curveMeans; ///< References to the curve means
QMap<QString, QLabel*>* curveMedians; ///< References to the curve medians
QMap<QString, QWidget*> curveUnits; ///< References to the curve units
QMap<QString, QLabel*>* curveVariances; ///< References to the curve variances
QMap<QString, int> intData; ///< Current values for integer-valued curves
QMap<QString, QWidget*> colorIcons; ///< Reference to color icons
QMap<QString, QCheckBox*> checkBoxes; ///< Reference to checkboxes
QWidget* curvesWidget; ///< The QWidget containing the curve selection button
QGridLayout* curvesWidgetLayout; ///< The layout for the curvesWidget QWidget
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment