diff --git a/kstars/ekos/scheduler/scheduler.cpp b/kstars/ekos/scheduler/scheduler.cpp --- a/kstars/ekos/scheduler/scheduler.cpp +++ b/kstars/ekos/scheduler/scheduler.cpp @@ -42,24 +42,6 @@ namespace Ekos { -bool scoreHigherThan(SchedulerJob *job1, SchedulerJob *job2) -{ - return job1->getScore() > job2->getScore(); -} - -bool priorityHigherThan(SchedulerJob *job1, SchedulerJob *job2) -{ - return job1->getPriority() < job2->getPriority(); -} - -bool altitudeHigherThan(SchedulerJob *job1, SchedulerJob *job2) -{ - double job1_altitude = Scheduler::findAltitude(job1->getTargetCoords(), job1->getStartupTime()); - double job2_altitude = Scheduler::findAltitude(job2->getTargetCoords(), job2->getStartupTime()); - - return job1_altitude > job2_altitude; -} - Scheduler::Scheduler() { setupUi(this); @@ -1319,12 +1301,14 @@ sortedJobs.erase(std::remove_if(sortedJobs.begin(), sortedJobs.end(),[](SchedulerJob* job) { return job->getState() > SchedulerJob::JOB_SCHEDULED;}), sortedJobs.end()); + /* FIXME: refactor so all sorts are using the same predicates */ + /* FIXME: use std::sort as qSort is deprecated */ if (Options::sortSchedulerJobs()) { - // Order by altitude first - qSort(sortedJobs.begin(), sortedJobs.end(), altitudeHigherThan); - // Then by priority - qSort(sortedJobs.begin(), sortedJobs.end(), priorityHigherThan); + // Order by altitude, greater altitude first + qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::decreasingAltitudeOrder); + // Then by priority, lower priority value first + qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::increasingPriorityOrder); } // Our first job now takes priority over ALL others. @@ -1414,12 +1398,14 @@ }*/ #if 0 + /* FIXME: refactor so all sorts are using the same predicates */ + /* FIXME: use std::sort as qSort is deprecated */ if (Options::sortSchedulerJobs()) { - // Order by score first - qSort(sortedJobs.begin(), sortedJobs.end(), scoreHigherThan); + // Order by score score first + qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::decreasingScoreOrder); // Then by priority - qSort(sortedJobs.begin(), sortedJobs.end(), priorityHigherThan); + qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::increasingPriorityOrder); foreach (SchedulerJob *job, sortedJobs) { @@ -1444,12 +1430,14 @@ } #endif + /* FIXME: refactor so all sorts are using the same predicates */ + /* FIXME: use std::sort as qSort is deprecated */ if (Options::sortSchedulerJobs()) { // Order by score first - qSort(sortedJobs.begin(), sortedJobs.end(), scoreHigherThan); + qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::decreasingScoreOrder); // Then by priority - qSort(sortedJobs.begin(), sortedJobs.end(), priorityHigherThan); + qSort(sortedJobs.begin(), sortedJobs.end(), SchedulerJob::increasingPriorityOrder); } // Get the first job that can run. diff --git a/kstars/ekos/scheduler/schedulerjob.h b/kstars/ekos/scheduler/schedulerjob.h --- a/kstars/ekos/scheduler/schedulerjob.h +++ b/kstars/ekos/scheduler/schedulerjob.h @@ -66,8 +66,8 @@ QString getName() const; void setName(const QString &value); + SkyPoint const & getTargetCoords() const; void setTargetCoords(dms& ra, dms& dec); - SkyPoint &getTargetCoords(); StartupCondition getStartupCondition() const; void setStartupCondition(const StartupCondition &value); @@ -148,6 +148,27 @@ QMap getCapturedFramesMap() const; void setCapturedFramesMap(const QMap &value); + /** @brief Compare ::SchedulerJob instances based on score. This is a qSort predicate, deprecated in QT5. + * @arg a, b are ::SchedulerJob instances to compare. + * @return true if the score of b is lower than the score of a. + * @return false if the score of b is higher than or equal to the score of a. + */ + static bool decreasingScoreOrder(SchedulerJob const *a, SchedulerJob const *b); + + /** @brief Compare ::SchedulerJob instances based on priority. This is a qSort predicate, deprecated in QT5. + * @arg a, b are ::SchedulerJob instances to compare. + * @return true if the priority of a is lower than the priority of b. + * @return false if the priority of a is higher than or equal to the priority of b. + */ + static bool increasingPriorityOrder(SchedulerJob const *a, SchedulerJob const *b); + + /** @brief Compare ::SchedulerJob instances based on altitude. This is a qSort predicate, deprecated in QT5. + * @arg a, b are ::SchedulerJob instances to compare. + * @return true if the altitude of b is lower than the altitude of a. + * @return false if the altitude of b is higher than or equal to the altitude of a. + */ + static bool decreasingAltitudeOrder(SchedulerJob const *a, SchedulerJob const *b); + private: QString name; SkyPoint targetCoords; diff --git a/kstars/ekos/scheduler/schedulerjob.cpp b/kstars/ekos/scheduler/schedulerjob.cpp --- a/kstars/ekos/scheduler/schedulerjob.cpp +++ b/kstars/ekos/scheduler/schedulerjob.cpp @@ -8,6 +8,7 @@ */ #include "schedulerjob.h" +#include "scheduler.h" #include "dms.h" #include "kstarsdata.h" @@ -30,7 +31,7 @@ name = value; } -SkyPoint &SchedulerJob::getTargetCoords() +SkyPoint const & SchedulerJob::getTargetCoords() const { return targetCoords; } @@ -395,3 +396,19 @@ targetCoords.updateCoordsNow(KStarsData::Instance()->updateNum()); } + +bool SchedulerJob::decreasingScoreOrder(SchedulerJob const *job1, SchedulerJob const *job2) +{ + return job1->getScore() > job2->getScore(); +} + +bool SchedulerJob::increasingPriorityOrder(SchedulerJob const *job1, SchedulerJob const *job2) +{ + return job1->getPriority() < job2->getPriority(); +} + +bool SchedulerJob::decreasingAltitudeOrder(SchedulerJob const *job1, SchedulerJob const *job2) +{ + return Ekos::Scheduler::findAltitude(job1->getTargetCoords(), job1->getStartupTime()) > + Ekos::Scheduler::findAltitude(job2->getTargetCoords(), job2->getStartupTime()); +}