diff --git a/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt b/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt index b8030c4a2fa2098356e7d362983cf3214b4a7167..473fb9340b353cebefa2fdfa6b4f9f9598279e22 100644 --- a/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt +++ b/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt @@ -10,6 +10,7 @@ set(SOURCES set(HEADERS DiagramList.h + getDateTime.h QArrow.h QGraphicsGrid.h DiagramScene.h diff --git a/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp b/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp index 46c992a80c7216d8824a6cbf758a42336df9f46b..495f298f8563ef211268622aa92f50a988a84060 100644 --- a/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp +++ b/Applications/DataExplorer/DataView/DiagramView/DiagramList.cpp @@ -13,6 +13,7 @@ */ #include "DiagramList.h" +#include "getDateTime.h" #include <logog/include/logog.hpp> @@ -260,12 +261,12 @@ int DiagramList::readList(const SensorData* data, std::vector<DiagramList*> &lis if (is_date) { l->setXUnit("day"); - QDateTime startDate(getDateTime(QString::fromStdString(BaseLib::int2date(time_steps[0])))); + QDateTime const startDate(getDateTime(BaseLib::int2date(time_steps[0]))); lists[i]->setStartDate(startDate); for (std::size_t j = 0; j < nValues; j++) { - QString const data_str = QString::fromStdString(BaseLib::int2date(time_steps[j])); - float numberOfSecs = static_cast<float>(startDate.secsTo(getDateTime(data_str))); + QDateTime const currentDate(getDateTime(BaseLib::int2date(time_steps[j]))); + float numberOfSecs = static_cast<float>(startDate.secsTo(currentDate)); lists[i]->addNextPoint(numberOfSecs, (*time_series)[j]); } } @@ -352,13 +353,4 @@ void DiagramList::update() _maxY = calcMaxYValue(); } -QDateTime DiagramList::getDateTime(QString stringDate) -{ - if (stringDate.length() == 10) - return QDateTime::fromString(stringDate, "dd.MM.yyyy"); - - if (stringDate.length() == 19) - return QDateTime::fromString(stringDate, "dd.MM.yyyy.HH.mm.ss"); - return QDateTime(); -} diff --git a/Applications/DataExplorer/DataView/DiagramView/DiagramList.h b/Applications/DataExplorer/DataView/DiagramView/DiagramList.h index 60114cadae3c061d43bce53586cc5705c4ca9968..36f45a45fc9be745c8584fafe4c6aae7821fbd3c 100644 --- a/Applications/DataExplorer/DataView/DiagramView/DiagramList.h +++ b/Applications/DataExplorer/DataView/DiagramView/DiagramList.h @@ -146,9 +146,6 @@ public: /// Returns the width of the bounding box of all data points within the list. double width() const { return _maxX - _minX; } - /// Converts string into QDateTime-format - static QDateTime getDateTime(QString s); - private: /// Returns the minimum x-value of all the data points. float calcMinXValue(); @@ -161,7 +158,7 @@ private: /// Returns the maximum y-value of all the data points. float calcMaxYValue(); - + /** * Reads an ASCII file containing the coordinates in the following format: * date (tab) value diff --git a/Applications/DataExplorer/DataView/DiagramView/DiagramPrefsDialog.cpp b/Applications/DataExplorer/DataView/DiagramView/DiagramPrefsDialog.cpp index 48abe51c040a5d8e9680251b4cc11ac3cd53ed5d..8841b619240d90063837400227e789adc720b20d 100644 --- a/Applications/DataExplorer/DataView/DiagramView/DiagramPrefsDialog.cpp +++ b/Applications/DataExplorer/DataView/DiagramView/DiagramPrefsDialog.cpp @@ -12,9 +12,10 @@ * */ +#include "DiagramPrefsDialog.h" #include "DetailWindow.h" #include "DiagramList.h" -#include "DiagramPrefsDialog.h" +#include "getDateTime.h" #include "OGSError.h" #include "Station.h" @@ -67,8 +68,8 @@ DiagramPrefsDialog::~DiagramPrefsDialog() void DiagramPrefsDialog::accept() { - QDateTime start_date(DiagramList::getDateTime(fromDateLine->text())); - QDateTime end_date(DiagramList::getDateTime(toDateLine->text())); + QDateTime start_date(getDateTime(fromDateLine->text())); + QDateTime end_date(getDateTime(toDateLine->text())); if (start_date == QDateTime() || end_date == QDateTime() || start_date > end_date || _list.empty()) @@ -77,42 +78,40 @@ void DiagramPrefsDialog::accept() return; } - // Data has been loaded. - // If loading the other lists fails at least nothing terrible will happen. - if (_list[0]->size() > 0) + if (_list[0]->size() == 0) { - bool window_is_empty(false); - if (_window == nullptr) - { - _window = new DetailWindow(); - _window->setAttribute(Qt::WA_DeleteOnClose); - window_is_empty = true; - } + OGSError::box("Invalid station data."); + this->done(QDialog::Rejected); + } - for (std::size_t i = 0; i < _list.size(); i++) - if (_visability[i]->isChecked()) - { - _list[i]->truncateToRange(start_date, end_date); - _window->addList(_list[i]); - window_is_empty = false; - } + // Data has been loaded. + // If loading lists beyond the first one fails at least nothing terrible will happen. + bool window_is_empty(false); + if (_window == nullptr) + { + _window = new DetailWindow(); + _window->setAttribute(Qt::WA_DeleteOnClose); + window_is_empty = true; + } - if (!window_is_empty) - { - _window->show(); - this->done(QDialog::Accepted); - } - else + for (std::size_t i = 0; i < _list.size(); i++) + if (_visability[i]->isChecked()) { - delete _window; - _window = nullptr; - OGSError::box("No dataset selected."); + _list[i]->truncateToRange(start_date, end_date); + _window->addList(_list[i]); + window_is_empty = false; } + + if (!window_is_empty) + { + _window->show(); + this->done(QDialog::Accepted); } else { - OGSError::box("Invalid station data."); - this->done(QDialog::Rejected); + delete _window; + _window = nullptr; + OGSError::box("No dataset selected."); } } diff --git a/Applications/DataExplorer/DataView/DiagramView/DiagramScene.cpp b/Applications/DataExplorer/DataView/DiagramView/DiagramScene.cpp index 2fc9e0569afad8d1d5a77fd0d556ca3515cce0a3..0c02905aabbc7ef2780bb68719042172a8d9a33f 100644 --- a/Applications/DataExplorer/DataView/DiagramView/DiagramScene.cpp +++ b/Applications/DataExplorer/DataView/DiagramView/DiagramScene.cpp @@ -142,8 +142,8 @@ void DiagramScene::adjustAxis(qreal& min, qreal& max, int& numberOfTicks) numberOfTicks = int(ceil(max / step) - std::floor(min / step)); if (numberOfTicks < MinTicks) numberOfTicks = MinTicks; - min = (std::floor(min / step) * step); - max = (ceil(max / step) * step); + min = std::floor(min / step) * step; + max = ceil(max / step) * step; } ///Calculates scaling factors to set coordinate system and graphs to default window size