Skip to content

Commit

Permalink
Update libshv
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Apr 29, 2024
1 parent 5ed0795 commit 07563ca
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 286 deletions.
1 change: 0 additions & 1 deletion quickevent/app/quickevent/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ if(WITH_QE_SHVAPI)
plugins/Event/src/services/shvapi/shvnode.cpp
plugins/Event/src/services/shvapi/sqlnode.cpp
plugins/Event/src/services/shvapi/nodes.cpp
plugins/Event/src/services/shvapi/rpcsqlresult.cpp
)
endif()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ void CardReaderWidget::updateTableView(int card_id)
void CardReaderWidget::showSelectedReceipt()
{
qfLogFuncFrame();
int card_id = ui->tblCards->selectedRow().value("cards.id").toInt();
int card_id = ui->tblCards->tableRow().value("cards.id").toInt();
getPlugin<ReceiptsPlugin>()->previewReceipt(card_id);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool CompetitorDocument::saveData()
q.exec(QStringLiteral("SELECT id FROM runs WHERE competitorId = %1").arg(competitor_id));
while(q.next()) {
int run_id = q.value(0).toInt();
old_records[run_id] = runs_plugin->runRecord(run_id);
old_records[run_id] = runs_plugin->runsRecord(run_id);
}
}
bool siid_dirty = isDirty("competitors.siId");
Expand Down Expand Up @@ -69,7 +69,7 @@ bool CompetitorDocument::saveData()
if(m_isEmitDbEventsOnSave) {
getPlugin<EventPlugin>()->emitDbEvent(Event::EventPlugin::DBEVENT_COMPETITOR_COUNTS_CHANGED);
for (auto run_id : m_lastInsertedRunsIds) {
auto rec = runs_plugin->runRecord(run_id);
auto rec = runs_plugin->runsRecord(run_id);
getPlugin<EventPlugin>()->emitDbEvent(Event::EventPlugin::DBEVENT_RUN_CHANGED, QVariantList {run_id, rec});
}
}
Expand All @@ -90,7 +90,7 @@ bool CompetitorDocument::saveData()
getPlugin<EventPlugin>()->emitDbEvent(Event::EventPlugin::DBEVENT_COMPETITOR_COUNTS_CHANGED);
}
for(const auto &[run_id, old_record] : old_records.asKeyValueRange()) {
auto record = runs_plugin->runRecord(run_id);
auto record = runs_plugin->runsRecord(run_id);
auto diff = qf::core::sql::recordDiff(old_record, record);
if (!diff.isEmpty()) {
getPlugin<EventPlugin>()->emitDbEvent(Event::EventPlugin::DBEVENT_RUN_CHANGED, QVariantList {run_id, diff});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,12 @@ Client::Client(QObject *parent)
new DotAppNode(m_rootNode);
connect(event_plugin, &EventPlugin::eventOpenChanged, this, [this](bool is_open) {
if (is_open) {
auto *event_plugin = getPlugin<EventPlugin>();
auto *event = new EventNode(m_rootNode);
auto *stage = new shv::iotqt::node::ShvNode("stage", event);
for (auto i = 0; i < event_plugin->stageCount(); i++) {
auto *nd = new shv::iotqt::node::ShvNode(std::to_string(i + 1), stage);
auto *runs = new SqlViewNode("runs", nd);
auto qb = getPlugin<RunsPlugin>()->runsQuery(i + 1);
runs->setQueryBuilder(qb);
}
new SqlNode(m_rootNode);
auto *event = new EventNode(m_rootNode);
auto *stage = new shv::iotqt::node::ShvNode("currentStage", event);
auto *runs = new CurrentStageSqlViewNode("startList", stage);
auto qb = getPlugin<RunsPlugin>()->startListQuery();
runs->setQueryBuilder(qb);
}
else {
qDeleteAll(m_rootNode->findChildren<EventNode*>());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "nodes.h"
#include "rpcsqlresult.h"

#include "sqlnode.h"
#include "../../eventplugin.h"

#include <qf/qmlwidgets/framework/mainwindow.h>
Expand All @@ -10,6 +10,7 @@

#include <shv/chainpack/rpc.h>
#include <shv/coreqt/rpc.h>
#include <shv/coreqt/data/rpcsqlresult.h>

#include <QSqlField>

Expand Down Expand Up @@ -53,8 +54,10 @@ RpcValue DotAppNode::callMethod(const StringViewList &shv_path, const std::strin
//=========================================================
// EventNode
//=========================================================
static auto METH_CURRENT_STAGE = "currentStage";
static auto SIG_RUN_CHANGED = "runChanged";
static const auto METH_CURRENT_STAGE = "currentStage";
static const auto METH_EVENT_CONFIG = "eventConfig";
static const auto METH_RUN_CHANGED = "runChanged";
static const auto SIG_RUN_CHANGED = "runChanged";

EventNode::EventNode(shv::iotqt::node::ShvNode *parent)
: Super("event", parent)
Expand Down Expand Up @@ -82,7 +85,8 @@ const std::vector<MetaMethod> &EventNode::metaMethods()
methods::LS,
{METH_NAME, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read},
{METH_CURRENT_STAGE, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read},
//{SIG_RUN_CHANGED, MetaMethod::Signature::VoidParam, MetaMethod::Flag::IsSignal, Rpc::ROLE_READ},
{METH_EVENT_CONFIG, MetaMethod::Flag::IsGetter, {}, "RpcValue", AccessLevel::Read},
{METH_RUN_CHANGED, MetaMethod::Flag::None, {}, {}, AccessLevel::Read, {{SIG_RUN_CHANGED, "Map"}}},
};
return meta_methods;
}
Expand All @@ -97,6 +101,10 @@ RpcValue EventNode::callMethod(const StringViewList &shv_path, const std::string
if(method == METH_CURRENT_STAGE) {
return getPlugin<EventPlugin>()->currentStageId();
}
if(method == METH_EVENT_CONFIG) {
auto cfg = getPlugin<EventPlugin>()->eventConfig();
return shv::coreqt::rpc::qVariantToRpcValue(cfg->values());
}
}
return Super::callMethod(shv_path, method, params, user_id);
}
Expand All @@ -106,22 +114,27 @@ RpcValue EventNode::callMethod(const StringViewList &shv_path, const std::string
//=========================================================
static const auto METH_TABLE = "table";
static const auto METH_RECORD = "record";
static const auto METH_SET_RECORD = "setRecord";
static const auto SIG_REC_CHNG = "recchng";
//static const auto METH_SET_RECORD = "setRecord";
//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<MetaMethod> &SqlViewNode::metaMethods()
{
static std::vector<MetaMethod> meta_methods {
methods::DIR,
methods::LS,
{METH_TABLE, MetaMethod::Flag::None, {}, "RpcValue", AccessLevel::Read},
{METH_RECORD, MetaMethod::Flag::None, "RpcValue", "RpcValue", AccessLevel::Read, {{SIG_REC_CHNG}} },
{METH_SET_RECORD, MetaMethod::Flag::None, "RpcValue", {}, AccessLevel::Write},
{METH_RECORD, MetaMethod::Flag::None, "RpcValue", "RpcValue", AccessLevel::Read },
//{METH_SET_RECORD, MetaMethod::Flag::None, "RpcValue", {}, AccessLevel::Write},
};
return meta_methods;
}
Expand All @@ -134,33 +147,42 @@ RpcValue SqlViewNode::callMethod(const StringViewList &shv_path, const std::stri
if(method == METH_TABLE) {
const auto &m = params.asMap();
auto where = m.value("where").to<QString>();
auto qb = m_queryBuilder;
auto qb = effectiveQueryBuilder();
if (!where.isEmpty()) {
qb.where(where);
}
qf::core::sql::Query q;
QString qs = qb.toString();
q.exec(qs, qf::core::Exception::Throw);
auto res = RpcSqlResult::fromQuery(q);
auto res = SqlNode::rpcSqlResultFromQuery(q);
return res.toRpcValue();
}
if(method == METH_RECORD) {
auto id = params.toInt();
auto qb = m_queryBuilder;
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 shvapi::recordToMap(q.record());
}
else {
return RpcValue::Map{};
return SqlNode::recordToMap(q.record());
}
return RpcValue::Map{};
}
}
return Super::callMethod(shv_path, method, params, user_id);
}

//=========================================================
// CurrentStageSqlViewNode
//=========================================================
qf::core::sql::QueryBuilder CurrentStageSqlViewNode::effectiveQueryBuilder()
{
auto qb = Super::effectiveQueryBuilder();
auto *event_plugin = getPlugin<EventPlugin>();
qb.where(QStringLiteral("runs.stageId=%1").arg(event_plugin->currentStageId()));
return qb;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,26 @@ class SqlViewNode : public shvapi::ShvNode
: Super(name, parent)
{}
void setQueryBuilder(const qf::core::sql::QueryBuilder &qb);
protected:
virtual qf::core::sql::QueryBuilder effectiveQueryBuilder();
private:
const std::vector<shv::chainpack::MetaMethod> &metaMethods() override;
shv::chainpack::RpcValue callMethod(const StringViewList &shv_path, const std::string &method, const shv::chainpack::RpcValue &params, const shv::chainpack::RpcValue &user_id) override;
private:
qf::core::sql::QueryBuilder m_queryBuilder;
};

class CurrentStageSqlViewNode : public SqlViewNode
{
Q_OBJECT

using Super = SqlViewNode;
public:
explicit CurrentStageSqlViewNode(const std::string &name, shv::iotqt::node::ShvNode *parent)
: Super(name, parent)
{}
protected:
qf::core::sql::QueryBuilder effectiveQueryBuilder() override;
};

}
Loading

0 comments on commit 07563ca

Please sign in to comment.