Skip to content

Commit

Permalink
fix new soil
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomei committed Nov 15, 2023
1 parent f639e0b commit d321235
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 24 deletions.
35 changes: 22 additions & 13 deletions agrolib/soil/soilDbTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 2 additions & 5 deletions agrolib/soilWidget/soilWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand All @@ -809,9 +809,7 @@ void Crit3DSoilWidget::tabChanged(int index)
else
{
horizonsTab->resetAll();
horizonsTab->addRowClicked();
}

}
}
else if (index == 1) // tab water retention data
Expand All @@ -829,7 +827,6 @@ void Crit3DSoilWidget::tabChanged(int index)
wrDataTab->resetAll();
}
}

}
else if (index == 2) // tab water retention curve
{
Expand Down
11 changes: 5 additions & 6 deletions agrolib/soilWidget/tabHorizons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,14 @@ void TabHorizons::updateTableModel(soil::Crit3DSoil *soil)
checkComputedValues(i);
}
}

}


bool TabHorizons::checkDepths()
{
bool depthsOk = true;
// reset background color
for (int horizonNum = 0; horizonNum<tableDb->rowCount(); horizonNum++)
for (int horizonNum = 0; horizonNum < tableDb->rowCount(); horizonNum++)
{
tableDb->item(horizonNum,0)->setBackground(Qt::white);
tableDb->item(horizonNum,1)->setBackground(Qt::white);
Expand Down Expand Up @@ -759,12 +758,11 @@ void TabHorizons::cellChanged(int row, int column)
emit horizonSelected(row);
emit updateSignal();
}

}


void TabHorizons::addRowClicked()
{

tableDb->blockSignals(true);
int numRow;

Expand Down Expand Up @@ -793,12 +791,13 @@ void TabHorizons::addRowClicked()
tableDb->insertRow(numRow);
tableModel->insertRow(numRow);

for (int j=0; j<tableDb->columnCount(); 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; j<tableModel->columnCount(); j++)

for (int j=0; j < tableModel->columnCount(); j++)
{
tableModel->setItem(numRow, j, new QTableWidgetItem());
if (j>0)
Expand Down

0 comments on commit d321235

Please sign in to comment.