From abd3aeffe3c2b650c8acf2a25c6aab18e4256175 Mon Sep 17 00:00:00 2001 From: ftomei Date: Tue, 31 Oct 2023 19:59:40 +0100 Subject: [PATCH] update new crop --- DATA/PROJECT/test/data/crop.db | Bin 10240 -> 12288 bytes DATA/TEMPLATE/crop_default.db | Bin 21504 -> 12288 bytes agrolib/criteria1DWidget/criteria1DWidget.cpp | 2 +- agrolib/criteria1DWidget/dialogNewCrop.cpp | 69 +++++++++++++----- agrolib/criteria1DWidget/dialogNewCrop.h | 9 ++- agrolib/crop/crop.cpp | 2 - agrolib/crop/crop.h | 2 +- agrolib/crop/cropDbQuery.cpp | 27 +++++++ agrolib/crop/cropDbQuery.h | 2 + 9 files changed, 90 insertions(+), 23 deletions(-) diff --git a/DATA/PROJECT/test/data/crop.db b/DATA/PROJECT/test/data/crop.db index 594d7b9dc6c794b0f2ea14abc25b5abdf4347d8a..31308084c812c43fc3cf123933d5b964de5b05cc 100644 GIT binary patch delta 3189 zcmdT`OKclO7@pbjdcCeUZ)d!5VtX7?Lm!a7fFc#gPMpNTieckWNQHtMZ&M@J8|~U{ z8qvB7g$M~j!g47GZX7sNfXbm22qeS-AwWIxxF7@q73if1snDW|nO!@MY3>yx+3THu z{{R2}*XKF&=$WTi`?_Ep0N|sa`r`Gq9lLw!?!Chg@pKQOn@l30oAAba=1Z{VVXx*1 zBw#||^ZP6L!zHzpFBj&jGc{Txuev z?4Wz){4q5u=2B1O*jqt0=Jn!YrKpvgo5fmTj+v?&^^=jY)OcbhlZ(X06PZl*V2r6! z013tJ4Pr+F@2JZs5 z*37SV-qpj)JHwvwtdg3}C3P)dD5?1)kt3R}8kMAyO^jtyiSbZ3FUMrjx)$ml98D-n zHrLa|V~oY@R60AAEz`8yzep#KcVW?*3gEHHtddK2cJO|`UsTegDWy2CvgfvTp6thB zT2az-*-ZNJR9e@I3;Bv#h-jtaaW%4_YsXc?7G3y|ALIHNelOY!&{gyu`V5^%ucI0& zp+hKx_Fm}p1yHTm%i|$QI!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QVkm9_ti!{YKQhDmm8%CrK{%Ai5%4=GTjN$tfP^3VnO6QMrfDG@85dR|WL=szvF&uAGH_|AQwIv6T~!q9rcGJvRzsR% zR_EF)we!W=a9*k+_~L_t$jH;6_~$|Jp$;DehrSdU4q=GHF{FLa@7$ZDnbCJYxaTD2 zJKw+G_xsN3>DAn3B#8D9LT&KXM0uui-veE6Ix-#cz!|3dQsbff)wqhON0t9XnXYRJ z*5PLd-WE*h1?3j5ZhIajK53=UTk>9;@cGv(Ij?E^y*!qVW1?cDVoV5TjA=}K;(y(s z9-c5;RmTGb+Np4HB@hx{2QC_2l*dP%YdV%5zyZTdJR7tPo!qOE&O!BiaM=i99*h6O z3gX(Kg{&c{uF0yxGfaJa2f~cr4bc`Z-=Sn8u^gR@KXg zN`|g->u8c-pclrfOD|x+-9yWU&Un&ttsLgncyqb`4gD;+M#k``=m_pXA6BxF=t2-8 zn22c7jog4o8q+oKDPBlCatz;jESK2@nt)_}nRUc7gZ7rYxS2k%bI7eR1a?Fc73;c~ zJp7z#cZ7KK_h=TYBt>%nlf$L&CPhdATV_!i@l-fK{?%GIQ5XhOj$aDcM6&Z zIXZ07#A~TO-OWX2h0jy*S!(d%U)|bS7rw((U`DMk^&KiUcp_=(;KkvS^ritXgg>1+ zjn6lj^rwpu>8G51H`aO7kuTm7rS17kdzp{jD4Bit{9hQj5Qd?&8nku8h!4`))PLK^ z$4M8kc%o=NY&g a8J#y)dR#ym%;rJU#rvaub?C2-KK?f@do`s1 diff --git a/DATA/TEMPLATE/crop_default.db b/DATA/TEMPLATE/crop_default.db index 81ae169e7d15775fedb45f5ddb742fc41311b926..0506a966fca7609745fb019705e2202b99b8adec 100644 GIT binary patch delta 471 zcmZoz!Pt;6L0Zs`fq{Vsh@pVBaH5W}s2zizffXxIh>`g>NP?aDH{-93jh&1f93XCE zIrC&zJ_SaW$!dJp8JQ;kh6 zI=c3XHB;;&_Ax>V2?muZO{DhoM^J zBP9gUv*acraQv^Bno|O+A{v%i3;709_9yXUk@?hXt+1ItJU-8OAD9iS2CNQ@r{e%q z^5(#PD@izfR&~4a!eDmj#Ay2Q%;|A%v@qeJgq`x*3RfCkSm^8S>SZ7L?tWd61sS73 z1i${g89GeAP~&mDnB-r>Ssz)mkagC?nb8xeYQ#CLzy(Zf&5;bc%W)qGJNd$`})ZB}q~w zg4o-R6=0Jca?W%2i8IgLL#~&(yWv{m?wPu=P%W=R9j`+T&&y`j0i!rVaq=xm;&*Ta zy@C??F7-jvW!G}O0B?hc^glDZwPX9rX0k_myS1k68w&HDWoooTbnBU|*VKrLh=LKu zXlBc-2v3n%PxG-m3-2A&NB5j{yhBX{Dra3{Kgf@NH0y;XdydM6oiRc?bCr7Hq;swi-_4$Yrki< zQ4a)kJCT7KY%lX=N9_03{pEd&;Ra@em4i0*X%C{O8<_!y~h^>b8c`#gg7uZ_xQU2-uEfz!9S}yU~ zTjs}CRf|PcvnRrBWwn7|rIKLT zkKraddItem(QString::fromStdString(getCropTypeString(type))); } + QString cropType = typeCropComboBox->currentText(); + newCrop->type = getCropType(cropType.toStdString()); + + QList cropList; + QString errorStr; + if (! getCropListFromType(*dbCrop, cropType, cropList, errorStr)) + { + QMessageBox::information(this, "Error in reading crop list", errorStr); + return; + } + + QLabel* templateCropLabel = new QLabel(tr("Copy other parameters from crop: ")); + templateCropComboBox = new QComboBox(); + for (int i=0; i < cropList.size(); i++) + { + templateCropComboBox->addItem(cropList[i]); + } + sowingDoY = new QLabel(tr("Enter sowing DOY: ")); sowingDoYValue = new QSpinBox(); sowingDoYValue->setMinimum(-365); sowingDoYValue->setMaximum(365); - cycleMaxDuration = new QLabel(tr("Enter cycle max duration: ")); + cycleMaxDuration = new QLabel(tr("Enter crop cycle max duration [days]: ")); cycleMaxDurationValue = new QSpinBox(); cycleMaxDurationValue->setMinimum(0); cycleMaxDurationValue->setMaximum(365); @@ -41,12 +60,13 @@ DialogNewCrop::DialogNewCrop(Crit3DCrop *newCrop) layoutCrop->addWidget(nameCropValue, 1 , 1); layoutCrop->addWidget(typeCropLabel, 2 , 0); layoutCrop->addWidget(typeCropComboBox, 2 , 1); - layoutCrop->addWidget(sowingDoY, 3 , 0); - layoutCrop->addWidget(sowingDoYValue, 3 , 1); - layoutCrop->addWidget(cycleMaxDuration, 4 , 0); - layoutCrop->addWidget(cycleMaxDurationValue, 4 , 1); + layoutCrop->addWidget(templateCropLabel, 3 , 0); + layoutCrop->addWidget(templateCropComboBox, 3, 1); + layoutCrop->addWidget(sowingDoY, 4, 0); + layoutCrop->addWidget(sowingDoYValue, 4, 1); + layoutCrop->addWidget(cycleMaxDuration, 5, 0); + layoutCrop->addWidget(cycleMaxDurationValue, 5, 1); - newCrop->type = getCropType(typeCropComboBox->currentText().toStdString()); if (newCrop->isSowingCrop()) { sowingDoY->setVisible(true); @@ -72,7 +92,6 @@ DialogNewCrop::DialogNewCrop(Crit3DCrop *newCrop) layoutOk->addWidget(&buttonBox); - mainLayout->addLayout(layoutCrop); mainLayout->addLayout(layoutOk); @@ -80,12 +99,13 @@ DialogNewCrop::DialogNewCrop(Crit3DCrop *newCrop) show(); exec(); - } -void DialogNewCrop::on_actionChooseType(QString type) + +void DialogNewCrop::on_actionChooseType(QString cropType) { - newCrop->type = getCropType(type.toStdString()); + newCrop->type = getCropType(cropType.toStdString()); + if (newCrop->isSowingCrop()) { sowingDoY->setVisible(true); @@ -102,6 +122,21 @@ void DialogNewCrop::on_actionChooseType(QString type) newCrop->sowingDoy = NODATA; newCrop->plantCycle = 365; } + + templateCropComboBox->clear(); + + QList cropList; + QString errorStr; + if (! getCropListFromType(*dbCrop, cropType, cropList, errorStr)) + { + QMessageBox::information(this, "Error in reading crop list", errorStr); + return; + } + + for (int i=0; i < cropList.size(); i++) + { + templateCropComboBox->addItem(cropList[i]); + } } @@ -140,24 +175,24 @@ bool DialogNewCrop::checkData() { if (idCropValue->text().isEmpty()) { - QMessageBox::information(nullptr, "Missing parameter", "Insert ID CROP"); + QMessageBox::information(nullptr, "Missing parameter", "Insert crop ID"); return false; } if (nameCropValue->text().isEmpty()) { - QMessageBox::information(nullptr, "Missing parameter", "Insert ID NAME"); + QMessageBox::information(nullptr, "Missing parameter", "Insert crop NAME"); return false; } if (sowingDoY->isVisible()) { - if (sowingDoYValue->text().isEmpty()) + if (sowingDoYValue->text().isEmpty() || sowingDoYValue->text().toInt() == 0) { QMessageBox::information(nullptr, "Missing parameter", "Insert sowing day of year"); return false; } - if (cycleMaxDurationValue->text().isEmpty()) + if (cycleMaxDurationValue->text().isEmpty() || cycleMaxDurationValue->text().toInt() == 0) { - QMessageBox::information(nullptr, "Missing parameter", "Insert plant cycle max duration"); + QMessageBox::information(nullptr, "Missing parameter", "Insert crop cycle max duration"); return false; } } diff --git a/agrolib/criteria1DWidget/dialogNewCrop.h b/agrolib/criteria1DWidget/dialogNewCrop.h index e63cc0e0..f12e5d52 100644 --- a/agrolib/criteria1DWidget/dialogNewCrop.h +++ b/agrolib/criteria1DWidget/dialogNewCrop.h @@ -3,26 +3,31 @@ #include class Crit3DCrop; + class QSqlDatabase; class DialogNewCrop : public QDialog { Q_OBJECT public: - DialogNewCrop(Crit3DCrop* newCrop); - void on_actionChooseType(QString type); + DialogNewCrop(QSqlDatabase* dbCrop, Crit3DCrop* newCrop); + + void on_actionChooseType(QString cropType); void done(int res); bool checkData(); QString getNameCrop(); private: + QSqlDatabase* dbCrop; Crit3DCrop* newCrop; QLineEdit* idCropValue; QLineEdit* nameCropValue; QLineEdit* typeCropValue; + QLineEdit* templateCropValue; QLabel *sowingDoY; QSpinBox* sowingDoYValue; QLabel *cycleMaxDuration; QSpinBox* cycleMaxDurationValue; + QComboBox* templateCropComboBox; }; #endif // DIALOGNEWCROP_H diff --git a/agrolib/crop/crop.cpp b/agrolib/crop/crop.cpp index 188abfd0..8b030d15 100644 --- a/agrolib/crop/crop.cpp +++ b/agrolib/crop/crop.cpp @@ -726,8 +726,6 @@ speciesType getCropType(std::string cropType) return HORTICULTURAL; else if (cropType == "grass") return GRASS; - else if (cropType == "grass_first_year") - return GRASS; else if (cropType == "fallow") return FALLOW; else if (cropType == "annual_fallow" || cropType == "fallow_annual") diff --git a/agrolib/crop/crop.h b/agrolib/crop/crop.h index 9af159b6..35766f17 100644 --- a/agrolib/crop/crop.h +++ b/agrolib/crop/crop.h @@ -12,7 +12,7 @@ #endif enum speciesType {HERBACEOUS_ANNUAL, HERBACEOUS_PERENNIAL, HORTICULTURAL, GRASS, TREE, FALLOW, FALLOW_ANNUAL}; - #define NR_CROP_SPECIES 6 + #define NR_CROP_SPECIES 7 /*! * \brief The Crit3DCrop class diff --git a/agrolib/crop/cropDbQuery.cpp b/agrolib/crop/cropDbQuery.cpp index 84210b57..970c582a 100644 --- a/agrolib/crop/cropDbQuery.cpp +++ b/agrolib/crop/cropDbQuery.cpp @@ -147,3 +147,30 @@ float getIrriRatioFromCropId(const QSqlDatabase &dbCrop, QString cropClassTable, else return NODATA; } + + +bool getCropListFromType(const QSqlDatabase &dbCrop, QString cropType, QList& cropList, QString& errorStr) +{ + QString queryString = "SELECT id_crop FROM crop WHERE type = '" + cropType + "'"; + + QSqlQuery query = dbCrop.exec(queryString); + query.last(); + if (! query.isValid()) + { + if (query.lastError().isValid()) + errorStr = "Error in reading crop list from type: " + cropType + "\n" + query.lastError().text(); + else + errorStr = "Missing crop type: " + cropType; + + return false; + } + + query.first(); + do + { + cropList.append(query.value("id_crop").toString()); + } + while (query.next()); + + return true; +} diff --git a/agrolib/crop/cropDbQuery.h b/agrolib/crop/cropDbQuery.h index 16b803ba..ee068393 100644 --- a/agrolib/crop/cropDbQuery.h +++ b/agrolib/crop/cropDbQuery.h @@ -20,5 +20,7 @@ float getIrriRatioFromCropId(const QSqlDatabase &dbCrop, QString cropClassTable, QString cropIdField, int cropId, QString& errorStr); + bool getCropListFromType(const QSqlDatabase &dbCrop, QString cropType, QList& cropList, QString& errorStr); + #endif // CROPDBQUERY_H