From 218f765c487dbcc8ae98c5ba76b65a2446daf8a2 Mon Sep 17 00:00:00 2001 From: Fausto Tomei Date: Sat, 28 Oct 2023 17:00:23 +0200 Subject: [PATCH 1/3] .. --- criteriaModel/criteria1DProject.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/criteriaModel/criteria1DProject.cpp b/criteriaModel/criteria1DProject.cpp index 05ec9616..b4227423 100644 --- a/criteriaModel/criteria1DProject.cpp +++ b/criteriaModel/criteria1DProject.cpp @@ -7,7 +7,6 @@ #include "cropDbTools.h" #include "cropDbQuery.h" #include "criteria1DMeteo.h" -#include "water1D.h" #include "utilities.h" #include From 13ba7e6f9f08331eba0e5ed76eecbdf35c409855 Mon Sep 17 00:00:00 2001 From: Fausto Tomei Date: Sat, 28 Oct 2023 19:26:24 +0200 Subject: [PATCH 2/3] fix locale decimal separator --- criteria1DWidget/criteria1DWidget.cpp | 319 +++++++++++++------------- criteria1DWidget/criteria1DWidget.h | 14 +- criteriaModel/criteria1DMeteo.cpp | 14 +- criteriaModel/criteria1DMeteo.h | 2 +- crop/crop.cpp | 14 +- crop/crop.h | 2 - crop/root.h | 5 +- 7 files changed, 187 insertions(+), 183 deletions(-) diff --git a/criteria1DWidget/criteria1DWidget.cpp b/criteria1DWidget/criteria1DWidget.cpp index 96190ace..668888f9 100644 --- a/criteria1DWidget/criteria1DWidget.cpp +++ b/criteria1DWidget/criteria1DWidget.cpp @@ -51,7 +51,7 @@ Criteria1DWidget::Criteria1DWidget() { - resize(1200, 700); + resize(1000, 800); setWindowState(Qt::WindowMaximized); // font @@ -91,15 +91,19 @@ Criteria1DWidget::Criteria1DWidget() QPixmap savePixmap; QPixmap updatePixmap; - if (QFileInfo(saveButtonPath).exists()) + if (QFileInfo::exists(saveButtonPath)) + { savePixmap.load(saveButtonPath); + } else { QMessageBox::critical(nullptr, "errorStr", "missing file: img/saveButton.png"); } - if (QFileInfo(updateButtonPath).exists()) + if (QFileInfo::exists(updateButtonPath)) + { updatePixmap.load(updateButtonPath); + } else { QMessageBox::critical(nullptr, "errorStr", "missing file: img/updateButton.png"); @@ -247,14 +251,14 @@ Criteria1DWidget::Criteria1DWidget() degreeDaysEmergenceValue->setValidator(positiveValidator); QLabel *degreeDaysLAIinc = new QLabel(tr("degree days phase 1 [°C]: ")); - degreeDaysLAIincValue = new QLineEdit(); - degreeDaysLAIincValue->setMaximumWidth(laiParametersGroup->width()/5); - degreeDaysLAIincValue->setValidator(positiveValidator); + degreeDaysLaiIncreaseValue = new QLineEdit(); + degreeDaysLaiIncreaseValue->setMaximumWidth(laiParametersGroup->width()/5); + degreeDaysLaiIncreaseValue->setValidator(positiveValidator); QLabel *degreeDaysLAIdec = new QLabel(tr("degree days phase 2 [°C]: ")); - degreeDaysLAIdecValue = new QLineEdit(); - degreeDaysLAIdecValue->setMaximumWidth(laiParametersGroup->width()/5); - degreeDaysLAIdecValue->setValidator(positiveValidator); + degreeDaysLaiDecreaseValue = new QLineEdit(); + degreeDaysLaiDecreaseValue->setMaximumWidth(laiParametersGroup->width()/5); + degreeDaysLaiDecreaseValue->setValidator(positiveValidator); QLabel *LAIcurveA = new QLabel(tr("LAI curve factor A [-]: ")); LAIcurveAValue = new QLineEdit(); @@ -284,9 +288,9 @@ Criteria1DWidget::Criteria1DWidget() parametersLaiLayout->addWidget(degreeDaysEmergence, 6, 0); parametersLaiLayout->addWidget(degreeDaysEmergenceValue, 6, 1); parametersLaiLayout->addWidget(degreeDaysLAIinc, 7, 0); - parametersLaiLayout->addWidget(degreeDaysLAIincValue, 7, 1); + parametersLaiLayout->addWidget(degreeDaysLaiIncreaseValue, 7, 1); parametersLaiLayout->addWidget(degreeDaysLAIdec, 8, 0); - parametersLaiLayout->addWidget(degreeDaysLAIdecValue, 8, 1); + parametersLaiLayout->addWidget(degreeDaysLaiDecreaseValue, 8, 1); parametersLaiLayout->addWidget(LAIcurveA, 9, 0); parametersLaiLayout->addWidget(LAIcurveAValue, 9, 1); parametersLaiLayout->addWidget(LAIcurveB, 10, 0); @@ -308,7 +312,7 @@ Criteria1DWidget::Criteria1DWidget() rootShapeComboBox = new QComboBox(); rootShapeComboBox->setMaximumWidth(rootParametersGroup->width()/3); - for (int i=0; i < numRootDistributionType; i++) + for (int i=0; i < nrRootDistributionType; i++) { rootDistributionType type = rootDistributionType(i); rootShapeComboBox->addItem(QString::fromStdString(root::getRootDistributionTypeString(type))); @@ -322,10 +326,10 @@ Criteria1DWidget::Criteria1DWidget() shapeDeformationValue->setDecimals(1); shapeDeformationValue->setSingleStep(0.1); - rootDegreeDaysInc = new QLabel(tr("degree days root inc [°C]: ")); - rootDegreeDaysIncValue = new QLineEdit(); - rootDegreeDaysIncValue->setMaximumWidth(rootParametersGroup->width()/5); - rootDegreeDaysIncValue->setValidator(positiveValidator); + rootDegreeDaysGrowth = new QLabel(tr("degree days root inc [°C]: ")); + rootDegreeDaysGrowthValue = new QLineEdit(); + rootDegreeDaysGrowthValue->setMaximumWidth(rootParametersGroup->width()/5); + rootDegreeDaysGrowthValue->setValidator(positiveValidator); parametersRootDepthLayout->addWidget(rootDepthZero, 0, 0); parametersRootDepthLayout->addWidget(rootDepthZeroValue, 0, 1); @@ -335,12 +339,12 @@ Criteria1DWidget::Criteria1DWidget() parametersRootDepthLayout->addWidget(rootShapeComboBox, 2, 1); parametersRootDepthLayout->addWidget(shapeDeformation, 3, 0); parametersRootDepthLayout->addWidget(shapeDeformationValue, 3, 1); - parametersRootDepthLayout->addWidget(rootDegreeDaysInc, 4, 0); - parametersRootDepthLayout->addWidget(rootDegreeDaysIncValue, 4, 1); + parametersRootDepthLayout->addWidget(rootDegreeDaysGrowth, 4, 0); + parametersRootDepthLayout->addWidget(rootDegreeDaysGrowthValue, 4, 1); QLabel *irrigationVolume = new QLabel(tr("irrigation quantity [mm]: ")); irrigationVolumeValue = new QLineEdit(); - irrigationVolumeValue->setText(QString::number(0)); + irrigationVolumeValue->setText(QLocale().toString(0)); irrigationVolumeValue->setMaximumWidth(irrigationParametersGroup->width()/5); irrigationVolumeValue->setValidator(positiveValidator); QLabel *irrigationShift = new QLabel(tr("irrigation shift [days]: ")); @@ -509,7 +513,8 @@ Criteria1DWidget::Criteria1DWidget() viewMenu->addAction(viewWeather); viewMenu->addAction(viewSoil); - cropChanged = false; + isCropChanged = false; + isOnlyOneYear = false; connect(openProject, &QAction::triggered, this, &Criteria1DWidget::on_actionOpenProject); connect(newProject, &QAction::triggered, this, &Criteria1DWidget::on_actionNewProject); @@ -609,6 +614,7 @@ void Criteria1DWidget::on_actionOpenProject() isRedraw = true; } + void Criteria1DWidget::on_actionNewProject() { DialogNewProject dialog; @@ -633,7 +639,7 @@ void Criteria1DWidget::on_actionNewProject() if (confirm == QMessageBox::Yes) { clearDir(completePath); - QDir().mkdir(completePath+"/data"); + QDir().mkdir(completePath + "/data"); } else { @@ -648,7 +654,7 @@ void Criteria1DWidget::on_actionNewProject() if (!QFile::copy(dataPath + PATH_TEMPLATE + "template_comp_units.db", completePath + "/data/" + "comp_units.db")) { - QMessageBox::critical(nullptr, "Error", "Copy failed: template_comp_units.db"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying template_comp_units.db"); return; } QString db_soil, db_meteo, db_crop; @@ -658,16 +664,16 @@ void Criteria1DWidget::on_actionNewProject() db_soil = "soil.db"; if (!QFile::copy(dataPath + PATH_TEMPLATE + "template_soil.db", completePath + "/data/" + db_soil)) { - QMessageBox::critical(nullptr, "Error", "Copy failed: template_soil.db"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying template_soil.db"); return; } } else if (dialog.getSoilDbOption() == DEFAULT_DB) { - db_soil = "soil_ER_2002.db"; - if (!QFile::copy(dataPath+"SOIL/soil_ER_2002.db", completePath+"/data/"+db_soil)) + db_soil = "soil_ER_2021.db"; + if (!QFile::copy(dataPath + "SOIL/soil_ER_2021.db", completePath + "/data/" + db_soil)) { - QMessageBox::critical(nullptr, "Error in copy soil_ER_2002.db", "Copy failed"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying soil_ER_2021.db"); return; } } @@ -677,7 +683,7 @@ void Criteria1DWidget::on_actionNewProject() db_soil = QFileInfo(soilPath).baseName()+".db"; if (!QFile::copy(soilPath, completePath+"/data/"+db_soil)) { - QMessageBox::critical(nullptr, "Error in copy "+soilPath, "Copy failed"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying " + soilPath); return; } } @@ -685,9 +691,9 @@ void Criteria1DWidget::on_actionNewProject() if (dialog.getMeteoDbOption() == NEW_DB) { db_meteo = "meteo.db"; - if (!QFile::copy(dataPath+PATH_TEMPLATE+"template_meteo.db", completePath+"/data/"+db_meteo)) + if (!QFile::copy(dataPath +PATH_TEMPLATE + "template_meteo.db", completePath + "/data/" + db_meteo)) { - QMessageBox::critical(nullptr, "Error in copy template_meteo.db", "Copy failed"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying template_meteo.db"); return; } } @@ -696,17 +702,17 @@ void Criteria1DWidget::on_actionNewProject() db_meteo = "meteo.db"; if (!QFile::copy(dataPath+PATH_PROJECT+"test/data/meteo.db", completePath+"/data/"+db_meteo)) { - QMessageBox::critical(nullptr, "Error in copy meteo.db", "Copy failed"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying meteo.db"); return; } } else if (dialog.getMeteoDbOption() == CHOOSE_DB) { QString meteoPath = dialog.getDbMeteoCompletePath(); - db_meteo = QFileInfo(meteoPath).baseName()+".db"; - if (!QFile::copy(meteoPath, completePath+"/data/"+db_meteo)) + db_meteo = QFileInfo(meteoPath).baseName() + ".db"; + if (!QFile::copy(meteoPath, completePath + "/data/" + db_meteo)) { - QMessageBox::critical(nullptr, "Error in copy "+meteoPath, "Copy failed"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying " + meteoPath); return; } } @@ -714,9 +720,9 @@ void Criteria1DWidget::on_actionNewProject() if (dialog.getCropDbOption() == DEFAULT_DB) { db_crop = "crop.db"; - if (!QFile::copy(dataPath+PATH_TEMPLATE+"crop_default.db", completePath+"/data/"+"crop.db")) + if (!QFile::copy(dataPath + PATH_TEMPLATE + "crop_default.db", completePath + "/data/" + "crop.db")) { - QMessageBox::critical(nullptr, "Error", "Copy failed: crop_default.db"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying crop_default.db"); return; } } @@ -726,10 +732,11 @@ void Criteria1DWidget::on_actionNewProject() db_crop = QFileInfo(cropPath).baseName()+".db"; if (!QFile::copy(cropPath, completePath+"/data/"+db_crop)) { - QMessageBox::critical(nullptr, "Error in copy "+cropPath, "Copy failed"); + QMessageBox::critical(nullptr, "Copy failed", "Error in copying " + cropPath); return; } } + // write .ini QSettings* projectSetting = new QSettings(dataPath+PATH_PROJECT+projectName+"/"+projectName+".ini", QSettings::IniFormat); projectSetting->beginGroup("software"); @@ -738,17 +745,16 @@ void Criteria1DWidget::on_actionNewProject() projectSetting->beginGroup("project"); projectSetting->setValue("path", "./"); projectSetting->setValue("name", projectName); - projectSetting->setValue("db_soil", "./data/"+db_soil); - projectSetting->setValue("db_meteo", "./data/"+db_meteo); - projectSetting->setValue("db_crop", "./data/"+db_crop); + projectSetting->setValue("db_soil", "./data/" + db_soil); + projectSetting->setValue("db_meteo", "./data/" + db_meteo); + projectSetting->setValue("db_crop", "./data/" + db_crop); projectSetting->setValue("db_comp_units", "./data/comp_units.db"); - projectSetting->setValue("db_output", "./output/"+projectName+".db"); + projectSetting->setValue("db_output", "./output/" + projectName + ".db"); projectSetting->endGroup(); projectSetting->sync(); - } - QMessageBox::information(nullptr, "Success", "project created: " + dataPath+PATH_PROJECT+projectName); + QMessageBox::information(nullptr, "Success!", "project created: " + dataPath + PATH_PROJECT + projectName); } } @@ -770,7 +776,7 @@ void Criteria1DWidget::checkCropUpdate() { if (!myProject.myCase.crop.idCrop.empty()) { - if (checkIfCropIsChanged()) + if (checkCropIsChanged()) { QString idCropChanged = QString::fromStdString(myProject.myCase.crop.idCrop); QMessageBox::StandardButton confirm; @@ -784,7 +790,7 @@ void Criteria1DWidget::checkCropUpdate() if (saveCrop()) { // already saved - cropChanged = false; + isCropChanged = false; } } } @@ -1082,7 +1088,7 @@ void Criteria1DWidget::on_actionChooseCrop(QString idCrop) { return; } - if (checkIfCropIsChanged()) + if (checkCropIsChanged()) { QString idCropChanged = QString::fromStdString(myProject.myCase.crop.idCrop); QMessageBox::StandardButton confirm; @@ -1095,7 +1101,7 @@ void Criteria1DWidget::on_actionChooseCrop(QString idCrop) { if (saveCrop()) { - cropChanged = false; //already saved + isCropChanged = false; //already saved } } } @@ -1144,7 +1150,7 @@ void Criteria1DWidget::updateCropParam(QString idCrop) cropSowingValue->setVisible(false); cropCycleMaxValue->setVisible(false); } - maxKcValue->setText(QString::number(myProject.myCase.crop.kcMax)); + maxKcValue->setText(QLocale().toString(myProject.myCase.crop.kcMax)); // LAI parameters LAIminValue->setValue(myProject.myCase.crop.LAImin); @@ -1153,39 +1159,40 @@ void Criteria1DWidget::updateCropParam(QString idCrop) { LAIgrass->setVisible(true); LAIgrassValue->setVisible(true); - LAIgrassValue->setText(QString::number(myProject.myCase.crop.LAIgrass)); + LAIgrassValue->setText(QLocale().toString(myProject.myCase.crop.LAIgrass)); } else { LAIgrass->setVisible(false); LAIgrassValue->setVisible(false); } - thermalThresholdValue->setText(QString::number(myProject.myCase.crop.thermalThreshold)); - upperThermalThresholdValue->setText(QString::number(myProject.myCase.crop.upperThermalThreshold)); + thermalThresholdValue->setText(QLocale().toString(myProject.myCase.crop.thermalThreshold)); + upperThermalThresholdValue->setText(QLocale().toString(myProject.myCase.crop.upperThermalThreshold)); degreeDaysEmergenceValue->setText(QString::number(myProject.myCase.crop.degreeDaysEmergence)); - degreeDaysLAIincValue->setText(QString::number(myProject.myCase.crop.degreeDaysIncrease)); - degreeDaysLAIdecValue->setText(QString::number(myProject.myCase.crop.degreeDaysDecrease)); - LAIcurveAValue->setText(QString::number(myProject.myCase.crop.LAIcurve_a)); - LAIcurveBValue->setText(QString::number(myProject.myCase.crop.LAIcurve_b)); + degreeDaysLaiIncreaseValue->setText(QString::number(myProject.myCase.crop.degreeDaysIncrease)); + degreeDaysLaiDecreaseValue->setText(QString::number(myProject.myCase.crop.degreeDaysDecrease)); + LAIcurveAValue->setText(QLocale().toString(myProject.myCase.crop.LAIcurve_a)); + LAIcurveBValue->setText(QLocale().toString(myProject.myCase.crop.LAIcurve_b)); // root parameters - rootDepthZeroValue->setText(QString::number(myProject.myCase.crop.roots.rootDepthMin)); - rootDepthMaxValue->setText(QString::number(myProject.myCase.crop.roots.rootDepthMax)); + rootDepthZeroValue->setText(QLocale().toString(myProject.myCase.crop.roots.rootDepthMin)); + rootDepthMaxValue->setText(QLocale().toString(myProject.myCase.crop.roots.rootDepthMax)); shapeDeformationValue->setValue(myProject.myCase.crop.roots.shapeDeformation); rootShapeComboBox->setCurrentText(QString::fromStdString(root::getRootDistributionTypeString(myProject.myCase.crop.roots.rootShape))); + if (myProject.myCase.crop.isRootStatic()) { - rootDegreeDaysInc->setVisible(false); - rootDegreeDaysIncValue->setVisible(false); + rootDegreeDaysGrowth->setVisible(false); + rootDegreeDaysGrowthValue->setVisible(false); } else { - rootDegreeDaysInc->setVisible(true); - rootDegreeDaysIncValue->setVisible(true); - rootDegreeDaysIncValue->setText(QString::number(myProject.myCase.crop.roots.degreeDaysRootGrowth)); + rootDegreeDaysGrowth->setVisible(true); + rootDegreeDaysGrowthValue->setVisible(true); + rootDegreeDaysGrowthValue->setText(QString::number(myProject.myCase.crop.roots.degreeDaysRootGrowth)); } // irrigation parameters - irrigationVolumeValue->setText(QString::number(myProject.myCase.crop.irrigationVolume)); + irrigationVolumeValue->setText(QLocale().toString(myProject.myCase.crop.irrigationVolume)); if (irrigationVolumeValue->text() == "0") { irrigationShiftValue->setValue(0); @@ -1195,7 +1202,7 @@ void Criteria1DWidget::updateCropParam(QString idCrop) degreeDaysEndValue->setText(nullptr); degreeDaysEndValue->setEnabled(false); } - else if (irrigationVolumeValue->text().toDouble() > 0) + else if (QLocale().toDouble(irrigationVolumeValue->text()) > 0) { irrigationShiftValue->setEnabled(true); irrigationShiftValue->setValue(myProject.myCase.crop.irrigationShift); @@ -1205,7 +1212,7 @@ void Criteria1DWidget::updateCropParam(QString idCrop) degreeDaysEndValue->setText(QString::number(myProject.myCase.crop.degreeDaysEndIrrigation)); } // water stress parameters - psiLeafValue->setText(QString::number(myProject.myCase.crop.psiLeaf)); + psiLeafValue->setText(QLocale().toString(myProject.myCase.crop.psiLeaf)); rawFractionValue->setValue(myProject.myCase.crop.fRAW); stressToleranceValue->setValue(myProject.myCase.crop.stressTolerance); @@ -1215,7 +1222,6 @@ void Criteria1DWidget::updateCropParam(QString idCrop) void Criteria1DWidget::on_actionChooseMeteo(QString idMeteo) { - if (idMeteo.isEmpty()) { return; @@ -1338,18 +1344,19 @@ void Criteria1DWidget::on_actionChooseMeteo(QString idMeteo) // store last Date getLastDate(&(myProject.dbMeteo), meteoTableName, yearList[yearList.size()-1], &myProject.lastSimulationDate, &errorStr); } + if (yearList.size() == 1) { - onlyOneYear = true; - yearList.insert(0,QString::number(yearList[0].toInt()-1)); + isOnlyOneYear = true; + yearList.insert(0, QString::number(yearList[0].toInt()-1)); } else { - onlyOneYear = false; + isOnlyOneYear = false; } // add year if exists previous year - for (int i = 1; ifirstYearListComboBox.currentText().toInt() > MAX_YEARS) { - QString msg = "Period too long: maximum " + QString::number(MAX_YEARS) + " years"; + QString msg = "Period is too long: maximum " + QString::number(MAX_YEARS) + " years"; QMessageBox::information(nullptr, "Error", msg); - int max = this->firstYearListComboBox.currentText().toInt() + MAX_YEARS; - this->lastYearListComboBox.setCurrentText(QString::number(max)); + int maxYear = this->firstYearListComboBox.currentText().toInt() + MAX_YEARS; + this->lastYearListComboBox.setCurrentText(QString::number(maxYear)); return; } updateMeteoPointValues(); @@ -1471,7 +1478,7 @@ void Criteria1DWidget::updateMeteoPointValues() waterDepth = myProject.observedMeteoGrid->meteoGrid()->meteoPointPointer(row, col)->getMeteoPointValueD(myDate, dailyWaterTableDepth); myProject.myCase.meteoPoint.setMeteoPointValueD(myDate, dailyWaterTableDepth, waterDepth); } - if (onlyOneYear) + if (isOnlyOneYear) { // copy values to prev years Crit3DDate myDate = getCrit3DDate(lastDate); @@ -1490,16 +1497,17 @@ void Criteria1DWidget::updateMeteoPointValues() } else { - if (onlyOneYear) + if (isOnlyOneYear) { - if (!fillDailyTempPrecCriteria1D(&(myProject.dbMeteo), meteoTableName, &(myProject.myCase.meteoPoint), QString::number(lastYear), &errorStr)) + if (!fillDailyTempPrecCriteria1D(&(myProject.dbMeteo), meteoTableName, &(myProject.myCase.meteoPoint), lastYear, &errorStr)) { - QMessageBox::critical(nullptr, "Error!", errorStr + " year: " + QString::number(firstYear)); + QMessageBox::critical(nullptr, "Error! ", errorStr + " year: " + QString::number(lastYear)); return; } - // copy values to prev years + // copy values to previous year Crit3DDate myDate = getCrit3DDate(lastDate); Crit3DDate prevDate = getCrit3DDate(firstDate); + for (int i = 0; i < lastDate.daysInYear(); i++) { prevDate = getCrit3DDate(firstDate).addDays(i); @@ -1516,10 +1524,10 @@ void Criteria1DWidget::updateMeteoPointValues() // fill meteoPoint for (int year = firstYear; year <= lastYear; year++) { - if (!fillDailyTempPrecCriteria1D(&(myProject.dbMeteo), meteoTableName, - &(myProject.myCase.meteoPoint), QString::number(year), &errorStr)) + if (! fillDailyTempPrecCriteria1D(&(myProject.dbMeteo), meteoTableName, + &(myProject.myCase.meteoPoint), year, &errorStr)) { - QMessageBox::critical(nullptr, "Error!", errorStr + " year: " + QString::number(firstYear)); + QMessageBox::critical(nullptr, "Error! ", errorStr + " year: " + QString::number(year)); return; } } @@ -1532,6 +1540,7 @@ void Criteria1DWidget::updateMeteoPointValues() } } + void Criteria1DWidget::on_actionChooseSoil(QString soilCode) { // soilListComboBox has been cleared @@ -1608,7 +1617,7 @@ void Criteria1DWidget::on_actionDeleteCrop() void Criteria1DWidget::on_actionRestoreData() { - if (checkIfCropIsChanged()) + if (checkCropIsChanged()) { myProject.myCase.crop = cropFromDB; updateCropParam(QString::fromStdString(myProject.myCase.crop.idCrop)); @@ -1627,7 +1636,7 @@ void Criteria1DWidget::on_actionSave() { if (saveCrop()) { - cropChanged = false; //already saved + isCropChanged = false; //already saved } } } @@ -1699,12 +1708,12 @@ void Criteria1DWidget::on_actionUpdate() bool Criteria1DWidget::updateCrop() { - if (myProject.myCase.crop.idCrop.empty()) { return false; } myProject.myCase.crop.type = getCropType(cropTypeValue->text().toStdString()); + // sowing if (cropSowing.isVisible()) { myProject.myCase.crop.sowingDoy = cropSowingValue->value(); @@ -1715,28 +1724,32 @@ bool Criteria1DWidget::updateCrop() myProject.myCase.crop.sowingDoy = NODATA; myProject.myCase.crop.plantCycle = NODATA; } - myProject.myCase.crop.kcMax = maxKcValue->text().toDouble(); + + myProject.myCase.crop.kcMax = QLocale().toDouble(maxKcValue->text()); + + // LAI myProject.myCase.crop.LAImin = LAIminValue->value(); myProject.myCase.crop.LAImax = LAImaxValue->value(); if (myProject.myCase.crop.type == TREE) { - myProject.myCase.crop.LAIgrass = LAIgrassValue->text().toDouble(); + myProject.myCase.crop.LAIgrass = QLocale().toDouble(LAIgrassValue->text()); } else { myProject.myCase.crop.LAIgrass = NODATA; } - myProject.myCase.crop.thermalThreshold = thermalThresholdValue->text().toDouble(); - myProject.myCase.crop.upperThermalThreshold = upperThermalThresholdValue->text().toDouble(); + myProject.myCase.crop.thermalThreshold = QLocale().toDouble(thermalThresholdValue->text()); + myProject.myCase.crop.upperThermalThreshold = QLocale().toDouble(upperThermalThresholdValue->text()); + myProject.myCase.crop.LAIcurve_a = QLocale().toDouble(LAIcurveAValue->text()); + myProject.myCase.crop.LAIcurve_b = QLocale().toDouble(LAIcurveBValue->text()); + myProject.myCase.crop.degreeDaysEmergence = degreeDaysEmergenceValue->text().toDouble(); - myProject.myCase.crop.degreeDaysIncrease = degreeDaysLAIincValue->text().toDouble(); - myProject.myCase.crop.degreeDaysDecrease = degreeDaysLAIdecValue->text().toDouble(); - myProject.myCase.crop.LAIcurve_a = LAIcurveAValue->text().toDouble(); - myProject.myCase.crop.LAIcurve_b = LAIcurveBValue->text().toDouble(); + myProject.myCase.crop.degreeDaysIncrease = degreeDaysLaiIncreaseValue->text().toDouble(); + myProject.myCase.crop.degreeDaysDecrease = degreeDaysLaiDecreaseValue->text().toDouble(); // root - myProject.myCase.crop.roots.rootDepthMin = rootDepthZeroValue->text().toDouble(); - myProject.myCase.crop.roots.rootDepthMax = rootDepthMaxValue->text().toDouble(); + myProject.myCase.crop.roots.rootDepthMin = QLocale().toDouble(rootDepthZeroValue->text()); + myProject.myCase.crop.roots.rootDepthMax = QLocale().toDouble(rootDepthMaxValue->text()); myProject.myCase.crop.roots.shapeDeformation = shapeDeformationValue->value(); myProject.myCase.crop.roots.rootShape = root::getRootDistributionTypeFromString(rootShapeComboBox->currentText().toStdString()); if (myProject.myCase.crop.isRootStatic()) @@ -1745,8 +1758,9 @@ bool Criteria1DWidget::updateCrop() } else { - myProject.myCase.crop.roots.degreeDaysRootGrowth = rootDegreeDaysIncValue->text().toDouble(); + myProject.myCase.crop.roots.degreeDaysRootGrowth = rootDegreeDaysGrowthValue->text().toInt(); } + // irrigation QString errorStr; if (irrigationVolumeValue->text().isEmpty()) @@ -1763,7 +1777,7 @@ bool Criteria1DWidget::updateCrop() myProject.myCase.crop.degreeDaysEndIrrigation = NODATA; } - else if (irrigationVolumeValue->text().toDouble() > 0) + else if (QLocale().toDouble(irrigationVolumeValue->text()) > 0) { if (irrigationShiftValue->value() == 0) { @@ -1777,17 +1791,17 @@ bool Criteria1DWidget::updateCrop() QMessageBox::critical(nullptr, "Error irrigation update", errorStr); return false; } - myProject.myCase.crop.irrigationVolume = irrigationVolumeValue->text().toDouble(); + myProject.myCase.crop.irrigationVolume = QLocale().toDouble(irrigationVolumeValue->text()); myProject.myCase.crop.irrigationShift = irrigationShiftValue->value(); myProject.myCase.crop.degreeDaysStartIrrigation = degreeDaysStartValue->text().toInt(); myProject.myCase.crop.degreeDaysEndIrrigation = degreeDaysEndValue->text().toInt(); } // water stress - myProject.myCase.crop.psiLeaf = psiLeafValue->text().toDouble(); + myProject.myCase.crop.psiLeaf = QLocale().toDouble(psiLeafValue->text()); myProject.myCase.crop.fRAW = rawFractionValue->value(); myProject.myCase.crop.stressTolerance = stressToleranceValue->value(); - cropChanged = true; + isCropChanged = true; return true; } @@ -1804,17 +1818,12 @@ void Criteria1DWidget::on_actionNewCrop() Crit3DCrop* newCrop = new Crit3DCrop(); DialogNewCrop dialog(newCrop); - if (dialog.result() != QDialog::Accepted) + if (dialog.result() == QDialog::Accepted) { - delete newCrop; - return; - } - else - { - // TODO - // write newCrop on Db - delete newCrop; + // write newCrop on Db } + + delete newCrop; } @@ -1993,92 +2002,100 @@ void Criteria1DWidget::tabChanged(int index) } -bool Criteria1DWidget::checkIfCropIsChanged() +bool Criteria1DWidget::checkCropIsChanged() { // check all editable fields if (myProject.myCase.crop.idCrop.empty()) { - cropChanged = false; - return cropChanged; + isCropChanged = false; + return isCropChanged; } if(cropSowingValue->isVisible()) { if (cropFromDB.sowingDoy != cropSowingValue->value() || cropFromDB.plantCycle != cropCycleMaxValue->value()) { - cropChanged = true; - return cropChanged; + isCropChanged = true; + return isCropChanged; } } // LAI if (cropFromDB.LAImin != LAIminValue->value() || cropFromDB.LAImax != LAImaxValue->value()) { - cropChanged = true; - return cropChanged; + isCropChanged = true; + return isCropChanged; } - if (cropFromDB.type == TREE && cropFromDB.LAIgrass != LAIgrassValue->text().toDouble()) + if (cropFromDB.type == TREE && cropFromDB.LAIgrass != QLocale().toDouble(LAIgrassValue->text())) { - cropChanged = true; - return cropChanged; + isCropChanged = true; + return isCropChanged; } + // degree days - if (cropFromDB.thermalThreshold != thermalThresholdValue->text().toDouble() - || cropFromDB.upperThermalThreshold != upperThermalThresholdValue->text().toDouble() + if ( ! isEqual(cropFromDB.thermalThreshold, QLocale().toDouble(thermalThresholdValue->text())) + || ! isEqual(cropFromDB.upperThermalThreshold, QLocale().toDouble(upperThermalThresholdValue->text())) + || ! isEqual(cropFromDB.LAIcurve_a, QLocale().toDouble(LAIcurveAValue->text())) + || ! isEqual(cropFromDB.LAIcurve_b, QLocale().toDouble(LAIcurveBValue->text())) || cropFromDB.degreeDaysEmergence != degreeDaysEmergenceValue->text().toDouble() - || cropFromDB.degreeDaysIncrease != degreeDaysLAIincValue->text().toDouble() - || cropFromDB.degreeDaysDecrease != degreeDaysLAIdecValue->text().toDouble() - || cropFromDB.LAIcurve_a != LAIcurveAValue->text().toDouble() - || cropFromDB.LAIcurve_b != LAIcurveBValue->text().toDouble()) + || cropFromDB.degreeDaysIncrease != degreeDaysLaiIncreaseValue->text().toDouble() + || cropFromDB.degreeDaysDecrease != degreeDaysLaiDecreaseValue->text().toDouble() ) { - cropChanged = true; - return cropChanged; + isCropChanged = true; + return isCropChanged; } + // roots - if(! isEqual(cropFromDB.roots.rootDepthMin, rootDepthZeroValue->text().toDouble()) - || ! isEqual(cropFromDB.roots.rootDepthMax, rootDepthMaxValue->text().toDouble()) + if(! isEqual(cropFromDB.roots.rootDepthMin, QLocale().toDouble(rootDepthZeroValue->text())) + || ! isEqual(cropFromDB.roots.rootDepthMax, QLocale().toDouble(rootDepthMaxValue->text())) || ! isEqual(cropFromDB.roots.shapeDeformation, shapeDeformationValue->value()) || cropFromDB.roots.rootShape != root::getRootDistributionTypeFromString(rootShapeComboBox->currentText().toStdString())) { - cropChanged = true; - return cropChanged; + isCropChanged = true; + return isCropChanged; } - if (!cropFromDB.isRootStatic() && cropFromDB.roots.degreeDaysRootGrowth != rootDegreeDaysIncValue->text().toDouble()) + if (! cropFromDB.isRootStatic()) { - cropChanged = true; - return cropChanged; + if ( cropFromDB.roots.degreeDaysRootGrowth != rootDegreeDaysGrowthValue->text().toInt() ) + { + isCropChanged = true; + return isCropChanged; + } } + // water needs - if( cropFromDB.kcMax != maxKcValue->text().toDouble() - || cropFromDB.psiLeaf != psiLeafValue->text().toDouble() + if( ! isEqual(cropFromDB.kcMax, QLocale().toDouble(maxKcValue->text())) + || ! isEqual(cropFromDB.psiLeaf, QLocale().toDouble(psiLeafValue->text())) || ! isEqual(cropFromDB.fRAW, rawFractionValue->value()) || ! isEqual(cropFromDB.stressTolerance, stressToleranceValue->value()) ) { - cropChanged = true; - return cropChanged; + isCropChanged = true; + return isCropChanged; } // irrigation parameters // TODO gestire caso irrigazioni azzerate if(irrigationShiftValue->isVisible()) { - if( cropFromDB.irrigationVolume != irrigationVolumeValue->text().toDouble() + if( isEqual(cropFromDB.irrigationVolume, QLocale().toDouble(irrigationVolumeValue->text())) || cropFromDB.irrigationShift != irrigationShiftValue->value() || cropFromDB.degreeDaysStartIrrigation != degreeDaysStartValue->text().toInt() || cropFromDB.degreeDaysEndIrrigation != degreeDaysEndValue->text().toInt() ) { - cropChanged = true; - return cropChanged; + isCropChanged = true; + return isCropChanged; } } - cropChanged = false; - return cropChanged; + isCropChanged = false; + return isCropChanged; } void Criteria1DWidget::irrigationVolumeChanged() { - if (irrigationVolumeValue->text().toDouble() == 0) + double irrigationVolume = QLocale().toDouble(irrigationVolumeValue->text()); + + if (irrigationVolume == 0) { irrigationShiftValue->setValue(0); irrigationShiftValue->setEnabled(false); @@ -2087,7 +2104,7 @@ void Criteria1DWidget::irrigationVolumeChanged() degreeDaysEndValue->setText(nullptr); degreeDaysEndValue->setEnabled(false); } - else if (irrigationVolumeValue->text().toDouble() > 0) + else if (irrigationVolume > 0) { irrigationShiftValue->setEnabled(true); irrigationShiftValue->setValue(cropFromDB.irrigationShift); @@ -2101,7 +2118,6 @@ void Criteria1DWidget::irrigationVolumeChanged() bool Criteria1DWidget::setMeteoSqlite(QString& errorStr) { - if (myProject.myCase.meteoPoint.id.empty()) return false; @@ -2114,7 +2130,7 @@ bool Criteria1DWidget::setMeteoSqlite(QString& errorStr) if (query.lastError().text() != "") errorStr = "dbMeteo errorStr: " + query.lastError().text(); else - errorStr = "Missing meteo table:" + meteoTableName; + errorStr = "Missing meteo table: " + meteoTableName; return false; } @@ -2122,17 +2138,7 @@ bool Criteria1DWidget::setMeteoSqlite(QString& errorStr) QDate firstDate = query.value("date").toDate(); query.last(); QDate lastDate = query.value("date").toDate(); - unsigned nrDays; - bool subQuery = false; - - nrDays = unsigned(firstDate.daysTo(lastDate)) + 1; - if (subQuery) - { - query.clear(); - queryString = "SELECT * FROM '" + meteoTableName + "' WHERE date BETWEEN '" - + firstDate.toString("yyyy-MM-dd") + "' AND '" + lastDate.toString("yyyy-MM-dd") + "'"; - query = myProject.dbMeteo.exec(queryString); - } + unsigned nrDays = unsigned(firstDate.daysTo(lastDate)) + 1; // Initialize data myProject.myCase.meteoPoint.initializeObsDataD(nrDays, getCrit3DDate(firstDate)); @@ -2146,7 +2152,6 @@ bool Criteria1DWidget::setMeteoSqlite(QString& errorStr) QMessageBox::warning(nullptr, "WARNING!", errorStr); return true; - } diff --git a/criteria1DWidget/criteria1DWidget.h b/criteria1DWidget/criteria1DWidget.h index 78a4ccf4..1c0d2cee 100644 --- a/criteria1DWidget/criteria1DWidget.h +++ b/criteria1DWidget/criteria1DWidget.h @@ -60,7 +60,7 @@ void updateTabCarbonNitrogen(); void tabChanged(int index); - bool checkIfCropIsChanged(); + bool checkCropIsChanged(); void irrigationVolumeChanged(); private: @@ -69,9 +69,9 @@ Crit3DCrop cropFromDB; QString meteoTableName; - bool cropChanged; + bool isCropChanged; QList yearList; - bool onlyOneYear; + bool isOnlyOneYear; Crit3DMeteoSettings meteoSettings; @@ -106,16 +106,16 @@ QLineEdit* thermalThresholdValue; QLineEdit* upperThermalThresholdValue; QLineEdit* degreeDaysEmergenceValue; - QLineEdit* degreeDaysLAIincValue; - QLineEdit* degreeDaysLAIdecValue; + QLineEdit* degreeDaysLaiIncreaseValue; + QLineEdit* degreeDaysLaiDecreaseValue; QLineEdit* LAIcurveAValue; QLineEdit* LAIcurveBValue; QLineEdit* rootDepthZeroValue; QLineEdit* rootDepthMaxValue; QComboBox* rootShapeComboBox; QDoubleSpinBox* shapeDeformationValue; - QLabel *rootDegreeDaysInc; - QLineEdit* rootDegreeDaysIncValue; + QLabel *rootDegreeDaysGrowth; + QLineEdit* rootDegreeDaysGrowthValue; QLineEdit* irrigationVolumeValue; QSpinBox* irrigationShiftValue; QLineEdit* degreeDaysStartValue; diff --git a/criteriaModel/criteria1DMeteo.cpp b/criteriaModel/criteria1DMeteo.cpp index 92974e67..4503b870 100644 --- a/criteriaModel/criteria1DMeteo.cpp +++ b/criteriaModel/criteria1DMeteo.cpp @@ -696,11 +696,11 @@ bool checkYearMeteoGrid(QSqlDatabase dbMeteo, QString tableD, QString fieldTime, } -bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, QString validYear, QString *error) +bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, int validYear, QString *error) { *error = ""; - QString queryString = "SELECT * FROM '" + table +"'" + " WHERE strftime('%Y',date) = '" + validYear +"'"; + QString queryString = "SELECT * FROM '" + table +"'" + " WHERE strftime('%Y',date) = '" + QString::number(validYear) +"'"; QSqlQuery query = dbMeteo->exec(queryString); query.first(); @@ -711,8 +711,8 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet } QDate date; - QDate previousDate(validYear.toInt()-1, 12, 31); - QDate lastDate(validYear.toInt(), 12, 31); + QDate previousDate(validYear-1, 12, 31); + QDate lastDate(validYear, 12, 31); float tmin = NODATA; float tmax = NODATA; float tavg = NODATA; @@ -725,7 +725,6 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet const float tmax_min = -40; const float tmax_max = 60; - do { getValue(query.value("date"), &date); @@ -767,7 +766,7 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet } while(query.next()); - QDate firstDate(validYear.toInt(), 1, 1); + QDate firstDate(validYear, 1, 1); int daysInYear = firstDate.daysInYear(); float prevTmin = NODATA; float prevTmax = NODATA; @@ -846,6 +845,7 @@ bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMet * \details date format: "yyyy-mm-dd" * \return true if data are correctly loaded * \note meteoPoint have to be initialized BEFORE function + * \note maxNrDays = NODATA: read all data */ bool readDailyDataCriteria1D(QSqlQuery &query, Crit3DMeteoPoint &meteoPoint, int maxNrDays, QString &error) { @@ -884,7 +884,7 @@ bool readDailyDataCriteria1D(QSqlQuery &query, Crit3DMeteoPoint &meteoPoint, int if (! myDate.isValid()) { - if (currentIndex < (maxNrDays-1)) + if (maxNrDays != NODATA && currentIndex < (maxNrDays-1)) { error = meteoID + "Wrong date format: " + query.value("date").toString(); return false; diff --git a/criteriaModel/criteria1DMeteo.h b/criteriaModel/criteria1DMeteo.h index 496d8e32..db0ad0fa 100644 --- a/criteriaModel/criteria1DMeteo.h +++ b/criteriaModel/criteria1DMeteo.h @@ -27,7 +27,7 @@ bool getLastDate(QSqlDatabase* dbMeteo, QString table, QString year, QDate* date, QString *error); bool getLastDateGrid(QSqlDatabase dbMeteo, QString table, QString fieldTime, QString year, QDate* date, QString *error); - bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, QString validYear, QString *error); + bool fillDailyTempPrecCriteria1D(QSqlDatabase* dbMeteo, QString table, Crit3DMeteoPoint *meteoPoint, int validYear, QString *error); bool readDailyDataCriteria1D(QSqlQuery &query, Crit3DMeteoPoint &meteoPoint, int maxNrDays, QString &error); diff --git a/crop/crop.cpp b/crop/crop.cpp index 6d3b37bc..188abfd0 100644 --- a/crop/crop.cpp +++ b/crop/crop.cpp @@ -463,7 +463,13 @@ bool Crit3DCrop::dailyUpdate(const Crit3DDate &myDate, double latitude, const st int currentDoy = getDoyFromDate(myDate); // update degree days - degreeDays += computeDegreeDays(tmin, tmax, thermalThreshold, upperThermalThreshold); + double dailyDD = getDailyDegreeIncrease(tmin, tmax, currentDoy); + if (isEqual(dailyDD, NODATA)) + { + myError = "Error in computing degree dyas for " + myDate.toStdString(); + return false; + } + degreeDays += dailyDD; // update LAI if ( !updateLAI(latitude, nrLayers, currentDoy)) @@ -755,9 +761,3 @@ std::string getCropTypeString(speciesType cropType) return "No crop type"; } -double computeDegreeDays(double myTmin, double myTmax, double myLowerThreshold, double myUpperThreshold) -{ - return MAXVALUE((myTmin + MINVALUE(myTmax, myUpperThreshold)) / 2. - myLowerThreshold, 0); -} - - diff --git a/crop/crop.h b/crop/crop.h index 1d4561e5..62826620 100644 --- a/crop/crop.h +++ b/crop/crop.h @@ -109,7 +109,5 @@ speciesType getCropType(std::string cropType); std::string getCropTypeString(speciesType cropType); - double computeDegreeDays(double myTmin, double myTmax, double myLowerThreshold, double myUpperThreshold); - #endif // CROP_H diff --git a/crop/root.h b/crop/root.h index 63f82464..e8aeb30c 100644 --- a/crop/root.h +++ b/crop/root.h @@ -9,7 +9,8 @@ class Crit3DCrop; enum rootDistributionType {CYLINDRICAL_DISTRIBUTION, CARDIOID_DISTRIBUTION, GAMMA_DISTRIBUTION}; - const int numRootDistributionType = 3; + const int nrRootDistributionType = 3; + enum rootGrowthType {LINEAR, EXPONENTIAL, LOGISTIC}; /*! @@ -22,7 +23,7 @@ rootGrowthType growth; /*! parameters */ - double degreeDaysRootGrowth; /*!< [°D] */ + int degreeDaysRootGrowth; /*!< [°D] */ double rootDepthMin; /*!< [m] */ double rootDepthMax; /*!< [m] */ double shapeDeformation; /*!< [-] */ From 08fd2396541fd93ed2f175c44a74f44473a9783b Mon Sep 17 00:00:00 2001 From: Fausto Tomei Date: Sat, 28 Oct 2023 19:45:53 +0200 Subject: [PATCH 3/3] update --- soilWidget/soilWidget.cpp | 1 - soilWidget/tabWaterRetentionCurve.cpp | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/soilWidget/soilWidget.cpp b/soilWidget/soilWidget.cpp index 89622fbe..a5acd8a0 100644 --- a/soilWidget/soilWidget.cpp +++ b/soilWidget/soilWidget.cpp @@ -844,7 +844,6 @@ void Crit3DSoilWidget::tabChanged(int index) wrCurveTab->resetAll(); } } - } else if (index == 3) // tab hydraulic conductivity curve { diff --git a/soilWidget/tabWaterRetentionCurve.cpp b/soilWidget/tabWaterRetentionCurve.cpp index 83bb3294..467c4904 100644 --- a/soilWidget/tabWaterRetentionCurve.cpp +++ b/soilWidget/tabWaterRetentionCurve.cpp @@ -44,12 +44,11 @@ TabWaterRetentionCurve::TabWaterRetentionCurve() setLayout(mainLayout); setMouseTracking(true); fillElement = false; - } + void TabWaterRetentionCurve::resetAll() { - // delete all Widgets barHorizons.clear(); @@ -70,9 +69,9 @@ void TabWaterRetentionCurve::resetAll() m_tooltip = new Callout(chart); m_tooltip->hide(); fillElement = false; - } + bool TabWaterRetentionCurve::getFillElement() const { return fillElement;