diff --git a/src/ui/map/QGCMapToolBar.cc b/src/ui/map/QGCMapToolBar.cc index 7eed4610aed12e5fe91b4a8c26d865150ea1544d..a077c8cae0ac74923997da6e0d8e7839819a649b 100644 --- a/src/ui/map/QGCMapToolBar.cc +++ b/src/ui/map/QGCMapToolBar.cc @@ -4,8 +4,13 @@ QGCMapToolBar::QGCMapToolBar(QWidget *parent) : QWidget(parent), + ui(new Ui::QGCMapToolBar), map(NULL), - ui(new Ui::QGCMapToolBar) + optionsMenu(this), + trailPlotMenu(this), + updateTimesMenu(this), + trailSettingsGroup(new QActionGroup(this)), + updateTimesGroup(new QActionGroup(this)) { ui->setupUi(this); } @@ -30,60 +35,139 @@ 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); + 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; + + // Set exclusive items + trailSettingsGroup->setExclusive(true); + updateTimesGroup->setExclusive(true); + + + // Build up menu + trailPlotMenu.setTitle(tr("&Add trail dot every..")); + updateTimesMenu.setTitle(tr("&Limit map view update rate to..")); + + // FIXME MARK CURRENT VALUES IN MENU + + for (int i = 0; i < uavTrailTimeCount; ++i) + { + QAction* action = trailPlotMenu.addAction(tr("%1 second%2").arg(uavTrailTimeList[i]).arg((uavTrailTimeList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailTime())); + action->setData(uavTrailTimeList[i]); + action->setCheckable(true); + trailSettingsGroup->addAction(action); + } + for (int i = 0; i < uavTrailDistanceCount; ++i) + { + QAction* action = trailPlotMenu.addAction(tr("%1 meter%2").arg(uavTrailDistanceList[i]).arg((uavTrailDistanceList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailDistance())); + action->setData(uavTrailDistanceList[i]); + action->setCheckable(true); + trailSettingsGroup->addAction(action); + } + optionsMenu.addMenu(&trailPlotMenu); + + // Add update times menu + for (int i = 100; i < 5000; i+=400) + { + float time = i/1000.0f; // Convert from ms to seconds + QAction* action = updateTimesMenu.addAction(tr("%1 seconds").arg(time), this, SLOT(setUpdateInterval())); + action->setData(time); + action->setCheckable(true); + if (time == map->getUpdateRateLimit()) + { + action->blockSignals(true); + action->setChecked(true); + action->blockSignals(false); + } + updateTimesGroup->addAction(action); + } + + // If the current time is not part of the menu defaults + // still add it as new option + if (!updateTimesGroup->checkedAction()) + { + float time = map->getUpdateRateLimit(); + QAction* action = updateTimesMenu.addAction(tr("uptate every %1 seconds").arg(time), this, SLOT(setUpdateInterval())); + action->setData(time); + action->setCheckable(true); + action->setChecked(true); + updateTimesGroup->addAction(action); + } + optionsMenu.addMenu(&updateTimesMenu); + + + ui->optionsButton->setMenu(&optionsMenu); } } void QGCMapToolBar::setUAVTrailTime() { + QObject* sender = QObject::sender(); + QAction* action = qobject_cast(sender); + if (action) + { + bool ok; + int trailTime = action->data().toInt(&ok); + if (ok) + { + (map->setTrailModeTimed(trailTime)); + ui->posLabel->setText(tr("Trail mode: Every %1 second%2").arg(trailTime).arg((trailTime > 1) ? "s" : "")); + } + } } void QGCMapToolBar::setUAVTrailDistance() { + QObject* sender = QObject::sender(); + QAction* action = qobject_cast(sender); + if (action) + { + bool ok; + int trailDistance = action->data().toInt(&ok); + if (ok) + { + map->setTrailModeDistance(trailDistance); + ui->posLabel->setText(tr("Trail mode: Every %1 meter%2").arg(trailDistance).arg((trailDistance > 1) ? "s" : "")); + } + } +} + +void QGCMapToolBar::setUpdateInterval() +{ + QObject* sender = QObject::sender(); + QAction* action = qobject_cast(sender); + + if (action) + { + bool ok; + float time = action->data().toFloat(&ok); + if (ok) map->setUpdateRateLimit(time); + } } void QGCMapToolBar::tileLoadStart() { - ui->posLabel->setText(QString("Starting to load tiles..")); + ui->posLabel->setText(tr("Starting to load tiles..")); } void QGCMapToolBar::tileLoadEnd() { - ui->posLabel->setText(QString("Finished")); + ui->posLabel->setText(tr("Finished")); } void QGCMapToolBar::tileLoadProgress(int progress) { if (progress == 1) { - ui->posLabel->setText(QString("1 tile to load..")); + ui->posLabel->setText(tr("1 tile to load..")); } else if (progress > 0) { - ui->posLabel->setText(QString("%1 tiles to load..").arg(progress)); + ui->posLabel->setText(tr("%1 tiles to load..").arg(progress)); } else { @@ -94,4 +178,7 @@ void QGCMapToolBar::tileLoadProgress(int progress) QGCMapToolBar::~QGCMapToolBar() { delete ui; + delete trailSettingsGroup; + delete updateTimesGroup; + // FIXME Delete all actions } diff --git a/src/ui/map/QGCMapToolBar.h b/src/ui/map/QGCMapToolBar.h index d7d4284bd43319f19db850e9cfcf06bf69af4d0f..a7e75f220f64daf5c3a66f35a566a36d753447cb 100644 --- a/src/ui/map/QGCMapToolBar.h +++ b/src/ui/map/QGCMapToolBar.h @@ -3,6 +3,7 @@ #include #include +#include class QGCMapWidget; @@ -26,14 +27,18 @@ public slots: void tileLoadProgress(int progress); void setUAVTrailTime(); void setUAVTrailDistance(); + void setUpdateInterval(); + +private: + Ui::QGCMapToolBar *ui; protected: QGCMapWidget* map; QMenu optionsMenu; QMenu trailPlotMenu; - -private: - Ui::QGCMapToolBar *ui; + QMenu updateTimesMenu; + QActionGroup* trailSettingsGroup; + QActionGroup* updateTimesGroup; }; #endif // QGCMAPTOOLBAR_H diff --git a/src/ui/map/QGCMapToolBar.ui b/src/ui/map/QGCMapToolBar.ui index 84d7a8a615bab543a75713fb86cbae7d96356600..ccb3561d61ce048ea43f201cf810f375b1c4e9ff 100644 --- a/src/ui/map/QGCMapToolBar.ui +++ b/src/ui/map/QGCMapToolBar.ui @@ -6,14 +6,14 @@ 0 0 - 669 + 693 35 Form - + 12 @@ -70,25 +70,25 @@ - - - Options - - - - - + Qt::Horizontal - 242 + 40 20 + + + + Options + + + diff --git a/src/ui/map/QGCMapWidget.cc b/src/ui/map/QGCMapWidget.cc index 744a71fecd6704dd1cd1264b29d9e27b318f75a9..3f2f90d2ac97dac96551bb912f4fb584e9974f3a 100644 --- a/src/ui/map/QGCMapWidget.cc +++ b/src/ui/map/QGCMapWidget.cc @@ -10,7 +10,7 @@ QGCMapWidget::QGCMapWidget(QWidget *parent) : mapcontrol::OPMapWidget(parent), currWPManager(NULL), firingWaypointChange(NULL), - maxUpdateInterval(2), // 2 seconds + maxUpdateInterval(2.1), // 2 seconds followUAVEnabled(false) { // Widget is inactive until shown diff --git a/src/ui/map/QGCMapWidget.h b/src/ui/map/QGCMapWidget.h index 2b6048161b5a45823b4143e6628e4aaa281b497f..4e8ce078d13e4a1e507f946e377702712e339e3c 100644 --- a/src/ui/map/QGCMapWidget.h +++ b/src/ui/map/QGCMapWidget.h @@ -26,6 +26,8 @@ public: /** @brief Map centered on current active system */ bool getFollowUAVEnabled() { return followUAVEnabled; } + /** @brief The maximum map update rate */ + float getUpdateRateLimit() { return maxUpdateInterval; }; signals: void homePositionChanged(double latitude, double longitude, double altitude); @@ -60,6 +62,24 @@ public slots: void cacheVisibleRegion(); /** @brief Set follow mode */ void setFollowUAVEnabled(bool enabled) { followUAVEnabled = enabled; } + /** @brief Set trail to time mode and set time */ + void setTrailModeTimed(int seconds) + { + foreach(mapcontrol::UAVItem* uav, GetUAVS()) + { + uav->SetTrailTime(seconds); + uav->SetTrailType(mapcontrol::UAVTrailType::ByTimeElapsed); + } + } + /** @brief Set trail to distance mode and set time */ + void setTrailModeDistance(int meters) + { + foreach(mapcontrol::UAVItem* uav, GetUAVS()) + { + uav->SetTrailDistance(meters); + uav->SetTrailType(mapcontrol::UAVTrailType::ByDistance); + } + } void loadSettings(); void storeSettings();