diff --git a/main.cpp b/main.cpp index 156a456..7798cc1 100644 --- a/main.cpp +++ b/main.cpp @@ -24,7 +24,16 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); + MainWidget w; + + if (QApplication::arguments().count() > 1) { + w.loadGpx(QApplication::arguments().at(1)); + } + + QObject::connect(&w, SIGNAL(close()), &a, SLOT(quit())); w.show(); + return a.exec(); } + diff --git a/mainwidget.cpp b/mainwidget.cpp index d3cc7e0..44394e1 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -42,11 +42,6 @@ MainWidget::MainWidget(QWidget *parent) m_dlWidget(new DownloadWidget(this)), m_routingWidget(new RoutingWidget(this)) { - QString fileName; - if (QApplication::arguments().count() > 1) { - fileName = QApplication::arguments().at(1); - } - QHBoxLayout *layout = new QHBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); layout->addWidget(m_stack); @@ -59,12 +54,6 @@ MainWidget::MainWidget(QWidget *parent) l->setVisible(false); m_map->addLayer(l, 4); - if (fileName.endsWith(".gpx")) { - l = new GpxLayer(m_map); - l->load(fileName); - m_map->addLayer(l, 2); - } - l = new MarkerLayer(m_map); connect(l, SIGNAL(markerAdded(QString)), m_markerList, SLOT(addMarker(QString))); connect(m_markerList, SIGNAL(centerOnMarker(int)), l, SLOT(centerOnMarker(int))); @@ -76,6 +65,7 @@ MainWidget::MainWidget(QWidget *parent) l = new GpsLayer(m_map); m_map->addLayer(l, 1); + connect(m_map, SIGNAL(close()), this, SIGNAL(close())); connect(m_map, SIGNAL(showMarkerList()), this, SLOT(showList())); connect(m_map, SIGNAL(downloadArea(int, QRectF)), this, SLOT(downloadArea(int, QRectF))); connect(m_map, SIGNAL(route(QPointF, QPointF)), this, SLOT(findRoute(QPointF, QPointF))); @@ -98,6 +88,15 @@ MainWidget::~MainWidget() { } +void MainWidget::loadGpx(const QString &fileName) +{ + if (fileName.endsWith(".gpx")) { + AbstractLayer *l = new GpxLayer(m_map); + l->load(fileName); + m_map->addLayer(l, 2); + } +} + void MainWidget::showList() { m_stack->setCurrentIndex(1); diff --git a/mainwidget.h b/mainwidget.h index 76e3fc5..dc95d02 100644 --- a/mainwidget.h +++ b/mainwidget.h @@ -36,6 +36,11 @@ public: MainWidget(QWidget *parent = 0); ~MainWidget(); + void loadGpx(const QString &fileName); + +signals: + void close(); + private slots: void showList(); void markerAdded(const QString &name);