summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-07-24 20:55:15 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-07-24 20:55:15 (GMT)
commit524293b025dc1339ed58d4115d428fbd07cbe1e2 (patch)
tree75faca3ccbaee6a4b36446a14314378254137f2c
parent15f981159cdf90b6c7b4a5b54996db9142d26bb8 (diff)
StarsPlugin: fix states of context menu
* inverting the action state in the handler is not needed and broken * set new state by state as requested from action, not current model state * do not depend action state on optional additional label rendering * consistently only enable optional additional label rendering if turned on * delay creation of configdialog to usage * contextmenu actions are owned by contextmenu
-rw-r--r--src/plugins/render/stars/StarsPlugin.cpp147
-rw-r--r--src/plugins/render/stars/StarsPlugin.h17
2 files changed, 66 insertions, 98 deletions
diff --git a/src/plugins/render/stars/StarsPlugin.cpp b/src/plugins/render/stars/StarsPlugin.cpp
index 97773ea..a33fc9c 100644
--- a/src/plugins/render/stars/StarsPlugin.cpp
+++ b/src/plugins/render/stars/StarsPlugin.cpp
@@ -80,10 +80,6 @@ StarsPlugin::StarsPlugin( const MarbleModel *marbleModel )
StarsPlugin::~StarsPlugin()
{
delete m_contextMenu;
- delete m_constellationsAction;
- delete m_sunMoonAction;
- delete m_planetsAction;
- delete m_dsoAction;
}
QStringList StarsPlugin::backendTypes() const
@@ -1332,19 +1328,15 @@ void StarsPlugin::requestRepaint()
emit repaintNeeded( QRegion() );
}
-void StarsPlugin::toggleSunMoon()
+void StarsPlugin::toggleSunMoon(bool on)
{
- QAction *sunMoonAction = qobject_cast<QAction*>(sender());
- sunMoonAction->setChecked(!sunMoonAction->isChecked());
-
- const bool changed = !(m_renderSun || m_renderMoon);
- m_renderSun = changed;
- m_renderMoon = changed;
- if (changed) {
+ m_renderSun = on;
+ m_renderMoon = on;
+ if (on) {
m_viewSolarSystemLabel = true;
}
- Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
+ const Qt::CheckState state = on ? Qt::Checked : Qt::Unchecked;
if ( m_configDialog ) {
ui_configWidget->m_solarSystemListWidget->item( 0 )->setCheckState( state );
ui_configWidget->m_solarSystemListWidget->item( 1 )->setCheckState( state );
@@ -1354,16 +1346,15 @@ void StarsPlugin::toggleSunMoon()
requestRepaint();
}
-void StarsPlugin::toggleDsos()
+void StarsPlugin::toggleDsos(bool on)
{
- QAction *dsosAction = qobject_cast<QAction*>(sender());
- dsosAction->setChecked(!dsosAction->isChecked());
-
- const bool changed = !(m_renderDsos || m_renderDsoLabels);
- m_renderDsos = changed;
- m_renderDsoLabels = changed;
+ m_renderDsos = on;
+ // only enable lables if set to true
+ if (on) {
+ m_renderDsoLabels = true;
+ }
- Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
+ const Qt::CheckState state = on ? Qt::Checked : Qt::Unchecked;
if ( m_configDialog ) {
ui_configWidget->m_viewDsosCheckbox->setChecked(state);
ui_configWidget->m_viewDsoLabelCheckbox->setChecked(state);
@@ -1372,16 +1363,12 @@ void StarsPlugin::toggleDsos()
requestRepaint();
}
-void StarsPlugin::toggleConstellations()
+void StarsPlugin::toggleConstellations(bool on)
{
- QAction *constellationsAction = qobject_cast<QAction*>(sender());
- constellationsAction->setChecked(!constellationsAction->isChecked());
+ m_renderConstellationLines = on;
+ m_renderConstellationLabels = on;
- const bool changed = !(m_renderConstellationLines || m_renderConstellationLabels);
- m_renderConstellationLines = changed;
- m_renderConstellationLabels = changed;
-
- Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
+ const Qt::CheckState state = on ? Qt::Checked : Qt::Unchecked;
if ( m_configDialog ) {
ui_configWidget->m_viewConstellationLinesCheckbox->setChecked( state );
ui_configWidget->m_viewConstellationLabelsCheckbox->setChecked( state );
@@ -1390,21 +1377,17 @@ void StarsPlugin::toggleConstellations()
requestRepaint();
}
-void StarsPlugin::togglePlanets()
+void StarsPlugin::togglePlanets(bool on)
{
- QAction *planetsAction = qobject_cast<QAction*>(sender());
- planetsAction->setChecked(!planetsAction->isChecked());
-
- const bool changed = !planetsAction->isChecked();
- m_renderPlanet["venus"] = changed;
- m_renderPlanet["mars"] = changed;
- m_renderPlanet["jupiter"] = changed;
- m_renderPlanet["mercury"] = changed;
- m_renderPlanet["saturn"] = changed;
- m_renderPlanet["uranus"] = changed;
- m_renderPlanet["neptune"] = changed;
-
- Qt::CheckState state = changed ? Qt::Checked : Qt::Unchecked;
+ m_renderPlanet["venus"] = on;
+ m_renderPlanet["mars"] = on;
+ m_renderPlanet["jupiter"] = on;
+ m_renderPlanet["mercury"] = on;
+ m_renderPlanet["saturn"] = on;
+ m_renderPlanet["uranus"] = on;
+ m_renderPlanet["neptune"] = on;
+
+ const Qt::CheckState state = on ? Qt::Checked : Qt::Unchecked;
if ( m_configDialog ) {
// Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune
ui_configWidget->m_solarSystemListWidget->item(2)->setCheckState(state);
@@ -1420,6 +1403,13 @@ void StarsPlugin::togglePlanets()
requestRepaint();
}
+void StarsPlugin::executeConfigDialog()
+{
+ QDialog *dialog = configDialog();
+ Q_ASSERT( dialog );
+ dialog->exec();
+}
+
bool StarsPlugin::eventFilter( QObject *object, QEvent *e )
{
if ( !enabled() || !visible() ) {
@@ -1447,62 +1437,39 @@ bool StarsPlugin::eventFilter( QObject *object, QEvent *e )
}
}
- bool scheduleConfigAction = false;
if (!m_contextMenu) {
m_contextMenu = new QMenu;
- scheduleConfigAction = true;
- }
-
- if (!m_constellationsAction) {
- m_constellationsAction =
- m_contextMenu->addAction( tr("Show &Constellations"),
- this, SLOT(toggleConstellations()) );
- }
+ m_constellationsAction = m_contextMenu->addAction(tr("Show &Constellations"),
+ this, SLOT(toggleConstellations(bool)));
+ m_constellationsAction->setCheckable(true);
- m_constellationsAction->setCheckable( true );
- m_constellationsAction->setChecked(
- m_renderConstellationLines || m_renderConstellationLabels );
+ m_sunMoonAction = m_contextMenu->addAction(tr("Show &Sun and Moon"),
+ this, SLOT(toggleSunMoon(bool)));
+ m_sunMoonAction->setCheckable(true);
+ m_planetsAction = m_contextMenu->addAction(tr("Show &Planets"),
+ this, SLOT(togglePlanets(bool)));
+ m_planetsAction->setCheckable(true);
- if (!m_sunMoonAction) {
- m_sunMoonAction = m_contextMenu->addAction( tr("Show &Sun and Moon"),
- this, SLOT(toggleSunMoon()) );
- }
-
- m_sunMoonAction->setCheckable( true );
- m_sunMoonAction->setChecked( m_renderSun || m_renderMoon || m_viewSolarSystemLabel );
+ m_dsoAction = m_contextMenu->addAction(tr("Show &Deep Sky Objects"),
+ this, SLOT(toggleDsos(bool)) );
+ m_dsoAction->setCheckable(true);
- if (!m_planetsAction) {
- m_planetsAction = m_contextMenu->addAction( tr("Show &Planets"),
- this, SLOT(togglePlanets()));
+ m_contextMenu->addSeparator();
+ m_contextMenu->addAction(tr("&Configure..."),
+ this, SLOT(executeConfigDialog()));
}
- m_planetsAction->setCheckable( true );
- if (m_renderPlanet["venus"] || m_renderPlanet["mars"] ||
+ // update action states
+ m_constellationsAction->setChecked(m_renderConstellationLines || m_renderConstellationLabels);
+ m_sunMoonAction->setChecked(m_renderSun || m_renderMoon);
+ m_dsoAction->setChecked(m_renderDsos);
+ const bool isAnyPlanetRendered =
+ m_renderPlanet["venus"] || m_renderPlanet["mars"] ||
m_renderPlanet["jupiter"] || m_renderPlanet["mercury"] ||
- m_renderPlanet["saturn"] || m_renderPlanet["uranus"] ||
- m_renderPlanet["neptune"]) {
- // then
- m_planetsAction->setChecked( true );
- } else {
- m_planetsAction->setChecked( false );
- }
-
- if (!m_dsoAction) {
- m_dsoAction = m_contextMenu->addAction( tr("Show &Deep Sky Objects"),
- this, SLOT(toggleDsos()) );
- }
-
- m_dsoAction->setCheckable( true );
- m_dsoAction->setChecked( m_renderDsos || m_renderDsoLabels );
-
- if (scheduleConfigAction) {
- QDialog *dialog = configDialog();
- Q_ASSERT( dialog );
- m_contextMenu->addSeparator();
- QAction *configAction = m_contextMenu->addAction( tr( "&Configure..." ) );
- connect( configAction, SIGNAL(triggered()), dialog, SLOT(exec()) );
- }
+ m_renderPlanet["saturn"] || m_renderPlanet["uranus"] ||
+ m_renderPlanet["neptune"];
+ m_planetsAction->setChecked(isAnyPlanetRendered);
m_contextMenu->exec(widget->mapToGlobal(menuEvent->pos()));
return true;
diff --git a/src/plugins/render/stars/StarsPlugin.h b/src/plugins/render/stars/StarsPlugin.h
index c5fcb5f..cc3c2c6 100644
--- a/src/plugins/render/stars/StarsPlugin.h
+++ b/src/plugins/render/stars/StarsPlugin.h
@@ -176,10 +176,11 @@ protected:
private Q_SLOTS:
void requestRepaint();
- void toggleSunMoon();
- void togglePlanets();
- void toggleDsos();
- void toggleConstellations();
+ void toggleSunMoon(bool on);
+ void togglePlanets(bool on);
+ void toggleDsos(bool on);
+ void toggleConstellations(bool on);
+ void executeConfigDialog();
public Q_SLOTS:
void readSettings();
@@ -265,10 +266,10 @@ private:
/* Context menu */
QPointer<QMenu> m_contextMenu;
- QPointer<QAction> m_constellationsAction;
- QPointer<QAction> m_sunMoonAction;
- QPointer<QAction> m_planetsAction;
- QPointer<QAction> m_dsoAction;
+ QAction* m_constellationsAction;
+ QAction* m_sunMoonAction;
+ QAction* m_planetsAction;
+ QAction* m_dsoAction;
bool m_doRender;
};