diff --git a/quickevent/app/plugins/Event/src/eventplugin.cpp b/quickevent/app/plugins/Event/src/eventplugin.cpp index b93f76ce0..94800b7fa 100644 --- a/quickevent/app/plugins/Event/src/eventplugin.cpp +++ b/quickevent/app/plugins/Event/src/eventplugin.cpp @@ -648,7 +648,8 @@ void EventPlugin::connectToSqlServer() //qfInfo() << conn_w->serverPassword(); db.setPassword(conn_w->serverPassword()); db.setDatabaseName("quickevent"); - qfInfo().nospace() << "connecting to: " << db.userName() << "@" << db.hostName() << ":" << db.port(); + qfInfo().nospace() << "connecting to database: " << db.databaseName() + << " as " << db.userName() << "@" << db.hostName() << ":" << db.port(); connect_ok = db.open(); if(connect_ok) { bool ok = connect(db.driver(), SIGNAL(notification(QString, QSqlDriver::NotificationSource,QVariant)), this, SLOT(onDbEvent(QString,QSqlDriver::NotificationSource, QVariant))); diff --git a/quickevent/app/plugins/Runs/src/runstableitemdelegate.cpp b/quickevent/app/plugins/Runs/src/runstableitemdelegate.cpp index a1ca9296f..2a6d0fc3b 100644 --- a/quickevent/app/plugins/Runs/src/runstableitemdelegate.cpp +++ b/quickevent/app/plugins/Runs/src/runstableitemdelegate.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -18,6 +19,12 @@ namespace qfs = qf::core::sql; +static Event::EventPlugin* eventPlugin() +{ + qf::qmlwidgets::framework::MainWindow *fwk = qf::qmlwidgets::framework::MainWindow::frameWork(); + return fwk->plugin(); +} + RunsTableItemDelegate::RunsTableItemDelegate(qf::qmlwidgets::TableView * parent) : Super(parent) { @@ -25,6 +32,7 @@ RunsTableItemDelegate::RunsTableItemDelegate(qf::qmlwidgets::TableView * parent) void RunsTableItemDelegate::setHighlightedClassId(int class_id, int stage_id) { + //qfWarning() << stage_id << class_id; m_stageId = stage_id; m_highlightedClassId = class_id; reloadHighlightedClassId(); @@ -35,9 +43,12 @@ void RunsTableItemDelegate::reloadHighlightedClassId() qf::core::sql::QueryBuilder qb; qb.select2("classdefs", "startTimeMin, lastStartTimeMin, startIntervalMin, vacantsBefore, vacantEvery, vacantsAfter") .from("classdefs") - .where("stageId=" QF_IARG(m_stageId)) .where("classId=" QF_IARG(m_highlightedClassId)); + bool is_relays = eventPlugin()->eventConfig()->isRelays(); + if(!is_relays) + qb.where("leg=" QF_IARG(m_stageId)); qfs::Query q(qfs::Connection::forName()); + //qfInfo() << qb.toString(); q.exec(qb.toString(), qf::core::Exception::Throw); if(q.next()) { m_classInterval = q.value("startIntervalMin").toInt() * 60 * 1000; @@ -63,67 +74,87 @@ void RunsTableItemDelegate::paintBackground(QPainter *painter, const QStyleOptio auto *tm = qobject_cast(v->tableModel()); if(!(m && tm)) return; - if(m_highlightedClassId > 0 && m_classInterval > 0 && isStartTimeHighlightVisible()) { - //qfInfo() << "col:" << index.column() << m_highlightedClassId << "interval:" << m_classInterval << isStartTimeHighlightVisible(); - QVariant stime_v = m->data(index.sibling(index.row(), RunsTableModel::Columns::col_runs_startTimeMs), Qt::EditRole); - quickevent::core::og::TimeMs stime = stime_v.value(); - if(!stime.isValid()) - return; - int start_ms = stime.msec(); - int prev_start_ms = m_classStartFirst; - int next_start_ms = m_classStartLast; - //int table_row = v->toTableModelRowNo(index.row()); - QString club = m->data(index.sibling(index.row(), RunsTableModel::Columns::col_registration), Qt::EditRole).toString().mid(0, 3).trimmed(); - QString prev_club; - if(index.row() > 0) { - prev_start_ms = m->data(index.sibling(index.row() - 1, RunsTableModel::Columns::col_runs_startTimeMs), Qt::EditRole).value().msec(); - prev_club = m->data(index.sibling(index.row() - 1, RunsTableModel::Columns::col_registration), Qt::EditRole).toString().mid(0, 3).trimmed(); - } - if(index.row() < tm->rowCount() - 1) { - next_start_ms = m->data(index.sibling(index.row() + 1, RunsTableModel::Columns::col_runs_startTimeMs), Qt::EditRole).value().msec(); + bool is_relays = eventPlugin()->eventConfig()->isRelays(); + if(m_highlightedClassId > 0) { + if(is_relays) { + // check that start time in classes is the same + if(index.column() == RunsTableModel::Columns::col_runs_startTimeMs) { + QVariant stime_v = m->data(index.sibling(index.row(), RunsTableModel::Columns::col_runs_startTimeMs), Qt::EditRole); + quickevent::core::og::TimeMs stime = stime_v.value(); + int start_ms = stime.msec(); + if(!stime.isValid()) + return; + int leg = m->data(index.sibling(index.row(), RunsTableModel::Columns::col_runs_leg), Qt::EditRole).toInt(); + if(leg == 1 && m_classStartFirst != start_ms) { + //qfInfo() << m_highlightedClassId << m_classStartFirst << start_ms; + QColor c = Qt::red; + c.setAlphaF(0.5); + painter->fillRect(option.rect, c); + } + } } + else if(isStartTimeHighlightVisible() && m_classInterval > 0) { + //qfInfo() << "col:" << index.column() << m_highlightedClassId << "interval:" << m_classInterval << isStartTimeHighlightVisible(); + QVariant stime_v = m->data(index.sibling(index.row(), RunsTableModel::Columns::col_runs_startTimeMs), Qt::EditRole); + quickevent::core::og::TimeMs stime = stime_v.value(); + int start_ms = stime.msec(); + if(!stime.isValid()) + return; + int prev_start_ms = m_classStartFirst; + int next_start_ms = m_classStartLast; + //int table_row = v->toTableModelRowNo(index.row()); + QString club = m->data(index.sibling(index.row(), RunsTableModel::Columns::col_registration), Qt::EditRole).toString().mid(0, 3).trimmed(); + QString prev_club; + if(index.row() > 0) { + prev_start_ms = m->data(index.sibling(index.row() - 1, RunsTableModel::Columns::col_runs_startTimeMs), Qt::EditRole).value().msec(); + prev_club = m->data(index.sibling(index.row() - 1, RunsTableModel::Columns::col_registration), Qt::EditRole).toString().mid(0, 3).trimmed(); + } + if(index.row() < tm->rowCount() - 1) { + next_start_ms = m->data(index.sibling(index.row() + 1, RunsTableModel::Columns::col_runs_startTimeMs), Qt::EditRole).value().msec(); + } - bool bad_start_time = (start_ms > m_classStartFirst && start_ms == prev_start_ms) || ((start_ms - prev_start_ms) % m_classInterval) != 0; - bool vacant_before = !bad_start_time && (((start_ms - prev_start_ms) > m_classInterval) || ((index.row() == 0) && (start_ms > m_classStartFirst))); - bool vacant_after = !bad_start_time - && (((next_start_ms - start_ms) > m_classInterval) - || ((index.row() == tm->rowCount() - 1) && (start_ms < m_classStartLast))); - bool bad_club = !vacant_before && (club == prev_club); - //auto cd = tm->columnDefinition(index.column()); - if(index.column() == RunsTableModel::Columns::col_runs_startTimeMs) { - //qfWarning() << ix.row() << club << prev_club; - //qfInfo() << prev_start_ms << start_ms << (start_ms - prev_start_ms) << m_classInterval; - if(bad_start_time) { - QColor c = Qt::red; - c.setAlphaF(0.5); - painter->fillRect(option.rect, c); + bool bad_start_time = (start_ms > m_classStartFirst && start_ms == prev_start_ms) || ((start_ms - prev_start_ms) % m_classInterval) != 0; + bool vacant_before = !bad_start_time && (((start_ms - prev_start_ms) > m_classInterval) || ((index.row() == 0) && (start_ms > m_classStartFirst))); + bool vacant_after = !bad_start_time + && (((next_start_ms - start_ms) > m_classInterval) + || ((index.row() == tm->rowCount() - 1) && (start_ms < m_classStartLast))); + bool bad_club = !vacant_before && (club == prev_club); + //auto cd = tm->columnDefinition(index.column()); + if(index.column() == RunsTableModel::Columns::col_runs_startTimeMs) { + //qfWarning() << ix.row() << club << prev_club; + //qfInfo() << prev_start_ms << start_ms << (start_ms - prev_start_ms) << m_classInterval; + if(bad_start_time) { + QColor c = Qt::red; + c.setAlphaF(0.5); + painter->fillRect(option.rect, c); + } + /* + else if(vacant_before) { + QColor c = QColor("lime"); + painter->fillRect(option.rect, c); + } + */ + else if(bad_club) { + //qfInfo() << (start_ms - prev_start_ms) << m_classInterval; + QColor c = QColor(Qt::magenta); + painter->fillRect(option.rect, c); + } } - /* - else if(vacant_before) { - QColor c = QColor("lime"); - painter->fillRect(option.rect, c); + static const QColor vacant_color("forestgreen"); + static constexpr int vacant_h_ratio = 20; + if(vacant_before) { + QRect r = option.rect; + int h = r.height() / vacant_h_ratio + 1; + r.setHeight(h); + painter->fillRect(r, vacant_color); } - */ - else if(bad_club) { - //qfInfo() << (start_ms - prev_start_ms) << m_classInterval; - QColor c = QColor(Qt::magenta); - painter->fillRect(option.rect, c); + if(vacant_after) { + QRect r = option.rect; + int h = r.height() / vacant_h_ratio + 1; + r.setY(r.bottom() - h); + //r.setHeight(h); + painter->fillRect(r, vacant_color); } } - static const QColor vacant_color("forestgreen"); - static constexpr int vacant_h_ratio = 20; - if(vacant_before) { - QRect r = option.rect; - int h = r.height() / vacant_h_ratio + 1; - r.setHeight(h); - painter->fillRect(r, vacant_color); - } - if(vacant_after) { - QRect r = option.rect; - int h = r.height() / vacant_h_ratio + 1; - r.setY(r.bottom() - h); - //r.setHeight(h); - painter->fillRect(r, vacant_color); - } } } diff --git a/quickevent/app/plugins/Runs/src/runstablewidget.cpp b/quickevent/app/plugins/Runs/src/runstablewidget.cpp index 9ed2522ce..0851bbd75 100644 --- a/quickevent/app/plugins/Runs/src/runstablewidget.cpp +++ b/quickevent/app/plugins/Runs/src/runstablewidget.cpp @@ -32,26 +32,19 @@ namespace qfm = qf::core::model; static Event::EventPlugin* eventPlugin() { qf::qmlwidgets::framework::MainWindow *fwk = qf::qmlwidgets::framework::MainWindow::frameWork(); - auto *plugin = qobject_cast(fwk->plugin("Event")); - QF_ASSERT_EX(plugin != nullptr, "Bad event plugin!"); - return plugin; + return fwk->plugin(); } static Runs::RunsPlugin *runsPlugin() { qf::qmlwidgets::framework::MainWindow *fwk = qf::qmlwidgets::framework::MainWindow::frameWork(); - auto *plugin = qobject_cast(fwk->plugin("Runs")); - QF_ASSERT(plugin != nullptr, "Runs plugin not installed!", return nullptr); - return plugin; + return fwk->plugin(); } static Competitors::CompetitorsPlugin *competitorsPlugin() { qf::qmlwidgets::framework::MainWindow *fwk = qf::qmlwidgets::framework::MainWindow::frameWork(); - auto *plugin = qobject_cast(fwk->plugin("Competitors")); - if(plugin == nullptr) - QF_EXCEPTION("Competitors plugin not installed!"); - return plugin; + return fwk->plugin(); } RunsTableWidget::RunsTableWidget(QWidget *parent) : @@ -125,7 +118,7 @@ void RunsTableWidget::clear() void RunsTableWidget::reload(int stage_id, int class_id, bool show_offrace, const QString &sort_column, int select_competitor_id) { - qfLogFuncFrame(); + qfLogFuncFrame() << "class id:" << class_id; bool is_relays = eventPlugin()->eventConfig()->isRelays(); { int class_start_time_min = 0; @@ -189,15 +182,27 @@ void RunsTableWidget::reload(int stage_id, int class_id, bool show_offrace, cons m_runsModel->setQueryBuilder(qb, false); m_runsModel->reload(); - ui->tblRuns->horizontalHeader()->setSectionHidden(RunsTableModel::col_runs_isRunning, !show_offrace); - ui->tblRuns->horizontalHeader()->setSectionHidden(RunsTableModel::col_relays_name, !is_relays); - ui->tblRuns->horizontalHeader()->setSectionHidden(RunsTableModel::col_runs_leg, !is_relays); - ui->tblRuns->horizontalHeader()->reset(); // revealed columns are not sometimes visible without reset(), atleast in 5.5.1 + QHeaderView *hh = ui->tblRuns->horizontalHeader(); + hh->setSectionHidden(RunsTableModel::col_runs_isRunning, !show_offrace); + if(show_offrace) { + // section might be hidden from previous persistent settings + if(hh->sectionSize(RunsTableModel::col_runs_isRunning) < 5) + hh->resizeSection(RunsTableModel::col_runs_isRunning, 50); + } + hh->setSectionHidden(RunsTableModel::col_relays_name, !is_relays); + hh->setSectionHidden(RunsTableModel::col_runs_leg, !is_relays); + if(is_relays) { + if(hh->sectionSize(RunsTableModel::col_relays_name) < 5) + hh->resizeSection(RunsTableModel::col_relays_name, 50); + if(hh->sectionSize(RunsTableModel::col_runs_leg) < 5) + hh->resizeSection(RunsTableModel::col_runs_leg, 50); + } + hh->reset(); // revealed columns are not sometimes visible without reset(), atleast in 5.5.1 if(!sort_column.isEmpty()) { int sort_col_ix = m_runsModel->columnIndex(sort_column); if(sort_col_ix >= 0) { - QHeaderView *hdrv = ui->tblRuns->horizontalHeader(); + QHeaderView *hdrv = hh; hdrv->setSortIndicator(sort_col_ix, Qt::AscendingOrder); if(select_competitor_id > 0) { for (int i = 0; i < m_runsModel->rowCount(); ++i) { diff --git a/quickevent/app/plugins/Runs/src/runswidget.cpp b/quickevent/app/plugins/Runs/src/runswidget.cpp index 4bdd1b40e..69e4d6130 100644 --- a/quickevent/app/plugins/Runs/src/runswidget.cpp +++ b/quickevent/app/plugins/Runs/src/runswidget.cpp @@ -70,7 +70,7 @@ RunsWidget::RunsWidget(QWidget *parent) : return; bool is_relays = eventPlugin()->eventConfig()->isRelays(); if(is_relays) { - ui->cbxDrawMethod->addItem(tr("Relays first leg"), static_cast(DrawMethod::Relays)); + ui->cbxDrawMethod->addItem(tr("Relays first leg"), static_cast(DrawMethod::RelaysFirstLeg)); } else { ui->cbxDrawMethod->addItem(tr("Randomized equidistant clubs"), static_cast(DrawMethod::RandomizedEquidistantClubs)); @@ -99,6 +99,7 @@ void RunsWidget::lazyInit() void RunsWidget::reset(int class_id) { + qfLogFuncFrame(); bool is_relays = eventPlugin()->eventConfig()->isRelays(); if(!eventPlugin()->isEventOpen()) { ui->wRunsTableWidget->clear(); @@ -659,7 +660,7 @@ void RunsWidget::on_btDraw_clicked() else if(draw_method == DrawMethod::KeepOrder) { runners_draw_ids = runsForClass(stage_id, class_id, QString(), "runs.startTimeMs"); } - else if(draw_method == DrawMethod::Relays) { + else if(draw_method == DrawMethod::RelaysFirstLeg) { runners_draw_ids = runsForClass(stage_id, class_id, "runs.leg=1"); } else if(draw_method == DrawMethod::GroupedC) { diff --git a/quickevent/app/plugins/Runs/src/runswidget.h b/quickevent/app/plugins/Runs/src/runswidget.h index fe1d1acc2..b346f7e4d 100644 --- a/quickevent/app/plugins/Runs/src/runswidget.h +++ b/quickevent/app/plugins/Runs/src/runswidget.h @@ -79,7 +79,7 @@ private slots: private: enum class DrawMethod : int {Invalid = 0, RandomNumber, EquidistantClubs, RandomizedEquidistantClubs, StageReverseOrder, Handicap, - KeepOrder, Relays, GroupedC, GroupedCB, GroupedRanking}; + KeepOrder, RelaysFirstLeg, GroupedC, GroupedCB, GroupedRanking}; Ui::RunsWidget *ui; qf::qmlwidgets::ForeignKeyComboBox *m_cbxClasses = nullptr;