Commit 3cc4b36a authored by Don Gagne's avatar Don Gagne

QMenu doesn't like being embedded in class

Switched to new. I’ve seen this before with other Qt classes and have
had to change the usage in the same way.
parent a218daec
...@@ -4,41 +4,41 @@ ...@@ -4,41 +4,41 @@
QGCMapToolBar::QGCMapToolBar(QWidget *parent) : QGCMapToolBar::QGCMapToolBar(QWidget *parent) :
QWidget(parent), QWidget(parent),
ui(new Ui::QGCMapToolBar), _ui(new Ui::QGCMapToolBar),
map(NULL), _map(NULL),
optionsMenu(this), _optionsMenu(new QMenu(this)),
trailPlotMenu(this), _trailPlotMenu(new QMenu(this)),
updateTimesMenu(this), _updateTimesMenu(new QMenu(this)),
mapTypesMenu(this), _mapTypesMenu(new QMenu(this)),
trailSettingsGroup(new QActionGroup(this)), _trailSettingsGroup(new QActionGroup(this)),
updateTimesGroup(new QActionGroup(this)), _updateTimesGroup(new QActionGroup(this)),
mapTypesGroup(new QActionGroup(this)), _mapTypesGroup(new QActionGroup(this)),
statusMaxLen(15) _statusMaxLen(15)
{ {
ui->setupUi(this); _ui->setupUi(this);
} }
void QGCMapToolBar::setMap(QGCMapWidget* map) void QGCMapToolBar::setMap(QGCMapWidget* map)
{ {
this->map = map; _map = map;
if (map) if (_map)
{ {
connect(ui->goToButton, SIGNAL(clicked()), map, SLOT(showGoToDialog())); connect(_ui->goToButton, SIGNAL(clicked()), _map, SLOT(showGoToDialog()));
connect(ui->goHomeButton, SIGNAL(clicked()), map, SLOT(goHome())); connect(_ui->goHomeButton, SIGNAL(clicked()), _map, SLOT(goHome()));
connect(ui->lastPosButton, SIGNAL(clicked()), map, SLOT(loadSettings())); connect(_ui->lastPosButton, SIGNAL(clicked()), _map, SLOT(loadSettings()));
connect(ui->clearTrailsButton, SIGNAL(clicked()), map, SLOT(deleteTrails())); connect(_ui->clearTrailsButton, SIGNAL(clicked()), _map, SLOT(deleteTrails()));
connect(ui->lockCheckBox, SIGNAL(clicked(bool)), map, SLOT(setZoomBlocked(bool))); connect(_ui->lockCheckBox, SIGNAL(clicked(bool)), _map, SLOT(setZoomBlocked(bool)));
connect(map, SIGNAL(OnTileLoadStart()), this, SLOT(tileLoadStart())); connect(_map, SIGNAL(OnTileLoadStart()), this, SLOT(tileLoadStart()));
connect(map, SIGNAL(OnTileLoadComplete()), this, SLOT(tileLoadEnd())); connect(_map, SIGNAL(OnTileLoadComplete()), this, SLOT(tileLoadEnd()));
connect(map, SIGNAL(OnTilesStillToLoad(int)), this, SLOT(tileLoadProgress(int))); connect(_map, SIGNAL(OnTilesStillToLoad(int)), this, SLOT(tileLoadProgress(int)));
connect(ui->ripMapButton, SIGNAL(clicked()), map, SLOT(cacheVisibleRegion())); connect(_ui->ripMapButton, SIGNAL(clicked()), _map, SLOT(cacheVisibleRegion()));
ui->followCheckBox->setChecked(map->getFollowUAVEnabled()); _ui->followCheckBox->setChecked(_map->getFollowUAVEnabled());
connect(ui->followCheckBox, SIGNAL(clicked(bool)), map, SLOT(setFollowUAVEnabled(bool))); connect(_ui->followCheckBox, SIGNAL(clicked(bool)), _map, SLOT(setFollowUAVEnabled(bool)));
// Edit mode handling // Edit mode handling
ui->editButton->hide(); _ui->editButton->hide();
const int uavTrailTimeList[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // seconds const int uavTrailTimeList[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // seconds
const int uavTrailTimeCount = 10; const int uavTrailTimeCount = 10;
...@@ -47,58 +47,58 @@ void QGCMapToolBar::setMap(QGCMapWidget* map) ...@@ -47,58 +47,58 @@ void QGCMapToolBar::setMap(QGCMapWidget* map)
const int uavTrailDistanceCount = 9; const int uavTrailDistanceCount = 9;
// Set exclusive items // Set exclusive items
trailSettingsGroup->setExclusive(true); _trailSettingsGroup->setExclusive(true);
updateTimesGroup->setExclusive(true); _updateTimesGroup->setExclusive(true);
mapTypesGroup->setExclusive(true); _mapTypesGroup->setExclusive(true);
// Build up menu // Build up menu
trailPlotMenu.setTitle(tr("&Add trail dot every..")); _trailPlotMenu->setTitle(tr("&Add trail dot every.."));
updateTimesMenu.setTitle(tr("&Limit map view update rate to..")); _updateTimesMenu->setTitle(tr("&Limit map view update rate to.."));
mapTypesMenu.setTitle(tr("&Map type")); _mapTypesMenu->setTitle(tr("&Map type"));
//setup the mapTypesMenu //setup the mapTypesMenu
QAction* action; QAction* action;
action = mapTypesMenu.addAction(tr("Bing Hybrid"),this,SLOT(setMapType())); action = _mapTypesMenu->addAction(tr("Bing Hybrid"),this,SLOT(setMapType()));
action->setData(MapType::BingHybrid); action->setData(MapType::BingHybrid);
action->setCheckable(true); action->setCheckable(true);
#ifdef MAP_DEFAULT_TYPE_BING #ifdef MAP_DEFAULT_TYPE_BING
action->setChecked(true); action->setChecked(true);
#endif #endif
mapTypesGroup->addAction(action); _mapTypesGroup->addAction(action);
action = mapTypesMenu.addAction(tr("Google Hybrid"),this,SLOT(setMapType())); action = _mapTypesMenu->addAction(tr("Google Hybrid"),this,SLOT(setMapType()));
action->setData(MapType::GoogleHybrid); action->setData(MapType::GoogleHybrid);
action->setCheckable(true); action->setCheckable(true);
#ifdef MAP_DEFAULT_TYPE_GOOGLE #ifdef MAP_DEFAULT_TYPE_GOOGLE
action->setChecked(true); action->setChecked(true);
#endif #endif
mapTypesGroup->addAction(action); _mapTypesGroup->addAction(action);
action = mapTypesMenu.addAction(tr("OpenStreetMap"),this,SLOT(setMapType())); action = _mapTypesMenu->addAction(tr("OpenStreetMap"),this,SLOT(setMapType()));
action->setData(MapType::OpenStreetMap); action->setData(MapType::OpenStreetMap);
action->setCheckable(true); action->setCheckable(true);
#ifdef MAP_DEFAULT_TYPE_OSM #ifdef MAP_DEFAULT_TYPE_OSM
action->setChecked(true); action->setChecked(true);
#endif #endif
mapTypesGroup->addAction(action); _mapTypesGroup->addAction(action);
optionsMenu.addMenu(&mapTypesMenu); _optionsMenu->addMenu(_mapTypesMenu);
// FIXME MARK CURRENT VALUES IN MENU // FIXME MARK CURRENT VALUES IN MENU
QAction *defaultTrailAction = trailPlotMenu.addAction(tr("No trail"), this, SLOT(setUAVTrailTime())); QAction *defaultTrailAction = _trailPlotMenu->addAction(tr("No trail"), this, SLOT(setUAVTrailTime()));
defaultTrailAction->setData(-1); defaultTrailAction->setData(-1);
defaultTrailAction->setCheckable(true); defaultTrailAction->setCheckable(true);
trailSettingsGroup->addAction(defaultTrailAction); _trailSettingsGroup->addAction(defaultTrailAction);
for (int i = 0; i < uavTrailTimeCount; ++i) for (int i = 0; i < uavTrailTimeCount; ++i)
{ {
action = trailPlotMenu.addAction(tr("%1 second%2").arg(uavTrailTimeList[i]).arg((uavTrailTimeList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailTime())); action = _trailPlotMenu->addAction(tr("%1 second%2").arg(uavTrailTimeList[i]).arg((uavTrailTimeList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailTime()));
action->setData(uavTrailTimeList[i]); action->setData(uavTrailTimeList[i]);
action->setCheckable(true); action->setCheckable(true);
trailSettingsGroup->addAction(action); _trailSettingsGroup->addAction(action);
if (static_cast<mapcontrol::UAVTrailType::Types>(map->getTrailType()) == mapcontrol::UAVTrailType::ByTimeElapsed && map->getTrailInterval() == uavTrailTimeList[i]) if (static_cast<mapcontrol::UAVTrailType::Types>(map->getTrailType()) == mapcontrol::UAVTrailType::ByTimeElapsed && _map->getTrailInterval() == uavTrailTimeList[i])
{ {
// This is the current active time, set the action checked // This is the current active time, set the action checked
action->setChecked(true); action->setChecked(true);
...@@ -106,11 +106,11 @@ void QGCMapToolBar::setMap(QGCMapWidget* map) ...@@ -106,11 +106,11 @@ void QGCMapToolBar::setMap(QGCMapWidget* map)
} }
for (int i = 0; i < uavTrailDistanceCount; ++i) for (int i = 0; i < uavTrailDistanceCount; ++i)
{ {
action = trailPlotMenu.addAction(tr("%1 meter%2").arg(uavTrailDistanceList[i]).arg((uavTrailDistanceList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailDistance())); action = _trailPlotMenu->addAction(tr("%1 meter%2").arg(uavTrailDistanceList[i]).arg((uavTrailDistanceList[i] > 1) ? "s" : ""), this, SLOT(setUAVTrailDistance()));
action->setData(uavTrailDistanceList[i]); action->setData(uavTrailDistanceList[i]);
action->setCheckable(true); action->setCheckable(true);
trailSettingsGroup->addAction(action); _trailSettingsGroup->addAction(action);
if (static_cast<mapcontrol::UAVTrailType::Types>(map->getTrailType()) == mapcontrol::UAVTrailType::ByDistance && map->getTrailInterval() == uavTrailDistanceList[i]) if (static_cast<mapcontrol::UAVTrailType::Types>(_map->getTrailType()) == mapcontrol::UAVTrailType::ByDistance && _map->getTrailInterval() == uavTrailDistanceList[i])
{ {
// This is the current active time, set the action checked // This is the current active time, set the action checked
action->setChecked(true); action->setChecked(true);
...@@ -118,43 +118,43 @@ void QGCMapToolBar::setMap(QGCMapWidget* map) ...@@ -118,43 +118,43 @@ void QGCMapToolBar::setMap(QGCMapWidget* map)
} }
// Set no trail checked if no action is checked yet // Set no trail checked if no action is checked yet
if (!trailSettingsGroup->checkedAction()) if (!_trailSettingsGroup->checkedAction())
{ {
defaultTrailAction->setChecked(true); defaultTrailAction->setChecked(true);
} }
optionsMenu.addMenu(&trailPlotMenu); _optionsMenu->addMenu(_trailPlotMenu);
// Add update times menu // Add update times menu
for (int i = 100; i < 5000; i+=400) for (int i = 100; i < 5000; i+=400)
{ {
float time = i/1000.0f; // Convert from ms to seconds float time = i/1000.0f; // Convert from ms to seconds
QAction* action = updateTimesMenu.addAction(tr("%1 seconds").arg(time), this, SLOT(setUpdateInterval())); QAction* action = _updateTimesMenu->addAction(tr("%1 seconds").arg(time), this, SLOT(setUpdateInterval()));
action->setData(time); action->setData(time);
action->setCheckable(true); action->setCheckable(true);
if (time == map->getUpdateRateLimit()) if (time == _map->getUpdateRateLimit())
{ {
action->blockSignals(true); action->blockSignals(true);
action->setChecked(true); action->setChecked(true);
action->blockSignals(false); action->blockSignals(false);
} }
updateTimesGroup->addAction(action); _updateTimesGroup->addAction(action);
} }
// If the current time is not part of the menu defaults // If the current time is not part of the menu defaults
// still add it as new option // still add it as new option
if (!updateTimesGroup->checkedAction()) if (!_updateTimesGroup->checkedAction())
{ {
float time = map->getUpdateRateLimit(); float time = _map->getUpdateRateLimit();
QAction* action = updateTimesMenu.addAction(tr("uptate every %1 seconds").arg(time), this, SLOT(setUpdateInterval())); QAction* action = _updateTimesMenu->addAction(tr("uptate every %1 seconds").arg(time), this, SLOT(setUpdateInterval()));
action->setData(time); action->setData(time);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(true); action->setChecked(true);
updateTimesGroup->addAction(action); _updateTimesGroup->addAction(action);
} }
optionsMenu.addMenu(&updateTimesMenu); _optionsMenu->addMenu(_updateTimesMenu);
ui->optionsButton->setMenu(&optionsMenu); _ui->optionsButton->setMenu(_optionsMenu);
} }
} }
...@@ -169,7 +169,7 @@ void QGCMapToolBar::setUAVTrailTime() ...@@ -169,7 +169,7 @@ void QGCMapToolBar::setUAVTrailTime()
int trailTime = action->data().toInt(&ok); int trailTime = action->data().toInt(&ok);
if (ok) if (ok)
{ {
(map->setTrailModeTimed(trailTime)); (_map->setTrailModeTimed(trailTime));
setStatusLabelText(tr("Trail mode: Every %1 second%2").arg(trailTime).arg((trailTime > 1) ? "s" : "")); setStatusLabelText(tr("Trail mode: Every %1 second%2").arg(trailTime).arg((trailTime > 1) ? "s" : ""));
} }
} }
...@@ -177,7 +177,7 @@ void QGCMapToolBar::setUAVTrailTime() ...@@ -177,7 +177,7 @@ void QGCMapToolBar::setUAVTrailTime()
void QGCMapToolBar::setStatusLabelText(const QString &text) void QGCMapToolBar::setStatusLabelText(const QString &text)
{ {
ui->posLabel->setText(text.leftJustified(statusMaxLen, QChar('.'), true)); _ui->posLabel->setText(text.leftJustified(_statusMaxLen, QChar('.'), true));
} }
void QGCMapToolBar::setUAVTrailDistance() void QGCMapToolBar::setUAVTrailDistance()
...@@ -191,7 +191,7 @@ void QGCMapToolBar::setUAVTrailDistance() ...@@ -191,7 +191,7 @@ void QGCMapToolBar::setUAVTrailDistance()
int trailDistance = action->data().toInt(&ok); int trailDistance = action->data().toInt(&ok);
if (ok) if (ok)
{ {
map->setTrailModeDistance(trailDistance); _map->setTrailModeDistance(trailDistance);
setStatusLabelText(tr("Trail mode: Every %1 meter%2").arg(trailDistance).arg((trailDistance == 1) ? "s" : "")); setStatusLabelText(tr("Trail mode: Every %1 meter%2").arg(trailDistance).arg((trailDistance == 1) ? "s" : ""));
} }
} }
...@@ -208,7 +208,7 @@ void QGCMapToolBar::setUpdateInterval() ...@@ -208,7 +208,7 @@ void QGCMapToolBar::setUpdateInterval()
float time = action->data().toFloat(&ok); float time = action->data().toFloat(&ok);
if (ok) if (ok)
{ {
map->setUpdateRateLimit(time); _map->setUpdateRateLimit(time);
setStatusLabelText(tr("Limit: %1 second%2").arg(time).arg((time != 1.0f) ? "s" : "")); setStatusLabelText(tr("Limit: %1 second%2").arg(time).arg((time != 1.0f) ? "s" : ""));
} }
} }
...@@ -225,7 +225,7 @@ void QGCMapToolBar::setMapType() ...@@ -225,7 +225,7 @@ void QGCMapToolBar::setMapType()
int mapType = action->data().toInt(&ok); int mapType = action->data().toInt(&ok);
if (ok) if (ok)
{ {
map->SetMapType((MapType::Types)mapType); _map->SetMapType((MapType::Types)mapType);
setStatusLabelText(tr("Map: %1").arg(mapType)); setStatusLabelText(tr("Map: %1").arg(mapType));
} }
} }
...@@ -256,13 +256,3 @@ void QGCMapToolBar::tileLoadProgress(int progress) ...@@ -256,13 +256,3 @@ void QGCMapToolBar::tileLoadProgress(int progress)
tileLoadEnd(); tileLoadEnd();
} }
} }
QGCMapToolBar::~QGCMapToolBar()
{
delete ui;
delete trailSettingsGroup;
delete updateTimesGroup;
delete mapTypesGroup;
// FIXME Delete all actions
}
...@@ -17,7 +17,6 @@ class QGCMapToolBar : public QWidget ...@@ -17,7 +17,6 @@ class QGCMapToolBar : public QWidget
public: public:
explicit QGCMapToolBar(QWidget *parent = 0); explicit QGCMapToolBar(QWidget *parent = 0);
~QGCMapToolBar();
void setMap(QGCMapWidget* map); void setMap(QGCMapWidget* map);
...@@ -32,20 +31,19 @@ public slots: ...@@ -32,20 +31,19 @@ public slots:
void setStatusLabelText(const QString &text); void setStatusLabelText(const QString &text);
private: private:
Ui::QGCMapToolBar *ui; Ui::QGCMapToolBar* _ui;
protected: QGCMapWidget* _map;
QGCMapWidget* map; QMenu* _optionsMenu;
QMenu optionsMenu; QMenu* _trailPlotMenu;
QMenu trailPlotMenu; QMenu* _updateTimesMenu;
QMenu updateTimesMenu; QMenu* _mapTypesMenu;
QMenu mapTypesMenu;
QActionGroup* trailSettingsGroup; QActionGroup* _trailSettingsGroup;
QActionGroup* updateTimesGroup; QActionGroup* _updateTimesGroup;
QActionGroup* mapTypesGroup; QActionGroup* _mapTypesGroup;
unsigned statusMaxLen; unsigned _statusMaxLen;
}; };
#endif // QGCMAPTOOLBAR_H #endif // QGCMAPTOOLBAR_H
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