From 5d4fe1509728767826d04fcc3448c8faf9b62ced Mon Sep 17 00:00:00 2001 From: rinkk <karsten.rink@ufz.de> Date: Fri, 10 Aug 2018 16:26:06 +0200 Subject: [PATCH] moved helper function to seperate file --- .../DataView/DiagramView/CMakeLists.txt | 1 + .../DataView/DiagramView/DiagramList.cpp | 16 ++--- .../DataView/DiagramView/DiagramList.h | 5 +- .../DiagramView/DiagramPrefsDialog.cpp | 61 +++++++++---------- .../DataView/DiagramView/DiagramScene.cpp | 4 +- 5 files changed, 38 insertions(+), 49 deletions(-) diff --git a/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt b/Applications/DataExplorer/DataView/DiagramView/CMakeLists.txt index b8030c4a2fa..473fb9340b3 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 46c992a80c7..495f298f856 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 60114cadae3..36f45a45fc9 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 48abe51c040..8841b619240 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 2fc9e0569af..0c02905aabb 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 -- GitLab