From 25a87fe3c0c177e439fa46c4ea74a27e96ef62fa Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 18 Jan 2026 12:20:06 +0100 Subject: [PATCH 01/29] Unify application version and db version DB version equals to app version ignoring patch number --- quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp | 6 ++++-- quickevent/app/quickevent/src/appversion.h | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp b/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp index c8893ef72..796c38221 100644 --- a/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp @@ -571,8 +571,10 @@ DbSchema *EventPlugin::dbSchema() int EventPlugin::dbVersion() { - // equals to minimal app version compatible with this DB - return 30301; + // equals to app version ignoring patch number + auto app_ver = QCoreApplication::applicationVersion(); + auto db_ver = (qf::core::Utils::versionStringToInt(app_ver) / 100) * 100; + return db_ver; } QString EventPlugin::dbVersionString() diff --git a/quickevent/app/quickevent/src/appversion.h b/quickevent/app/quickevent/src/appversion.h index b3670d327..f8dc06624 100644 --- a/quickevent/app/quickevent/src/appversion.h +++ b/quickevent/app/quickevent/src/appversion.h @@ -1,4 +1,4 @@ #pragma once -#define APP_VERSION "3.4.27" +#define APP_VERSION "3.5.0" From 28a0999f93221a4c606c035127b19baa045a591a Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 23 Jan 2026 22:57:07 +0100 Subject: [PATCH 02/29] Multi-course classes #1086 --- quickevent/app/quickevent/CMakeLists.txt | 1 + .../plugins/Classes/src/classeswidget.cpp | 70 ++----------------- .../Classes/src/courseitemdelegate.cpp | 55 +++++++++++++++ .../plugins/Classes/src/courseitemdelegate.h | 26 +++++++ .../quickevent/plugins/Event/qml/DbSchema.qml | 1 + .../plugins/Event/src/eventconfig.cpp | 11 +-- .../plugins/Event/src/eventconfig.h | 4 +- .../plugins/Runs/src/runstablemodel.cpp | 26 +++++-- .../plugins/Runs/src/runstablemodel.h | 3 +- .../plugins/Runs/src/runstablewidget.cpp | 26 +++++-- .../plugins/Runs/src/runstablewidget.h | 3 + 11 files changed, 142 insertions(+), 84 deletions(-) create mode 100644 quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp create mode 100644 quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h diff --git a/quickevent/app/quickevent/CMakeLists.txt b/quickevent/app/quickevent/CMakeLists.txt index 52ca15c1b..8d10661f1 100644 --- a/quickevent/app/quickevent/CMakeLists.txt +++ b/quickevent/app/quickevent/CMakeLists.txt @@ -43,6 +43,7 @@ add_executable(quickevent plugins/Classes/src/editcourseswidget.cpp plugins/Classes/src/editcourseswidget.ui plugins/Classes/src/importcoursedef.cpp + plugins/Classes/src/courseitemdelegate.h plugins/Classes/src/courseitemdelegate.cpp plugins/Competitors/src/competitordocument.cpp plugins/Competitors/src/competitorwidget.cpp diff --git a/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp b/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp index 56faf7216..40a4f8323 100644 --- a/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp +++ b/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp @@ -1,12 +1,15 @@ -#include "classesplugin.h" #include "classeswidget.h" #include "ui_classeswidget.h" +#include "classesplugin.h" #include "importcoursedef.h" #include "editcodeswidget.h" #include "editcourseswidget.h" #include "drawing/drawingganttwidget.h" +#include +#include + #include #include @@ -26,7 +29,6 @@ #include #include #include -#include #include #include @@ -48,70 +50,6 @@ using qf::gui::framework::getPlugin; using Event::EventPlugin; using Classes::ClassesPlugin; -class CourseItemDelegate : public QStyledItemDelegate -{ - Q_OBJECT -public: - CourseItemDelegate(QObject *parent) : QStyledItemDelegate(parent) {} - - Q_SIGNAL void courseIdChanged(); - - QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE - { - Q_UNUSED(option) - Q_UNUSED(index) - auto *editor = new QComboBox(parent); -#if QT_VERSION_MAJOR >= 6 - QMultiMapIterator it(m_courseNameToId); -#else - QMapIterator it(m_courseNameToId); -#endif - while(it.hasNext()) { - it.next(); - editor->addItem(it.key(), it.value()); - } - return editor; - } - void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE - { - auto *cbx = qobject_cast(editor); - QF_ASSERT(cbx != nullptr, "Bad combo!", return); - QString id = index.data(Qt::EditRole).toString(); - int ix = cbx->findData(id); - cbx->setCurrentIndex(ix); - } - void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const Q_DECL_OVERRIDE - { - qfLogFuncFrame(); - auto *cbx = qobject_cast(editor); - QF_ASSERT(cbx != nullptr, "Bad combo!", return); - qfDebug() << "setting model data:" << cbx->currentText() << cbx->currentData(); - model->setData(index, cbx->currentData(), Qt::EditRole); - emit const_cast(this)->courseIdChanged(); // NOLINT(cppcoreguidelines-pro-type-const-cast) - } - - QString displayText(const QVariant &value, const QLocale &locale) const Q_DECL_OVERRIDE - { - Q_UNUSED(locale) - return m_idToCourseName.value(value.toInt(), QStringLiteral("???")); - } - - void setCourses(const QMap &courses) - { - m_idToCourseName = courses; - m_courseNameToId.clear(); - QMapIterator it(m_idToCourseName); - while(it.hasNext()) { - it.next(); - m_courseNameToId.insert(it.value(), it.key()); - } - } - -private: - QMap m_idToCourseName; - QMultiMap m_courseNameToId; -}; - class CourseCodesTableModel : public qfm::SqlTableModel { Q_OBJECT diff --git a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp new file mode 100644 index 000000000..841f43514 --- /dev/null +++ b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp @@ -0,0 +1,55 @@ +#include "courseitemdelegate.h" + +#include + +#include + +CourseItemDelegate::CourseItemDelegate(QObject *parent) + : QStyledItemDelegate(parent) +{} + +QWidget *CourseItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + Q_UNUSED(option) + Q_UNUSED(index) + auto *editor = new QComboBox(parent); + QMap name_to_id; + if (!m_nullText.isEmpty()) { + editor->addItem(m_nullText, {}); + } + for (const auto &[id, name] : m_idToCourseName.asKeyValueRange()) { + name_to_id[name] = id; + } + for (const auto &[name, id] : name_to_id.asKeyValueRange()) { + editor->addItem(name, id); + } + return editor; +} +void CourseItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const +{ + auto *cbx = qobject_cast(editor); + QF_ASSERT(cbx != nullptr, "Bad combo!", return); + QString id = index.data(Qt::EditRole).toString(); + int ix = cbx->findData(id); + cbx->setCurrentIndex(ix); +} +void CourseItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + qfLogFuncFrame(); + auto *cbx = qobject_cast(editor); + QF_ASSERT(cbx != nullptr, "Bad combo!", return); + qfDebug() << "setting model data:" << cbx->currentText() << cbx->currentData(); + model->setData(index, cbx->currentData(), Qt::EditRole); + emit const_cast(this)->courseIdChanged(); // NOLINT(cppcoreguidelines-pro-type-const-cast) +} + +QString CourseItemDelegate::displayText(const QVariant &value, const QLocale &locale) const +{ + Q_UNUSED(locale) + return m_idToCourseName.value(value.toInt(), "???"); +} + +void CourseItemDelegate::setCourses(const QMap &courses) +{ + m_idToCourseName = courses; +} diff --git a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h new file mode 100644 index 000000000..200f68eeb --- /dev/null +++ b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +class CourseItemDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + CourseItemDelegate(QObject *parent); + + Q_SIGNAL void courseIdChanged(); + + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; + void setEditorData(QWidget *editor, const QModelIndex &index) const override; + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; + + QString displayText(const QVariant &value, const QLocale &locale) const override; + void setNullText(const QString &text) { m_nullText = text; } + + void setCourses(const QMap &courses); +private: + QMap m_idToCourseName; + QString m_nullText; +}; + + diff --git a/quickevent/app/quickevent/plugins/Event/qml/DbSchema.qml b/quickevent/app/quickevent/plugins/Event/qml/DbSchema.qml index c6a8946ac..c06846d00 100644 --- a/quickevent/app/quickevent/plugins/Event/qml/DbSchema.qml +++ b/quickevent/app/quickevent/plugins/Event/qml/DbSchema.qml @@ -191,6 +191,7 @@ Schema { //defaultValue: 0; //notNull: true }, + Field { name: 'courseId'; type: Int {} }, Field { name: 'relayId'; type: Int {} }, Field { name: 'corridorTime'; type: DateTime {} comment: 'DateTime when competitor entered start corridor. (Experimental)' diff --git a/quickevent/app/quickevent/plugins/Event/src/eventconfig.cpp b/quickevent/app/quickevent/plugins/Event/src/eventconfig.cpp index a9c15a07e..d45f0c389 100644 --- a/quickevent/app/quickevent/plugins/Event/src/eventconfig.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/eventconfig.cpp @@ -65,11 +65,12 @@ void EventConfig::load() Connection conn = Connection::forName(); // Check connection existence / validity - if(!conn.isOpen()) { - qfWarning() << "EventConfig::load(): database connection is not open:" - << conn.errorString(); - return; - } + Q_ASSERT(conn.isOpen()); + // if(!conn.isOpen()) { + // qfWarning() << "EventConfig::load(): database connection is not open:" + // << conn.errorString(); + // return; + // } Query q(conn); QueryBuilder qb; diff --git a/quickevent/app/quickevent/plugins/Event/src/eventconfig.h b/quickevent/app/quickevent/plugins/Event/src/eventconfig.h index 11819cac5..a0f876b42 100644 --- a/quickevent/app/quickevent/plugins/Event/src/eventconfig.h +++ b/quickevent/app/quickevent/plugins/Event/src/eventconfig.h @@ -35,7 +35,9 @@ class EventConfig : public QObject public: QVariantMap values() const {return m_data;} QVariant value(const QStringList &path, const QVariant &default_value = QVariant()) const; - QVariant value(const QString &path, const QVariant &default_value = QVariant()) const {return value(path.split('.'), default_value);} + QVariant value(const QString &path, const QVariant &default_value = QVariant()) const { + return value(path.split('.'), default_value); + } void setValue(const QStringList &path, const QVariant &val); void setValue(const QString &path, const QVariant &val) {setValue(path.split('.'), val);} void load(); diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp index 45775f89f..fe183294e 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp @@ -29,6 +29,7 @@ RunsTableModel::RunsTableModel(QObject *parent) setColumn(col_runs_leg, ColumnDefinition("runs.leg", tr("Leg"))); setColumn(col_classes_name, ColumnDefinition("classes.name", tr("Class"))); setColumn(col_startNumber, ColumnDefinition("startNumber", tr("SN", "start number")).setToolTip(tr("Start number"))); + setColumn(col_course_id, ColumnDefinition("runs.courseId", tr("Course"))); setColumn(col_competitors_siId, ColumnDefinition("competitors.siId", tr("SI")).setToolTip(tr("Registered SI")).setReadOnly(true)); setColumn(col_competitorName, ColumnDefinition("competitorName", tr("Name"))); setColumn(col_registration, ColumnDefinition("registration", tr("Reg"))); @@ -49,13 +50,6 @@ RunsTableModel::RunsTableModel(QObject *parent) connect(this, &RunsTableModel::dataChanged, this, &RunsTableModel::onDataChanged, Qt::QueuedConnection); } -QVariant RunsTableModel::data(const QModelIndex &index, int role) const -{ - QVariant ret; - ret = Super::data(index, role); - return ret; -} - Qt::ItemFlags RunsTableModel::flags(const QModelIndex &index) const { Qt::ItemFlags flgs = Super::flags(index); @@ -64,9 +58,27 @@ Qt::ItemFlags RunsTableModel::flags(const QModelIndex &index) const flgs = Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | flgs; //qfInfo() << flgs; } + if(index.column() == col_course_id) { + if (getPlugin()->eventConfig()->isRelays()) { + flgs &= ~Qt::ItemIsEditable; + } + } return flgs; } +QVariant RunsTableModel::data(const QModelIndex &index, int role) const +{ + if(index.column() == col_course_id && role == Qt::DisplayRole) { + if (getPlugin()->eventConfig()->isRelays()) { + auto start_number = value(index.row(), "startNumber").toInt(); + auto leg = value(index.row(), "runs.leg").toInt(); + return QStringLiteral("%1.%2").arg(start_number).arg(leg); + } + } + + return Super::data(index, role); +} + QVariant RunsTableModel::value(int row_ix, int column_ix) const { if(column_ix == col_runFlags) { diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h index e58e1618b..9379bfebd 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h @@ -15,6 +15,7 @@ class RunsTableModel : public quickevent::gui::og::SqlTableModel col_relays_name, col_runs_leg, col_classes_name, + col_course_id, col_startNumber, col_competitors_siId, col_competitorName, @@ -38,9 +39,9 @@ class RunsTableModel : public quickevent::gui::og::SqlTableModel RunsTableModel(QObject *parent = nullptr); int columnCount(const QModelIndex &) const override { return col_COUNT; } + Qt::ItemFlags flags(const QModelIndex &index) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; //bool setData(const QModelIndex &index, const QVariant &value, int role) override; - Qt::ItemFlags flags(const QModelIndex &index) const override; using Super::value; QVariant value(int row_ix, int column_ix) const override; diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index 302c8a7b5..5383f4f66 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -7,6 +7,11 @@ #include "runflagsdialog.h" #include "cardflagsdialog.h" +#include +#include +#include +#include + #include #include @@ -19,9 +24,6 @@ #include #include #include -#include -#include -#include #include #include @@ -54,7 +56,14 @@ RunsTableWidget::RunsTableWidget(QWidget *parent) : ui->tblRuns->setInlineEditSaveStrategy(qfw::TableView::OnEditedValueCommit); m_runsTableItemDelegate = new RunsTableItemDelegate(ui->tblRuns); ui->tblRuns->setItemDelegate(m_runsTableItemDelegate); - + auto *event_plugin = getPlugin(); + connect(event_plugin, &EventPlugin::eventOpenChanged, this, [this, event_plugin](bool is_open) { + if (is_open && !event_plugin->eventConfig()->isRelays() && !m_courseItemDelegate) { + m_courseItemDelegate = new CourseItemDelegate(ui->tblRuns); + m_courseItemDelegate->setNullText(tr("Implicit")); + ui->tblRuns->setItemDelegateForColumn(RunsTableModel::col_course_id, m_courseItemDelegate); + } + }); //ui->tblRuns->setSelectionMode(QTableView::SingleSelection); ui->tblRuns->viewport()->setAcceptDrops(true); ui->tblRuns->setDropIndicatorShown(true); @@ -158,6 +167,15 @@ void RunsTableWidget::reload(int stage_id, int class_id, bool show_offrace, cons ui->lblClassInterval->setText(class_start_interval_min >= 0? QString::number(class_start_interval_min): "---"); } bool is_relays = getPlugin()->eventConfig()->isRelays(); + if (!is_relays && m_courseItemDelegate) { + QMap courses; + qf::core::sql::Query q; + q.exec("SELECT id, name, note FROM courses ORDER BY name, note"); + while(q.next()) { + courses[q.value(0).toInt()] = q.value(1).toString() + ' ' + q.value(2).toString(); + } + m_courseItemDelegate->setCourses(courses); + } auto qb = getPlugin()->runsQuery(stage_id, class_id, show_offrace); qfDebug() << qb.toString(); m_runsTableItemDelegate->setHighlightedClassId(class_id, stage_id); diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h index 0fd3e80db..332d43b3b 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h @@ -4,6 +4,8 @@ class RunsTableModel; class RunsTableItemDelegate; +class CourseItemDelegate; + namespace qf::gui { class TableView; } namespace Ui { @@ -36,5 +38,6 @@ class RunsTableWidget : public QWidget Ui::RunsTableWidget *ui; RunsTableModel *m_runsModel; RunsTableItemDelegate *m_runsTableItemDelegate; + CourseItemDelegate *m_courseItemDelegate = nullptr; }; From 83edcb435ac7aa92e1197afbea15f2bdbf2dc629 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 23 Jan 2026 23:18:50 +0100 Subject: [PATCH 03/29] Add "Set course in selected rows" context menu --- .../plugins/Runs/src/runstablewidget.cpp | 60 ++++++++++++++++--- .../plugins/Runs/src/runstablewidget.h | 2 + 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index 5383f4f66..bed6f4e2e 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -168,13 +168,7 @@ void RunsTableWidget::reload(int stage_id, int class_id, bool show_offrace, cons } bool is_relays = getPlugin()->eventConfig()->isRelays(); if (!is_relays && m_courseItemDelegate) { - QMap courses; - qf::core::sql::Query q; - q.exec("SELECT id, name, note FROM courses ORDER BY name, note"); - while(q.next()) { - courses[q.value(0).toInt()] = q.value(1).toString() + ' ' + q.value(2).toString(); - } - m_courseItemDelegate->setCourses(courses); + m_courseItemDelegate->setCourses(definedCourses()); } auto qb = getPlugin()->runsQuery(stage_id, class_id, show_offrace); qfDebug() << qb.toString(); @@ -234,6 +228,17 @@ qf::gui::TableView *RunsTableWidget::tableView() return ui->tblRuns; } +QMap RunsTableWidget::definedCourses() +{ + QMap courses; + qf::core::sql::Query q; + q.exec("SELECT id, name, note FROM courses ORDER BY name, note"); + while(q.next()) { + courses[q.value(0).toInt()] = q.value(1).toString() + ' ' + q.value(2).toString(); + } + return courses; +} + void RunsTableWidget::onCustomContextMenuRequest(const QPoint &pos) { qfLogFuncFrame(); @@ -244,12 +249,14 @@ void RunsTableWidget::onCustomContextMenuRequest(const QPoint &pos) QAction a_shift_start_times(tr("Shift start times in selected rows"), nullptr); QAction a_clear_start_times(tr("Clear start times in selected rows"), nullptr); QAction a_change_class(tr("Set class in selected rows"), nullptr); + QAction a_change_course(tr("Set course in selected rows"), nullptr); QList lst; lst << &a_show_receipt << &a_load_card << &a_print_card << &a_sep1 << &a_shift_start_times << &a_clear_start_times - << &a_change_class; + << &a_change_class + << &a_change_course; QAction *a = QMenu::exec(lst, ui->tblRuns->viewport()->mapToGlobal(pos)); if(a == &a_load_card) { qf::gui::framework::MainWindow *fwk = qf::gui::framework::MainWindow::frameWork(); @@ -362,7 +369,7 @@ void RunsTableWidget::onCustomContextMenuRequest(const QPoint &pos) for(int i : rows) { qf::core::utils::TableRow row = ui->tblRuns->tableRowRef(i); int competitor_id = row.value("competitors.id").toInt(); - q.exec(QString("UPDATE competitors SET classId=%1 WHERE id=%2").arg(class_id).arg(competitor_id), qfc::Exception::Throw); + q.exec(QStringLiteral("UPDATE competitors SET classId=%1 WHERE id=%2").arg(class_id).arg(competitor_id), qfc::Exception::Throw); } transaction.commit(); } @@ -373,6 +380,41 @@ void RunsTableWidget::onCustomContextMenuRequest(const QPoint &pos) ui->tblRuns->reload(true); } } + else if(a == &a_change_course) { + qfw::dialogs::GetItemInputDialog dlg(this); + QComboBox *box = dlg.comboBox(); + auto courses = definedCourses(); + box->addItem(tr("Implicit"), {}); + QMap name_to_id; + for (const auto &[id, name] : courses.asKeyValueRange()) { + name_to_id[name] = id; + } + for (const auto &[name, id] : name_to_id.asKeyValueRange()) { + box->addItem(name, id); + } + dlg.setWindowTitle(tr("Quick Event - Select course")); + dlg.setLabelText(tr("Select course")); + dlg.setCurrentItemIndex(0); + if(dlg.exec()) { + auto course_id = dlg.currentData(); + qfs::Transaction transaction; + try { + QList rows = ui->tblRuns->selectedRowsIndexes(); + qfs::Query q; + for(int i : rows) { + qf::core::utils::TableRow row = ui->tblRuns->tableRowRef(i); + int run_id = row.value("runs.id").toInt(); + auto course_id_str = course_id.isNull() ? QStringLiteral("NULL") : QString::number(course_id.toInt()); + q.exec(QStringLiteral("UPDATE runs SET courseId=%1 WHERE id=%2").arg(course_id_str).arg(run_id), qfc::Exception::Throw); + } + transaction.commit(); + } + catch (std::exception &e) { + qfError() << e.what(); + } + ui->tblRuns->reload(true); + } + } } void RunsTableWidget::onTableViewSqlException(const QString &what, const QString &where, const QString &stack_trace) diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h index 332d43b3b..8ba2e0964 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h @@ -30,6 +30,8 @@ class RunsTableWidget : public QWidget Q_SIGNAL void editCompetitorRequest(int competitor_id, int mode); private: + QMap definedCourses(); + void updateStartTimeHighlight() const; void onCustomContextMenuRequest(const QPoint &pos); void onTableViewSqlException(const QString &what, const QString &where, const QString &stack_trace); From e1f6718588bda0eb9acaa90f20339a38558df98b Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sat, 24 Jan 2026 22:02:32 +0100 Subject: [PATCH 04/29] Add completer to courses combo --- .../plugins/Classes/src/courseitemdelegate.cpp | 14 ++++++++++++++ .../plugins/Runs/src/runstablewidget.cpp | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp index 841f43514..0335e3c90 100644 --- a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp +++ b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp @@ -3,6 +3,7 @@ #include #include +#include CourseItemDelegate::CourseItemDelegate(QObject *parent) : QStyledItemDelegate(parent) @@ -13,6 +14,10 @@ QWidget *CourseItemDelegate::createEditor(QWidget *parent, const QStyleOptionVie Q_UNUSED(option) Q_UNUSED(index) auto *editor = new QComboBox(parent); + editor->setInsertPolicy(QComboBox::NoInsert); + editor->setSizeAdjustPolicy(QComboBox::AdjustToContents); + editor->setMaxVisibleItems(20); + editor->setEditable(true); QMap name_to_id; if (!m_nullText.isEmpty()) { editor->addItem(m_nullText, {}); @@ -23,6 +28,15 @@ QWidget *CourseItemDelegate::createEditor(QWidget *parent, const QStyleOptionVie for (const auto &[name, id] : name_to_id.asKeyValueRange()) { editor->addItem(name, id); } + // Enable filtering + auto items = name_to_id.keys(); + if (!m_nullText.isEmpty()) { + items.insert(0, m_nullText); + } + auto *completer = new QCompleter(items, editor); + completer->setCaseSensitivity(Qt::CaseInsensitive); + completer->setFilterMode(Qt::MatchContains); + editor->setCompleter(completer); return editor; } void CourseItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index bed6f4e2e..2d0e48f00 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -63,6 +63,10 @@ RunsTableWidget::RunsTableWidget(QWidget *parent) : m_courseItemDelegate->setNullText(tr("Implicit")); ui->tblRuns->setItemDelegateForColumn(RunsTableModel::col_course_id, m_courseItemDelegate); } + else if (!is_open && m_courseItemDelegate) { + delete m_courseItemDelegate; + ui->tblRuns->setItemDelegateForColumn(RunsTableModel::col_course_id, nullptr); + } }); //ui->tblRuns->setSelectionMode(QTableView::SingleSelection); ui->tblRuns->viewport()->setAcceptDrops(true); From 775f4a00bc7e439379d0a826fcd6b0e10676b502 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 25 Jan 2026 17:19:56 +0100 Subject: [PATCH 05/29] Add QCompleter also to context popup menu combo --- .../Classes/src/courseitemdelegate.cpp | 38 ++++++++++++------- .../plugins/Classes/src/courseitemdelegate.h | 5 +++ .../plugins/Runs/src/runstablewidget.cpp | 11 +----- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp index 0335e3c90..3f6c73858 100644 --- a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp +++ b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.cpp @@ -14,31 +14,37 @@ QWidget *CourseItemDelegate::createEditor(QWidget *parent, const QStyleOptionVie Q_UNUSED(option) Q_UNUSED(index) auto *editor = new QComboBox(parent); - editor->setInsertPolicy(QComboBox::NoInsert); - editor->setSizeAdjustPolicy(QComboBox::AdjustToContents); - editor->setMaxVisibleItems(20); - editor->setEditable(true); + initCombo(editor, m_idToCourseName, textImplicit()); + return editor; +} + +void CourseItemDelegate::initCombo(QComboBox *combo, const QMap &courses, const QString &null_text) +{ + combo->setInsertPolicy(QComboBox::NoInsert); + combo->setSizeAdjustPolicy(QComboBox::AdjustToContents); + combo->setMaxVisibleItems(20); + combo->setEditable(true); QMap name_to_id; - if (!m_nullText.isEmpty()) { - editor->addItem(m_nullText, {}); + if (!null_text.isEmpty()) { + combo->addItem(null_text, {}); } - for (const auto &[id, name] : m_idToCourseName.asKeyValueRange()) { + for (const auto &[id, name] : courses.asKeyValueRange()) { name_to_id[name] = id; } for (const auto &[name, id] : name_to_id.asKeyValueRange()) { - editor->addItem(name, id); + combo->addItem(name, id); } // Enable filtering auto items = name_to_id.keys(); - if (!m_nullText.isEmpty()) { - items.insert(0, m_nullText); + if (!null_text.isEmpty()) { + items.insert(0, null_text); } - auto *completer = new QCompleter(items, editor); + auto *completer = new QCompleter(items, combo); completer->setCaseSensitivity(Qt::CaseInsensitive); completer->setFilterMode(Qt::MatchContains); - editor->setCompleter(completer); - return editor; + combo->setCompleter(completer); } + void CourseItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { auto *cbx = qobject_cast(editor); @@ -67,3 +73,9 @@ void CourseItemDelegate::setCourses(const QMap &courses) { m_idToCourseName = courses; } + +QString CourseItemDelegate::textImplicit() +{ + return tr("Implicit"); +} + diff --git a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h index 200f68eeb..d7903ca7d 100644 --- a/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h +++ b/quickevent/app/quickevent/plugins/Classes/src/courseitemdelegate.h @@ -2,6 +2,8 @@ #include +class QComboBox; + class CourseItemDelegate : public QStyledItemDelegate { Q_OBJECT @@ -18,6 +20,9 @@ class CourseItemDelegate : public QStyledItemDelegate void setNullText(const QString &text) { m_nullText = text; } void setCourses(const QMap &courses); + + static QString textImplicit(); + static void initCombo(QComboBox *combo, const QMap &courses, const QString &null_text); private: QMap m_idToCourseName; QString m_nullText; diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index 2d0e48f00..175446b03 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -386,16 +386,9 @@ void RunsTableWidget::onCustomContextMenuRequest(const QPoint &pos) } else if(a == &a_change_course) { qfw::dialogs::GetItemInputDialog dlg(this); - QComboBox *box = dlg.comboBox(); auto courses = definedCourses(); - box->addItem(tr("Implicit"), {}); - QMap name_to_id; - for (const auto &[id, name] : courses.asKeyValueRange()) { - name_to_id[name] = id; - } - for (const auto &[name, id] : name_to_id.asKeyValueRange()) { - box->addItem(name, id); - } + QComboBox *box = dlg.comboBox(); + CourseItemDelegate::initCombo(box, courses, CourseItemDelegate::textImplicit()); dlg.setWindowTitle(tr("Quick Event - Select course")); dlg.setLabelText(tr("Select course")); dlg.setCurrentItemIndex(0); From 270bdbb84a60cd96ef6bd166507a9d8e3dbfc131 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 30 Jan 2026 23:13:59 +0100 Subject: [PATCH 06/29] Fix Card readout - doesn't use custom course at all. --- quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp b/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp index 7f77820c4..c2a8d069e 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp @@ -283,7 +283,8 @@ quickevent::core::CourseDef RunsPlugin::courseForCourseId(int course_id) int RunsPlugin::courseForRun_Classic(int run_id) { qfs::QueryBuilder qb; - qb.select("classdefs.courseId") + qb.select("classdefs.courseId AS implicitCourseId") + .select("runs.courseId AS explicitCourseId") .from("runs") .join("runs.competitorId", "competitors.id") .joinRestricted("competitors.classId", "classdefs.classId", "classdefs.stageId=runs.stageId") @@ -297,7 +298,9 @@ int RunsPlugin::courseForRun_Classic(int run_id) qfError() << "more courses found for run_id:" << run_id; return 0; } - ret = q.value(0).toInt(); + auto implicit_course_id = q.value("implicitCourseId").toInt(); + auto explicit_course_id = q.value("explicitCourseId").toInt(); + ret = explicit_course_id > 0 ? explicit_course_id : implicit_course_id; cnt++; } return ret; From a82e0c9c0869b0c55087bb93bd1aad0b9d1743aa Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 30 Jan 2026 23:24:30 +0100 Subject: [PATCH 07/29] Fix SQL error on course to class assignment --- .../app/quickevent/plugins/Classes/src/classeswidget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp b/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp index 40a4f8323..8da479d89 100644 --- a/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp +++ b/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp @@ -114,8 +114,8 @@ ClassesWidget::ClassesWidget(QWidget *parent) : ui->tblClassesTB->setTableView(ui->tblClasses); auto *m = new qfm::SqlTableModel(this); - //m->setObjectName("classes.classesModel"); - m->addColumn("id").setReadOnly(true); + m->setIdColumnName("classes.id"); + m->addColumn("classes.id").setReadOnly(true); m->addColumn("classes.name", tr("Class")); m->addColumn("classdefs.drawLock", tr("DL")).setToolTip(tr("Locked for drawing")); m->addColumn("classdefs.startTimeMin", tr("Start")); From 9f76585b9ca52cf5206ad35c1693230b5b261c1c Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Mon, 3 Nov 2025 11:12:15 +0100 Subject: [PATCH 08/29] Add libshv dependency to enable QxEvent service implementation --- .clang-tidy | 1 + .gitmodules | 3 + 3rdparty/libshv | 1 + CMakeLists.txt | 4 + .../libqfgui/src/framework/datadialogwidget.h | 2 +- quickevent/app/quickevent/CMakeLists.txt | 6 +- .../Event/src/services/qx/qxclientservice.cpp | 187 ++++++++++++++---- .../Event/src/services/qx/qxclientservice.h | 16 ++ .../Event/src/services/serviceswidget.cpp | 7 +- .../Event/src/services/servicewidget.cpp | 11 +- .../Event/src/services/servicewidget.h | 2 +- 11 files changed, 184 insertions(+), 56 deletions(-) create mode 160000 3rdparty/libshv diff --git a/.clang-tidy b/.clang-tidy index fd21b3531..64c3c28fa 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -40,6 +40,7 @@ Checks: -cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-special-member-functions, + -cppcoreguidelines-use-enum-class -hicpp-avoid-c-arrays, -hicpp-avoid-goto, -hicpp-braces-around-statements, diff --git a/.gitmodules b/.gitmodules index 6e2bec6bb..5006631e0 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "3rdparty/necrolog"] path = 3rdparty/necrolog url = https://github.com/fvacek/necrolog.git +[submodule "3rdparty/libshv"] + path = 3rdparty/libshv + url = https://github.com/silicon-heaven/libshv.git diff --git a/3rdparty/libshv b/3rdparty/libshv new file mode 160000 index 000000000..3cbe496ea --- /dev/null +++ b/3rdparty/libshv @@ -0,0 +1 @@ +Subproject commit 3cbe496ea4d2c48695994850a09c2cc794c3f80b diff --git a/CMakeLists.txt b/CMakeLists.txt index 53fe104c1..025c808c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 3.18.4) set(QF_BUILD_QML_PLUGINS ON CACHE BOOL "Build with QML Plugins support") +set(QF_WITH_LIBSHV OFF CACHE BOOL "Build with libshv") project(quickbox LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 20) @@ -26,6 +27,9 @@ endif (WIN32) if (NOT TARGET libnecrolog) add_subdirectory(3rdparty/necrolog) endif() +if (QF_WITH_LIBSHV) + add_subdirectory(3rdparty/libshv) +endif() set(USE_QT6 ON) find_package(Qt6 REQUIRED COMPONENTS Core Widgets Gui Sql Qml Xml LinguistTools PrintSupport Svg SerialPort Multimedia Network) diff --git a/libqf/libqfgui/src/framework/datadialogwidget.h b/libqf/libqfgui/src/framework/datadialogwidget.h index 37c4c1d91..ec4cca8e0 100644 --- a/libqf/libqfgui/src/framework/datadialogwidget.h +++ b/libqf/libqfgui/src/framework/datadialogwidget.h @@ -26,7 +26,7 @@ class QFGUI_DECL_EXPORT DataDialogWidget : public DialogWidget qf::gui::model::DataDocument* dataDocument(bool throw_exc = qf::core::Exception::Throw); - Q_SLOT virtual bool load(const QVariant &id = QVariant(), int mode = qf::gui::model::DataDocument::ModeEdit); + virtual bool load(const QVariant &id = QVariant(), int mode = qf::gui::model::DataDocument::ModeEdit); bool acceptDialogDone(int result) Q_DECL_OVERRIDE; diff --git a/quickevent/app/quickevent/CMakeLists.txt b/quickevent/app/quickevent/CMakeLists.txt index 05c88047d..f094728f1 100644 --- a/quickevent/app/quickevent/CMakeLists.txt +++ b/quickevent/app/quickevent/CMakeLists.txt @@ -270,12 +270,14 @@ qt6_add_lupdate(quickevent TS_FILES target_sources(quickevent PRIVATE ${QM_FILES}) target_include_directories(quickevent PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/src) target_link_libraries(quickevent PUBLIC libquickeventcore libquickeventgui libqfgui libsiut) +if (QF_WITH_LIBSHV) + target_link_libraries(quickevent PUBLIC libshviotqt) + target_compile_definitions(quickevent PRIVATE QF_WITH_LIBSHV) +endif() install(TARGETS quickevent) install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_BINDIR}/translations) -#install(DIRECTORY plugins/Runs/qml/reports DESTINATION ${CMAKE_INSTALL_BINDIR}/reports/Runs/qml) -#install(DIRECTORY plugins/Receipts/qml/reports DESTINATION ${CMAKE_INSTALL_BINDIR}/reports/Receipts/qml) foreach(plugin IN ITEMS Classes Runs Relays Receipts shared) install(DIRECTORY plugins/${plugin}/qml/reports DESTINATION ${CMAKE_INSTALL_BINDIR}/reports/${plugin}/qml) endforeach() diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.cpp index 502483522..7a9acb8fd 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.cpp @@ -9,6 +9,10 @@ #include #include +#include +#include +#include + #include #include #include @@ -24,6 +28,10 @@ #include #include +using namespace shv::chainpack; +using namespace shv::iotqt::rpc; +using namespace shv::iotqt::node; + using namespace qf::core; using namespace qf::gui; using namespace qf::gui::dialogs; @@ -66,28 +74,41 @@ QString QxClientService::serviceId() } void QxClientService::run() { + using namespace shv::iotqt::rpc; + auto ss = settings(); - auto *reply = getRemoteEventInfo(ss.exchangeServerUrl(), apiToken()); - connect(reply, &QNetworkReply::finished, this, [this, reply, ss]() { - if (reply->error() == QNetworkReply::NetworkError::NoError) { - auto data = reply->readAll(); - auto doc = QJsonDocument::fromJson(data); - EventInfo event_info(doc.toVariant().toMap()); - setStatusMessage(event_info.name() + (event_info.stage_count() > 1? QStringLiteral(" E%1").arg(event_info.stage()): QString())); - m_eventId = event_info.id(); - connectToSSE(m_eventId); - if (!m_pollChangesTimer) { - m_pollChangesTimer = new QTimer(this); - connect(m_pollChangesTimer, &QTimer::timeout, this, &QxClientService::pollQxChanges); - } - pollQxChanges(); - m_pollChangesTimer->start(10000); - Super::run(); - } - else { - qfWarning() << "Cannot run QX service, network error:" << reply->errorString(); - } - }); + + delete m_rpcConnection; + m_rpcConnection = new ClientConnection(this); + m_rpcConnection->setConnectionString(ss.exchangeServerUrl()); + + connect(m_rpcConnection, &ClientConnection::brokerConnectedChanged, this, &QxClientService::onBrokerConnectedChanged); + connect(m_rpcConnection, &ClientConnection::socketError, this, &QxClientService::onBrokerSocketError); + connect(m_rpcConnection, &ClientConnection::brokerLoginError, this, &QxClientService::onBrokerLoginError); + connect(m_rpcConnection, &ClientConnection::rpcMessageReceived, this, &QxClientService::onRpcMessageReceived); + + m_rpcConnection->open(); + +// connect(reply, &QNetworkReply::finished, this, [this, reply, ss]() { +// if (reply->error() == QNetworkReply::NetworkError::NoError) { +// auto data = reply->readAll(); +// auto doc = QJsonDocument::fromJson(data); +// EventInfo event_info(doc.toVariant().toMap()); +// setStatusMessage(event_info.name() + (event_info.stage_count() > 1? QStringLiteral(" E%1").arg(event_info.stage()): QString())); +// m_eventId = event_info.id(); +// connectToSSE(m_eventId); +// if (!m_pollChangesTimer) { +// m_pollChangesTimer = new QTimer(this); +// connect(m_pollChangesTimer, &QTimer::timeout, this, &QxClientService::pollQxChanges); +// } +// pollQxChanges(); +// m_pollChangesTimer->start(10000); +// Super::run(); +// } +// else { +// qfWarning() << "Cannot run QX service, network error:" << reply->errorString(); +// } +// }); } void QxClientService::stop() @@ -537,35 +558,115 @@ EventInfo QxClientService::eventInfo() const // qfInfo() << qf::core::Utils::qvariantToJson(ei, false); return ei; } -/* -namespace { -auto query_to_json_csv(QSqlQuery &q) +//namespace { +//auto query_to_json_csv(QSqlQuery &q) +//{ +// QVariantList csv; +// { +// // QStringList columns{"name", "control_count", "length", "climb", "start_time", "interval", "start_slot_count"}; +// QStringList columns; +// auto rec = q.record(); +// for (auto i = 0; i < rec.count(); ++i) { +// columns << rec.field(i).name(); +// } +// csv.insert(csv.length(), columns); +// } +// while (q.next()) { +// QVariantList values; +// auto rec = q.record(); +// for (auto i = 0; i < rec.count(); ++i) { +// values << q.value(i); +// } +// csv.insert(csv.length(), values); +// } +// return csv; +//} +//} +int QxClientService::currentConnectionId() { - QVariantList csv; - { - // QStringList columns{"name", "control_count", "length", "climb", "start_time", "interval", "start_slot_count"}; - QStringList columns; - auto rec = q.record(); - for (auto i = 0; i < rec.count(); ++i) { - columns << rec.field(i).name(); - } - csv.insert(csv.length(), columns); + return qf::core::sql::Connection::forName().connectionId(); +} + +void QxClientService::onBrokerConnectedChanged(bool is_connected) +{ + if(is_connected) { + setStatus(Status::Running); + QTimer::singleShot(0, this, [this]() { + subscribeChanges(); +// testRpcCall(); + }); + } else { + setStatus(Status::Stopped); } - while (q.next()) { - QVariantList values; - auto rec = q.record(); - for (auto i = 0; i < rec.count(); ++i) { - values << q.value(i); + +} + +void QxClientService::onBrokerSocketError(const QString &err) +{ + setStatusMessage(tr("Broker socket error: %1").arg(err)); +} + +void QxClientService::onBrokerLoginError(const shv::chainpack::RpcError &err) +{ + setStatusMessage(tr("Broker login error: %1").arg(err.toString())); +} + +void QxClientService::onRpcMessageReceived(const shv::chainpack::RpcMessage &msg) +{ +// shvLogFuncFrame() << msg.toCpon(); + if(msg.isRequest()) { + RpcRequest rq(msg); + qfMessage() << "RPC request received:" << rq.toPrettyString(); + if(m_shvTree->root()) { + m_shvTree->root()->handleRpcRequest(rq); } - csv.insert(csv.length(), values); } - return csv; + else if(msg.isResponse()) { + RpcResponse rp(msg); + qfMessage() << "RPC response received:" << rp.toPrettyString(); + } + else if(msg.isSignal()) { + RpcSignal nt(msg); + qfMessage() << "RPC signal received:" << nt.toPrettyString(); + } } + +void QxClientService::subscribeChanges() +{ + Q_ASSERT(m_rpcConnection); + QString shv_path = "test"; + QString signal_name = shv::chainpack::Rpc::SIG_VAL_CHANGED; + auto *rpc_call = RpcCall::createSubscriptionRequest(m_rpcConnection, shv_path, signal_name); + connect(rpc_call, &RpcCall::maybeResult, this, [this, shv_path, signal_name](const ::shv::chainpack::RpcValue &result, const shv::chainpack::RpcError &error) { + if(error.isValid()) { + qfError() << "Signal:" << signal_name << "on SHV path:" << shv_path << "subscribe error:" << error.toString(); + } + else { + qfMessage() << "Signal:" << signal_name << "on SHV path:" << shv_path << "subscribed successfully" << result.toCpon(); + // generate data change without ret value check + m_rpcConnection->callShvMethod((shv_path + "/someInt").toStdString(), "set", 123); + QTimer::singleShot(500, this, [this, shv_path]() { + m_rpcConnection->callShvMethod((shv_path + "/someInt").toStdString(), "set", 321); + }); + } + }); + rpc_call->start(); } -*/ -int QxClientService::currentConnectionId() + +void QxClientService::testRpcCall() const { - return qf::core::sql::Connection::forName().connectionId(); + Q_ASSERT(m_rpcConnection); + auto *rpc_call = RpcCall::create(m_rpcConnection) + ->setShvPath("test") + ->setMethod("ls"); +// ->setTimeout(5000); + connect(rpc_call, &RpcCall::maybeResult, [](const ::shv::chainpack::RpcValue &result, const shv::chainpack::RpcError &error) { + if(error.isValid()) + qfError() << "RPC call error:" << error.toString(); + else + qfInfo() << "Got RPC response, result:" << result.toCpon(); + }); + rpc_call->start(); } } // namespace Event::services::qx diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.h index 636a54c4d..7e1f046be 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.h @@ -7,6 +7,10 @@ class QNetworkReply; class QUrlQuery; class QTimer; +namespace shv::iotqt::node { class ShvNodeTree; } +namespace shv::iotqt::rpc { class ClientConnection; } +namespace shv::chainpack { class RpcMessage; class RpcError; } + namespace Event::services::qx { class QxClientServiceSettings : public ServiceSettings @@ -68,6 +72,14 @@ class QxClientService : public Service QUrl exchangeServerUrl() const; int eventId() const; +private: // shv + void onBrokerConnectedChanged(bool is_connected); + void onRpcMessageReceived(const shv::chainpack::RpcMessage &msg); + void onBrokerSocketError(const QString &err); + void onBrokerLoginError(const shv::chainpack::RpcError &err); + + void subscribeChanges(); + void testRpcCall() const; private: void loadSettings() override; qf::gui::framework::DialogWidget *createDetailWidget() override; @@ -84,6 +96,10 @@ class QxClientService : public Service void pollQxChanges(); EventInfo eventInfo() const; +private: // shv + shv::iotqt::rpc::ClientConnection *m_rpcConnection = nullptr; + shv::iotqt::node::ShvNodeTree *m_shvTree = nullptr; + private: QNetworkAccessManager *m_networkManager = nullptr; QNetworkReply *m_replySSE = nullptr; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/serviceswidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/serviceswidget.cpp index e4c9a604a..324dd0424 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/serviceswidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/serviceswidget.cpp @@ -35,12 +35,7 @@ void ServicesWidget::reload() Service *svc = Service::serviceAt(i); auto *sw = new ServiceWidget(); - sw->setStatus(svc->status()); - connect(svc, &Service::statusChanged, sw, &ServiceWidget::setStatus); - sw->setServiceId(svc->serviceId(), svc->serviceDisplayName()); - sw->setMessage(svc->statusMessage()); - connect(svc, &Service::statusMessageChanged, sw, &ServiceWidget::setMessage); - connect(sw, &ServiceWidget::setRunningRequest, svc, &Service::setRunning); + sw->setService(svc); ly2->addWidget(sw); } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.cpp index dd4bf8233..3069eb848 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.cpp @@ -45,10 +45,15 @@ void ServiceWidget::setStatus(Service::Status st) } } -void ServiceWidget::setServiceId(const QString &id, const QString &display_name) +void ServiceWidget::setService(Service *service) { - m_serviceId = id; - ui->lblServiceName->setText(display_name.isEmpty()? id: display_name); + m_serviceId = service->serviceId(); + ui->lblServiceName->setText(service->serviceDisplayName()); + setStatus(service->status()); + connect(service, &Service::statusChanged, this, &ServiceWidget::setStatus); + setMessage(service->statusMessage()); + connect(service, &Service::statusMessageChanged, this, &ServiceWidget::setMessage); + connect(this, &ServiceWidget::setRunningRequest, service, &Service::setRunning); } QString ServiceWidget::serviceId() const diff --git a/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.h b/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.h index f659cafde..4d589d2fe 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.h @@ -21,7 +21,7 @@ class ServiceWidget : public QWidget ~ServiceWidget(); void setStatus(Service::Status st); - void setServiceId(const QString &id, const QString &display_name); + void setService(Service *service); QString serviceId() const; void setMessage(const QString &m); From 848ea9d8569afe759d558e5533e0eff5d84160e2 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sat, 8 Nov 2025 11:47:27 +0100 Subject: [PATCH 09/29] Rename QxClientService to QxEventService --- quickevent/app/quickevent/CMakeLists.txt | 7 +- .../plugins/Event/src/eventplugin.cpp | 4 +- ...qxclientservice.cpp => qxeventservice.cpp} | 84 +++++++++---------- .../{qxclientservice.h => qxeventservice.h} | 10 +-- ...icewidget.cpp => qxeventservicewidget.cpp} | 46 +++++----- ...servicewidget.h => qxeventservicewidget.h} | 14 ++-- ...rvicewidget.ui => qxeventservicewidget.ui} | 4 +- .../services/qx/qxlateregistrationswidget.cpp | 6 +- .../services/qx/qxlateregistrationswidget.h | 4 +- .../Event/src/services/qx/runchangedialog.cpp | 8 +- .../Event/src/services/qx/runchangedialog.h | 4 +- 11 files changed, 94 insertions(+), 97 deletions(-) rename quickevent/app/quickevent/plugins/Event/src/services/qx/{qxclientservice.cpp => qxeventservice.cpp} (87%) rename quickevent/app/quickevent/plugins/Event/src/services/qx/{qxclientservice.h => qxeventservice.h} (91%) rename quickevent/app/quickevent/plugins/Event/src/services/qx/{qxclientservicewidget.cpp => qxeventservicewidget.cpp} (76%) rename quickevent/app/quickevent/plugins/Event/src/services/qx/{qxclientservicewidget.h => qxeventservicewidget.h} (65%) rename quickevent/app/quickevent/plugins/Event/src/services/qx/{qxclientservicewidget.ui => qxeventservicewidget.ui} (97%) diff --git a/quickevent/app/quickevent/CMakeLists.txt b/quickevent/app/quickevent/CMakeLists.txt index f094728f1..3f9d47af1 100644 --- a/quickevent/app/quickevent/CMakeLists.txt +++ b/quickevent/app/quickevent/CMakeLists.txt @@ -89,11 +89,8 @@ add_executable(quickevent plugins/Event/src/services/serviceswidget.cpp plugins/Event/src/services/servicewidget.cpp plugins/Event/src/services/servicewidget.ui - plugins/Event/src/services/qx/qxclientservice.cpp - plugins/Event/src/services/qx/qxclientservice.h - plugins/Event/src/services/qx/qxclientservicewidget.cpp - plugins/Event/src/services/qx/qxclientservicewidget.h - plugins/Event/src/services/qx/qxclientservicewidget.ui + plugins/Event/src/services/qx/qxeventservice.cpp plugins/Event/src/services/qx/qxeventservice.h plugins/Event/src/services/qx/qxeventservicewidget.cpp plugins/Event/src/services/qx/qxeventservicewidget.h + plugins/Event/src/services/qx/qxeventservicewidget.ui plugins/Event/src/services/qx/qxlateregistrationswidget.h plugins/Event/src/services/qx/qxlateregistrationswidget.cpp plugins/Event/src/services/qx/qxlateregistrationswidget.ui diff --git a/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp b/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp index 796c38221..6f7accfcc 100644 --- a/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/eventplugin.cpp @@ -11,7 +11,7 @@ #include "services/serviceswidget.h" #include "services/emmaclient.h" -#include "services/qx/qxclientservice.h" +#include "services/qx/qxeventservice.h" #include #include @@ -380,7 +380,7 @@ void EventPlugin::onInstalled() auto *emma_client = new services::EmmaClient(this); services::Service::addService(emma_client); - auto shvapi_client = new services::qx::QxClientService(this); + auto shvapi_client = new services::qx::QxEventService(this); services::Service::addService(shvapi_client); { diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp similarity index 87% rename from quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.cpp rename to quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index 7a9acb8fd..6b673328e 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -1,5 +1,5 @@ -#include "qxclientservice.h" -#include "qxclientservicewidget.h" +#include "qxeventservice.h" +#include "qxeventservicewidget.h" #include "../../eventplugin.h" #include "../../../../Runs/src/runsplugin.h" @@ -56,24 +56,24 @@ namespace Event::services::qx { //=============================================== // QxClientService //=============================================== -QxClientService::QxClientService(QObject *parent) - : Super(QxClientService::serviceId(), parent) +QxEventService::QxEventService(QObject *parent) + : Super(QxEventService::serviceId(), parent) { auto *event_plugin = getPlugin(); - connect(event_plugin, &Event::EventPlugin::dbEventNotify, this, &QxClientService::onDbEventNotify, Qt::QueuedConnection); + connect(event_plugin, &Event::EventPlugin::dbEventNotify, this, &QxEventService::onDbEventNotify, Qt::QueuedConnection); } -QString QxClientService::serviceDisplayName() const +QString QxEventService::serviceDisplayName() const { return tr("QE Exchange"); } -QString QxClientService::serviceId() +QString QxEventService::serviceId() { return QStringLiteral("qx"); } -void QxClientService::run() { +void QxEventService::run() { using namespace shv::iotqt::rpc; auto ss = settings(); @@ -82,10 +82,10 @@ void QxClientService::run() { m_rpcConnection = new ClientConnection(this); m_rpcConnection->setConnectionString(ss.exchangeServerUrl()); - connect(m_rpcConnection, &ClientConnection::brokerConnectedChanged, this, &QxClientService::onBrokerConnectedChanged); - connect(m_rpcConnection, &ClientConnection::socketError, this, &QxClientService::onBrokerSocketError); - connect(m_rpcConnection, &ClientConnection::brokerLoginError, this, &QxClientService::onBrokerLoginError); - connect(m_rpcConnection, &ClientConnection::rpcMessageReceived, this, &QxClientService::onRpcMessageReceived); + connect(m_rpcConnection, &ClientConnection::brokerConnectedChanged, this, &QxEventService::onBrokerConnectedChanged); + connect(m_rpcConnection, &ClientConnection::socketError, this, &QxEventService::onBrokerSocketError); + connect(m_rpcConnection, &ClientConnection::brokerLoginError, this, &QxEventService::onBrokerLoginError); + connect(m_rpcConnection, &ClientConnection::rpcMessageReceived, this, &QxEventService::onRpcMessageReceived); m_rpcConnection->open(); @@ -111,7 +111,7 @@ void QxClientService::run() { // }); } -void QxClientService::stop() +void QxEventService::stop() { disconnectSSE(); if (m_pollChangesTimer) { @@ -120,13 +120,13 @@ void QxClientService::stop() Super::stop(); } -qf::gui::framework::DialogWidget *QxClientService::createDetailWidget() +qf::gui::framework::DialogWidget *QxEventService::createDetailWidget() { - auto *w = new QxClientServiceWidget(); + auto *w = new QxEventServiceWidget(); return w; } -void QxClientService::loadSettings() +void QxEventService::loadSettings() { Super::loadSettings(); auto ss = settings(); @@ -136,7 +136,7 @@ void QxClientService::loadSettings() m_settings = ss; } -void QxClientService::onDbEventNotify(const QString &domain, int connection_id, const QVariant &data) +void QxEventService::onDbEventNotify(const QString &domain, int connection_id, const QVariant &data) { Q_UNUSED(connection_id) Q_UNUSED(data) @@ -183,7 +183,7 @@ void QxClientService::onDbEventNotify(const QString &domain, int connection_id, } } -QNetworkAccessManager *QxClientService::networkManager() +QNetworkAccessManager *QxEventService::networkManager() { if (!m_networkManager) { m_networkManager = new QNetworkAccessManager(this); @@ -191,7 +191,7 @@ QNetworkAccessManager *QxClientService::networkManager() return m_networkManager; } -QNetworkReply *QxClientService::getRemoteEventInfo(const QString &qxhttp_host, const QString &api_token) +QNetworkReply *QxEventService::getRemoteEventInfo(const QString &qxhttp_host, const QString &api_token) { auto *nm = networkManager(); QNetworkRequest request; @@ -202,7 +202,7 @@ QNetworkReply *QxClientService::getRemoteEventInfo(const QString &qxhttp_host, c return nm->get(request); } -QNetworkReply *QxClientService::postEventInfo(const QString &qxhttp_host, const QString &api_token) +QNetworkReply *QxEventService::postEventInfo(const QString &qxhttp_host, const QString &api_token) { auto *nm = networkManager(); QNetworkRequest request; @@ -218,7 +218,7 @@ QNetworkReply *QxClientService::postEventInfo(const QString &qxhttp_host, const return nm->post(request, data); } -void QxClientService::postStartListIofXml3(QObject *context, std::function call_back) +void QxEventService::postStartListIofXml3(QObject *context, std::function call_back) { auto *ep = getPlugin(); int current_stage = ep->currentStageId(); @@ -229,7 +229,7 @@ void QxClientService::postStartListIofXml3(QObject *context, std::function call_back) +void QxEventService::postRuns(QObject *context, std::function call_back) { auto *ep = getPlugin(); int current_stage = ep->currentStageId(); @@ -241,7 +241,7 @@ void QxClientService::postRuns(QObject *context, std::function c } } -void QxClientService::getHttpJson(const QString &path, const QUrlQuery &query, QObject *context, const std::function &call_back) +void QxEventService::getHttpJson(const QString &path, const QUrlQuery &query, QObject *context, const std::function &call_back) { auto url = exchangeServerUrl(); url.setPath(path); @@ -270,7 +270,7 @@ void QxClientService::getHttpJson(const QString &path, const QUrlQuery &query, Q }); } -QNetworkReply* QxClientService::getQxChangesReply(int from_id) +QNetworkReply* QxEventService::getQxChangesReply(int from_id) { auto url = exchangeServerUrl(); @@ -282,7 +282,7 @@ QNetworkReply* QxClientService::getQxChangesReply(int from_id) return networkManager()->get(request); } -int QxClientService::eventId() const +int QxEventService::eventId() const { if (m_eventId == 0) { throw qf::core::Exception(tr("Event ID is not loaded, service is not probably running.")); @@ -290,7 +290,7 @@ int QxClientService::eventId() const return m_eventId; } -QByteArray QxClientService::apiToken() const +QByteArray QxEventService::apiToken() const { // API token must not be cached to enable service point // always to current stage event on qxhttpd @@ -299,13 +299,13 @@ QByteArray QxClientService::apiToken() const return event_plugin->stageData(current_stage).qxApiToken().toUtf8(); } -QUrl QxClientService::exchangeServerUrl() const +QUrl QxEventService::exchangeServerUrl() const { auto ss = settings(); return QUrl(ss.exchangeServerUrl()); } -void QxClientService::postFileCompressed(std::optional path, std::optional name, QByteArray data, QObject *context , std::function call_back) +void QxEventService::postFileCompressed(std::optional path, std::optional name, QByteArray data, QObject *context , std::function call_back) { auto url = exchangeServerUrl(); @@ -333,7 +333,7 @@ void QxClientService::postFileCompressed(std::optional path, std::optio }); } -void QxClientService::uploadSpecFile(SpecFile file, QByteArray data, QObject *context, const std::function &call_back) +void QxEventService::uploadSpecFile(SpecFile file, QByteArray data, QObject *context, const std::function &call_back) { switch (file) { case SpecFile::StartListIofXml3: @@ -345,7 +345,7 @@ void QxClientService::uploadSpecFile(SpecFile file, QByteArray data, QObject *co } } -QByteArray QxClientService::zlibCompress(QByteArray data) +QByteArray QxEventService::zlibCompress(QByteArray data) { QByteArray compressedData = qCompress(data); // strip the 4-byte length put on by qCompress @@ -354,7 +354,7 @@ QByteArray QxClientService::zlibCompress(QByteArray data) return compressedData; } -void QxClientService::httpPostJson(const QString &path, const QString &query, QVariantMap json, QObject *context, const std::function &call_back) +void QxEventService::httpPostJson(const QString &path, const QString &query, QVariantMap json, QObject *context, const std::function &call_back) { if (!isRunning()) { return; @@ -394,7 +394,7 @@ void QxClientService::httpPostJson(const QString &path, const QString &query, QV } } -void QxClientService::connectToSSE(int event_id) +void QxEventService::connectToSSE(int event_id) { Q_UNUSED(event_id); // auto url = exchangeServerUrl(); @@ -417,7 +417,7 @@ void QxClientService::connectToSSE(int event_id) // }); } -void QxClientService::disconnectSSE() +void QxEventService::disconnectSSE() { if (m_replySSE) { qfInfo() << "Disconnecting SSE:" << m_replySSE; @@ -426,7 +426,7 @@ void QxClientService::disconnectSSE() } } -void QxClientService::pollQxChanges() +void QxEventService::pollQxChanges() { auto event_plugin = getPlugin(); if(!getPlugin()->isEventOpen()) { @@ -501,7 +501,7 @@ void QxClientService::pollQxChanges() } } -EventInfo QxClientService::eventInfo() const +EventInfo QxEventService::eventInfo() const { auto *event_plugin = getPlugin(); auto *event_config = event_plugin->eventConfig(); @@ -582,12 +582,12 @@ EventInfo QxClientService::eventInfo() const // return csv; //} //} -int QxClientService::currentConnectionId() +int QxEventService::currentConnectionId() { return qf::core::sql::Connection::forName().connectionId(); } -void QxClientService::onBrokerConnectedChanged(bool is_connected) +void QxEventService::onBrokerConnectedChanged(bool is_connected) { if(is_connected) { setStatus(Status::Running); @@ -601,17 +601,17 @@ void QxClientService::onBrokerConnectedChanged(bool is_connected) } -void QxClientService::onBrokerSocketError(const QString &err) +void QxEventService::onBrokerSocketError(const QString &err) { setStatusMessage(tr("Broker socket error: %1").arg(err)); } -void QxClientService::onBrokerLoginError(const shv::chainpack::RpcError &err) +void QxEventService::onBrokerLoginError(const shv::chainpack::RpcError &err) { setStatusMessage(tr("Broker login error: %1").arg(err.toString())); } -void QxClientService::onRpcMessageReceived(const shv::chainpack::RpcMessage &msg) +void QxEventService::onRpcMessageReceived(const shv::chainpack::RpcMessage &msg) { // shvLogFuncFrame() << msg.toCpon(); if(msg.isRequest()) { @@ -631,7 +631,7 @@ void QxClientService::onRpcMessageReceived(const shv::chainpack::RpcMessage &msg } } -void QxClientService::subscribeChanges() +void QxEventService::subscribeChanges() { Q_ASSERT(m_rpcConnection); QString shv_path = "test"; @@ -653,7 +653,7 @@ void QxClientService::subscribeChanges() rpc_call->start(); } -void QxClientService::testRpcCall() const +void QxEventService::testRpcCall() const { Q_ASSERT(m_rpcConnection); auto *rpc_call = RpcCall::create(m_rpcConnection) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h similarity index 91% rename from quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.h rename to quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h index 7e1f046be..1ab8d14b7 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservice.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h @@ -13,13 +13,13 @@ namespace shv::chainpack { class RpcMessage; class RpcError; } namespace Event::services::qx { -class QxClientServiceSettings : public ServiceSettings +class QxEventServiceSettings : public ServiceSettings { using Super = ServiceSettings; QF_VARIANTMAP_FIELD2(QString, e, setE, xchangeServerUrl, "http://localhost:8000") public: - QxClientServiceSettings(const QVariantMap &o = QVariantMap()) : Super(o) {} + QxEventServiceSettings(const QVariantMap &o = QVariantMap()) : Super(o) {} }; class EventInfo : public QVariantMap @@ -38,7 +38,7 @@ class EventInfo : public QVariantMap EventInfo(const QVariantMap &data = QVariantMap()) : QVariantMap(data) {} }; -class QxClientService : public Service +class QxEventService : public Service { Q_OBJECT @@ -46,14 +46,14 @@ class QxClientService : public Service public: static constexpr auto QX_API_TOKEN = "qx-api-token"; public: - QxClientService(QObject *parent); + QxEventService(QObject *parent); static QString serviceId(); QString serviceDisplayName() const override; void run() override; void stop() override; - QxClientServiceSettings settings() const {return QxClientServiceSettings(m_settings);} + QxEventServiceSettings settings() const {return QxEventServiceSettings(m_settings);} void onDbEventNotify(const QString &domain, int connection_id, const QVariant &data); QNetworkAccessManager* networkManager(); diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp similarity index 76% rename from quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.cpp rename to quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp index e9a04902e..ede33ffb4 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp @@ -1,6 +1,6 @@ -#include "qxclientservicewidget.h" -#include "ui_qxclientservicewidget.h" -#include "qxclientservice.h" +#include "qxeventservicewidget.h" +#include "ui_qxeventservicewidget.h" +#include "qxeventservice.h" #include @@ -19,14 +19,14 @@ using qf::gui::framework::getPlugin; namespace Event::services::qx { -QxClientServiceWidget::QxClientServiceWidget(QWidget *parent) +QxEventServiceWidget::QxEventServiceWidget(QWidget *parent) : Super(parent) - , ui(new Ui::QxClientServiceWidget) + , ui(new Ui::QxEventServiceWidget) { setPersistentSettingsId("QxClientServiceWidget"); ui->setupUi(this); - connect(ui->edServerUrl, &QLineEdit::textChanged, this, &QxClientServiceWidget::updateOCheckListPostUrl); - connect(ui->edApiToken, &QLineEdit::textChanged, this, &QxClientServiceWidget::updateOCheckListPostUrl); + connect(ui->edServerUrl, &QLineEdit::textChanged, this, &QxEventServiceWidget::updateOCheckListPostUrl); + connect(ui->edApiToken, &QLineEdit::textChanged, this, &QxEventServiceWidget::updateOCheckListPostUrl); setMessage(""); @@ -38,18 +38,18 @@ QxClientServiceWidget::QxClientServiceWidget(QWidget *parent) ui->edServerUrl->setText(settings.exchangeServerUrl()); ui->edApiToken->setText(svc->apiToken()); ui->edCurrentStage->setValue(current_stage); - connect(ui->btTestConnection, &QAbstractButton::clicked, this, &QxClientServiceWidget::testConnection); - connect(ui->btExportEventInfo, &QAbstractButton::clicked, this, &QxClientServiceWidget::exportEventInfo); - connect(ui->btExportStartList, &QAbstractButton::clicked, this, &QxClientServiceWidget::exportStartList); - connect(ui->btExportRuns, &QAbstractButton::clicked, this, &QxClientServiceWidget::exportRuns); + connect(ui->btTestConnection, &QAbstractButton::clicked, this, &QxEventServiceWidget::testConnection); + connect(ui->btExportEventInfo, &QAbstractButton::clicked, this, &QxEventServiceWidget::exportEventInfo); + connect(ui->btExportStartList, &QAbstractButton::clicked, this, &QxEventServiceWidget::exportStartList); + connect(ui->btExportRuns, &QAbstractButton::clicked, this, &QxEventServiceWidget::exportRuns); } -QxClientServiceWidget::~QxClientServiceWidget() +QxEventServiceWidget::~QxEventServiceWidget() { delete ui; } -void QxClientServiceWidget::setMessage(const QString &msg, MessageType msg_type) +void QxEventServiceWidget::setMessage(const QString &msg, MessageType msg_type) { if (msg.isEmpty()) { ui->lblStatus->setStyleSheet({}); @@ -70,7 +70,7 @@ void QxClientServiceWidget::setMessage(const QString &msg, MessageType msg_type) ui->lblStatus->setText(msg); } -bool QxClientServiceWidget::acceptDialogDone(int result) +bool QxEventServiceWidget::acceptDialogDone(int result) { if(result == QDialog::Accepted) { if(!saveSettings()) { @@ -80,14 +80,14 @@ bool QxClientServiceWidget::acceptDialogDone(int result) return true; } -QxClientService *QxClientServiceWidget::service() +QxEventService *QxEventServiceWidget::service() { - auto *svc = qobject_cast(Service::serviceByName(QxClientService::serviceId())); - QF_ASSERT(svc, QxClientService::serviceId() + " doesn't exist", return nullptr); + auto *svc = qobject_cast(Service::serviceByName(QxEventService::serviceId())); + QF_ASSERT(svc, QxEventService::serviceId() + " doesn't exist", return nullptr); return svc; } -bool QxClientServiceWidget::saveSettings() +bool QxEventServiceWidget::saveSettings() { auto *svc = service(); if(svc) { @@ -104,14 +104,14 @@ bool QxClientServiceWidget::saveSettings() return true; } -void QxClientServiceWidget::updateOCheckListPostUrl() +void QxEventServiceWidget::updateOCheckListPostUrl() { auto url = QStringLiteral("%1/api/event/current/oc").arg(ui->edServerUrl->text()); ui->edOChecklistUrl->setText(url); ui->edOChecklistUrlHeader->setText(QStringLiteral("qx-api-token=%1").arg(ui->edApiToken->text())); } -void QxClientServiceWidget::testConnection() +void QxEventServiceWidget::testConnection() { auto *svc = service(); Q_ASSERT(svc); @@ -131,7 +131,7 @@ void QxClientServiceWidget::testConnection() }); } -void QxClientServiceWidget::exportEventInfo() +void QxEventServiceWidget::exportEventInfo() { auto *svc = service(); Q_ASSERT(svc); @@ -151,7 +151,7 @@ void QxClientServiceWidget::exportEventInfo() }); } -void QxClientServiceWidget::exportStartList() +void QxEventServiceWidget::exportStartList() { auto *svc = service(); Q_ASSERT(svc); @@ -167,7 +167,7 @@ void QxClientServiceWidget::exportStartList() }); } -void QxClientServiceWidget::exportRuns() +void QxEventServiceWidget::exportRuns() { auto *svc = service(); Q_ASSERT(svc); diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.h similarity index 65% rename from quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.h rename to quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.h index f1b108a30..19454ad86 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.h @@ -5,23 +5,23 @@ namespace Event::services::qx { namespace Ui { -class QxClientServiceWidget; +class QxEventServiceWidget; } -class QxClientService; +class QxEventService; -class QxClientServiceWidget : public qf::gui::framework::DialogWidget +class QxEventServiceWidget : public qf::gui::framework::DialogWidget { Q_OBJECT using Super = qf::gui::framework::DialogWidget; public: - explicit QxClientServiceWidget(QWidget *parent = nullptr); - ~QxClientServiceWidget() override; + explicit QxEventServiceWidget(QWidget *parent = nullptr); + ~QxEventServiceWidget() override; private: enum class MessageType { Ok, Error, Progress }; void setMessage(const QString &msg = {}, MessageType msg_type = MessageType::Ok); - QxClientService* service(); + QxEventService* service(); bool saveSettings(); void updateOCheckListPostUrl(); void testConnection(); @@ -29,7 +29,7 @@ class QxClientServiceWidget : public qf::gui::framework::DialogWidget void exportStartList(); void exportRuns(); private: - Ui::QxClientServiceWidget *ui; + Ui::QxEventServiceWidget *ui; bool acceptDialogDone(int result) override; }; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.ui b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.ui similarity index 97% rename from quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.ui rename to quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.ui index d8824707e..261a65af9 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxclientservicewidget.ui +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.ui @@ -1,7 +1,7 @@ - Event::services::qx::QxClientServiceWidget - + Event::services::qx::QxEventServiceWidget + 0 diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.cpp index f0747e77a..083af5d69 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.cpp @@ -1,7 +1,7 @@ #include "qxlateregistrationswidget.h" #include "ui_qxlateregistrationswidget.h" -#include "qxclientservice.h" +#include "qxeventservice.h" #include "runchangedialog.h" #include "runchange.h" @@ -152,9 +152,9 @@ void QxLateRegistrationsWidget::onVisibleChanged(bool is_visible) } } -QxClientService *QxLateRegistrationsWidget::service() +QxEventService *QxLateRegistrationsWidget::service() { - auto *svc = qobject_cast(Event::services::Service::serviceByName(QxClientService::serviceId())); + auto *svc = qobject_cast(Event::services::Service::serviceByName(QxEventService::serviceId())); Q_ASSERT(svc); return svc; } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.h index 6c972c739..ea906b649 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxlateregistrationswidget.h @@ -10,7 +10,7 @@ namespace Ui { class QxLateRegistrationsWidget; } -class QxClientService; +class QxEventService; class QxLateRegistrationsWidget : public QWidget { @@ -23,7 +23,7 @@ class QxLateRegistrationsWidget : public QWidget void onDbEventNotify(const QString &domain, int connection_id, const QVariant &payload); void onVisibleChanged(bool is_visible); private: - QxClientService* service(); + QxEventService* service(); void reload(); void addQxChangeRow(int sql_id); diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp index c44c38a94..789cb44e0 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp @@ -1,7 +1,7 @@ #include "runchangedialog.h" #include "ui_runchangedialog.h" -#include "qxclientservice.h" +#include "qxeventservice.h" #include "runchange.h" #include @@ -72,9 +72,9 @@ RunChangeDialog::~RunChangeDialog() delete ui; } -QxClientService *RunChangeDialog::service() +QxEventService *RunChangeDialog::service() { - auto *svc = qobject_cast(Service::serviceByName(QxClientService::serviceId())); + auto *svc = qobject_cast(Service::serviceByName(QxEventService::serviceId())); Q_ASSERT(svc); return svc; } @@ -220,7 +220,7 @@ void RunChangeDialog::resolveChanges(bool is_accepted) url.setQuery(query); request.setUrl(url); - request.setRawHeader(QxClientService::QX_API_TOKEN, svc->apiToken()); + request.setRawHeader(QxEventService::QX_API_TOKEN, svc->apiToken()); auto *reply = nm->get(request); connect(reply, &QNetworkReply::finished, this, [this, reply]() { if (reply->error() == QNetworkReply::NetworkError::NoError) { diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.h index d704a1d48..15a9bf147 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.h @@ -14,7 +14,7 @@ class RunChangeDialog; } struct RunChange; -class QxClientService; +class QxEventService; class RunChangeDialog : public QDialog { @@ -25,7 +25,7 @@ class RunChangeDialog : public QDialog ~RunChangeDialog() override; private: - QxClientService* service(); + QxEventService* service(); void setMessage(const QString &msg, bool error); void loadOrigValues(); From 844d9e4c826abf3f013bfed189a77dc9e3937cc3 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 9 Nov 2025 18:34:22 +0100 Subject: [PATCH 10/29] Fix DesktopUtils::moveRectToVisibleDesktopScreen --- libqf/libqfgui/src/framework/dialogwidget.cpp | 15 ++++-------- libqf/libqfgui/src/framework/dialogwidget.h | 2 +- .../src/framework/ipersistentsettings.cpp | 23 ++++++++----------- 3 files changed, 15 insertions(+), 25 deletions(-) diff --git a/libqf/libqfgui/src/framework/dialogwidget.cpp b/libqf/libqfgui/src/framework/dialogwidget.cpp index f46cd8f23..8d5769997 100644 --- a/libqf/libqfgui/src/framework/dialogwidget.cpp +++ b/libqf/libqfgui/src/framework/dialogwidget.cpp @@ -9,13 +9,13 @@ using namespace qf::gui::framework; -DialogWidget::DialogWidget(QWidget *parent) : - Super(parent), IPersistentSettings(this) +DialogWidget::DialogWidget(QWidget *parent) + : Super(parent) + , IPersistentSettings(this) { } -DialogWidget::~DialogWidget() -= default; +DialogWidget::~DialogWidget() = default; bool DialogWidget::acceptDialogDone(int result) { @@ -23,12 +23,7 @@ bool DialogWidget::acceptDialogDone(int result) Q_UNUSED(result); return true; } -/* -QVariant DialogWidget::acceptDialogDone_qml(const QVariant &result) -{ - return acceptDialogDone(result.toBool()); -} -*/ + void DialogWidget::settleDownInDialog_qml(const QVariant &dlg) { auto *o = dlg.value(); diff --git a/libqf/libqfgui/src/framework/dialogwidget.h b/libqf/libqfgui/src/framework/dialogwidget.h index 13893c8a0..611be6b95 100644 --- a/libqf/libqfgui/src/framework/dialogwidget.h +++ b/libqf/libqfgui/src/framework/dialogwidget.h @@ -32,7 +32,7 @@ class QFGUI_DECL_EXPORT DialogWidget : public Frame, public IPersistentSettings typedef Frame Super; public: explicit DialogWidget(QWidget *parent = nullptr); - ~DialogWidget() Q_DECL_OVERRIDE; + ~DialogWidget() override; QF_PROPERTY_IMPL(QString, t, T, itle) QF_PROPERTY_IMPL(QString, i, I, conSource) diff --git a/libqf/libqfgui/src/framework/ipersistentsettings.cpp b/libqf/libqfgui/src/framework/ipersistentsettings.cpp index c639c374c..7fff48174 100644 --- a/libqf/libqfgui/src/framework/ipersistentsettings.cpp +++ b/libqf/libqfgui/src/framework/ipersistentsettings.cpp @@ -48,7 +48,7 @@ static void callMethodRecursively(QObject *obj, const char *method_name) QMetaMethod mm = obj->metaObject()->method(ix); mm.invoke(obj); } - Q_FOREACH(auto *o, obj->children()) { + for (auto *o : obj->children()) { //static int level = 0; //level++; //QString indent = QString(level, ' '); @@ -103,25 +103,20 @@ QString IPersistentSettings::rawPersistentSettingsPath() QString persistent_id = persistentSettingsId(); QStringList raw_path; if(!persistent_id.isEmpty()) { - for(QObject *obj=m_controlledObject->parent(); obj!=nullptr; obj=obj->parent()) { + for(QObject* obj = m_controlledObject->parent(); obj != nullptr; obj = obj->parent()) { auto *ps = dynamic_cast(obj); if(ps) { QString pp = ps->rawPersistentSettingsPath(); - if(!pp.isEmpty()) + if(!pp.isEmpty()) { raw_path.insert(0, pp); - //qfWarning() << "reading property 'persistentSettingsId' error" << obj << "casted to IPersistentSettings" << ps; - //qfWarning() << "\tcorrect value should be:" << parent_id; + } break; } - QVariant vid = obj->property("persistentSettingsId"); - QString parent_id = vid.toString(); - if(!parent_id.isEmpty()) { - raw_path.insert(0, parent_id); - } - - // reading property using QQmlProperty is crashing my app Qt 5.3.1 commit a83826dad0f62d7a96f5a6093240e4c8f7f2e06e - //QQmlProperty p(obj, "persistentSettingsId"); - //QVariant v2 = p.read(); + QVariant vid = obj->property("persistentSettingsId"); + QString parent_id = vid.toString(); + if(!parent_id.isEmpty()) { + raw_path.insert(0, parent_id); + } } raw_path.append(persistent_id); } From aac947aef8a934724dddd0d7de8520a493cb8227 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 9 Nov 2025 18:34:34 +0100 Subject: [PATCH 11/29] Update libshv --- 3rdparty/libshv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/3rdparty/libshv b/3rdparty/libshv index 3cbe496ea..40f0b3cf2 160000 --- a/3rdparty/libshv +++ b/3rdparty/libshv @@ -1 +1 @@ -Subproject commit 3cbe496ea4d2c48695994850a09c2cc794c3f80b +Subproject commit 40f0b3cf213ab799fb17bf6a31ce527a8851ee30 From 833622eacf10352823884da84f0b1115bd37c881 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 9 Nov 2025 18:35:51 +0100 Subject: [PATCH 12/29] Add QX event SHV nodes --- .../src/reportoptionsdialog.h | 8 +- quickevent/app/quickevent/CMakeLists.txt | 17 +- .../plugins/Event/src/services/qx/nodes.cpp | 300 ++++++++++++++++++ .../plugins/Event/src/services/qx/nodes.h | 103 ++++++ .../Event/src/services/qx/qxeventservice.cpp | 74 +++-- .../Event/src/services/qx/qxeventservice.h | 14 +- .../src/services/qx/qxeventservicewidget.cpp | 6 +- .../src/services/qx/qxeventservicewidget.ui | 2 +- .../plugins/Event/src/services/qx/qxnode.cpp | 36 +++ .../plugins/Event/src/services/qx/qxnode.h | 23 ++ .../Event/src/services/qx/runchangedialog.cpp | 2 +- .../Event/src/services/qx/sqlapinode.cpp | 119 +++++++ .../Event/src/services/qx/sqlapinode.h | 27 ++ 13 files changed, 682 insertions(+), 49 deletions(-) create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.cpp create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.h create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h diff --git a/libquickevent/libquickeventgui/src/reportoptionsdialog.h b/libquickevent/libquickeventgui/src/reportoptionsdialog.h index e4b22c6f9..bdccb558b 100644 --- a/libquickevent/libquickeventgui/src/reportoptionsdialog.h +++ b/libquickevent/libquickeventgui/src/reportoptionsdialog.h @@ -86,13 +86,13 @@ class QUICKEVENTGUI_DECL_EXPORT ReportOptionsDialog : public QDialog, public qf: explicit ReportOptionsDialog(QWidget *parent = nullptr); ~ReportOptionsDialog() override; - int exec() Q_DECL_OVERRIDE; + int exec() override; void setStartListPrintVacantsVisible(bool b); void setStartListForRelays(); - QString persistentSettingsPath() Q_DECL_OVERRIDE; - bool setPersistentSettingsId(const QString &id) Q_DECL_OVERRIDE; + QString persistentSettingsPath() override; + bool setPersistentSettingsId(const QString &id) override; Q_SIGNAL void persistentSettingsIdChanged(const QString &id); void setOptions(const Options &options); @@ -127,7 +127,7 @@ class QUICKEVENTGUI_DECL_EXPORT ReportOptionsDialog : public QDialog, public qf: static QString sqlWhereExpression(const Options &opts, const int stage_id); static QString getClassesForStartNumber(const int number, const int stage_id); protected: - //void showEvent(QShowEvent *event) Q_DECL_OVERRIDE; + //void showEvent(QShowEvent *event) override; private: Ui::ReportOptionsDialog *ui; }; diff --git a/quickevent/app/quickevent/CMakeLists.txt b/quickevent/app/quickevent/CMakeLists.txt index 3f9d47af1..18208eab7 100644 --- a/quickevent/app/quickevent/CMakeLists.txt +++ b/quickevent/app/quickevent/CMakeLists.txt @@ -1,3 +1,5 @@ +find_package(Qt6 REQUIRED COMPONENTS Core) + add_executable(quickevent plugins/CardReader/src/cardchecker.cpp plugins/CardReader/src/cardcheckerclassiccpp.cpp @@ -89,11 +91,13 @@ add_executable(quickevent plugins/Event/src/services/serviceswidget.cpp plugins/Event/src/services/servicewidget.cpp plugins/Event/src/services/servicewidget.ui - plugins/Event/src/services/qx/qxeventservice.cpp plugins/Event/src/services/qx/qxeventservice.h plugins/Event/src/services/qx/qxeventservicewidget.cpp plugins/Event/src/services/qx/qxeventservicewidget.h - plugins/Event/src/services/qx/qxeventservicewidget.ui - plugins/Event/src/services/qx/qxlateregistrationswidget.h - plugins/Event/src/services/qx/qxlateregistrationswidget.cpp - plugins/Event/src/services/qx/qxlateregistrationswidget.ui + + plugins/Event/src/services/qx/qxnode.cpp + plugins/Event/src/services/qx/sqlapinode.cpp + plugins/Event/src/services/qx/nodes.cpp + plugins/Event/src/services/qx/qxeventservice.cpp plugins/Event/src/services/qx/qxeventservice.h + plugins/Event/src/services/qx/qxeventservicewidget.cpp plugins/Event/src/services/qx/qxeventservicewidget.h plugins/Event/src/services/qx/qxeventservicewidget.ui + plugins/Event/src/services/qx/qxlateregistrationswidget.h plugins/Event/src/services/qx/qxlateregistrationswidget.cpp plugins/Event/src/services/qx/qxlateregistrationswidget.ui plugins/Event/src/services/qx/runchangedialog.h plugins/Event/src/services/qx/runchangedialog.cpp plugins/Event/src/services/qx/runchangedialog.ui plugins/Event/src/services/qx/runchange.h plugins/Event/src/services/qx/runchange.cpp @@ -269,7 +273,8 @@ target_include_directories(quickevent PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAK target_link_libraries(quickevent PUBLIC libquickeventcore libquickeventgui libqfgui libsiut) if (QF_WITH_LIBSHV) target_link_libraries(quickevent PUBLIC libshviotqt) - target_compile_definitions(quickevent PRIVATE QF_WITH_LIBSHV) +target_link_libraries(quickevent PRIVATE Qt6::Core) +target_compile_definitions(quickevent PRIVATE QF_WITH_LIBSHV) endif() install(TARGETS quickevent) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp new file mode 100644 index 000000000..07c57d53d --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp @@ -0,0 +1,300 @@ +#include "nodes.h" + +#include "sqlapinode.h" +#include "../../eventplugin.h" +#include "../../../../Runs/src/runsplugin.h" + +#include +#include +#include +#include + +#include +#include +#include + +#include + +using namespace qf::core::sql; +using namespace shv::chainpack; +using qf::gui::framework::getPlugin; +using Event::EventPlugin; +using Runs::RunsPlugin; + +namespace Event::services::qx { + +//========================================================= +// DotAppNode +//========================================================= +namespace { +auto METH_NAME = "name"; +} +const std::vector &DotAppNode::metaMethods() +{ + static std::vector meta_methods { + methods::DIR, + methods::LS, + {Rpc::METH_PING, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Browse}, + {METH_NAME, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Browse}, + }; + return meta_methods; +} + +RpcValue DotAppNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) +{ + qfLogFuncFrame() << shv_path.join('/') << method; + //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); + if(shv_path.empty()) { + if(method == Rpc::METH_PING) { + return nullptr; + } + if(method == METH_NAME) { + return "QuickEvent"; + } + } + return Super::callMethod(shv_path, method, params, user_id); +} + +//========================================================= +// EventNode +//========================================================= +static const auto METH_CURRENT_STAGE = "currentStage"; +static const auto METH_EVENT_CONFIG = "eventConfig"; + +EventNode::EventNode(shv::iotqt::node::ShvNode *parent) +: Super("event", parent) +{ +} + +const std::vector &EventNode::metaMethods() +{ + static std::vector meta_methods { + methods::DIR, + methods::LS, + {METH_NAME, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read}, + {METH_CURRENT_STAGE, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read}, + {METH_EVENT_CONFIG, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read}, + }; + return meta_methods; +} + +RpcValue EventNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) +{ + qfLogFuncFrame() << shv_path.join('/') << method; + if(shv_path.empty()) { + if(method == METH_NAME) { + return getPlugin()->eventConfig()->eventName().toStdString(); + } + if(method == METH_CURRENT_STAGE) { + return getPlugin()->currentStageId(); + } + if(method == METH_EVENT_CONFIG) { + auto cfg = getPlugin()->eventConfig(); + return shv::coreqt::rpc::qVariantToRpcValue(cfg->values()); + } + } + return Super::callMethod(shv_path, method, params, user_id); +} + +//========================================================= +// StartListNode +//========================================================= +static const auto METH_TABLE = "table"; +static const auto METH_RECORD = "record"; +//static const auto SIG_REC_CHNG = "recchng"; + +void SqlViewNode::setQueryBuilder(const qf::core::sql::QueryBuilder &qb) +{ + m_queryBuilder = qb; +} + +qf::core::sql::QueryBuilder SqlViewNode::effectiveQueryBuilder() +{ + return m_queryBuilder; +} + +const std::vector &SqlViewNode::metaMethods() +{ + static std::vector meta_methods { + methods::DIR, + methods::LS, + {METH_TABLE, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Read}, + {METH_RECORD, MetaMethod::Flag::None, "RpcValue", "RpcValue", AccessLevel::Read }, + //{METH_SET_RECORD, MetaMethod::Flag::None, "RpcValue", {}, AccessLevel::Write}, + }; + return meta_methods; +} + +RpcValue SqlViewNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) +{ + qfLogFuncFrame() << shv_path.join('/') << method; + //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); + if(shv_path.empty()) { + if(method == METH_TABLE) { + const auto &m = params.asMap(); + auto qb = effectiveQueryBuilder(); + if (auto where = m.value("where").to(); !where.isEmpty()) { + qb.where(where); + } + if (auto order_by = m.value("orderBy").to(); !order_by.isEmpty()) { + qb.orderBy(order_by); + } + qf::core::sql::Query q; + QString qs = qb.toString(); + q.exec(qs, qf::core::Exception::Throw); + auto res = SqlApiNode::rpcSqlResultFromQuery(q); + return res.toRpcValue(); + } + if(method == METH_RECORD) { + auto id = params.toInt(); + auto qb = effectiveQueryBuilder(); + qb.where("runs.id = " + QString::number(id)); + qf::core::sql::Query q; + QString qs = qb.toString(); + qfDebug() << qs; + q.exec(qs, qf::core::Exception::Throw); + if (q.next()) { + return SqlApiNode::recordToMap(q.record()); + } + return RpcValue::Map{}; + } + } + return Super::callMethod(shv_path, method, params, user_id); +} + +//========================================================= +// CurrentStageConfigNode +//========================================================= +const std::vector &CurrentStageConfigNode::metaMethods() +{ + static std::vector meta_methods { + methods::DIR, + methods::LS, + {Rpc::METH_GET, MetaMethod::Flag::IsGetter, {}, "Map", AccessLevel::Read}, + }; + return meta_methods; +} + +RpcValue CurrentStageConfigNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) +{ + qfLogFuncFrame() << shv_path.join('/') << method; + //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); + if(shv_path.empty()) { + if(method == Rpc::METH_GET) { + auto *event_plugin = getPlugin(); + QVariantMap data = event_plugin->stageData(event_plugin->currentStageId()); + data.remove("drawingConfig"); // remove internal key + return shv::coreqt::rpc::qVariantToRpcValue(data); + } + } + return Super::callMethod(shv_path, method, params, user_id); +} + +//========================================================= +// CurrentStageStartListNode +//========================================================= +CurrentStageStartListNode::CurrentStageStartListNode(shv::iotqt::node::ShvNode *parent) + : Super("startList", parent) +{ + auto qb = getPlugin()->startListQuery(); + //qb.orderBy("runs.startTimeMs"); + setQueryBuilder(qb); +} + +qf::core::sql::QueryBuilder CurrentStageStartListNode::effectiveQueryBuilder() +{ + auto qb = Super::effectiveQueryBuilder(); + auto *event_plugin = getPlugin(); + qb.where(QStringLiteral("runs.stageId=%1").arg(event_plugin->currentStageId())); + return qb; +} + +//========================================================= +// CurrentStageRunsNode +//========================================================= +CurrentStageRunsNode::CurrentStageRunsNode(shv::iotqt::node::ShvNode *parent) + : Super("runs", parent) +{ +} + +QueryBuilder CurrentStageRunsNode::effectiveQueryBuilder() +{ + auto *event_plugin = getPlugin(); + auto qb = getPlugin()->runsQuery(event_plugin->currentStageId()); + return qb; +} + +static const auto METH_SET_RECORD = "setRecord"; +//static const auto METH_RUN_CHANGED = "runchng"; +static const auto SIG_RUN_CHANGED = "runchng"; + +const std::vector &CurrentStageRunsNode::metaMethods() +{ + static std::vector meta_methods { + methods::DIR, + methods::LS, + {METH_TABLE, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Read}, + {METH_RECORD, MetaMethod::Flag::None, "Int", "Map", AccessLevel::Read, {{SIG_RUN_CHANGED, "[Int, RpcValue]"}} }, + {METH_SET_RECORD, MetaMethod::Flag::None, "[Int, RpcValue]", {}, AccessLevel::Write}, + }; + return meta_methods; + static auto s_meta_methods = [this]() { + auto mm = Super::metaMethods(); + mm.push_back({METH_SET_RECORD, MetaMethod::Flag::None, "[int, Map]", {}, AccessLevel::Write }); + return mm; + }(); + return s_meta_methods; +} + +RpcValue CurrentStageRunsNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) +{ + qfLogFuncFrame() << shv_path.join('/') << method; + if(shv_path.empty()) { + if(method == METH_SET_RECORD) { + auto *plugin = getPlugin(); + const auto &lst = params.asList(); + plugin->setRunsRecord(lst.value(0).toInt(), shv::coreqt::rpc::rpcValueToQVariant(lst.value(1))); + return nullptr; + } + } + return Super::callMethod(shv_path, method, params, user_id); +} + +void CurrentStageRunsNode::sendRunChangedSignal(const QVariant &qparam) +{ + auto param = shv::coreqt::rpc::qVariantToRpcValue(qparam); + Q_ASSERT(param.isList()); + Q_ASSERT(param.asList().value(0).toInt() > 0); // run.id + RpcSignal sig; + sig.setShvPath(shvPath().asString()); + sig.setMethod(SIG_RUN_CHANGED); + sig.setSource(METH_RECORD); + sig.setParams(param); + qfDebug() << "emit:" << sig.toPrettyString(); + emitSendRpcMessage(sig); +} + +//========================================================= +// CurrentStageClassesNode +//========================================================= +CurrentStageClassesNode::CurrentStageClassesNode(shv::iotqt::node::ShvNode *parent) + : Super("classes", parent) +{ +} + +QueryBuilder CurrentStageClassesNode::effectiveQueryBuilder() +{ + auto *event_plugin = getPlugin(); + QueryBuilder qb; + qb.select2("classes", "*") + .select2("classdefs", "*") + .select2("courses", "id, name, length, climb") + .from("classes") + .joinRestricted("classes.id", "classdefs.classId", "classdefs.stageId=" QF_IARG(event_plugin->currentStageId())) + .join("classdefs.courseId", "courses.id") + .orderBy("classes.name");//.limit(10); + return qb; +} + + +} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h new file mode 100644 index 000000000..917a75f2c --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h @@ -0,0 +1,103 @@ +#pragma once + +#include "qxnode.h" + +#include + +namespace Event::services::qx { + +class DotAppNode : public QxNode +{ + Q_OBJECT + + using Super = QxNode; +public: + explicit DotAppNode(shv::iotqt::node::ShvNode *parent) : Super(".app", parent) {} +private: + //shv::chainpack::RpcValue callMethodRq(const shv::chainpack::RpcRequest &rq) override; + const std::vector &metaMethods() override; + shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; +}; + +class EventNode : public QxNode +{ + Q_OBJECT + + using Super = QxNode; +public: + explicit EventNode(shv::iotqt::node::ShvNode *parent); +private: + const std::vector &metaMethods() override; + shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; +}; + +class SqlViewNode : public QxNode +{ + Q_OBJECT + + using Super = QxNode; +public: + explicit SqlViewNode(const std::string &name, shv::iotqt::node::ShvNode *parent) + : Super(name, parent) + {} + void setQueryBuilder(const qf::core::sql::QueryBuilder &qb); +protected: + virtual qf::core::sql::QueryBuilder effectiveQueryBuilder(); + const std::vector &metaMethods() override; + shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; +private: + qf::core::sql::QueryBuilder m_queryBuilder; +}; + +class CurrentStageConfigNode : public QxNode +{ + Q_OBJECT + + using Super = QxNode; +public: + explicit CurrentStageConfigNode(shv::iotqt::node::ShvNode *parent) + : Super("config", parent) + {} +protected: + const std::vector &metaMethods() override; + shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; +}; + +class CurrentStageStartListNode : public SqlViewNode +{ + Q_OBJECT + + using Super = SqlViewNode; +public: + explicit CurrentStageStartListNode(shv::iotqt::node::ShvNode *parent); +protected: + qf::core::sql::QueryBuilder effectiveQueryBuilder() override; +}; + +class CurrentStageRunsNode : public SqlViewNode +{ + Q_OBJECT + + using Super = SqlViewNode; +public: + explicit CurrentStageRunsNode(shv::iotqt::node::ShvNode *parent); + void sendRunChangedSignal(const QVariant &qparam); +protected: + const std::vector &metaMethods() override; + shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; + qf::core::sql::QueryBuilder effectiveQueryBuilder() override; +}; + +class CurrentStageClassesNode : public SqlViewNode +{ + Q_OBJECT + + using Super = SqlViewNode; +public: + explicit CurrentStageClassesNode(shv::iotqt::node::ShvNode *parent); + +protected: + qf::core::sql::QueryBuilder effectiveQueryBuilder() override; +}; + +} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index 6b673328e..e693f4b45 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -1,5 +1,7 @@ #include "qxeventservice.h" #include "qxeventservicewidget.h" +#include "nodes.h" +#include "sqlapinode.h" #include "../../eventplugin.h" #include "../../../../Runs/src/runsplugin.h" @@ -9,7 +11,7 @@ #include #include -#include +#include #include #include @@ -41,31 +43,39 @@ using Event::EventPlugin; using Runs::RunsPlugin; namespace Event::services::qx { -//=============================================== -// QxClientServiceSettings -//=============================================== -// QString QxClientServiceSettings::eventKey() const -// { -// auto *event_plugin = getPlugin(); -// auto *cfg = event_plugin->eventConfig(); -// auto key = cfg->apiKey(); -// auto current_stage = cfg->currentStageId(); -// return QStringLiteral("%1%2").arg(key).arg(current_stage); -// } //=============================================== // QxClientService //=============================================== QxEventService::QxEventService(QObject *parent) : Super(QxEventService::serviceId(), parent) + , m_rootNode(new shv::iotqt::node::ShvRootNode(this)) { auto *event_plugin = getPlugin(); - connect(event_plugin, &Event::EventPlugin::dbEventNotify, this, &QxEventService::onDbEventNotify, Qt::QueuedConnection); + // connect(event_plugin, &Event::EventPlugin::dbEventNotify, this, &QxEventService::onDbEventNotify, Qt::QueuedConnection); + + new DotAppNode(m_rootNode); + connect(event_plugin, &EventPlugin::eventOpenChanged, this, [this](bool is_open) { + if (is_open) { + new SqlApiNode(m_rootNode); + auto *event = new EventNode(m_rootNode); + auto *current_stage = new shv::iotqt::node::ShvNode("currentStage", event); + new CurrentStageConfigNode(current_stage); + //new CurrentStageStartListNode(current_stage); + new CurrentStageRunsNode(current_stage); + new CurrentStageClassesNode(current_stage); + } + else { + qDeleteAll(m_rootNode->findChildren()); + } + }); + + connect(m_rootNode, &shv::iotqt::node::ShvNode::sendRpcMessage, this, &QxEventService::sendRpcMessage); } QString QxEventService::serviceDisplayName() const { - return tr("QE Exchange"); + return tr("QX Event"); } QString QxEventService::serviceId() @@ -79,8 +89,13 @@ void QxEventService::run() { auto ss = settings(); delete m_rpcConnection; - m_rpcConnection = new ClientConnection(this); - m_rpcConnection->setConnectionString(ss.exchangeServerUrl()); + m_rpcConnection = new DeviceConnection(this); + m_rpcConnection->setConnectionString(ss.shvBrokerUrl()); + RpcValue::Map opts; + RpcValue::Map device; + device["mountPoint"] = "test/quickbox"; + opts["device"] = device; + m_rpcConnection->setConnectionOptions(opts); connect(m_rpcConnection, &ClientConnection::brokerConnectedChanged, this, &QxEventService::onBrokerConnectedChanged); connect(m_rpcConnection, &ClientConnection::socketError, this, &QxEventService::onBrokerSocketError); @@ -130,8 +145,8 @@ void QxEventService::loadSettings() { Super::loadSettings(); auto ss = settings(); - if (ss.exchangeServerUrl().isEmpty()) { - ss.setExchangeServerUrl("http://localhost:8000"); + if (ss.shvBrokerUrl().isEmpty()) { + ss.setShvBrokerUrl("tcp://localhost?user=test&password=test"); } m_settings = ss; } @@ -243,7 +258,7 @@ void QxEventService::postRuns(QObject *context, std::function ca void QxEventService::getHttpJson(const QString &path, const QUrlQuery &query, QObject *context, const std::function &call_back) { - auto url = exchangeServerUrl(); + auto url = shvBrokerUrl(); url.setPath(path); url.setQuery(query); // qfInfo() << url.toString(); @@ -272,7 +287,7 @@ void QxEventService::getHttpJson(const QString &path, const QUrlQuery &query, QO QNetworkReply* QxEventService::getQxChangesReply(int from_id) { - auto url = exchangeServerUrl(); + auto url = shvBrokerUrl(); url.setPath(QStringLiteral("/api/event/%1/changes").arg(eventId())); url.setQuery(QStringLiteral("from_id=%1").arg(from_id)); @@ -299,15 +314,15 @@ QByteArray QxEventService::apiToken() const return event_plugin->stageData(current_stage).qxApiToken().toUtf8(); } -QUrl QxEventService::exchangeServerUrl() const +QUrl QxEventService::shvBrokerUrl() const { auto ss = settings(); - return QUrl(ss.exchangeServerUrl()); + return QUrl(ss.shvBrokerUrl()); } void QxEventService::postFileCompressed(std::optional path, std::optional name, QByteArray data, QObject *context , std::function call_back) { - auto url = exchangeServerUrl(); + auto url = shvBrokerUrl(); url.setPath(path.value_or("/api/event/current/file")); if (name.has_value()) { @@ -359,7 +374,7 @@ void QxEventService::httpPostJson(const QString &path, const QString &query, QVa if (!isRunning()) { return; } - auto url = exchangeServerUrl(); + auto url = shvBrokerUrl(); url.setPath(path); url.setQuery(query); @@ -617,9 +632,7 @@ void QxEventService::onRpcMessageReceived(const shv::chainpack::RpcMessage &msg) if(msg.isRequest()) { RpcRequest rq(msg); qfMessage() << "RPC request received:" << rq.toPrettyString(); - if(m_shvTree->root()) { - m_shvTree->root()->handleRpcRequest(rq); - } + m_rootNode->handleRpcRequest(rq); } else if(msg.isResponse()) { RpcResponse rp(msg); @@ -631,6 +644,13 @@ void QxEventService::onRpcMessageReceived(const shv::chainpack::RpcMessage &msg) } } +void QxEventService::sendRpcMessage(const shv::chainpack::RpcMessage &rpc_msg) +{ + if(m_rpcConnection && m_rpcConnection->isBrokerConnected()) { + m_rpcConnection->sendRpcMessage(rpc_msg); + } +} + void QxEventService::subscribeChanges() { Q_ASSERT(m_rpcConnection); diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h index 1ab8d14b7..2a103a9d7 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h @@ -7,8 +7,8 @@ class QNetworkReply; class QUrlQuery; class QTimer; -namespace shv::iotqt::node { class ShvNodeTree; } -namespace shv::iotqt::rpc { class ClientConnection; } +namespace shv::iotqt::node { class ShvNodeTree; class ShvRootNode; } +namespace shv::iotqt::rpc { class DeviceConnection; } namespace shv::chainpack { class RpcMessage; class RpcError; } namespace Event::services::qx { @@ -17,7 +17,7 @@ class QxEventServiceSettings : public ServiceSettings { using Super = ServiceSettings; - QF_VARIANTMAP_FIELD2(QString, e, setE, xchangeServerUrl, "http://localhost:8000") + QF_VARIANTMAP_FIELD2(QString, s, setS, hvBrokerUrl, "http://localhost:8000") public: QxEventServiceSettings(const QVariantMap &o = QVariantMap()) : Super(o) {} }; @@ -69,12 +69,13 @@ class QxEventService : public Service QByteArray apiToken() const; static int currentConnectionId(); - QUrl exchangeServerUrl() const; + QUrl shvBrokerUrl() const; int eventId() const; private: // shv void onBrokerConnectedChanged(bool is_connected); void onRpcMessageReceived(const shv::chainpack::RpcMessage &msg); + void sendRpcMessage(const shv::chainpack::RpcMessage &rpc_msg); void onBrokerSocketError(const QString &err); void onBrokerLoginError(const shv::chainpack::RpcError &err); @@ -97,9 +98,8 @@ class QxEventService : public Service EventInfo eventInfo() const; private: // shv - shv::iotqt::rpc::ClientConnection *m_rpcConnection = nullptr; - shv::iotqt::node::ShvNodeTree *m_shvTree = nullptr; - + shv::iotqt::rpc::DeviceConnection *m_rpcConnection = nullptr; + shv::iotqt::node::ShvRootNode *m_rootNode; private: QNetworkAccessManager *m_networkManager = nullptr; QNetworkReply *m_replySSE = nullptr; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp index ede33ffb4..416bb25b4 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp @@ -23,7 +23,7 @@ QxEventServiceWidget::QxEventServiceWidget(QWidget *parent) : Super(parent) , ui(new Ui::QxEventServiceWidget) { - setPersistentSettingsId("QxClientServiceWidget"); + setPersistentSettingsId("QxEventServiceWidget"); ui->setupUi(this); connect(ui->edServerUrl, &QLineEdit::textChanged, this, &QxEventServiceWidget::updateOCheckListPostUrl); connect(ui->edApiToken, &QLineEdit::textChanged, this, &QxEventServiceWidget::updateOCheckListPostUrl); @@ -35,7 +35,7 @@ QxEventServiceWidget::QxEventServiceWidget(QWidget *parent) auto *event_plugin = getPlugin(); auto current_stage = event_plugin->currentStageId(); auto settings = svc->settings(); - ui->edServerUrl->setText(settings.exchangeServerUrl()); + ui->edServerUrl->setText(settings.shvBrokerUrl()); ui->edApiToken->setText(svc->apiToken()); ui->edCurrentStage->setValue(current_stage); connect(ui->btTestConnection, &QAbstractButton::clicked, this, &QxEventServiceWidget::testConnection); @@ -92,7 +92,7 @@ bool QxEventServiceWidget::saveSettings() auto *svc = service(); if(svc) { auto ss = svc->settings(); - ss.setExchangeServerUrl(ui->edServerUrl->text()); + ss.setShvBrokerUrl(ui->edServerUrl->text()); svc->setSettings(ss); auto *event_plugin = getPlugin(); diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.ui b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.ui index 261a65af9..5f4a41e1a 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.ui +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.ui @@ -19,7 +19,7 @@ - Exchange server url + SHV broker url diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.cpp new file mode 100644 index 000000000..dfcea61fd --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.cpp @@ -0,0 +1,36 @@ +#include "qxnode.h" + +#include +#include + +#include + +using namespace shv::chainpack; + +namespace Event::services::qx { + +QxNode::QxNode(const std::string &name, shv::iotqt::node::ShvNode *parent) + : Super(name, parent) +{ + +} + +size_t QxNode::methodCount(const StringViewList &shv_path) +{ + if(shv_path.empty()) { + return metaMethods().size(); + } + return Super::methodCount(shv_path); +} + +const MetaMethod *QxNode::metaMethod(const StringViewList &shv_path, size_t ix) +{ + if(shv_path.empty()) { + if(metaMethods().size() <= ix) + QF_EXCEPTION("Invalid method index: " + QString::number(ix) + " of: " + QString::number(metaMethods().size())); + return &(metaMethods()[ix]); + } + return Super::metaMethod(shv_path, ix); +} + +} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.h new file mode 100644 index 000000000..79e42c174 --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxnode.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace Event::services::qx { + +class QxNode : public shv::iotqt::node::ShvNode +{ + Q_OBJECT + + using Super = shv::iotqt::node::ShvNode; +public: + explicit QxNode(const std::string &name, shv::iotqt::node::ShvNode *parent); + + size_t methodCount(const StringViewList &shv_path) override; + const shv::chainpack::MetaMethod* metaMethod(const StringViewList &shv_path, size_t ix) override; +protected: + //shv::chainpack::RpcValue callMethodRq(const shv::chainpack::RpcRequest &rq) override; + //shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; + virtual const std::vector &metaMethods() = 0; +}; + +} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp index 789cb44e0..1c16121ce 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp @@ -208,7 +208,7 @@ void RunChangeDialog::resolveChanges(bool is_accepted) auto *svc = service(); auto *nm = svc->networkManager(); QNetworkRequest request; - auto url = svc->exchangeServerUrl(); + auto url = svc->shvBrokerUrl(); // qfInfo() << "url " << url.toString(); url.setPath("/api/event/current/changes/resolve-change"); diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp new file mode 100644 index 000000000..ac90ce45f --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp @@ -0,0 +1,119 @@ +#include "sqlapinode.h" + +#include +#include +#include + +#include +#include +#include + +#include +#include + +using namespace shv::chainpack; +using namespace shv::coreqt::data; + +namespace Event::services::qx { +namespace { + +/* + +RpcSqlResult RpcSqlResult::fromRpcValue(const shv::chainpack::RpcValue &rv) +{ + RpcSqlResult ret; + const RpcValue::Map &map = rv.asMap(); + const RpcValue::List &flds = map.value("fields").asList(); + if(flds.empty()) { + ret.numRowsAffected = map.value("numRowsAffected").toInt(); + ret.lastInsertId = map.value("lastInsertId").toInt(); + } + else { + + } + return ret; + +} +*/ +} + +SqlApiNode::SqlApiNode(shv::iotqt::node::ShvNode *parent) + : Super("sql", parent) +{ + +} + +shv::chainpack::RpcValue::Map SqlApiNode::recordToMap(const QSqlRecord &rec) +{ + RpcValue::Map record; + for (int i = 0; i < rec.count(); ++i) { + QSqlField fld = rec.field(i); + auto fld_name = fld.name(); + fld_name.replace("__", "."); + record[fld_name.toStdString()] = shv::coreqt::rpc::qVariantToRpcValue(fld.value()); + } + return record; +} + +RpcSqlResult SqlApiNode::rpcSqlResultFromQuery(QSqlQuery &q) +{ + RpcSqlResult ret; + if(q.isSelect()) { + QSqlRecord rec = q.record(); + for (int i = 0; i < rec.count(); ++i) { + QSqlField fld = rec.field(i); + RpcSqlField rfld; + rfld.name = fld.name(); + rfld.name.replace("__", "."); + rfld.type = fld.metaType().id(); + ret.fields.append(rfld); + } + while(q.next()) { + RpcSqlResult::Row row; + for (int i = 0; i < rec.count(); ++i) { + const QVariant v = q.value(i); + if (v.isNull()) + row.append(QVariant()); + else + row.append(v); + //shvError() << v << v.isNull() << jsv.toVariant() << jsv.toVariant().isNull(); + } + ret.rows.insert(ret.rows.count(), row); + } + } + else { + ret.numRowsAffected = q.numRowsAffected(); + ret.lastInsertId = q.lastInsertId().toInt(); + } + return ret; +} + +static auto METH_EXEC_SQL = "execSql"; + +const std::vector &SqlApiNode::metaMethods() +{ + static std::vector meta_methods { + methods::DIR, + methods::LS, + {METH_EXEC_SQL, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Write}, + }; + return meta_methods; +} + +RpcValue SqlApiNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) +{ + qfLogFuncFrame() << shv_path.join('/') << method; + //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); + if(shv_path.empty()) { + if(method == METH_EXEC_SQL) { + qf::core::sql::Query q; + QString qs = params.to(); + q.exec(qs, qf::core::Exception::Throw); + auto res = rpcSqlResultFromQuery(q); + return res.toRpcValue(); + } + } + return Super::callMethod(shv_path, method, params, user_id); +} + +} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h new file mode 100644 index 000000000..c2e112f26 --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h @@ -0,0 +1,27 @@ +#pragma once + +#include "qxnode.h" + +class QSqlQuery; +class QSqlRecord; + +namespace shv::coreqt::data { class RpcSqlResult; } + +namespace Event::services::qx { + +class SqlApiNode : public QxNode +{ + Q_OBJECT + + using Super = QxNode; +public: + explicit SqlApiNode(shv::iotqt::node::ShvNode *parent); + + static shv::coreqt::data::RpcSqlResult rpcSqlResultFromQuery(QSqlQuery &q); + static shv::chainpack::RpcValue::Map recordToMap(const QSqlRecord &rec); +protected: + const std::vector &metaMethods() override; + shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; +}; + +} From e789281626aeaf00ffad1f3a51052e29a087f191 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 9 Nov 2025 18:43:07 +0100 Subject: [PATCH 13/29] Remove unused shv odes --- .../plugins/Event/src/services/qx/nodes.cpp | 249 ------------------ .../plugins/Event/src/services/qx/nodes.h | 81 ------ .../Event/src/services/qx/qxeventservice.cpp | 18 +- 3 files changed, 1 insertion(+), 347 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp index 07c57d53d..6a4db4533 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.cpp @@ -1,9 +1,5 @@ #include "nodes.h" -#include "sqlapinode.h" -#include "../../eventplugin.h" -#include "../../../../Runs/src/runsplugin.h" - #include #include #include @@ -17,9 +13,6 @@ using namespace qf::core::sql; using namespace shv::chainpack; -using qf::gui::framework::getPlugin; -using Event::EventPlugin; -using Runs::RunsPlugin; namespace Event::services::qx { @@ -55,246 +48,4 @@ RpcValue DotAppNode::callMethod(const StringViewList &shv_path, const std::strin return Super::callMethod(shv_path, method, params, user_id); } -//========================================================= -// EventNode -//========================================================= -static const auto METH_CURRENT_STAGE = "currentStage"; -static const auto METH_EVENT_CONFIG = "eventConfig"; - -EventNode::EventNode(shv::iotqt::node::ShvNode *parent) -: Super("event", parent) -{ -} - -const std::vector &EventNode::metaMethods() -{ - static std::vector meta_methods { - methods::DIR, - methods::LS, - {METH_NAME, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read}, - {METH_CURRENT_STAGE, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read}, - {METH_EVENT_CONFIG, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read}, - }; - return meta_methods; -} - -RpcValue EventNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) -{ - qfLogFuncFrame() << shv_path.join('/') << method; - if(shv_path.empty()) { - if(method == METH_NAME) { - return getPlugin()->eventConfig()->eventName().toStdString(); - } - if(method == METH_CURRENT_STAGE) { - return getPlugin()->currentStageId(); - } - if(method == METH_EVENT_CONFIG) { - auto cfg = getPlugin()->eventConfig(); - return shv::coreqt::rpc::qVariantToRpcValue(cfg->values()); - } - } - return Super::callMethod(shv_path, method, params, user_id); -} - -//========================================================= -// StartListNode -//========================================================= -static const auto METH_TABLE = "table"; -static const auto METH_RECORD = "record"; -//static const auto SIG_REC_CHNG = "recchng"; - -void SqlViewNode::setQueryBuilder(const qf::core::sql::QueryBuilder &qb) -{ - m_queryBuilder = qb; -} - -qf::core::sql::QueryBuilder SqlViewNode::effectiveQueryBuilder() -{ - return m_queryBuilder; -} - -const std::vector &SqlViewNode::metaMethods() -{ - static std::vector meta_methods { - methods::DIR, - methods::LS, - {METH_TABLE, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Read}, - {METH_RECORD, MetaMethod::Flag::None, "RpcValue", "RpcValue", AccessLevel::Read }, - //{METH_SET_RECORD, MetaMethod::Flag::None, "RpcValue", {}, AccessLevel::Write}, - }; - return meta_methods; -} - -RpcValue SqlViewNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) -{ - qfLogFuncFrame() << shv_path.join('/') << method; - //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); - if(shv_path.empty()) { - if(method == METH_TABLE) { - const auto &m = params.asMap(); - auto qb = effectiveQueryBuilder(); - if (auto where = m.value("where").to(); !where.isEmpty()) { - qb.where(where); - } - if (auto order_by = m.value("orderBy").to(); !order_by.isEmpty()) { - qb.orderBy(order_by); - } - qf::core::sql::Query q; - QString qs = qb.toString(); - q.exec(qs, qf::core::Exception::Throw); - auto res = SqlApiNode::rpcSqlResultFromQuery(q); - return res.toRpcValue(); - } - if(method == METH_RECORD) { - auto id = params.toInt(); - auto qb = effectiveQueryBuilder(); - qb.where("runs.id = " + QString::number(id)); - qf::core::sql::Query q; - QString qs = qb.toString(); - qfDebug() << qs; - q.exec(qs, qf::core::Exception::Throw); - if (q.next()) { - return SqlApiNode::recordToMap(q.record()); - } - return RpcValue::Map{}; - } - } - return Super::callMethod(shv_path, method, params, user_id); -} - -//========================================================= -// CurrentStageConfigNode -//========================================================= -const std::vector &CurrentStageConfigNode::metaMethods() -{ - static std::vector meta_methods { - methods::DIR, - methods::LS, - {Rpc::METH_GET, MetaMethod::Flag::IsGetter, {}, "Map", AccessLevel::Read}, - }; - return meta_methods; -} - -RpcValue CurrentStageConfigNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) -{ - qfLogFuncFrame() << shv_path.join('/') << method; - //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); - if(shv_path.empty()) { - if(method == Rpc::METH_GET) { - auto *event_plugin = getPlugin(); - QVariantMap data = event_plugin->stageData(event_plugin->currentStageId()); - data.remove("drawingConfig"); // remove internal key - return shv::coreqt::rpc::qVariantToRpcValue(data); - } - } - return Super::callMethod(shv_path, method, params, user_id); -} - -//========================================================= -// CurrentStageStartListNode -//========================================================= -CurrentStageStartListNode::CurrentStageStartListNode(shv::iotqt::node::ShvNode *parent) - : Super("startList", parent) -{ - auto qb = getPlugin()->startListQuery(); - //qb.orderBy("runs.startTimeMs"); - setQueryBuilder(qb); -} - -qf::core::sql::QueryBuilder CurrentStageStartListNode::effectiveQueryBuilder() -{ - auto qb = Super::effectiveQueryBuilder(); - auto *event_plugin = getPlugin(); - qb.where(QStringLiteral("runs.stageId=%1").arg(event_plugin->currentStageId())); - return qb; -} - -//========================================================= -// CurrentStageRunsNode -//========================================================= -CurrentStageRunsNode::CurrentStageRunsNode(shv::iotqt::node::ShvNode *parent) - : Super("runs", parent) -{ -} - -QueryBuilder CurrentStageRunsNode::effectiveQueryBuilder() -{ - auto *event_plugin = getPlugin(); - auto qb = getPlugin()->runsQuery(event_plugin->currentStageId()); - return qb; -} - -static const auto METH_SET_RECORD = "setRecord"; -//static const auto METH_RUN_CHANGED = "runchng"; -static const auto SIG_RUN_CHANGED = "runchng"; - -const std::vector &CurrentStageRunsNode::metaMethods() -{ - static std::vector meta_methods { - methods::DIR, - methods::LS, - {METH_TABLE, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Read}, - {METH_RECORD, MetaMethod::Flag::None, "Int", "Map", AccessLevel::Read, {{SIG_RUN_CHANGED, "[Int, RpcValue]"}} }, - {METH_SET_RECORD, MetaMethod::Flag::None, "[Int, RpcValue]", {}, AccessLevel::Write}, - }; - return meta_methods; - static auto s_meta_methods = [this]() { - auto mm = Super::metaMethods(); - mm.push_back({METH_SET_RECORD, MetaMethod::Flag::None, "[int, Map]", {}, AccessLevel::Write }); - return mm; - }(); - return s_meta_methods; -} - -RpcValue CurrentStageRunsNode::callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) -{ - qfLogFuncFrame() << shv_path.join('/') << method; - if(shv_path.empty()) { - if(method == METH_SET_RECORD) { - auto *plugin = getPlugin(); - const auto &lst = params.asList(); - plugin->setRunsRecord(lst.value(0).toInt(), shv::coreqt::rpc::rpcValueToQVariant(lst.value(1))); - return nullptr; - } - } - return Super::callMethod(shv_path, method, params, user_id); -} - -void CurrentStageRunsNode::sendRunChangedSignal(const QVariant &qparam) -{ - auto param = shv::coreqt::rpc::qVariantToRpcValue(qparam); - Q_ASSERT(param.isList()); - Q_ASSERT(param.asList().value(0).toInt() > 0); // run.id - RpcSignal sig; - sig.setShvPath(shvPath().asString()); - sig.setMethod(SIG_RUN_CHANGED); - sig.setSource(METH_RECORD); - sig.setParams(param); - qfDebug() << "emit:" << sig.toPrettyString(); - emitSendRpcMessage(sig); -} - -//========================================================= -// CurrentStageClassesNode -//========================================================= -CurrentStageClassesNode::CurrentStageClassesNode(shv::iotqt::node::ShvNode *parent) - : Super("classes", parent) -{ -} - -QueryBuilder CurrentStageClassesNode::effectiveQueryBuilder() -{ - auto *event_plugin = getPlugin(); - QueryBuilder qb; - qb.select2("classes", "*") - .select2("classdefs", "*") - .select2("courses", "id, name, length, climb") - .from("classes") - .joinRestricted("classes.id", "classdefs.classId", "classdefs.stageId=" QF_IARG(event_plugin->currentStageId())) - .join("classdefs.courseId", "courses.id") - .orderBy("classes.name");//.limit(10); - return qb; -} - - } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h index 917a75f2c..58cf1125e 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/nodes.h @@ -19,85 +19,4 @@ class DotAppNode : public QxNode shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; }; -class EventNode : public QxNode -{ - Q_OBJECT - - using Super = QxNode; -public: - explicit EventNode(shv::iotqt::node::ShvNode *parent); -private: - const std::vector &metaMethods() override; - shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; -}; - -class SqlViewNode : public QxNode -{ - Q_OBJECT - - using Super = QxNode; -public: - explicit SqlViewNode(const std::string &name, shv::iotqt::node::ShvNode *parent) - : Super(name, parent) - {} - void setQueryBuilder(const qf::core::sql::QueryBuilder &qb); -protected: - virtual qf::core::sql::QueryBuilder effectiveQueryBuilder(); - const std::vector &metaMethods() override; - shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; -private: - qf::core::sql::QueryBuilder m_queryBuilder; -}; - -class CurrentStageConfigNode : public QxNode -{ - Q_OBJECT - - using Super = QxNode; -public: - explicit CurrentStageConfigNode(shv::iotqt::node::ShvNode *parent) - : Super("config", parent) - {} -protected: - const std::vector &metaMethods() override; - shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; -}; - -class CurrentStageStartListNode : public SqlViewNode -{ - Q_OBJECT - - using Super = SqlViewNode; -public: - explicit CurrentStageStartListNode(shv::iotqt::node::ShvNode *parent); -protected: - qf::core::sql::QueryBuilder effectiveQueryBuilder() override; -}; - -class CurrentStageRunsNode : public SqlViewNode -{ - Q_OBJECT - - using Super = SqlViewNode; -public: - explicit CurrentStageRunsNode(shv::iotqt::node::ShvNode *parent); - void sendRunChangedSignal(const QVariant &qparam); -protected: - const std::vector &metaMethods() override; - shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; - qf::core::sql::QueryBuilder effectiveQueryBuilder() override; -}; - -class CurrentStageClassesNode : public SqlViewNode -{ - Q_OBJECT - - using Super = SqlViewNode; -public: - explicit CurrentStageClassesNode(shv::iotqt::node::ShvNode *parent); - -protected: - qf::core::sql::QueryBuilder effectiveQueryBuilder() override; -}; - } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index e693f4b45..8aa7f5642 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -51,24 +51,8 @@ QxEventService::QxEventService(QObject *parent) : Super(QxEventService::serviceId(), parent) , m_rootNode(new shv::iotqt::node::ShvRootNode(this)) { - auto *event_plugin = getPlugin(); - // connect(event_plugin, &Event::EventPlugin::dbEventNotify, this, &QxEventService::onDbEventNotify, Qt::QueuedConnection); - new DotAppNode(m_rootNode); - connect(event_plugin, &EventPlugin::eventOpenChanged, this, [this](bool is_open) { - if (is_open) { - new SqlApiNode(m_rootNode); - auto *event = new EventNode(m_rootNode); - auto *current_stage = new shv::iotqt::node::ShvNode("currentStage", event); - new CurrentStageConfigNode(current_stage); - //new CurrentStageStartListNode(current_stage); - new CurrentStageRunsNode(current_stage); - new CurrentStageClassesNode(current_stage); - } - else { - qDeleteAll(m_rootNode->findChildren()); - } - }); + new SqlApiNode(m_rootNode); connect(m_rootNode, &shv::iotqt::node::ShvNode::sendRpcMessage, this, &QxEventService::sendRpcMessage); } From b5e5d2a9d16fbeadc1db66d15a38772187e48c06 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 9 Nov 2025 22:10:51 +0100 Subject: [PATCH 14/29] QX SQL API node implemented --- .../Event/src/services/qx/sqlapinode.cpp | 244 +++++++++++++++--- .../Event/src/services/qx/sqlapinode.h | 3 - 2 files changed, 203 insertions(+), 44 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp index ac90ce45f..846e6c7e6 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -10,32 +11,12 @@ #include #include +#include using namespace shv::chainpack; using namespace shv::coreqt::data; namespace Event::services::qx { -namespace { - -/* - -RpcSqlResult RpcSqlResult::fromRpcValue(const shv::chainpack::RpcValue &rv) -{ - RpcSqlResult ret; - const RpcValue::Map &map = rv.asMap(); - const RpcValue::List &flds = map.value("fields").asList(); - if(flds.empty()) { - ret.numRowsAffected = map.value("numRowsAffected").toInt(); - ret.lastInsertId = map.value("lastInsertId").toInt(); - } - else { - - } - return ret; - -} -*/ -} SqlApiNode::SqlApiNode(shv::iotqt::node::ShvNode *parent) : Super("sql", parent) @@ -43,20 +24,60 @@ SqlApiNode::SqlApiNode(shv::iotqt::node::ShvNode *parent) } -shv::chainpack::RpcValue::Map SqlApiNode::recordToMap(const QSqlRecord &rec) +namespace { +class Transaction { - RpcValue::Map record; - for (int i = 0; i < rec.count(); ++i) { - QSqlField fld = rec.field(i); - auto fld_name = fld.name(); - fld_name.replace("__", "."); - record[fld_name.toStdString()] = shv::coreqt::rpc::qVariantToRpcValue(fld.value()); +public: + Transaction(QSqlDatabase db) : m_db(db) { } - return record; -} + ~Transaction() { + if (m_inTransaction) { + m_db.rollback(); + } + } + void begin() { + if (!m_db.transaction()) { + qfWarning() << "BEGIN transaction error:" << m_db.lastError().text(); + throw std::runtime_error("BEGIN transaction error"); + } + m_inTransaction = true; + } + void commit() { + if (m_inTransaction) { + if (!m_db.commit()) { + qfWarning() << "COMMIT transaction error:" << m_db.lastError().text(); + throw std::runtime_error("COMMIT transaction error"); + } + m_inTransaction = false; + } + } +private: + QSqlDatabase m_db; + bool m_inTransaction = false; +}; -RpcSqlResult SqlApiNode::rpcSqlResultFromQuery(QSqlQuery &q) +RpcSqlResult rpcSqlQuery(const QString &query, const RpcValue ¶ms, bool in_transaction = false) { + auto conn = qf::core::sql::Connection::forName(); + Transaction tranaction(conn); + if (in_transaction) { + tranaction.begin(); + } + qf::core::sql::Query q(conn); + q.prepare(query, qf::core::Exception::Throw); + for (const auto &[k, v] : params.asMap()) { + bool ok; + QVariant val = shv::coreqt::rpc::rpcValueToQVariant(v, &ok); + if (!ok) { + QF_EXCEPTION(QStringLiteral("Cannot convert SHV type: %1 to QVariant").arg(v.typeName())); + } + q.bindValue(QString::fromStdString(k), val); + } + q.exec(qf::core::Exception::Throw); + if (in_transaction) { + tranaction.commit(); + } + RpcSqlResult ret; if(q.isSelect()) { QSqlRecord rec = q.record(); @@ -72,10 +93,12 @@ RpcSqlResult SqlApiNode::rpcSqlResultFromQuery(QSqlQuery &q) RpcSqlResult::Row row; for (int i = 0; i < rec.count(); ++i) { const QVariant v = q.value(i); - if (v.isNull()) - row.append(QVariant()); - else + if (v.isNull()) { + row.append(QVariant::fromValue(nullptr)); + } + else { row.append(v); + } //shvError() << v << v.isNull() << jsv.toVariant() << jsv.toVariant().isNull(); } ret.rows.insert(ret.rows.count(), row); @@ -88,14 +111,29 @@ RpcSqlResult SqlApiNode::rpcSqlResultFromQuery(QSqlQuery &q) return ret; } -static auto METH_EXEC_SQL = "execSql"; +auto METH_QUERY = "query"; +auto METH_EXEC = "exec"; +auto METH_TRANSACTION = "transaction"; +auto METH_LIST = "list"; +auto METH_CREATE = "create"; +auto METH_READ = "read"; +auto METH_UPDATE = "update"; +auto METH_DELETE = "delete"; +} const std::vector &SqlApiNode::metaMethods() { static std::vector meta_methods { methods::DIR, methods::LS, - {METH_EXEC_SQL, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Write}, + {METH_QUERY, MetaMethod::Flag::LargeResultHint, "[s:query,{s|i|b|t|n}:params]", "{{s:name}:fields,[[s|i|b|t|n]]:rows}", AccessLevel::Read}, + {METH_EXEC, MetaMethod::Flag::None, "[s:query,{s|i|b|t|n}:params]", "{i:rows_affected,i|n:insert_id}", AccessLevel::Write}, + {METH_TRANSACTION, MetaMethod::Flag::None, "[s:query,{s|i|b|t|n}:params]", "n", AccessLevel::Write}, + {METH_LIST, MetaMethod::Flag::LargeResultHint, "{s:table,[s]|n:fields,i|n:ids_above,i|n:limit}", "[{s|i|b|t|n}]", AccessLevel::Write}, + {METH_CREATE, MetaMethod::Flag::None, "{s:table,{s|i|b|t|n}:record}", "i", AccessLevel::Write}, + {METH_READ, MetaMethod::Flag::None, "{s:table,i:id,{s}|n:fields}", "{s|i|b|t|n}|n", AccessLevel::Read}, + {METH_UPDATE, MetaMethod::Flag::None, "{s:table,i:id,{s|i|b|t|n}:record}", "b", AccessLevel::Write}, + {METH_DELETE, MetaMethod::Flag::None, "{s:table,i:id}", "b", AccessLevel::Write}, }; return meta_methods; } @@ -105,13 +143,137 @@ RpcValue SqlApiNode::callMethod(const StringViewList &shv_path, const std::strin qfLogFuncFrame() << shv_path.join('/') << method; //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); if(shv_path.empty()) { - if(method == METH_EXEC_SQL) { - qf::core::sql::Query q; - QString qs = params.to(); - q.exec(qs, qf::core::Exception::Throw); - auto res = rpcSqlResultFromQuery(q); + if(method == METH_EXEC) { + auto sql_query = params.asList().valref(0).to(); + const auto &sql_params = params.asList().valref(0); + auto res = rpcSqlQuery(sql_query, sql_params); + return res.toRpcValue(); + } + if(method == METH_QUERY) { + auto sql_query = params.asList().valref(0).to(); + const auto &sql_params = params.asList().valref(0); + auto res = rpcSqlQuery(sql_query, sql_params); return res.toRpcValue(); } + if(method == METH_TRANSACTION) { + auto sql_query = params.asList().valref(0).to(); + const auto &sql_params = params.asList().valref(0); + auto res = rpcSqlQuery(sql_query, sql_params, true); + return RpcValue(nullptr); + } + if(method == METH_LIST) { + const auto &map = params.asMap(); + QStringList fields; + for (const auto &fn : map.valref("fields").asList()) { + fields << fn.to(); + } + if (fields.isEmpty()) { + fields << "*"; + } + QString sql_query = QStringLiteral("SELECT %1 FROM %2").arg(fields.join(',')).arg(map.value("table").to()); + if (auto ids_above = map.value("ids_above"); ids_above.isInt()) { + sql_query += " WHERE id > " + QString::number(ids_above.toInt()); + } + if (auto limit = map.value("limit"); limit.isInt()) { + sql_query += " LIMIT " + QString::number(limit.toInt()); + } + auto res = rpcSqlQuery(sql_query, {}); + if (res.rows.isEmpty()) { + return RpcValue(nullptr); + } + RpcValue::List ret; + for (const auto &row : res.rows) { + auto cells = row.toList(); + RpcValue::Map rec; + int n = 0; + for (const auto &field : res.fields) { + rec[field.name.toStdString()] = shv::coreqt::rpc::qVariantToRpcValue(cells.value(n++)); + } + ret.push_back(rec); + } + return ret; + } + if(method == METH_CREATE) { + const auto &map = params.asMap(); + auto table = map.valref("table").to(); + const auto &record = map.valref("record").asMap(); + QStringList fields; + QStringList placeholders; + for (const auto &[k, v] : record) { + auto name = QString::fromStdString(k); + fields << name; + placeholders << ':' + name; + } + QString sql_query = QStringLiteral("INSERT INTO %1 (%2) VALUES (%3)") + .arg(table) + .arg(fields.join(',')) + .arg(placeholders.join(',')); + qf::core::sql::Query q; + q.prepare(sql_query, qf::core::Exception::Throw); + for (const auto &[k, v] : record) { + q.bindValue(QString::fromStdString(k), shv::coreqt::rpc::rpcValueToQVariant(v)); + } + q.exec(qf::core::Exception::Throw); + return q.lastInsertId().toInt(); + } + if(method == METH_READ) { + const auto &map = params.asMap(); + QStringList fields; + for (const auto &fn : map.valref("fields").asList()) { + fields << fn.to(); + } + if (fields.isEmpty()) { + fields << "*"; + } + QString sql_query = QStringLiteral("SELECT %1 FROM %2 WHERE id = %3") + .arg(fields.join(',')) + .arg(map.value("table").to()) + .arg(map.value("id").toInt()) ; + auto res = rpcSqlQuery(sql_query, {}); + if (res.rows.isEmpty()) { + return RpcValue(nullptr); + } + RpcValue::Map rec; + auto cells = res.rows[0].toList(); + int n = 0; + for (const auto &field : res.fields) { + rec[field.name.toStdString()] = shv::coreqt::rpc::qVariantToRpcValue(cells.value(n++)); + } + return rec; + } + if(method == METH_UPDATE) { + const auto &map = params.asMap(); + auto table = map.valref("table").to(); + auto id = map.valref("id").toInt(); + const auto &record = map.valref("record").asMap(); + QStringList fields; + for (const auto &[k, v] : record) { + auto name = QString::fromStdString(k); + fields << name + " = :" + name; + } + QString sql_query = QStringLiteral("UPDATE %1 SET %2 WHERE id = %3") + .arg(table) + .arg(fields.join(',')) + .arg(id); + qf::core::sql::Query q; + q.prepare(sql_query, qf::core::Exception::Throw); + for (const auto &[k, v] : record) { + q.bindValue(QString::fromStdString(k), shv::coreqt::rpc::rpcValueToQVariant(v)); + } + q.exec(qf::core::Exception::Throw); + return q.numRowsAffected() == 1; + } + if(method == METH_DELETE) { + const auto &map = params.asMap(); + auto table = map.valref("table").to(); + auto id = map.valref("id").toInt(); + QString sql_query = QStringLiteral("DELETE FROM %1 WHERE id = %2") + .arg(table) + .arg(id); + qf::core::sql::Query q; + q.exec(sql_query, qf::core::Exception::Throw); + return q.numRowsAffected() == 1; + } } return Super::callMethod(shv_path, method, params, user_id); } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h index c2e112f26..a36f7ed8c 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.h @@ -16,9 +16,6 @@ class SqlApiNode : public QxNode using Super = QxNode; public: explicit SqlApiNode(shv::iotqt::node::ShvNode *parent); - - static shv::coreqt::data::RpcSqlResult rpcSqlResultFromQuery(QSqlQuery &q); - static shv::chainpack::RpcValue::Map recordToMap(const QSqlRecord &rec); protected: const std::vector &metaMethods() override; shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue ¶ms, const shv::chainpack::RpcValue &user_id) override; From 074f053e05525433f1a85ddaa3ff8e4f4cfcc5f1 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Mon, 10 Nov 2025 23:10:32 +0100 Subject: [PATCH 15/29] QxSQL API in QE --- 3rdparty/libshv | 2 +- libqf/libqfgui/src/tableview.cpp | 2 +- quickevent/app/quickevent/CMakeLists.txt | 6 +- .../Event/src/services/qx/qxeventservice.cpp | 54 +-- .../Event/src/services/qx/qxeventservice.h | 6 +- .../src/services/qx/qxeventservicewidget.cpp | 34 +- .../plugins/Event/src/services/qx/sqlapi.cpp | 406 ++++++++++++++++++ .../plugins/Event/src/services/qx/sqlapi.h | 88 ++++ .../Event/src/services/qx/sqlapinode.cpp | 217 ++-------- .../plugins/Runs/src/runstablewidget.cpp | 28 ++ .../plugins/Runs/src/runstablewidget.h | 3 + .../quickevent/plugins/Runs/src/runswidget.h | 15 +- 12 files changed, 601 insertions(+), 260 deletions(-) create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp create mode 100644 quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h diff --git a/3rdparty/libshv b/3rdparty/libshv index 40f0b3cf2..f108e5d72 160000 --- a/3rdparty/libshv +++ b/3rdparty/libshv @@ -1 +1 @@ -Subproject commit 40f0b3cf213ab799fb17bf6a31ce527a8851ee30 +Subproject commit f108e5d72729c16ee5b27ee8a9096182a5ceb7fa diff --git a/libqf/libqfgui/src/tableview.cpp b/libqf/libqfgui/src/tableview.cpp index 72cae3801..bd3183e59 100644 --- a/libqf/libqfgui/src/tableview.cpp +++ b/libqf/libqfgui/src/tableview.cpp @@ -1146,7 +1146,7 @@ void TableView::rowExternallySaved(const QVariant &id) qf::core::sql::Query q; bool ok = q.exec(query_str); if (!ok) { - qfInfo() << "Query:" << query_str; + qfMessage() << "Query:" << query_str; qfWarning() << "SQL error:" << q.lastErrorText(); return; } diff --git a/quickevent/app/quickevent/CMakeLists.txt b/quickevent/app/quickevent/CMakeLists.txt index 18208eab7..ab9e29298 100644 --- a/quickevent/app/quickevent/CMakeLists.txt +++ b/quickevent/app/quickevent/CMakeLists.txt @@ -1,5 +1,3 @@ -find_package(Qt6 REQUIRED COMPONENTS Core) - add_executable(quickevent plugins/CardReader/src/cardchecker.cpp plugins/CardReader/src/cardcheckerclassiccpp.cpp @@ -92,6 +90,7 @@ add_executable(quickevent plugins/Event/src/services/servicewidget.cpp plugins/Event/src/services/servicewidget.ui + plugins/Event/src/services/qx/sqlapi.h plugins/Event/src/services/qx/sqlapi.cpp plugins/Event/src/services/qx/qxnode.cpp plugins/Event/src/services/qx/sqlapinode.cpp plugins/Event/src/services/qx/nodes.cpp @@ -273,8 +272,7 @@ target_include_directories(quickevent PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAK target_link_libraries(quickevent PUBLIC libquickeventcore libquickeventgui libqfgui libsiut) if (QF_WITH_LIBSHV) target_link_libraries(quickevent PUBLIC libshviotqt) -target_link_libraries(quickevent PRIVATE Qt6::Core) -target_compile_definitions(quickevent PRIVATE QF_WITH_LIBSHV) + target_compile_definitions(quickevent PRIVATE QF_WITH_LIBSHV) endif() install(TARGETS quickevent) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index 8aa7f5642..320548969 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -2,6 +2,7 @@ #include "qxeventservicewidget.h" #include "nodes.h" #include "sqlapinode.h" +#include "sqlapi.h" #include "../../eventplugin.h" #include "../../../../Runs/src/runsplugin.h" @@ -77,7 +78,7 @@ void QxEventService::run() { m_rpcConnection->setConnectionString(ss.shvBrokerUrl()); RpcValue::Map opts; RpcValue::Map device; - device["mountPoint"] = "test/quickbox"; + device["mountPoint"] = "test/quickevent"; opts["device"] = device; m_rpcConnection->setConnectionOptions(opts); @@ -86,28 +87,9 @@ void QxEventService::run() { connect(m_rpcConnection, &ClientConnection::brokerLoginError, this, &QxEventService::onBrokerLoginError); connect(m_rpcConnection, &ClientConnection::rpcMessageReceived, this, &QxEventService::onRpcMessageReceived); - m_rpcConnection->open(); + connect(SqlApi::instance(), &SqlApi::recchng, this, &QxEventService::onRecchg); -// connect(reply, &QNetworkReply::finished, this, [this, reply, ss]() { -// if (reply->error() == QNetworkReply::NetworkError::NoError) { -// auto data = reply->readAll(); -// auto doc = QJsonDocument::fromJson(data); -// EventInfo event_info(doc.toVariant().toMap()); -// setStatusMessage(event_info.name() + (event_info.stage_count() > 1? QStringLiteral(" E%1").arg(event_info.stage()): QString())); -// m_eventId = event_info.id(); -// connectToSSE(m_eventId); -// if (!m_pollChangesTimer) { -// m_pollChangesTimer = new QTimer(this); -// connect(m_pollChangesTimer, &QTimer::timeout, this, &QxClientService::pollQxChanges); -// } -// pollQxChanges(); -// m_pollChangesTimer->start(10000); -// Super::run(); -// } -// else { -// qfWarning() << "Cannot run QX service, network error:" << reply->errorString(); -// } -// }); + m_rpcConnection->open(); } void QxEventService::stop() @@ -615,6 +597,10 @@ void QxEventService::onRpcMessageReceived(const shv::chainpack::RpcMessage &msg) // shvLogFuncFrame() << msg.toCpon(); if(msg.isRequest()) { RpcRequest rq(msg); + if (rq.shvPath().asString().starts_with(".broker/")) { + // ignore broker discovery messages + return; + } qfMessage() << "RPC request received:" << rq.toPrettyString(); m_rootNode->handleRpcRequest(rq); } @@ -641,36 +627,22 @@ void QxEventService::subscribeChanges() QString shv_path = "test"; QString signal_name = shv::chainpack::Rpc::SIG_VAL_CHANGED; auto *rpc_call = RpcCall::createSubscriptionRequest(m_rpcConnection, shv_path, signal_name); - connect(rpc_call, &RpcCall::maybeResult, this, [this, shv_path, signal_name](const ::shv::chainpack::RpcValue &result, const shv::chainpack::RpcError &error) { + connect(rpc_call, &RpcCall::maybeResult, this, [shv_path, signal_name](const ::shv::chainpack::RpcValue &result, const shv::chainpack::RpcError &error) { if(error.isValid()) { qfError() << "Signal:" << signal_name << "on SHV path:" << shv_path << "subscribe error:" << error.toString(); } else { qfMessage() << "Signal:" << signal_name << "on SHV path:" << shv_path << "subscribed successfully" << result.toCpon(); - // generate data change without ret value check - m_rpcConnection->callShvMethod((shv_path + "/someInt").toStdString(), "set", 123); - QTimer::singleShot(500, this, [this, shv_path]() { - m_rpcConnection->callShvMethod((shv_path + "/someInt").toStdString(), "set", 321); - }); } }); rpc_call->start(); } -void QxEventService::testRpcCall() const +void QxEventService::onRecchg(const QxRecChng &chng) { - Q_ASSERT(m_rpcConnection); - auto *rpc_call = RpcCall::create(m_rpcConnection) - ->setShvPath("test") - ->setMethod("ls"); -// ->setTimeout(5000); - connect(rpc_call, &RpcCall::maybeResult, [](const ::shv::chainpack::RpcValue &result, const shv::chainpack::RpcError &error) { - if(error.isValid()) - qfError() << "RPC call error:" << error.toString(); - else - qfInfo() << "Got RPC response, result:" << result.toCpon(); - }); - rpc_call->start(); + if (isRunning()) { + m_rpcConnection->sendShvSignal("sql", "recchng", chng.toRpcValue()); + } } } // namespace Event::services::qx diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h index 2a103a9d7..b25076626 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h @@ -13,11 +13,13 @@ namespace shv::chainpack { class RpcMessage; class RpcError; } namespace Event::services::qx { +struct QxRecChng; + class QxEventServiceSettings : public ServiceSettings { using Super = ServiceSettings; - QF_VARIANTMAP_FIELD2(QString, s, setS, hvBrokerUrl, "http://localhost:8000") + QF_VARIANTMAP_FIELD2(QString, s, setS, hvBrokerUrl, "tcp://localhost?user=test&password=test") public: QxEventServiceSettings(const QVariantMap &o = QVariantMap()) : Super(o) {} }; @@ -78,9 +80,9 @@ class QxEventService : public Service void sendRpcMessage(const shv::chainpack::RpcMessage &rpc_msg); void onBrokerSocketError(const QString &err); void onBrokerLoginError(const shv::chainpack::RpcError &err); + void onRecchg(const QxRecChng &chng); void subscribeChanges(); - void testRpcCall() const; private: void loadSettings() override; qf::gui::framework::DialogWidget *createDetailWidget() override; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp index 416bb25b4..125d70f16 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp @@ -1,5 +1,6 @@ #include "qxeventservicewidget.h" #include "ui_qxeventservicewidget.h" + #include "qxeventservice.h" #include @@ -8,6 +9,8 @@ #include #include +#include + #include #include #include @@ -113,22 +116,27 @@ void QxEventServiceWidget::updateOCheckListPostUrl() void QxEventServiceWidget::testConnection() { - auto *svc = service(); - Q_ASSERT(svc); - auto *reply = svc->getRemoteEventInfo(ui->edServerUrl->text(), ui->edApiToken->text()); - connect(reply, &QNetworkReply::finished, this, [this, reply]() { - if (reply->error() == QNetworkReply::NetworkError::NoError) { - auto data = reply->readAll(); - auto doc = QJsonDocument::fromJson(data); - EventInfo event_info(doc.toVariant().toMap()); - ui->edEventId->setValue(event_info.id()); + using namespace shv::iotqt::rpc; + using namespace shv::chainpack; + + auto *rpc = new DeviceConnection(this); + rpc->setConnectionString(ui->edServerUrl->text()); + + connect(rpc, &ClientConnection::brokerConnectedChanged, this, [this, rpc](bool is_connected) { + if (is_connected) { + rpc->deleteLater(); setMessage(tr("Connected OK")); } - else { - setMessage(tr("Connection error: %1").arg(reply->errorString()), MessageType::Error); - } - reply->deleteLater(); }); + connect(rpc, &ClientConnection::socketError, this, [this, rpc](const QString &error) { + rpc->deleteLater(); + setMessage(tr("Connection error: %1").arg(error), MessageType::Error); + }); + connect(rpc, &ClientConnection::brokerLoginError, this, [this, rpc](const auto &error) { + rpc->deleteLater(); + setMessage(tr("Login error: %1").arg(QString::fromStdString(error.toString())), MessageType::Error); + }); + rpc->open(); } void QxEventServiceWidget::exportEventInfo() diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp new file mode 100644 index 000000000..fde4ae512 --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp @@ -0,0 +1,406 @@ +#include "sqlapi.h" + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +using namespace shv::chainpack; + +namespace Event::services::qx { + +//============================================== +// RpcSqlField +//============================================== +RpcValue RpcSqlField::toRpcValue() const +{ + RpcValue::Map ret; + ret["name"] = name; + return RpcValue(std::move(ret)); +} + +RpcSqlField RpcSqlField::fromRpcValue(const shv::chainpack::RpcValue &rv) +{ + RpcSqlField ret; + const RpcValue::Map &map = rv.asMap(); + ret.name = map.value("name").asString(); + return ret; +} + +//============================================== +// RpcSqlResult +//============================================== +const RpcValue &RpcSqlResult::value(size_t row, size_t col) const +{ + if (row < rows.size()) { + const auto &cells = rows[row]; + if (col < cells.size()) { + return cells[col]; + } + } + static RpcValue s; + return s; +} + +const RpcValue& RpcSqlResult::value(size_t row, const std::string &name) const +{ + if (auto ix = columnIndex(name); ix.has_value()) { + return value(row, ix.value()); + } + static RpcValue s; + return s; +} + +void RpcSqlResult::setValue(size_t row, size_t col, const RpcValue &val) +{ + if (row < rows.size()) { + auto &r = rows[row]; + if (col < r.size()) { + r[col] = val; + } + } +} + +void RpcSqlResult::setValue(size_t row, const std::string &name, const RpcValue &val) +{ + if (auto ix = columnIndex(name); ix.has_value()) { + setValue(row, ix.value(), val); + } +} + +RpcValue::List RpcSqlResult::toRecordList() const +{ + RpcValue::List ret; + for (const auto &row : rows) { + SqlRecord rec; + int n = 0; + for (const auto &field : fields) { + rec[field.name] = row[n++]; + } + ret.push_back(rec); + } + return ret; +} + +std::optional RpcSqlResult::columnIndex(const std::string &name) const +{ + for (size_t col = 0; col < fields.size(); ++col) { + const auto &fld = fields[col]; + if (fld.name == name) { + return col; + } + } + return {}; +} + +RpcValue RpcSqlResult::toRpcValue() const +{ + RpcValue::Map ret; + if(isSelect()) { + RpcValue::List flds; + for(const auto &fld : this->fields) + flds.push_back(fld.toRpcValue()); + ret["fields"] = flds; + ret["rows"] = rows; + } + else { + ret["numRowsAffected"] = numRowsAffected; + ret["lastInsertId"] = lastInsertId.has_value()? RpcValue(lastInsertId.value()): RpcValue(nullptr); + } + return ret; +} + +RpcSqlResult RpcSqlResult::fromRpcValue(const RpcValue &rv) +{ + RpcSqlResult ret; + const auto &map = rv.asMap(); + const auto &flds = map.valref("fields").asList(); + if(flds.empty()) { + ret.numRowsAffected = map.value("numRowsAffected").toInt(); + ret.lastInsertId = map.value("lastInsertId").toInt(); + } + else { + for(const auto &fv : flds) { + ret.fields.push_back(RpcSqlField::fromRpcValue(fv)); + } + for (const auto &row : map.value("rows").asList()) { + ret.rows.push_back(row.asList()); + } + } + return ret; +} + +SqlQueryAndParams SqlQueryAndParams::fromRpcValue(const shv::chainpack::RpcValue &rv) +{ + auto sql_query = rv.asList().valref(0).asString(); + const auto &sql_params = rv.asList().valref(0); + return SqlQueryAndParams { .query = sql_query, .params = sql_params.asMap() }; +} + +RpcValue QxRecChng::toRpcValue() const +{ + RpcValue::Map ret; + ret["table"] = table.toStdString(); + ret["id"] = id; + ret["record"] = shv::coreqt::rpc::qVariantToRpcValue(record); + auto rec_op_string = [](RecOp op) { + switch (op) { + case RecOp::Insert: return "Insert"; + case RecOp::Update: return "Update"; + case RecOp::Delete: return "Delete"; + } + return ""; + }; + ret["op"] = rec_op_string(op); + return ret; +} + +//============================================== +// SqlApi +//============================================== +SqlApi::SqlApi(QObject *parent) + : QObject{parent} +{ + +} + +SqlApi *SqlApi::instance() +{ + static auto *api = new SqlApi(QCoreApplication::instance()); + return api; +} + +namespace { + +class Transaction +{ +public: + Transaction(QSqlDatabase db) : m_db(db) { + if (!m_db.transaction()) { + qfWarning() << "BEGIN transaction error:" << m_db.lastError().text(); + throw std::runtime_error("BEGIN transaction error"); + } + } + ~Transaction() { + if (m_inTransaction) { + m_db.rollback(); + } + } + void commit() { + if (!m_db.commit()) { + qfWarning() << "COMMIT transaction error:" << m_db.lastError().text(); + throw std::runtime_error("COMMIT transaction error"); + } + m_inTransaction = false; + } +private: + QSqlDatabase m_db; + bool m_inTransaction = true; +}; + +RpcSqlResult rpcSqlQuery(const SqlQueryAndParams ¶ms) +{ + qf::core::sql::Query q; + q.prepare(QString::fromUtf8(params.query), qf::core::Exception::Throw); + for (const auto &[k, v] : params.params) { + bool ok; + QVariant val = shv::coreqt::rpc::rpcValueToQVariant(v, &ok); + if (!ok) { + QF_EXCEPTION(QStringLiteral("Cannot convert SHV type: %1 to QVariant").arg(v.typeName())); + } + q.bindValue(':' + QString::fromStdString(k), val); + } + q.exec(qf::core::Exception::Throw); + RpcSqlResult ret; + if(q.isSelect()) { + QSqlRecord rec = q.record(); + for (int i = 0; i < rec.count(); ++i) { + QSqlField fld = rec.field(i); + RpcSqlField rfld; + rfld.name = fld.name().toStdString(); + // rfld.name.replace("__", "."); + ret.fields.push_back(rfld); + } + while(q.next()) { + RpcSqlResult::Row row; + for (int i = 0; i < rec.count(); ++i) { + const QVariant v = q.value(i); + if (v.isNull()) { + row.push_back(RpcValue(nullptr)); + } + else { + row.push_back(shv::coreqt::rpc::qVariantToRpcValue(v)); + } + //shvError() << v << v.isNull() << jsv.toVariant() << jsv.toVariant().isNull(); + } + ret.rows.push_back(row); + } + } + else { + ret.numRowsAffected = q.numRowsAffected(); + ret.lastInsertId = q.lastInsertId().toInt(); + } + return ret; +} + +} + +RpcSqlResult SqlApi::exec(const SqlQueryAndParams ¶ms) +{ + return rpcSqlQuery(params); +} + +RpcSqlResult SqlApi::query(const SqlQueryAndParams ¶ms) +{ + return rpcSqlQuery(params); +} + +void SqlApi::transaction(const std::string &query, const shv::chainpack::RpcValue::List ¶ms) +{ + auto conn = qf::core::sql::Connection::forName(); + Transaction tranaction(conn); + qf::core::sql::Query q(conn); + q.prepare(QString::fromUtf8(query), qf::core::Exception::Throw); + for (const auto ¶m : params) { + for (const auto &[k, v] : param.asMap()) { + bool ok; + QVariant val = shv::coreqt::rpc::rpcValueToQVariant(v, &ok); + if (!ok) { + QF_EXCEPTION(QStringLiteral("Cannot convert SHV type: %1 to QVariant").arg(v.typeName())); + } + q.bindValue(':' + QString::fromStdString(k), val); + } + q.exec(qf::core::Exception::Throw); + } + tranaction.commit(); +} + +RpcSqlResult SqlApi::list(const std::string &table, const std::vector &fields, std::optional ids_above, std::optional limit) +{ + QStringList qfields; + for (const auto &fn : fields) { + qfields << QString::fromStdString(fn); + } + if (qfields.isEmpty()) { + qfields << "*"; + } + QString sql_query = QStringLiteral("SELECT %1 FROM %2").arg(qfields.join(',')).arg(QString::fromStdString(table)); + if (ids_above.has_value()) { + sql_query += " WHERE id > " + QString::number(ids_above.value()); + } + if (limit.has_value()) { + sql_query += " LIMIT " + QString::number(limit.value()); + } + auto res = rpcSqlQuery(SqlQueryAndParams { .query = sql_query.toStdString(), .params = {}}); + return res; +} + +int64_t SqlApi::create(const std::string &table, const SqlRecord &record) +{ + QStringList fields; + QStringList placeholders; + for (const auto &[k, v] : record) { + auto name = QString::fromStdString(k); + fields << name; + placeholders << ':' + name; + } + QString sql_query = QStringLiteral("INSERT INTO %1 (%2) VALUES (%3)") + .arg(table) + .arg(fields.join(',')) + .arg(placeholders.join(',')); + qf::core::sql::Query q; + q.prepare(sql_query, qf::core::Exception::Throw); + for (const auto &[k, v] : record) { + q.bindValue(':' + QString::fromStdString(k), shv::coreqt::rpc::rpcValueToQVariant(v)); + } + q.exec(qf::core::Exception::Throw); + auto id = q.lastInsertId().toInt(); + emit SqlApi::instance()->recchng(QxRecChng { + .table = QString::fromStdString(table), + .id = id, + .record = shv::coreqt::rpc::rpcValueToQVariant(record), + .op = RecOp::Insert + }); + return id; +} + +std::optional SqlApi::read(const std::string &table, int64_t id, const std::vector &fields) +{ + QStringList qfields; + for (const auto &fn : fields) { + qfields << QString::fromStdString(fn); + } + if (qfields.isEmpty()) { + qfields << "*"; + } + QString sql_query = QStringLiteral("SELECT %1 FROM %2 WHERE id = %3") + .arg(qfields.join(',')) + .arg(QString::fromStdString(table)) + .arg(id) ; + auto res = rpcSqlQuery(SqlQueryAndParams { .query = sql_query.toStdString(), .params = {}}); + auto lst = res.toRecordList(); + if (lst.empty()) { + return {}; + } + return lst[0].asMap(); +} + +bool SqlApi::update(const std::string &table, int64_t id, const SqlRecord &record) +{ + QStringList fields; + for (const auto &[k, v] : record) { + auto name = QString::fromStdString(k); + fields << name + " = :" + name; + } + QString sql_query = QStringLiteral("UPDATE %1 SET %2 WHERE id = %3") + .arg(table) + .arg(fields.join(',')) + .arg(id); + qf::core::sql::Query q; + q.prepare(sql_query, qf::core::Exception::Throw); + for (const auto &[k, v] : record) { + auto qv = shv::coreqt::rpc::rpcValueToQVariant(v); + q.bindValue(':' + QString::fromStdString(k), qv); + } + q.exec(qf::core::Exception::Throw); + bool updated = q.numRowsAffected() == 1; + if (updated) { + emit SqlApi::instance()->recchng(QxRecChng { + .table = QString::fromStdString(table), + .id = id, + .record = shv::coreqt::rpc::rpcValueToQVariant(record), + .op = RecOp::Update + }); + } + return updated; +} + +bool SqlApi::drop(const std::string &table, int64_t id) +{ + QString sql_query = QStringLiteral("DELETE FROM %1 WHERE id = %2") + .arg(table) + .arg(id); + qf::core::sql::Query q; + q.exec(sql_query, qf::core::Exception::Throw); + bool is_drop = q.numRowsAffected() == 1; + if (is_drop) { + emit SqlApi::instance()->recchng(QxRecChng { + .table = QString::fromStdString(table), + .id = id, + .record = {}, + .op = RecOp::Delete + }); + } + return is_drop; +} + +} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h new file mode 100644 index 000000000..3594ca510 --- /dev/null +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h @@ -0,0 +1,88 @@ +#pragma once + +#include + +#include +#include + +namespace Event::services::qx { + +struct RpcSqlField +{ + std::string name; + + //explicit RpcSqlField(const QJsonObject &jo = QJsonObject()) : Super(jo) {} + shv::chainpack::RpcValue toRpcValue() const; + // QVariant toVariant() const; + static RpcSqlField fromRpcValue(const shv::chainpack::RpcValue &rv); + // static RpcSqlField fromVariant(const QVariant &v); +}; + +struct RpcSqlResult +{ + int numRowsAffected = 0; + std::optional lastInsertId = 0; + std::vector fields; + using Row = shv::chainpack::RpcValue::List; + std::vector rows; + + RpcSqlResult() = default; + // explicit RpcSqlResult(const QSqlQuery &q); + + std::optional columnIndex(const std::string &name) const; + const shv::chainpack::RpcValue& value(size_t row, size_t col) const; + const shv::chainpack::RpcValue& value(size_t row, const std::string &name) const; + void setValue(size_t row, size_t col, const shv::chainpack::RpcValue &val); + void setValue(size_t row, const std::string &name, const shv::chainpack::RpcValue &val); + + bool isSelect() const {return !fields.empty();} + shv::chainpack::RpcValue toRpcValue() const; + shv::chainpack::RpcValue::List toRecordList() const; + // QVariant toVariant() const; + // static RpcSqlResult fromVariant(const QVariant &v); + static RpcSqlResult fromRpcValue(const shv::chainpack::RpcValue &rv); +}; + +using SqlRecord = shv::chainpack::RpcValue::Map; + +struct SqlQueryAndParams +{ + std::string query; + SqlRecord params; + + static SqlQueryAndParams fromRpcValue(const shv::chainpack::RpcValue &rv); +}; + +enum class RecOp { Insert, Update, Delete, }; + +struct QxRecChng +{ + QString table; + int64_t id; + QVariant record; + RecOp op; + + shv::chainpack::RpcValue toRpcValue() const; +}; + +class SqlApi : public QObject +{ + Q_OBJECT +public: + static SqlApi* instance(); + + Q_SIGNAL void recchng(const QxRecChng &chng); + + static RpcSqlResult exec(const SqlQueryAndParams ¶ms); + static RpcSqlResult query(const SqlQueryAndParams ¶ms); + static void transaction(const std::string &query, const shv::chainpack::RpcValue::List ¶ms); + static RpcSqlResult list(const std::string &table, const std::vector &fields, std::optional ids_above, std::optional limit); + static int64_t create(const std::string &table, const SqlRecord &record); + static std::optional read(const std::string &table, int64_t id, const std::vector &fields); + static bool update(const std::string &table, int64_t id, const SqlRecord &record); + static bool drop(const std::string &table, int64_t id); +private: + explicit SqlApi(QObject *parent = nullptr); +}; + +} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp index 846e6c7e6..d12474363 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp @@ -1,4 +1,5 @@ #include "sqlapinode.h" +#include "sqlapi.h" #include #include @@ -21,96 +22,9 @@ namespace Event::services::qx { SqlApiNode::SqlApiNode(shv::iotqt::node::ShvNode *parent) : Super("sql", parent) { - } namespace { -class Transaction -{ -public: - Transaction(QSqlDatabase db) : m_db(db) { - } - ~Transaction() { - if (m_inTransaction) { - m_db.rollback(); - } - } - void begin() { - if (!m_db.transaction()) { - qfWarning() << "BEGIN transaction error:" << m_db.lastError().text(); - throw std::runtime_error("BEGIN transaction error"); - } - m_inTransaction = true; - } - void commit() { - if (m_inTransaction) { - if (!m_db.commit()) { - qfWarning() << "COMMIT transaction error:" << m_db.lastError().text(); - throw std::runtime_error("COMMIT transaction error"); - } - m_inTransaction = false; - } - } -private: - QSqlDatabase m_db; - bool m_inTransaction = false; -}; - -RpcSqlResult rpcSqlQuery(const QString &query, const RpcValue ¶ms, bool in_transaction = false) -{ - auto conn = qf::core::sql::Connection::forName(); - Transaction tranaction(conn); - if (in_transaction) { - tranaction.begin(); - } - qf::core::sql::Query q(conn); - q.prepare(query, qf::core::Exception::Throw); - for (const auto &[k, v] : params.asMap()) { - bool ok; - QVariant val = shv::coreqt::rpc::rpcValueToQVariant(v, &ok); - if (!ok) { - QF_EXCEPTION(QStringLiteral("Cannot convert SHV type: %1 to QVariant").arg(v.typeName())); - } - q.bindValue(QString::fromStdString(k), val); - } - q.exec(qf::core::Exception::Throw); - if (in_transaction) { - tranaction.commit(); - } - - RpcSqlResult ret; - if(q.isSelect()) { - QSqlRecord rec = q.record(); - for (int i = 0; i < rec.count(); ++i) { - QSqlField fld = rec.field(i); - RpcSqlField rfld; - rfld.name = fld.name(); - rfld.name.replace("__", "."); - rfld.type = fld.metaType().id(); - ret.fields.append(rfld); - } - while(q.next()) { - RpcSqlResult::Row row; - for (int i = 0; i < rec.count(); ++i) { - const QVariant v = q.value(i); - if (v.isNull()) { - row.append(QVariant::fromValue(nullptr)); - } - else { - row.append(v); - } - //shvError() << v << v.isNull() << jsv.toVariant() << jsv.toVariant().isNull(); - } - ret.rows.insert(ret.rows.count(), row); - } - } - else { - ret.numRowsAffected = q.numRowsAffected(); - ret.lastInsertId = q.lastInsertId().toInt(); - } - return ret; -} - auto METH_QUERY = "query"; auto METH_EXEC = "exec"; auto METH_TRANSACTION = "transaction"; @@ -128,7 +42,7 @@ const std::vector &SqlApiNode::metaMethods() methods::LS, {METH_QUERY, MetaMethod::Flag::LargeResultHint, "[s:query,{s|i|b|t|n}:params]", "{{s:name}:fields,[[s|i|b|t|n]]:rows}", AccessLevel::Read}, {METH_EXEC, MetaMethod::Flag::None, "[s:query,{s|i|b|t|n}:params]", "{i:rows_affected,i|n:insert_id}", AccessLevel::Write}, - {METH_TRANSACTION, MetaMethod::Flag::None, "[s:query,{s|i|b|t|n}:params]", "n", AccessLevel::Write}, + {METH_TRANSACTION, MetaMethod::Flag::None, "[s:query,[{s|i|b|t|n}]:params]", "n", AccessLevel::Write}, {METH_LIST, MetaMethod::Flag::LargeResultHint, "{s:table,[s]|n:fields,i|n:ids_above,i|n:limit}", "[{s|i|b|t|n}]", AccessLevel::Write}, {METH_CREATE, MetaMethod::Flag::None, "{s:table,{s|i|b|t|n}:record}", "i", AccessLevel::Write}, {METH_READ, MetaMethod::Flag::None, "{s:table,i:id,{s}|n:fields}", "{s|i|b|t|n}|n", AccessLevel::Read}, @@ -144,135 +58,66 @@ RpcValue SqlApiNode::callMethod(const StringViewList &shv_path, const std::strin //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); if(shv_path.empty()) { if(method == METH_EXEC) { - auto sql_query = params.asList().valref(0).to(); - const auto &sql_params = params.asList().valref(0); - auto res = rpcSqlQuery(sql_query, sql_params); + auto res = SqlApi::exec(SqlQueryAndParams::fromRpcValue(params)); return res.toRpcValue(); } if(method == METH_QUERY) { - auto sql_query = params.asList().valref(0).to(); - const auto &sql_params = params.asList().valref(0); - auto res = rpcSqlQuery(sql_query, sql_params); + auto res = SqlApi::exec(SqlQueryAndParams::fromRpcValue(params)); return res.toRpcValue(); } if(method == METH_TRANSACTION) { - auto sql_query = params.asList().valref(0).to(); + auto sql_query = params.asList().valref(0).asString(); const auto &sql_params = params.asList().valref(0); - auto res = rpcSqlQuery(sql_query, sql_params, true); + SqlApi::transaction(sql_query, sql_params.asList()); return RpcValue(nullptr); } if(method == METH_LIST) { const auto &map = params.asMap(); - QStringList fields; + const auto &table = map.value("table").asString(); + std::vector fields; for (const auto &fn : map.valref("fields").asList()) { - fields << fn.to(); - } - if (fields.isEmpty()) { - fields << "*"; - } - QString sql_query = QStringLiteral("SELECT %1 FROM %2").arg(fields.join(',')).arg(map.value("table").to()); - if (auto ids_above = map.value("ids_above"); ids_above.isInt()) { - sql_query += " WHERE id > " + QString::number(ids_above.toInt()); - } - if (auto limit = map.value("limit"); limit.isInt()) { - sql_query += " LIMIT " + QString::number(limit.toInt()); - } - auto res = rpcSqlQuery(sql_query, {}); - if (res.rows.isEmpty()) { - return RpcValue(nullptr); + fields.push_back(fn.asString()); } - RpcValue::List ret; - for (const auto &row : res.rows) { - auto cells = row.toList(); - RpcValue::Map rec; - int n = 0; - for (const auto &field : res.fields) { - rec[field.name.toStdString()] = shv::coreqt::rpc::qVariantToRpcValue(cells.value(n++)); - } - ret.push_back(rec); - } - return ret; + auto ids_above = map.contains("ids_above")? std::optional(map.value("ids_above").toInt64()): std::optional(); + auto limit = map.contains("limit")? std::optional(map.value("limit").toInt64()): std::optional(); + auto res = SqlApi::list(table, fields, ids_above, limit); + return res.toRecordList(); } if(method == METH_CREATE) { const auto &map = params.asMap(); - auto table = map.valref("table").to(); + const auto &table = map.value("table").asString(); const auto &record = map.valref("record").asMap(); - QStringList fields; - QStringList placeholders; - for (const auto &[k, v] : record) { - auto name = QString::fromStdString(k); - fields << name; - placeholders << ':' + name; - } - QString sql_query = QStringLiteral("INSERT INTO %1 (%2) VALUES (%3)") - .arg(table) - .arg(fields.join(',')) - .arg(placeholders.join(',')); - qf::core::sql::Query q; - q.prepare(sql_query, qf::core::Exception::Throw); - for (const auto &[k, v] : record) { - q.bindValue(QString::fromStdString(k), shv::coreqt::rpc::rpcValueToQVariant(v)); - } - q.exec(qf::core::Exception::Throw); - return q.lastInsertId().toInt(); + auto res = SqlApi::create(table, record); + return res; } if(method == METH_READ) { const auto &map = params.asMap(); - QStringList fields; + const auto &table = map.value("table").asString(); + auto id = map.value("id").toInt64(); + std::vector fields; for (const auto &fn : map.valref("fields").asList()) { - fields << fn.to(); - } - if (fields.isEmpty()) { - fields << "*"; - } - QString sql_query = QStringLiteral("SELECT %1 FROM %2 WHERE id = %3") - .arg(fields.join(',')) - .arg(map.value("table").to()) - .arg(map.value("id").toInt()) ; - auto res = rpcSqlQuery(sql_query, {}); - if (res.rows.isEmpty()) { - return RpcValue(nullptr); + fields.push_back(fn.asString()); } - RpcValue::Map rec; - auto cells = res.rows[0].toList(); - int n = 0; - for (const auto &field : res.fields) { - rec[field.name.toStdString()] = shv::coreqt::rpc::qVariantToRpcValue(cells.value(n++)); + auto res = SqlApi::read(table, id, fields); + if (res.has_value()) { + return res.value(); } - return rec; + return RpcValue(nullptr); } if(method == METH_UPDATE) { const auto &map = params.asMap(); - auto table = map.valref("table").to(); - auto id = map.valref("id").toInt(); + const auto &table = map.value("table").asString(); + auto id = map.value("id").toInt64(); const auto &record = map.valref("record").asMap(); - QStringList fields; - for (const auto &[k, v] : record) { - auto name = QString::fromStdString(k); - fields << name + " = :" + name; - } - QString sql_query = QStringLiteral("UPDATE %1 SET %2 WHERE id = %3") - .arg(table) - .arg(fields.join(',')) - .arg(id); - qf::core::sql::Query q; - q.prepare(sql_query, qf::core::Exception::Throw); - for (const auto &[k, v] : record) { - q.bindValue(QString::fromStdString(k), shv::coreqt::rpc::rpcValueToQVariant(v)); - } - q.exec(qf::core::Exception::Throw); - return q.numRowsAffected() == 1; + auto res = SqlApi::update(table, id, record); + return res; } if(method == METH_DELETE) { const auto &map = params.asMap(); - auto table = map.valref("table").to(); + const auto &table = map.value("table").asString(); auto id = map.valref("id").toInt(); - QString sql_query = QStringLiteral("DELETE FROM %1 WHERE id = %2") - .arg(table) - .arg(id); - qf::core::sql::Query q; - q.exec(sql_query, qf::core::Exception::Throw); - return q.numRowsAffected() == 1; + auto res = SqlApi::drop(table, id); + return res; } } return Super::callMethod(shv_path, method, params, user_id); diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index 175446b03..34b4c29f9 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -20,6 +20,12 @@ #include #include +#include +#include +#include +#include +#include + #include #include #include @@ -129,6 +135,8 @@ RunsTableWidget::RunsTableWidget(QWidget *parent) : } } }, Qt::QueuedConnection); + + connect(Event::services::qx::SqlApi::instance(), &Event::services::qx::SqlApi::recchng, this, &RunsTableWidget::onQxRecChng); } RunsTableWidget::~RunsTableWidget() @@ -430,4 +438,24 @@ void RunsTableWidget::onBadTableDataInput(const QString &message) qf::gui::dialogs::MessageBox::showError(this, message); } +void RunsTableWidget::onQxRecChng(const Event::services::qx::QxRecChng &chng) +{ + std::optional run_id; + if (chng.table == "competitors") { + auto *m = m_runsModel; + for (auto i=0; irowCount(); ++i) { + if (m->table().row(i).value("competitors.id").toInt() == chng.id) { + run_id = m->value(i, "runs.id").toInt(); + break; + } + } + } + else if (chng.table == "runs") { + run_id = chng.id; + } + if (run_id.has_value()) { + ui->tblRuns->rowExternallySaved(run_id.value()); + } +} + diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h index 8ba2e0964..a5379f689 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h @@ -7,6 +7,7 @@ class RunsTableItemDelegate; class CourseItemDelegate; namespace qf::gui { class TableView; } +namespace Event::services::qx { struct QxRecChng; } namespace Ui { class RunsTableWidget; @@ -36,6 +37,8 @@ class RunsTableWidget : public QWidget void onCustomContextMenuRequest(const QPoint &pos); void onTableViewSqlException(const QString &what, const QString &where, const QString &stack_trace); void onBadTableDataInput(const QString &message); + + void onQxRecChng(const Event::services::qx::QxRecChng &chng); private: Ui::RunsTableWidget *ui; RunsTableModel *m_runsModel; diff --git a/quickevent/app/quickevent/plugins/Runs/src/runswidget.h b/quickevent/app/quickevent/plugins/Runs/src/runswidget.h index 9be9da658..9335be37d 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runswidget.h +++ b/quickevent/app/quickevent/plugins/Runs/src/runswidget.h @@ -11,19 +11,11 @@ class QTextStream; class QLabel; namespace qf { -namespace core { -namespace model { -class SqlTableModel; -} -} -namespace gui { -class ForeignKeyComboBox; -} +namespace core { namespace model { class SqlTableModel; } } +namespace gui { class ForeignKeyComboBox; } } -namespace Event { -class EventPlugin; -} +namespace Event { class EventPlugin; } namespace Ui { class RunsWidget; @@ -69,7 +61,6 @@ class RunsWidget : public QFrame void onDrawRemoveClicked(); void onCbxStageCurrentIndexChanged(); private: - /** * @brief runnersInClubsHistogram * @return list of runs.id for each club sorted by their count, longest list of runners is first From e4c5d38cbfb6f177fa33710b33137c9e7784f2aa Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Wed, 12 Nov 2025 21:15:09 +0100 Subject: [PATCH 16/29] Do not reload whole row on qxSqlApi update recchng --- libqf/libqfcore/src/utils/table.cpp | 4 +++- .../plugins/Event/src/services/qx/sqlapi.cpp | 14 +++++++------- .../plugins/Event/src/services/qx/sqlapi.h | 4 ++-- .../plugins/Runs/src/runstablewidget.cpp | 18 +++++++++++++++++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libqf/libqfcore/src/utils/table.cpp b/libqf/libqfcore/src/utils/table.cpp index 78d073307..c4210506b 100644 --- a/libqf/libqfcore/src/utils/table.cpp +++ b/libqf/libqfcore/src/utils/table.cpp @@ -1310,7 +1310,8 @@ QVariant Table::sumValue(int field_ix) const return ret; } -static void setDomElementText(QDomDocument &owner_doc, QDomElement &el, const QString &str) +namespace { +void setDomElementText(QDomDocument &owner_doc, QDomElement &el, const QString &str) { QDomNode nd = el.firstChild(); QDomText el_txt = nd.toText(); @@ -1322,6 +1323,7 @@ static void setDomElementText(QDomDocument &owner_doc, QDomElement &el, const QS el_txt.setData(str); } } +} QDomElement Table::toHtmlElement(QDomDocument &owner_doc, const QString & col_names, TextExportOptions opts) const { diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp index fde4ae512..2c58823bf 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp @@ -152,11 +152,11 @@ RpcValue QxRecChng::toRpcValue() const ret["table"] = table.toStdString(); ret["id"] = id; ret["record"] = shv::coreqt::rpc::qVariantToRpcValue(record); - auto rec_op_string = [](RecOp op) { + auto rec_op_string = [](QxRecOp op) { switch (op) { - case RecOp::Insert: return "Insert"; - case RecOp::Update: return "Update"; - case RecOp::Delete: return "Delete"; + case QxRecOp::Insert: return "Insert"; + case QxRecOp::Update: return "Update"; + case QxRecOp::Delete: return "Delete"; } return ""; }; @@ -328,7 +328,7 @@ int64_t SqlApi::create(const std::string &table, const SqlRecord &record) .table = QString::fromStdString(table), .id = id, .record = shv::coreqt::rpc::rpcValueToQVariant(record), - .op = RecOp::Insert + .op = QxRecOp::Insert }); return id; } @@ -378,7 +378,7 @@ bool SqlApi::update(const std::string &table, int64_t id, const SqlRecord &recor .table = QString::fromStdString(table), .id = id, .record = shv::coreqt::rpc::rpcValueToQVariant(record), - .op = RecOp::Update + .op = QxRecOp::Update }); } return updated; @@ -397,7 +397,7 @@ bool SqlApi::drop(const std::string &table, int64_t id) .table = QString::fromStdString(table), .id = id, .record = {}, - .op = RecOp::Delete + .op = QxRecOp::Delete }); } return is_drop; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h index 3594ca510..b8a8f64b9 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h @@ -53,14 +53,14 @@ struct SqlQueryAndParams static SqlQueryAndParams fromRpcValue(const shv::chainpack::RpcValue &rv); }; -enum class RecOp { Insert, Update, Delete, }; +enum class QxRecOp { Insert, Update, Delete, }; struct QxRecChng { QString table; int64_t id; QVariant record; - RecOp op; + QxRecOp op; shv::chainpack::RpcValue toRpcValue() const; }; diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index 34b4c29f9..aefc064c4 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -441,20 +441,36 @@ void RunsTableWidget::onBadTableDataInput(const QString &message) void RunsTableWidget::onQxRecChng(const Event::services::qx::QxRecChng &chng) { std::optional run_id; + int row = 0; if (chng.table == "competitors") { auto *m = m_runsModel; for (auto i=0; irowCount(); ++i) { if (m->table().row(i).value("competitors.id").toInt() == chng.id) { run_id = m->value(i, "runs.id").toInt(); + row = i; break; } } } else if (chng.table == "runs") { run_id = chng.id; + auto *m = m_runsModel; + for (auto i=0; irowCount(); ++i) { + if (m->table().row(i).value("runs.id").toInt() == chng.id) { + row = i; + break; + } + } } if (run_id.has_value()) { - ui->tblRuns->rowExternallySaved(run_id.value()); + if (chng.op == Event::services::qx::QxRecOp::Update) { + for (const auto &[k, v] : chng.record.toMap().asKeyValueRange()) { + m_runsModel->setValue(row, k, v); + m_runsModel->setDirty(row, k, false); + } + } else { + ui->tblRuns->rowExternallySaved(run_id.value()); + } } } From bb2da886761fcdc7981bb8706cfe3f55f006262e Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Mon, 17 Nov 2025 22:05:33 +0100 Subject: [PATCH 17/29] Recchng is emitted on SqlTableModel::postRow --- .../libqfcore/include/qf/core/sql/qxrecchng.h | 1 + libqf/libqfcore/src/sql/qxrecchng.h | 17 +++++ libqf/libqfgui/src/model/sqldatadocument.h | 8 +- libqf/libqfgui/src/model/sqltablemodel.cpp | 73 ++++++++++++------- libqf/libqfgui/src/model/sqltablemodel.h | 14 ++-- quickevent/app/quickevent/CMakeLists.txt | 5 +- .../Competitors/src/competitordocument.h | 8 +- .../Event/src/services/qx/qxeventservice.cpp | 10 +-- .../Event/src/services/qx/qxeventservice.h | 5 +- .../Event/src/services/qx/sqlapinode.cpp | 18 ++--- .../plugins/Runs/src/runsplugin.cpp | 2 +- .../plugins/Runs/src/runstablemodel.cpp | 10 ++- .../plugins/Runs/src/runstablemodel.h | 6 +- .../plugins/Runs/src/runstablewidget.cpp | 29 +++++--- .../plugins/Runs/src/runstablewidget.h | 4 +- .../Event/src/services => src}/qx/sqlapi.cpp | 64 +++++++++++----- .../Event/src/services => src}/qx/sqlapi.h | 23 ++---- .../app/quickevent/src/qx/sqldatadocument.cpp | 17 +++++ .../app/quickevent/src/qx/sqldatadocument.h | 21 ++++++ .../app/quickevent/src/qx/sqltablemodel.cpp | 13 ++++ .../app/quickevent/src/qx/sqltablemodel.h | 17 +++++ 21 files changed, 252 insertions(+), 113 deletions(-) create mode 100644 libqf/libqfcore/include/qf/core/sql/qxrecchng.h create mode 100644 libqf/libqfcore/src/sql/qxrecchng.h rename quickevent/app/quickevent/{plugins/Event/src/services => src}/qx/sqlapi.cpp (86%) rename quickevent/app/quickevent/{plugins/Event/src/services => src}/qx/sqlapi.h (85%) create mode 100644 quickevent/app/quickevent/src/qx/sqldatadocument.cpp create mode 100644 quickevent/app/quickevent/src/qx/sqldatadocument.h create mode 100644 quickevent/app/quickevent/src/qx/sqltablemodel.cpp create mode 100644 quickevent/app/quickevent/src/qx/sqltablemodel.h diff --git a/libqf/libqfcore/include/qf/core/sql/qxrecchng.h b/libqf/libqfcore/include/qf/core/sql/qxrecchng.h new file mode 100644 index 000000000..7f444660c --- /dev/null +++ b/libqf/libqfcore/include/qf/core/sql/qxrecchng.h @@ -0,0 +1 @@ +#include "../../../../src/sql/qxrecchng.h" diff --git a/libqf/libqfcore/src/sql/qxrecchng.h b/libqf/libqfcore/src/sql/qxrecchng.h new file mode 100644 index 000000000..5ec42a70e --- /dev/null +++ b/libqf/libqfcore/src/sql/qxrecchng.h @@ -0,0 +1,17 @@ +#pragma once + +#include "../core/coreglobal.h" + +namespace qf::core::sql { + +enum class QxRecOp { Insert, Update, Delete, }; + +struct QFCORE_DECL_EXPORT QxRecChng +{ + QString table; + int64_t id; + QVariant record; + QxRecOp op; +}; + +} diff --git a/libqf/libqfgui/src/model/sqldatadocument.h b/libqf/libqfgui/src/model/sqldatadocument.h index ee56ac5b5..2a2b755e1 100644 --- a/libqf/libqfgui/src/model/sqldatadocument.h +++ b/libqf/libqfgui/src/model/sqldatadocument.h @@ -3,9 +3,7 @@ #include "datadocument.h" #include "sqltablemodel.h" -namespace qf { -namespace gui { -namespace model { +namespace qf::gui::model { class QFGUI_DECL_EXPORT SqlDataDocument : public DataDocument { @@ -21,7 +19,7 @@ class QFGUI_DECL_EXPORT SqlDataDocument : public DataDocument qf::core::sql::QueryBuilder queryBuilder(); void setQueryBuilder(const qf::core::sql::QueryBuilder &qb); protected: - SqlTableModel* createModel(QObject *parent) Q_DECL_OVERRIDE; + SqlTableModel* createModel(QObject *parent) override; ///! load model persistent storage via model bool loadData() Q_DECL_OVERRIDE; @@ -35,5 +33,5 @@ class QFGUI_DECL_EXPORT SqlDataDocument : public DataDocument */ }; -}}} +} diff --git a/libqf/libqfgui/src/model/sqltablemodel.cpp b/libqf/libqfgui/src/model/sqltablemodel.cpp index 276caf493..17ac9ab96 100644 --- a/libqf/libqfgui/src/model/sqltablemodel.cpp +++ b/libqf/libqfgui/src/model/sqltablemodel.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -150,8 +151,7 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) int serial_ix = -1; bool serial_ix_explicitly_set = false; int primary_ix = -1; - //QSqlIndex pri_ix = ti.primaryIndex(); - //bool has_blob_field = false; + QVariantMap qx_record; Q_FOREACH(const qf::core::utils::Table::Field &fld, row_ref.fields()) { i++; if(fld.tableId() != table_id) @@ -186,6 +186,7 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) new_fld.setValue(v); //qfInfo() << "\t\t" << "val is QString:" << (v.metaType().id() == QMetaType::QString); rec.append(new_fld); + qx_record[fld.shortName().toLower()] = v; } } @@ -201,40 +202,23 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) } else { qs = sqldrv->sqlStatement(QSqlDriver::InsertStatement, table, rec, false); - //qs = fixSerialDefaultValue(qs, serial_ix, rec); } - if(qs.isEmpty()) + if(qs.isEmpty()) { continue; - /* - qfDebug() << "\texecuting prepared query:" << qs; - bool ok = q.prepare(qs); - if(!ok) { - qfError() << "Cannot prepare query:" << qs; } - else { - for(int i=0; i= 0 && !serial_ix_explicitly_set) { - QVariant v = q.lastInsertId(); - qfDebug() << "\tsetting serial index:" << serial_ix << "to generated value:" << v; - if(v.isValid()) { - row_ref.setValue(serial_ix, v); + qfDebug() << "\tsetting serial index:" << serial_ix << "to generated value:" << insert_id; + if(insert_id.isValid()) { + row_ref.setValue(serial_ix, insert_id); row_ref.setDirty(serial_ix, false); } else { @@ -251,6 +235,15 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) qfDebug() << "\tsetting value of foreign key" << slave_key << "to value of master key:" << row_ref.value(master_key).toString(); row_ref.setValue(slave_key, row_ref.value(master_key)); } + if (!qx_record.isEmpty() && master_key == "id") { + qf::core::sql::QxRecChng chng { + .table = table_id, + .id = insert_id.toInt(), + .record = qx_record, + .op = qf::core::sql::QxRecOp::Insert, + }; + emit qxRecChng(chng); + } } } else { @@ -268,7 +261,7 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) QSqlDriver *sqldrv = sql_conn.driver(); Q_FOREACH(QString table_id, tableIds(m_table.fields())) { qfDebug() << "\ttableid:" << table_id; - //table = conn.fullTableNameToQtDriverTableName(table); + QVariantMap qx_record; QSqlRecord edit_rec; int i = -1; Q_FOREACH(qfu::Table::Field fld, row_ref.fields()) { @@ -286,12 +279,13 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) //qfDebug() << "\ttableid:" << tableid << "fullTableName:" << fld.fullTableName(); qfDebug() << "\tdirty field" << fld.name() << "type:" << fld.type().id() << "orig val:" << row_ref.origValue(i).toString() << "new val:" << v.toString(); //qfDebug().noSpace() << "\tdirty value: '" << v.toString() << "' isNull(): " << v.isNull() << " type(): " << v.type(); - QSqlField sqlfld(fld.shortName(), fld.type()); + QSqlField sqlfld(fld.shortName().toLower(), fld.type()); sqlfld.setValue(v); //if(sqlfld.type() == QVariant::ByteArray) // has_blob_field = true; qfDebug() << "\tfield is null: " << sqlfld.isNull(); edit_rec.append(sqlfld); + qx_record[fld.shortName()] = v; } if(!edit_rec.isEmpty()) { qfDebug() << "updating table edits:" << table_id; @@ -300,7 +294,9 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) query_str += " "; QSqlRecord where_rec; qfDebug() << "looking for primary index of table:" << table_id; - Q_FOREACH(auto fld_name, sql_conn.primaryIndexFieldNames(table_id)) { + std::optional id_pri_key_value; + auto pri_keys = sql_conn.primaryIndexFieldNames(table_id); + for (const auto &fld_name : pri_keys) { QString full_fld_name = table_id + '.' + fld_name; qfDebug() << "\t checking value of field:" << full_fld_name; int fld_ix = m_table.fields().fieldIndex(full_fld_name); @@ -313,6 +309,9 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) sqlfld.setValue(row_ref.origValue(fld_ix)); qfDebug() << "\tpri index field" << full_fld_name << "type:" << sqlfld.metaType().id() << "orig val:" << row_ref.origValue(fld_ix) << "current val:" << row_ref.value(fld_ix); where_rec.append(sqlfld); + if (auto id = sqlfld.value().toInt(); id > 0) { + id_pri_key_value = id; + } } QF_ASSERT(!where_rec.isEmpty(), QString("pri keys values not generated for table '%1'").arg(table_id), @@ -335,6 +334,15 @@ bool SqlTableModel::postRow(int row_no, bool throw_exc) ret = false; break; } + if (!qx_record.isEmpty() && pri_keys.size() == 1 && pri_keys[0] == "id" && id_pri_key_value.has_value()) { + qf::core::sql::QxRecChng chng { + .table = table_id, + .id = id_pri_key_value.value(), + .record = qx_record, + .op = qf::core::sql::QxRecOp::Update, + }; + emit qxRecChng(chng); + } } } } @@ -437,6 +445,17 @@ bool SqlTableModel::removeTableRow(int row_no, bool throw_exc) ret = false; break; } + if (where_rec.count() == 1 && where_rec.field(0).name() == "id") { + if (auto id = where_rec.field(0).value().toInt(); id < 0) { + qf::core::sql::QxRecChng chng { + .table = table_id, + .id = id, + .record = {}, + .op = qf::core::sql::QxRecOp::Delete, + }; + emit qxRecChng(chng); + } + } } } if(ret) { diff --git a/libqf/libqfgui/src/model/sqltablemodel.h b/libqf/libqfgui/src/model/sqltablemodel.h index 95a2cbebd..e055385f6 100644 --- a/libqf/libqfgui/src/model/sqltablemodel.h +++ b/libqf/libqfgui/src/model/sqltablemodel.h @@ -10,12 +10,10 @@ #include #include -namespace qf { -namespace gui { -namespace sql { -class Connection; -} -namespace model { +namespace qf::core::sql { struct QxRecChng; } +namespace qf::gui::sql { class Connection; } + +namespace qf::gui::model { class QFGUI_DECL_EXPORT SqlTableModel : public TableModel { @@ -51,6 +49,8 @@ class QFGUI_DECL_EXPORT SqlTableModel : public TableModel int reloadRow(int row_no) Q_DECL_OVERRIDE; int reloadInserts(const QString &id_column_name) Q_DECL_OVERRIDE; QString reloadRowQuery(const QVariant &record_id); + + Q_SIGNAL void qxRecChng(const qf::core::sql::QxRecChng &recchng); public: void setQueryBuilder(const qf::core::sql::QueryBuilder &qb, bool clear_columns = false); const qf::core::sql::QueryBuilder& queryBuilder() const; @@ -100,5 +100,5 @@ class QFGUI_DECL_EXPORT SqlTableModel : public TableModel QMap m_foreignKeyDependencies; }; -}}} +} diff --git a/quickevent/app/quickevent/CMakeLists.txt b/quickevent/app/quickevent/CMakeLists.txt index ab9e29298..29f5b352b 100644 --- a/quickevent/app/quickevent/CMakeLists.txt +++ b/quickevent/app/quickevent/CMakeLists.txt @@ -90,7 +90,6 @@ add_executable(quickevent plugins/Event/src/services/servicewidget.cpp plugins/Event/src/services/servicewidget.ui - plugins/Event/src/services/qx/sqlapi.h plugins/Event/src/services/qx/sqlapi.cpp plugins/Event/src/services/qx/qxnode.cpp plugins/Event/src/services/qx/sqlapinode.cpp plugins/Event/src/services/qx/nodes.cpp @@ -173,6 +172,10 @@ add_executable(quickevent plugins/Runs/Runs.qrc plugins/CardReader/CardReader.qrc + src/qx/sqlapi.cpp src/qx/sqlapi.h + src/qx/sqltablemodel.h src/qx/sqltablemodel.cpp + src/qx/sqldatadocument.h src/qx/sqldatadocument.cpp + src/appclioptions.cpp src/application.cpp src/loggerwidget.cpp diff --git a/quickevent/app/quickevent/plugins/Competitors/src/competitordocument.h b/quickevent/app/quickevent/plugins/Competitors/src/competitordocument.h index a394edbe4..ebca84986 100644 --- a/quickevent/app/quickevent/plugins/Competitors/src/competitordocument.h +++ b/quickevent/app/quickevent/plugins/Competitors/src/competitordocument.h @@ -1,24 +1,22 @@ #ifndef COMPETITORS_COMPETITORDOCUMENT_H #define COMPETITORS_COMPETITORDOCUMENT_H -#include +#include "src/qx/sqldatadocument.h" #include namespace Competitors { -class CompetitorDocument : public qf::gui::model::SqlDataDocument +class CompetitorDocument : public qx::SqlDataDocument { Q_OBJECT private: - typedef qf::gui::model::SqlDataDocument Super; + typedef qx::SqlDataDocument Super; public: CompetitorDocument(QObject *parent = nullptr); - //bool isSaveSiidToRuns() const {return m_saveSiidToRuns;} void setEmitDbEventsOnSave(bool b) {m_isEmitDbEventsOnSave = b;} - //void setSiid(const QVariant &siid, bool save_siid_to_runs); void setSiid(const QVariant &siid); QVariant siid() const; const QVector& runsIds() const {return m_runsIds;} diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index 320548969..1b8b1d7ec 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -2,7 +2,7 @@ #include "qxeventservicewidget.h" #include "nodes.h" #include "sqlapinode.h" -#include "sqlapi.h" +#include "src/qx/sqlapi.h" #include "../../eventplugin.h" #include "../../../../Runs/src/runsplugin.h" @@ -78,7 +78,7 @@ void QxEventService::run() { m_rpcConnection->setConnectionString(ss.shvBrokerUrl()); RpcValue::Map opts; RpcValue::Map device; - device["mountPoint"] = "test/quickevent"; + device["mountPoint"] = "test/qx/event/1"; opts["device"] = device; m_rpcConnection->setConnectionOptions(opts); @@ -87,7 +87,7 @@ void QxEventService::run() { connect(m_rpcConnection, &ClientConnection::brokerLoginError, this, &QxEventService::onBrokerLoginError); connect(m_rpcConnection, &ClientConnection::rpcMessageReceived, this, &QxEventService::onRpcMessageReceived); - connect(SqlApi::instance(), &SqlApi::recchng, this, &QxEventService::onRecchg); + connect(::qx::SqlApi::instance(), &::qx::SqlApi::recchng, this, &QxEventService::sendRecchgShvSignal); m_rpcConnection->open(); } @@ -638,10 +638,10 @@ void QxEventService::subscribeChanges() rpc_call->start(); } -void QxEventService::onRecchg(const QxRecChng &chng) +void QxEventService::sendRecchgShvSignal(const qf::core::sql::QxRecChng &chng) { if (isRunning()) { - m_rpcConnection->sendShvSignal("sql", "recchng", chng.toRpcValue()); + m_rpcConnection->sendShvSignal("sql", "recchng", ::qx::qxRecChngToRpcValue(chng)); } } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h index b25076626..2b5e2e1de 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h @@ -10,11 +10,10 @@ class QTimer; namespace shv::iotqt::node { class ShvNodeTree; class ShvRootNode; } namespace shv::iotqt::rpc { class DeviceConnection; } namespace shv::chainpack { class RpcMessage; class RpcError; } +namespace qf::core::sql { struct QxRecChng; } namespace Event::services::qx { -struct QxRecChng; - class QxEventServiceSettings : public ServiceSettings { using Super = ServiceSettings; @@ -80,7 +79,7 @@ class QxEventService : public Service void sendRpcMessage(const shv::chainpack::RpcMessage &rpc_msg); void onBrokerSocketError(const QString &err); void onBrokerLoginError(const shv::chainpack::RpcError &err); - void onRecchg(const QxRecChng &chng); + void sendRecchgShvSignal(const qf::core::sql::QxRecChng &chng); void subscribeChanges(); private: diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp index d12474363..bbeeb3b08 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapinode.cpp @@ -1,5 +1,5 @@ #include "sqlapinode.h" -#include "sqlapi.h" +#include "src/qx/sqlapi.h" #include #include @@ -58,17 +58,17 @@ RpcValue SqlApiNode::callMethod(const StringViewList &shv_path, const std::strin //eyascore::utils::UserId user_id = eyascore::utils::UserId::makeUserName(QString::fromStdString(rq.userId().toMap().value("userName").toString())); if(shv_path.empty()) { if(method == METH_EXEC) { - auto res = SqlApi::exec(SqlQueryAndParams::fromRpcValue(params)); + auto res = ::qx::SqlApi::exec(::qx::SqlQueryAndParams::fromRpcValue(params)); return res.toRpcValue(); } if(method == METH_QUERY) { - auto res = SqlApi::exec(SqlQueryAndParams::fromRpcValue(params)); + auto res = ::qx::SqlApi::exec(::qx::SqlQueryAndParams::fromRpcValue(params)); return res.toRpcValue(); } if(method == METH_TRANSACTION) { auto sql_query = params.asList().valref(0).asString(); const auto &sql_params = params.asList().valref(0); - SqlApi::transaction(sql_query, sql_params.asList()); + ::qx::SqlApi::transaction(sql_query, sql_params.asList()); return RpcValue(nullptr); } if(method == METH_LIST) { @@ -80,14 +80,14 @@ RpcValue SqlApiNode::callMethod(const StringViewList &shv_path, const std::strin } auto ids_above = map.contains("ids_above")? std::optional(map.value("ids_above").toInt64()): std::optional(); auto limit = map.contains("limit")? std::optional(map.value("limit").toInt64()): std::optional(); - auto res = SqlApi::list(table, fields, ids_above, limit); + auto res = ::qx::SqlApi::list(table, fields, ids_above, limit); return res.toRecordList(); } if(method == METH_CREATE) { const auto &map = params.asMap(); const auto &table = map.value("table").asString(); const auto &record = map.valref("record").asMap(); - auto res = SqlApi::create(table, record); + auto res = ::qx::SqlApi::create(table, record); return res; } if(method == METH_READ) { @@ -98,7 +98,7 @@ RpcValue SqlApiNode::callMethod(const StringViewList &shv_path, const std::strin for (const auto &fn : map.valref("fields").asList()) { fields.push_back(fn.asString()); } - auto res = SqlApi::read(table, id, fields); + auto res = ::qx::SqlApi::read(table, id, fields); if (res.has_value()) { return res.value(); } @@ -109,14 +109,14 @@ RpcValue SqlApiNode::callMethod(const StringViewList &shv_path, const std::strin const auto &table = map.value("table").asString(); auto id = map.value("id").toInt64(); const auto &record = map.valref("record").asMap(); - auto res = SqlApi::update(table, id, record); + auto res = ::qx::SqlApi::update(table, id, record); return res; } if(method == METH_DELETE) { const auto &map = params.asMap(); const auto &table = map.value("table").asString(); auto id = map.valref("id").toInt(); - auto res = SqlApi::drop(table, id); + auto res = ::qx::SqlApi::drop(table, id); return res; } } diff --git a/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp b/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp index c2a8d069e..6435e251b 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runsplugin.cpp @@ -1298,7 +1298,7 @@ qf::core::sql::QueryBuilder RunsPlugin::runsQuery(int stage_id, int class_id, bo qfs::QueryBuilder qb; qb.select2("runs", "*") .select2("classes", "name") - .select2("competitors", "id, iofId, registration, licence, ranking, siId, note") + .select2("competitors", "id, firstName, lastName, iofId, registration, licence, ranking, siId, note") .select("COALESCE(lastName, '') || ' ' || COALESCE(firstName, '') AS competitorName") .select("lentcards.siid IS NOT NULL AS cardInLentTable") diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp index fe183294e..5f2dfccda 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.cpp @@ -1,8 +1,10 @@ #include "runstablemodel.h" +#include "../../Event/src/eventplugin.h" +#include "src/qx/sqlapi.h" + #include #include -#include "../../Event/src/eventplugin.h" #include #include @@ -81,6 +83,12 @@ QVariant RunsTableModel::data(const QModelIndex &index, int role) const QVariant RunsTableModel::value(int row_ix, int column_ix) const { + if(column_ix == col_competitorName) { + qf::core::utils::TableRow row = tableRow(row_ix); + auto first_name = row.value(QStringLiteral("firstName")).toString(); + auto last_name = row.value(QStringLiteral("lastName")).toString(); + return last_name + ' ' + first_name; + } if(column_ix == col_runFlags) { qf::core::utils::TableRow row = tableRow(row_ix); bool mis_punch = row.value(QStringLiteral("runs.misPunch")).toBool(); diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h index 9379bfebd..94b1ca389 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablemodel.h @@ -1,13 +1,13 @@ #ifndef RUNSTABLEMODEL_H #define RUNSTABLEMODEL_H -#include +#include "src/qx/sqltablemodel.h" -class RunsTableModel : public quickevent::gui::og::SqlTableModel +class RunsTableModel : public ::qx::SqlTableModel { Q_OBJECT private: - using Super = quickevent::gui::og::SqlTableModel; + using Super = ::qx::SqlTableModel; public: enum Columns { col_runs_isRunning = 0, diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index aefc064c4..3b59b067c 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -7,10 +7,14 @@ #include "runflagsdialog.h" #include "cardflagsdialog.h" +#include "src/qx/sqlapi.h" + #include -#include #include #include +#include +#include +#include #include #include @@ -20,11 +24,7 @@ #include #include -#include -#include -#include -#include -#include +#include #include #include @@ -136,7 +136,7 @@ RunsTableWidget::RunsTableWidget(QWidget *parent) : } }, Qt::QueuedConnection); - connect(Event::services::qx::SqlApi::instance(), &Event::services::qx::SqlApi::recchng, this, &RunsTableWidget::onQxRecChng); + connect(::qx::SqlApi::instance(), &::qx::SqlApi::recchng, this, &RunsTableWidget::onQxRecChng); } RunsTableWidget::~RunsTableWidget() @@ -438,7 +438,7 @@ void RunsTableWidget::onBadTableDataInput(const QString &message) qf::gui::dialogs::MessageBox::showError(this, message); } -void RunsTableWidget::onQxRecChng(const Event::services::qx::QxRecChng &chng) +void RunsTableWidget::onQxRecChng(const qf::core::sql::QxRecChng &chng) { std::optional run_id; int row = 0; @@ -463,10 +463,17 @@ void RunsTableWidget::onQxRecChng(const Event::services::qx::QxRecChng &chng) } } if (run_id.has_value()) { - if (chng.op == Event::services::qx::QxRecOp::Update) { + if (chng.op == qf::core::sql::QxRecOp::Update) { for (const auto &[k, v] : chng.record.toMap().asKeyValueRange()) { - m_runsModel->setValue(row, k, v); - m_runsModel->setDirty(row, k, false); + if (k == "firstname" || k == "lastname") { + auto &r = m_runsModel->tableRowRef(row); + r.setValue("competitors." + k, v); + auto ix = m_runsModel->index(row, RunsTableModel::col_competitorName); + m_runsModel->dataChanged(ix, ix); + } else { + m_runsModel->setValue(row, k, v); + m_runsModel->setDirty(row, k, false); + } } } else { ui->tblRuns->rowExternallySaved(run_id.value()); diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h index a5379f689..d7ed07e6e 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.h @@ -7,7 +7,7 @@ class RunsTableItemDelegate; class CourseItemDelegate; namespace qf::gui { class TableView; } -namespace Event::services::qx { struct QxRecChng; } +namespace qf::core::sql { struct QxRecChng; } namespace Ui { class RunsTableWidget; @@ -38,7 +38,7 @@ class RunsTableWidget : public QWidget void onTableViewSqlException(const QString &what, const QString &where, const QString &stack_trace); void onBadTableDataInput(const QString &message); - void onQxRecChng(const Event::services::qx::QxRecChng &chng); + void onQxRecChng(const qf::core::sql::QxRecChng &chng); private: Ui::RunsTableWidget *ui; RunsTableModel *m_runsModel; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp b/quickevent/app/quickevent/src/qx/sqlapi.cpp similarity index 86% rename from quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp rename to quickevent/app/quickevent/src/qx/sqlapi.cpp index 2c58823bf..2fd65b9d8 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.cpp +++ b/quickevent/app/quickevent/src/qx/sqlapi.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -16,7 +17,7 @@ using namespace shv::chainpack; -namespace Event::services::qx { +namespace qx { //============================================== // RpcSqlField @@ -146,21 +147,22 @@ SqlQueryAndParams SqlQueryAndParams::fromRpcValue(const shv::chainpack::RpcValue return SqlQueryAndParams { .query = sql_query, .params = sql_params.asMap() }; } -RpcValue QxRecChng::toRpcValue() const + +RpcValue qxRecChngToRpcValue(const qf::core::sql::QxRecChng &chng) { RpcValue::Map ret; - ret["table"] = table.toStdString(); - ret["id"] = id; - ret["record"] = shv::coreqt::rpc::qVariantToRpcValue(record); - auto rec_op_string = [](QxRecOp op) { + ret["table"] = chng.table.toStdString(); + ret["id"] = chng.id; + ret["record"] = shv::coreqt::rpc::qVariantToRpcValue(chng.record); + auto rec_op_string = [](qf::core::sql::QxRecOp op) { switch (op) { - case QxRecOp::Insert: return "Insert"; - case QxRecOp::Update: return "Update"; - case QxRecOp::Delete: return "Delete"; + case qf::core::sql::QxRecOp::Insert: return "Insert"; + case qf::core::sql::QxRecOp::Update: return "Update"; + case qf::core::sql::QxRecOp::Delete: return "Delete"; } return ""; }; - ret["op"] = rec_op_string(op); + ret["op"] = rec_op_string(chng.op); return ret; } @@ -179,6 +181,12 @@ SqlApi *SqlApi::instance() return api; } +void SqlApi::emitRecChng(const qf::core::sql::QxRecChng &chng) +{ + qfInfo() << "REC_CHNG:" << qxRecChngToRpcValue(chng).toCpon(); + emit recchng(chng); +} + namespace { class Transaction @@ -303,7 +311,27 @@ RpcSqlResult SqlApi::list(const std::string &table, const std::vectorrecchng(QxRecChng { + SqlApi::instance()->emitRecChng(qf::core::sql::QxRecChng { .table = QString::fromStdString(table), .id = id, - .record = shv::coreqt::rpc::rpcValueToQVariant(record), - .op = QxRecOp::Insert + .record = shv::coreqt::rpc::rpcValueToQVariant(normalizeFieldNames(record)), + .op = qf::core::sql::QxRecOp::Insert }); return id; } @@ -374,11 +402,11 @@ bool SqlApi::update(const std::string &table, int64_t id, const SqlRecord &recor q.exec(qf::core::Exception::Throw); bool updated = q.numRowsAffected() == 1; if (updated) { - emit SqlApi::instance()->recchng(QxRecChng { + SqlApi::instance()->emitRecChng(qf::core::sql::QxRecChng { .table = QString::fromStdString(table), .id = id, - .record = shv::coreqt::rpc::rpcValueToQVariant(record), - .op = QxRecOp::Update + .record = shv::coreqt::rpc::rpcValueToQVariant(normalizeFieldNames(record)), + .op = qf::core::sql::QxRecOp::Update }); } return updated; @@ -393,11 +421,11 @@ bool SqlApi::drop(const std::string &table, int64_t id) q.exec(sql_query, qf::core::Exception::Throw); bool is_drop = q.numRowsAffected() == 1; if (is_drop) { - emit SqlApi::instance()->recchng(QxRecChng { + SqlApi::instance()->emitRecChng(qf::core::sql::QxRecChng { .table = QString::fromStdString(table), .id = id, .record = {}, - .op = QxRecOp::Delete + .op = qf::core::sql::QxRecOp::Delete }); } return is_drop; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h b/quickevent/app/quickevent/src/qx/sqlapi.h similarity index 85% rename from quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h rename to quickevent/app/quickevent/src/qx/sqlapi.h index b8a8f64b9..80bee09b2 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/sqlapi.h +++ b/quickevent/app/quickevent/src/qx/sqlapi.h @@ -1,11 +1,15 @@ #pragma once #include +// #include +#include #include #include -namespace Event::services::qx { +namespace qf::core::sql { struct QxRecChng; } + +namespace qx { struct RpcSqlField { @@ -27,7 +31,6 @@ struct RpcSqlResult std::vector rows; RpcSqlResult() = default; - // explicit RpcSqlResult(const QSqlQuery &q); std::optional columnIndex(const std::string &name) const; const shv::chainpack::RpcValue& value(size_t row, size_t col) const; @@ -38,8 +41,6 @@ struct RpcSqlResult bool isSelect() const {return !fields.empty();} shv::chainpack::RpcValue toRpcValue() const; shv::chainpack::RpcValue::List toRecordList() const; - // QVariant toVariant() const; - // static RpcSqlResult fromVariant(const QVariant &v); static RpcSqlResult fromRpcValue(const shv::chainpack::RpcValue &rv); }; @@ -53,17 +54,8 @@ struct SqlQueryAndParams static SqlQueryAndParams fromRpcValue(const shv::chainpack::RpcValue &rv); }; -enum class QxRecOp { Insert, Update, Delete, }; - -struct QxRecChng -{ - QString table; - int64_t id; - QVariant record; - QxRecOp op; +shv::chainpack::RpcValue qxRecChngToRpcValue(const qf::core::sql::QxRecChng &chng); - shv::chainpack::RpcValue toRpcValue() const; -}; class SqlApi : public QObject { @@ -71,7 +63,8 @@ class SqlApi : public QObject public: static SqlApi* instance(); - Q_SIGNAL void recchng(const QxRecChng &chng); + Q_SIGNAL void recchng(const qf::core::sql::QxRecChng &chng); + void emitRecChng(const qf::core::sql::QxRecChng &chng); static RpcSqlResult exec(const SqlQueryAndParams ¶ms); static RpcSqlResult query(const SqlQueryAndParams ¶ms); diff --git a/quickevent/app/quickevent/src/qx/sqldatadocument.cpp b/quickevent/app/quickevent/src/qx/sqldatadocument.cpp new file mode 100644 index 000000000..1f7040921 --- /dev/null +++ b/quickevent/app/quickevent/src/qx/sqldatadocument.cpp @@ -0,0 +1,17 @@ +#include "sqldatadocument.h" + + +namespace qx { + +SqlDataDocument::SqlDataDocument(QObject *parent) + : Super{parent} +{ + +} + +SqlTableModel *SqlDataDocument::createModel(QObject *parent) +{ + return new ::qx::SqlTableModel(parent); +} + +} // namespace qx diff --git a/quickevent/app/quickevent/src/qx/sqldatadocument.h b/quickevent/app/quickevent/src/qx/sqldatadocument.h new file mode 100644 index 000000000..cea298076 --- /dev/null +++ b/quickevent/app/quickevent/src/qx/sqldatadocument.h @@ -0,0 +1,21 @@ +#pragma once + +#include "sqltablemodel.h" + +#include + +namespace qx { + +class SqlDataDocument : public qf::gui::model::SqlDataDocument +{ + Q_OBJECT + + using Super = qf::gui::model::SqlDataDocument; +public: + explicit SqlDataDocument(QObject *parent = nullptr); +protected: + ::qx::SqlTableModel* createModel(QObject *parent) override; +}; + +} // namespace qx + diff --git a/quickevent/app/quickevent/src/qx/sqltablemodel.cpp b/quickevent/app/quickevent/src/qx/sqltablemodel.cpp new file mode 100644 index 000000000..0bad5b1fc --- /dev/null +++ b/quickevent/app/quickevent/src/qx/sqltablemodel.cpp @@ -0,0 +1,13 @@ +#include "sqltablemodel.h" +#include "sqlapi.h" + +namespace qx { + +SqlTableModel::SqlTableModel(QObject *parent) + : Super{parent} +{ + auto *sql_api = SqlApi::instance(); + connect(this, &qf::gui::model::SqlTableModel::qxRecChng, sql_api, &SqlApi::emitRecChng); +} + +} // namespace qx diff --git a/quickevent/app/quickevent/src/qx/sqltablemodel.h b/quickevent/app/quickevent/src/qx/sqltablemodel.h new file mode 100644 index 000000000..1581be19e --- /dev/null +++ b/quickevent/app/quickevent/src/qx/sqltablemodel.h @@ -0,0 +1,17 @@ +#pragma once + +#include + +namespace qx { + +class SqlTableModel : public quickevent::gui::og::SqlTableModel +{ + Q_OBJECT + + using Super = quickevent::gui::og::SqlTableModel; +public: + explicit SqlTableModel(QObject *parent = nullptr); +}; + +} // namespace qx + From 4902f86f0ff0d3f3490b3cdbe34b272e7421c841 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 23 Nov 2025 14:17:39 +0100 Subject: [PATCH 18/29] Fix CardReader model id column name --- .../app/quickevent/plugins/CardReader/src/cardreaderwidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/quickevent/app/quickevent/plugins/CardReader/src/cardreaderwidget.cpp b/quickevent/app/quickevent/plugins/CardReader/src/cardreaderwidget.cpp index 9fd066be2..f9a6a90fa 100644 --- a/quickevent/app/quickevent/plugins/CardReader/src/cardreaderwidget.cpp +++ b/quickevent/app/quickevent/plugins/CardReader/src/cardreaderwidget.cpp @@ -112,6 +112,7 @@ class Model : public quickevent::gui::og::SqlTableModel Model::Model(QObject *parent) : Super(parent) { + setIdColumnName("cards.id"); clearColumns(col_COUNT); setColumn(col_cards_id, ColumnDefinition("cards.id", "id").setReadOnly(true)); setColumn(col_cards_siId, ColumnDefinition("cards.siId", tr("SI")).setReadOnly(true).setCastType(qMetaTypeId())); From 189663888385d57cfc53402525a8a73f7e0f2e55 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Sun, 30 Nov 2025 20:36:51 +0100 Subject: [PATCH 19/29] Change default SHV mount point --- .../quickevent/plugins/Event/src/services/qx/qxeventservice.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index 1b8b1d7ec..e098be777 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -78,7 +78,7 @@ void QxEventService::run() { m_rpcConnection->setConnectionString(ss.shvBrokerUrl()); RpcValue::Map opts; RpcValue::Map device; - device["mountPoint"] = "test/qx/event/1"; + device["mountPoint"] = "test/hsh2025"; opts["device"] = device; m_rpcConnection->setConnectionOptions(opts); From 7ff7af0d9c9134de6fc7b230e0eb9a351b652527 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 19 Dec 2025 11:09:53 +0100 Subject: [PATCH 20/29] Enable QF_WITH_LIBSHV option in CMake action --- .github/actions/cmake/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/cmake/action.yml b/.github/actions/cmake/action.yml index 4ff81aa9e..ac208298e 100644 --- a/.github/actions/cmake/action.yml +++ b/.github/actions/cmake/action.yml @@ -66,6 +66,7 @@ runs: -B '${{github.workspace}}/build' \ -DCMAKE_BUILD_TYPE=Release \ -DQF_BUILD_QML_PLUGINS=ON \ + -DQF_WITH_LIBSHV=ON \ -DBUILD_TESTING=OFF \ -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ -DUSE_QT6=${{ inputs.use_qt6 }} \ From 19d8499a4ddbfdd1e90d2405eb4f3ed60ea7419c Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 19 Dec 2025 11:20:25 +0100 Subject: [PATCH 21/29] Update Qt version to 6.10 in workflow --- .github/workflows/appimage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/appimage.yml b/.github/workflows/appimage.yml index c4fba4011..6b4639fb4 100644 --- a/.github/workflows/appimage.yml +++ b/.github/workflows/appimage.yml @@ -12,7 +12,7 @@ on: jobs: ubuntu-qe3: - name: Qt 6.8 / Ubuntu 22.04 + name: Qt 6.10 / Ubuntu 22.04 runs-on: ubuntu-22.04 steps: - name: Clone the repository @@ -23,7 +23,7 @@ jobs: - name: Setup CMake uses: ./.github/actions/cmake with: - qt_version: 6.8.3 + qt_version: 6.10.1 use_qt6: ON modules: qtserialport qtmultimedia additional_cmake_args: -DCMAKE_INSTALL_PREFIX='${{ github.workspace }}/install/usr' From 1a773d8e8d0596b57743c5e0421753979d7b51ee Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 19 Dec 2025 11:49:57 +0100 Subject: [PATCH 22/29] Remove libqsqloci.so from SQL drivers Remove additional SQL driver plugin for OCI from QT_ROOT_DIR. --- .github/actions/appimage/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/appimage/action.yml b/.github/actions/appimage/action.yml index 91f54a335..808c9ca1e 100644 --- a/.github/actions/appimage/action.yml +++ b/.github/actions/appimage/action.yml @@ -39,6 +39,7 @@ runs: rm ${{ env.QT_ROOT_DIR }}/plugins/sqldrivers/libqsqlmimer.so rm ${{ env.QT_ROOT_DIR }}/plugins/sqldrivers/libqsqlmysql.so rm ${{ env.QT_ROOT_DIR }}/plugins/sqldrivers/libqsqlodbc.so + rm ${{ env.QT_ROOT_DIR }}/plugins/sqldrivers/libqsqloci.so shell: bash - name: Create AppImage From 40ee83f4bd403f08b6fa2095950b9fa0f1ce22ae Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 19 Dec 2025 17:36:01 +0100 Subject: [PATCH 23/29] Upgrade Qt version from 6.8 to 6.10 in windows workflow --- .github/workflows/installer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/installer.yml b/.github/workflows/installer.yml index b4c69395c..2ed6fbf86 100644 --- a/.github/workflows/installer.yml +++ b/.github/workflows/installer.yml @@ -8,7 +8,7 @@ on: jobs: windows: - name: Qt 6.8 / Windows + name: Qt 6.10 / Windows runs-on: windows-2025 steps: - name: Clone the repository @@ -62,7 +62,7 @@ jobs: - name: Setup CMake uses: ./.github/actions/cmake with: - qt_version: 6.8.3 + qt_version: 6.10.1 qt_arch: win64_mingw use_qt6: ON modules: qtserialport qtmultimedia From 1e1fb1814bd1475fb50edc7a9f8b63282d5a36bc Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 19 Dec 2025 17:38:50 +0100 Subject: [PATCH 24/29] Update Qt version to 6.10.1 in linter action --- .github/actions/run-linter/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/run-linter/action.yml b/.github/actions/run-linter/action.yml index c7e0771a9..0d70e8a3a 100644 --- a/.github/actions/run-linter/action.yml +++ b/.github/actions/run-linter/action.yml @@ -11,7 +11,7 @@ runs: - name: Setup CMake uses: ./.github/actions/cmake with: - qt_version: 6.8.3 + qt_version: 6.10.1 use_qt6: ON modules: qtserialport qtmultimedia additional_cmake_args: -DCMAKE_GLOBAL_AUTOGEN_TARGET=ON -DCMAKE_AUTOGEN_ORIGIN_DEPENDS=OFF From 760e61d92f89476efb1b05374ca119b283566236 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Wed, 24 Dec 2025 00:08:01 +0100 Subject: [PATCH 25/29] Make service status text expandable --- .../plugins/Event/src/services/qx/qxeventservice.cpp | 2 ++ .../app/quickevent/plugins/Event/src/services/servicewidget.ui | 3 +++ 2 files changed, 5 insertions(+) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index e098be777..de1c055b2 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -584,11 +584,13 @@ void QxEventService::onBrokerConnectedChanged(bool is_connected) void QxEventService::onBrokerSocketError(const QString &err) { + qfWarning() << "onBrokerSocketError:" << err; setStatusMessage(tr("Broker socket error: %1").arg(err)); } void QxEventService::onBrokerLoginError(const shv::chainpack::RpcError &err) { + qfWarning() << "onBrokerLoginError:" << err.toString(); setStatusMessage(tr("Broker login error: %1").arg(err.toString())); } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.ui b/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.ui index cdff60fa1..510d437a7 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.ui +++ b/quickevent/app/quickevent/plugins/Event/src/services/servicewidget.ui @@ -87,6 +87,9 @@ neco neco + + true + From 59416fbe8492f0a42c9ba6a2476544a19b4e8373 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Fri, 30 Jan 2026 23:51:09 +0100 Subject: [PATCH 26/29] Rebased on multi-course --- .clang-tidy | 2 +- 3rdparty/libshv | 2 +- .../quickevent/plugins/Classes/src/classeswidget.cpp | 10 +++++++--- .../plugins/Event/src/services/qx/qxeventservice.cpp | 2 +- .../Event/src/services/qx/qxeventservicewidget.cpp | 2 +- .../quickevent/plugins/Runs/src/runstablewidget.cpp | 1 - 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 64c3c28fa..543d5ca53 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -40,7 +40,7 @@ Checks: -cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-special-member-functions, - -cppcoreguidelines-use-enum-class + -cppcoreguidelines-use-enum-class, -hicpp-avoid-c-arrays, -hicpp-avoid-goto, -hicpp-braces-around-statements, diff --git a/3rdparty/libshv b/3rdparty/libshv index f108e5d72..f77c05674 160000 --- a/3rdparty/libshv +++ b/3rdparty/libshv @@ -1 +1 @@ -Subproject commit f108e5d72729c16ee5b27ee8a9096182a5ceb7fa +Subproject commit f77c05674413e5bd5a1a98c894385e89805406d0 diff --git a/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp b/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp index 8da479d89..c4750dadc 100644 --- a/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp +++ b/quickevent/app/quickevent/plugins/Classes/src/classeswidget.cpp @@ -390,7 +390,8 @@ void ClassesWidget::importCourses(const QList &course_defs, con reload(); } -static QString normalize_course_name(const QString &course_name) +namespace { +QString normalize_course_name(const QString &course_name) { QString ret = qf::core::Collator::toAscii7(QLocale::Czech, course_name, false); ret.replace(' ', QString()); @@ -400,6 +401,7 @@ static QString normalize_course_name(const QString &course_name) ret.replace('-', '+'); return ret; } +} void ClassesWidget::import_ocad_txt() { @@ -566,7 +568,8 @@ void ClassesWidget::import_ocad_v8() } } -static QString element_text(const QDomElement &parent, const QString &tag_name) +namespace { +QString element_text(const QDomElement &parent, const QString &tag_name) { QDomElement el = parent.firstChildElement(tag_name); if(el.isNull()) @@ -574,13 +577,14 @@ static QString element_text(const QDomElement &parent, const QString &tag_name) return el.text(); } -static QString dump_element(const QDomElement &el) +QString dump_element(const QDomElement &el) { QString ret; QTextStream s(&ret); el.save(s, QDomNode::EncodingFromDocument); return ret; } +} void ClassesWidget::import_ocad_iofxml_2() { diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index de1c055b2..e691cd9b8 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -74,7 +74,7 @@ void QxEventService::run() { auto ss = settings(); delete m_rpcConnection; - m_rpcConnection = new DeviceConnection(this); + m_rpcConnection = new DeviceConnection("QuickEvent", this); m_rpcConnection->setConnectionString(ss.shvBrokerUrl()); RpcValue::Map opts; RpcValue::Map device; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp index 125d70f16..4d0e0bcbb 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp @@ -119,7 +119,7 @@ void QxEventServiceWidget::testConnection() using namespace shv::iotqt::rpc; using namespace shv::chainpack; - auto *rpc = new DeviceConnection(this); + auto *rpc = new DeviceConnection("QuickEventTest", this); rpc->setConnectionString(ui->edServerUrl->text()); connect(rpc, &ClientConnection::brokerConnectedChanged, this, [this, rpc](bool is_connected) { diff --git a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp index 3b59b067c..969a9c671 100644 --- a/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/quickevent/plugins/Runs/src/runstablewidget.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include From 89d0020b65824d6240dc6c1beeb4cfe8ef7ee6d1 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Mon, 2 Feb 2026 14:49:36 +0100 Subject: [PATCH 27/29] Update CI linter ubuntu version --- .github/workflows/lint.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 82fc37b7a..335707572 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -8,8 +8,8 @@ on: jobs: clang-tidy: - name: clang-tidy / Ubuntu 22.04 - runs-on: ubuntu-22.04 + name: clang-tidy / Ubuntu 24.04 + runs-on: ubuntu-24.04 env: CC: clang CXX: clang++ @@ -25,8 +25,8 @@ jobs: lint_program_with_args: clang-tidy --quiet --warnings-as-errors=* clazy: - name: clazy / Ubuntu 22.04 - runs-on: ubuntu-22.04 + name: clazy / Ubuntu 24.04 + runs-on: ubuntu-24.04 env: CC: clang CXX: clang++ From b3c90bb677cee914d7bc098d1c2e2b64316bb5d2 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Mon, 2 Feb 2026 14:50:26 +0100 Subject: [PATCH 28/29] Fix QxService login procedure --- .../Event/src/services/qx/qxeventservice.cpp | 48 ++++++++++++++----- .../Event/src/services/qx/qxeventservice.h | 3 +- .../src/services/qx/qxeventservicewidget.cpp | 35 +++++++++++--- .../Event/src/services/qx/runchangedialog.cpp | 2 +- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp index e691cd9b8..24f6bab19 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.cpp @@ -74,11 +74,19 @@ void QxEventService::run() { auto ss = settings(); delete m_rpcConnection; + m_eventId = 0; + + auto api_token = apiToken(); + if (api_token.isEmpty()) { + setStatus(Status::Stopped); + setStatusMessage(tr("API token is not set.")); + } + m_rpcConnection = new DeviceConnection("QuickEvent", this); m_rpcConnection->setConnectionString(ss.shvBrokerUrl()); RpcValue::Map opts; RpcValue::Map device; - device["mountPoint"] = "test/hsh2025"; + device["deviceId"] = api_token.toStdString(); opts["device"] = device; m_rpcConnection->setConnectionOptions(opts); @@ -94,6 +102,7 @@ void QxEventService::run() { void QxEventService::stop() { + m_eventId = 0; disconnectSSE(); if (m_pollChangesTimer) { m_pollChangesTimer->stop(); @@ -265,19 +274,19 @@ QNetworkReply* QxEventService::getQxChangesReply(int from_id) int QxEventService::eventId() const { - if (m_eventId == 0) { - throw qf::core::Exception(tr("Event ID is not loaded, service is not probably running.")); - } + // if (m_eventId == 0) { + // throw qf::core::Exception(tr("Event ID is not loaded, service is not probably running.")); + // } return m_eventId; } -QByteArray QxEventService::apiToken() const +QString QxEventService::apiToken() const { - // API token must not be cached to enable service point + // API token must not be cached to enable service to point // always to current stage event on qxhttpd auto *event_plugin = getPlugin(); auto current_stage = event_plugin->currentStageId(); - return event_plugin->stageData(current_stage).qxApiToken().toUtf8(); + return event_plugin->stageData(current_stage).qxApiToken(); } QUrl QxEventService::shvBrokerUrl() const @@ -296,7 +305,7 @@ void QxEventService::postFileCompressed(std::optional path, std::option } QNetworkRequest request; request.setUrl(url); - request.setRawHeader(QX_API_TOKEN, apiToken()); + request.setRawHeader(QX_API_TOKEN, apiToken().toUtf8()); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/zip")); auto zdata = zlibCompress(data); QNetworkReply *reply = networkManager()->post(request, zdata); @@ -347,7 +356,7 @@ void QxEventService::httpPostJson(const QString &path, const QString &query, QVa QNetworkRequest request; request.setUrl(url); - request.setRawHeader(QX_API_TOKEN, apiToken()); + request.setRawHeader(QX_API_TOKEN, apiToken().toUtf8()); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json")); auto data = QJsonDocument::fromVariant(json).toJson(QJsonDocument::Compact); qfInfo() << "HTTP POST JSON:" << url.toString() << "data:" << QString::fromUtf8(data); @@ -571,11 +580,24 @@ int QxEventService::currentConnectionId() void QxEventService::onBrokerConnectedChanged(bool is_connected) { if(is_connected) { - setStatus(Status::Running); - QTimer::singleShot(0, this, [this]() { - subscribeChanges(); -// testRpcCall(); + auto *rpc_call = shv::iotqt::rpc::RpcCall::create(m_rpcConnection) + ->setShvPath(".broker/currentClient") + ->setMethod("info"); + connect(rpc_call, &shv::iotqt::rpc::RpcCall::maybeResult, this, [this](const ::shv::chainpack::RpcValue &result, const shv::chainpack::RpcError &error) { + if (error.isValid()) { + setStatus(Status::Stopped); + setStatusMessage(tr("Client info discovery error: %1").arg(error.toString())); + } + else { + const auto &info = result.asMap(); + m_eventMountPoint = info.value("mountPoint").to(); + m_eventId = m_eventMountPoint.section('/', -1, -1).toInt(); + setStatus(Status::Running); + setStatusMessage(tr("Event ID: %1").arg(m_eventId)); + subscribeChanges(); + } }); + rpc_call->start(); } else { setStatus(Status::Stopped); } diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h index 2b5e2e1de..add24852e 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservice.h @@ -68,7 +68,7 @@ class QxEventService : public Service QNetworkReply* getQxChangesReply(int from_id); - QByteArray apiToken() const; + QString apiToken() const; static int currentConnectionId(); QUrl shvBrokerUrl() const; @@ -105,6 +105,7 @@ class QxEventService : public Service QNetworkAccessManager *m_networkManager = nullptr; QNetworkReply *m_replySSE = nullptr; int m_eventId = 0; + QString m_eventMountPoint; QTimer *m_pollChangesTimer = nullptr; }; diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp index 4d0e0bcbb..d18cd0e38 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/qxeventservicewidget.cpp @@ -10,6 +10,8 @@ #include #include +#include +#include #include #include @@ -41,6 +43,7 @@ QxEventServiceWidget::QxEventServiceWidget(QWidget *parent) ui->edServerUrl->setText(settings.shvBrokerUrl()); ui->edApiToken->setText(svc->apiToken()); ui->edCurrentStage->setValue(current_stage); + ui->edEventId->setValue(svc->eventId()); connect(ui->btTestConnection, &QAbstractButton::clicked, this, &QxEventServiceWidget::testConnection); connect(ui->btExportEventInfo, &QAbstractButton::clicked, this, &QxEventServiceWidget::exportEventInfo); connect(ui->btExportStartList, &QAbstractButton::clicked, this, &QxEventServiceWidget::exportStartList); @@ -119,21 +122,41 @@ void QxEventServiceWidget::testConnection() using namespace shv::iotqt::rpc; using namespace shv::chainpack; + delete findChild(); + auto *rpc = new DeviceConnection("QuickEventTest", this); rpc->setConnectionString(ui->edServerUrl->text()); + RpcValue::Map opts; + RpcValue::Map device; + device["deviceId"] = ui->edApiToken->text().toStdString(); + opts["device"] = device; + rpc->setConnectionOptions(opts); connect(rpc, &ClientConnection::brokerConnectedChanged, this, [this, rpc](bool is_connected) { if (is_connected) { - rpc->deleteLater(); - setMessage(tr("Connected OK")); + setMessage(tr("Broker connected OK")); + auto *rpc_call = shv::iotqt::rpc::RpcCall::create(rpc) + ->setShvPath(".broker/currentClient") + ->setMethod("info"); + connect(rpc_call, &shv::iotqt::rpc::RpcCall::maybeResult, this, [this](const ::shv::chainpack::RpcValue &result, const shv::chainpack::RpcError &error) { + if (error.isValid()) { + setMessage(tr("Client info discovery error: %1").arg(error.toString()), MessageType::Error); + } + else { + const auto &info = result.asMap(); + auto mount_point = info.value("mountPoint").to(); + auto event_id = mount_point.section('/', -1, -1).toInt(); + ui->edEventId->setValue(event_id); + setMessage(tr("Event mounted at: %1, event id: %2").arg(mount_point).arg(event_id)); + } + }); + rpc_call->start(); } }); - connect(rpc, &ClientConnection::socketError, this, [this, rpc](const QString &error) { - rpc->deleteLater(); + connect(rpc, &ClientConnection::socketError, this, [this](const QString &error) { setMessage(tr("Connection error: %1").arg(error), MessageType::Error); }); - connect(rpc, &ClientConnection::brokerLoginError, this, [this, rpc](const auto &error) { - rpc->deleteLater(); + connect(rpc, &ClientConnection::brokerLoginError, this, [this](const auto &error) { setMessage(tr("Login error: %1").arg(QString::fromStdString(error.toString())), MessageType::Error); }); rpc->open(); diff --git a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp index 1c16121ce..e2c50edd5 100644 --- a/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp +++ b/quickevent/app/quickevent/plugins/Event/src/services/qx/runchangedialog.cpp @@ -220,7 +220,7 @@ void RunChangeDialog::resolveChanges(bool is_accepted) url.setQuery(query); request.setUrl(url); - request.setRawHeader(QxEventService::QX_API_TOKEN, svc->apiToken()); + request.setRawHeader(QxEventService::QX_API_TOKEN, svc->apiToken().toUtf8()); auto *reply = nm->get(request); connect(reply, &QNetworkReply::finished, this, [this, reply]() { if (reply->error() == QNetworkReply::NetworkError::NoError) { From 006dcd4200ab8702b38d40ff09eaf2d3d6d03d41 Mon Sep 17 00:00:00 2001 From: Fanda Vacek Date: Mon, 2 Feb 2026 17:13:02 +0100 Subject: [PATCH 29/29] Fix CI linter --- .github/actions/run-linter/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/run-linter/action.yml b/.github/actions/run-linter/action.yml index 0d70e8a3a..3768f8833 100644 --- a/.github/actions/run-linter/action.yml +++ b/.github/actions/run-linter/action.yml @@ -20,7 +20,7 @@ runs: - uses: mjp41/workaround8649@c8550b715ccdc17f89c8d5c28d7a48eeff9c94a8 if: runner.os == 'Linux' with: - os: ubuntu-latest + os: ubuntu-24.04 - name: Build autogenerated stuff shell: bash