//----------------------------------------------------------------------------- // $Id: QtRun/TimestepList.cpp 2017/02/15 14:49:12 philw $ //----------------------------------------------------------------------------- // Note [Phil, 10-2013, Rw 6.4, Gnats 5207]: We have never properly // supported a weekly timestep; (they always started Tuesday night). // For now, we will show the Weekly timestep item ONLY ON DEMAND, // e.g. from an old model which uses a Weekly run timestep, or for // a SeriesSlot which already has a weekly timestep. #include "TimestepList.hpp" #include "rwError.hpp" //--- for rwAssert #include #include // // singleton instance and methods // // private, static TimestepList* TimestepList::_instance(0); // static const TimestepList& TimestepList::instance() { if (_instance == 0) { _instance = new TimestepList; } return *_instance; } // static void TimestepList::deleteInstance() { delete _instance; _instance = 0; } // static bool TimestepList::isInstantiated() { return _instance != 0; } const QList& TimestepList::timesteps (const DeltaTime& toBeUsedForStep) const { if (toBeUsedForStep == _tstepWeek.step()) return _timestepsWithWeekly; return _timestepsStd; } // // constructors and destructor // TimestepList::TimestepList() : _tstep1Hour (DeltaTime (1L, DeltaTime::Hours), QObject::tr ("1 Hour")), _tstep6Hour (DeltaTime (6L, DeltaTime::Hours), QObject::tr ("6 Hour")), _tstep12Hour (DeltaTime (12L, DeltaTime::Hours), QObject::tr ("12 Hour")), _tstepDay (DeltaTime (1L, DeltaTime::Days), QObject::tr ("Daily")), _tstepWeek (DeltaTime (1L, DeltaTime::Weeks), QObject::tr ("Weekly")), _tstepMonth (DeltaTime (1L, DeltaTime::Months), QObject::tr ("Monthly")), _tstepYear (DeltaTime (1L, DeltaTime::Years), QObject::tr ("Yearly")) { static const char* mname ("TimestepList ctor"); static int callCnt (0); ++callCnt; // std::cout << mname << " [#" << callCnt << "]" << std::endl; _timestepsStd << _tstep1Hour << _tstep6Hour << _tstep12Hour << _tstepDay << _tstepMonth << _tstepYear; _timestepsWithWeekly << _tstep1Hour << _tstep6Hour << _tstep12Hour << _tstepDay << _tstepWeek << _tstepMonth << _tstepYear; } // virtual TimestepList::~TimestepList() { } QStringList TimestepList::stringList() const { const int cnt = _timestepsStd.count(); QStringList stepSizeNames; stepSizeNames.reserve (cnt); for (int inx = 0; inx < cnt; ++inx) stepSizeNames.append (_timestepsStd [inx].text()); return stepSizeNames; } QStringList TimestepList::stringList(const DeltaTime& toBeUsedForStep) const { const QList& stepList = timesteps (toBeUsedForStep); const int cnt = stepList.count(); QStringList stepSizeNames; stepSizeNames.reserve (cnt); for (int inx = 0; inx < cnt; ++inx) stepSizeNames.append (stepList [inx].text()); return stepSizeNames; } // // return the timestep text // QString TimestepList::text (const DeltaTime& refStep) const { const int cnt = _timestepsWithWeekly.count(); for (int inx = 0; inx < cnt; ++inx) { if (_timestepsWithWeekly [inx] .step() == refStep) { return _timestepsWithWeekly [inx] .text(); } } return QString(); } DeltaTime TimestepList::step (const QString& refText) const { const int cnt = _timestepsWithWeekly.count(); for (int inx = 0; inx < cnt; ++inx) { if (_timestepsWithWeekly [inx] .text() == refText) { return _timestepsWithWeekly [inx] .step(); } } rwAssert (("Timestep not found for given timestep text", 0)); return _tstepDay.step(); // arbitrary } //--- (end TimestepList.cpp) ---