Skip to content

Commit

Permalink
#450 #354 bag relays first leg start times are painted
Browse files Browse the repository at this point in the history
red in Runs view
  • Loading branch information
fvacek committed Dec 21, 2019
1 parent e7144fd commit 35ee0fb
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 77 deletions.
3 changes: 2 additions & 1 deletion quickevent/app/plugins/Event/src/eventplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
145 changes: 88 additions & 57 deletions quickevent/app/plugins/Runs/src/runstableitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <quickevent/core/og/timems.h>

#include <qf/qmlwidgets/tableview.h>
#include <qf/qmlwidgets/framework/mainwindow.h>

#include <qf/core/model/sqltablemodel.h>
#include <qf/core/sql/connection.h>
Expand All @@ -18,13 +19,20 @@

namespace qfs = qf::core::sql;

static Event::EventPlugin* eventPlugin()
{
qf::qmlwidgets::framework::MainWindow *fwk = qf::qmlwidgets::framework::MainWindow::frameWork();
return fwk->plugin<Event::EventPlugin*>();
}

RunsTableItemDelegate::RunsTableItemDelegate(qf::qmlwidgets::TableView * parent)
: Super(parent)
{
}

void RunsTableItemDelegate::setHighlightedClassId(int class_id, int stage_id)
{
//qfWarning() << stage_id << class_id;
m_stageId = stage_id;
m_highlightedClassId = class_id;
reloadHighlightedClassId();
Expand All @@ -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;
Expand All @@ -63,67 +74,87 @@ void RunsTableItemDelegate::paintBackground(QPainter *painter, const QStyleOptio
auto *tm = qobject_cast<RunsTableModel*>(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<quickevent::core::og::TimeMs>();
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<quickevent::core::og::TimeMs>().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<quickevent::core::og::TimeMs>().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<quickevent::core::og::TimeMs>();
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<quickevent::core::og::TimeMs>();
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<quickevent::core::og::TimeMs>().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<quickevent::core::og::TimeMs>().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);
}
}
}
37 changes: 21 additions & 16 deletions quickevent/app/plugins/Runs/src/runstablewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event::EventPlugin*>(fwk->plugin("Event"));
QF_ASSERT_EX(plugin != nullptr, "Bad event plugin!");
return plugin;
return fwk->plugin<Event::EventPlugin*>();
}

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(plugin != nullptr, "Runs plugin not installed!", return nullptr);
return plugin;
return fwk->plugin<Runs::RunsPlugin *>();
}

static Competitors::CompetitorsPlugin *competitorsPlugin()
{
qf::qmlwidgets::framework::MainWindow *fwk = qf::qmlwidgets::framework::MainWindow::frameWork();
auto *plugin = qobject_cast<Competitors::CompetitorsPlugin *>(fwk->plugin("Competitors"));
if(plugin == nullptr)
QF_EXCEPTION("Competitors plugin not installed!");
return plugin;
return fwk->plugin<Competitors::CompetitorsPlugin *>();
}

RunsTableWidget::RunsTableWidget(QWidget *parent) :
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions quickevent/app/plugins/Runs/src/runswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(DrawMethod::Relays));
ui->cbxDrawMethod->addItem(tr("Relays first leg"), static_cast<int>(DrawMethod::RelaysFirstLeg));
}
else {
ui->cbxDrawMethod->addItem(tr("Randomized equidistant clubs"), static_cast<int>(DrawMethod::RandomizedEquidistantClubs));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion quickevent/app/plugins/Runs/src/runswidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 35ee0fb

Please sign in to comment.