Map Matching
qmapwidget.cpp
Go to the documentation of this file.
1 #include "qmapwidget.h"
2 
3 #define WIDGET_WIDTH 1000
4 QMapWidget::QMapWidget(QWidget* parent)
5  : QWidget(parent)
6 {
7  m_layout = new QVBoxLayout;
8  m_scene = new QMapScene(this);
9  m_view = new QGraphicsView(m_scene);
10  m_view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
11  m_layout->addWidget(m_view);
12  buildControls();
13  m_layout->addWidget(m_controlZone);
14  setLayout(m_layout);
15  setWindowTitle(tr("Map viewer"));
16 
17  connect(m_play, SIGNAL(clicked()), m_scene, SLOT(onSignalStart()));
18  connect(m_zoom, SIGNAL(valueChanged(int)), this, SLOT(sceneScaleChanged(int)));
19  connect(m_scene, SIGNAL(signalItemToShow(QGraphicsItem*)), this, SLOT(onSignalItemToShow(QGraphicsItem*)));
20 }
21 
23 {
24  m_controlZone = new QWidget(this);
25  QHBoxLayout* layout = new QHBoxLayout();
26  m_play = new QPushButton("Play all", m_controlZone);
27  m_next = new QPushButton("One step", m_controlZone);
28  m_zoom = new QSlider(Qt::Horizontal, m_controlZone);
29  m_zoom->setTickInterval(10);
30  m_zoom->setMinimum(0);
31  m_zoom->setMaximum(100);
32  m_zoom->setValue(1);
33  layout->addWidget(m_play);
34  layout->addWidget(m_next);
35  layout->addWidget(m_zoom);
36  m_controlZone->setLayout(layout);
37  m_controlZone->adjustSize();
38 }
39 void QMapWidget::onSignalDimension(double xMinGrid, double xMaxGrid, double yMinGrid, double yMaxGrid)
40 {
41  m_scene->initialize(int(xMinGrid), int(yMinGrid), int(xMaxGrid), int(yMaxGrid));
42  double ratio = (yMaxGrid - yMinGrid) / (xMaxGrid - xMinGrid);
43  resize(WIDGET_WIDTH, (int)(WIDGET_WIDTH * ratio));
44  m_view->fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio);
45  m_view->scale(1, -1);
46  show();
47 }
48 
49 void QMapWidget::onSignalItemToShow(QGraphicsItem* item)
50 {
51  m_view->centerOn(item);
52 }
53 
54 void QMapWidget::sceneScaleChanged(int scaleTickValue)
55 {
56  double newScale = scaleTickValue / 100.0;
57  m_view->resetMatrix();
58  m_view->scale(newScale, -newScale);
59 }
#define WIDGET_WIDTH
Definition: qmapwidget.cpp:3
QPushButton * m_next
Definition: qmapwidget.h:21
void buildControls()
Definition: qmapwidget.cpp:22
void onSignalDimension(double xMinGrid, double xMaxGrid, double yMinGrid, double yMaxGrid)
Definition: qmapwidget.cpp:39
QSlider * m_zoom
Definition: qmapwidget.h:37
void onSignalItemToShow(QGraphicsItem *item)
Definition: qmapwidget.cpp:49
QGraphicsView * m_view
Definition: qmapwidget.h:32
QMapScene * m_scene
Definition: qmapwidget.h:20
QWidget * m_controlZone
Definition: qmapwidget.h:34
QPushButton * m_play
Definition: qmapwidget.h:35
QVBoxLayout * m_layout
Definition: qmapwidget.h:33
QMapWidget(QWidget *parent=0)
Definition: qmapwidget.cpp:4
void initialize(int startx, int starty, int width, int height)
Definition: qmapscene.cpp:17
void sceneScaleChanged(int scaleTickValue)
Definition: qmapwidget.cpp:54