StopModel: allow skipping travel time recalculation

- Now EditStopDialog and StopDelegate check for SHIFT pressed on save.
- Added tooltips to StopEditor and EditStopDialog Ok button
This commit is contained in:
Filippo Gentile 2023-02-18 18:46:37 +01:00
parent 0c04121867
commit de54030785
5 changed files with 14 additions and 6 deletions

View File

@ -107,6 +107,9 @@ EditStopDialog::EditStopDialog(StopModel *m, QWidget *parent) :
//So you get a mixed state: Arrival/Departure/Descriptio ecc changes are canceled but Coupling changes are still applied
ui->buttonBox->setStandardButtons(QDialogButtonBox::Ok);
ui->buttonBox->button(QDialogButtonBox::Ok)->setToolTip(tr("Press SHIFT modifier and click to save changes"
" without recalculating travel times."));
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
@ -261,7 +264,8 @@ void EditStopDialog::saveDataToModel()
ui->descriptionEdit->toPlainText());
}
stopModel->setStopInfo(stopIdx, curStop, prevStop.nextSegment);
bool avoidTimeRecalc = QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
stopModel->setStopInfo(stopIdx, curStop, prevStop.nextSegment, avoidTimeRecalc);
}
void EditStopDialog::editCoupled()

View File

@ -837,7 +837,7 @@ void StopModel::setNewShiftId(db_id shiftId)
emit jobShiftChanged(newShiftId);
}
void StopModel::setStopInfo(const QModelIndex &idx, StopItem newStop, StopItem::Segment prevSeg)
void StopModel::setStopInfo(const QModelIndex &idx, StopItem newStop, StopItem::Segment prevSeg, bool avoidTimeRecalc)
{
const int row = idx.row();
int lastUpdatedRow = row;
@ -971,7 +971,7 @@ void StopModel::setStopInfo(const QModelIndex &idx, StopItem newStop, StopItem::
nextStop.arrival = s.departure.addSecs(secs);
if(oldNextArr != nextStop.arrival)
if(timeCalcEnabled && !avoidTimeRecalc)
{
if(!updateStopTime(nextStop, row + 1, true, oldNextArr, oldNextDep))
{

View File

@ -99,7 +99,7 @@ public:
db_id getNewShiftId() const;
// Setters
void setStopInfo(const QModelIndex& idx, StopItem newStop, StopItem::Segment prevSeg);
void setStopInfo(const QModelIndex& idx, StopItem newStop, StopItem::Segment prevSeg, bool avoidTimeRecalc = false);
bool setStopTypeRange(int firstRow, int lastRow, StopType type);

View File

@ -10,7 +10,7 @@
#include "app/scopedebug.h"
#include <QCoreApplication>
#include <QGuiApplication>
#include <QDebug>
@ -258,7 +258,9 @@ void StopDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
StopEditor *ed = static_cast<StopEditor*>(editor);
StopModel *stopModel = static_cast<StopModel *>(model);
stopModel->setStopInfo(index, ed->getCurItem(), ed->getPrevItem().nextSegment);
bool avoidTimeRecalc = QGuiApplication::keyboardModifiers().testFlag(Qt::ShiftModifier);
stopModel->setStopInfo(index, ed->getCurItem(), ed->getPrevItem().nextSegment, avoidTimeRecalc);
}
void StopDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const

View File

@ -43,6 +43,8 @@ StopEditor::StopEditor(sqlite3pp::database &db, StopModel *m, QWidget *parent) :
setTabOrder(mStationEdit, arrEdit);
setTabOrder(arrEdit, depEdit);
setTabOrder(depEdit, mOutGateEdit);
setToolTip(tr("To avoid recalculation of travel times when saving changes, hold SHIFT modifier while closing editor"));
}
StopEditor::~StopEditor()