Skip to content
This repository was archived by the owner on Jun 2, 2025. It is now read-only.

Commit 1bc7958

Browse files
committed
Add relative start time settings option
1 parent 0b5796e commit 1bc7958

9 files changed

+45
-7
lines changed

src/application.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ void Application::updateRun(int run_id, const QVariant &record)
108108

109109
void Application::setCardInserted(unsigned int siid)
110110
{
111-
if (siid == m_cardRead)
112-
return;
111+
//if (siid == m_cardRead)
112+
// return;
113113
m_cardRead = siid;
114114
if (siid > 0) {
115115
playAlert(Application::Alert::CardInserted);

src/startlistitemdelegate.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ void StartListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
2626
int letter_width = line_height / 2;
2727
int corridor_status_width = letter_width;
2828

29-
auto start_time = index.data(StartListModel::Role::StartDateTime).toDateTime();
29+
auto start_time_msec = index.data(StartListModel::Role::StartTime).toInt();
30+
auto start_date_time = index.data(StartListModel::Role::StartDateTime).toDateTime();
3031
auto corridor_time = index.data(StartListModel::Role::CorridorTime).toDateTime();
3132

3233
constexpr auto CORRIDOR1_COLOR = Qt::red;
@@ -136,7 +137,17 @@ void StartListItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem
136137
painter->setPen(pen);
137138
auto rect = option.rect;
138139
rect.translate(time_offset, 0);
139-
painter->drawText(rect, start_time.toString("hh:mm:ss"));
140+
if (m_relativeStartTime) {
141+
int min = start_time_msec / 1000 / 60;
142+
int sec = start_time_msec / 1000 % 60;
143+
painter->drawText(rect, QStringLiteral("%1:%2")
144+
.arg(min, 3, 10, QChar('0'))
145+
.arg(sec, 2, 10, QChar('0'))
146+
);
147+
}
148+
else {
149+
painter->drawText(rect, start_date_time.toString("hh:mm:ss"));
150+
}
140151
}
141152
{
142153
auto rect = option.rect;

src/startlistitemdelegate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ class StartListItemDelegate : public QStyledItemDelegate
1616
StartListItemDelegate(QObject *parent = nullptr);
1717
~StartListItemDelegate() override = default;
1818
public:
19+
void setRelativeStartTime(bool on) { m_relativeStartTime = on; }
1920
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
21+
private:
22+
bool m_relativeStartTime = false;
2023
};
2124

2225
#endif // STARTLISTITEMDELEGATE_H

src/startlistmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ void StartListModel::updateLocalRecord(int run_id, const QMap<StartListModel::Ro
184184
auto corridor_time = val.toDateTime();
185185
if (!checkCorridorTime(row, corridor_time)) {
186186
emit corridorTimeCheckError();
187-
continue;
187+
//continue;
188188
}
189189
}
190190
chngmap[colname.value()] = v2;

src/startlistwidget.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ StartListWidget::StartListWidget(QWidget *parent) :
4040
connect(m_model, &StartListModel::corridorTimeCheckError, []() {
4141
Application::instance()->playAlert(Application::Alert::CorridorTimeCheckError);
4242
});
43-
connect(app, &Application::settingsChanged, this, &StartListWidget::reload);
43+
connect(app, &Application::settingsChanged, this, [this]() {
44+
reload();
45+
});
4446
connect(ui->tableView, &StartListTableView::editButtonPressed, this, [this](int run_id) {
4547
auto *widget = new RunWidget(m_model);
4648
widget->load(run_id);
@@ -106,9 +108,9 @@ void StartListWidget::onCardInserted(unsigned int siid)
106108
auto siid2 = m_model->roleValue(row, StartListModel::Role::SiId).toUInt();
107109
if (siid == siid2) {
108110
auto run_id = m_model->roleValue(row, StartListModel::Role::RunId).toInt();
109-
//shvDebug() << "row:" << run_id << "dt:" << corridor_time.toString();
110111
QMap<StartListModel::Role, QVariant> record;
111112
record.insert(StartListModel::CorridorTime, QDateTime::currentDateTime());
113+
//shvDebug() << "row:" << run_id << "record:" << shv::coreqt::rpc::qVariantToPrettyString();
112114
m_model->updateLocalRecord(run_id, record);
113115
setSelectedRow(row);
114116
return;
@@ -124,8 +126,17 @@ void StartListWidget::resizeEvent(QResizeEvent *event)
124126
updateHeadersSectionSizes();
125127
}
126128

129+
void StartListWidget::applySettings()
130+
{
131+
auto ui_settings = UiSettingsPage::loadSettings();
132+
auto *delegate = findChild<StartListItemDelegate*>();
133+
Q_ASSERT(delegate);
134+
delegate->setRelativeStartTime(ui_settings.relativeStartTime);
135+
}
136+
127137
void StartListWidget::reload()
128138
{
139+
applySettings();
129140
auto class_filter = ClassFilterSettingsPage::checkedClasses();
130141
QVariantMap param;
131142
param["orderBy"] = "runs.startTimeMs";

src/startlistwidget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class StartListWidget : public QWidget
2727
protected:
2828
void resizeEvent(QResizeEvent *event) override;
2929
private:
30+
void applySettings();
3031
void reload();
3132
void updateHeadersSectionSizes();
3233
private:

src/uisettingspage.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace {
1414
constexpr auto TOGGLE_CORRIDOR_TIME = "ui/toggleCorridorTime";
15+
constexpr auto RELATIVE_START_TIME = "ui/relativeStartTime";
1516

1617
constexpr auto SOUND_CARD_INSERTED = "ui/sound/cardInserted";
1718
constexpr auto SOUND_CARD_NOT_FOUND = "ui/sound/cardNotFound";
@@ -71,6 +72,7 @@ UiSettings UiSettingsPage::loadSettings()
7172
//shvInfo() << "soundCorridorTimeError" << settings.value(SOUND_CORRIDOR_TIME_ERROR, SOUND_CORRIDOR_TIME_ERROR_FILE).toString();
7273
return UiSettings {
7374
.toggleCorridorTime = settings.value(TOGGLE_CORRIDOR_TIME).toBool(),
75+
.relativeStartTime = settings.value(RELATIVE_START_TIME).toBool(),
7476
.soundCardInserted = settings.value(SOUND_CARD_INSERTED, SOUND_CARD_INSERTED_FILE).toString(),
7577
.soundCardNotFound = settings.value(SOUND_CARD_NOT_FOUND, SOUND_CARD_NOT_FOUND_FILE).toString(),
7678
.soundCorridorTimeError = settings.value(SOUND_CORRIDOR_TIME_ERROR, SOUND_CORRIDOR_TIME_ERROR_FILE).toString(),
@@ -81,6 +83,7 @@ void UiSettingsPage::load()
8183
{
8284
auto ui_settings = loadSettings();
8385
ui->toggleCorridorTime->setChecked(ui_settings.toggleCorridorTime);
86+
ui->relativeStartTime->setChecked(ui_settings.relativeStartTime);
8487

8588
auto set_sound_file = [](QComboBox *lst, const QString &file_name) {
8689
if (auto ix = lst->findData(file_name); ix >= 0) {
@@ -99,6 +102,7 @@ void UiSettingsPage::save()
99102
{
100103
QSettings settings;
101104
settings.setValue(TOGGLE_CORRIDOR_TIME, ui->toggleCorridorTime->isChecked());
105+
settings.setValue(RELATIVE_START_TIME, ui->relativeStartTime->isChecked());
102106

103107
settings.setValue(SOUND_CARD_INSERTED, ui->lstSoundCardInserted->currentData().toString());
104108
settings.setValue(SOUND_CARD_NOT_FOUND, ui->lstSoundCardNotFound->currentData().toString());

src/uisettingspage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
struct UiSettings
77
{
88
bool toggleCorridorTime = false;
9+
bool relativeStartTime = false;
910
QString soundCardInserted;
1011
QString soundCardNotFound;
1112
QString soundCorridorTimeError;

src/uisettingspage.ui

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
</property>
2222
</widget>
2323
</item>
24+
<item>
25+
<widget class="QCheckBox" name="relativeStartTime">
26+
<property name="text">
27+
<string>Relative start time</string>
28+
</property>
29+
</widget>
30+
</item>
2431
<item>
2532
<widget class="QGroupBox" name="groupBox">
2633
<property name="title">

0 commit comments

Comments
 (0)