Skip to content

Commit

Permalink
Save assigned SI option in assign card to runner dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
fvacek committed Aug 10, 2020
1 parent 8ddcff6 commit 3e85bc9
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 25 deletions.
14 changes: 11 additions & 3 deletions quickevent/app/plugins/CardReader/src/cardreaderplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ int CardReaderPlugin::currentStageId()
return ret;
}

int CardReaderPlugin::cardIdToSiId(int card_id)
{
qf::core::sql::Query q = qf::core::sql::Query::fromExec("SELECT siId FROM cards WHERE id=" QF_IARG(card_id) , qf::core::Exception::Throw);
if(q.next())
return q.value(0).toInt();
return 0;
}

int CardReaderPlugin::findRunId(int si_id, int si_finish_time, QString *err_msg)
{
int ret = 0;
Expand Down Expand Up @@ -421,14 +429,14 @@ void CardReaderPlugin::updateCheckedCardValuesSql(const quickevent::core::si::Ch
void CardReaderPlugin::updateCardToRunAssignmentInPunches(int stage_id, int card_id, int run_id)
{
qfLogFuncFrame();
qf::core::sql::Query q = qf::core::sql::Query::fromExec("SELECT siId FROM cards WHERE id=" QF_IARG(card_id) );
if(q.next()) {
int si_id = q.value(0).toInt();
int si_id = cardIdToSiId(card_id);
if(si_id > 0) {
QString qs = "UPDATE punches SET runId=" QF_IARG(run_id)
" WHERE stageId=" QF_IARG(stage_id)
" AND siId=" QF_IARG(si_id)
" AND (runId IS NULL OR runId=0)";
qfDebug() << qs;
qf::core::sql::Query q;
q.execThrow(qs);
}
}
Expand Down
1 change: 1 addition & 0 deletions quickevent/app/plugins/CardReader/src/cardreaderplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class CARDREADERPLUGIN_DECL_EXPORT CardReaderPlugin : public qf::qmlwidgets::fra
Q_INVOKABLE QString settingsPrefix();

int currentStageId();
int cardIdToSiId(int card_id);
int findRunId(int si_id, int si_finish_time, QString *err_msg = nullptr);
bool isCardLent(int si_id, int si_finish_time, int run_id);
quickevent::core::si::ReadCard readCard(int card_id);
Expand Down
25 changes: 20 additions & 5 deletions quickevent/app/plugins/CardReader/src/cardreaderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,15 +804,30 @@ void CardReaderWidget::assignRunnerToSelectedCard()
dlg.setCentralWidget(w);
//w->setFocusToWidget(Runs::FindRunnerWidget::FocusWidget::Name);
w->focusLineEdit();
connect(w, &Runs::FindRunnerWidget::runnerSelected, [this, card_id, &dlg](const QVariantMap &values) {
dlg.accept();
if(dlg.exec()) {
QVariantMap values = w->selectedRunner();
qfDebug() << values;
int run_id = values.value("runid").toInt();
if(run_id) {
int si_id = thisPlugin()->cardIdToSiId(card_id);
if(run_id > 0 && si_id > 0) {
thisPlugin()->assignCardToRun(card_id, run_id);
if(values.value(Runs::FindRunnerWidget::UseSIInNextStages).toBool()) {
qf::core::sql::QueryBuilder qb;
qb.select("stageId").from("runs").where("id=" QF_IARG(run_id) );
qf::core::sql::Query q;
qfDebug() << qb.toString();
q.execThrow(qb.toString());
if(q.next()) {
int competitor_id = values.value("competitorid").toInt();
int stage_id = q.value("stageId").toInt();
QString qs = "UPDATE runs SET siId=" QF_IARG(si_id) " WHERE competitorId=" QF_IARG(competitor_id) "AND stageId>=" QF_IARG(stage_id);
qfDebug() << qs;
q.execThrow(qs);
}
}
this->ui->tblCards->reloadRow();
}
});
dlg.exec();
}
}

quickevent::gui::audio::Player *CardReaderWidget::audioPlayer()
Expand Down
8 changes: 7 additions & 1 deletion quickevent/app/plugins/Runs/src/findrunneredit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void FindRunnerEdit::setTable(const qf::core::utils::Table &t)
setCompleter(m_completer);
}

QVariantMap FindRunnerEdit::selectedRunner() const
{
return m_selectedRunner;
}

void FindRunnerEdit::onCompleterActivated(const QModelIndex &index)
{
qfLogFuncFrame() << index << index.data();
Expand All @@ -114,6 +119,7 @@ void FindRunnerEdit::onCompleterActivated(const QModelIndex &index)
int row_no = ix.row();
if(row_no >= 0 && row_no < table.rowCount()) {
qf::core::utils::TableRow table_row = table.row(row_no);
emit runnerSelected(table_row.valuesMap(false));
m_selectedRunner = table_row.valuesMap(false);
emit runnerSelected(m_selectedRunner);
}
}
3 changes: 3 additions & 0 deletions quickevent/app/plugins/Runs/src/findrunneredit.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ class FindRunnerEdit : public QLineEdit
//const qf::core::utils::Table& table() const {return m_table;}
void setTable(const qf::core::utils::Table &t);

QVariantMap selectedRunner() const;

Q_SIGNAL void runnerSelected(const QVariantMap &runner_values);
private:
Q_SLOT void onCompleterActivated(const QModelIndex &index);
private:
FindRunnersModel *m_findRunnersModel = nullptr;
QCompleter *m_completer = nullptr;
QVariantMap m_selectedRunner;
};

#endif
20 changes: 11 additions & 9 deletions quickevent/app/plugins/Runs/src/findrunnerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ static RunsPlugin *runsPlugin()
return plugin;
}

const QString FindRunnerWidget::UseSIInNextStages = QStringLiteral("useSIInNextStages");

FindRunnerWidget::FindRunnerWidget(int stage_id, QWidget *parent)
: QWidget(parent)
, ui(new Ui::FindRunnerWidget)
Expand All @@ -29,24 +31,24 @@ FindRunnerWidget::FindRunnerWidget(int stage_id, QWidget *parent)
ui->setupUi(this);
ui->edFindRunner->setFocus();
ui->edFindRunner->setTable(runsPlugin()->runnersTable(stage_id));
connect(ui->edFindRunner, &FindRunnerEdit::runnerSelected, this, &FindRunnerWidget::runnerSelected);
//connect(ui->edFindRunner, &FindRunnerEdit::runnerSelected, this, &FindRunnerWidget::onRunnerSelected);
}

FindRunnerWidget::~FindRunnerWidget()
{
delete ui;
}

void FindRunnerWidget::focusLineEdit()
QVariantMap FindRunnerWidget::selectedRunner() const
{
ui->edFindRunner->setFocus();
QVariantMap ret = ui->edFindRunner->selectedRunner();
ret[UseSIInNextStages] = ui->cbxUseSIInNextStages->isChecked();
return ret;
}
/*
void FindRunnerWidget::reload()

void FindRunnerWidget::focusLineEdit()
{
qfLogFuncFrame();
if(!isVisible())
return;
ui->edFindRunner->setFocus();
}
*/

}
6 changes: 3 additions & 3 deletions quickevent/app/plugins/Runs/src/findrunnerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "runspluginglobal.h"

#include <QWidget>
#include <QVariantMap>

namespace qf {
namespace core {
Expand All @@ -25,17 +26,16 @@ class RUNSPLUGIN_DECL_EXPORT FindRunnerWidget : public QWidget
{
Q_OBJECT
public:
enum class FocusWidget {Name, Registration};
static const QString UseSIInNextStages;
public:
explicit FindRunnerWidget(int stage_id, QWidget *parent = 0);
~FindRunnerWidget() Q_DECL_OVERRIDE;

Q_SIGNAL void runnerSelected(const QVariantMap &runner_values);
QVariantMap selectedRunner() const;

void focusLineEdit();
private:
Ui::FindRunnerWidget *ui;
//int m_stageId = 0;
};

}
Expand Down
11 changes: 9 additions & 2 deletions quickevent/app/plugins/Runs/src/findrunnerwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>661</width>
<height>56</height>
<width>656</width>
<height>117</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -24,6 +24,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxUseSIInNextStages">
<property name="text">
<string>Use this SI card in next stages</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down
2 changes: 1 addition & 1 deletion quickevent/app/plugins/Runs/src/runsplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const qf::core::utils::Table &RunsPlugin::runnersTable(int stage_id)
qfs::QueryBuilder qb;
qb.select2("competitors", "registration")
.select("COALESCE(lastName, '') || ' ' || COALESCE(firstName, '') AS competitorName")
.select2("runs", "id, siId")
.select2("runs", "id, siId, competitorId")
.select("runs.id AS runId")
.select2("classes", "name")
.from("competitors")
Expand Down
2 changes: 1 addition & 1 deletion quickevent/app/quickevent/src/appversion.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define APP_VERSION "2.3.6"
#define APP_VERSION "2.3.7"

0 comments on commit 3e85bc9

Please sign in to comment.