Skip to content

Commit

Permalink
Merge commit '839976f7f9953f5985f0baf1270bc095b5fd7c41'
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed May 20, 2024
2 parents d60ac61 + 839976f commit 6f2530f
Show file tree
Hide file tree
Showing 11 changed files with 333 additions and 7 deletions.
10 changes: 5 additions & 5 deletions agrolib/project/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include "dialogPointDeleteData.h"
#include "formInfo.h"
#include "importData.h"
#include "waterTable.h"
#include "dialogSummary.h"
#include "waterTableWidget.h"


#include <iostream>
Expand Down Expand Up @@ -4600,9 +4600,6 @@ bool Project::waterTableImportDepths(QString csvDepths)

bool Project::computeSingleWell(QString idWell, int indexWell)
{
// TO DO
qDebug() << "selectedId " << idWell;
qDebug() << "selectedIndex " << QString::number(indexWell);
bool isMeteoGridLoaded;
QDate firstMeteoDate = wellPoints[indexWell].getFirstDate().addDays(-730); // necessari 24 mesi di dati meteo precedenti il primo dato di falda
if (this->meteoGridDbHandler != nullptr)
Expand All @@ -4624,6 +4621,9 @@ bool Project::computeSingleWell(QString idWell, int indexWell)
int maxNrDays = 730; // attualmente fisso
WaterTable waterTable(meteoPoints, nrMeteoPoints, meteoGridDbHandler->meteoGrid(), isMeteoGridLoaded, *meteoSettings, gisSettings);
waterTable.computeWaterTable(wellPoints[indexWell], maxNrDays);
DialogSummary dialogResult(waterTable); // show results
waterTableList.push_back(waterTable);
DialogSummary* dialogResult = new DialogSummary(waterTable); // show results
waterTable.viewWaterTableSeries(); // prepare series to show
WaterTableWidget* chartResult = new WaterTableWidget(idWell, waterTable.getMyDates(), waterTable.getMyHindcastSeries(), waterTable.getMyInterpolateSeries(), waterTable.getDepths());
return true;
}
5 changes: 5 additions & 0 deletions agrolib/project/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
#ifndef LOCALPROXYWIDGET_H
#include "localProxyWidget.h"
#endif
#ifndef WATERTABLE_H
#include "waterTable.h"
#endif

#ifndef _FSTREAM_
#include <fstream>
Expand Down Expand Up @@ -153,6 +156,8 @@
Crit3DProxyWidget* proxyWidget;
Crit3DLocalProxyWidget* localProxyWidget;

QList<WaterTable> waterTableList;

Project();

void initializeProject();
Expand Down
12 changes: 11 additions & 1 deletion agrolib/waterTable/dialogSummary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,15 @@ DialogSummary::DialogSummary(WaterTable myWaterTable)
mainLayout->addLayout(infoLayout);

setLayout(mainLayout);
exec();
show();
}

DialogSummary::~DialogSummary()
{

}

void DialogSummary::closeEvent(QCloseEvent *event)
{
event->accept();
}
2 changes: 2 additions & 0 deletions agrolib/waterTable/dialogSummary.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class DialogSummary : public QDialog
{
public:
DialogSummary(WaterTable myWaterTable);
~DialogSummary();
void closeEvent(QCloseEvent *event);
};

#endif // DIALOGSUMMARY_H
41 changes: 41 additions & 0 deletions agrolib/waterTable/waterTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ QDate WaterTable::getLastDateWell()
return lastDateWell;
}

QMap<QDate, int> WaterTable::getDepths()
{
return well.getDepths();
}

QString WaterTable::getError() const
{
return error;
Expand Down Expand Up @@ -70,6 +75,21 @@ int WaterTable::getNrObsData() const
return nrObsData;
}

std::vector<QDate> WaterTable::getMyDates() const
{
return myDates;
}

std::vector<float> WaterTable::getMyHindcastSeries() const
{
return myHindcastSeries;
}

std::vector<float> WaterTable::getMyInterpolateSeries() const
{
return myInterpolateSeries;
}

void WaterTable::initializeWaterTable(Well myWell)
{

Expand Down Expand Up @@ -646,3 +666,24 @@ bool WaterTable::getWaterTableHindcast(QDate myDate, float* myValue, float* myDe
return getWaterTableHindcast;
}

void WaterTable::viewWaterTableSeries()
{
QMap<QDate, int> myDepths = well.getDepths();
QMapIterator<QDate, int> it(myDepths);

myDates.clear();
myHindcastSeries.clear();
myInterpolateSeries.clear();
float myDepth;
float myDelta;
int myDeltaDays;

for (QDate myDate = firstMeteoDate; myDate<=lastMeteoDate; myDate=myDate.addDays(1))
{
myDates.push_back(myDate);
float computedValue = getWaterTableDaily(myDate);
myHindcastSeries.push_back(computedValue);
getWaterTableHindcast(myDate, &myDepth, &myDelta, &myDeltaDays);
myInterpolateSeries.push_back(myDepth);
}
}
11 changes: 11 additions & 0 deletions agrolib/waterTable/waterTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class WaterTable
float getWaterTableClimate(QDate myDate);
bool computeWaterTableClimate(QDate currentDate, int yearFrom, int yearTo, float* myValue);
bool getWaterTableHindcast(QDate myDate, float* myValue, float* myDelta, int* myDeltaDays);
void viewWaterTableSeries();
QString getError() const;

float getAlpha() const;
Expand All @@ -40,6 +41,11 @@ class WaterTable
float getEF() const;
int getNrObsData() const;

std::vector<QDate> getMyDates() const;
std::vector<float> getMyHindcastSeries() const;
std::vector<float> getMyInterpolateSeries() const;
QMap<QDate, int> getDepths();

private:
Crit3DMeteoPoint *meteoPoints;
int nrMeteoPoints;
Expand Down Expand Up @@ -74,6 +80,11 @@ class WaterTable
bool isCWBEquationReady;
float avgDailyCWB; //[mm]
Crit3DMeteoPoint linkedMeteoPoint;

// graph
std::vector<QDate> myDates;
std::vector<float> myHindcastSeries;
std::vector<float> myInterpolateSeries;
};

#endif // WATERTABLE_H
6 changes: 5 additions & 1 deletion agrolib/waterTable/waterTable.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,23 @@ win32:{
TARGET = waterTable
}

INCLUDEPATH += ../crit3dDate ../mathFunctions ../meteo ../interpolation ../gis ../weatherGenerator
INCLUDEPATH += ../crit3dDate ../mathFunctions ../meteo ../interpolation ../gis ../commonChartElements ../weatherGenerator

SOURCES += \
dialogSelectWell.cpp \
dialogSummary.cpp \
importData.cpp \
waterTable.cpp \
waterTableChartView.cpp \
waterTableWidge.cpp \
well.cpp

HEADERS += \
dialogSelectWell.h \
dialogSummary.h \
importData.h \
waterTable.h \
waterTableChartView.h \
waterTableWidget.h \
well.h

173 changes: 173 additions & 0 deletions agrolib/waterTable/waterTableChartView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#include "waterTableChartView.h"

WaterTableChartView::WaterTableChartView(QWidget *parent) :
QChartView(new QChart(), parent)
{
obsDepthSeries = new QScatterSeries();
obsDepthSeries->setName("Observed");
obsDepthSeries->setColor(Qt::green);
obsDepthSeries->setMarkerSize(10.0);

hindcastSeries = new QLineSeries();
hindcastSeries->setName("hindcast");
hindcastSeries->setColor(Qt::red);

interpolationSeries = new QLineSeries();
interpolationSeries->setName("interpolation");
interpolationSeries->setColor(Qt::black);

axisX = new QDateTimeAxis();
axisX->setFormat("yyyy/MM/dd");
axisY = new QValueAxis();
axisY->setReverse(true);

chart()->addAxis(axisX, Qt::AlignBottom);
chart()->addAxis(axisY, Qt::AlignLeft);
chart()->setDropShadowEnabled(false);

chart()->legend()->setVisible(true);
chart()->legend()->setAlignment(Qt::AlignBottom);
m_tooltip = new Callout(chart());
m_tooltip->hide();
}

void WaterTableChartView::draw(std::vector<QDate> myDates, std::vector<float> myHindcastSeries, std::vector<float> myInterpolateSeries, QMap<QDate, int> obsDepths)
{

int nDays = myDates.size();
QDateTime myDateTime;
myDateTime.setTime(QTime(0,0));
for (int day = 0; day < nDays; day++)
{
myDateTime.setDate(myDates[day]);
hindcastSeries->append(myDateTime.toMSecsSinceEpoch(), myHindcastSeries[day]);
interpolationSeries->append(myDateTime.toMSecsSinceEpoch(), myInterpolateSeries[day]);

if(obsDepths.contains(myDates[day]))
{
int myDepth = obsDepths[myDates[day]];
obsDepthSeries->append(myDateTime.toMSecsSinceEpoch(), myDepth);
}
}


axisY->setMax(300);
axisY->setMin(0);
axisY->setLabelFormat("%d");

QDateTime firstDateTime;
firstDateTime.setDate(myDates[0]);
firstDateTime.setTime(QTime(0,0));
QDateTime lastDateTime;
lastDateTime.setDate(myDates[myDates.size()-1]);
lastDateTime.setTime(QTime(0,0));

axisX->setTickCount(12);
axisX->setMin(firstDateTime);
axisX->setMax(lastDateTime);

chart()->addSeries(obsDepthSeries);
chart()->addSeries(hindcastSeries);
chart()->addSeries(interpolationSeries);

connect(obsDepthSeries, &QScatterSeries::hovered, this, &WaterTableChartView::tooltipObsDepthSeries);
connect(hindcastSeries, &QLineSeries::hovered, this, &WaterTableChartView::tooltipLineSeries);
connect(interpolationSeries, &QLineSeries::hovered, this, &WaterTableChartView::tooltipLineSeries);
foreach(QLegendMarker* marker, chart()->legend()->markers())
{
marker->setVisible(true);
marker->series()->setVisible(true);
QObject::connect(marker, &QLegendMarker::clicked, this, &WaterTableChartView::handleMarkerClicked);
}
return;
}

void WaterTableChartView::tooltipObsDepthSeries(QPointF point, bool state)
{

auto serie = qobject_cast<QScatterSeries *>(sender());
if (state)
{
QDateTime firstDate(QDate(1970,1,1), QTime(0,0,0));
QDateTime xValue = firstDate.addMSecs(point.x());
double yValue = point.y();

m_tooltip->setText(QString("%1: %2").arg(xValue.date().toString("yyyy/MM/dd")).arg(yValue, 0, 'd'));
m_tooltip->setSeries(serie);
m_tooltip->setAnchor(point);
m_tooltip->setZValue(11);
m_tooltip->updateGeometry();
m_tooltip->show();
}
else
{
m_tooltip->hide();
}
}

void WaterTableChartView::tooltipLineSeries(QPointF point, bool state)
{

auto serie = qobject_cast<QLineSeries *>(sender());
if (state)
{
QDateTime firstDate(QDate(1970,1,1), QTime(0,0,0));
QDateTime xValue = firstDate.addMSecs(point.x());
double yValue = point.y();

m_tooltip->setText(QString("%1: %2").arg(xValue.date().toString("yyyy/MM/dd")).arg(yValue, 0, 'd'));
m_tooltip->setSeries(serie);
m_tooltip->setAnchor(point);
m_tooltip->setZValue(11);
m_tooltip->updateGeometry();
m_tooltip->show();
}
else
{
m_tooltip->hide();
}
}

void WaterTableChartView::handleMarkerClicked()
{

QLegendMarker* marker = qobject_cast<QLegendMarker*> (sender());

// Toggle visibility of series
bool isVisible = marker->series()->isVisible();
marker->series()->setVisible(!isVisible);

// Turn legend marker back to visible, since otherwise hiding series also hides the marker
marker->setVisible(true);

// change marker alpha, if series is not visible
qreal alpha;
if (isVisible)
{
alpha = 0.5;
}
else
{
alpha = 1.0;
}

QColor color;
QBrush brush = marker->labelBrush();
color = brush.color();
color.setAlphaF(alpha);
brush.setColor(color);
marker->setLabelBrush(brush);

brush = marker->brush();
color = brush.color();
color.setAlphaF(alpha);
brush.setColor(color);
marker->setBrush(brush);

QPen pen = marker->pen();
color = pen.color();
color.setAlphaF(alpha);
pen.setColor(color);
marker->setPen(pen);

}
26 changes: 26 additions & 0 deletions agrolib/waterTable/waterTableChartView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef WATERTABLECHARTVIEW_H
#define WATERTABLECHARTVIEW_H

#include <QtWidgets>
#include <QtCharts>
#include "waterTable.h"
#include "callout.h"

class WaterTableChartView : public QChartView
{
public:
WaterTableChartView(QWidget *parent = 0);
void draw(std::vector<QDate> myDates, std::vector<float> myHindcastSeries, std::vector<float> myInterpolateSeries, QMap<QDate, int> obsDepths);
void tooltipObsDepthSeries(QPointF point, bool state);
void tooltipLineSeries(QPointF point, bool state);
void handleMarkerClicked();
private:
QScatterSeries* obsDepthSeries;
QLineSeries* hindcastSeries;
QLineSeries* interpolationSeries;
QDateTimeAxis* axisX;
QValueAxis* axisY;
Callout *m_tooltip;
};

#endif // WATERTABLECHARTVIEW_H
Loading

0 comments on commit 6f2530f

Please sign in to comment.