Skip to content

Commit

Permalink
Relay - can add unregistered runner to relay - fix of Quick-Box#665
Browse files Browse the repository at this point in the history
Fix missing disconnect in dialog destructor.
  • Loading branch information
arnost00 committed Oct 31, 2021
1 parent 6392f51 commit b5fdec8
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ AddLegDialogWidget::AddLegDialogWidget(QWidget *parent)
auto *reg_model = getPlugin<CompetitorsPlugin>()->registrationsModel();
ui->tblRegistrations->setTableModel(reg_model);
ui->tblRegistrations->setReadOnly(true);
connect(reg_model, &qf::core::model::SqlTableModel::reloaded, [this]() {
regUpdateConnect = connect(reg_model, &qf::core::model::SqlTableModel::reloaded, [this]() {
ui->tblRegistrations->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents);
});

connect(ui->edFilter, &QLineEdit::textChanged, this, &AddLegDialogWidget::onFilterTextChanged);
connect(ui->tblCompetitors, &qf::qmlwidgets::TableView::doubleClicked, this, &AddLegDialogWidget::onCompetitorSelected);
connect(ui->tblRegistrations, &qf::qmlwidgets::TableView::doubleClicked, this, &AddLegDialogWidget::onRegistrationSelected);
connect(ui->btUseUnregRunner, &QPushButton::clicked, this, &AddLegDialogWidget::onUnregistredRunnerAdded);
}

AddLegDialogWidget::~AddLegDialogWidget()
{
disconnect(regUpdateConnect);
delete ui;
}

Expand Down Expand Up @@ -177,3 +179,35 @@ int AddLegDialogWidget::findFreeLeg()
}
return free_leg;
}

void AddLegDialogWidget::onUnregistredRunnerAdded()
{
QString firstName = ui->edFirstName->text();
QString lastName = ui->edLastName->text();
if (lastName.isEmpty() || firstName.isEmpty())
return;

Competitors::CompetitorDocument doc;
doc.loadForInsert();
doc.setValue("firstName", firstName);
doc.setValue("lastName", lastName);
doc.setValue("siid", ui->edSiId->value());
doc.setValue("classId", classId());
doc.save();
QString name = lastName + " " + firstName;
int run_id = doc.lastInsertedRunsIds().value(0);
QF_ASSERT(run_id > 0, "Bad insert", return);
int free_leg = findFreeLeg();
qf::core::sql::Query q;
q.exec("UPDATE runs SET relayId=" + QString::number(relayId()) + ", leg=" + QString::number(free_leg)
+ " WHERE id=" + QString::number(run_id), qf::core::Exception::Throw);

updateLegAddedStatus(tr("Runner %1 was assigned to leg %2")
.arg(name)
.arg(free_leg));
emit legAdded();

ui->edFirstName->setText("");
ui->edLastName->setText("");
ui->edSiId->setValue(0);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AddLegDialogWidget : public qf::qmlwidgets::framework::DialogWidget
void onFilterTextChanged();
void onCompetitorSelected();
void onRegistrationSelected();
void onUnregistredRunnerAdded();

void updateLegAddedStatus(const QString &msg);

Expand All @@ -34,6 +35,7 @@ class AddLegDialogWidget : public qf::qmlwidgets::framework::DialogWidget
Ui::AddLegDialogWidget *ui;
QTimer *m_updateStatusTimer = nullptr;
QString m_defaultStatusText;
QMetaObject::Connection regUpdateConnect;
};

#endif // ADDLEGDIALOGWIDGET_H
102 changes: 101 additions & 1 deletion quickevent/app/quickevent/plugins/Relays/src/addlegdialogwidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0">
<property name="spacing">
<number>5</number>
</property>
Expand Down Expand Up @@ -91,6 +91,97 @@
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Unregistered runner</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>First name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="edLastName">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Last name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="edFirstName">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>4</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="label_6">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>SI</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QSpinBox" name="edSiId">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<number>99999999</number>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="btUseUnregRunner">
<property name="text">
<string>Add to leg</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand All @@ -100,6 +191,15 @@
<header location="global">qf/qmlwidgets/tableview.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>edFilter</tabstop>
<tabstop>tblRegistrations</tabstop>
<tabstop>tblCompetitors</tabstop>
<tabstop>edFirstName</tabstop>
<tabstop>edLastName</tabstop>
<tabstop>edSiId</tabstop>
<tabstop>btUseUnregRunner</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

0 comments on commit b5fdec8

Please sign in to comment.