2525#include < QTimer>
2626
2727#include " Observability.hpp"
28+ #ifndef NO_GUI
2829#include " ObservabilityDialog.hpp"
30+ #include " StelGui.hpp"
31+ #include " StelGuiItems.hpp"
32+ #endif
2933
3034#include " Planet.hpp"
3135#include " SolarSystem.hpp"
3236// #include "StelActionMgr.hpp"
3337#include " StelApp.hpp"
3438#include " StelCore.hpp"
35- #include " StelGui.hpp"
36- #include " StelGuiItems.hpp"
3739#include " StelLocaleMgr.hpp"
3840#include " StelModuleMgr.hpp"
3941#include " StelMovementMgr.hpp"
@@ -75,8 +77,7 @@ const double Observability::RefFullMoon = 2451564.696; // Reference Julian date
7577const double Observability::MoonPerilune = 0.0024236308 ; // Smallest Earth-Moon distance (in AU).
7678
7779Observability::Observability ()
78- : configDialog(new ObservabilityDialog())
79- , nextFullMoon(0 .)
80+ : nextFullMoon(0 .)
8081 , prevFullMoon(0 .)
8182 , GMTShift(0 .)
8283 , Jan1stJD(0 .)
@@ -112,9 +113,12 @@ Observability::Observability()
112113 , show_Best_Night(false )
113114 , show_Today(false )
114115 , show_FullMoon(false )
115- , flagShowReport (false )
116+ , flagEnabled (false )
116117 , fontSize(14 )
118+ #ifndef NO_GUI
119+ , configDialog(new ObservabilityDialog()),
117120 , button(Q_NULLPTR)
121+ #endif
118122{
119123 setObjectName (" Observability" );
120124
@@ -141,8 +145,10 @@ Observability::Observability()
141145Observability::~Observability ()
142146{
143147 // Shouldn't this be in the deinit()? --BM
144- if (configDialog != Q_NULLPTR)
148+ #ifndef NO_GUI
149+ if (configDialog)
145150 delete configDialog;
151+ #endif
146152}
147153
148154void Observability::updateMessageText ()
@@ -194,7 +200,8 @@ void Observability::init()
194200{
195201 loadConfiguration ();
196202
197- addAction (" actionShow_Observability" , N_ (" Observability" ), N_ (" Observability" ), " flagShowReport" );
203+ addAction (" actionShow_Observability" , N_ (" Observability" ), N_ (" Observability" ), " flagEnabled" );
204+ #ifndef NO_GUI
198205 addAction (" actionShow_Observability_dialog" , N_ (" Observability" ), N_ (" Show settings dialog" ), configDialog, " visible" , " " ); // Allow assign shortkey
199206
200207 StelGui * gui = dynamic_cast <StelGui *>(StelApp::getInstance ().getGui ());
@@ -208,12 +215,12 @@ void Observability::init()
208215 " actionShow_Observability_dialog" );
209216 gui->getButtonBar ()->addButton (button, " 065-pluginsGroup" );
210217 }
211-
218+ # endif
212219 updateMessageText ();
213220 connect (&StelApp::getInstance (), &StelApp::languageChanged, this , &Observability::onLanguageChanged);
214221 connect (StelApp::getInstance ().getCore (), SIGNAL (configurationDataSaved ()), this , SLOT (saveConfiguration ()));
215222
216- connect (this , &Observability::flagReportVisibilityChanged , this , [&](bool enabled) {
223+ connect (this , &Observability::flagEnabledChanged , this , [&](bool enabled) {
217224 if (enabled) {
218225 qDebug () << " [Observability] Creating plugin status dependent connections." ;
219226 createConnections ();
@@ -230,7 +237,7 @@ void Observability::init()
230237// MAIN CODE:
231238void Observability::draw (StelCore* core)
232239{
233- if (!flagShowReport )
240+ if (!flagEnabled )
234241 return ; // Button is off.
235242// ///////////////////////////////////////////////////////////////
236243// PRELIMINARS:
@@ -276,10 +283,7 @@ void Observability::draw(StelCore* core)
276283 }
277284
278285// Add refraction, if necessary:
279- Vec3d TempRefr;
280- TempRefr[0 ] = std::cos (horizonAltitude);
281- TempRefr[1 ] = 0.0 ;
282- TempRefr[2 ] = std::sin (horizonAltitude);
286+ Vec3d TempRefr (std::cos (horizonAltitude), 0.0 , std::sin (horizonAltitude));
283287 Vec3d CorrRefr = core->altAzToEquinoxEqu (TempRefr,StelCore::RefractionAuto);
284288 TempRefr = core->equinoxEquToAltAz (CorrRefr,StelCore::RefractionOff);
285289 double RefracAlt = std::asin (TempRefr[2 ]);
@@ -1433,9 +1437,13 @@ bool Observability::calculateSolarSystemEvents(StelCore* core, int bodyType)
14331437
14341438bool Observability::configureGui (bool show)
14351439{
1440+ #ifdef NO_GUI
1441+ return false ;
1442+ #else
14361443 if (show)
14371444 configDialog->setVisible (true );
14381445 return true ;
1446+ #endif
14391447}
14401448
14411449void Observability::resetConfiguration ()
@@ -1465,6 +1473,7 @@ void Observability::loadConfiguration()
14651473 show_FullMoon = conf->value (" show_FullMoon" , true ).toBool ();
14661474// show_Crescent = conf->value("show_Crescent", true).toBool();
14671475// show_SuperMoon = conf->value("show_SuperMoon", true).toBool();
1476+ flagEnabled = conf->value (" enabled" , false ).toBool ();
14681477
14691478 // For backwards compatibility, the value of this key is stored with
14701479 // inverted sign.
@@ -1602,12 +1611,13 @@ void Observability::setHorizonAltitude(int altitude)
16021611 configChanged = true ;
16031612}
16041613
1605- void Observability::showReport (bool b)
1614+ void Observability::setEnabled (bool b)
16061615{
1607- if (b!=flagShowReport )
1616+ if (b!=flagEnabled )
16081617 {
1609- flagShowReport = b;
1610- emit flagReportVisibilityChanged (b);
1618+ flagEnabled = b;
1619+ StelApp::immediateSave (" Observability/enabled" , b);
1620+ emit flagEnabledChanged (b);
16111621 }
16121622}
16131623
0 commit comments