Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
  2. {
  3. ui->setupUi(this);
  4. ui->txtLatitude->setText("45.5075693");
  5. ui->txtLongtitude->setText("13.5824982");
  6. ui->lblStatus->setText("Ready!");
  7.  
  8. QQmlEngine engine;
  9. QQmlComponent component(&engine,QUrl(QStringLiteral("qrc:/Map.qml")));
  10. ui->quickWidget->setSource(QStringLiteral("qrc:/Map.qml"));
  11. object = component.create();
  12. }
  13.  
  14. MainWindow::~MainWindow()
  15. {
  16. delete ui;
  17. }
  18.  
  19. void MainWindow::on_btnSimulate_clicked()
  20. {
  21. QTimer *timer;
  22. if(ui->btnSimulate->text() == "Simulate")
  23. {
  24. ui->btnSimulate->setText("End simulation");
  25. ui->txtLatitude->setEnabled(false);
  26. ui->txtLongtitude->setEnabled(false);
  27.  
  28. timer = new QTimer(this);
  29. connect(timer, SIGNAL(timeout()), this, SLOT(UpdateCoordinates()));
  30. timer->start(1000);
  31. }
  32. else {
  33. ui->btnSimulate->setText("Simulate");
  34. ui->txtLatitude->setEnabled(false);
  35. ui->txtLongtitude->setEnabled(false);
  36. }
  37. }
  38.  
  39. void MainWindow::UpdateCoordinates()
  40. {
  41. float LATDEGM = (60 * 1853.181);
  42. float DEG2RAD = (PI / 180.0);
  43.  
  44. QString speedData = ui->sboxSpeed->text();
  45. bool ok;
  46. AirSpeed = speedData.toInt(&ok);
  47.  
  48. AirCourse = (AirCourse + 360) % 360;
  49.  
  50. Dx = AirSpeed * sin((float)AirCourse * DEG2RAD);
  51. Dy = AirSpeed * cos((float)AirCourse * DEG2RAD);
  52.  
  53. QString dat = ui->txtLatitude->text();
  54. Lat = dat.toDouble();
  55. QString dat2 = ui->txtLongtitude->text();
  56. Lon = dat2.toDouble();
  57.  
  58. Dx /= 3.6;
  59. Dy /= 3.6;
  60.  
  61. Lat += Dy / LATDEGM;
  62. Lon += Dx / (LATDEGM * cos(Lat * DEG2RAD));
  63.  
  64. ui->txtLatitude->setText(QString::number(Lat));
  65. ui->txtLongtitude->setText(QString::number(Lon));
  66.  
  67. QObject* map = object->children().first();
  68.  
  69. QVariant returnedValue;
  70. QVariant msg = "Hello from C++";
  71. QMetaObject::invokeMethod(map, "qmlFunction",
  72. Q_RETURN_ARG(QVariant, returnedValue),
  73. Q_ARG(QVariant, msg));
  74.  
  75. qDebug() << "QML function returned:" << returnedValue.toString();
  76. }
  77.  
  78. import QtQuick 2.0
  79. import QtQuick.Window 2.0
  80. import QtLocation 5.6
  81. import QtPositioning 5.6
  82.  
  83. Item{
  84. id: itemControl
  85. objectName: "itemControl"
  86. width: 512
  87. height: 512
  88. visible: true
  89.  
  90. property int maxZoom: 15
  91. property int minZoom: 15
  92.  
  93. property real newLat: 45.5075693
  94. property real newLon: 13.5824982
  95.  
  96. Plugin {
  97. id: mapPlugin
  98. name: "esri"
  99. }
  100.  
  101. Map {
  102. id:map
  103. objectName: "map"
  104. anchors.fill: parent
  105. maximumZoomLevel: itemControl.maxZoom
  106. minimumZoomLevel: itemControl.minZoom
  107. width: 512
  108. height: 512
  109. plugin: mapPlugin
  110. center {
  111. latitude: itemControl.newLat
  112. longitude: itemControl.newLon
  113. }
  114. zoomLevel: 15
  115.  
  116. function startupFunction(){
  117. console.log("Finish method");
  118. }
  119.  
  120. function qmlFunction(msg) {
  121. console.log("Got message:", msg);
  122. return "some return value";
  123. }
  124.  
  125. Component.onCompleted: {
  126. startupFunction();
  127. }
  128.  
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement