Skip to content

Commit

Permalink
LineGraphScene: fix tooltip logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gfgit committed Aug 26, 2021
1 parent 3b8d4f1 commit 6918fb0
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions src/graph/model/linegraphscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,35 +261,37 @@ JobEntry LineGraphScene::getJobAt(const QPointF &pos, const double tolerance)
}

auto prevSt = stations.constFind(prevStId);
if(prevSt == stations.constEnd())
return job; //Error

auto nextSt = stations.constFind(nextStId);
if(nextSt == stations.constEnd())

if(prevSt == stations.constEnd() && nextSt == stations.constEnd())
return job; //Error

const StationGraphObject::PlatformGraph *prevPlatf = nullptr;
const StationGraphObject::PlatformGraph *nextPlatf = nullptr;
double prevPos = 0;
double nextPos = 0;

double xPos = prevSt->xPos;
for(const StationGraphObject::PlatformGraph& platf : prevSt->platforms)
double xPos = 0;
if(prevSt != stations.constEnd())
{
if(xPos <= pos.x())
{
prevPlatf = &platf;
prevPos = xPos;
}
if(xPos >= pos.x())
xPos = prevSt->xPos;
for(const StationGraphObject::PlatformGraph& platf : prevSt->platforms)
{
//We went past the requested position
nextPlatf = &platf;
nextPos = xPos;
break;
}
if(xPos <= pos.x())
{
prevPlatf = &platf;
prevPos = xPos;
}
if(xPos >= pos.x())
{
//We went past the requested position
nextPlatf = &platf;
nextPos = xPos;
break;
}

xPos += platformOffset;
xPos += platformOffset;
}
}

const double prevDistance = qAbs(prevPos - pos.x());
Expand All @@ -299,13 +301,13 @@ JobEntry LineGraphScene::getJobAt(const QPointF &pos, const double tolerance)
prevPlatf = nullptr;
}

if(!nextPlatf)
if(!nextPlatf && nextSt != stations.constEnd())
{
//Use second station
xPos = nextSt->xPos;
for(const StationGraphObject::PlatformGraph& platf : nextSt->platforms)
{
if(xPos <= pos.x())
if(xPos >= pos.x())
{
nextPlatf = &platf;
nextPos = xPos;
Expand Down

0 comments on commit 6918fb0

Please sign in to comment.