From b65f2570c66f69d55c23e837576d5c94c0dccc55 Mon Sep 17 00:00:00 2001 From: Ake Hedman Date: Sun, 22 Sep 2024 22:34:24 +0200 Subject: [PATCH] Removed dependency on QSql --- CMakeLists.txt | 6 +- src/cdlgknownguid.cpp | 171 ++++++++++++----------- src/cdlgsensorindex.cpp | 302 ++++++++++++++++++++-------------------- src/cfrmmdf.cpp | 4 +- src/cfrmnodeconfig.cpp | 4 +- src/cfrmnodeconfig.h | 3 +- src/cfrmnodescan.cpp | 4 +- src/cfrmsession.cpp | 4 +- src/cfrmsession.h | 5 +- src/main.cpp | 1 + src/vscpworks.cpp | 271 +++++++++++++++++------------------ src/vscpworks.h | 9 +- 12 files changed, 397 insertions(+), 387 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 31563492..d5331bb2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,8 +87,8 @@ set(CMAKE_AUTORCC ON) # set the module path set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules) -# qt -find_package(Qt6 REQUIRED COMPONENTS Widgets Qml Core Network Sql Charts Quick SerialBus SerialPort) +# qt sql Network +find_package(Qt6 REQUIRED COMPONENTS Widgets Qml Core Charts Quick SerialBus SerialPort) qt_standard_project_setup() @@ -678,7 +678,7 @@ else() target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Widgets Qt6::Qml - Qt6::Sql +# Qt6::Sql Qt6::Charts m dl diff --git a/src/cdlgknownguid.cpp b/src/cdlgknownguid.cpp index c95c2d06..3e4d280c 100644 --- a/src/cdlgknownguid.cpp +++ b/src/cdlgknownguid.cpp @@ -128,7 +128,7 @@ CDlgKnownGuid::fillGuidFromDb(void) { vscpworks* pworks = (vscpworks*)QCoreApplication::instance(); - pworks->m_mutexGuidMap.lock(); + /*pworks->m_mutexGuidMap.lock(); QSqlQuery query("SELECT * FROM guid order by name", pworks->m_worksdb); @@ -139,7 +139,7 @@ CDlgKnownGuid::fillGuidFromDb(void) insertGuidItem(guid, name); } - pworks->m_mutexGuidMap.unlock(); + pworks->m_mutexGuidMap.unlock();*/ } /////////////////////////////////////////////////////////////////////////////// @@ -201,7 +201,7 @@ void CDlgKnownGuid::listItemClicked(QTableWidgetItem* item) { vscpworks* pworks = (vscpworks*)QCoreApplication::instance(); - +/* int currentRow = ui->listGuid->selectionModel()->currentIndex().row(); if (-1 == currentRow) { currentRow = 0; // First row @@ -235,6 +235,7 @@ CDlgKnownGuid::listItemClicked(QTableWidgetItem* item) } pworks->m_mutexGuidMap.unlock(); +*/ } /////////////////////////////////////////////////////////////////////////////// @@ -459,7 +460,7 @@ CDlgKnownGuid::btnAdd(void) } QString strQuery = tr("INSERT INTO guid (guid, name, description) VALUES ('%1', '%2', '%3');"); - +/* pworks->m_mutexGuidMap.lock(); QSqlQuery query(strQuery .arg(strguid) @@ -475,7 +476,7 @@ CDlgKnownGuid::btnAdd(void) query.lastError().text().toStdString()); goto again; } - +*/ // Add to the internal table pworks->m_mapGuidToSymbolicName[strguid] = dlg.getName(); pworks->m_mutexGuidMap.unlock(); @@ -531,7 +532,7 @@ CDlgKnownGuid::btnEdit(void) QString strQuery = tr("SELECT * FROM guid WHERE guid='%1';"); pworks->m_mutexGuidMap.lock(); - QSqlQuery query(strQuery.arg(strguid), pworks->m_worksdb); + /*QSqlQuery query(strQuery.arg(strguid), pworks->m_worksdb); if (QSqlError::NoError != query.lastError().type()) { pworks->m_mutexGuidMap.unlock(); @@ -551,7 +552,7 @@ CDlgKnownGuid::btnEdit(void) } pworks->m_mutexGuidMap.unlock(); - +*/ again: if (QDialog::Accepted == dlg.exec()) { @@ -560,22 +561,22 @@ CDlgKnownGuid::btnEdit(void) QString strQuery = tr("UPDATE guid SET name='%1', description='%2' WHERE guid='%3';"); pworks->m_mutexGuidMap.lock(); - QSqlQuery query(strQuery - .arg(strname) - .arg(strdescription) - .arg(strguid), - pworks->m_worksdb); - if (QSqlError::NoError != query.lastError().type()) { - pworks->m_mutexGuidMap.unlock(); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to save edited GUID into database.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok); - - spdlog::error(std::string(tr("Unable to save edited GUID into database. Err =").toStdString()) + - query.lastError().text().toStdString()); - goto again; - } + // QSqlQuery query(strQuery + // .arg(strname) + // .arg(strdescription) + // .arg(strguid), + // pworks->m_worksdb); + // if (QSqlError::NoError != query.lastError().type()) { + // pworks->m_mutexGuidMap.unlock(); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to save edited GUID into database.\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok); + + // spdlog::error(std::string(tr("Unable to save edited GUID into database. Err =").toStdString()) + + // query.lastError().text().toStdString()); + // goto again; + // } // Add to the internal table pworks->m_mapGuidToSymbolicName[strguid] = dlg.getName(); @@ -616,26 +617,26 @@ CDlgKnownGuid::btnClone(void) QString strguid = itemGuid->text(); strguid = strguid.trimmed(); - QString strQuery = tr("SELECT * FROM guid WHERE guid='%1';"); - pworks->m_mutexGuidMap.lock(); - QSqlQuery query(strQuery.arg(strguid), pworks->m_worksdb); - - if (QSqlError::NoError != query.lastError().type()) { - pworks->m_mutexGuidMap.unlock(); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok); - spdlog::error(std::string(tr("Unable to find record in database. Err =").toStdString()) + - query.lastError().text().toStdString()); - return; - } - - if (query.next()) { - dlg.setGuid(query.value(1).toString()); - dlg.setName(query.value(2).toString()); - dlg.setDescription(query.value(3).toString()); - } + // QString strQuery = tr("SELECT * FROM guid WHERE guid='%1';"); + // pworks->m_mutexGuidMap.lock(); + // QSqlQuery query(strQuery.arg(strguid), pworks->m_worksdb); + + // if (QSqlError::NoError != query.lastError().type()) { + // pworks->m_mutexGuidMap.unlock(); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok); + // spdlog::error(std::string(tr("Unable to find record in database. Err =").toStdString()) + + // query.lastError().text().toStdString()); + // return; + // } + + // if (query.next()) { + // dlg.setGuid(query.value(1).toString()); + // dlg.setName(query.value(2).toString()); + // dlg.setDescription(query.value(3).toString()); + // } pworks->m_mutexGuidMap.unlock(); @@ -672,22 +673,22 @@ CDlgKnownGuid::btnClone(void) QString strQuery = tr("INSERT INTO guid (guid, name, description) VALUES ('%1', '%2', '%3');"); - pworks->m_mutexGuidMap.lock(); - QSqlQuery query(strQuery - .arg(strguid) - .arg(dlg.getName()) - .arg(dlg.getDescription()), - pworks->m_worksdb); - if (QSqlError::NoError != query.lastError().type()) { - pworks->m_mutexGuidMap.unlock(); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to save GUID into database (duplicate?).\n\n Error =") + query.lastError().text(), - QMessageBox::Ok); - spdlog::error(std::string(tr("Unable to save GUID into database (duplicate?). Err =").toStdString()) + - query.lastError().text().toStdString()); - goto again; - } + // pworks->m_mutexGuidMap.lock(); + // QSqlQuery query(strQuery + // .arg(strguid) + // .arg(dlg.getName()) + // .arg(dlg.getDescription()), + // pworks->m_worksdb); + // if (QSqlError::NoError != query.lastError().type()) { + // pworks->m_mutexGuidMap.unlock(); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to save GUID into database (duplicate?).\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok); + // spdlog::error(std::string(tr("Unable to save GUID into database (duplicate?). Err =").toStdString()) + + // query.lastError().text().toStdString()); + // goto again; + // } // Add to the internal table pworks->m_mapGuidToSymbolicName[strguid] = dlg.getName(); @@ -726,32 +727,32 @@ CDlgKnownGuid::btnDelete(void) QString strguid = item->text(); strguid = strguid.trimmed(); - QString strQuery = tr("DELETE FROM guid WHERE guid='%1';"); - pworks->m_mutexGuidMap.lock(); - QSqlQuery query(strQuery.arg(strguid), pworks->m_worksdb); - - if (QSqlError::NoError != query.lastError().type()) { - pworks->m_mutexGuidMap.unlock(); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to delete GUID.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok); - spdlog::error(std::string(tr("Unable to delete GUID. Err =").toStdString()) + - query.lastError().text().toStdString()); - return; - } - else { - - // Delete row - ui->listGuid->removeRow(row); - - // Delete from internal table - pworks->m_mapGuidToSymbolicName.erase(strguid); - // std::map::iterator it = pworks->m_mapGuidToSymbolicName.find(strguid); - // if (std::map::end != it) { - - // } - } + // QString strQuery = tr("DELETE FROM guid WHERE guid='%1';"); + // pworks->m_mutexGuidMap.lock(); + // QSqlQuery query(strQuery.arg(strguid), pworks->m_worksdb); + + // if (QSqlError::NoError != query.lastError().type()) { + // pworks->m_mutexGuidMap.unlock(); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to delete GUID.\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok); + // spdlog::error(std::string(tr("Unable to delete GUID. Err =").toStdString()) + + // query.lastError().text().toStdString()); + // return; + // } + // else { + + // // Delete row + // ui->listGuid->removeRow(row); + + // // Delete from internal table + // pworks->m_mapGuidToSymbolicName.erase(strguid); + // // std::map::iterator it = pworks->m_mapGuidToSymbolicName.find(strguid); + // // if (std::map::end != it) { + + // // } + // } pworks->m_mutexGuidMap.unlock(); } diff --git a/src/cdlgsensorindex.cpp b/src/cdlgsensorindex.cpp index f82ce04a..b87c9c5e 100644 --- a/src/cdlgsensorindex.cpp +++ b/src/cdlgsensorindex.cpp @@ -104,17 +104,17 @@ CDlgSensorIndex::CDlgSensorIndex(QWidget *parent, int link_to_guid) : pworks->m_mutexSensorIndexMap.lock(); - QString strQuery = "SELECT * FROM sensorindex WHERE link_to_guid = %1 ORDER BY sensor;"; - QSqlQuery query(strQuery.arg(m_link_to_guid), pworks->m_worksdb); + // QString strQuery = "SELECT * FROM sensorindex WHERE link_to_guid = %1 ORDER BY sensor;"; + // QSqlQuery query(strQuery.arg(m_link_to_guid), pworks->m_worksdb); - while (query.next()) { - QString sensor = query.value(2).toString(); - QString name = query.value(3).toString(); + // while (query.next()) { + // QString sensor = query.value(2).toString(); + // QString name = query.value(3).toString(); - insertSensorIndexItem(sensor, name); - } + // insertSensorIndexItem(sensor, name); + // } - pworks->m_mutexSensorIndexMap.unlock(); + // pworks->m_mutexSensorIndexMap.unlock(); } /////////////////////////////////////////////////////////////////////////////// @@ -177,31 +177,31 @@ void CDlgSensorIndex::listItemClicked(QTableWidgetItem *item) QString strsensor = itemSensor->text(); // Search db record for description - QString strQuery = tr("SELECT * FROM sensorindex WHERE sensor=%1 AND link_to_guid=%2;"); - pworks->m_mutexSensorIndexMap.lock(); - QSqlQuery query(strQuery.arg(strsensor.toInt()).arg(m_link_to_guid), pworks->m_worksdb); - - // Check for database operation error - if (QSqlError::NoError != query.lastError().type()) { - spdlog::error(std::string(tr("Unable to find record in database. Err =").toStdString() - + query.lastError().text().toStdString())); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok ); - pworks->m_mutexSensorIndexMap.unlock(); - return; - } - - if (query.next()) { -#if QT_VERSION >= 0x050E00 - ui->textDescription->setMarkdown(query.value(4).toString()); -#else - ui->textDescription->setText(query.value(3).toString()); -#endif - } - - pworks->m_mutexSensorIndexMap.unlock(); +// QString strQuery = tr("SELECT * FROM sensorindex WHERE sensor=%1 AND link_to_guid=%2;"); +// pworks->m_mutexSensorIndexMap.lock(); +// QSqlQuery query(strQuery.arg(strsensor.toInt()).arg(m_link_to_guid), pworks->m_worksdb); + +// // Check for database operation error +// if (QSqlError::NoError != query.lastError().type()) { +// spdlog::error(std::string(tr("Unable to find record in database. Err =").toStdString() +// + query.lastError().text().toStdString())); +// QMessageBox::information(this, +// tr(APPNAME), +// tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), +// QMessageBox::Ok ); +// pworks->m_mutexSensorIndexMap.unlock(); +// return; +// } + +// if (query.next()) { +// #if QT_VERSION >= 0x050E00 +// ui->textDescription->setMarkdown(query.value(4).toString()); +// #else +// ui->textDescription->setText(query.value(3).toString()); +// #endif +// } + +// pworks->m_mutexSensorIndexMap.unlock(); } /////////////////////////////////////////////////////////////////////////////// @@ -425,30 +425,30 @@ void CDlgSensorIndex::btnAdd(void) QString strQuery = tr("INSERT INTO sensorindex (link_to_guid, sensor, name, description) VALUES (%1, %2, '%3', '%4');"); - pworks->m_mutexSensorIndexMap.lock(); - QSqlQuery query(strQuery - .arg(m_link_to_guid) - .arg(dlg.getSensor()) - .arg(dlg.getName()) - .arg(dlg.getDescription()), - pworks->m_worksdb); + // pworks->m_mutexSensorIndexMap.lock(); + // QSqlQuery query(strQuery + // .arg(m_link_to_guid) + // .arg(dlg.getSensor()) + // .arg(dlg.getName()) + // .arg(dlg.getDescription()), + // pworks->m_worksdb); - // Check for database operation error - if (QSqlError::NoError != query.lastError().type()) { - spdlog::error(std::string(tr("Unable to save GUID into database (duplicate?). Err =").toStdString() - + query.lastError().text().toStdString())); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to save sensor into database (duplicate?).\n\n Error =") + query.lastError().text(), - QMessageBox::Ok ); - pworks->m_mutexSensorIndexMap.unlock(); - goto again; - } - - // Add to the internal table - pworks->m_mapSensorIndexToSymbolicName[(m_link_to_guid << 8) + dlg.getSensor()] = dlg.getName(); - - pworks->m_mutexSensorIndexMap.unlock(); + // // Check for database operation error + // if (QSqlError::NoError != query.lastError().type()) { + // spdlog::error(std::string(tr("Unable to save GUID into database (duplicate?). Err =").toStdString() + // + query.lastError().text().toStdString())); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to save sensor into database (duplicate?).\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok ); + // pworks->m_mutexSensorIndexMap.unlock(); + // goto again; + // } + + // // Add to the internal table + // pworks->m_mapSensorIndexToSymbolicName[(m_link_to_guid << 8) + dlg.getSensor()] = dlg.getName(); + + // pworks->m_mutexSensorIndexMap.unlock(); // Add to dialog List insertSensorIndexItem(QString::number(dlg.getSensor()), dlg.getName()); @@ -499,25 +499,25 @@ void CDlgSensorIndex::btnEdit(void) QString strQuery = tr("SELECT * FROM sensorindex WHERE sensor=%1 AND link_to_guid=%2;"); pworks->m_mutexSensorIndexMap.lock(); - QSqlQuery query(strQuery.arg(strsensor).arg(m_link_to_guid), pworks->m_worksdb); - - // Check for database operation error - if (QSqlError::NoError != query.lastError().type()) { - spdlog::error(std::string(tr("Unable to find record in database. Err =").toStdString() - + query.lastError().text().toStdString())); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok ); - pworks->m_mutexSensorIndexMap.unlock(); - return; - } + // QSqlQuery query(strQuery.arg(strsensor).arg(m_link_to_guid), pworks->m_worksdb); + + // // Check for database operation error + // if (QSqlError::NoError != query.lastError().type()) { + // spdlog::error(std::string(tr("Unable to find record in database. Err =").toStdString() + // + query.lastError().text().toStdString())); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok ); + // pworks->m_mutexSensorIndexMap.unlock(); + // return; + // } - if (query.next()) { - dlg.setSensor(query.value(2).toInt()); - dlg.setName(query.value(3).toString()); - dlg.setDescription(query.value(4).toString()); - } + // if (query.next()) { + // dlg.setSensor(query.value(2).toInt()); + // dlg.setName(query.value(3).toString()); + // dlg.setDescription(query.value(4).toString()); + // } pworks->m_mutexSensorIndexMap.unlock(); @@ -529,24 +529,24 @@ void CDlgSensorIndex::btnEdit(void) QString strQuery = tr("UPDATE sensorindex SET name='%1', description='%2' WHERE sensor='%3' AND link_to_guid=%4;"); pworks->m_mutexSensorIndexMap.lock(); - QSqlQuery query(strQuery - .arg(strname) - .arg(strdescription) - .arg(strsensor) - .arg(m_link_to_guid), - pworks->m_worksdb); - - // Check for database operation error - if (QSqlError::NoError != query.lastError().type()) { - spdlog::error(std::string(tr("Unable to save edited GUID into database. Err =").toStdString() - + query.lastError().text().toStdString())); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to save edited GUID into database.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok ); - pworks->m_mutexSensorIndexMap.unlock(); - goto again; - } + // QSqlQuery query(strQuery + // .arg(strname) + // .arg(strdescription) + // .arg(strsensor) + // .arg(m_link_to_guid), + // pworks->m_worksdb); + + // // Check for database operation error + // if (QSqlError::NoError != query.lastError().type()) { + // spdlog::error(std::string(tr("Unable to save edited GUID into database. Err =").toStdString() + // + query.lastError().text().toStdString())); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to save edited GUID into database.\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok ); + // pworks->m_mutexSensorIndexMap.unlock(); + // goto again; + // } // Add to the in memory table pworks->m_mapSensorIndexToSymbolicName[(m_link_to_guid << 8) + dlg.getSensor()] = dlg.getName(); @@ -589,25 +589,25 @@ void CDlgSensorIndex::btnClone(void) QString strQuery = tr("SELECT * FROM sensorindex WHERE sensor=%1 AND link_to_guid=%2;"); pworks->m_mutexSensorIndexMap.lock(); - QSqlQuery query(strQuery.arg(strsensor).arg(m_link_to_guid), pworks->m_worksdb); - - // Check for database operation error - if (QSqlError::NoError != query.lastError().type()) { - spdlog::error(std::string(tr("Unable to find record in database Err =").toStdString() - + query.lastError().text().toStdString())); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok ); - pworks->m_mutexSensorIndexMap.unlock(); - return; - } + // QSqlQuery query(strQuery.arg(strsensor).arg(m_link_to_guid), pworks->m_worksdb); + + // // Check for database operation error + // if (QSqlError::NoError != query.lastError().type()) { + // spdlog::error(std::string(tr("Unable to find record in database Err =").toStdString() + // + query.lastError().text().toStdString())); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to find record in database.\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok ); + // pworks->m_mutexSensorIndexMap.unlock(); + // return; + // } - if (query.next()) { - //dlg.setSensor(query.value(2).toInt()); - dlg.setName(query.value(3).toString()); - dlg.setDescription(query.value(4).toString()); - } + // if (query.next()) { + // //dlg.setSensor(query.value(2).toInt()); + // dlg.setName(query.value(3).toString()); + // dlg.setDescription(query.value(4).toString()); + // } pworks->m_mutexSensorIndexMap.unlock(); @@ -616,30 +616,30 @@ void CDlgSensorIndex::btnClone(void) QString strQuery = tr("INSERT INTO sensorindex (link_to_guid, sensor, name, description) VALUES (%1, %2, '%3', '%4');"); - pworks->m_mutexSensorIndexMap.lock(); - QSqlQuery query(strQuery - .arg(m_link_to_guid) - .arg(dlg.getSensor()) - .arg(dlg.getName()) - .arg(dlg.getDescription()), - pworks->m_worksdb); + // pworks->m_mutexSensorIndexMap.lock(); + // QSqlQuery query(strQuery + // .arg(m_link_to_guid) + // .arg(dlg.getSensor()) + // .arg(dlg.getName()) + // .arg(dlg.getDescription()), + // pworks->m_worksdb); - // Check for database operation error - if (QSqlError::NoError != query.lastError().type()) { - spdlog::error(std::string(tr("Unable to save GUID into database (duplicate?). Err =").toStdString() - + query.lastError().text().toStdString())); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to save sensor into database (duplicate?).\n\n Error =") + query.lastError().text(), - QMessageBox::Ok ); - pworks->m_mutexSensorIndexMap.unlock(); - goto again; - } - - // Add to the in memory table - pworks->m_mapSensorIndexToSymbolicName[(m_link_to_guid << 8) + dlg.getSensor()] = dlg.getName(); - - pworks->m_mutexSensorIndexMap.unlock(); + // // Check for database operation error + // if (QSqlError::NoError != query.lastError().type()) { + // spdlog::error(std::string(tr("Unable to save GUID into database (duplicate?). Err =").toStdString() + // + query.lastError().text().toStdString())); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to save sensor into database (duplicate?).\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok ); + // pworks->m_mutexSensorIndexMap.unlock(); + // goto again; + // } + + // // Add to the in memory table + // pworks->m_mapSensorIndexToSymbolicName[(m_link_to_guid << 8) + dlg.getSensor()] = dlg.getName(); + + // pworks->m_mutexSensorIndexMap.unlock(); // Add to dialog List insertSensorIndexItem(QString::number(dlg.getSensor()), dlg.getName()); @@ -686,27 +686,27 @@ void CDlgSensorIndex::btnDelete(void) QString strQuery = tr("DELETE FROM sensorindex WHERE sensor='%1' AND link_to_guid=%2;"); pworks->m_mutexSensorIndexMap.lock(); - QSqlQuery query(strQuery.arg(strsensor).arg(m_link_to_guid), pworks->m_worksdb); - - // Check for database operation error - if (QSqlError::NoError != query.lastError().type()) { - spdlog::error(std::string(tr("Unable to delete sensor. Err =").toStdString() - + query.lastError().text().toStdString())); - QMessageBox::information(this, - tr(APPNAME), - tr("Unable to delete sensor.\n\n Error =") + query.lastError().text(), - QMessageBox::Ok ); - } - else { + // QSqlQuery query(strQuery.arg(strsensor).arg(m_link_to_guid), pworks->m_worksdb); + + // // Check for database operation error + // if (QSqlError::NoError != query.lastError().type()) { + // spdlog::error(std::string(tr("Unable to delete sensor. Err =").toStdString() + // + query.lastError().text().toStdString())); + // QMessageBox::information(this, + // tr(APPNAME), + // tr("Unable to delete sensor.\n\n Error =") + query.lastError().text(), + // QMessageBox::Ok ); + // } + // else { - // Delete row - ui->listSensors->removeRow(row); + // // Delete row + // ui->listSensors->removeRow(row); - // Delete from in memory table - pworks->m_mapSensorIndexToSymbolicName.erase((m_link_to_guid << 8) + strsensor.toInt()); - } + // // Delete from in memory table + // pworks->m_mapSensorIndexToSymbolicName.erase((m_link_to_guid << 8) + strsensor.toInt()); + // } - pworks->m_mutexSensorIndexMap.unlock(); + // pworks->m_mutexSensorIndexMap.unlock(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/cfrmmdf.cpp b/src/cfrmmdf.cpp index 0d09d08a..64f0bd14 100644 --- a/src/cfrmmdf.cpp +++ b/src/cfrmmdf.cpp @@ -78,12 +78,12 @@ #include #include #include -#include +//#include #include #include #include #include -#include +//#include #include // ---------------------------------------------------------------------------- diff --git a/src/cfrmnodeconfig.cpp b/src/cfrmnodeconfig.cpp index 0d3535c8..f231b0bf 100644 --- a/src/cfrmnodeconfig.cpp +++ b/src/cfrmnodeconfig.cpp @@ -79,13 +79,13 @@ #include #include #include -#include +//#include #include #include #include #include #include -#include +//#include #include #include diff --git a/src/cfrmnodeconfig.h b/src/cfrmnodeconfig.h index 3b398076..153d3b0f 100644 --- a/src/cfrmnodeconfig.h +++ b/src/cfrmnodeconfig.h @@ -44,7 +44,8 @@ #include #include #include -#include +#include +//#include QT_BEGIN_NAMESPACE class QAction; diff --git a/src/cfrmnodescan.cpp b/src/cfrmnodescan.cpp index aaa6fe85..6b14bc19 100644 --- a/src/cfrmnodescan.cpp +++ b/src/cfrmnodescan.cpp @@ -67,12 +67,12 @@ #include #include #include -#include +//#include #include #include #include #include -#include +//#include #include // ---------------------------------------------------------------------------- diff --git a/src/cfrmsession.cpp b/src/cfrmsession.cpp index 05440b4b..a177a2bc 100644 --- a/src/cfrmsession.cpp +++ b/src/cfrmsession.cpp @@ -65,13 +65,13 @@ #include #include #include -#include +//#include #include #include #include #include #include -#include +//#include #include // ---------------------------------------------------------------------------- diff --git a/src/cfrmsession.h b/src/cfrmsession.h index b3a88007..498dd82e 100644 --- a/src/cfrmsession.h +++ b/src/cfrmsession.h @@ -43,7 +43,10 @@ #include #include #include -#include +#include +#include +#include +//#include #include QT_BEGIN_NAMESPACE diff --git a/src/main.cpp b/src/main.cpp index 7f78d439..cb93a3be 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,6 +10,7 @@ #include "vscp.h" #include "vscphelper.h" +#include #include #include diff --git a/src/vscpworks.cpp b/src/vscpworks.cpp index acb5c577..683fa043 100644 --- a/src/vscpworks.cpp +++ b/src/vscpworks.cpp @@ -47,14 +47,15 @@ #include #include #include +#include #include #include #include #include #include #include -#include -#include +// #include +// #include #include #include #include @@ -137,7 +138,7 @@ vscpworks::~vscpworks() break; } } - m_worksdb.close(); + //m_worksdb.close(); } /////////////////////////////////////////////////////////////////////////////// @@ -609,6 +610,7 @@ vscpworks::removeConnection(const QString& uuid, bool bSave) bool vscpworks::loadEventDb(void) { +/* m_mutexVscpEventsMaps.lock(); m_evdb = QSqlDatabase::addDatabase("QSQLITE", "vscpevents"); @@ -654,6 +656,7 @@ vscpworks::loadEventDb(void) } m_mutexVscpEventsMaps.unlock(); +*/ return true; } @@ -694,53 +697,53 @@ vscpworks::openVscpWorksDatabase(void) // Set up database QString eventdbname = m_shareFolder + "vscpworks.sqlite3"; - QString dbName(eventdbname); - m_worksdb = QSqlDatabase::addDatabase("QSQLITE", "vscpworks"); - m_worksdb.setDatabaseName(dbName); - m_worksdb.open(); + // QString dbName(eventdbname); + // m_worksdb = QSqlDatabase::addDatabase("QSQLITE", "vscpworks"); + // m_worksdb.setDatabaseName(dbName); + // m_worksdb.open(); // Create GUID table if it does not exist - QSqlQuery query = QSqlQuery(m_worksdb); - if (!query.exec("CREATE TABLE IF NOT EXISTS guid (" - "idx INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," - "guid TEXT UNIQUE," - "name TEXT," - "description TEXT);")) { - qDebug() << query.lastError(); - return false; - } + // QSqlQuery query = QSqlQuery(m_worksdb); + // if (!query.exec("CREATE TABLE IF NOT EXISTS guid (" + // "idx INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," + // "guid TEXT UNIQUE," + // "name TEXT," + // "description TEXT);")) { + // qDebug() << query.lastError(); + // return false; + // } // Create GUID name index - if (!query.exec("CREATE INDEX IF NOT EXISTS \"idxGuidName\" ON \"guid\" (\"guid\" ASC)")) { - qDebug() << query.lastError(); - return false; - } - - if (!query.exec("CREATE TABLE IF NOT EXISTS \"sensorindex\" (" - "\"idx\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," - "\"link_to_guid\" INTEGER, " - "\"sensor\" INTEGER, " - "\"name\" TEXT, " - "\"description\" TEXT );")) { - qDebug() << query.lastError(); - return false; - } - - // Create sensor link + idx unique index - if (!query.exec("CREATE UNIQUE INDEX IF NOT EXISTS \"idxSensors\" ON \"sensorindex\" (\"link_to_guid\" ASC, \"sensor\" ASC)")) { - qDebug() << query.lastError(); - return false; - } - - // Create log table if it does not exist - if (!query.exec("CREATE TABLE IF NOT EXISTS log (" - "idx INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," - "level INTEGER," - "datetime TEXT," - "message TEXT);")) { - qDebug() << query.lastError(); - return false; - } + // if (!query.exec("CREATE INDEX IF NOT EXISTS \"idxGuidName\" ON \"guid\" (\"guid\" ASC)")) { + // qDebug() << query.lastError(); + // return false; + // } + + // if (!query.exec("CREATE TABLE IF NOT EXISTS \"sensorindex\" (" + // "\"idx\" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," + // "\"link_to_guid\" INTEGER, " + // "\"sensor\" INTEGER, " + // "\"name\" TEXT, " + // "\"description\" TEXT );")) { + // qDebug() << query.lastError(); + // return false; + // } + + // // Create sensor link + idx unique index + // if (!query.exec("CREATE UNIQUE INDEX IF NOT EXISTS \"idxSensors\" ON \"sensorindex\" (\"link_to_guid\" ASC, \"sensor\" ASC)")) { + // qDebug() << query.lastError(); + // return false; + // } + + // // Create log table if it does not exist + // if (!query.exec("CREATE TABLE IF NOT EXISTS log (" + // "idx INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE," + // "level INTEGER," + // "datetime TEXT," + // "message TEXT);")) { + // qDebug() << query.lastError(); + // return false; + // } // Load known GUID's to memory loadGuidTable(); @@ -760,17 +763,17 @@ vscpworks::loadGuidTable(void) { m_mutexGuidMap.lock(); - QSqlQuery query("SELECT * FROM guid order by name", m_worksdb); - if (QSqlError::NoError != query.lastError().type()) { - m_mutexGuidMap.unlock(); - return false; - } + // QSqlQuery query("SELECT * FROM guid order by name", m_worksdb); + // if (QSqlError::NoError != query.lastError().type()) { + // m_mutexGuidMap.unlock(); + // return false; + // } - while (query.next()) { - QString guid = query.value(1).toString(); - QString name = query.value(2).toString(); - m_mapGuidToSymbolicName[guid] = name; - } + // while (query.next()) { + // QString guid = query.value(1).toString(); + // QString name = query.value(2).toString(); + // m_mapGuidToSymbolicName[guid] = name; + // } m_mutexGuidMap.unlock(); return true; @@ -785,18 +788,18 @@ vscpworks::loadSensorTable(void) { m_mutexSensorIndexMap.lock(); - QSqlQuery query("SELECT * FROM sensorindex order by sensor", m_worksdb); - if (QSqlError::NoError != query.lastError().type()) { - m_mutexSensorIndexMap.unlock(); - return false; - } + // QSqlQuery query("SELECT * FROM sensorindex order by sensor", m_worksdb); + // if (QSqlError::NoError != query.lastError().type()) { + // m_mutexSensorIndexMap.unlock(); + // return false; + // } - while (query.next()) { - int link_to_guid = query.value(1).toInt(); - int sensor = query.value(2).toInt(); - QString name = query.value(3).toString(); - m_mapSensorIndexToSymbolicName[(link_to_guid << 8) + sensor] = name; - } + // while (query.next()) { + // int link_to_guid = query.value(1).toInt(); + // int sensor = query.value(2).toInt(); + // QString name = query.value(3).toString(); + // m_mapSensorIndexToSymbolicName[(link_to_guid << 8) + sensor] = name; + // } m_mutexSensorIndexMap.unlock(); return true; @@ -818,15 +821,15 @@ vscpworks::addGuid(QString guid, QString name) return true; } - QString strInsert = "INSERT INTO guid (guid, name) VALUES (%1,%2);"; - QSqlQuery queryClass(strInsert.arg(guid).arg(name), m_worksdb); - if (queryClass.lastError().isValid()) { - spdlog::error(std::string(tr("Failed to insert GUID into database %s") - .arg(queryClass.lastError().text()) - .toStdString())); - qDebug() << queryClass.lastError(); - return false; - } + // QString strInsert = "INSERT INTO guid (guid, name) VALUES (%1,%2);"; + // QSqlQuery queryClass(strInsert.arg(guid).arg(name), m_worksdb); + // if (queryClass.lastError().isValid()) { + // spdlog::error(std::string(tr("Failed to insert GUID into database %s") + // .arg(queryClass.lastError().text()) + // .toStdString())); + // qDebug() << queryClass.lastError(); + // return false; + // } // Add to loaded m_mapGuidToSymbolicName[guid] = name; @@ -848,15 +851,15 @@ vscpworks::getIdxForGuidRecord(const QString& guid) QString strInsert = "SELECT * FROM guid WHERE guid='%1';"; - QSqlQuery query(strInsert.arg(guid), m_worksdb); - if (query.lastError().isValid()) { - m_mutexGuidMap.unlock(); - return -1; - } + // QSqlQuery query(strInsert.arg(guid), m_worksdb); + // if (query.lastError().isValid()) { + // m_mutexGuidMap.unlock(); + // return -1; + // } - if (query.next()) { - index = query.value(0).toInt(); - } + // if (query.next()) { + // index = query.value(0).toInt(); + // } m_mutexGuidMap.unlock(); return index; @@ -929,18 +932,18 @@ vscpworks::getUnitInfo(uint16_t vscpClass, uint16_t vscpType, uint8_t unit) QString strQuery = "SELECT * FROM vscp_unit WHERE nunit='%1' AND link_to_class=%2 AND link_to_type=%3;"; - QSqlQuery query(m_evdb); - query.exec(strQuery.arg(unit).arg(vscpClass).arg(vscpType)); - - while (query.next()) { - u.m_unit = query.value(3).toInt(); - u.m_name = query.value(4).toString().toStdString(); - u.m_description = query.value(5).toString().toStdString(); - u.m_conversion0 = query.value(6).toString().toStdString(); - u.m_conversion = query.value(7).toString().toStdString(); - u.m_symbol_ascii = query.value(8).toString().toStdString(); - u.m_symbol_utf8 = query.value(9).toString().toStdString(); - } + // QSqlQuery query(m_evdb); + // query.exec(strQuery.arg(unit).arg(vscpClass).arg(vscpType)); + + // while (query.next()) { + // u.m_unit = query.value(3).toInt(); + // u.m_name = query.value(4).toString().toStdString(); + // u.m_description = query.value(5).toString().toStdString(); + // u.m_conversion0 = query.value(6).toString().toStdString(); + // u.m_conversion = query.value(7).toString().toStdString(); + // u.m_symbol_ascii = query.value(8).toString().toStdString(); + // u.m_symbol_utf8 = query.value(9).toString().toStdString(); + // } return u; } @@ -1027,44 +1030,44 @@ vscpworks::getVscpRenderData(uint16_t vscpClass, uint16_t vscpType, QString type QString strQuery = "SELECT * FROM vscp_render WHERE type='%1' AND link_to_class=%2 AND link_to_type=%3;"; qDebug() << strQuery.arg(type).arg(vscpClass).arg(vscpType); - QSqlQuery query(m_evdb); - query.exec(strQuery.arg(type).arg(vscpClass).arg(vscpType)); - // Try if there is a general render definition if none - // is defined for the event - qDebug() << query.size(); - qDebug() << query.numRowsAffected(); - if (query.next()) { - query.first(); - } - else { - // Definition for all events of class - query.exec(strQuery.arg(type).arg(vscpClass).arg(-1)); - query.first(); - } - do { - - // * * * VARIABLES * * * - QString vscpVariables = query.value(4).toString(); - if (vscpVariables.startsWith("BASE64:", Qt::CaseInsensitive)) { - vscpVariables = vscpVariables.right(vscpVariables.length() - 7); - vscpVariables = QByteArray::fromBase64(vscpVariables.toLatin1(), QByteArray::Base64Encoding); - } - - qDebug() << vscpVariables; - qDebug() << "---------------------------------------------"; - vscpVariables.replace("\"", ""e;").replace(""e;", "'").replace("&", "&").replace(">", ">").replace("<", "<"); - qDebug() << vscpVariables; - - // * * * TEMPLATES * * * - QString vscpTemplate = query.value(5).toString(); - if (vscpTemplate.startsWith("BASE64:", Qt::CaseInsensitive)) { - vscpTemplate = vscpTemplate.right(vscpTemplate.length() - 7); - vscpTemplate = QByteArray::fromBase64(vscpVariables.toLatin1(), QByteArray::Base64Encoding); - } - vscpTemplate.replace("\"", ""e;").replace(""e;", "'").replace("&", "&").replace(">", ">").replace("<", "<"); - qDebug() << vscpTemplate; - strList << vscpVariables << vscpTemplate; - } while (query.next()); + // QSqlQuery query(m_evdb); + // query.exec(strQuery.arg(type).arg(vscpClass).arg(vscpType)); + // // Try if there is a general render definition if none + // // is defined for the event + // qDebug() << query.size(); + // qDebug() << query.numRowsAffected(); + // if (query.next()) { + // query.first(); + // } + // else { + // // Definition for all events of class + // query.exec(strQuery.arg(type).arg(vscpClass).arg(-1)); + // query.first(); + // } + // do { + + // // * * * VARIABLES * * * + // QString vscpVariables = query.value(4).toString(); + // if (vscpVariables.startsWith("BASE64:", Qt::CaseInsensitive)) { + // vscpVariables = vscpVariables.right(vscpVariables.length() - 7); + // vscpVariables = QByteArray::fromBase64(vscpVariables.toLatin1(), QByteArray::Base64Encoding); + // } + + // qDebug() << vscpVariables; + // qDebug() << "---------------------------------------------"; + // vscpVariables.replace("\"", ""e;").replace(""e;", "'").replace("&", "&").replace(">", ">").replace("<", "<"); + // qDebug() << vscpVariables; + + // // * * * TEMPLATES * * * + // QString vscpTemplate = query.value(5).toString(); + // if (vscpTemplate.startsWith("BASE64:", Qt::CaseInsensitive)) { + // vscpTemplate = vscpTemplate.right(vscpTemplate.length() - 7); + // vscpTemplate = QByteArray::fromBase64(vscpVariables.toLatin1(), QByteArray::Base64Encoding); + // } + // vscpTemplate.replace("\"", ""e;").replace(""e;", "'").replace("&", "&").replace(">", ">").replace("<", "<"); + // qDebug() << vscpTemplate; + // strList << vscpVariables << vscpTemplate; + // } while (query.next()); return strList; } diff --git a/src/vscpworks.h b/src/vscpworks.h index 4a5b5a93..197510cc 100644 --- a/src/vscpworks.h +++ b/src/vscpworks.h @@ -49,8 +49,9 @@ #include #include #include -#include - +#include +#include +//#include #include #include @@ -537,10 +538,10 @@ class vscpworks : public QApplication { std::map m_mapSensorIndexToSymbolicName; /// VSCP works database - QSqlDatabase m_worksdb; + //QSqlDatabase m_worksdb; /// Event database - QSqlDatabase m_evdb; + //QSqlDatabase m_evdb; // List with open childwindows std::list m_childWindows;