widget.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <QDeclarativeView>
  2. #include <QDeclarativeEngine>
  3. #include <QDeclarativeContext>
  4. #include <QtDebug>
  5. #include "widget.h"
  6. #include "ui_widget.h"
  7. Widget::Widget(QWidget *parent) :
  8. QWidget(parent),
  9. ui(new Ui::Widget)
  10. {
  11. m_mapProvider = "init.html";
  12. ui->setupUi(this);
  13. m_view = new QDeclarativeView(this);
  14. m_view->rootContext()->setContextProperty("cppEngine", this);
  15. m_view->setSource(QUrl("qrc:/qmls/main.qml"));
  16. ui->verticalLayout->addWidget(m_view);
  17. m_view->setResizeMode(QDeclarativeView::SizeRootObjectToView);
  18. ui->comboBox->addItem("Select Map Provider", QVariant("init.html"));
  19. ui->comboBox->addItem("OVI Maps", QVariant("ovimaps.html"));
  20. ui->comboBox->addItem("Google Maps", QVariant("gmaps.html"));
  21. ui->comboBox->addItem("Bing Maps", QVariant("bingmaps.html"));
  22. m_geoSource = QGeoPositionInfoSource::createDefaultSource(this);
  23. if (m_geoSource)
  24. {
  25. connect(m_geoSource, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdated(QGeoPositionInfo)));
  26. m_geoSource->setUpdateInterval(10000);
  27. m_geoSource->startUpdates();
  28. }
  29. connect(ui->comboBox, SIGNAL(currentIndexChanged(int)),
  30. this, SLOT(mapProviderSelected(int)));
  31. }
  32. Widget::~Widget()
  33. {
  34. delete ui;
  35. }
  36. QString Widget::mapProvider()
  37. {
  38. return m_mapProvider;
  39. }
  40. void Widget::mapProviderSelected(int index)
  41. {
  42. QString htmlFileName = ui->comboBox->itemData( index ).toString();
  43. setMapProvider( htmlFileName );
  44. }
  45. void Widget::setMapProvider(QString newMapProvider)
  46. {
  47. if (m_mapProvider == newMapProvider)
  48. return;
  49. else
  50. {
  51. m_mapProvider = newMapProvider;
  52. emit mapProviderChanged(m_mapProvider);
  53. }
  54. }
  55. void Widget::positionUpdated(QGeoPositionInfo info)
  56. {
  57. emit posUpdated( info.coordinate().latitude(), info.coordinate().longitude());
  58. }