Skip to content

Commit

Permalink
Removed dependency on QSql
Browse files Browse the repository at this point in the history
  • Loading branch information
grodansparadis committed Sep 22, 2024
1 parent 4569c0d commit b65f257
Show file tree
Hide file tree
Showing 12 changed files with 397 additions and 387 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -678,7 +678,7 @@ else()
target_link_libraries(${PROJECT_NAME} PRIVATE
Qt6::Widgets
Qt6::Qml
Qt6::Sql
# Qt6::Sql
Qt6::Charts
m
dl
Expand Down
171 changes: 86 additions & 85 deletions src/cdlgknownguid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -139,7 +139,7 @@ CDlgKnownGuid::fillGuidFromDb(void)
insertGuidItem(guid, name);
}
pworks->m_mutexGuidMap.unlock();
pworks->m_mutexGuidMap.unlock();*/
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -235,6 +235,7 @@ CDlgKnownGuid::listItemClicked(QTableWidgetItem* item)
}
pworks->m_mutexGuidMap.unlock();
*/
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -551,7 +552,7 @@ CDlgKnownGuid::btnEdit(void)
}
pworks->m_mutexGuidMap.unlock();

*/
again:
if (QDialog::Accepted == dlg.exec()) {

Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<QString, QString>::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<QString, QString>::iterator it = pworks->m_mapGuidToSymbolicName.find(strguid);
// // if (std::map::end != it) {

// // }
// }

pworks->m_mutexGuidMap.unlock();
}
Expand Down
Loading

0 comments on commit b65f257

Please sign in to comment.