RSCouplingInterface: add importJobRS()
Imports uncoupled RS from another Job stop and couples them to current stop.
This commit is contained in:
parent
02f4938396
commit
a4393aec43
|
@ -7,6 +7,9 @@
|
|||
#include <QDebug>
|
||||
|
||||
#include "stopmodel.h"
|
||||
#include "utils/rs_utils.h"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
RSCouplingInterface::RSCouplingInterface(database &db, QObject *parent) :
|
||||
QObject(parent),
|
||||
|
@ -394,6 +397,64 @@ bool RSCouplingInterface::uncoupleRS(db_id rsId, const QString& rsName, bool on)
|
|||
return true;
|
||||
}
|
||||
|
||||
int RSCouplingInterface::importRSFromJob(db_id otherStopId)
|
||||
{
|
||||
query q_getUncoupled(mDb, "SELECT coupling.rs_id, rs_list.number,"
|
||||
" rs_models.name, rs_models.suffix, rs_models.type"
|
||||
" FROM coupling"
|
||||
" JOIN rs_list ON rs_list.id=coupling.rs_id"
|
||||
" JOIN rs_models ON rs_models.id=rs_list.model_id"
|
||||
" WHERE coupling.stop_id=? AND coupling.operation=0");
|
||||
q_getUncoupled.bind(1, otherStopId);
|
||||
|
||||
int count = 0;
|
||||
bool lineElectrified = stopsModel->isRailwayElectrifiedAfterStop(m_stopId);
|
||||
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
|
||||
for(auto rs : q_getUncoupled)
|
||||
{
|
||||
db_id rsId = rs.get<db_id>(0);
|
||||
|
||||
int number = rs.get<int>(1);
|
||||
int modelNameLen = sqlite3_column_bytes(q_getUncoupled.stmt(), 2);
|
||||
const char *modelName = reinterpret_cast<char const*>(sqlite3_column_text(q_getUncoupled.stmt(), 2));
|
||||
|
||||
int modelSuffixLen = sqlite3_column_bytes(q_getUncoupled.stmt(), 3);
|
||||
const char *modelSuffix = reinterpret_cast<char const*>(sqlite3_column_text(q_getUncoupled.stmt(), 3));
|
||||
RsType rsType = RsType(rs.get<int>(4));
|
||||
|
||||
QString rsName = rs_utils::formatNameRef(modelName,
|
||||
modelNameLen,
|
||||
number,
|
||||
modelSuffix,
|
||||
modelSuffixLen,
|
||||
rsType);
|
||||
|
||||
//TODO: optimize work
|
||||
if(coupleRS(rsId, rsName, true, !lineElectrified))
|
||||
count++;
|
||||
|
||||
if(timer.elapsed() > 10000)
|
||||
{
|
||||
//After 10 seconds, give opportunity to stop
|
||||
int ret = QMessageBox::question(
|
||||
qApp->activeWindow(),
|
||||
tr("Continue Importation?"),
|
||||
tr("Rollingstock importation is taking more time than expected.\n"
|
||||
"Do you want to continue?"));
|
||||
|
||||
if(ret == QMessageBox::No)
|
||||
return count; //Abort here
|
||||
|
||||
timer.restart(); //Count again
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool RSCouplingInterface::hasEngineAfterStop(bool *isElectricOnNonElectrifiedLine)
|
||||
{
|
||||
query q_hasEngine(mDb, "SELECT coupling.rs_id,MAX(rs_models.sub_type),MAX(stops.arrival)"
|
||||
|
|
|
@ -25,6 +25,8 @@ public:
|
|||
bool coupleRS(db_id rsId, const QString &rsName, bool on, bool checkTractionType);
|
||||
bool uncoupleRS(db_id rsId, const QString &rsName, bool on);
|
||||
|
||||
int importRSFromJob(db_id otherStopId);
|
||||
|
||||
bool hasEngineAfterStop(bool *isElectricOnNonElectrifiedLine = nullptr);
|
||||
|
||||
bool isRailwayElectrified() const;
|
||||
|
|
Loading…
Reference in New Issue