Skip to content

Commit

Permalink
QE: #376 Štafety - chybný startovní čas při vyčtení čipů ve
Browse files Browse the repository at this point in the history
špatném pořadí.

* autorefresh checkbox in statistics widget removed
* autorefresh checkbox in card reader widget removed
  • Loading branch information
fvacek committed May 19, 2019
1 parent 337467a commit 5e19abf
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../services/racomclient.h"

#include <Event/eventplugin.h>
#include <Runs/runsplugin.h>

#include <quickevent/core/og/timems.h>
#include <quickevent/core/si/punchrecord.h>
Expand Down Expand Up @@ -40,6 +41,14 @@ static Event::EventPlugin* eventPlugin()
return plugin;
}

static Runs::RunsPlugin *runsPlugin()
{
qf::qmlwidgets::framework::MainWindow *fwk = qf::qmlwidgets::framework::MainWindow::frameWork();
auto *plugin = qobject_cast<Runs::RunsPlugin *>(fwk->plugin("Runs"));
QF_ASSERT_EX(plugin != nullptr, "Bad plugin");
return plugin;
}

const QLatin1String CardReaderPlugin::SETTINGS_PREFIX("plugins/CardReader");
const int CardReaderPlugin::FINISH_PUNCH_POS = quickevent::core::si::PunchRecord::FINISH_PUNCH_CODE;

Expand Down Expand Up @@ -453,33 +462,59 @@ void CardReaderPlugin::assignCardToRun(int card_id, int run_id)
processCardToRunAssignment(card_id, run_id);
}

void CardReaderPlugin::processCardToRunAssignment(int card_id, int run_id)
bool CardReaderPlugin::processCardToRunAssignment(int card_id, int run_id)
{
bool is_relays = eventPlugin()->eventConfig()->isRelays();
if(is_relays) {
/// take start time from previous leg
qf::core::sql::Query q;
q.execThrow("SELECT relayId, leg FROM runs WHERE id=" + QString::number(run_id));
if(q.next()) {
int relay_id = q.value(0).toInt();
int leg = q.value(1).toInt();
if(leg > 1) {
q.execThrow("SELECT finishTimeMs FROM runs"
" WHERE relayId=" + QString::number(relay_id)
+ " AND leg=" + QString::number(leg-1));
if(q.next()) {
int start_time = q.value(0).toInt();
q.execThrow("UPDATE runs SET startTimeMs=" + QString::number(start_time)
q.execThrow("SELECT relayId, leg, startTimeMs FROM runs WHERE id=" + QString::number(run_id));
if(!q.next()) {
qfError() << "Run not found, id:" << run_id;
return false;
}
int relay_id = q.value(0).toInt();
int leg = q.value(1).toInt();
QVariant start_time = q.value(2);
if(start_time.isNull() && leg > 1) {
/// if strt time not set, take start time from previous leg
q.execThrow("SELECT finishTimeMs FROM runs"
" WHERE relayId=" + QString::number(relay_id)
+ " AND leg=" + QString::number(leg-1));
if(q.next()) {
int prev_finish_time = q.value(0).toInt();
if(prev_finish_time > 0) {
q.execThrow("UPDATE runs SET startTimeMs=" + QString::number(prev_finish_time)
+ " WHERE relayId=" + QString::number(relay_id)
+ " AND leg=" + QString::number(leg)
+ " AND COALESCE(startTimeMs, 0)=0");
}
}
}
quickevent::core::si::CheckedCard checked_card = checkCard(card_id, run_id);
updateCheckedCardValuesSql(checked_card);
eventPlugin()->emitDbEvent(Event::EventPlugin::DBEVENT_CARD_PROCESSED_AND_ASSIGNED, checked_card, true);

/// if next leg is finished and has not start time set, proces it too
/// This covers cases when next leg is read-out before this one
q.execThrow("SELECT id, startTimeMs, finishTimeMs FROM runs"
" WHERE relayId=" + QString::number(relay_id)
+ " AND leg=" + QString::number(leg+1));
if(q.next()) {
start_time = q.value(1);
int finish_time = q.value(2).toInt();
if(finish_time > 0 && start_time.isNull()) {
run_id = q.value(0).toInt();
card_id = runsPlugin()->cardForRun(run_id);
processCardToRunAssignment(card_id, run_id);
}
}
}
else {
quickevent::core::si::CheckedCard checked_card = checkCard(card_id, run_id);
updateCheckedCardValuesSql(checked_card);
eventPlugin()->emitDbEvent(Event::EventPlugin::DBEVENT_CARD_PROCESSED_AND_ASSIGNED, checked_card, true);
}
quickevent::core::si::CheckedCard checked_card = checkCard(card_id, run_id);
updateCheckedCardValuesSql(checked_card);
eventPlugin()->emitDbEvent(Event::EventPlugin::DBEVENT_CARD_ASSIGNED, checked_card, true);
return true;
}

int CardReaderPlugin::resolveAltCode(int maybe_alt_code, int stage_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CARDREADERPLUGIN_DECL_EXPORT CardReaderPlugin : public qf::qmlwidgets::fra

Q_INVOKABLE bool reloadTimesFromCard(int card_id, int run_id = 0);
void assignCardToRun(int card_id, int run_id);
void processCardToRunAssignment(int card_id, int run_id);
bool processCardToRunAssignment(int card_id, int run_id);

static int resolveAltCode(int maybe_alt_code, int stage_id);

Expand Down
22 changes: 13 additions & 9 deletions quickevent/app/plugins/qml/CardReader/src/cardreaderwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <QCheckBox>
#include <QPushButton>
#include <QProgressDialog>
#include <QTimer>

namespace qfc = qf::core;
namespace qfm = qf::core::model;
Expand Down Expand Up @@ -205,6 +206,15 @@ CardReaderWidget::CardReaderWidget(QWidget *parent)
}
ui->tblCards->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->tblCards, &qfw::TableView::customContextMenuRequested, this, &CardReaderWidget::onCustomContextMenuRequest);
/*
{
QTimer *t = new QTimer(this);
connect(t, &QTimer::timeout, [this]() {
qfInfo() << "CardReaderWidget visible:" << isVisible();
});
t->start(2000);
}
*/
}

void CardReaderWidget::onCustomContextMenuRequest(const QPoint & pos)
Expand Down Expand Up @@ -380,12 +390,6 @@ void CardReaderWidget::settleDownInPartWidget(CardReaderPartWidget *part_widget)
onCbxCardCheckersActivated(m_cbxCardCheckers->currentIndex());
}
main_tb->addSeparator();
{
m_cbxAutoRefresh = new QCheckBox();
m_cbxAutoRefresh->setText(tr("Auto refresh"));
main_tb->addWidget(m_cbxAutoRefresh);
}
main_tb->addSeparator();
{
QLabel *lbl = new QLabel(tr(" Reader mode "));
main_tb->addWidget(lbl);
Expand Down Expand Up @@ -446,8 +450,7 @@ void CardReaderWidget::onDbEventNotify(const QString &domain, int connection_id,
Q_UNUSED(connection_id)
if(domain == QLatin1String(Event::EventPlugin::DBEVENT_CARD_READ)) {
int card_id = data.toInt();
// TODO: only if widget is visible (plugin window active)
if(m_cbxAutoRefresh->isChecked())
if(isVisible())
updateTableView(card_id);
}
}
Expand Down Expand Up @@ -705,7 +708,8 @@ void CardReaderWidget::processReadCard(const quickevent::core::si::ReadCard &rea
thisPlugin()->assignCardToRun(card_id, read_card.runId());
}
if(card_id) {
/// must be after card processing, receipts printer needs this
/// receipts printer needs this
/// emitDbEvent is using queued invocation
eventPlugin()->emitDbEvent(Event::EventPlugin::DBEVENT_CARD_READ, card_id, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ private slots:
qf::qmlwidgets::Action *m_actSettings = nullptr;
qf::core::model::SqlTableModel *m_cardsModel = nullptr;
QComboBox *m_cbxCardCheckers = nullptr;
QCheckBox *m_cbxAutoRefresh = nullptr;
QComboBox *m_cbxPunchMarking = nullptr;
quickevent::gui::audio::Player *m_audioPlayer = nullptr;
siut::DeviceDriver *f_siDriver = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion quickevent/app/plugins/qml/Event/src/Event/eventplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static auto QBE_EXT = QStringLiteral(".qbe");
const char* EventPlugin::DBEVENT_COMPETITOR_COUNTS_CHANGED = "competitorCountsChanged";
const char* EventPlugin::DBEVENT_CARD_READ = "cardRead";
//const char* EventPlugin::DBEVENT_CARD_CHECKED = "cardChecked";
const char* EventPlugin::DBEVENT_CARD_ASSIGNED = "cardAssigned";
const char* EventPlugin::DBEVENT_CARD_PROCESSED_AND_ASSIGNED = "cardProcessedAndAssigned";
const char* EventPlugin::DBEVENT_PUNCH_RECEIVED = "punchReceived";
const char* EventPlugin::DBEVENT_REGISTRATIONS_IMPORTED = "registrationsImported";
const char* EventPlugin::DBEVENT_STAGE_START_CHANGED = "stageStartChanged";
Expand Down
2 changes: 1 addition & 1 deletion quickevent/app/plugins/qml/Event/src/Event/eventplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class EVENTPLUGIN_DECL_EXPORT EventPlugin : public qf::qmlwidgets::framework::Pl
static const char* DBEVENT_COMPETITOR_COUNTS_CHANGED; //< number of competitors in classes changed
static const char* DBEVENT_CARD_READ;
//static const char* DBEVENT_CARD_CHECKED;
static const char* DBEVENT_CARD_ASSIGNED;
static const char* DBEVENT_CARD_PROCESSED_AND_ASSIGNED;
static const char* DBEVENT_PUNCH_RECEIVED;
static const char* DBEVENT_REGISTRATIONS_IMPORTED;
static const char* DBEVENT_STAGE_START_CHANGED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ void EmmaClient::onDbEventNotify(const QString &domain, int connection_id, const
Q_UNUSED(connection_id)
Q_UNUSED(data)
//qfInfo() << domain << data;
if(domain == QLatin1String(Event::EventPlugin::DBEVENT_CARD_ASSIGNED)) {
if(domain == QLatin1String(Event::EventPlugin::DBEVENT_CARD_PROCESSED_AND_ASSIGNED)) {
onCardChecked(data.toMap());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void RelaysPlugin::onDbEventNotify(const QString &domain, int connection_id, con
{
Q_UNUSED(connection_id)
qfLogFuncFrame() << "domain:" << domain << "payload:" << data;
if(domain == QLatin1String(Event::EventPlugin::DBEVENT_CARD_ASSIGNED)) {
if(domain == QLatin1String(Event::EventPlugin::DBEVENT_CARD_PROCESSED_AND_ASSIGNED)) {
processRunnerFinished(quickevent::core::si::CheckedCard(data.toMap()));
}
emit dbEventNotify(domain, connection_id, data);
Expand Down
51 changes: 23 additions & 28 deletions quickevent/app/plugins/qml/Runs/src/eventstatisticswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ void FooterView::resetFooterAttributes()

void FooterView::syncSectionSizes()
{
qfInfo() << Q_FUNC_INFO << this;
//qfInfo() << Q_FUNC_INFO << this;
QAbstractItemModel *m = model();
QF_ASSERT(m != nullptr, "Model is NULL!", return);

Expand Down Expand Up @@ -413,24 +413,22 @@ EventStatisticsWidget::EventStatisticsWidget(QWidget *parent)
m_tableFooterView->setMinimumHeight(20);
ui->tableLayout->addWidget(m_tableFooterView);

connect(ui->chkAutoRefresh, &QCheckBox::toggled, [this](bool checked) {
if(checked)
autoRefreshTimer()->start();
else
autoRefreshTimer()->stop();
});

connect(eventPlugin(), &Event::EventPlugin::dbEventNotify, this, &EventStatisticsWidget::onDbEventNotify, Qt::QueuedConnection);
connect(eventPlugin(), &Event::EventPlugin::currentStageIdChanged, this, &EventStatisticsWidget::reload);
connect(eventPlugin(), &Event::EventPlugin::currentStageIdChanged, this, &EventStatisticsWidget::reloadDeferred);

initAutoRefreshTimer();
}

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

void EventStatisticsWidget::reloadLater()
void EventStatisticsWidget::reloadDeferred()
{
if(!isVisible())
return;

if(!m_reloadLaterTimer) {
m_reloadLaterTimer = new QTimer(this);
m_reloadLaterTimer->setInterval(200);
Expand Down Expand Up @@ -477,9 +475,9 @@ void EventStatisticsWidget::reload()
void EventStatisticsWidget::onDbEventNotify(const QString &domain, const QVariant &payload)
{
Q_UNUSED(payload)
if(domain == QLatin1String(Event::EventPlugin::DBEVENT_CARD_READ)
if(domain == QLatin1String(Event::EventPlugin::DBEVENT_CARD_PROCESSED_AND_ASSIGNED)
|| domain == QLatin1String(Event::EventPlugin::DBEVENT_COMPETITOR_COUNTS_CHANGED)) {
reloadOnEvent();
reloadDeferred();
}
}

Expand All @@ -505,15 +503,20 @@ int EventStatisticsWidget::currentStageId()
return ret;
}

QTimer *EventStatisticsWidget::autoRefreshTimer()
void EventStatisticsWidget::initAutoRefreshTimer()
{
if(!m_autoRefreshTimer) {
m_autoRefreshTimer = new QTimer(this);
EventStatisticsOptions::Options opts(options());
m_autoRefreshTimer->setInterval(opts.autoRefreshSec() * 1000);
connect(m_autoRefreshTimer, &QTimer::timeout, this, &EventStatisticsWidget::reloadOnEvent);
EventStatisticsOptions::Options opts(options());
int sec = opts.autoRefreshSec();
if(sec > 0) {
if(!m_autoRefreshTimer) {
m_autoRefreshTimer = new QTimer(this);
connect(m_autoRefreshTimer, &QTimer::timeout, this, &EventStatisticsWidget::reloadDeferred);
}
m_autoRefreshTimer->start(sec * 1000);
}
else {
QF_SAFE_DELETE(m_autoRefreshTimer);
}
return m_autoRefreshTimer;
}

void EventStatisticsWidget::on_btReload_clicked()
Expand Down Expand Up @@ -597,13 +600,6 @@ void EventStatisticsWidget::on_btClearNewInSelectedRows_clicked()
reload();
}

void EventStatisticsWidget::reloadOnEvent()
{
if(ui->chkAutoRefresh->isChecked()) {
reloadLater();
}
}

void EventStatisticsWidget::clearNewResults(const QList<int> &classdefs_ids, const QList<int> &runners_finished)
{
qfLogFuncFrame();
Expand All @@ -630,8 +626,7 @@ void EventStatisticsWidget::on_btOptions_clicked()
{
EventStatisticsOptions dlg(this);
if(dlg.exec()) {
EventStatisticsOptions::Options opts(options());
autoRefreshTimer()->setInterval(opts.autoRefreshSec() * 1000);
initAutoRefreshTimer();
}
}

Expand Down
6 changes: 2 additions & 4 deletions quickevent/app/plugins/qml/Runs/src/eventstatisticswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EventStatisticsWidget : public QWidget
explicit EventStatisticsWidget(QWidget *parent = nullptr);
~EventStatisticsWidget();

Q_SLOT void reloadLater();
Q_SLOT void reloadDeferred();
void reload();
Q_SLOT void onDbEventNotify(const QString &domain, const QVariant &payload);
Q_SLOT void onVisibleChanged(bool is_visible);
Expand All @@ -33,11 +33,9 @@ private slots:
void on_btPrintResultsSelected_clicked();
void on_btPrintResultsNew_clicked();
void on_btClearNewInSelectedRows_clicked();

void reloadOnEvent();
private:
int currentStageId();
QTimer* autoRefreshTimer();
void initAutoRefreshTimer();
//QTimer* printResultsTimer();
void clearNewResults(const QList<int> &classdefs_ids, const QList<int> &runners_finished);

Expand Down
7 changes: 0 additions & 7 deletions quickevent/app/plugins/qml/Runs/src/eventstatisticswidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,6 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkAutoRefresh">
<property name="text">
<string>auto refresh</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
Expand Down

0 comments on commit 5e19abf

Please sign in to comment.