From 361ac1d77b991a5a19174765995515dd105c313f Mon Sep 17 00:00:00 2001 From: LM Date: Thu, 21 Jul 2011 20:06:47 +0200 Subject: [PATCH] Working on map menu, fixing plot --- src/ui/QGCDataPlot2D.cc | 53 ++++++++++++++++++++++++++++++++----- src/ui/QGCDataPlot2D.ui | 8 +++--- src/ui/map/QGCMapTool.cc | 2 ++ src/ui/map/QGCMapTool.h | 1 + src/ui/map/QGCMapToolBar.cc | 33 +++++++++++++++++++++++ src/ui/map/QGCMapToolBar.h | 5 ++++ src/ui/map/QGCMapToolBar.ui | 7 +++++ src/ui/map/QGCMapWidget.cc | 8 +----- 8 files changed, 100 insertions(+), 17 deletions(-) diff --git a/src/ui/QGCDataPlot2D.cc b/src/ui/QGCDataPlot2D.cc index 659313cae..14a4e02f1 100644 --- a/src/ui/QGCDataPlot2D.cc +++ b/src/ui/QGCDataPlot2D.cc @@ -405,8 +405,6 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil int curveNameIndex = 0; - //int xValueIndex = curveNames.indexOf(xAxisName); - QString xAxisFilter; if (xAxisName == "") { xAxisFilter = curveNames.first(); @@ -414,6 +412,36 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil xAxisFilter = xAxisName; } + // Fill y-axis renaming lookup table + // Allow the user to rename data dimensions in the plot + QMap renaming; + + QStringList yCurves = yAxisFilter.split("|", QString::SkipEmptyParts); + qDebug() << "YFILTER" << yAxisFilter; + + // Figure out the correct renaming + for (int i = 0; i < yCurves.count(); ++i) + { + qDebug() << "CURVE:" << yCurves.at(i); + if (yCurves.at(i).contains(":")) + { + QStringList parts = yCurves.at(i).split(":", QString::SkipEmptyParts); + if (parts.count() > 1) + { + // Insert renaming map + renaming.insert(parts.first(), parts.last()); + // Replace curve value with first part only + yCurves.replace(i, parts.first()); + } + } +// else +// { +// // Insert same value, not renaming anything +// renaming.insert(yCurves.at(i), yCurves.at(i)); +// } + } + + foreach(curveName, curveNames) { // Add to plot x axis selection ui->xAxis->addItem(curveName); @@ -421,14 +449,19 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil ui->xRegressionComboBox->addItem(curveName); ui->yRegressionComboBox->addItem(curveName); if (curveName != xAxisFilter) { - if ((yAxisFilter == "") || yAxisFilter.contains(curveName)) { + if ((yAxisFilter == "") || yCurves.contains(curveName)) { yValues.insert(curveName, new QVector()); xValues.insert(curveName, new QVector()); // Add separator starting with second item if (curveNameIndex > 0 && curveNameIndex < curveNames.count()) { ui->yAxis->setText(ui->yAxis->text()+"|"); } - ui->yAxis->setText(ui->yAxis->text()+curveName); + // If this curve was renamed, re-add the renaming to the text field + QString renamingText = ""; + if (renaming.contains(curveName)) renamingText = QString(":%1").arg(renaming.value(curveName)); + ui->yAxis->setText(ui->yAxis->text()+curveName+renamingText); + // Insert same value, not renaming anything + if (!renaming.contains(curveName)) renaming.insert(curveName, curveName); curveNameIndex++; } } @@ -478,7 +511,8 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil foreach(curveName, curveNames) { // Y AXIS HANDLING - if(curveName != xAxisFilter && (yAxisFilter == "" || yAxisFilter.contains(curveName))) + // Only plot non-x curver and those selected in the yAxisFilter (or all if the filter is not set) + if(curveName != xAxisFilter && (yAxisFilter == "" || yCurves.contains(curveName))) { bool oky; int curveNameIndex = curveNames.indexOf(curveName); @@ -504,7 +538,14 @@ void QGCDataPlot2D::loadCsvLog(QString file, QString xAxisName, QString yAxisFil // Add data array of each curve to the plot at once (fast) // Iterates through all x-y curve combinations for (int i = 0; i < yValues.count(); i++) { - plot->appendData(yValues.keys().at(i), xValues.values().at(i)->data(), yValues.values().at(i)->data(), xValues.values().at(i)->count()); + if (renaming.contains(yValues.keys().at(i))) + { + plot->appendData(renaming.value(yValues.keys().at(i)), xValues.values().at(i)->data(), yValues.values().at(i)->data(), xValues.values().at(i)->count()); + } + else + { + plot->appendData(yValues.keys().at(i), xValues.values().at(i)->data(), yValues.values().at(i)->data(), xValues.values().at(i)->count()); + } } plot->updateScale(); plot->setStyleText(ui->style->currentText()); diff --git a/src/ui/QGCDataPlot2D.ui b/src/ui/QGCDataPlot2D.ui index 04861aebb..1cd5288e4 100644 --- a/src/ui/QGCDataPlot2D.ui +++ b/src/ui/QGCDataPlot2D.ui @@ -6,14 +6,14 @@ 0 0 - 1073 - 308 + 1463 + 311 Form - + @@ -303,7 +303,7 @@ - 40 + 5 20 diff --git a/src/ui/map/QGCMapTool.cc b/src/ui/map/QGCMapTool.cc index f7ed1442e..ef159c69d 100644 --- a/src/ui/map/QGCMapTool.cc +++ b/src/ui/map/QGCMapTool.cc @@ -1,5 +1,7 @@ #include "QGCMapTool.h" #include "ui_QGCMapTool.h" +#include +#include QGCMapTool::QGCMapTool(QWidget *parent) : QWidget(parent), diff --git a/src/ui/map/QGCMapTool.h b/src/ui/map/QGCMapTool.h index d7d4f4c4a..784bf7862 100644 --- a/src/ui/map/QGCMapTool.h +++ b/src/ui/map/QGCMapTool.h @@ -2,6 +2,7 @@ #define QGCMAPTOOL_H #include +#include namespace Ui { class QGCMapTool; diff --git a/src/ui/map/QGCMapToolBar.cc b/src/ui/map/QGCMapToolBar.cc index 490a2cd74..f57aa2ae1 100644 --- a/src/ui/map/QGCMapToolBar.cc +++ b/src/ui/map/QGCMapToolBar.cc @@ -29,9 +29,42 @@ void QGCMapToolBar::setMap(QGCMapWidget* map) // Edit mode handling ui->editButton->hide(); + + const int uavTrailTimeList[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // seconds + const int uavTrailTimeCount = 10; + + const int uavTrailDistanceList[] = {1, 2, 5, 10, 20, 50, 100, 200, 500}; // meters + const int uavTrailDistanceCount = 9; + + optionsMenu.setParent(this); + + + // Build up menu + //trailPlotMenu(tr("Add trail dot every.."), this); + for (int i = 0; i < uavTrailTimeCount; ++i) + { + trailPlotMenu.addAction(QString("%1 second%2").arg(uavTrailTimeList[i]).arg((uavTrailTimeList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailTime())); + } + for (int i = 0; i < uavTrailDistanceCount; ++i) + { + trailPlotMenu.addAction(QString("%1 meter%2").arg(uavTrailDistanceList[i]).arg((uavTrailDistanceList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailDistance())); + } + optionsMenu.addMenu(&trailPlotMenu); + + ui->optionsButton->setMenu(&optionsMenu); } } +void QGCMapToolBar::setUAVTrailTime() +{ + +} + +void QGCMapToolBar::setUAVTrailDistance() +{ + +} + void QGCMapToolBar::tileLoadStart() { ui->posLabel->setText(QString("Starting to load tiles..")); diff --git a/src/ui/map/QGCMapToolBar.h b/src/ui/map/QGCMapToolBar.h index 8b61d776b..d7d4284bd 100644 --- a/src/ui/map/QGCMapToolBar.h +++ b/src/ui/map/QGCMapToolBar.h @@ -2,6 +2,7 @@ #define QGCMAPTOOLBAR_H #include +#include class QGCMapWidget; @@ -23,9 +24,13 @@ public slots: void tileLoadStart(); void tileLoadEnd(); void tileLoadProgress(int progress); + void setUAVTrailTime(); + void setUAVTrailDistance(); protected: QGCMapWidget* map; + QMenu optionsMenu; + QMenu trailPlotMenu; private: Ui::QGCMapToolBar *ui; diff --git a/src/ui/map/QGCMapToolBar.ui b/src/ui/map/QGCMapToolBar.ui index 38f0151fe..84d7a8a61 100644 --- a/src/ui/map/QGCMapToolBar.ui +++ b/src/ui/map/QGCMapToolBar.ui @@ -69,6 +69,13 @@ + + + + Options + + + diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index cfdccc53f..744a71fec 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -60,12 +60,6 @@ void QGCMapWidget::showEvent(QShowEvent* event) // magic_waypoint.time_seconds = 0; // magic_waypoint.hold_time_seconds = 0; - const int safe_area_radius_list[] = {5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000}; // meters - - const int uav_trail_time_list[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // seconds - - const int uav_trail_distance_list[] = {1, 2, 5, 10, 20, 50, 100, 200, 500}; // meters - SetMouseWheelZoomType(internals::MouseWheelZoomType::MousePositionWithoutCenter); // set how the mouse wheel zoom functions SetFollowMouse(true); // we want a contiuous mouse position reading @@ -74,7 +68,7 @@ void QGCMapWidget::showEvent(QShowEvent* event) //SetShowDiagnostics(true); // Not needed in flight / production mode - Home->SetSafeArea(safe_area_radius_list[0]); // set radius (meters) + Home->SetSafeArea(30); // set radius (meters) Home->SetShowSafeArea(true); // show the safe area //// UAV->SetTrailTime(uav_trail_time_list[0]); // seconds -- 2.22.0