Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit Station Graph #7

Merged
merged 53 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
9981b07
Initial commit Station Graph
gfgit Jul 16, 2021
bd497c8
Initial commit Station Graph
gfgit Jul 16, 2021
f53e4b3
Merge branch 'new_station_graph' of ../../git_repo_origin_bare/TrainT…
gfgit Jul 16, 2021
2a452ae
Fix commit mess and add support for segments
gfgit Jul 16, 2021
9dfcaa4
Allow loading lines
gfgit Jul 16, 2021
a5be3f6
Added note for future development
gfgit Jul 16, 2021
b2c0be9
Added station graph view classes
gfgit Jul 17, 2021
537f53d
New line graph widget class
gfgit Jul 17, 2021
47e9156
Move scroll area to separate class
gfgit Jul 17, 2021
c4c130d
CustomCompletionLineEdit: allow setting model
gfgit Jul 17, 2021
1e1ab7f
LineGraphScene: new signal, changed enum values
gfgit Jul 17, 2021
a664790
fixup! CustomCompletionLineEdit: allow setting model
gfgit Jul 17, 2021
0fd080d
LineGraphToolbar: separate class
gfgit Jul 17, 2021
5bbde88
Missing connections on LineGraphToolbar
gfgit Jul 17, 2021
51a8f10
Test new graph widget
gfgit Jul 17, 2021
64cc4d5
Fix LineGraphScene header
gfgit Jul 17, 2021
15a2907
LineGraphToolbar: wrong signal connections
gfgit Jul 17, 2021
271c9a4
LineGraphViewport: fix height
gfgit Jul 17, 2021
3453383
LineGraphToolbar: store previous graph type for comparison
gfgit Jul 17, 2021
bf5b5c7
LineGraphScene: LineGraphType enum start from zero.
gfgit Jul 17, 2021
d135b11
LineGraphScene: forgot to bind id to SQL query
gfgit Jul 17, 2021
31fa2ce
LineGraphToolbar: add new combo item
gfgit Jul 17, 2021
8ba629b
LineGraphViewport: inverted x and y on painting, wrong slots
gfgit Jul 17, 2021
f8c3b5e
LineGraphToolbar: force clearing graph
gfgit Jul 17, 2021
efc92a8
LineGraphScene: added getters
gfgit Jul 17, 2021
9ea6856
LineGraphScrollArea: request sync toolbar on click
gfgit Jul 17, 2021
1bd9085
LineGraphToolbar: sync on scroll area request
gfgit Jul 17, 2021
6d0e50b
StationLabelsHeader: smaller station font
gfgit Jul 17, 2021
d0b7766
LineGraphWidget: connect sync request
gfgit Jul 17, 2021
41e373b
Minor function modification for code clarity
gfgit Jul 17, 2021
c8b1a7c
LineGraphToolbar: new button to reload
gfgit Jul 17, 2021
32f8653
Centralize signals for railway layout changes
gfgit Jul 17, 2021
ae3bb8b
LineGraphManager: new class to manage graphs
gfgit Jul 17, 2021
2dee27b
StationsModel: emit also on short-name changes
gfgit Jul 17, 2021
26c3ea4
LineGraphView: new class to paint scene
gfgit Jul 18, 2021
78a725c
LineGraphToolbar: make toolbar vertically smaller
gfgit Jul 18, 2021
0ddafd2
LineGraphWidget: rename viewport to view
gfgit Jul 18, 2021
3f4e8c2
LineGraphView: fix background updates
gfgit Jul 18, 2021
451bd9c
LineGraphView: preserve box frame
gfgit Jul 18, 2021
76e7887
LineGraphScene: handle size calculation
gfgit Jul 18, 2021
35b86a6
LineGraphView, StationLabelsHeader: center labels
gfgit Jul 18, 2021
979c181
HourPanel: get color from settings
gfgit Jul 18, 2021
95a5aa0
LineGraphManager: react to settings changes
gfgit Jul 18, 2021
77d1410
LineGraphView: attempt to drawBackgroundHourLines
gfgit Jul 18, 2021
cdfb447
LineGraphView: drawBackgroundHourLines
gfgit Jul 18, 2021
c6e0027
TrainTimetableSettings: tweak default platform offset value
gfgit Jul 19, 2021
36c5c3c
LineGraphScene: rework positioning
gfgit Jul 19, 2021
4ff710f
Revert "LineGraphView: attempt to drawBackgroundHourLines"
gfgit Jul 19, 2021
887be82
Merge branch 'new_station_graph' of ../../git_repo_origin_bare/TrainT…
gfgit Jul 19, 2021
3bf45b0
LineGraphView: missing nullptr initialization
gfgit Jul 19, 2021
26568cb
LineGraphScene: reorder function for better code readability
gfgit Jul 19, 2021
fe5fa99
Schema Diagram PDF
gfgit Jul 19, 2021
c400026
Schema Diagram PDF
gfgit Jul 19, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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