Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- ui->txtLatitude->setText("45.5075693");
- ui->txtLongtitude->setText("13.5824982");
- ui->lblStatus->setText("Ready!");
- QQmlEngine engine;
- QQmlComponent component(&engine,QUrl(QStringLiteral("qrc:/Map.qml")));
- ui->quickWidget->setSource(QStringLiteral("qrc:/Map.qml"));
- object = component.create();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::on_btnSimulate_clicked()
- {
- QTimer *timer;
- if(ui->btnSimulate->text() == "Simulate")
- {
- ui->btnSimulate->setText("End simulation");
- ui->txtLatitude->setEnabled(false);
- ui->txtLongtitude->setEnabled(false);
- timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(UpdateCoordinates()));
- timer->start(1000);
- }
- else {
- ui->btnSimulate->setText("Simulate");
- ui->txtLatitude->setEnabled(false);
- ui->txtLongtitude->setEnabled(false);
- }
- }
- void MainWindow::UpdateCoordinates()
- {
- float LATDEGM = (60 * 1853.181);
- float DEG2RAD = (PI / 180.0);
- QString speedData = ui->sboxSpeed->text();
- bool ok;
- AirSpeed = speedData.toInt(&ok);
- AirCourse = (AirCourse + 360) % 360;
- Dx = AirSpeed * sin((float)AirCourse * DEG2RAD);
- Dy = AirSpeed * cos((float)AirCourse * DEG2RAD);
- QString dat = ui->txtLatitude->text();
- Lat = dat.toDouble();
- QString dat2 = ui->txtLongtitude->text();
- Lon = dat2.toDouble();
- Dx /= 3.6;
- Dy /= 3.6;
- Lat += Dy / LATDEGM;
- Lon += Dx / (LATDEGM * cos(Lat * DEG2RAD));
- ui->txtLatitude->setText(QString::number(Lat));
- ui->txtLongtitude->setText(QString::number(Lon));
- QObject* map = object->children().first();
- QVariant returnedValue;
- QVariant msg = "Hello from C++";
- QMetaObject::invokeMethod(map, "qmlFunction",
- Q_RETURN_ARG(QVariant, returnedValue),
- Q_ARG(QVariant, msg));
- qDebug() << "QML function returned:" << returnedValue.toString();
- }
- import QtQuick 2.0
- import QtQuick.Window 2.0
- import QtLocation 5.6
- import QtPositioning 5.6
- Item{
- id: itemControl
- objectName: "itemControl"
- width: 512
- height: 512
- visible: true
- property int maxZoom: 15
- property int minZoom: 15
- property real newLat: 45.5075693
- property real newLon: 13.5824982
- Plugin {
- id: mapPlugin
- name: "esri"
- }
- Map {
- id:map
- objectName: "map"
- anchors.fill: parent
- maximumZoomLevel: itemControl.maxZoom
- minimumZoomLevel: itemControl.minZoom
- width: 512
- height: 512
- plugin: mapPlugin
- center {
- latitude: itemControl.newLat
- longitude: itemControl.newLon
- }
- zoomLevel: 15
- function startupFunction(){
- console.log("Finish method");
- }
- function qmlFunction(msg) {
- console.log("Got message:", msg);
- return "some return value";
- }
- Component.onCompleted: {
- startupFunction();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement