diff --git a/agrolib/soil/soilDbTools.cpp b/agrolib/soil/soilDbTools.cpp index f891be4a..593c4b56 100644 --- a/agrolib/soil/soilDbTools.cpp +++ b/agrolib/soil/soilDbTools.cpp @@ -234,17 +234,18 @@ bool loadSoilData(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Cri { if (query.lastError().type() != QSqlError::NoError) { - errorStr = "dbSoil error: "+ query.lastError().text(); + errorStr = "dbSoil error: "+ query.lastError().text(); + return false; } else { - errorStr = "Soil " + soilCode + " is missing, check soil_code in dbSoil."; + // soil has no horizons + mySoil.initialize(soilCode.toStdString(), 0); + return true; } - return false; } int nrHorizons = query.at() + 1; // SQLITE doesn't support SIZE - mySoil.initialize(soilCode.toStdString(), nrHorizons); unsigned int i = 0; @@ -376,17 +377,25 @@ bool loadSoil(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Crit3DS } } - // error on the last horizon is tolerated (bedrock) - unsigned int lastHorizonIndex = mySoil.nrHorizons -1; - if (firstWrongIndex != NODATA) + // check total depth + // errors on the last horizon is tolerated (bedrock) + if (mySoil.nrHorizons > 0) { - if (mySoil.nrHorizons == 1) - return false; - else - lastHorizonIndex = firstWrongIndex-1; - } + int lastHorizonIndex = mySoil.nrHorizons-1; + if (firstWrongIndex != NODATA) + { + if (mySoil.nrHorizons == 1) + return false; + else + lastHorizonIndex = firstWrongIndex-1; + } - mySoil.totalDepth = mySoil.horizon[lastHorizonIndex].lowerDepth; + mySoil.totalDepth = mySoil.horizon[lastHorizonIndex].lowerDepth; + } + else + { + mySoil.totalDepth = 0; + } return true; } diff --git a/agrolib/soilWidget/soilWidget.cpp b/agrolib/soilWidget/soilWidget.cpp index a5acd8a0..e54cd7f4 100644 --- a/agrolib/soilWidget/soilWidget.cpp +++ b/agrolib/soilWidget/soilWidget.cpp @@ -386,7 +386,7 @@ void Crit3DSoilWidget::on_actionChooseSoil(QString soilCode) copyEstimatedParamTable->setEnabled(true); QString errorStr; - // somethig has been modified, ask for saving + // something has been modified, ask for saving if (changed) { QString soilCodeChanged = QString::fromStdString(mySoil.code); @@ -791,11 +791,11 @@ void Crit3DSoilWidget::setInfoTextural(int nHorizon) void Crit3DSoilWidget::tabChanged(int index) { - if (soilListComboBox.currentText().isEmpty()) { return; } + if (index == 0) { if (!horizonsTab->getInsertSoilElement()) @@ -809,9 +809,7 @@ void Crit3DSoilWidget::tabChanged(int index) else { horizonsTab->resetAll(); - horizonsTab->addRowClicked(); } - } } else if (index == 1) // tab water retention data @@ -829,7 +827,6 @@ void Crit3DSoilWidget::tabChanged(int index) wrDataTab->resetAll(); } } - } else if (index == 2) // tab water retention curve { diff --git a/agrolib/soilWidget/tabHorizons.cpp b/agrolib/soilWidget/tabHorizons.cpp index 31f426a2..ee1a686b 100644 --- a/agrolib/soilWidget/tabHorizons.cpp +++ b/agrolib/soilWidget/tabHorizons.cpp @@ -248,7 +248,6 @@ void TabHorizons::updateTableModel(soil::Crit3DSoil *soil) checkComputedValues(i); } } - } @@ -256,7 +255,7 @@ bool TabHorizons::checkDepths() { bool depthsOk = true; // reset background color - for (int horizonNum = 0; horizonNumrowCount(); horizonNum++) + for (int horizonNum = 0; horizonNum < tableDb->rowCount(); horizonNum++) { tableDb->item(horizonNum,0)->setBackground(Qt::white); tableDb->item(horizonNum,1)->setBackground(Qt::white); @@ -759,12 +758,11 @@ void TabHorizons::cellChanged(int row, int column) emit horizonSelected(row); emit updateSignal(); } - } + void TabHorizons::addRowClicked() { - tableDb->blockSignals(true); int numRow; @@ -793,12 +791,13 @@ void TabHorizons::addRowClicked() tableDb->insertRow(numRow); tableModel->insertRow(numRow); - for (int j=0; jcolumnCount(); j++) + for (int j=0; j < tableDb->columnCount(); j++) { tableDb->setItem(numRow, j, new QTableWidgetItem()); tableDb->item(numRow,j)->setTextAlignment(Qt::AlignRight); } - for (int j=0; jcolumnCount(); j++) + + for (int j=0; j < tableModel->columnCount(); j++) { tableModel->setItem(numRow, j, new QTableWidgetItem()); if (j>0)