diff --git a/kstars/ekos/observatory/observatory.h b/kstars/ekos/observatory/observatory.h --- a/kstars/ekos/observatory/observatory.h +++ b/kstars/ekos/observatory/observatory.h @@ -121,6 +121,7 @@ // sensor data graphs void mouseOverLine(QMouseEvent *event); + void refreshSensorGraph(); // reacting on weather changes void weatherWarningSettingsChanged(); diff --git a/kstars/ekos/observatory/observatory.cpp b/kstars/ekos/observatory/observatory.cpp --- a/kstars/ekos/observatory/observatory.cpp +++ b/kstars/ekos/observatory/observatory.cpp @@ -386,6 +386,7 @@ weatherBox->setEnabled(enable); clearGraphHistory->setVisible(enable); clearGraphHistory->setEnabled(enable); + autoscaleValuesCB->setVisible(enable); sensorGraphs->setVisible(enable); } @@ -507,13 +508,19 @@ connect(getWeatherModel(), &Ekos::ObservatoryWeatherModel::newStatus, this, &Ekos::Observatory::setWeatherStatus); connect(getWeatherModel(), &Ekos::ObservatoryWeatherModel::disconnected, this, &Ekos::Observatory::shutdownWeather); connect(clearGraphHistory, &QPushButton::clicked, this, &Observatory::clearSensorDataHistory); + connect(autoscaleValuesCB, &QCheckBox::clicked, [this](bool checked) + { + getWeatherModel()->setAutoScaleValues(checked); + this->refreshSensorGraph(); + }); connect(&weatherStatusTimer, &QTimer::timeout, [this]() { weatherWarningStatusLabel->setText(getWeatherModel()->getWarningActionsStatus()); weatherAlertStatusLabel->setText(getWeatherModel()->getAlertActionsStatus()); }); weatherBox->setEnabled(true); + autoscaleValuesCB->setChecked(getWeatherModel()->autoScaleValues()); weatherActionsBox->setVisible(true); weatherActionsBox->setEnabled(true); weatherWarningBox->setChecked(getWeatherModel()->getWarningActionsActive()); @@ -524,6 +531,8 @@ weatherStatusTimer.start(1000); if (getWeatherModel()->refresh() == false) appendLogText(i18n("Refreshing weather data failed.")); + // avoid double init + disconnect(getWeatherModel(), &Ekos::ObservatoryWeatherModel::ready, this, &Ekos::Observatory::initWeather); } void Observatory::shutdownWeather() @@ -560,17 +569,12 @@ // display data point sensorGraphs->graph()->addData(sensorGraphData[id]->last().key, sensorGraphData[id]->last().value); - sensorGraphs->rescaleAxes(); - // ensure that the 0-line is visible + + // determine where the x axis is relatively to the value ranges if ((sensorRanges[id] > 0 && value < 0) || (sensorRanges[id] < 0 && value > 0)) sensorRanges[id] = 0; - // ensure visibility of the 0-line on the y-axis - if (sensorRanges[id] > 0) - sensorGraphs->yAxis->setRangeLower(0); - else if (sensorRanges[id] < 0) - sensorGraphs->yAxis->setRangeUpper(0); - sensorGraphs->replot(); + refreshSensorGraph(); } } @@ -645,6 +649,23 @@ } +void Observatory::refreshSensorGraph() +{ + + sensorGraphs->rescaleAxes(); + + // restrict the y-Axis to the values range + if (getWeatherModel()->autoScaleValues() == false) + { + if (sensorRanges[selectedSensorID] > 0) + sensorGraphs->yAxis->setRangeLower(0); + else if (sensorRanges[selectedSensorID] < 0) + sensorGraphs->yAxis->setRangeUpper(0); + } + + sensorGraphs->replot(); +} + void Observatory::selectedSensorChanged(QString id) { QVector *data = sensorGraphData[id]; @@ -657,9 +678,8 @@ container->add(QCPGraphData(it->key, it->value)); sensorGraphs->graph()->setData(QSharedPointer(container)); - sensorGraphs->rescaleAxes(); - sensorGraphs->replot(); selectedSensorID = id; + refreshSensorGraph(); } } @@ -765,6 +785,8 @@ struct WeatherActions actions; actions.parkDome = weatherWarningDomeCB->isChecked(); actions.closeShutter = weatherWarningShutterCB->isChecked(); + // Fixme: not implemented yet + actions.stopScheduler = false; actions.delay = static_cast(weatherWarningDelaySB->value()); getWeatherModel()->setWarningActions(actions); @@ -775,6 +797,8 @@ struct WeatherActions actions; actions.parkDome = weatherAlertDomeCB->isChecked(); actions.closeShutter = weatherAlertShutterCB->isChecked(); + // Fixme: not implemented yet + actions.stopScheduler = false; actions.delay = static_cast(weatherAlertDelaySB->value()); getWeatherModel()->setAlertActions(actions); diff --git a/kstars/ekos/observatory/observatory.ui b/kstars/ekos/observatory/observatory.ui --- a/kstars/ekos/observatory/observatory.ui +++ b/kstars/ekos/observatory/observatory.ui @@ -22,7 +22,7 @@ Qt::Horizontal - + 3 @@ -810,54 +810,15 @@ 3 - - - - - 0 - 0 - - - - - - - - - - - - 140 - 0 - - - - <html><head/><body><p>Current data of the weather sensors. Click on the sensor name to display its data over time.</p></body></html> - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + false Actions - + 3 @@ -873,55 +834,55 @@ 3 - - + + - War&ning + Ale&rt true - + 3 - 0 + 3 3 0 - + 3 - - + + - Park Dome + Close Shutter - - + + - Close Shutter + Park Dome - + Stop Scheduler - + - + <html><head/><body><p><span style=" font-style:italic;">Status: inactive</span></p></body></html> @@ -931,7 +892,7 @@ - + Qt::Horizontal @@ -944,14 +905,14 @@ - + Delay (sec): - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -966,54 +927,33 @@ - + - Ale&rt + War&ning true - + 3 - 3 + 0 3 0 - + 3 - - - - Close Shutter - - - - - - - Park Dome - - - - - - - Stop Scheduler - - - - + - + <html><head/><body><p><span style=" font-style:italic;">Status: inactive</span></p></body></html> @@ -1023,7 +963,7 @@ - + Qt::Horizontal @@ -1036,14 +976,14 @@ - + Delay (sec): - + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter @@ -1054,29 +994,60 @@ + + + + Park Dome + + + + + + + Stop Scheduler + + + + + + + Close Shutter + + + - - + + + + + 0 + 0 + + + + + + + + + Qt::Horizontal - - QSizePolicy::Fixed - - 10 + 40 20 - + @@ -1101,40 +1072,95 @@ - - - - false - + + - 24 - 24 - - - - - 24 - 24 + 140 + 0 - <html><head/><body><p>Clear sensor data history</p></body></html> - - - - - - - - - - 24 - 24 - + <html><head/><body><p>Current data of the weather sensors. Click on the sensor name to display its data over time.</p></body></html> + + + + + 9 + + + 3 + + + 9 + + + 3 + + + + + <html><head/><body><p>Scale the value axis to the current value range.</p></body></html> + + + auto scale values + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + + 24 + 24 + + + + + 24 + 24 + + + + <html><head/><body><p>Clear sensor data history</p></body></html> + + + + + + + .. + + + + 24 + 24 + + + + + + + diff --git a/kstars/ekos/observatory/observatoryweathermodel.h b/kstars/ekos/observatory/observatoryweathermodel.h --- a/kstars/ekos/observatory/observatoryweathermodel.h +++ b/kstars/ekos/observatory/observatoryweathermodel.h @@ -68,6 +68,11 @@ */ std::vector getWeatherData() { return m_WeatherData; } + /** + * @brief Flag whether the X axis should be visible in the sensor graph + */ + bool autoScaleValues() {return m_autoScaleValues;} + void setAutoScaleValues(bool show); public slots: /** @@ -79,11 +84,11 @@ */ void setAlertActionsActive(bool active); - private: +private: Weather *weatherInterface; QTimer warningTimer, alertTimer; struct WeatherActions warningActions, alertActions; - bool warningActionsActive, alertActionsActive; + bool warningActionsActive, alertActionsActive, m_autoScaleValues; void startAlertTimer(); void startWarningTimer(); diff --git a/kstars/ekos/observatory/observatoryweathermodel.cpp b/kstars/ekos/observatory/observatoryweathermodel.cpp --- a/kstars/ekos/observatory/observatoryweathermodel.cpp +++ b/kstars/ekos/observatory/observatoryweathermodel.cpp @@ -35,6 +35,7 @@ alertActions.parkDome = Options::weatherAlertCloseDome(); alertActions.closeShutter = Options::weatherAlertCloseShutter(); alertActions.delay = Options::weatherAlertDelay(); + m_autoScaleValues = Options::weatherAutoScaleValues(); // not implemented yet warningActions.stopScheduler = false; @@ -108,6 +109,12 @@ startAlertTimer(); } +void ObservatoryWeatherModel::setAutoScaleValues(bool value) +{ + m_autoScaleValues = value; + Options::setWeatherAutoScaleValues(value); +} + void ObservatoryWeatherModel::startAlertTimer() { if (alertActionsActive && (alertActions.parkDome || alertActions.closeShutter || alertActions.stopScheduler)) diff --git a/kstars/kstars.kcfg b/kstars/kstars.kcfg --- a/kstars/kstars.kcfg +++ b/kstars/kstars.kcfg @@ -2447,6 +2447,10 @@ true + + + true +