Skip to content

Commit

Permalink
Merge pull request #7 from gfgit/new_station_graph
Browse files Browse the repository at this point in the history
Initial commit Station Graph
  • Loading branch information
gfgit authored Jul 19, 2021
2 parents 083becc + c400026 commit 9e27911
Show file tree
Hide file tree
Showing 30 changed files with 1,490 additions and 12 deletions.
Binary file added files/diagram/new_station_layout.pdf
Binary file not shown.
Binary file not shown.
16 changes: 9 additions & 7 deletions src/app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
#include "settings/settingsdialog.h"

#include "graph/graphmanager.h"
#include "graph/graphicsview.h"
#include "graph/graphicsview.h" //FIXME: remove
#include <QGraphicsItem>

#include "graph/view/linegraphwidget.h"

#include "db_metadata/meetinginformationdialog.h"

#include "lines/linestorage.h"
Expand Down Expand Up @@ -83,9 +85,9 @@ MainWindow::MainWindow(QWidget *parent) :
auto graphMgr = viewMgr->getGraphMgr();
connect(graphMgr, &GraphManager::jobSelected, this, &MainWindow::onJobSelected);

view = graphMgr->getView();
//view = graphMgr->getView();
view = new LineGraphWidget(this);
view->setObjectName("GraphicsView");
view->setParent(this);

auto linesMatchModel = new LinesMatchModel(Session->m_Db, true, this);
linesMatchModel->setHasEmptyRow(false); //Do not allow empty view (no line selected)
Expand Down Expand Up @@ -847,17 +849,17 @@ void MainWindow::checkLineNumber()
{
auto graphMgr = Session->getViewManager()->getGraphMgr();
//db_id firstLineId = graphMgr->getFirstLineId();

//FIXME: lines are now optional, you can work using only segments
//Segments are now more important than lines, check segments
db_id firstLineId = 0; //FIXME
if(firstLineId && m_mode != CentralWidgetMode::ViewSessionMode)
if(/*firstLineId &&*/ m_mode != CentralWidgetMode::ViewSessionMode)
{
//First line was added or newly opened file -> Session has at least one line
ui->actionAddJob->setEnabled(true);
ui->actionAddJob->setToolTip(tr("Add train job"));
ui->actionRemoveJob->setEnabled(true);
setCentralWidgetMode(CentralWidgetMode::ViewSessionMode);

//Show first line (Alphabetically)
graphMgr->setCurrentLine(firstLineId);
}
else if(firstLineId == 0 && m_mode != CentralWidgetMode::NoLinesWarningMode)
{
Expand Down
5 changes: 3 additions & 2 deletions src/app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class database;

using namespace sqlite3pp;

class QGraphicsView;
class LineGraphWidget;
class QGraphicsView; //FIXME: remove
class QGraphicsScene;
class JobPathEditor;
class QDockWidget;
Expand Down Expand Up @@ -115,7 +116,7 @@ private slots:
QDockWidget *rsErrDock;
#endif

QGraphicsView *view;
LineGraphWidget *view;
QDockWidget *jobDock;

CustomCompletionLineEdit *searchEdit;
Expand Down
2 changes: 2 additions & 0 deletions src/app/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ DB_Error MeetingSession::closeDB()
if(!viewManager->closeEditors())
return DB_Error::EditorsStillOpened; //User wants to continue editing

viewManager->clearAllLineGraphs();

releaseAllSavepoints();

finalizeStatements();
Expand Down
8 changes: 8 additions & 0 deletions src/app/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ class MeetingSession : public QObject
//Jobs
void jobChanged(db_id jobId, db_id oldJobId); //Updated id/category/stops

//Stations
void stationNameChanged(db_id stationId);
void stationPlanChanged(db_id stationId);
void segmentNameChanged(db_id segmentId);
void segmentStationsChanged(db_id segmentId);
void lineNameChanged(db_id lineId);
void lineSegmentsChanged(db_id lineId);

//TODO: old methods, remove them
public:
qreal getStationGraphPos(db_id lineId, db_id stId, int platf = 0);
Expand Down
5 changes: 4 additions & 1 deletion src/graph/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
add_subdirectory(model)
add_subdirectory(view)

set(TRAINTIMETABLE_SOURCES
${TRAINTIMETABLE_SOURCES}
graph/backgroundhelper.h
Expand All @@ -13,4 +16,4 @@ set(TRAINTIMETABLE_SOURCES
graph/stationlayer.h
graph/stationlayer.cpp
PARENT_SCOPE
)
)
11 changes: 11 additions & 0 deletions src/graph/model/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set(TRAINTIMETABLE_SOURCES
${TRAINTIMETABLE_SOURCES}
graph/model/linegraphmanager.h
graph/model/linegraphscene.h
graph/model/stationgraphobject.h

graph/model/linegraphmanager.cpp
graph/model/linegraphscene.cpp
graph/model/stationgraphobject.cpp
PARENT_SCOPE
)
107 changes: 107 additions & 0 deletions src/graph/model/linegraphmanager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include "linegraphmanager.h"

#include "linegraphscene.h"

#include "app/session.h"

LineGraphManager::LineGraphManager(QObject *parent) :
QObject(parent)
{
auto session = Session;
connect(session, &MeetingSession::stationNameChanged, this, &LineGraphManager::onStationNameChanged);
connect(session, &MeetingSession::stationPlanChanged, this, &LineGraphManager::onStationPlanChanged);
connect(session, &MeetingSession::segmentNameChanged, this, &LineGraphManager::onSegmentNameChanged);
connect(session, &MeetingSession::segmentStationsChanged, this, &LineGraphManager::onSegmentStationsChanged);
connect(session, &MeetingSession::lineNameChanged, this, &LineGraphManager::onLineNameChanged);
connect(session, &MeetingSession::lineSegmentsChanged, this, &LineGraphManager::onLineSegmentsChanged);

connect(&AppSettings, &TrainTimetableSettings::jobGraphOptionsChanged, this, &LineGraphManager::updateGraphOptions);
}

void LineGraphManager::registerScene(LineGraphScene *scene)
{
Q_ASSERT(!scenes.contains(scene));

scenes.append(scene);

connect(scene, &LineGraphScene::destroyed, this, &LineGraphManager::onSceneDestroyed);
}

void LineGraphManager::unregisterScene(LineGraphScene *scene)
{
Q_ASSERT(scenes.contains(scene));

scenes.removeOne(scene);

disconnect(scene, &LineGraphScene::destroyed, this, &LineGraphManager::onSceneDestroyed);
}

void LineGraphManager::clearAllGraphs()
{
for(LineGraphScene *scene : qAsConst(scenes))
{
scene->loadGraph(0, LineGraphType::NoGraph);
}
}

void LineGraphManager::onSceneDestroyed(QObject *obj)
{
LineGraphScene *scene = static_cast<LineGraphScene *>(obj);
unregisterScene(scene);
}

void LineGraphManager::onStationNameChanged(db_id stationId)
{
onStationPlanChanged(stationId); //FIXME: update only labels
}

void LineGraphManager::onStationPlanChanged(db_id stationId)
{
//FIXME: speed up with threads???
for(LineGraphScene *scene : qAsConst(scenes))
{
if(scene->stations.contains(stationId))
scene->reload();
}
}

void LineGraphManager::onSegmentNameChanged(db_id segmentId)
{
onSegmentStationsChanged(segmentId); //FIXME: update only labels
}

void LineGraphManager::onSegmentStationsChanged(db_id segmentId)
{
//FIXME: speed up with threads???
for(LineGraphScene *scene : qAsConst(scenes))
{
if(scene->graphType == LineGraphType::RailwaySegment && scene->graphObjectId == segmentId)
scene->reload();
else if(scene->graphType == LineGraphType::RailwayLine)
scene->reload(); //FIXME: only if inside this line
//Single stations are not affected
}
}

void LineGraphManager::onLineNameChanged(db_id lineId)
{
onLineSegmentsChanged(lineId); //FIXME: update only labels
}

void LineGraphManager::onLineSegmentsChanged(db_id lineId)
{
//FIXME: speed up with threads???
for(LineGraphScene *scene : qAsConst(scenes))
{
if(scene->graphType == LineGraphType::RailwayLine && scene->graphObjectId == lineId)
scene->reload();
}
}

void LineGraphManager::updateGraphOptions()
{
for(LineGraphScene *scene : qAsConst(scenes))
{
scene->reload();
}
}
39 changes: 39 additions & 0 deletions src/graph/model/linegraphmanager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef LINEGRAPHMANAGER_H
#define LINEGRAPHMANAGER_H

#include <QObject>

#include <QVector>

#include "utils/types.h"

class LineGraphScene;

class LineGraphManager : public QObject
{
Q_OBJECT
public:
explicit LineGraphManager(QObject *parent = nullptr);

void registerScene(LineGraphScene *scene);
void unregisterScene(LineGraphScene *scene);

void clearAllGraphs();

private slots:
void onSceneDestroyed(QObject *obj);

void onStationNameChanged(db_id stationId);
void onStationPlanChanged(db_id stationId);
void onSegmentNameChanged(db_id segmentId);
void onSegmentStationsChanged(db_id segmentId);
void onLineNameChanged(db_id lineId);
void onLineSegmentsChanged(db_id lineId);

void updateGraphOptions();

private:
QVector<LineGraphScene *> scenes;
};

#endif // LINEGRAPHMANAGER_H
Loading

0 comments on commit 9e27911

Please sign in to comment.