diff --git a/agrolib/dbMeteoGrid/dbMeteoGrid.cpp b/agrolib/dbMeteoGrid/dbMeteoGrid.cpp index 580322c5..09f093b0 100644 --- a/agrolib/dbMeteoGrid/dbMeteoGrid.cpp +++ b/agrolib/dbMeteoGrid/dbMeteoGrid.cpp @@ -37,14 +37,14 @@ bool Crit3DMeteoGridDbHandler::parseXMLFile(QString xmlFileName, QDomDocument* x return (false); } - QString myError; + QString errorStr; int myErrLine, myErrColumn; - if (!xmlDoc->setContent(&myFile, &myError, &myErrLine, &myErrColumn)) + if (!xmlDoc->setContent(&myFile, &errorStr, &myErrLine, &myErrColumn)) { *error = "Parse xml failed:" + xmlFileName + " Row: " + QString::number(myErrLine) + " - Column: " + QString::number(myErrColumn) - + "\n" + myError; + + "\n" + errorStr; myFile.close(); return(false); } @@ -54,11 +54,11 @@ bool Crit3DMeteoGridDbHandler::parseXMLFile(QString xmlFileName, QDomDocument* x } -bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myError) +bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *errorStr) { QDomDocument xmlDoc; - if (! parseXMLFile(xmlFileName, &xmlDoc, myError)) return false; + if (! parseXMLFile(xmlFileName, &xmlDoc, errorStr)) return false; QDomNode child; QDomNode secondChild; @@ -86,7 +86,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing provider"; + *errorStr = "Missing provider"; return false; } _connection.provider = child.toElement().text(); @@ -97,7 +97,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing server"; + *errorStr = "Missing server"; return false; } _connection.server = child.toElement().text(); @@ -108,7 +108,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing name"; + *errorStr = "Missing name"; return false; } _connection.name = child.toElement().text(); @@ -119,7 +119,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing user"; + *errorStr = "Missing user"; return false; } _connection.user = child.toElement().text(); @@ -130,7 +130,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing password"; + *errorStr = "Missing password"; return false; } _connection.password = child.toElement().text(); @@ -153,7 +153,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro } else { - *myError = "Invalid isRegular attribute"; + *errorStr = "Invalid isRegular attribute"; return false; } @@ -167,7 +167,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro } else { - *myError = "Invalid isutm attribute"; + *errorStr = "Invalid isutm attribute"; return false; } @@ -181,7 +181,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro } else { - *myError = "Invalid istin attribute"; + *errorStr = "Invalid istin attribute"; return false; } @@ -196,7 +196,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro } else { - *myError = "Invalid isfixedfields attribute"; + *errorStr = "Invalid isfixedfields attribute"; return false; } @@ -236,7 +236,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing XLL"; + *errorStr = "Missing XLL"; return false; } header.llCorner.longitude = child.toElement().text().toFloat(); @@ -245,7 +245,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing YLL"; + *errorStr = "Missing YLL"; return false; } header.llCorner.latitude = child.toElement().text().toFloat(); @@ -254,7 +254,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing NROWS"; + *errorStr = "Missing NROWS"; return false; } header.nrRows = child.toElement().text().toInt(); @@ -264,7 +264,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing NCOLS"; + *errorStr = "Missing NCOLS"; return false; } header.nrCols = child.toElement().text().toInt(); @@ -274,7 +274,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing XWIDTH"; + *errorStr = "Missing XWIDTH"; return false; } header.dx = child.toElement().text().toFloat(); @@ -283,7 +283,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { if (child.toElement().text().isEmpty()) { - *myError = "Missing YWIDTH"; + *errorStr = "Missing YWIDTH"; return false; } header.dy = child.toElement().text().toFloat(); @@ -291,7 +291,6 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro child = child.nextSibling(); } _gridStructure.setHeader(header); - } else if (ancestor.toElement().tagName().toUpper() == "TABLEDAILY") @@ -329,17 +328,14 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { mySecondTag = secondChild.toElement().tagName().toUpper(); - if (mySecondTag == "VARFIELD") { _tableDaily.varcode[_tableDaily.varcode.size()-1].varField = secondChild.toElement().text(); - } else if (mySecondTag == "VARCODE") { _tableDaily.varcode[_tableDaily.varcode.size()-1].varCode = secondChild.toElement().text().toInt(); - } else if (mySecondTag == "VARPRAGANAME") @@ -395,17 +391,14 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { mySecondTag = secondChild.toElement().tagName().toUpper(); - if (mySecondTag == "VARFIELD") { _tableHourly.varcode[_tableHourly.varcode.size()-1].varField = secondChild.toElement().text(); - } else if (mySecondTag == "VARCODE") { _tableHourly.varcode[_tableHourly.varcode.size()-1].varCode = secondChild.toElement().text().toInt(); - } else if (mySecondTag == "VARPRAGANAME") @@ -444,17 +437,14 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro { mySecondTag = secondChild.toElement().tagName().toUpper(); - if (mySecondTag == "VARFIELD") { _tableMonthly.varcode[_tableMonthly.varcode.size()-1].varField = secondChild.toElement().text(); - } else if (mySecondTag == "VARCODE") { _tableMonthly.varcode[_tableMonthly.varcode.size()-1].varCode = secondChild.toElement().text().toInt(); - } else if (mySecondTag == "VARPRAGANAME") @@ -479,7 +469,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro } xmlDoc.clear(); - if (!checkXML(myError)) + if (!checkXML(errorStr)) { return false; } @@ -496,9 +486,8 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro catch (const std::out_of_range& oor) { QString errMess = QString("%1 does not exist" ).arg(_tableDaily.varcode[i].varPragaName); - *myError = oor.what() + errMess; + *errorStr = oor.what() + errMess; } - } for (unsigned int i=0; i < _tableHourly.varcode.size(); i++) @@ -512,7 +501,7 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro catch (const std::out_of_range& oor) { QString errMess = QString("%1 does not exist" ).arg(_tableHourly.varcode[i].varPragaName); - *myError = oor.what() + errMess; + *errorStr = oor.what() + errMess; } } @@ -527,17 +516,17 @@ bool Crit3DMeteoGridDbHandler::parseXMLGrid(QString xmlFileName, QString *myErro catch (const std::out_of_range& oor) { QString errMess = QString("%1 does not exist" ).arg(_tableMonthly.varcode[i].varPragaName); - *myError = oor.what() + errMess; + *errorStr = oor.what() + errMess; } } _meteoGrid->setGridStructure(_gridStructure); - _meteoGrid->initMeteoPoints(nRow, nCol); return true; } + void Crit3DMeteoGridDbHandler::initMapMySqlVarType() { _mapDailyMySqlVarType[dailyAirTemperatureMin] = "float(4,1)"; @@ -570,36 +559,35 @@ void Crit3DMeteoGridDbHandler::initMapMySqlVarType() _mapHourlyMySqlVarType[windVectorDirection] = "smallint(3) UNSIGNED"; _mapHourlyMySqlVarType[referenceEvapotranspiration] = "float(3,1) UNSIGNED"; _mapHourlyMySqlVarType[leafWetness] = "tinyint(3) UNSIGNED"; - } -bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) -{ +bool Crit3DMeteoGridDbHandler::checkXML(QString *errorStr) +{ /* connection */ if (_connection.provider.isNull() || _connection.provider.isEmpty()) { - *myError = "Missing connection provider"; + *errorStr = "Missing connection provider"; return false; } if (_connection.server.isNull() || _connection.server.isEmpty()) { - *myError = "Missing connection server"; + *errorStr = "Missing connection server"; return false; } if (_connection.name.isNull() || _connection.name.isEmpty()) { - *myError = "Missing connection name"; + *errorStr = "Missing connection name"; return false; } if (_connection.user.isNull() || _connection.user.isEmpty()) { - *myError = "Missing connection user"; + *errorStr = "Missing connection user"; return false; } if (_connection.password.isNull() || _connection.password.isEmpty()) { - *myError = "Missing connection password"; + *errorStr = "Missing connection password"; return false; } @@ -607,38 +595,38 @@ bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) if (_gridStructure.header().llCorner.longitude == NODATA) { - *myError = "Error missing xll tag"; + *errorStr = "Error missing xll tag"; return false; } if (_gridStructure.header().llCorner.latitude == NODATA) { - *myError = "Error missing yll tag"; + *errorStr = "Error missing yll tag"; return false; } if (_gridStructure.header().nrRows == NODATA) { - *myError = "Error missing nrows tag"; + *errorStr = "Error missing nrows tag"; return false; } if (_gridStructure.header().nrCols == NODATA) { - *myError = "Error missing ncols tag"; + *errorStr = "Error missing ncols tag"; return false; } if (_gridStructure.header().dx == NODATA) { - *myError = "Error missing xwidth tag"; + *errorStr = "Error missing xwidth tag"; return false; } if (_gridStructure.header().dy == NODATA) { - *myError = "Error missing ywidth tag"; + *errorStr = "Error missing ywidth tag"; return false; } if (_gridStructure.isUTM() == true && _gridStructure.header().dx != _gridStructure.header().dy ) { - *myError = "UTM grid with dx != dy"; + *errorStr = "UTM grid with dx != dy"; return false; } @@ -647,13 +635,13 @@ bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) { if (_tableDaily.fieldTime.isNull() || _tableDaily.fieldTime.isEmpty()) { - *myError = "Missing table Daily fieldTime"; + *errorStr = "Missing table Daily fieldTime"; return false; } if (_tableDaily.varcode.size() < 1 && _tableHourly.varcode.size() < 1) { - *myError = "Missing daily and hourly var code"; + *errorStr = "Missing daily and hourly var code"; return false; } @@ -661,17 +649,17 @@ bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) { if (_tableDaily.varcode[i].varCode == NODATA) { - *myError = "Missing daily var code"; + *errorStr = "Missing daily var code"; return false; } if (_tableDaily.varcode[i].varPragaName.isNull() || _tableDaily.varcode[i].varPragaName.isEmpty()) { - *myError = "Missing daily varPragaName"; + *errorStr = "Missing daily varPragaName"; return false; } if (_gridStructure.isFixedFields() == true && (_tableDaily.varcode[i].varField.isNull() || _tableDaily.varcode[i].varField.isEmpty()) ) { - *myError = "Fixed Field: Missing daily varField"; + *errorStr = "Fixed Field: Missing daily varField"; return false; } } @@ -682,7 +670,7 @@ bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) { if (_tableHourly.fieldTime.isNull() || _tableHourly.fieldTime.isEmpty()) { - *myError = "Missing table Hourly fieldTime"; + *errorStr = "Missing table Hourly fieldTime"; return false; } @@ -690,17 +678,17 @@ bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) { if (_tableHourly.varcode[i].varCode == NODATA) { - *myError = "Missing daily var code"; + *errorStr = "Missing daily var code"; return false; } if (_tableHourly.varcode[i].varPragaName.isNull() || _tableHourly.varcode[i].varPragaName.isEmpty()) { - *myError = "Missing daily varPragaName"; + *errorStr = "Missing daily varPragaName"; return false; } if (_gridStructure.isFixedFields() == true && (_tableHourly.varcode[i].varField.isNull() || _tableHourly.varcode[i].varField.isEmpty()) ) { - *myError = "Fixed Field: Missing daily varField"; + *errorStr = "Fixed Field: Missing daily varField"; return false; } } @@ -713,12 +701,12 @@ bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) { if (_tableMonthly.varcode[i].varCode == NODATA) { - *myError = "Missing monthly var code"; + *errorStr = "Missing monthly var code"; return false; } if (_tableMonthly.varcode[i].varPragaName.isNull() || _tableMonthly.varcode[i].varPragaName.isEmpty()) { - *myError = "Missing monthly varPragaName"; + *errorStr = "Missing monthly varPragaName"; return false; } } @@ -727,32 +715,34 @@ bool Crit3DMeteoGridDbHandler::checkXML(QString *myError) return true; } + int Crit3DMeteoGridDbHandler::getDailyVarCode(meteoVariable meteoGridDailyVar) { - int varCode = NODATA; + //check if (meteoGridDailyVar == noMeteoVar) { return varCode; } + if (_gridDailyVar.empty()) { qDebug() << "_gridDailyVar is empty"; return varCode; } + if(_gridDailyVar.contains(meteoGridDailyVar)) { varCode = _gridDailyVar[meteoGridDailyVar]; } return varCode; - } + QString Crit3DMeteoGridDbHandler::getDailyVarField(meteoVariable meteoGridDailyVar) { - QString varField = ""; //check if (meteoGridDailyVar == noMeteoVar) @@ -769,9 +759,9 @@ QString Crit3DMeteoGridDbHandler::getDailyVarField(meteoVariable meteoGridDailyV } return varField; - } + meteoVariable Crit3DMeteoGridDbHandler::getDailyVarEnum(int varCode) { if (varCode == NODATA) @@ -794,7 +784,6 @@ meteoVariable Crit3DMeteoGridDbHandler::getDailyVarEnum(int varCode) meteoVariable Crit3DMeteoGridDbHandler::getDailyVarFieldEnum(QString varField) { - if (varField == "") { return noMeteoVar; @@ -812,53 +801,57 @@ meteoVariable Crit3DMeteoGridDbHandler::getDailyVarFieldEnum(QString varField) return noMeteoVar; } + int Crit3DMeteoGridDbHandler::getHourlyVarCode(meteoVariable meteoGridHourlyVar) { - int varCode = NODATA; + //check if (meteoGridHourlyVar == noMeteoVar) { return varCode; } + if (_gridHourlyVar.empty()) { return varCode; } + if(_gridHourlyVar.contains(meteoGridHourlyVar)) { varCode = _gridHourlyVar[meteoGridHourlyVar]; } return varCode; - } + QString Crit3DMeteoGridDbHandler::getHourlyVarField(meteoVariable meteoGridHourlyVar) { - QString varField = ""; + //check if (meteoGridHourlyVar == noMeteoVar) { return varField; } + if (_gridHourlyVarField.empty()) { return varField; } + if(_gridHourlyVarField.contains(meteoGridHourlyVar)) { varField = _gridHourlyVarField[meteoGridHourlyVar]; } return varField; - } + meteoVariable Crit3DMeteoGridDbHandler::getHourlyVarEnum(int varCode) { - if (varCode == NODATA) { return noMeteoVar; @@ -874,12 +867,11 @@ meteoVariable Crit3DMeteoGridDbHandler::getHourlyVarEnum(int varCode) } return noMeteoVar; - } + meteoVariable Crit3DMeteoGridDbHandler::getHourlyVarFieldEnum(QString varField) { - if (varField == "") { return noMeteoVar; @@ -895,9 +887,9 @@ meteoVariable Crit3DMeteoGridDbHandler::getHourlyVarFieldEnum(QString varField) } return noMeteoVar; - } + int Crit3DMeteoGridDbHandler::getMonthlyVarCode(meteoVariable meteoGridMonthlyVar) { @@ -917,9 +909,9 @@ int Crit3DMeteoGridDbHandler::getMonthlyVarCode(meteoVariable meteoGridMonthlyVa } return varCode; - } + QString Crit3DMeteoGridDbHandler::getMonthlyVarField(meteoVariable meteoGridMonthlyVar) { @@ -965,7 +957,6 @@ meteoVariable Crit3DMeteoGridDbHandler::getMonthlyVarEnum(int varCode) meteoVariable Crit3DMeteoGridDbHandler::getMonthlyVarFieldEnum(QString varField) { - if (varField == "") { return noMeteoVar; @@ -981,12 +972,11 @@ meteoVariable Crit3DMeteoGridDbHandler::getMonthlyVarFieldEnum(QString varField) } return noMeteoVar; - } + std::string Crit3DMeteoGridDbHandler::getDailyPragaName(meteoVariable meteoVar) { - std::map::const_iterator it; std::string key = ""; @@ -998,12 +988,13 @@ std::string Crit3DMeteoGridDbHandler::getDailyPragaName(meteoVariable meteoVar) break; } } + return key; } + std::string Crit3DMeteoGridDbHandler::getHourlyPragaName(meteoVariable meteoVar) { - std::map::const_iterator it; std::string key = ""; @@ -1015,12 +1006,13 @@ std::string Crit3DMeteoGridDbHandler::getHourlyPragaName(meteoVariable meteoVar) break; } } + return key; } + std::string Crit3DMeteoGridDbHandler::getMonthlyPragaName(meteoVariable meteoVar) { - std::map::const_iterator it; std::string key = ""; @@ -1032,13 +1024,13 @@ std::string Crit3DMeteoGridDbHandler::getMonthlyPragaName(meteoVariable meteoVar break; } } + return key; } -bool Crit3DMeteoGridDbHandler::openDatabase(QString *myError) +bool Crit3DMeteoGridDbHandler::openDatabase(QString *errorStr) { - if (_connection.provider.toUpper() == "MYSQL") { _db = QSqlDatabase::addDatabase("QMYSQL", "grid"); @@ -1051,16 +1043,16 @@ bool Crit3DMeteoGridDbHandler::openDatabase(QString *myError) if (!_db.open()) { - *myError = "Connection with database fail.\n" + _db.lastError().text(); + *errorStr = "Connection with database fail.\n" + _db.lastError().text(); return false; } - else - return true; + + return true; } -bool Crit3DMeteoGridDbHandler::newDatabase(QString *myError) -{ +bool Crit3DMeteoGridDbHandler::newDatabase(QString *errorStr) +{ if (_connection.provider.toUpper() == "MYSQL") { _db = QSqlDatabase::addDatabase("QMYSQL"); @@ -1077,20 +1069,22 @@ bool Crit3DMeteoGridDbHandler::newDatabase(QString *myError) if (!query.exec()) { - *myError = "MySQL error:" + query.lastError().text(); + *errorStr = "MySQL error:" + query.lastError().text(); return false; } + _db.setDatabaseName(_connection.name); if (!_db.open()) { - *myError = "Connection with database fail.\n" + _db.lastError().text(); + *errorStr = "Connection with database fail.\n" + _db.lastError().text(); return false; } - else - return true; + + return true; } -bool Crit3DMeteoGridDbHandler::deleteDatabase(QString *myError) + +bool Crit3DMeteoGridDbHandler::deleteDatabase(QString *errorStr) { QSqlQuery query(_db); @@ -1098,15 +1092,16 @@ bool Crit3DMeteoGridDbHandler::deleteDatabase(QString *myError) if (!query.exec()) { - *myError = "MySQL error:" + query.lastError().text(); + *errorStr = "MySQL error:" + query.lastError().text(); return false; } + return true; } -bool Crit3DMeteoGridDbHandler::newDatabase(QString *myError, QString connectionName) -{ +bool Crit3DMeteoGridDbHandler::newDatabase(QString *errorStr, QString connectionName) +{ if (_connection.provider.toUpper() == "MYSQL") { _db = QSqlDatabase::addDatabase("QMYSQL", connectionName); @@ -1123,22 +1118,23 @@ bool Crit3DMeteoGridDbHandler::newDatabase(QString *myError, QString connectionN if (!query.exec()) { - *myError = "MySQL error:" + query.lastError().text(); + *errorStr = "MySQL error:" + query.lastError().text(); return false; } + _db.setDatabaseName(_connection.name); if (!_db.open()) { - *myError = "Connection with database fail.\n" + _db.lastError().text(); + *errorStr = "Connection with database fail.\n" + _db.lastError().text(); return false; } - else - return true; + + return true; } -bool Crit3DMeteoGridDbHandler::openDatabase(QString *myError, QString connectionName) -{ +bool Crit3DMeteoGridDbHandler::openDatabase(QString *errorStr, QString connectionName) +{ if (_connection.provider.toUpper() == "MYSQL") { _db = QSqlDatabase::addDatabase("QMYSQL", connectionName); @@ -1151,11 +1147,11 @@ bool Crit3DMeteoGridDbHandler::openDatabase(QString *myError, QString connection if (!_db.open()) { - *myError = "Connection with database fail.\n" + _db.lastError().text(); + *errorStr = "Connection with database fail.\n" + _db.lastError().text(); return false; } - else - return true; + + return true; } @@ -1170,7 +1166,7 @@ void Crit3DMeteoGridDbHandler::closeDatabase() } } -bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) +bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *errorStr) { QSqlQuery qry(_db); int row, col, active, height; @@ -1179,7 +1175,7 @@ bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) qry.prepare( "SHOW TABLES LIKE '%ells%roperties'" ); if( !qry.exec() ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -1192,7 +1188,7 @@ bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -1203,7 +1199,7 @@ bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) if (! getValue(qry.value("Code"), &code)) { - *myError = "Missing data: Code"; + *errorStr = "Missing data: Code"; return false; } @@ -1215,13 +1211,13 @@ bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) if (! getValue(qry.value("Row"), &row)) { - *myError = "Missing data: Row"; + *errorStr = "Missing data: Row"; return false; } if (! getValue(qry.value("Col"), &col)) { - *myError = "Missing data: Col"; + *errorStr = "Missing data: Col"; return false; } @@ -1237,7 +1233,7 @@ bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) if (! getValue(qry.value("Active"), &active)) { - *myError = "Missing data: Active"; + *errorStr = "Missing data: Active"; return false; } @@ -1248,7 +1244,7 @@ bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) } else { - *myError = "Row or Col > nrRows or nrCols"; + *errorStr = "Row or Col > nrRows or nrCols"; return false; } } @@ -1257,7 +1253,7 @@ bool Crit3DMeteoGridDbHandler::loadCellProperties(QString *myError) } -bool Crit3DMeteoGridDbHandler::newCellProperties(QString *myError) +bool Crit3DMeteoGridDbHandler::newCellProperties(QString *errorStr) { QSqlQuery qry(_db); QString table = "CellsProperties"; @@ -1267,14 +1263,14 @@ bool Crit3DMeteoGridDbHandler::newCellProperties(QString *myError) if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } return true; } -bool Crit3DMeteoGridDbHandler::writeCellProperties(QString *myError, int nRow, int nCol) +bool Crit3DMeteoGridDbHandler::writeCellProperties(QString *errorStr, int nRow, int nCol) { QSqlQuery qry(_db); QString table = "CellsProperties"; @@ -1295,21 +1291,21 @@ bool Crit3DMeteoGridDbHandler::writeCellProperties(QString *myError, int nRow, i if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } return true; } -bool Crit3DMeteoGridDbHandler::activeAllCells(QString *myError) +bool Crit3DMeteoGridDbHandler::activeAllCells(QString *errorStr) { QSqlQuery qry(_db); qry.prepare( "UPDATE CellsProperties SET Active = 1" ); if( !qry.exec() ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -1318,14 +1314,14 @@ bool Crit3DMeteoGridDbHandler::activeAllCells(QString *myError) } } -bool Crit3DMeteoGridDbHandler::setActiveStateCellsInList(QString *myError, QList idList, bool activeState) +bool Crit3DMeteoGridDbHandler::setActiveStateCellsInList(QString *errorStr, QList idList, bool activeState) { QSqlQuery qry(_db); QString statement = QString("UPDATE CellsProperties SET Active = %1 WHERE `Code` IN ('%2')").arg(activeState).arg(idList.join("','")); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -1334,7 +1330,7 @@ bool Crit3DMeteoGridDbHandler::setActiveStateCellsInList(QString *myError, QList } } -bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString idMeteo) +bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *errorStr, QString idMeteo) { QSqlQuery qry(_db); int row, col, active, height; @@ -1343,7 +1339,7 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i qry.prepare( "SHOW TABLES LIKE '%ells%roperties'" ); if( !qry.exec() ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -1352,11 +1348,11 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i tableCellsProp = qry.value(0).toString(); } - QString statement = QString("SELECT * FROM `%1` WHERE `Code` = '%2'").arg(tableCellsProp).arg(idMeteo); + QString statement = QString("SELECT * FROM `%1` WHERE `Code` = '%2'").arg(tableCellsProp, idMeteo); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -1367,7 +1363,7 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i if (! getValue(qry.value("Code"), &code)) { - *myError = "Missing data: Code"; + *errorStr = "Missing data: Code"; return false; } @@ -1379,13 +1375,13 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i if (! getValue(qry.value("Row"), &row)) { - *myError = "Missing data: Row"; + *errorStr = "Missing data: Row"; return false; } if (! getValue(qry.value("Col"), &col)) { - *myError = "Missing data: Col"; + *errorStr = "Missing data: Col"; return false; } @@ -1401,7 +1397,7 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i if (! getValue(qry.value("Active"), &active)) { - *myError = "Missing data: Active"; + *errorStr = "Missing data: Active"; return false; } @@ -1412,7 +1408,7 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i } else { - *myError = "Row or Col > nrRows or nrCols"; + *errorStr = "Row or Col > nrRows or nrCols"; return false; } } @@ -1421,12 +1417,12 @@ bool Crit3DMeteoGridDbHandler::loadIdMeteoProperties(QString *myError, QString i } -bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) +bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &errorStr) { QList tableList = _db.tables(QSql::Tables); if (tableList.size() <= 1) { - myError = "No data."; + errorStr = "No data."; return false; } @@ -1437,7 +1433,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if (!_meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) { - myError = "No active cells."; + errorStr = "No active cells."; return false; } @@ -1477,7 +1473,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if (!_meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) { - myError = "active cell not found"; + errorStr = "active cell not found"; return false; } tableD = _tableDaily.prefix + QString::fromStdString(id) + _tableDaily.postFix; @@ -1489,7 +1485,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if ( qry.lastError().type() != QSqlError::NoError ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -1509,7 +1505,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) } else { - myError = "Daily time field not found: " + _tableDaily.fieldTime; + errorStr = "Daily time field not found: " + _tableDaily.fieldTime; return false; } } @@ -1535,7 +1531,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if (! _meteoGrid->findFirstActiveMeteoPoint(&id, &row, &col)) { - myError = "active cell not found"; + errorStr = "active cell not found"; return false; } @@ -1548,7 +1544,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if ( qry.lastError().type() != QSqlError::NoError && qry.lastError().nativeErrorCode() != tableNotFoundError) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -1569,7 +1565,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) } else { - myError = "Hourly time field not found: " + _tableHourly.fieldTime; + errorStr = "Hourly time field not found: " + _tableHourly.fieldTime; return false; } } @@ -1584,7 +1580,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if(! qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } @@ -1597,7 +1593,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if ( qry.lastError().type() != QSqlError::NoError ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -1609,7 +1605,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) } else { - myError = "PragaYear field not found"; + errorStr = "PragaYear field not found"; return false; } } @@ -1618,7 +1614,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if ( qry.lastError().type() != QSqlError::NoError ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -1629,7 +1625,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) } else { - myError = "PragaMonth field not found"; + errorStr = "PragaMonth field not found"; return false; } } @@ -1639,7 +1635,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if ( qry.lastError().type() != QSqlError::NoError ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -1650,7 +1646,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) } else { - myError = "PragaMonth field not found"; + errorStr = "PragaMonth field not found"; return false; } } @@ -1695,7 +1691,7 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) if (_firstDate == noDate || _lastDate == noDate) { - myError = "Missing data."; + errorStr = "Missing data."; return false; } @@ -1703,15 +1699,15 @@ bool Crit3DMeteoGridDbHandler::updateMeteoGridDate(QString &myError) } -bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate) +bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &errorStr, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate) { - myError = ""; + errorStr = ""; QString tableD = _tableDaily.prefix + meteoPointId + _tableDaily.postFix; unsigned row, col; if (! _meteoGrid->findMeteoPointFromId(&row, &col, meteoPointId.toStdString()) ) { - myError = "Missing meteoPoint id: " + meteoPointId; + errorStr = "Missing meteoPoint id: " + meteoPointId; return false; } @@ -1724,7 +1720,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, const QString { if (firstDate > _lastDailyDate || lastDate < _firstDailyDate) { - myError = "Missing data in this time interval."; + errorStr = "Missing data in this time interval."; return false; } } @@ -1749,7 +1745,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, const QString if(! qry.exec()) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } @@ -1765,14 +1761,14 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, const QString { if (! getValue(qry.value(_tableDaily.fieldTime), &date)) { - myError = "Missing " + _tableDaily.fieldTime; + errorStr = "Missing " + _tableDaily.fieldTime; return false; } } if (! getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode"; + errorStr = "Missing VariableCode"; return false; } @@ -1780,7 +1776,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, const QString if (! _meteoGrid->meteoPointPointer(row, col)->setMeteoPointValueD(getCrit3DDate(date), variable, value)) { - myError = "Error in setMeteoPointValueD"; + errorStr = "Error in setMeteoPointValueD"; return false; } } @@ -1789,15 +1785,15 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyData(QString &myError, const QString return true; } -bool Crit3DMeteoGridDbHandler::loadGridDailyMeteoPrec(QString &myError, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate) +bool Crit3DMeteoGridDbHandler::loadGridDailyMeteoPrec(QString &errorStr, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate) { - myError = ""; + errorStr = ""; QString tableD = _tableDaily.prefix + meteoPointId + _tableDaily.postFix; unsigned row, col; if ( !_meteoGrid->findMeteoPointFromId(&row, &col, meteoPointId.toStdString()) ) { - myError = "Missing meteoPoint id: " + meteoPointId; + errorStr = "Missing meteoPoint id: " + meteoPointId; return false; } @@ -1810,7 +1806,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyMeteoPrec(QString &myError, const QS { if (firstDate > _lastDailyDate || lastDate < _firstDailyDate) { - myError = "Missing data in this time interval."; + errorStr = "Missing data in this time interval."; return false; } } @@ -1844,7 +1840,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyMeteoPrec(QString &myError, const QS if(! qry.exec()) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } @@ -1860,14 +1856,14 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyMeteoPrec(QString &myError, const QS { if (! getValue(qry.value(_tableDaily.fieldTime), &date)) { - myError = "Missing " + _tableDaily.fieldTime; + errorStr = "Missing " + _tableDaily.fieldTime; return false; } } if (! getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode"; + errorStr = "Missing VariableCode"; return false; } @@ -1875,7 +1871,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyMeteoPrec(QString &myError, const QS if (! _meteoGrid->meteoPointPointer(row, col)->setMeteoPointValueD(getCrit3DDate(date), variable, value)) { - myError = "Error in setMeteoPointValueD"; + errorStr = "Error in setMeteoPointValueD"; return false; } } @@ -1885,13 +1881,13 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyMeteoPrec(QString &myError, const QS } -bool Crit3DMeteoGridDbHandler::loadGridDailyDataEnsemble(QString &myError, QString meteoPoint, int memberNr, QDate first, QDate last) +bool Crit3DMeteoGridDbHandler::loadGridDailyDataEnsemble(QString &errorStr, QString meteoPoint, int memberNr, QDate first, QDate last) { - myError = ""; + errorStr = ""; if (!_meteoGrid->gridStructure().isEnsemble()) { - myError = "Grid structure has not ensemble field"; + errorStr = "Grid structure has not ensemble field"; return false; } @@ -1905,17 +1901,17 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataEnsemble(QString &myError, QStri if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - myError = "Missing MeteoPoint id"; + errorStr = "Missing MeteoPoint id"; return false; } int numberOfDays = first.daysTo(last) + 1; _meteoGrid->meteoPointPointer(row,col)->initializeObsDataD(numberOfDays, getCrit3DDate(first)); - QString statement = QString("SELECT * FROM `%1` WHERE `%2`>= '%3' AND `%2`<= '%4' AND MemberNr = '%5' ORDER BY `%2`").arg(tableD).arg(_tableDaily.fieldTime).arg(first.toString("yyyy-MM-dd")).arg(last.toString("yyyy-MM-dd")).arg(memberNr); + QString statement = QString("SELECT * FROM `%1` WHERE `%2`>= '%3' AND `%2`<= '%4' AND MemberNr = '%5' ORDER BY `%2`").arg(tableD, _tableDaily.fieldTime).arg(first.toString("yyyy-MM-dd")).arg(last.toString("yyyy-MM-dd")).arg(memberNr); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -1924,19 +1920,19 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataEnsemble(QString &myError, QStri { if (!getValue(qry.value(_tableDaily.fieldTime), &date)) { - myError = "Missing fieldTime"; + errorStr = "Missing fieldTime"; return false; } if (!getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode"; + errorStr = "Missing VariableCode"; return false; } if (!getValue(qry.value("Value"), &value)) { - myError = "Missing Value"; + errorStr = "Missing Value"; } meteoVariable variable = getDailyVarEnum(varCode); @@ -1950,9 +1946,9 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataEnsemble(QString &myError, QStri } -bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &myError, QString meteoPoint, QDate first, QDate last) +bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &errorStr, QString meteoPoint, QDate first, QDate last) { - myError = ""; + errorStr = ""; QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPoint + _tableDaily.postFix; @@ -1964,7 +1960,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &myError, QS if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - myError = "Missing MeteoPoint id"; + errorStr = "Missing MeteoPoint id"; return false; } @@ -1975,7 +1971,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &myError, QS _tableDaily.fieldTime, first.toString("yyyy-MM-dd"), last.toString("yyyy-MM-dd")); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -1984,7 +1980,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &myError, QS { if (!getValue(qry.value(_tableDaily.fieldTime), &date)) { - myError = "Missing fieldTime"; + errorStr = "Missing fieldTime"; return false; } @@ -1993,7 +1989,7 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &myError, QS varCode = _tableDaily.varcode[i].varCode; if (!getValue(qry.value(_tableDaily.varcode[i].varField), &value)) { - myError = "Missing VarField"; + errorStr = "Missing VarField"; } meteoVariable variable = getDailyVarEnum(varCode); @@ -2008,15 +2004,15 @@ bool Crit3DMeteoGridDbHandler::loadGridDailyDataFixedFields(QString &myError, QS } -bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString meteoPoint, QDateTime firstDate, QDateTime lastDate) +bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &errorStr, QString meteoPoint, QDateTime firstDate, QDateTime lastDate) { - myError = ""; + errorStr = ""; QString tableH = _tableHourly.prefix + meteoPoint + _tableHourly.postFix; unsigned row, col; - if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) + if (! _meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - myError = "Missing MeteoPoint id"; + errorStr = "Missing MeteoPoint id"; return false; } @@ -2025,7 +2021,7 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString mete if (firstDate.date() > _lastHourlyDate || lastDate.date() < _firstHourlyDate) { - myError = "missing data"; + errorStr = "missing data"; return false; } @@ -2037,9 +2033,9 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString mete .arg(tableH, _tableHourly.fieldTime, firstDate.toString("yyyy-MM-dd hh:mm"), lastDate.toString("yyyy-MM-dd hh:mm") ); - if( !qry.exec(statement) ) + if(! qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); } else { @@ -2051,13 +2047,13 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString mete { if (! getValue(qry.value(_tableHourly.fieldTime), &date)) { - myError = "Missing fieldTime"; + errorStr = "Missing fieldTime"; return false; } if (! getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode"; + errorStr = "Missing VariableCode"; return false; } meteoVariable variable = getHourlyVarEnum(varCode); @@ -2065,7 +2061,7 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString mete if (! _meteoGrid->meteoPointPointer(row,col)->setMeteoPointValueH(getCrit3DDate(date.date()), date.time().hour(), date.time().minute(), variable, value)) { - myError = "Error in setMeteoPointValueH"; + errorStr = "Wrong VariableCode: " + QString::number(varCode); return false; } } @@ -2076,13 +2072,13 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyData(QString &myError, QString mete } -bool Crit3DMeteoGridDbHandler::loadGridHourlyDataEnsemble(QString &myError, QString meteoPoint, int memberNr, QDateTime first, QDateTime last) +bool Crit3DMeteoGridDbHandler::loadGridHourlyDataEnsemble(QString &errorStr, QString meteoPoint, int memberNr, QDateTime first, QDateTime last) { - myError = ""; + errorStr = ""; if (!_meteoGrid->gridStructure().isEnsemble()) { - myError = "Grid structure has not ensemble field"; + errorStr = "Grid structure has not ensemble field"; return false; } @@ -2097,7 +2093,7 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataEnsemble(QString &myError, QStr if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - myError = "Missing MeteoPoint id"; + errorStr = "Missing MeteoPoint id"; return false; } @@ -2105,11 +2101,11 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataEnsemble(QString &myError, QStr _meteoGrid->meteoPointPointer(row, col)->initializeObsDataH(1, numberOfDays, getCrit3DDate(first.date())); QString statement = QString("SELECT * FROM `%1` WHERE `%2` >= '%3' AND `%2` <= '%4' AND MemberNr = '%5' ORDER BY `%2`") - .arg(tableH).arg(_tableHourly.fieldTime).arg(first.toString("yyyy-MM-dd hh:mm")).arg(last.toString("yyyy-MM-dd hh:mm")).arg(memberNr); + .arg(tableH, _tableHourly.fieldTime).arg(first.toString("yyyy-MM-dd hh:mm")).arg(last.toString("yyyy-MM-dd hh:mm")).arg(memberNr); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); } else { @@ -2117,19 +2113,19 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataEnsemble(QString &myError, QStr { if (!getValue(qry.value(_tableHourly.fieldTime), &date)) { - myError = "Missing fieldTime"; + errorStr = "Missing fieldTime"; return false; } if (!getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode"; + errorStr = "Missing VariableCode"; return false; } if (!getValue(qry.value("Value"), &value)) { - myError = "Missing Value"; + errorStr = "Missing Value"; } meteoVariable variable = getHourlyVarEnum(varCode); @@ -2143,9 +2139,9 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataEnsemble(QString &myError, QStr } -bool Crit3DMeteoGridDbHandler::loadGridHourlyDataFixedFields(QString &myError, QString meteoPoint, QDateTime first, QDateTime last) +bool Crit3DMeteoGridDbHandler::loadGridHourlyDataFixedFields(QString &errorStr, QString meteoPoint, QDateTime first, QDateTime last) { - myError = ""; + errorStr = ""; QSqlQuery qry(_db); QString tableH = _tableHourly.prefix + meteoPoint + _tableHourly.postFix; @@ -2158,17 +2154,17 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataFixedFields(QString &myError, Q if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - myError = "Missing MeteoPoint id"; + errorStr = "Missing MeteoPoint id"; return false; } int numberOfDays = first.date().daysTo(last.date()); _meteoGrid->meteoPointPointer(row, col)->initializeObsDataH(1, numberOfDays, getCrit3DDate(first.date())); - QString statement = QString("SELECT * FROM `%1` WHERE `%2` >= '%3' AND `%2`<= '%4' ORDER BY `%2`").arg(tableH).arg(_tableHourly.fieldTime).arg(first.toString("yyyy-MM-dd hh:mm")).arg(last.toString("yyyy-MM-dd hh:mm")); + QString statement = QString("SELECT * FROM `%1` WHERE `%2` >= '%3' AND `%2`<= '%4' ORDER BY `%2`").arg(tableH, _tableHourly.fieldTime).arg(first.toString("yyyy-MM-dd hh:mm")).arg(last.toString("yyyy-MM-dd hh:mm")); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); } else { @@ -2176,7 +2172,7 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataFixedFields(QString &myError, Q { if (!getValue(qry.value(_tableHourly.fieldTime), &date)) { - myError = "Missing fieldTime"; + errorStr = "Missing fieldTime"; return false; } @@ -2186,7 +2182,7 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataFixedFields(QString &myError, Q if (!getValue(qry.value(_tableHourly.varcode[i].varField), &value)) { - myError = "Missing fieldTime"; + errorStr = "Missing fieldTime"; } meteoVariable variable = getHourlyVarEnum(varCode); @@ -2202,14 +2198,14 @@ bool Crit3DMeteoGridDbHandler::loadGridHourlyDataFixedFields(QString &myError, Q } -bool Crit3DMeteoGridDbHandler::loadGridMonthlySingleDate(QString &myError, const QString &meteoPoint, const QDate &myDate) +bool Crit3DMeteoGridDbHandler::loadGridMonthlySingleDate(QString &errorStr, const QString &meteoPoint, const QDate &myDate) { - myError = ""; + errorStr = ""; unsigned row, col; if (! _meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - myError = "Missing MeteoPoint id: " + meteoPoint; + errorStr = "Missing MeteoPoint id: " + meteoPoint; return false; } @@ -2227,7 +2223,7 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlySingleDate(QString &myError, const .arg(meteoPoint).arg(year).arg(month); if(! qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } @@ -2237,7 +2233,7 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlySingleDate(QString &myError, const { if (! getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode."; + errorStr = "Missing VariableCode."; return false; } meteoVariable variable = getMonthlyVarEnum(varCode); @@ -2252,9 +2248,9 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlySingleDate(QString &myError, const } -bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString meteoPoint, QDate firstDate, QDate lastDate) +bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &errorStr, QString meteoPoint, QDate firstDate, QDate lastDate) { - myError = ""; + errorStr = ""; QString table = "MonthlyData"; // set day to 1 to better comparison @@ -2264,7 +2260,7 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met unsigned row, col; if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - myError = "Missing MeteoPoint id"; + errorStr = "Missing MeteoPoint id"; return false; } @@ -2283,7 +2279,7 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met QString statement = QString("SELECT * FROM `%1` WHERE `PragaYear` BETWEEN %2 AND %3 AND PointCode = '%4' ORDER BY `PragaYear`").arg(table).arg(firstDate.year()).arg(lastDate.year()).arg(meteoPoint); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -2292,13 +2288,13 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met { if (!getValue(qry.value("PragaYear"), &year)) { - myError = "Missing PragaYear"; + errorStr = "Missing PragaYear"; return false; } if (!getValue(qry.value("PragaMonth"), &month)) { - myError = "Missing PragaMonth"; + errorStr = "Missing PragaMonth"; return false; } @@ -2310,13 +2306,13 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met if (!getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode"; + errorStr = "Missing VariableCode"; return false; } if (!getValue(qry.value("Value"), &value)) { - myError = "Missing Value"; + errorStr = "Missing Value"; } meteoVariable variable = getMonthlyVarEnum(varCode); @@ -2330,9 +2326,9 @@ bool Crit3DMeteoGridDbHandler::loadGridMonthlyData(QString &myError, QString met } -bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate firstDate, QDate lastDate) +bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &errorStr, QDate firstDate, QDate lastDate) { - myError = ""; + errorStr = ""; QString table = "MonthlyData"; // set day to 1 to better comparison @@ -2366,7 +2362,7 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi QString statement = QString("SELECT * FROM `%1` WHERE `PragaYear` BETWEEN %2 AND %3 ORDER BY `PointCode`").arg(table).arg(firstDate.year()).arg(lastDate.year()); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } else @@ -2375,13 +2371,13 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi { if (! getValue(qry.value("PragaYear"), &year)) { - myError = "Missing PragaYear"; + errorStr = "Missing PragaYear"; return false; } if (! getValue(qry.value("PragaMonth"), &month)) { - myError = "Missing PragaMonth"; + errorStr = "Missing PragaMonth"; return false; } @@ -2393,7 +2389,7 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi if (! getValue(qry.value("PointCode"), &pointCode)) { - myError = "Missing PointCode"; + errorStr = "Missing PointCode"; return false; } @@ -2408,7 +2404,7 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi if (! getValue(qry.value("VariableCode"), &varCode)) { - myError = "Missing VariableCode: " + QString::number(varCode); + errorStr = "Missing VariableCode: " + QString::number(varCode); return false; } @@ -2420,12 +2416,12 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi if (! getValue(qry.value("Value"), &value)) { - myError = "Missing Value"; + errorStr = "Missing Value"; } if (! _meteoGrid->meteoPointPointer(row, col)->setMeteoPointValueM(getCrit3DDate(monthDate), variable, value)) { - myError = "Error in setMeteoPointValueM()"; + errorStr = "Error in setMeteoPointValueM()"; return false; } } @@ -2435,7 +2431,7 @@ bool Crit3DMeteoGridDbHandler::loadGridAllMonthlyData(QString &myError, QDate fi } -std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, QString meteoPoint, +std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *errorStr, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate* firstDateDB) { @@ -2447,14 +2443,14 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, int varCode = getDailyVarCode(variable); if (varCode == NODATA) { - *myError = "Variable not existing"; + *errorStr = "Variable not existing"; return dailyVarList; } unsigned row, col; if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - *myError = "Missing MeteoPoint id"; + *errorStr = "Missing MeteoPoint id"; return dailyVarList; } @@ -2462,10 +2458,10 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, if(! qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); if (!_db.isOpen()) { - qDebug() << "qry exec: db is not open: " << *myError; + qDebug() << "qry exec: db is not open: " << *errorStr; exit(EXIT_FAILURE); } else @@ -2477,10 +2473,10 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, // read first date if (!qry.first()) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); if (!_db.isOpen()) { - qDebug() << "qry.first: db is not open: " << *myError; + qDebug() << "qry.first: db is not open: " << *errorStr; exit(EXIT_FAILURE); } else @@ -2491,10 +2487,10 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, if (!getValue(qry.value(_tableDaily.fieldTime), firstDateDB)) { - *myError = "Missing first date"; + *errorStr = "Missing first date"; if (!_db.isOpen()) { - qDebug() << "qry.value: db is not open: " << *myError; + qDebug() << "qry.value: db is not open: " << *errorStr; exit(EXIT_FAILURE); } else @@ -2507,7 +2503,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, qry.last(); if (!getValue(qry.value(_tableDaily.fieldTime), &lastDateDB)) { - *myError = "Missing last date"; + *errorStr = "Missing last date"; return dailyVarList; } @@ -2536,7 +2532,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVar(QString *myError, } -std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr) +std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *errorStr, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr) { QString myDateStr; float value; @@ -2554,7 +2550,7 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, idVar = getDailyVarCode(variable); if (idVar == NODATA) { - *myError = "Variable not existing"; + *errorStr = "Variable not existing"; return allDataVarList; } tableName = _tableDaily.prefix + id + _tableDaily.postFix; @@ -2568,25 +2564,25 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, idVar = getHourlyVarCode(variable); if (idVar == NODATA) { - *myError = "Variable not existing"; + *errorStr = "Variable not existing"; return allDataVarList; } tableName = _tableHourly.prefix + id + _tableHourly.postFix; startDate = myFirstTime.date().toString("yyyy-MM-dd") + " " + myFirstTime.time().toString("hh:mm"); endDate = myLastTime.date().toString("yyyy-MM-dd") + " " + myLastTime.time().toString("hh:mm"); statement = QString( "SELECT * FROM `%1` WHERE VariableCode = '%2' AND `%3` >= '%4' AND `%3`<= '%5'") - .arg(tableName).arg(idVar).arg(_tableHourly.fieldTime).arg(startDate).arg(endDate); + .arg(tableName).arg(idVar).arg(_tableHourly.fieldTime, startDate, endDate); } else { - *myError = "Frequency should be daily or hourly"; + *errorStr = "Frequency should be daily or hourly"; return allDataVarList; } QDateTime dateTime; QDate date; if( !myQuery.exec(statement) ) { - *myError = myQuery.lastError().text(); + *errorStr = myQuery.lastError().text(); return allDataVarList; } else @@ -2597,7 +2593,7 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, { if (! getValue(myQuery.value(_tableDaily.fieldTime), &date)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return allDataVarList; } myDateStr = date.toString("yyyy-MM-dd"); @@ -2606,7 +2602,7 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, { if (! getValue(myQuery.value(_tableHourly.fieldTime), &dateTime)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return allDataVarList; } // LC dateTime.toString direttamente ritorna una stringa vuota nelle ore di passaggio all'ora legale @@ -2623,7 +2619,7 @@ std::vector Crit3DMeteoGridDbHandler::exportAllDataVar(QString *myError, } -std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString *myError, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate* firstDateDB) +std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString *errorStr, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate* firstDateDB) { QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPoint + _tableDaily.postFix; @@ -2639,7 +2635,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString if (varCode == NODATA) { - *myError = "Variable not existing"; + *errorStr = "Variable not existing"; return dailyVarList; } @@ -2655,7 +2651,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString QString statement = QString("SELECT `%1`, `%2` FROM `%3` WHERE `%1` >= '%4' AND `%1` <= '%5' ORDER BY `%1`").arg(_tableDaily.fieldTime).arg(varField).arg(tableD).arg(first.toString("yyyy-MM-dd")).arg(last.toString("yyyy-MM-dd")); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); } else { @@ -2666,13 +2662,13 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString { if (!getValue(qry.value(_tableDaily.fieldTime), firstDateDB)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return dailyVarList; } if (!getValue(qry.value(varField), &value)) { - *myError = "Missing Value"; + *errorStr = "Missing Value"; } dailyVarList.push_back(value); previousDate = *firstDateDB; @@ -2682,7 +2678,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString { if (!getValue(qry.value(_tableDaily.fieldTime), &date)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return dailyVarList; } @@ -2694,7 +2690,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString if (!getValue(qry.value(varField), &value)) { - *myError = "Missing Value"; + *errorStr = "Missing Value"; } dailyVarList.push_back(value); previousDate = date; @@ -2708,7 +2704,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridDailyVarFixedFields(QString } -std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVar(QString *myError, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB) +std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVar(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB) { QSqlQuery qry(_db); @@ -2728,20 +2724,20 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVar(QString *myError, if (varCode == NODATA) { - *myError = "Variable not existing"; + *errorStr = "Variable not existing"; return hourlyVarList; } if (!_meteoGrid->findMeteoPointFromId(&row, &col, meteoPoint.toStdString()) ) { - *myError = "Missing MeteoPoint id"; + *errorStr = "Missing MeteoPoint id"; return hourlyVarList; } QString statement = QString("SELECT * FROM `%1` WHERE VariableCode = '%2' AND `%3` >= '%4' AND `%3` <= '%5' ORDER BY `%3`").arg(tableH).arg(varCode).arg(_tableHourly.fieldTime).arg(first.toString("yyyy-MM-dd hh:mm")).arg(last.toString("yyyy-MM-dd hh:mm")); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); } else { @@ -2752,13 +2748,13 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVar(QString *myError, { if (!getValue(qry.value(_tableHourly.fieldTime), firstDateDB)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return hourlyVarList; } if (!getValue(qry.value("Value"), &value)) { - *myError = "Missing Value"; + *errorStr = "Missing Value"; } hourlyVarList.push_back(value); previousDateTime = *firstDateDB; @@ -2768,7 +2764,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVar(QString *myError, { if (!getValue(qry.value(_tableHourly.fieldTime), &dateTime)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return hourlyVarList; } @@ -2780,7 +2776,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVar(QString *myError, if (!getValue(qry.value("Value"), &value)) { - *myError = "Missing Value"; + *errorStr = "Missing Value"; } hourlyVarList.push_back(value); previousDateTime = dateTime; @@ -2795,7 +2791,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVar(QString *myError, } -std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QString *myError, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB) +std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB) { QSqlQuery qry(_db); QString tableH = _tableHourly.prefix + meteoPoint + _tableHourly.postFix; @@ -2811,7 +2807,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QStrin if (varCode == NODATA) { - *myError = "Variable not existing"; + *errorStr = "Variable not existing"; return hourlyVarList; } @@ -2829,7 +2825,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QStrin QString statement = QString("SELECT `%1`, `%2` FROM `%3` WHERE `%1` >= '%4' AND `%1` <= '%5' ORDER BY `%1`").arg(_tableHourly.fieldTime).arg(varField).arg(tableH).arg(first.toString("yyyy-MM-dd hh:mm")).arg(last.toString("yyyy-MM-dd hh:mm")); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); } else { @@ -2840,13 +2836,13 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QStrin { if (!getValue(qry.value(_tableHourly.fieldTime), firstDateDB)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return hourlyVarList; } if (!getValue(qry.value(varField), &value)) { - *myError = "Missing Value"; + *errorStr = "Missing Value"; } hourlyVarList.push_back(value); previousDateTime = *firstDateDB; @@ -2856,7 +2852,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QStrin { if (!getValue(qry.value(_tableHourly.fieldTime), &dateTime)) { - *myError = "Missing fieldTime"; + *errorStr = "Missing fieldTime"; return hourlyVarList; } @@ -2868,7 +2864,7 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QStrin if (!getValue(qry.value(varField), &value)) { - *myError = "Missing Value"; + *errorStr = "Missing Value"; } hourlyVarList.push_back(value); previousDateTime = dateTime; @@ -2883,18 +2879,18 @@ std::vector Crit3DMeteoGridDbHandler::loadGridHourlyVarFixedFields(QStrin } -bool Crit3DMeteoGridDbHandler::saveCellGridDailyData(QString *myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, +bool Crit3DMeteoGridDbHandler::saveCellGridDailyData(QString *errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList, Crit3DMeteoSettings* meteoSettings) { QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPointID + _tableDaily.postFix; QString statement = QString("CREATE TABLE IF NOT EXISTS `%1`" - "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableD).arg(_tableDaily.fieldTime); + "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableD, _tableDaily.fieldTime); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -2919,7 +2915,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridDailyData(QString *myError, QString m if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } } @@ -2929,7 +2925,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridDailyData(QString *myError, QString m // warning: delete all previous data -bool Crit3DMeteoGridDbHandler::deleteAndWriteCellGridDailyData(QString& myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, +bool Crit3DMeteoGridDbHandler::deleteAndWriteCellGridDailyData(QString& errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList, Crit3DMeteoSettings* meteoSettings) { QSqlQuery qry(_db); @@ -2938,10 +2934,10 @@ bool Crit3DMeteoGridDbHandler::deleteAndWriteCellGridDailyData(QString& myError, QString statement = QString("DROP TABLE `%1`").arg(tableD); qry.exec(statement); - statement = QString("CREATE TABLE `%1`(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableD).arg(_tableDaily.fieldTime); + statement = QString("CREATE TABLE `%1`(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableD, _tableDaily.fieldTime); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } @@ -2966,7 +2962,7 @@ bool Crit3DMeteoGridDbHandler::deleteAndWriteCellGridDailyData(QString& myError, statement = statement.left(statement.length() - 1); if( !qry.exec(statement) ) { - myError = qry.lastError().text(); + errorStr = qry.lastError().text(); return false; } @@ -2974,23 +2970,23 @@ bool Crit3DMeteoGridDbHandler::deleteAndWriteCellGridDailyData(QString& myError, } -bool Crit3DMeteoGridDbHandler::saveCellGridDailyDataEnsemble(QString *myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, +bool Crit3DMeteoGridDbHandler::saveCellGridDailyDataEnsemble(QString *errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList, int memberNr, Crit3DMeteoSettings* meteoSettings) { QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPointID + _tableDaily.postFix; QString statement = QString("CREATE TABLE IF NOT EXISTS `%1`" - "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), MemberNr int(11), PRIMARY KEY(%2,VariableCode,MemberNr))").arg(tableD).arg(_tableDaily.fieldTime); + "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), MemberNr int(11), PRIMARY KEY(%2,VariableCode,MemberNr))").arg(tableD, _tableDaily.fieldTime); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else { - statement = QString(("REPLACE INTO `%1` (%2, VariableCode, Value, MemberNr) VALUES ")).arg(tableD).arg(_tableDaily.fieldTime); + statement = QString(("REPLACE INTO `%1` (%2, VariableCode, Value, MemberNr) VALUES ")).arg(tableD, _tableDaily.fieldTime); foreach (meteoVariable meteoVar, meteoVariableList) if (getVarFrequency(meteoVar) == daily) @@ -3011,7 +3007,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridDailyDataEnsemble(QString *myError, Q if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } } @@ -3019,29 +3015,29 @@ bool Crit3DMeteoGridDbHandler::saveCellGridDailyDataEnsemble(QString *myError, Q return true; } -bool Crit3DMeteoGridDbHandler::saveListHourlyData(QString *myError, QString meteoPointID, QDateTime firstDateTime, meteoVariable meteoVar, QList values) +bool Crit3DMeteoGridDbHandler::saveListHourlyData(QString *errorStr, QString meteoPointID, QDateTime firstDateTime, meteoVariable meteoVar, QList values) { QSqlQuery qry(_db); QString tableH = _tableHourly.prefix + meteoPointID + _tableHourly.postFix; int varCode = getHourlyVarCode(meteoVar); QString statement = QString("CREATE TABLE IF NOT EXISTS `%1`" - "(%2 datetime, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableH).arg(_tableHourly.fieldTime); + "(%2 datetime, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableH, _tableHourly.fieldTime); qry.exec(statement); int nHours = values.size(); QDateTime last = firstDateTime.addSecs(3600*(nHours-1)); statement = QString("DELETE FROM `%1` WHERE %2 BETWEEN CAST('%3' AS DATETIME) AND CAST('%4' AS DATETIME) AND VariableCode = '%5'") - .arg(tableH).arg(_tableHourly.fieldTime).arg(firstDateTime.toString("yyyy-MM-dd hh:mm:00")).arg(last.toString("yyyy-MM-dd hh:mm:00")).arg(varCode); + .arg(tableH, _tableHourly.fieldTime).arg(firstDateTime.toString("yyyy-MM-dd hh:mm:00")).arg(last.toString("yyyy-MM-dd hh:mm:00")).arg(varCode); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else { - statement = QString(("INSERT INTO `%1` (%2, VariableCode, Value) VALUES ")).arg(tableH).arg(_tableHourly.fieldTime); + statement = QString(("INSERT INTO `%1` (%2, VariableCode, Value) VALUES ")).arg(tableH, _tableHourly.fieldTime); for (int i = 0; i values, bool reverseOrder) +bool Crit3DMeteoGridDbHandler::saveListDailyData(QString *errorStr, QString meteoPointID, QDate firstDate, meteoVariable meteoVar, QList values, bool reverseOrder) { QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPointID + _tableDaily.postFix; int varCode = getDailyVarCode(meteoVar); QString statement = QString("CREATE TABLE IF NOT EXISTS `%1`" - "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableD).arg(_tableDaily.fieldTime); + "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(%2,VariableCode))").arg(tableD, _tableDaily.fieldTime); qry.exec(statement); int nDays = values.size(); QDate lastDate = firstDate.addDays(nDays-1); statement = QString("DELETE FROM `%1` WHERE %2 BETWEEN CAST('%3' AS DATE) AND CAST('%4' AS DATE) AND VariableCode = '%5'") - .arg(tableD).arg(_tableDaily.fieldTime).arg(firstDate.toString("yyyy-MM-dd")).arg(lastDate.toString("yyyy-MM-dd")).arg(varCode); + .arg(tableD, _tableDaily.fieldTime).arg(firstDate.toString("yyyy-MM-dd")).arg(lastDate.toString("yyyy-MM-dd")).arg(varCode); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else { - statement = QString(("INSERT INTO `%1` (%2, VariableCode, Value) VALUES ")).arg(tableD).arg(_tableDaily.fieldTime); + statement = QString(("INSERT INTO `%1` (%2, VariableCode, Value) VALUES ")).arg(tableD, _tableDaily.fieldTime); for (int i = 0; i values) + +bool Crit3DMeteoGridDbHandler::saveListDailyDataEnsemble(QString *errorStr, QString meteoPointID, QDate date, meteoVariable meteoVar, QList values) { QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPointID + _tableDaily.postFix; int varCode = getDailyVarCode(meteoVar); QString statement = QString("CREATE TABLE IF NOT EXISTS `%1`" - "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), MemberNr int(11), PRIMARY KEY(%2,VariableCode,MemberNr))").arg(tableD).arg(_tableDaily.fieldTime); + "(%2 date, VariableCode tinyint(3) UNSIGNED, Value float(6,1), MemberNr int(11), PRIMARY KEY(%2,VariableCode,MemberNr))").arg(tableD, _tableDaily.fieldTime); qry.exec(statement); statement = QString("DELETE FROM `%1` WHERE %2 = DATE('%3') AND VariableCode = '%4'") - .arg(tableD).arg(_tableDaily.fieldTime).arg(date.toString("yyyy-MM-dd")).arg(varCode); - if( !qry.exec(statement) ) + .arg(tableD, _tableDaily.fieldTime, date.toString("yyyy-MM-dd")).arg(varCode); + if(! qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else { - statement = QString(("INSERT INTO `%1` (%2, VariableCode, Value, MemberNr) VALUES ")).arg(tableD).arg(_tableDaily.fieldTime); - for (int i = 0; i meteoVariableList) { QSqlQuery qry(_db); @@ -3397,7 +3397,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridMonthlyData(QString *myError, QString if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -3427,7 +3427,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridMonthlyData(QString *myError, QString if( ! qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } } @@ -3435,7 +3435,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridMonthlyData(QString *myError, QString return true; } -bool Crit3DMeteoGridDbHandler::saveGridData(QString *myError, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList, Crit3DMeteoSettings* meteoSettings) +bool Crit3DMeteoGridDbHandler::saveGridData(QString *errorStr, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList, Crit3DMeteoSettings* meteoSettings) { std::string id; meteoVariable var; @@ -3458,13 +3458,13 @@ bool Crit3DMeteoGridDbHandler::saveGridData(QString *myError, QDateTime firstTim { if (! gridStructure().isFixedFields()) { - if (isHourly) saveCellGridHourlyData(myError, QString::fromStdString(id), row, col, firstTime, lastTime, meteoVariableList); - if (isDaily) saveCellGridDailyData(myError, QString::fromStdString(id), row, col, firstTime.date(), lastDate, meteoVariableList, meteoSettings); + if (isHourly) saveCellGridHourlyData(errorStr, QString::fromStdString(id), row, col, firstTime, lastTime, meteoVariableList); + if (isDaily) saveCellGridDailyData(errorStr, QString::fromStdString(id), row, col, firstTime.date(), lastDate, meteoVariableList, meteoSettings); } else { - if (isHourly) saveCellGridHourlyDataFF(myError, QString::fromStdString(id), row, col, firstTime, lastTime); - if (isDaily) saveCellGridDailyDataFF(myError, QString::fromStdString(id), row, col, firstTime.date(), lastDate, meteoSettings); + if (isHourly) saveCellGridHourlyDataFF(errorStr, QString::fromStdString(id), row, col, firstTime, lastTime); + if (isDaily) saveCellGridDailyDataFF(errorStr, QString::fromStdString(id), row, col, firstTime.date(), lastDate, meteoSettings); } } @@ -3472,7 +3472,7 @@ bool Crit3DMeteoGridDbHandler::saveGridData(QString *myError, QDateTime firstTim } -bool Crit3DMeteoGridDbHandler::saveGridHourlyData(QString *myError, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList) +bool Crit3DMeteoGridDbHandler::saveGridHourlyData(QString *errorStr, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList) { std::string id; @@ -3484,11 +3484,11 @@ bool Crit3DMeteoGridDbHandler::saveGridHourlyData(QString *myError, QDateTime fi { if (!gridStructure().isFixedFields()) { - saveCellGridHourlyData(myError, QString::fromStdString(id), row, col, firstDate, lastDate, meteoVariableList); + saveCellGridHourlyData(errorStr, QString::fromStdString(id), row, col, firstDate, lastDate, meteoVariableList); } else { - saveCellGridHourlyDataFF(myError, QString::fromStdString(id), row, col, firstDate, lastDate); + saveCellGridHourlyDataFF(errorStr, QString::fromStdString(id), row, col, firstDate, lastDate); } } } @@ -3497,7 +3497,7 @@ bool Crit3DMeteoGridDbHandler::saveGridHourlyData(QString *myError, QDateTime fi return true; } -bool Crit3DMeteoGridDbHandler::saveGridDailyData(QString *myError, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList, Crit3DMeteoSettings* meteoSettings) +bool Crit3DMeteoGridDbHandler::saveGridDailyData(QString *errorStr, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList, Crit3DMeteoSettings* meteoSettings) { std::string id; @@ -3509,11 +3509,11 @@ bool Crit3DMeteoGridDbHandler::saveGridDailyData(QString *myError, QDateTime fir { if (! gridStructure().isFixedFields()) { - saveCellGridDailyData(myError, QString::fromStdString(id), row, col, firstDate.date(), lastDate.date(), meteoVariableList, meteoSettings); + saveCellGridDailyData(errorStr, QString::fromStdString(id), row, col, firstDate.date(), lastDate.date(), meteoVariableList, meteoSettings); } else { - saveCellGridDailyDataFF(myError, QString::fromStdString(id), row, col, firstDate.date(), lastDate.date(), meteoSettings); + saveCellGridDailyDataFF(errorStr, QString::fromStdString(id), row, col, firstDate.date(), lastDate.date(), meteoSettings); } } } @@ -3522,7 +3522,7 @@ bool Crit3DMeteoGridDbHandler::saveGridDailyData(QString *myError, QDateTime fir return true; } -bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *myError, QString meteoPointID, int row, int col, +bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *errorStr, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList) { QSqlQuery qry(_db); @@ -3530,11 +3530,11 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *myError, QString QString statement = QString("CREATE TABLE IF NOT EXISTS `%1` " - "(`%2` datetime, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(`%2`,VariableCode))").arg(tableH).arg(_tableHourly.fieldTime); + "(`%2` datetime, VariableCode tinyint(3) UNSIGNED, Value float(6,1), PRIMARY KEY(`%2`,VariableCode))").arg(tableH, _tableHourly.fieldTime); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -3559,7 +3559,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *myError, QString if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } } @@ -3567,7 +3567,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyData(QString *myError, QString return true; } -bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *myError, QString meteoPointID, int row, int col, +bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *errorStr, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList, int memberNr) { QSqlQuery qry(_db); @@ -3580,7 +3580,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *myError, if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -3605,7 +3605,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *myError, if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } } @@ -3613,7 +3613,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataEnsemble(QString *myError, return true; } -bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataFF(QString *myError, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime) +bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataFF(QString *errorStr, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime) { QSqlQuery qry(_db); QString tableH = _tableHourly.prefix + meteoPointID + _tableHourly.postFix; @@ -3632,7 +3632,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataFF(QString *myError, QStrin if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -3660,7 +3660,7 @@ bool Crit3DMeteoGridDbHandler::saveCellGridHourlyDataFF(QString *myError, QStrin if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } } @@ -3799,6 +3799,7 @@ QDate Crit3DMeteoGridDbHandler::getFirstDailyDate() const return _firstDailyDate; } + QDate Crit3DMeteoGridDbHandler::getLastDailyDate() const { if (_lastDailyDate.year() == 1800) @@ -3808,6 +3809,7 @@ QDate Crit3DMeteoGridDbHandler::getLastDailyDate() const return _lastDailyDate; } + QDate Crit3DMeteoGridDbHandler::getFirstHourlyDate() const { if (_firstHourlyDate.year() == 1800) @@ -3817,6 +3819,7 @@ QDate Crit3DMeteoGridDbHandler::getFirstHourlyDate() const return _firstHourlyDate; } + QDate Crit3DMeteoGridDbHandler::getLastHourlyDate() const { if (_lastHourlyDate.year() == 1800) @@ -3826,6 +3829,7 @@ QDate Crit3DMeteoGridDbHandler::getLastHourlyDate() const return _lastHourlyDate; } + QDate Crit3DMeteoGridDbHandler::getFirstMonthlytDate() const { if (_firstMonthlyDate.year() == 1800) @@ -3835,6 +3839,7 @@ QDate Crit3DMeteoGridDbHandler::getFirstMonthlytDate() const return _firstMonthlyDate; } + QDate Crit3DMeteoGridDbHandler::getLastMonthlyDate() const { if (_lastMonthlyDate.year() == 1800) @@ -3844,14 +3849,15 @@ QDate Crit3DMeteoGridDbHandler::getLastMonthlyDate() const return _lastMonthlyDate; } -bool Crit3DMeteoGridDbHandler::idDailyList(QString *myError, QList* idMeteoList) + +bool Crit3DMeteoGridDbHandler::idDailyList(QString *errorStr, QList* idMeteoList) { QSqlQuery qry(_db); QString statement = QString("SHOW TABLES LIKE '%1%%2'").arg(_tableDaily.prefix, _tableDaily.postFix); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -3870,10 +3876,12 @@ bool Crit3DMeteoGridDbHandler::idDailyList(QString *myError, QList* idM idMeteoList->append(tableName); } } + return true; } -bool Crit3DMeteoGridDbHandler::getYearList(QString *myError, QString meteoPoint, QList* yearList) + +bool Crit3DMeteoGridDbHandler::getYearList(QString *errorStr, QString meteoPoint, QList* yearList) { QSqlQuery qry(_db); QString tableD = _tableDaily.prefix + meteoPoint + _tableDaily.postFix; @@ -3881,7 +3889,7 @@ bool Crit3DMeteoGridDbHandler::getYearList(QString *myError, QString meteoPoint, QString statement = QString("SELECT DISTINCT DATE_FORMAT(`%1`,'%Y') as Year FROM `%2` ORDER BY Year").arg(_tableDaily.fieldTime, tableD); if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -3900,7 +3908,7 @@ bool Crit3DMeteoGridDbHandler::getYearList(QString *myError, QString meteoPoint, return true; } -bool Crit3DMeteoGridDbHandler::saveLogProcedures(QString *myError, QString nameProc, QDate date) +bool Crit3DMeteoGridDbHandler::saveLogProcedures(QString *errorStr, QString nameProc, QDate date) { QSqlQuery qry(_db); QString table = "log_procedures"; @@ -3910,7 +3918,7 @@ bool Crit3DMeteoGridDbHandler::saveLogProcedures(QString *myError, QString nameP if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } else @@ -3919,7 +3927,7 @@ bool Crit3DMeteoGridDbHandler::saveLogProcedures(QString *myError, QString nameP if( !qry.exec(statement) ) { - *myError = qry.lastError().text(); + *errorStr = qry.lastError().text(); return false; } } @@ -4142,83 +4150,3 @@ bool Crit3DMeteoGridDbHandler::MeteoGridToRasterFlt(double cellSize, const gis:: return true; } - -QDate Crit3DMeteoGridDbHandler::firstDate() const -{ - return _firstDate; -} - -void Crit3DMeteoGridDbHandler::setFirstDate(const QDate &firstDate) -{ - _firstDate = firstDate; -} - -QDate Crit3DMeteoGridDbHandler::lastDate() const -{ - return _lastDate; -} - -void Crit3DMeteoGridDbHandler::setLastDate(const QDate &lastDate) -{ - _lastDate = lastDate; -} - -Crit3DMeteoGrid *Crit3DMeteoGridDbHandler::meteoGrid() const -{ - return _meteoGrid; -} - -void Crit3DMeteoGridDbHandler::setMeteoGrid(Crit3DMeteoGrid *meteoGrid) -{ - _meteoGrid = meteoGrid; -} - -QSqlDatabase Crit3DMeteoGridDbHandler::db() const -{ - return _db; -} - -void Crit3DMeteoGridDbHandler::setDb(const QSqlDatabase &db) -{ - _db = db; -} - -QString Crit3DMeteoGridDbHandler::fileName() const -{ - return _fileName; -} - -TXMLConnection Crit3DMeteoGridDbHandler::connection() const -{ - return _connection; -} - -Crit3DMeteoGridStructure Crit3DMeteoGridDbHandler::gridStructure() const -{ - return _gridStructure; -} - -TXMLTable Crit3DMeteoGridDbHandler::tableDaily() const -{ - return _tableDaily; -} - -TXMLTable Crit3DMeteoGridDbHandler::tableHourly() const -{ - return _tableHourly; -} - -TXMLTable Crit3DMeteoGridDbHandler::tableMonthly() const -{ - return _tableMonthly; -} - -QString Crit3DMeteoGridDbHandler::tableDailyModel() const -{ - return _tableDailyModel; -} - -QString Crit3DMeteoGridDbHandler::tableHourlyModel() const -{ - return _tableHourlyModel; -} diff --git a/agrolib/dbMeteoGrid/dbMeteoGrid.h b/agrolib/dbMeteoGrid/dbMeteoGrid.h index be2f384a..4dca06f0 100644 --- a/agrolib/dbMeteoGrid/dbMeteoGrid.h +++ b/agrolib/dbMeteoGrid/dbMeteoGrid.h @@ -31,7 +31,6 @@ QString password; }; - struct TXMLvar { QString varField; @@ -58,35 +57,41 @@ Crit3DMeteoGridDbHandler(); ~Crit3DMeteoGridDbHandler(); - bool openDatabase(QString *myError); - bool openDatabase(QString *myError, QString connectionName); - bool newDatabase(QString *myError); - bool newDatabase(QString *myError, QString connectionName); - bool deleteDatabase(QString *myError); + QString fileName() const { return _fileName; } + TXMLConnection connection() const { return _connection; } + + QSqlDatabase db() const { return _db; } + void setDb(const QSqlDatabase &db) { _db = db; } + + QDate firstDate() const { return _firstDate; } + QDate lastDate() const { return _lastDate; } + + void setFirstDate(const QDate &firstDate) { _firstDate = firstDate; } + void setLastDate(const QDate &lastDate) { _lastDate = lastDate; } + + Crit3DMeteoGridStructure gridStructure() const { return _gridStructure; } + + Crit3DMeteoGrid *meteoGrid() const { return _meteoGrid; } + void setMeteoGrid(Crit3DMeteoGrid *meteoGrid) { _meteoGrid = meteoGrid; } + + TXMLTable tableHourly() const { return _tableHourly; } + TXMLTable tableDaily() const { return _tableDaily; } + TXMLTable tableMonthly() const { return _tableMonthly; } + + QString tableDailyModel() const { return _tableDailyModel; } + QString tableHourlyModel() const { return _tableHourlyModel; } + + bool openDatabase(QString *errorStr); + bool openDatabase(QString *errorStr, QString connectionName); + bool newDatabase(QString *errorStr); + bool newDatabase(QString *errorStr, QString connectionName); + bool deleteDatabase(QString *errorStr); void closeDatabase(); bool parseXMLFile(QString xmlFileName, QDomDocument* xmlDoc, QString *error); - bool checkXML(QString *myError); - bool parseXMLGrid(QString xmlFileName, QString *myError); + bool checkXML(QString *errorStr); + bool parseXMLGrid(QString xmlFileName, QString *errorStr); void initMapMySqlVarType(); - QSqlDatabase db() const; - QString fileName() const; - TXMLConnection connection() const; - Crit3DMeteoGridStructure gridStructure() const; - Crit3DMeteoGrid *meteoGrid() const; - QDate firstDate() const; - QDate lastDate() const; - TXMLTable tableDaily() const; - TXMLTable tableHourly() const; - TXMLTable tableMonthly() const; - QString tableDailyModel() const; - QString tableHourlyModel() const; - - void setMeteoGrid(Crit3DMeteoGrid *meteoGrid); - void setDb(const QSqlDatabase &db); - void setFirstDate(const QDate &firstDate); - void setLastDate(const QDate &lastDate); - int getDailyVarCode(meteoVariable meteoGridDailyVar); QString getDailyVarField(meteoVariable meteoGridDailyVar); meteoVariable getDailyVarEnum(int varCode); @@ -106,60 +111,60 @@ std::string getHourlyPragaName(meteoVariable meteoVar); std::string getMonthlyPragaName(meteoVariable meteoVar); - bool loadCellProperties(QString *myError); - bool newCellProperties(QString *myError); - bool writeCellProperties(QString *myError, int nRow, int nCol); - bool loadIdMeteoProperties(QString *myError, QString idMeteo); - bool updateMeteoGridDate(QString &myError); - - bool loadGridDailyData(QString &myError, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate); - bool loadGridDailyDataFixedFields(QString &myError, QString meteoPoint, QDate first, QDate last); - bool loadGridDailyDataEnsemble(QString &myError, QString meteoPoint, int memberNr, QDate first, QDate last); - bool loadGridDailyMeteoPrec(QString &myError, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate); - bool loadGridHourlyData(QString &myError, QString meteoPoint, QDateTime firstDate, QDateTime lastDate); - bool loadGridHourlyDataFixedFields(QString &myError, QString meteoPoint, QDateTime first, QDateTime last); - bool loadGridHourlyDataEnsemble(QString &myError, QString meteoPoint, int memberNr, QDateTime first, QDateTime last); - bool loadGridMonthlyData(QString &myError, QString meteoPoint, QDate firstDate, QDate lastDate); - bool loadGridAllMonthlyData(QString &myError, QDate firstDate, QDate lastDate); - bool loadGridMonthlySingleDate(QString &myError, const QString &meteoPoint, const QDate &myDate); - - std::vector loadGridDailyVar(QString *myError, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate *firstDateDB); - std::vector loadGridDailyVarFixedFields(QString *myError, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate* firstDateDB); - std::vector loadGridHourlyVar(QString *myError, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB); - std::vector loadGridHourlyVarFixedFields(QString *myError, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB); - std::vector exportAllDataVar(QString *myError, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr); - bool getYearList(QString *myError, QString meteoPoint, QList* yearList); - bool idDailyList(QString *myError, QList* idMeteoList); - - bool saveGridData(QString *myError, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList, Crit3DMeteoSettings *meteoSettings); - bool saveGridHourlyData(QString *myError, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList); - bool saveGridDailyData(QString *myError, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList, Crit3DMeteoSettings *meteoSettings); - bool deleteAndWriteCellGridDailyData(QString& myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, + bool loadCellProperties(QString *errorStr); + bool newCellProperties(QString *errorStr); + bool writeCellProperties(QString *errorStr, int nRow, int nCol); + bool loadIdMeteoProperties(QString *errorStr, QString idMeteo); + bool updateMeteoGridDate(QString &errorStr); + + bool loadGridDailyData(QString &errorStr, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate); + bool loadGridDailyDataFixedFields(QString &errorStr, QString meteoPoint, QDate first, QDate last); + bool loadGridDailyDataEnsemble(QString &errorStr, QString meteoPoint, int memberNr, QDate first, QDate last); + bool loadGridDailyMeteoPrec(QString &errorStr, const QString &meteoPointId, const QDate &firstDate, const QDate &lastDate); + bool loadGridHourlyData(QString &errorStr, QString meteoPoint, QDateTime firstDate, QDateTime lastDate); + bool loadGridHourlyDataFixedFields(QString &errorStr, QString meteoPoint, QDateTime first, QDateTime last); + bool loadGridHourlyDataEnsemble(QString &errorStr, QString meteoPoint, int memberNr, QDateTime first, QDateTime last); + bool loadGridMonthlyData(QString &errorStr, QString meteoPoint, QDate firstDate, QDate lastDate); + bool loadGridAllMonthlyData(QString &errorStr, QDate firstDate, QDate lastDate); + bool loadGridMonthlySingleDate(QString &errorStr, const QString &meteoPoint, const QDate &myDate); + + std::vector loadGridDailyVar(QString *errorStr, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate *firstDateDB); + std::vector loadGridDailyVarFixedFields(QString *errorStr, QString meteoPoint, meteoVariable variable, QDate first, QDate last, QDate* firstDateDB); + std::vector loadGridHourlyVar(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB); + std::vector loadGridHourlyVarFixedFields(QString *errorStr, QString meteoPoint, meteoVariable variable, QDateTime first, QDateTime last, QDateTime* firstDateDB); + std::vector exportAllDataVar(QString *errorStr, frequencyType freq, meteoVariable variable, QString id, QDateTime myFirstTime, QDateTime myLastTime, std::vector &dateStr); + bool getYearList(QString *errorStr, QString meteoPoint, QList* yearList); + bool idDailyList(QString *errorStr, QList* idMeteoList); + + bool saveGridData(QString *errorStr, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList, Crit3DMeteoSettings *meteoSettings); + bool saveGridHourlyData(QString *errorStr, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList); + bool saveGridDailyData(QString *errorStr, QDateTime firstDate, QDateTime lastDate, QList meteoVariableList, Crit3DMeteoSettings *meteoSettings); + bool deleteAndWriteCellGridDailyData(QString& errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList, Crit3DMeteoSettings* meteoSettings); - bool saveCellGridDailyData(QString *myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList, Crit3DMeteoSettings *meteoSettings); - bool saveCellGridDailyDataFF(QString *myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, Crit3DMeteoSettings *meteoSettings); - bool saveCellGridDailyDataEnsemble(QString *myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, + bool saveCellGridDailyData(QString *errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList, Crit3DMeteoSettings *meteoSettings); + bool saveCellGridDailyDataFF(QString *errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, Crit3DMeteoSettings *meteoSettings); + bool saveCellGridDailyDataEnsemble(QString *errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList, int memberNr, Crit3DMeteoSettings *meteoSettings); - bool saveCellGridMonthlyData(QString *myError, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, + bool saveCellGridMonthlyData(QString *errorStr, QString meteoPointID, int row, int col, QDate firstDate, QDate lastDate, QList meteoVariableList); - bool saveListDailyDataEnsemble(QString *myError, QString meteoPointID, QDate date, meteoVariable meteoVar, QList values); - bool saveListDailyData(QString *myError, QString meteoPointID, QDate firstDate, meteoVariable meteoVar, QList values, bool reverseOrder); - bool cleanDailyOldData(QString *myError, QDate date); - bool saveListHourlyData(QString *myError, QString meteoPointID, QDateTime firstDateTime, meteoVariable meteoVar, QList values); - bool saveCellCurrentGridDaily(QString *myError, QString meteoPointID, QDate date, int varCode, float value); + bool saveListDailyDataEnsemble(QString *errorStr, QString meteoPointID, QDate date, meteoVariable meteoVar, QList values); + bool saveListDailyData(QString *errorStr, QString meteoPointID, QDate firstDate, meteoVariable meteoVar, QList values, bool reverseOrder); + bool cleanDailyOldData(QString *errorStr, QDate date); + bool saveListHourlyData(QString *errorStr, QString meteoPointID, QDateTime firstDateTime, meteoVariable meteoVar, QList values); + bool saveCellCurrentGridDaily(QString *errorStr, QString meteoPointID, QDate date, int varCode, float value); bool saveCellCurrentGridDailyList(QString meteoPointID, QList listEntries, QString &errorStr); bool saveCellCurrentGridHourlyList(QString meteoPointID, QList listEntries, QString &errorStr); bool saveCellCurrentGridDailyFF(QString &errorStr, QString meteoPointID, QDate date, QString varPragaName, float value); - bool saveCellGridHourlyData(QString *myError, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList); - bool saveCellGridHourlyDataFF(QString *myError, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime); - bool saveCellGridHourlyDataEnsemble(QString *myError, QString meteoPointID, int row, int col, + bool saveCellGridHourlyData(QString *errorStr, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList); + bool saveCellGridHourlyDataFF(QString *errorStr, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime); + bool saveCellGridHourlyDataEnsemble(QString *errorStr, QString meteoPointID, int row, int col, QDateTime firstTime, QDateTime lastTime, QList meteoVariableList, int memberNr); bool saveCellCurrentGridHourly(QString& errorStr, QString meteoPointID, QDateTime dateTime, int varCode, float value); bool saveCellCurrentGridHourlyFF(QString &errorStr, QString meteoPointID, QDateTime dateTime, QString varPragaName, float value); - bool activeAllCells(QString *myError); - bool setActiveStateCellsInList(QString *myError, QList idList, bool activeState); + bool activeAllCells(QString *errorStr); + bool setActiveStateCellsInList(QString *errorStr, QList idList, bool activeState); bool saveDailyDataCsv(const QString &csvFileName, const QList &variableList, const QDate &firstDate, const QDate &lastDate, unsigned row, unsigned col, QString &errorStr); @@ -180,7 +185,7 @@ bool isHourly(); bool isMonthly(); - bool saveLogProcedures(QString *myError, QString nameProc, QDate date); + bool saveLogProcedures(QString *errorStr, QString nameProc, QDate date); private: diff --git a/agrolib/dbMeteoPoints/dbMeteoPointsHandler.cpp b/agrolib/dbMeteoPoints/dbMeteoPointsHandler.cpp index 851af863..de82441f 100644 --- a/agrolib/dbMeteoPoints/dbMeteoPointsHandler.cpp +++ b/agrolib/dbMeteoPoints/dbMeteoPointsHandler.cpp @@ -76,28 +76,32 @@ Crit3DMeteoPointsDbHandler::~Crit3DMeteoPointsDbHandler() } -QString Crit3DMeteoPointsDbHandler::getDatasetURL(QString dataset) +QString Crit3DMeteoPointsDbHandler::getDatasetURL(QString dataset, bool &isOk) { - QSqlQuery qry(_db); - QString url = nullptr; - - qry.prepare( "SELECT URL FROM datasets WHERE dataset = :dataset"); - qry.bindValue(":dataset", dataset); + errorStr = ""; + QString queryStr = QString("SELECT URL FROM datasets WHERE dataset = '%1' OR dataset = '%2'").arg(dataset, dataset.toUpper()); - if( !qry.exec() ) + QSqlQuery qry(_db); + if(! qry.exec(queryStr)) { - qDebug() << qry.lastError(); + isOk = false; + errorStr = qry.lastError().text(); + return ""; } else { if (qry.next()) - url = qry.value(0).toString(); - + { + isOk = true; + return qry.value(0).toString(); + } else - qDebug( "Error: dataset not found" ); + { + isOk = false; + errorStr = "dataset " + dataset + " not found in the table 'datasets'"; + return ""; + } } - - return url; } diff --git a/agrolib/dbMeteoPoints/dbMeteoPointsHandler.h b/agrolib/dbMeteoPoints/dbMeteoPointsHandler.h index e159561b..43c859f8 100644 --- a/agrolib/dbMeteoPoints/dbMeteoPointsHandler.h +++ b/agrolib/dbMeteoPoints/dbMeteoPointsHandler.h @@ -40,7 +40,7 @@ QString getErrorString() { return errorStr; } void setErrorString(QString str) { errorStr = str; } - QString getDatasetURL(QString dataset); + QString getDatasetURL(QString dataset, bool &isOk); bool setAndOpenDb(QString dbname_); QList getAllDatasetsList(); diff --git a/agrolib/dbMeteoPoints/download.cpp b/agrolib/dbMeteoPoints/download.cpp index c0eb5e46..65d1e0a7 100644 --- a/agrolib/dbMeteoPoints/download.cpp +++ b/agrolib/dbMeteoPoints/download.cpp @@ -1,4 +1,5 @@ #include "download.h" +#include "dbMeteoPointsHandler.h" #include @@ -55,7 +56,7 @@ bool Download::getPointProperties(QList datasetList) qDebug() << "err: " << error->errorString() << " -> " << error->offset; // check validity of the document - if(!doc.isNull() && doc.isArray()) + if(! doc.isNull() && doc.isArray() ) { QJsonArray jsonArr = doc.array(); @@ -71,7 +72,7 @@ bool Download::getPointProperties(QList datasetList) qDebug() << "jsonDataset: value is not string"; else foreach(QString item, _datasetsList) - if (jsonDataset == item) + if (jsonDataset.toString().toUpper() == item.toUpper()) { this->downloadMetadata(obj); } @@ -258,9 +259,9 @@ void Download::downloadMetadata(QJsonObject obj) _dbMeteo->writePointProperties(pointProp); } + bool Download::getPointPropertiesFromId(QString id, Crit3DMeteoPoint* pointProp) { - bool result = true; QEventLoop loop; @@ -291,7 +292,7 @@ bool Download::getPointPropertiesFromId(QString id, Crit3DMeteoPoint* pointProp) qDebug() << "err: " << error->errorString() << " -> " << error->offset; // check validity of the document - if(!doc.isNull() && doc.isArray()) + if(! doc.isNull() && doc.isArray()) { QJsonArray jsonArr = doc.array(); @@ -392,7 +393,8 @@ bool Download::getPointPropertiesFromId(QString id, Crit3DMeteoPoint* pointProp) } -bool Download::downloadDailyData(QDate startDate, QDate endDate, QString dataset, QList stations, QList variables, bool prec0024) +bool Download::downloadDailyData(const QDate &startDate, const QDate &endDate, const QString &dataset, + QList &stations, QList &variables, bool prec0024, QString &errorString) { QString area, product, refTime; QDate myDate; @@ -403,13 +405,15 @@ bool Download::downloadDailyData(QDate startDate, QDate endDate, QString dataset QList idVar; for (int i = 0; i < variableList.size(); i++) + { idVar.append(QString::number(variableList[i].id())); + } // create station tables _dbMeteo->initStationsDailyTables(startDate, endDate, stations, idVar); // attenzione: il reference time dei giornalieri è a fine giornata (ore 00 di day+1) - refTime = QString("reftime:>%1,<=%2").arg(startDate.toString("yyyy-MM-dd")).arg(endDate.addDays(1).toString("yyyy-MM-dd")); + refTime = QString("reftime:>%1,<=%2").arg(startDate.toString("yyyy-MM-dd"), endDate.addDays(1).toString("yyyy-MM-dd")); product = QString(";product: VM2,%1").arg(variables[0]); @@ -432,20 +436,27 @@ bool Download::downloadDailyData(QDate startDate, QDate endDate, QString dataset if (j == 0) { area = QString(";area: VM2,%1").arg(stations[countStation]); - j = j+1; - countStation = countStation+1; + countStation++; + j++; } while (countStation < stations.size() && j < maxStationSize) { area = area % QString(" or VM2,%1").arg(stations[countStation]); - countStation = countStation+1; - j = j+1; + countStation++; + j++; + } + + bool isOk; + url = QUrl(QString("%1/query").arg(_dbMeteo->getDatasetURL(dataset, isOk))); + if (! isOk) + { + errorString = _dbMeteo->getErrorString(); + return false; } QNetworkAccessManager* manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit())); - url = QUrl(QString("%1/query").arg(_dbMeteo->getDatasetURL(dataset))); request.setUrl(url); request.setRawHeader("Authorization", _authorization); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded")); @@ -460,7 +471,7 @@ bool Download::downloadDailyData(QDate startDate, QDate endDate, QString dataset if (reply->error() != QNetworkReply::NoError) { - qDebug( "Network Error" ); + errorString = "Network Error"; downloadOk = false; } else @@ -515,7 +526,7 @@ bool Download::downloadDailyData(QDate startDate, QDate endDate, QString dataset } } - if (!emptyLine) + if (! emptyLine) { downloadOk = _dbMeteo->saveDailyData(); } @@ -533,9 +544,9 @@ bool Download::downloadDailyData(QDate startDate, QDate endDate, QString dataset } -bool Download::downloadHourlyData(QDate startDate, QDate endDate, QString dataset, QList stations, QList variables) +bool Download::downloadHourlyData(const QDate &startDate, const QDate &endDate, const QString &dataset, + QList &stations, QList &variables, QString &errorString) { - QList variableList = _dbMeteo->getVariableProperties(variables); if (variableList.size() == 0) return false; @@ -562,7 +573,7 @@ bool Download::downloadHourlyData(QDate startDate, QDate endDate, QString datase endTime = endTime.addSecs(3600 * 24); // reftime - QString refTime = QString("reftime:>=%1,<=%2").arg(startTime.toString("yyyy-MM-dd hh:mm")).arg(endTime.toString("yyyy-MM-dd hh:mm")); + QString refTime = QString("reftime:>=%1,<=%2").arg(startTime.toString("yyyy-MM-dd hh:mm"), endTime.toString("yyyy-MM-dd hh:mm")); QEventLoop loop; @@ -587,10 +598,18 @@ bool Download::downloadHourlyData(QDate startDate, QDate endDate, QString datase countStation = countStation+1; j = j+1; } + + bool isOk; + url = QUrl(QString("%1/query").arg(_dbMeteo->getDatasetURL(dataset, isOk))); + if (! isOk) + { + errorString = _dbMeteo->getErrorString(); + return false; + } + QNetworkAccessManager* manager = new QNetworkAccessManager(this); connect(manager, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit())); - url = QUrl(QString("%1/query").arg(_dbMeteo->getDatasetURL(dataset))); request.setUrl(url); request.setRawHeader("Authorization", _authorization); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded")); @@ -604,7 +623,7 @@ bool Download::downloadHourlyData(QDate startDate, QDate endDate, QString datase if (reply->error() != QNetworkReply::NoError) { - qDebug( "Network Error" ); + errorString = "Network Error"; delete reply; delete manager; return false; diff --git a/agrolib/dbMeteoPoints/download.h b/agrolib/dbMeteoPoints/download.h index 1dab6823..96316a64 100644 --- a/agrolib/dbMeteoPoints/download.h +++ b/agrolib/dbMeteoPoints/download.h @@ -16,8 +16,12 @@ bool getPointPropertiesFromId(QString id, Crit3DMeteoPoint* pointProp); QMap getArmiketIdList(QList datasetList); void downloadMetadata(QJsonObject obj); - bool downloadDailyData(QDate startDate, QDate endDate, QString dataset, QList stations, QList variables, bool prec0024); - bool downloadHourlyData(QDate startDate, QDate endDate, QString dataset, QList stations, QList variables); + + bool downloadDailyData(const QDate &startDate, const QDate &endDate, const QString &dataset, + QList &stations, QList &variables, bool prec0024, QString &errorString); + + bool downloadHourlyData(const QDate &startDate, const QDate &endDate, const QString &dataset, + QList &stations, QList &variables, QString &errorString); DbArkimet* getDbArkimet(); diff --git a/agrolib/gis/gis.cpp b/agrolib/gis/gis.cpp index ef6f831f..7a0a1fbd 100644 --- a/agrolib/gis/gis.cpp +++ b/agrolib/gis/gis.cpp @@ -622,7 +622,8 @@ namespace gis } /*! no values */ - if (isFirstValue) return false; + if (isFirstValue) + return false; myGrid->maximum = maximum; myGrid->minimum = minimum; diff --git a/agrolib/homogeneityWidget/annualSeriesChartView.cpp b/agrolib/homogeneityWidget/annualSeriesChartView.cpp index 096fb2dd..8332c69c 100644 --- a/agrolib/homogeneityWidget/annualSeriesChartView.cpp +++ b/agrolib/homogeneityWidget/annualSeriesChartView.cpp @@ -62,7 +62,7 @@ void AnnualSeriesChartView::draw(std::vector years, std::vector outp axisY->setMin(minValue-3); } axisX->setRange(years[0], years[years.size()-1]); - int nYears = years.size(); + int nYears = int(years.size()); if ( nYears <= 15) { axisX->setTickCount(nYears); diff --git a/agrolib/homogeneityWidget/homogeneityChartView.cpp b/agrolib/homogeneityWidget/homogeneityChartView.cpp index f9380be1..876ad56f 100644 --- a/agrolib/homogeneityWidget/homogeneityChartView.cpp +++ b/agrolib/homogeneityWidget/homogeneityChartView.cpp @@ -94,7 +94,7 @@ void HomogeneityChartView::drawSNHT(std::vector years, std::vector axisY->setMin(minValue-3); } axisX->setRange(years[0], years[years.size()-1]); - int nYears = years.size(); + int nYears = int(years.size()); if ( nYears <= 15) { axisX->setTickCount(nYears); diff --git a/agrolib/interpolation/interpolation.cpp b/agrolib/interpolation/interpolation.cpp index a93fa14d..4e4d4a06 100644 --- a/agrolib/interpolation/interpolation.cpp +++ b/agrolib/interpolation/interpolation.cpp @@ -1017,7 +1017,7 @@ float gaussWeighted(vector &myPointList) // TODO elevation std dev? void localSelection(vector &inputPoints, vector &selectedPoints, - float x, float y, Crit3DInterpolationSettings& mySettings) + float x, float y, float z, Crit3DInterpolationSettings& mySettings) { // search more stations to assure min points with all valid proxies float ratioMinPoints = float(1.3); @@ -1040,6 +1040,7 @@ void localSelection(vector &inputPoints, vector < unsigned int nrPrimaries = 0; float maxDistance = 0; + float maxHeightDelta = 0; while (nrValid < minPoints || (mySettings.getUseLapseRateCode() && nrPrimaries < minPoints)) { maxDistance = 0; @@ -1054,16 +1055,22 @@ void localSelection(vector &inputPoints, vector < if (checkLapseRateCode(inputPoints[i].lapseRateCode, mySettings.getUseLapseRateCode(), true)) nrPrimaries++; + + if (abs(inputPoints[i].point->z - z) > maxHeightDelta) + maxHeightDelta = fabs(float(inputPoints[i].point->z) - z); } } r0 = r1; r1 += stepRadius; } - if (maxDistance != 0) + if (maxDistance != 0 && maxHeightDelta != 0) for (i=0; i< selectedPoints.size(); i++) - selectedPoints[i].regressionWeight = MAXVALUE(1 - selectedPoints[i].distance / (maxDistance*maxDistance*maxDistance),EPSILON); - + { + selectedPoints[i].regressionWeight = MAXVALUE(1 - selectedPoints[i].distance / (maxDistance*maxDistance), EPSILON); + selectedPoints[i].heightWeight = 1./((2./maxHeightDelta)*selectedPoints[i].point->z+1); + //selectedPoints[i].heightWeight = 1; + } mySettings.setLocalRadius(maxDistance); } @@ -1357,50 +1364,22 @@ bool setAllFittingRanges(Crit3DProxyCombination myCombination, Crit3DInterpolati if (mySettings->getChosenElevationFunction() == piecewiseTwo) { mySettings->getProxy(i)->setFittingFunctionName(piecewiseTwo); - if ((mySettings->getProxy(i)->getFittingParametersRange().empty())) - tempParam = {-200, min-2, 0.001, -0.006, 1800, max+2, 0.01, 0.0015}; - else - { - tempParam = mySettings->getProxy(i)->getFittingParametersRange(); - tempParam[1] = min-2; - tempParam[5] = max+2; - } + tempParam = {-200, min-2, 0, -0.015, 2000, max+2, 0.01, 0.0015}; } else if (mySettings->getChosenElevationFunction() == piecewiseThreeFree) { mySettings->getProxy(i)->setFittingFunctionName(piecewiseThreeFree); - if ((mySettings->getProxy(i)->getFittingParametersRange().empty())) - tempParam = {-200, min-2, 100, 0.001, -0.006, -0.006, 1800, max+2, 1000, 0.007, 0.0015, 0.0015}; - else - { - tempParam = mySettings->getProxy(i)->getFittingParametersRange(); - tempParam[1] = min-2; - tempParam[7] = max+2; - } + tempParam = {-200, min-2, 100, 0, -0.015, -0.015, 2000, max+2, 1000, 0.007, 0.0015, 0.0015}; } else if (mySettings->getChosenElevationFunction() == piecewiseThree) { mySettings->getProxy(i)->setFittingFunctionName(piecewiseThree); - if ((mySettings->getProxy(i)->getFittingParametersRange().empty())) - tempParam = {-200, min-2, 100, 0.001, -0.006, 1800, max+2, 1000, 0.007, 0.0015}; - else - { - tempParam = mySettings->getProxy(i)->getFittingParametersRange(); - tempParam[1] = min-2; - tempParam[6] = max+2; - } + tempParam = {-200, min-2, 100, 0, -0.015, 2000, max+2, 1000, 0.007, 0.0015}; } else if (mySettings->getChosenElevationFunction() == freiFree) { mySettings->getProxy(i)->setFittingFunctionName(freiFree); - if ((mySettings->getProxy(i)->getFittingParametersRange().empty())) - tempParam = {min, 0, -4, -200, 0.1, 0, max+10, 0.006, 4, 1800, 1000, 0.006}; - else - { - tempParam = mySettings->getProxy(i)->getFittingParametersRange(); - tempParam[0] = min-2; - tempParam[6] = max+10; - } + tempParam = {min, 0, -4, -200, 0.1, 0, max+10, 0.006, 4, 2000, 1000, 0.006}; } mySettings->getProxy(i)->setFittingParametersRange(tempParam); } @@ -1441,7 +1420,11 @@ bool setAllFittingParameters_noRange(Crit3DProxyCombination myCombination, Crit3 isPreviousParam = true; } } - else return false; + else + { + errorStr = "no proxy selected."; + return false; + } const double RATIO_DELTA = 1000; @@ -1653,14 +1636,14 @@ bool multipleDetrendingMain(std::vector &myPoints elevationCombination.setProxyActive(elevationPos, true); if (!multipleDetrendingElevation(elevationCombination, elevationParameters, myPoints, mySettings, myVar, errorStr)) - return true; + return false; } Crit3DProxyCombination othersCombination = mySettings->getSelectedCombination(); othersCombination.setProxyActive(elevationPos,false); if (!multipleDetrending(othersCombination, otherParameters, myPoints, mySettings, myVar, errorStr)) - return true; + return false; return true; @@ -1784,7 +1767,7 @@ bool multipleDetrendingElevation(Crit3DProxyCombination elevationCombination, st { predictors.push_back(myPoints[i].getProxyValue(elevationPos)); predictands.push_back(myPoints[i].value); - weights.push_back(myPoints[i].regressionWeight); + weights.push_back(myPoints[i].regressionWeight*myPoints[i].heightWeight); } } @@ -1811,6 +1794,7 @@ bool multipleDetrendingElevation(Crit3DProxyCombination elevationCombination, st if (! setAllFittingParameters_noRange(elevationCombination, mySettings, myFunc, parametersMin, parametersMax, parametersDelta, parameters, errorStr)) { + errorStr = "couldn't prepare the fitting parameters for proxy: elevation."; return false; } int pos = 0; @@ -1819,7 +1803,7 @@ bool multipleDetrendingElevation(Crit3DProxyCombination elevationCombination, st if (!func) { - errorStr = "Wrong or missing fitting function for proxy: elevation."; + errorStr = "wrong or missing fitting function for proxy: elevation."; return false; } @@ -2038,9 +2022,7 @@ bool multipleDetrending(Crit3DProxyCombination othersCombination, std::vector &inputPoints, std::vector &selectedPoints, - float x, float y, Crit3DInterpolationSettings &mySettings); + float x, float y, float z, Crit3DInterpolationSettings &mySettings); bool proxyValidity(std::vector &myPoints, int proxyPos, float stdDevThreshold, double &avg, double &stdDev); diff --git a/agrolib/interpolation/interpolationPoint.h b/agrolib/interpolation/interpolationPoint.h index 82caaef5..126df5b9 100644 --- a/agrolib/interpolation/interpolationPoint.h +++ b/agrolib/interpolation/interpolationPoint.h @@ -22,6 +22,7 @@ float distance; float value; float regressionWeight; + float heightWeight; lapseRateCodeType lapseRateCode; gis::Crit3DRasterGrid* topographicDistance; std::vector proxyValues; diff --git a/agrolib/mathFunctions/furtherMathFunctions.cpp b/agrolib/mathFunctions/furtherMathFunctions.cpp index e54a1b74..202b49b7 100644 --- a/agrolib/mathFunctions/furtherMathFunctions.cpp +++ b/agrolib/mathFunctions/furtherMathFunctions.cpp @@ -2002,7 +2002,7 @@ namespace interpolation const int numSteps = 40; int directions[] = {1, -1}; - int numParamsToVary = parameters.size(); + size_t numParamsToVary = parameters.size(); std::vector firstGuessParam = parameters; for (int step = 1; step <= numSteps; ++step) diff --git a/agrolib/meteo/meteo.cpp b/agrolib/meteo/meteo.cpp index 53c327c1..6a9b1f88 100644 --- a/agrolib/meteo/meteo.cpp +++ b/agrolib/meteo/meteo.cpp @@ -944,9 +944,9 @@ std::string getKeyStringMeteoMap(std::map map, meteo return key; } + std::string getUnitFromVariable(meteoVariable var) { - std::string unit = ""; std::map, std::string>::const_iterator it; std::vector key; @@ -961,9 +961,11 @@ std::string getUnitFromVariable(meteoVariable var) } key.clear(); } + return unit; } + meteoVariable getKeyMeteoVarMeteoMap(std::map map, const std::string& value) { std::map::const_iterator it; diff --git a/agrolib/meteo/meteoPoint.cpp b/agrolib/meteo/meteoPoint.cpp index f823c063..9dd857d9 100644 --- a/agrolib/meteo/meteoPoint.cpp +++ b/agrolib/meteo/meteoPoint.cpp @@ -709,7 +709,7 @@ void Crit3DMeteoPoint::cleanObsDataM() bool Crit3DMeteoPoint::setMeteoPointValueH(const Crit3DDate& myDate, int myHour, int myMinutes, meteoVariable myVar, float myValue) { - //check + // check if (myVar == noMeteoVar || obsDataH == nullptr) { return false; @@ -718,13 +718,13 @@ bool Crit3DMeteoPoint::setMeteoPointValueH(const Crit3DDate& myDate, int myHour, // day index int i = obsDataH[0].date.daysTo(myDate); - //check if out of range (accept +1 date exceed) + // check if out of range (accept +1 date exceed) if (i < 0 || i > nrObsDataDaysH) return false; // sub hourly index int subH = int(ceil(float(myMinutes) / float(60 / hourlyFraction))); - //if +1 date exceed accept only hour 00:00 + // if +1 date exceed accept only hour 00:00 if (i == nrObsDataDaysH && (myHour != 0 || subH != 0)) return false; // hour 0 becomes hour 24 of the previous day diff --git a/agrolib/meteoWidget/meteoWidget.cpp b/agrolib/meteoWidget/meteoWidget.cpp index 17f19dee..e45b2b39 100644 --- a/agrolib/meteoWidget/meteoWidget.cpp +++ b/agrolib/meteoWidget/meteoWidget.cpp @@ -326,23 +326,23 @@ Crit3DMeteoWidget::Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMe axisX = new QBarCategoryAxis(); axisXvirtual = new QBarCategoryAxis(); - axisY = new QValueAxis(); - axisYdx = new QValueAxis(); + axisY_sx = new QValueAxis(); + axisY_dx = new QValueAxis(); axisX->setTitleText("Date"); axisXvirtual->setTitleText("Date"); axisXvirtual->setGridLineVisible(false); - axisY->setRange(0,30); - axisY->setGridLineVisible(false); + axisY_sx->setRange(0,30); + axisY_sx->setGridLineVisible(false); - axisYdx->setRange(0,8); - axisYdx->setGridLineVisible(false); + axisY_dx->setRange(0,8); + axisY_dx->setGridLineVisible(false); chart->addAxis(axisX, Qt::AlignBottom); chart->addAxis(axisXvirtual, Qt::AlignBottom); - chart->addAxis(axisY, Qt::AlignLeft); - chart->addAxis(axisYdx, Qt::AlignRight); + chart->addAxis(axisY_sx, Qt::AlignLeft); + chart->addAxis(axisY_dx, Qt::AlignRight); chart->legend()->setVisible(true); chart->legend()->setAlignment(Qt::AlignBottom); @@ -415,20 +415,20 @@ Crit3DMeteoWidget::~Crit3DMeteoWidget() } -void Crit3DMeteoWidget::setDateIntervalDaily(QDate firstDate, QDate lastDate) +void Crit3DMeteoWidget::setDailyRange(QDate firstDate, QDate lastDate) { firstDailyDate = firstDate; lastDailyDate = lastDate; } -void Crit3DMeteoWidget::setDateIntervalHourly(QDate firstDate, QDate lastDate) +void Crit3DMeteoWidget::setHourlyRange(QDate firstDate, QDate lastDate) { firstHourlyDate = firstDate; lastHourlyDate = lastDate; } -void Crit3DMeteoWidget::setDateIntervalMonthly(QDate firstDate, QDate lastDate) +void Crit3DMeteoWidget::setMonthlyRange(QDate firstDate, QDate lastDate) { firstMonthlyDate = firstDate; lastMonthlyDate = lastDate; @@ -628,13 +628,16 @@ void Crit3DMeteoWidget::drawEnsemble() { lastDailyDate = myDailyDateLast; } + myHourlyDateFirst.setDate(meteoPointsEnsemble[0].getMeteoPointHourlyValuesDate(0).year, meteoPointsEnsemble[0].getMeteoPointHourlyValuesDate(0).month, meteoPointsEnsemble[0].getMeteoPointHourlyValuesDate(0).day); myHourlyDateLast = myHourlyDateFirst.addDays(meteoPointsEnsemble[0].nrObsDataDaysH-1); + if (myHourlyDateFirst.isValid() && myHourlyDateFirst < firstHourlyDate) { firstHourlyDate = myHourlyDateFirst; } + if (myHourlyDateLast.isValid() && myHourlyDateLast > lastHourlyDate) { lastHourlyDate = myHourlyDateLast; @@ -926,7 +929,7 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() categories.append(QString::number(day)); } - QList sortedList; + std::vector sortedList; QList listBoxSet; if (isLine) @@ -952,7 +955,7 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() double value = meteoPointsEnsemble[mp].getMeteoPointValueD(myDate, meteoVar, meteoSettings); if (value != NODATA) { - sortedList.append(value); + sortedList.push_back(value); if (value > maxEnsembleLine) { maxEnsembleLine = value; @@ -964,15 +967,15 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() } } QBoxSet *box = new QBoxSet(); - if (!sortedList.isEmpty()) + if (! sortedList.empty()) { std::sort(sortedList.begin(), sortedList.end()); - int count = sortedList.count(); - box->setValue(QBoxSet::LowerExtreme, sortedList.first()); - box->setValue(QBoxSet::UpperExtreme, sortedList.last()); - box->setValue(QBoxSet::Median, findMedian(sortedList, 0, count)); - box->setValue(QBoxSet::LowerQuartile, findMedian(sortedList, 0, count / 2)); - box->setValue(QBoxSet::UpperQuartile, findMedian(sortedList, count / 2 + (count % 2), count)); + int lastIndex = int(sortedList.size())-1; + box->setValue(QBoxSet::LowerExtreme, sortedList.front()); + box->setValue(QBoxSet::UpperExtreme, sortedList.back()); + box->setValue(QBoxSet::Median, findMedian(sortedList, 0, lastIndex)); + box->setValue(QBoxSet::LowerQuartile, findMedian(sortedList, 0, lastIndex / 2)); + box->setValue(QBoxSet::UpperQuartile, findMedian(sortedList, lastIndex / 2 + (lastIndex % 2), lastIndex)); } else { @@ -992,7 +995,7 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() ensembleSeries.append(series); chart->addSeries(series); series->attachAxis(axisX); - series->attachAxis(axisY); + series->attachAxis(axisY_sx); } } } @@ -1019,7 +1022,7 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() double value = meteoPointsEnsemble[mp].getMeteoPointValueD(myDate, meteoVar, meteoSettings); if (value != NODATA) { - sortedList.append(value); + sortedList.push_back(value); if (value > maxEnsembleBar) { maxEnsembleBar = value; @@ -1027,15 +1030,15 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() } } QBoxSet *box = new QBoxSet(); - if (!sortedList.isEmpty()) + if (! sortedList.empty()) { std::sort(sortedList.begin(), sortedList.end()); - int count = sortedList.count(); - box->setValue(QBoxSet::LowerExtreme, sortedList.first()); - box->setValue(QBoxSet::UpperExtreme, sortedList.last()); - box->setValue(QBoxSet::Median, findMedian(sortedList, 0, count)); - box->setValue(QBoxSet::LowerQuartile, findMedian(sortedList, 0, count / 2)); - box->setValue(QBoxSet::UpperQuartile, findMedian(sortedList, count / 2 + (count % 2), count)); + int lastIndex = int(sortedList.size())-1; + box->setValue(QBoxSet::LowerExtreme, sortedList.front()); + box->setValue(QBoxSet::UpperExtreme, sortedList.back()); + box->setValue(QBoxSet::Median, findMedian(sortedList, 0, lastIndex)); + box->setValue(QBoxSet::LowerQuartile, findMedian(sortedList, 0, lastIndex / 2)); + box->setValue(QBoxSet::UpperQuartile, findMedian(sortedList, lastIndex / 2 + (lastIndex % 2), lastIndex)); } else { @@ -1055,7 +1058,7 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() ensembleSeries.append(series); chart->addSeries(series); series->attachAxis(axisX); - series->attachAxis(axisYdx); + series->attachAxis(axisY_dx); } } } @@ -1064,62 +1067,123 @@ void Crit3DMeteoWidget::drawEnsembleDailyVar() { if (maxEnsembleLine == NODATA && minEnsembleLine == -NODATA) { - axisY->setVisible(false); + axisY_sx->setVisible(false); } else { - axisY->setVisible(true); - axisY->setMax(maxEnsembleLine); - axisY->setMin(minEnsembleLine); - if (axisY->max() == axisY->min()) + axisY_sx->setVisible(true); + axisY_sx->setMax(maxEnsembleLine); + axisY_sx->setMin(minEnsembleLine); + if (axisY_sx->max() == axisY_sx->min()) { - axisY->setRange(axisY->min()-axisY->min()/100, axisY->max()+axisY->max()/100); + axisY_sx->setRange(axisY_sx->min()-axisY_sx->min()/100, axisY_sx->max()+axisY_sx->max()/100); } } } else { - axisY->setVisible(false); + axisY_sx->setVisible(false); } if (isBar) { if (maxEnsembleBar == -1) { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } else { - axisYdx->setVisible(true); + axisY_dx->setVisible(true); if (maxEnsembleBar != 0) { - axisYdx->setRange(0,maxEnsembleBar); + axisY_dx->setRange(0,maxEnsembleBar); } else { - axisYdx->setRange(0,1); + axisY_dx->setRange(0,1); } } } else { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } axisX->setCategories(categories); axisXvirtual->setCategories(categoriesVirtual); axisXvirtual->setGridLineVisible(false); + drawAxisTitle(); + formInfo.close(); + firstDate->blockSignals(false); lastDate->blockSignals(false); +} - formInfo.close(); + +void Crit3DMeteoWidget::drawAxisTitle() +{ + if (! isInitialized) + return; + + QList unitList; + QString axisTitle = ""; + + // axis sx (lines) + for (int i = 0; i < nameLines.size(); i++) + { + meteoVariable meteoVar = getMeteoVar(nameLines[i].toStdString()); + QString unitStr = QString::fromStdString(getUnitFromVariable(meteoVar)); + if (! unitList.contains(unitStr)) + { + unitList.append(unitStr); + } + } + + if (! unitList.empty()) + { + for (int i = 0; i < unitList.size(); i++) + { + if (i > 0) + axisTitle += " , "; + + axisTitle += unitList[i]; + } + } + axisY_sx->setTitleText(axisTitle); + + // axis dx (bar) + unitList.clear(); + for (int i = 0; i < nameBar.size(); i++) + { + meteoVariable meteoVar = getMeteoVar(nameBar[i].toStdString()); + QString unitStr = QString::fromStdString(getUnitFromVariable(meteoVar)); + if (! unitList.contains(unitStr)) + { + unitList.append(unitStr); + } + } + + axisTitle.clear(); + if (! unitList.empty()) + { + for (int i = 0; i < unitList.size(); i++) + { + if (i > 0) + axisTitle += " , "; + + axisTitle += unitList[i]; + } + } + + axisY_dx->setTitleText(axisTitle); } void Crit3DMeteoWidget::drawDailyVar() { - if (! isInitialized) return; + if (! isInitialized) + return; FormInfo formInfo; formInfo.showInfo("Draw daily data..."); @@ -1202,7 +1266,8 @@ void Crit3DMeteoWidget::drawDailyVar() { if (meteoPoints[mp].isDateLoadedD(myDate)) { - lineSeries[mp][i]->append(day, value); // nodata days are not drawed if they are the first of the last day of the serie + // nodata days are not drawed if they are the first of the last day of the series + lineSeries[mp][i]->append(day, value); } } } @@ -1254,33 +1319,33 @@ void Crit3DMeteoWidget::drawDailyVar() { chart->addSeries(barSeries[mp]); barSeries[mp]->attachAxis(axisX); - barSeries[mp]->attachAxis(axisYdx); + barSeries[mp]->attachAxis(axisY_dx); } } if (maxEnsembleBar == -1 && maxBar == -1) { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } else { - axisYdx->setVisible(true); + axisY_dx->setVisible(true); if (maxEnsembleBar > maxBar) { - axisYdx->setRange(0,maxEnsembleBar); + axisY_dx->setRange(0,maxEnsembleBar); } else { - axisYdx->setRange(0,maxBar); + axisY_dx->setRange(0,maxBar); } - if (axisYdx->max() == axisYdx->min()) + if (axisY_dx->max() == axisY_dx->min()) { - axisYdx->setRange(0,1); + axisY_dx->setRange(0,1); } } } else { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } if (isLine) @@ -1293,7 +1358,7 @@ void Crit3DMeteoWidget::drawDailyVar() { chart->addSeries(lineSeries[mp][i]); lineSeries[mp][i]->attachAxis(axisX); - lineSeries[mp][i]->attachAxis(axisY); + lineSeries[mp][i]->attachAxis(axisY_sx); connect(lineSeries[mp][i], &QLineSeries::hovered, this, &Crit3DMeteoWidget::tooltipLineSeries); connect(lineSeries[mp][i], &QLineSeries::clicked, this, &Crit3DMeteoWidget::editLineSeries); } @@ -1301,41 +1366,41 @@ void Crit3DMeteoWidget::drawDailyVar() } if (maxLine == NODATA && minLine == -NODATA && maxEnsembleLine == NODATA && minEnsembleLine == -NODATA) { - axisY->setVisible(false); + axisY_sx->setVisible(false); } else { - axisY->setVisible(true); + axisY_sx->setVisible(true); if (maxEnsembleLine > maxLine) { - axisY->setMax(maxEnsembleLine); + axisY_sx->setMax(maxEnsembleLine); } else { - axisY->setMax(maxLine); + axisY_sx->setMax(maxLine); } if (minEnsembleLine < minLine) { - axisY->setMin(minEnsembleLine); + axisY_sx->setMin(minEnsembleLine); } else { - axisY->setMin(minLine); + axisY_sx->setMin(minLine); } - if (axisY->max() == axisY->min()) + if (axisY_sx->max() == axisY_sx->min()) { - axisY->setRange(axisY->min()-axisY->min()/100, axisY->max()+axisY->max()/100); + axisY_sx->setRange(axisY_sx->min()-axisY_sx->min()/100, axisY_sx->max()+axisY_sx->max()/100); } } } else { - axisY->setVisible(false); + axisY_sx->setVisible(false); } // add zeroLine - if (axisY->min() <= 0 && axisY->max() >= 0) + if (axisY_sx->min() <= 0 && axisY_sx->max() >= 0) { zeroLine->clear(); for (int day = 0; day < nDays; day++) @@ -1344,7 +1409,7 @@ void Crit3DMeteoWidget::drawDailyVar() } chart->addSeries(zeroLine); zeroLine->attachAxis(axisX); - zeroLine->attachAxis(axisY); + zeroLine->attachAxis(axisY_sx); } // add minimimum values required @@ -1405,7 +1470,7 @@ void Crit3DMeteoWidget::drawDailyVar() } } - + drawAxisTitle(); formInfo.close(); } @@ -1556,29 +1621,29 @@ void Crit3DMeteoWidget::drawHourlyVar() { chart->addSeries(barSeries[mp]); barSeries[mp]->attachAxis(axisX); - barSeries[mp]->attachAxis(axisYdx); + barSeries[mp]->attachAxis(axisY_dx); } } if (maxBar == -1) { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } else { - axisYdx->setVisible(true); + axisY_dx->setVisible(true); if (maxBar != 0) { - axisYdx->setRange(0,maxBar); + axisY_dx->setRange(0,maxBar); } else { - axisYdx->setRange(0,1); + axisY_dx->setRange(0,1); } } } else { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } if (isLine) @@ -1589,34 +1654,34 @@ void Crit3DMeteoWidget::drawHourlyVar() { chart->addSeries(lineSeries[mp][i]); lineSeries[mp][i]->attachAxis(axisX); - lineSeries[mp][i]->attachAxis(axisY); + lineSeries[mp][i]->attachAxis(axisY_sx); connect(lineSeries[mp][i], &QLineSeries::hovered, this, &Crit3DMeteoWidget::tooltipLineSeries); connect(lineSeries[mp][i], &QLineSeries::clicked, this, &Crit3DMeteoWidget::editLineSeries); } } if (maxLine == NODATA && minLine == -NODATA) { - axisY->setVisible(false); + axisY_sx->setVisible(false); } else { - axisY->setVisible(true); - axisY->setMax(maxLine); - axisY->setMin(minLine); + axisY_sx->setVisible(true); + axisY_sx->setMax(maxLine); + axisY_sx->setMin(minLine); - if (axisY->max() == axisY->min()) + if (axisY_sx->max() == axisY_sx->min()) { - axisY->setRange(axisY->min()-axisY->min()/100, axisY->max()+axisY->max()/100); + axisY_sx->setRange(axisY_sx->min()-axisY_sx->min()/100, axisY_sx->max()+axisY_sx->max()/100); } } } else { - axisY->setVisible(false); + axisY_sx->setVisible(false); } // add zeroLine - if (axisY->min() <= 0 && axisY->max() >= 0) + if (axisY_sx->min() <= 0 && axisY_sx->max() >= 0) { zeroLine->clear(); for (int d = 0; d < nDays; d++) @@ -1629,7 +1694,7 @@ void Crit3DMeteoWidget::drawHourlyVar() } chart->addSeries(zeroLine); zeroLine->attachAxis(axisX); - zeroLine->attachAxis(axisY); + zeroLine->attachAxis(axisY_sx); } axisX->setCategories(categories); @@ -1654,9 +1719,11 @@ void Crit3DMeteoWidget::drawHourlyVar() } } + drawAxisTitle(); formInfo.close(); } + void Crit3DMeteoWidget::drawMonthlyVar() { if (! isInitialized) return; @@ -1791,33 +1858,33 @@ void Crit3DMeteoWidget::drawMonthlyVar() { chart->addSeries(barSeries[mp]); barSeries[mp]->attachAxis(axisX); - barSeries[mp]->attachAxis(axisYdx); + barSeries[mp]->attachAxis(axisY_dx); } } if (maxEnsembleBar == -1 && maxBar == -1) { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } else { - axisYdx->setVisible(true); + axisY_dx->setVisible(true); if (maxEnsembleBar > maxBar) { - axisYdx->setRange(0,maxEnsembleBar); + axisY_dx->setRange(0,maxEnsembleBar); } else { - axisYdx->setRange(0,maxBar); + axisY_dx->setRange(0,maxBar); } - if (axisYdx->max() == axisYdx->min()) + if (axisY_dx->max() == axisY_dx->min()) { - axisYdx->setRange(0,1); + axisY_dx->setRange(0,1); } } } else { - axisYdx->setVisible(false); + axisY_dx->setVisible(false); } if (isLine) @@ -1830,7 +1897,7 @@ void Crit3DMeteoWidget::drawMonthlyVar() { chart->addSeries(lineSeries[mp][i]); lineSeries[mp][i]->attachAxis(axisX); - lineSeries[mp][i]->attachAxis(axisY); + lineSeries[mp][i]->attachAxis(axisY_sx); connect(lineSeries[mp][i], &QLineSeries::hovered, this, &Crit3DMeteoWidget::tooltipLineSeries); connect(lineSeries[mp][i], &QLineSeries::clicked, this, &Crit3DMeteoWidget::editLineSeries); } @@ -1838,41 +1905,41 @@ void Crit3DMeteoWidget::drawMonthlyVar() } if (maxLine == NODATA && minLine == -NODATA && maxEnsembleLine == NODATA && minEnsembleLine == -NODATA) { - axisY->setVisible(false); + axisY_sx->setVisible(false); } else { - axisY->setVisible(true); + axisY_sx->setVisible(true); if (maxEnsembleLine > maxLine) { - axisY->setMax(maxEnsembleLine); + axisY_sx->setMax(maxEnsembleLine); } else { - axisY->setMax(maxLine); + axisY_sx->setMax(maxLine); } if (minEnsembleLine < minLine) { - axisY->setMin(minEnsembleLine); + axisY_sx->setMin(minEnsembleLine); } else { - axisY->setMin(minLine); + axisY_sx->setMin(minLine); } - if (axisY->max() == axisY->min()) + if (axisY_sx->max() == axisY_sx->min()) { - axisY->setRange(axisY->min()-axisY->min()/100, axisY->max()+axisY->max()/100); + axisY_sx->setRange(axisY_sx->min()-axisY_sx->min()/100, axisY_sx->max()+axisY_sx->max()/100); } } } else { - axisY->setVisible(false); + axisY_sx->setVisible(false); } // add zeroLine - if (axisY->min() <= 0 && axisY->max() >= 0) + if (axisY_sx->min() <= 0 && axisY_sx->max() >= 0) { zeroLine->clear(); for (int month = 0; month < numberOfMonths; month++) @@ -1881,7 +1948,7 @@ void Crit3DMeteoWidget::drawMonthlyVar() } chart->addSeries(zeroLine); zeroLine->attachAxis(axisX); - zeroLine->attachAxis(axisY); + zeroLine->attachAxis(axisY_sx); } // add minimimum values required @@ -1942,6 +2009,7 @@ void Crit3DMeteoWidget::drawMonthlyVar() } } + drawAxisTitle(); formInfo.close(); } @@ -2325,7 +2393,6 @@ void Crit3DMeteoWidget::redraw() } } } - } @@ -2895,38 +2962,14 @@ void Crit3DMeteoWidget::setIsEnsemble(bool value) tableButton->setEnabled(!value); } -bool Crit3DMeteoWidget::getIsEnsemble() -{ - return isEnsemble; -} - -void Crit3DMeteoWidget::setNrMembers(int value) -{ - nrMembers = value; -} - -int Crit3DMeteoWidget::getMeteoWidgetID() const -{ - return meteoWidgetID; -} - -void Crit3DMeteoWidget::setMeteoWidgetID(int value) -{ - meteoWidgetID = value; -} - -void Crit3DMeteoWidget::setCurrentDate(QDate myDate) -{ - currentDate = myDate; -} void Crit3DMeteoWidget::on_actionChangeLeftAxis() { DialogChangeAxis changeAxisDialog(true); if (changeAxisDialog.result() == QDialog::Accepted) { - axisY->setMax(changeAxisDialog.getMaxVal()); - axisY->setMin(changeAxisDialog.getMinVal()); + axisY_sx->setMax(changeAxisDialog.getMaxVal()); + axisY_sx->setMin(changeAxisDialog.getMinVal()); } } @@ -2936,8 +2979,8 @@ void Crit3DMeteoWidget::on_actionChangeRightAxis() DialogChangeAxis changeAxisDialog(false); if (changeAxisDialog.result() == QDialog::Accepted) { - axisYdx->setMax(changeAxisDialog.getMaxVal()); - axisYdx->setMin(changeAxisDialog.getMinVal()); + axisY_dx->setMax(changeAxisDialog.getMaxVal()); + axisY_dx->setMin(changeAxisDialog.getMinVal()); } } @@ -3206,7 +3249,7 @@ void Crit3DMeteoWidget::drawSum() cumulativePoints.clear(); } } - axisY->setRange(axisY->min(),max); + axisY_sx->setRange(axisY_sx->min(),max); } } if (! barSeries.isEmpty()) @@ -3238,24 +3281,24 @@ void Crit3DMeteoWidget::drawSum() cumulativeValues.clear(); } } - axisYdx->setRange(axisYdx->min(),max); + axisY_dx->setRange(axisY_dx->min(),max); } } } } -qreal findMedian(QList sortedList, int begin, int end) +qreal findMedian(std::vector sortedList, int begin, int end) { int count = end - begin; - if (count % 2) { + if (count % 2) + { return sortedList.at(count / 2 + begin); - } else { + } + else + { qreal right = sortedList.at(count / 2 + begin); qreal left = sortedList.at(count / 2 - 1 + begin); return (right + left) / 2.0; } } - - - diff --git a/agrolib/meteoWidget/meteoWidget.h b/agrolib/meteoWidget/meteoWidget.h index 39c878c0..447bc5c8 100644 --- a/agrolib/meteoWidget/meteoWidget.h +++ b/agrolib/meteoWidget/meteoWidget.h @@ -7,8 +7,6 @@ #include "meteoPoint.h" #include "callout.h" - qreal findMedian(QList sortedList, int begin, int end); - class Crit3DMeteoWidget : public QWidget { Q_OBJECT @@ -17,55 +15,24 @@ Crit3DMeteoWidget(bool isGrid_, QString projectPath, Crit3DMeteoSettings* meteoSettings_); ~Crit3DMeteoWidget() override; - int getMeteoWidgetID() const; - void setMeteoWidgetID(int value); + int getMeteoWidgetID() const { return meteoWidgetID; } + void setMeteoWidgetID(int value) { meteoWidgetID = value; } + + void setCurrentDate(QDate myDate) { currentDate = myDate; } - void setCurrentDate(QDate myDate); - void setDateIntervalDaily(QDate firstDate, QDate lastDate); - void setDateIntervalHourly(QDate firstDate, QDate lastDate); - void setDateIntervalMonthly(QDate firstDate, QDate lastDate); + void setIsEnsemble(bool value); + bool getIsEnsemble() { return isEnsemble; } + void setNrMembers(int value) { nrMembers = value; } + + void setDailyRange(QDate firstDate, QDate lastDate); + void setHourlyRange(QDate firstDate, QDate lastDate); + void setMonthlyRange(QDate firstDate, QDate lastDate); void addMeteoPointsEnsemble(Crit3DMeteoPoint mp); - void updateTimeRange(); void drawMeteoPoint(Crit3DMeteoPoint mp, bool isAppend); void drawEnsemble(); - void resetValues(); - void resetEnsembleValues(); - void drawDailyVar(); - void drawEnsembleDailyVar(); - void drawHourlyVar(); - void drawMonthlyVar(); - void showMonthlyGraph(); - void showDailyGraph(); - void showHourlyGraph(); - void updateSeries(); - void redraw(); - void shiftPrevious(); - void shiftFollowing(); - void showTable(); - void showVar(); - void tooltipLineSeries(QPointF point, bool state); - void editLineSeries(); - bool computeTooltipLineSeries(QLineSeries *series, QPointF point, bool state); - void tooltipBar(bool state, int index, QBarSet *barset); - void editBar(); - void handleMarkerClicked(); - void closeEvent(QCloseEvent *event) override; - void setIsEnsemble(bool value); - bool getIsEnsemble(); - void setNrMembers(int value); - void on_actionChangeLeftAxis(); - void on_actionChangeRightAxis(); - void on_actionExportGraph(); - void on_actionRemoveStation(); - void on_actionInfoPoint(); - void on_actionDataAvailability(); - void on_actionDataSum(); - void drawSum(); - void checkExistingData(); - private: int meteoWidgetID; bool isGrid; @@ -101,8 +68,8 @@ QChart *chart; QBarCategoryAxis *axisX; QBarCategoryAxis *axisXvirtual; - QValueAxis *axisY; - QValueAxis *axisYdx; + QValueAxis *axisY_sx; + QValueAxis *axisY_dx; QMap> MapCSVDefault; QMap> MapCSVStyles; QList currentVariables; @@ -128,6 +95,44 @@ bool isLine; bool isBar; Callout *m_tooltip; + + void updateTimeRange(); + void resetValues(); + void resetEnsembleValues(); + void drawDailyVar(); + void drawEnsembleDailyVar(); + void drawHourlyVar(); + void drawMonthlyVar(); + void showMonthlyGraph(); + void showDailyGraph(); + void showHourlyGraph(); + void updateSeries(); + void redraw(); + void shiftPrevious(); + void shiftFollowing(); + void showTable(); + void showVar(); + void tooltipLineSeries(QPointF point, bool state); + void editLineSeries(); + bool computeTooltipLineSeries(QLineSeries *series, QPointF point, bool state); + void tooltipBar(bool state, int index, QBarSet *barset); + void editBar(); + void handleMarkerClicked(); + void closeEvent(QCloseEvent *event) override; + + void on_actionChangeLeftAxis(); + void on_actionChangeRightAxis(); + void on_actionExportGraph(); + void on_actionRemoveStation(); + void on_actionInfoPoint(); + void on_actionDataAvailability(); + void on_actionDataSum(); + + void drawAxisTitle(); + void drawSum(); + void checkExistingData(); + + signals: void closeWidgetPoint(int); void closeWidgetGrid(int); @@ -135,4 +140,7 @@ }; + qreal findMedian(std::vector sortedList, int begin, int end); + + #endif // METEOWIDGET_H diff --git a/agrolib/pointStatisticsWidget/pointStatisticsWidget.cpp b/agrolib/pointStatisticsWidget/pointStatisticsWidget.cpp index a8bf09f9..3a7fdbc5 100644 --- a/agrolib/pointStatisticsWidget/pointStatisticsWidget.cpp +++ b/agrolib/pointStatisticsWidget/pointStatisticsWidget.cpp @@ -697,7 +697,8 @@ void Crit3DPointStatisticsWidget::plot() double availab = double(validData) / double(count) * 100.0; availability.setText(QString::number(availab, 'f', 3)); - double mkendall = statisticalElab(mannKendall, NODATA, outputValues, outputValues.size(), meteoSettings->getRainfallThreshold()); + double mkendall = statisticalElab(mannKendall, NODATA, outputValues, int(outputValues.size()), + meteoSettings->getRainfallThreshold()); significance.setText(QString::number(mkendall, 'f', 3)); double averageValue = sum / double(validData); average.setText(QString::number(averageValue, 'f', 1)); @@ -707,7 +708,7 @@ void Crit3DPointStatisticsWidget::plot() float myR2 = NODATA; bool isZeroIntercept = false; std::vector yearsFloat(years.begin(), years.end()); - statistics::linearRegression(yearsFloat, outputValues, outputValues.size(), isZeroIntercept, + statistics::linearRegression(yearsFloat, outputValues, int(outputValues.size()), isZeroIntercept, &myIntercept, &myCoeff, &myR2); r2.setText(QString::number(double(myR2), 'f', 3)); rate.setText(QString::number(double(myCoeff), 'f', 3)); @@ -868,7 +869,8 @@ void Crit3DPointStatisticsWidget::plot() float availab = ((float)validData/(float)count)*100.0; availability.setText(QString::number(availab, 'f', 3)); - float mkendall = statisticalElab(mannKendall, NODATA, outputValues, outputValues.size(), meteoSettings->getRainfallThreshold()); + float mkendall = statisticalElab(mannKendall, NODATA, outputValues, int(outputValues.size()), + meteoSettings->getRainfallThreshold()); significance.setText(QString::number(mkendall, 'f', 3)); float averageValue = sum/validYears; average.setText(QString::number(averageValue, 'f', 1)); @@ -878,7 +880,7 @@ void Crit3DPointStatisticsWidget::plot() float myR2 = NODATA; bool isZeroIntercept = false; std::vector yearsFloat(years.begin(), years.end()); - statistics::linearRegression(yearsFloat, outputValues, outputValues.size(), isZeroIntercept, + statistics::linearRegression(yearsFloat, outputValues, int(outputValues.size()), isZeroIntercept, &myIntercept, &myCoeff, &myR2); r2.setText(QString::number(myR2, 'f', 3)); rate.setText(QString::number(myCoeff, 'f', 3)); @@ -1171,8 +1173,8 @@ void Crit3DPointStatisticsWidget::plot() } avg = statistics::mean(series, nrValues); dev_std = statistics::standardDeviation(series, nrValues); - millile3dev = sorting::percentile(sortedSeries, nrValues, 99.73, true); - millile_3Dev = sorting::percentile(sortedSeries, nrValues, 0.27, false); + millile3dev = sorting::percentile(sortedSeries, nrValues, 99.73f, true); + millile_3Dev = sorting::percentile(sortedSeries, nrValues, 0.27f, false); } availability.setText(QString::number((float)nrValues/(float)totDays * 100, 'f', 3)); @@ -1449,8 +1451,8 @@ void Crit3DPointStatisticsWidget::plot() } avg = statistics::mean(series, nrValues); dev_std = statistics::standardDeviation(series, nrValues); - millile3dev = sorting::percentile(sortedSeries, nrValues, 99.73, true); - millile_3Dev = sorting::percentile(sortedSeries, nrValues, 0.27, false); + millile3dev = sorting::percentile(sortedSeries, nrValues, 99.73f, true); + millile_3Dev = sorting::percentile(sortedSeries, nrValues, 0.27f, false); } availability.setText(QString::number((float)nrValues/(float)totDays * 100, 'f', 3)); average.setText(QString::number(avg, 'f', 1)); @@ -1626,7 +1628,7 @@ void Crit3DPointStatisticsWidget::showElaboration() float availab = ((float)validYears/(float)years.size())*100.0; availability.setText(QString::number(availab, 'f', 3)); - float mkendall = statisticalElab(mannKendall, NODATA, outputValues, outputValues.size(), meteoSettings->getRainfallThreshold()); + float mkendall = statisticalElab(mannKendall, NODATA, outputValues, int(outputValues.size()), meteoSettings->getRainfallThreshold()); significance.setText(QString::number(mkendall, 'f', 3)); float averageValue = sum/validYears; average.setText(QString::number(averageValue, 'f', 1)); @@ -1636,7 +1638,7 @@ void Crit3DPointStatisticsWidget::showElaboration() float myR2 = NODATA; bool isZeroIntercept = false; std::vector yearsFloat(years.begin(), years.end()); - statistics::linearRegression(yearsFloat, outputValues, outputValues.size(), isZeroIntercept, + statistics::linearRegression(yearsFloat, outputValues, int(outputValues.size()), isZeroIntercept, &myIntercept, &myCoeff, &myR2); r2.setText(QString::number(myR2, 'f', 3)); rate.setText(QString::number(myCoeff, 'f', 3)); diff --git a/agrolib/pragaProject/pragaProject.cpp b/agrolib/pragaProject/pragaProject.cpp index fcba0433..29e44e00 100644 --- a/agrolib/pragaProject/pragaProject.cpp +++ b/agrolib/pragaProject/pragaProject.cpp @@ -1568,7 +1568,10 @@ bool PragaProject::downloadDailyDataArkimet(QList variables, bool prec0 while (date1 <= endDate) { - myDownload->downloadDailyData(date1, date2, datasetList[i], idList[i], arkIdVar, prec0024); + if (! myDownload->downloadDailyData(date1, date2, datasetList[i], idList[i], arkIdVar, prec0024, errorString)) + { + return false; + } if (showInfo) { @@ -1617,7 +1620,7 @@ bool PragaProject::downloadHourlyDataArkimet(QList variables, QDate sta id = QString::fromStdString(meteoPoints[i].id); dataset = QString::fromStdString(meteoPoints[i].dataset); - if (!datasetList.contains(dataset)) + if (! datasetList.contains(dataset)) { datasetList << dataset; QList myList; @@ -1650,8 +1653,11 @@ bool PragaProject::downloadHourlyDataArkimet(QList variables, QDate sta updateProgressBar(startDate.daysTo(date2) + 1); } - if (! myDownload->downloadHourlyData(date1, date2, datasetList[i], idList[i], arkIdVar)) - updateProgressBarText("NO DATA"); + errorString = ""; + if (! myDownload->downloadHourlyData(date1, date2, datasetList[i], idList[i], arkIdVar, errorString)) + { + updateProgressBarText("NO DATA: " + errorString); + } date1 = date2.addDays(1); date2 = std::min(date1.addDays(MAXDAYS_DOWNLOAD_HOURLY), endDate); diff --git a/agrolib/project/meteoMaps.cpp b/agrolib/project/meteoMaps.cpp index f790088a..e20d9863 100644 --- a/agrolib/project/meteoMaps.cpp +++ b/agrolib/project/meteoMaps.cpp @@ -2,6 +2,7 @@ #include "basicMath.h" #include "meteo.h" #include "meteoMaps.h" +#include "gis.h" Crit3DDailyMeteoMaps::Crit3DDailyMeteoMaps(const gis::Crit3DRasterGrid& DEM) diff --git a/agrolib/project/project.cpp b/agrolib/project/project.cpp index c818c219..77444758 100644 --- a/agrolib/project/project.cpp +++ b/agrolib/project/project.cpp @@ -1105,8 +1105,6 @@ bool Project::loadMeteoPointsDB(QString fileName) closeMeteoPointsDB(); - logInfoGUI("Load meteo points DB: " + fileName); - dbPointsFileName = fileName; QString dbName = getCompleteFileName(fileName, PATH_METEOPOINT); if (! QFile(dbName).exists()) @@ -1118,7 +1116,7 @@ bool Project::loadMeteoPointsDB(QString fileName) meteoPointsDbHandler = new Crit3DMeteoPointsDbHandler(dbName); if (! meteoPointsDbHandler->getErrorString().isEmpty()) { - errorString = "Function loadMeteoPointsDB:\n" + dbName + "\n" + meteoPointsDbHandler->getErrorString(); + errorString = meteoPointsDbHandler->getErrorString(); closeMeteoPointsDB(); return false; } @@ -1194,7 +1192,6 @@ bool Project::loadMeteoPointsDB(QString fileName) meteoPointsLoaded = true; logInfo("Meteo points DB = " + dbName); - closeLogInfo(); return true; } @@ -2389,7 +2386,7 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT getProxyValuesXY(x, y, &interpolationSettings, proxyValues); std::vector subsetInterpolationPoints; - localSelection(interpolationPoints, subsetInterpolationPoints, x, y, interpolationSettings); + localSelection(interpolationPoints, subsetInterpolationPoints, x, y,outputPoints[i].z, interpolationSettings); if (! preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) { @@ -2433,7 +2430,7 @@ bool Project::interpolationDemLocalDetrending(meteoVariable myVar, const Crit3DT if (! getProxyValuesXY(x, y, &interpolationSettings, proxyValues)) interpolationSettings.setProxiesComplete(false); std::vector subsetInterpolationPoints; - localSelection(interpolationPoints, subsetInterpolationPoints, x, y, interpolationSettings); + localSelection(interpolationPoints, subsetInterpolationPoints, x, y, z, interpolationSettings); if (interpolationSettings.getUseLocalDetrending()) interpolationSettings.setFittingParameters(myRaster->prepareParameters(row, col, myCombination.getActiveProxySize())); if (! preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, @@ -2736,7 +2733,7 @@ bool Project::interpolationGrid(meteoVariable myVar, const Crit3DTime& myTime) if (interpolationSettings.getUseLocalDetrending()) { std::vector subsetInterpolationPoints; - localSelection(interpolationPoints, subsetInterpolationPoints, myX, myY, interpolationSettings); + localSelection(interpolationPoints, subsetInterpolationPoints, myX, myY, myZ, interpolationSettings); interpolationSettings.setFittingParameters(meteoGridDbHandler->meteoGrid()->dataMeteoGrid.prepareParameters(row, col, myCombination.getActiveProxySize())); if (! preInterpolation(subsetInterpolationPoints, &interpolationSettings, meteoSettings, &climateParameters, meteoPoints, nrMeteoPoints, myVar, myTime, errorStdStr)) @@ -3410,11 +3407,11 @@ void Project::showMeteoWidgetPoint(std::string idMeteoPoint, std::string namePoi if (hasDailyData) { - meteoWidgetPoint->setDateIntervalDaily(firstDaily, lastDaily); + meteoWidgetPoint->setDailyRange(firstDaily, lastDaily); } if (hasHourlyData) { - meteoWidgetPoint->setDateIntervalHourly(firstHourly.date(), lastHourly.date()); + meteoWidgetPoint->setHourlyRange(firstHourly.date(), lastHourly.date()); } meteoWidgetPoint->setCurrentDate(this->currentDate); @@ -3432,7 +3429,6 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) QDate firstMonthlyDate = meteoGridDbHandler->getFirstMonthlytDate(); QDate lastMonthlyDate = meteoGridDbHandler->getLastMonthlyDate(); - QDateTime firstDateTime, lastDateTime; if (meteoGridDbHandler->getFirstHourlyDate().isValid()) { @@ -3444,21 +3440,24 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) } int meteoWidgetId = 0; - if (meteoWidgetGridList.isEmpty() || meteoGridDbHandler->gridStructure().isEnsemble()) + if (meteoWidgetGridList.isEmpty()) { isAppend = false; } if (meteoGridDbHandler->gridStructure().isEnsemble()) { - isAppend = false; - logInfoGUI("Meteo grid is ensemble: append mode is not possible, a new widget is opening."); + if (isAppend) + { + isAppend = false; + logWarning("Meteo grid is ensemble: append mode is not possible.\nA new meteo widget will be open."); + } } + logInfoGUI("Loading data...\n"); + if (isAppend) { - logInfoGUI("Loading data...\n"); - if (! meteoGridDbHandler->gridStructure().isFixedFields()) { if (meteoGridDbHandler->isDaily()) @@ -3467,6 +3466,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) } if (meteoGridDbHandler->isHourly()) { + logInfoGUI("Loading hourly data...\n"); meteoGridDbHandler->loadGridHourlyData(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } if (meteoGridDbHandler->isMonthly()) @@ -3482,6 +3482,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) } if (meteoGridDbHandler->isHourly()) { + logInfoGUI("Loading hourly data...\n"); meteoGridDbHandler->loadGridHourlyDataFixedFields(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } if (meteoGridDbHandler->isMonthly()) @@ -3509,7 +3510,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { bool isGrid = true; Crit3DMeteoWidget* meteoWidgetGrid = new Crit3DMeteoWidget(isGrid, projectPath, meteoSettings); - if (!meteoWidgetGridList.isEmpty()) + if (! meteoWidgetGridList.isEmpty()) { meteoWidgetId = meteoWidgetGridList[meteoWidgetGridList.size()-1]->getMeteoWidgetID()+1; } @@ -3524,8 +3525,6 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) QObject::connect(meteoWidgetGrid, SIGNAL(closeWidgetGrid(int)), this, SLOT(deleteMeteoWidgetGrid(int))); - logInfoGUI("Loading data..."); - if (meteoGridDbHandler->gridStructure().isEnsemble()) { meteoWidgetGrid->setIsEnsemble(true); @@ -3537,11 +3536,11 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { if (meteoGridDbHandler->isDaily()) { - meteoWidgetGrid->setDateIntervalDaily(firstDate, lastDate); + meteoWidgetGrid->setDailyRange(firstDate, lastDate); } if (meteoGridDbHandler->isHourly()) { - meteoWidgetGrid->setDateIntervalHourly(firstDateTime.date(), lastDateTime.date()); + meteoWidgetGrid->setHourlyRange(firstDateTime.date(), lastDateTime.date()); } } else @@ -3560,7 +3559,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) } else { - if (!meteoGridDbHandler->gridStructure().isFixedFields()) + if (! meteoGridDbHandler->gridStructure().isFixedFields()) { if (meteoGridDbHandler->isDaily()) { @@ -3568,6 +3567,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) } if (meteoGridDbHandler->isHourly()) { + logInfoGUI("Loading hourly data...\n"); meteoGridDbHandler->loadGridHourlyData(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } if (meteoGridDbHandler->isMonthly()) @@ -3583,6 +3583,7 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) } if (meteoGridDbHandler->isHourly()) { + logInfoGUI("Loading hourly data...\n"); meteoGridDbHandler->loadGridHourlyDataFixedFields(errorString, QString::fromStdString(idCell), firstDateTime, lastDateTime); } if (meteoGridDbHandler->isMonthly()) @@ -3597,11 +3598,11 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) { if (meteoGridDbHandler->isDaily()) { - meteoWidgetGrid->setDateIntervalDaily(firstDate, lastDate); + meteoWidgetGrid->setDailyRange(firstDate, lastDate); } if (meteoGridDbHandler->isHourly()) { - meteoWidgetGrid->setDateIntervalHourly(firstDateTime.date(), lastDateTime.date()); + meteoWidgetGrid->setHourlyRange(firstDateTime.date(), lastDateTime.date()); } meteoWidgetGrid->drawMeteoPoint(meteoGridDbHandler->meteoGrid()->meteoPoint(row,col), isAppend); @@ -3614,7 +3615,6 @@ void Project::showMeteoWidgetGrid(std::string idCell, bool isAppend) void Project::deleteMeteoWidgetPoint(int id) { - for (int i = 0; igetMeteoWidgetID() == id) @@ -4438,6 +4438,7 @@ void Project::logInfoGUI(QString myStr) formLog = new FormInfo(); } formLog->showInfo(myStr); + qApp->processEvents(); } else { @@ -4462,6 +4463,31 @@ void Project::logError(QString myStr) } +void Project::logWarning(QString myStr) +{ + errorString = myStr; + logWarning(); +} + + +void Project::logWarning() +{ + if (logFile.is_open()) + { + logFile << "WARNING! " << errorString.toStdString() << std::endl; + } + + if (modality == MODE_GUI) + { + QMessageBox::warning(nullptr, "WARNING!", errorString); + } + else + { + std::cout << "WARNING! " << errorString.toStdString() << std::endl; + } +} + + void Project::logError() { if (logFile.is_open()) diff --git a/agrolib/project/project.h b/agrolib/project/project.h index a2757c0c..c8ef74d5 100644 --- a/agrolib/project/project.h +++ b/agrolib/project/project.h @@ -203,12 +203,17 @@ QString getCompleteFileName(QString fileName, QString secondaryPath); bool setLogFile(QString myFileName); - void logError(QString myStr); + void logInfo(QString myStr); void logInfoGUI(QString myStr); void closeLogInfo(); + + void logError(QString myStr); void logError(); + void logWarning(QString myStr); + void logWarning(); + int setProgressBar(QString myStr, int nrValues); void updateProgressBar(int value); void updateProgressBarText(QString myStr); diff --git a/agrolib/project/shell.cpp b/agrolib/project/shell.cpp index b80e0521..9230ddcc 100644 --- a/agrolib/project/shell.cpp +++ b/agrolib/project/shell.cpp @@ -3,6 +3,7 @@ #include "project.h" #include "shell.h" #include "dbMeteoGrid.h" +#include "utilities.h" #include #include @@ -382,6 +383,14 @@ int cmdExportDailyDataCsv(Project* myProject, QList argumentList) QString completeOutputPath = myProject->getProjectPath() + outputPath; outputPath = QDir().cleanPath(completeOutputPath); } + else + { + if(getFileName(outputPath) == outputPath) + { + QString completeOutputPath = myProject->getProjectPath() + PATH_OUTPUT + outputPath; + outputPath = QDir().cleanPath(completeOutputPath); + } + } } } } diff --git a/agrolib/proxyWidget/localProxyWidget.cpp b/agrolib/proxyWidget/localProxyWidget.cpp index 2c2701b9..50a67dd4 100644 --- a/agrolib/proxyWidget/localProxyWidget.cpp +++ b/agrolib/proxyWidget/localProxyWidget.cpp @@ -379,7 +379,7 @@ void Crit3DLocalProxyWidget::plot() interpolationSettings, meteoSettings, climateParam, outInterpolationPoints, checkSpatialQuality, errorStdStr); - localSelection(outInterpolationPoints, subsetInterpolationPoints, x, y, *interpolationSettings); + localSelection(outInterpolationPoints, subsetInterpolationPoints, x, y, z, *interpolationSettings); detrending(subsetInterpolationPoints, interpolationSettings->getSelectedCombination(), interpolationSettings, climateParam, myVar, getCurrentTime()); } else @@ -387,7 +387,7 @@ void Crit3DLocalProxyWidget::plot() checkAndPassDataToInterpolation(quality, myVar, meteoPoints, nrMeteoPoints, getCurrentTime(), SQinterpolationSettings, interpolationSettings, meteoSettings, climateParam, outInterpolationPoints, checkSpatialQuality, errorStdStr); - localSelection(outInterpolationPoints, subsetInterpolationPoints, x, y, *interpolationSettings); + localSelection(outInterpolationPoints, subsetInterpolationPoints, x, y, z, *interpolationSettings); } QList pointListPrimary, pointListSecondary, pointListSupplemental, pointListMarked; QMap< QString, QPointF > idPointMap1; diff --git a/agrolib/proxyWidget/localProxyWidget.h b/agrolib/proxyWidget/localProxyWidget.h index a367eae6..cb62df4f 100644 --- a/agrolib/proxyWidget/localProxyWidget.h +++ b/agrolib/proxyWidget/localProxyWidget.h @@ -27,6 +27,7 @@ class Crit3DLocalProxyWidget : public QWidget private: double x; double y; + double z; std::vector> parameters; gis::Crit3DGisSettings gisSettings; Crit3DInterpolationSettings* interpolationSettings; diff --git a/agrolib/soil/soil.cpp b/agrolib/soil/soil.cpp index f24f982d..397ec2a9 100644 --- a/agrolib/soil/soil.cpp +++ b/agrolib/soil/soil.cpp @@ -813,7 +813,7 @@ namespace soil horizon.texture.silt = horizon.dbData.silt; horizon.texture.clay = horizon.dbData.clay; if (! isEqual(horizon.texture.sand, NODATA) && ! isEqual(horizon.texture.silt, NODATA) && ! isEqual(horizon.texture.clay, NODATA) - && (horizon.texture.sand + horizon.texture.silt + horizon.texture.clay) <= 1 ) + && (horizon.texture.sand + horizon.texture.silt + horizon.texture.clay) <= 1.01 ) { horizon.texture.sand *= 100; horizon.texture.silt *= 100; diff --git a/agrolib/soil/soilDbTools.cpp b/agrolib/soil/soilDbTools.cpp index 6c731ba7..1cbb95a7 100644 --- a/agrolib/soil/soilDbTools.cpp +++ b/agrolib/soil/soilDbTools.cpp @@ -1,6 +1,7 @@ #include "soil.h" #include "soilDbTools.h" #include "commonConstants.h" +#include "basicMath.h" #include "utilities.h" #include @@ -275,6 +276,13 @@ bool loadSoilData(const QSqlDatabase &dbSoil, const QString &soilCode, soil::Cri getValue(query.value("sand"), &sand); getValue(query.value("silt"), &silt); getValue(query.value("clay"), &clay); + // check + if (! isEqual(sand, NODATA) && ! isEqual(silt, NODATA) && ! isEqual(clay, NODATA) && (sand + silt + clay) <= 1.01) + { + sand *= 100; + silt *= 100; + clay *= 100; + } mySoil.horizon[i].dbData.sand = sand; mySoil.horizon[i].dbData.silt = silt; mySoil.horizon[i].dbData.clay = clay; diff --git a/agrolib/soilFluxes3D/header/soilFluxes3D.h b/agrolib/soilFluxes3D/header/soilFluxes3D.h index 5f509a39..7341310c 100644 --- a/agrolib/soilFluxes3D/header/soilFluxes3D.h +++ b/agrolib/soilFluxes3D/header/soilFluxes3D.h @@ -51,7 +51,7 @@ // WATER __EXTERN int DLL_EXPORT __STDCALL setHydraulicProperties(int waterRetentionCurve, int conductivityMeanType, float horizVertRatioConductivity); __EXTERN int DLL_EXPORT __STDCALL setWaterContent(long index, double myWaterContent); - __EXTERN int DLL_EXPORT __STDCALL setMatricPotential(long index, double potential); + __EXTERN int DLL_EXPORT __STDCALL setMatricPotential(long index, double psi); __EXTERN int DLL_EXPORT __STDCALL setTotalPotential(long index, double totalPotential); __EXTERN int DLL_EXPORT __STDCALL setPrescribedTotalPotential(long index, double prescribedTotalPotential); __EXTERN int DLL_EXPORT __STDCALL setWaterSinkSource(long index, double sinkSource); diff --git a/agrolib/soilFluxes3D/soilFluxes3D.cpp b/agrolib/soilFluxes3D/soilFluxes3D.cpp index 402fa5f0..ba552106 100644 --- a/agrolib/soilFluxes3D/soilFluxes3D.cpp +++ b/agrolib/soilFluxes3D/soilFluxes3D.cpp @@ -434,17 +434,17 @@ int DLL_EXPORT __STDCALL setHydraulicProperties(int waterRetentionCurve, /*! * \brief setMatricPotential * \param nodeIndex - * \param potential [m] + * \param psi [m] * \return OK/ERROR */ - int DLL_EXPORT __STDCALL setMatricPotential(long nodeIndex, double potential) + int DLL_EXPORT __STDCALL setMatricPotential(long nodeIndex, double psi) { if (nodeListPtr == nullptr) return MEMORY_ERROR; if ((nodeIndex < 0) || (nodeIndex >= myStructure.nrNodes)) return INDEX_ERROR; - nodeListPtr[nodeIndex].H = potential + nodeListPtr[nodeIndex].z; + nodeListPtr[nodeIndex].H = psi + nodeListPtr[nodeIndex].z; nodeListPtr[nodeIndex].oldH = nodeListPtr[nodeIndex].H; if (nodeListPtr[nodeIndex].isSurface)