Skip to content

Commit

Permalink
修复 QML 程序,合并冲突
Browse files Browse the repository at this point in the history
  • Loading branch information
BriFuture committed Jun 19, 2019
2 parents 425ec75 + 1e5fb3f commit b7130b8
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 3 deletions.
33 changes: 33 additions & 0 deletions include/QuickViewData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef QUICKVIEWDATA_H
#define QUICKVIEWDATA_H

#include <QObject>
#include <QQuickView>
#include <QQmlContext>

class QuickViewData : public QQuickView{
Q_OBJECT

public:
QuickViewData(QWindow *parent = Q_NULLPTR);
~QuickViewData();
bool event(QEvent *event);
Q_INVOKABLE double getHeading();
Q_INVOKABLE double getPitch();
Q_INVOKABLE double getRoll();
Q_INVOKABLE double getMagicVectorLength();

private:
double heading;
double pitch;
double roll;

signals:
void dataChanged();

public slots:

void changeData();
};

#endif // QUICKVIEWDATA_H
6 changes: 6 additions & 0 deletions libdisplay.pri
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
####################
# Webview version of 3D Program Library
# See more examples under directory `example/`
# Author: BriFuture
# Date: 2019/05/02
####################
CONFIG += c++11
QT += printsupport
QT += websockets webenginewidgets
Expand Down
6 changes: 3 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifdef QUICKVIEW
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include "data.h"
#include "QuickViewData.h"

int old_main(int argc, char *argv[])
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);

// qmlRegisterType<FileContent>("dis.filecontent", 1, 0, "FileContentItem");

Data *data = new Data();
QuickViewData *data = new QuickViewData();
data->show();

return app.exec();
Expand Down
81 changes: 81 additions & 0 deletions src/QuickViewData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include "QuickViewData.h"
#include <QQmlApplicationEngine>
#include <QDebug>
#include <QSettings>
#include <QtGlobal>
#include <QTimer>

QuickViewData::QuickViewData(QWindow *parent) : QQuickView( parent ) {
heading = 0;
pitch = 0;
roll = 0;
qDebug() << "[Info] Start to Show!" ;

this->rootContext()->setContextProperty("dataSource", this);
this->rootContext()->setContextProperty("window", this);
QIcon icon = QIcon(QStringLiteral(":/img/compass.ico"));
this->setIcon(icon);
// 设置窗口缩放时,根对象也会随之缩放
this->setResizeMode(QQuickView::SizeRootObjectToView);
this->setTitle("Compass heading pitch & roll");

// using a cfg file to change mode dynamically
QSettings setting( "compass.ini", QSettings::IniFormat, this );
int mode = setting.value( "mode", 0 ).toInt();

QUrl source;
switch (mode) {
case 1:
source = QUrl( "qrc:/qml/Compass.qml" );
break;
case 0:
default:
source = QUrl( "qrc:/qml/SpacePath.qml" );
break;
}
this->setSource( source );

int interval = setting.value( "interval", 500 ).toInt();
QTimer *timer = new QTimer( this );
connect( timer, &QTimer::timeout, this, &QuickViewData::changeData );
timer->setInterval( interval );
// timer->start( 100 );
}

QuickViewData::~QuickViewData() {
}

bool QuickViewData::event(QEvent *event) {
if( event->type() == QEvent::Close ) {
// on my deepin system, the program always quit with segment fault
// so it is used to tell Qt to delete itself without error
this->deleteLater();
return false;
}
return QQuickView::event( event );
}

double QuickViewData::getHeading() {
return heading;
}

double QuickViewData::getPitch() {
return pitch;
}

double QuickViewData::getMagicVectorLength() {
return 10000*(4);
}

double QuickViewData::getRoll() {
return roll;
}

void QuickViewData::changeData() {
double weight = 0.00003;
pitch += 0.2274 + qrand() * weight;
heading += 0.5252 + qrand() * weight;
roll += 1.3417 + qrand() * weight;
emit dataChanged();
}

0 comments on commit b7130b8

Please sign in to comment.