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
1 parent 2ce2f02 commit 425ec75
Show file tree
Hide file tree
Showing 35 changed files with 667 additions and 316 deletions.
81 changes: 0 additions & 81 deletions data.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions data.h

This file was deleted.

55 changes: 54 additions & 1 deletion examples/DataTransfer/MainWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MainWindow.h"
#include "MainWindow.h"
#include "ui_MainWindow.h"
#define REMOTE_PORT 16650

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
Expand All @@ -12,3 +13,55 @@ MainWindow::~MainWindow()
{
delete ui;
}

bool MainWindow::init()
{
displayer = new Displayer3D(0);
bool inited = displayer->init();
if(inited) {
// displayer->getView()->settings()->setAttribute( QWebEngineSettings::Accelerated2dCanvasEnabled, false);
displayer->show();
QObject::connect(displayer, &Displayer3D::closed, this, &QObject::deleteLater);

m_socket.connectToHost("localhost", REMOTE_PORT);
m_socket.write("PC:");
QTimer::singleShot(30000, [=] {
m_socket.write("31");
});
connect(displayer->getView(), &QWebEngineView::loadFinished, [=] {
connect(&m_socket, &QTcpSocket::readyRead, this, &MainWindow::read);
});
m_feeder = displayer->getDataFeeder();
}
return inited;
}

void MainWindow::read()
{
QByteArray tmpData = m_socket.readAll(); // format is: { "heading": 0, "pitch": 0 ...}
QByteArrayList tmpDatas = tmpData.split('\n');
foreach (QByteArray td, tmpDatas) {
QJsonDocument doc = QJsonDocument::fromJson(td);
QJsonObject obj = doc.object();
// qDebug() << doc;
// qDebug() << tmpData.data();
ui->textEdit->append(QString(tmpData));
double heading = obj.value("heading").toDouble();
double pitch = obj.value("pitch").toDouble();
double roll = obj.value("roll").toDouble();
ui->textEdit->append(QString("H: %1, P:%2").arg(heading).arg(pitch));
m_feeder->setHprData(heading,
pitch,
roll);
}
}

WebDataFeeder *MainWindow::feeder() const
{
return m_feeder;
}

void MainWindow::setFeeder(WebDataFeeder *feeder)
{
m_feeder = feeder;
}
20 changes: 18 additions & 2 deletions examples/DataTransfer/MainWindow.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#ifndef MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <Displayer3d.h>
#include <WebDataFeeder.h>
#include <QTcpSocket>
#include <QJsonDocument>
#include <QJsonObject>
#include <QWebEngineSettings>
namespace Ui {
class MainWindow;
}
Expand All @@ -14,7 +19,18 @@ class MainWindow : public QMainWindow
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public:
bool init();
WebDataFeeder *feeder() const;
void setFeeder(WebDataFeeder *feeder);

public Q_SLOTS:
void read();
public:
Displayer3D *displayer;
private:
WebDataFeeder *m_feeder;
QTcpSocket m_socket;
private:
Ui::MainWindow *ui;
};
Expand Down
40 changes: 31 additions & 9 deletions examples/DataTransfer/MainWindow.ui
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow" >
<property name="geometry" >
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QMenuBar" name="menuBar" />
<widget class="QToolBar" name="mainToolBar" />
<widget class="QWidget" name="centralWidget" />
<widget class="QStatusBar" name="statusBar" />
<widget class="QWidget" name="centralWidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>23</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutDefault spacing="6" margin="11" />
<pixmapfunction></pixmapfunction>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
63 changes: 4 additions & 59 deletions examples/DataTransfer/main.cpp
Original file line number Diff line number Diff line change
@@ -1,76 +1,21 @@
#include "MainWindow.h"
#include <QApplication>
#include <Displayer3d.h>
#include <WebDataFeeder.h>
#include <QTcpSocket>
#include <QJsonDocument>
#include <QJsonObject>
#include <QWebEngineSettings>

#include <QDebug>

#define REMOTE_PORT 8811

/** 通过串口传递数据
*/

class DataRecver:public QObject {

public:
bool init() {
displayer = new Displayer3D(0);
bool inited = displayer->init();
if(inited) {
// displayer->getView()->settings()->setAttribute( QWebEngineSettings::Accelerated2dCanvasEnabled, false);
displayer->show();
QObject::connect(displayer, &Displayer3D::closed, this, &QObject::deleteLater);

m_socket.connectToHost("localhost", REMOTE_PORT);
connect(displayer->getView(), &QWebEngineView::loadFinished, [=] {
connect(&m_socket, &QTcpSocket::readyRead, this, &DataRecver::read);
});
m_feeder = displayer->getDataFeeder();
}
return inited;
}
WebDataFeeder *feeder() const;
void setFeeder(WebDataFeeder *feeder);

public Q_SLOTS:
void read() {
QByteArray tmpData = m_socket.readAll(); // format is: { "heading": 0, "pitch": 0 ...}
QJsonDocument doc = QJsonDocument::fromJson(tmpData);
QJsonObject obj = doc.object();
// qDebug() << doc;
m_feeder->setHprData(obj.value("heading").toDouble(),
obj.value("pitch").toDouble(),
obj.value("roll").toDouble());
}
public:
Displayer3D *displayer;
private:
WebDataFeeder *m_feeder;
QTcpSocket m_socket;
};


WebDataFeeder *DataRecver::feeder() const
{
return m_feeder;
}

void DataRecver::setFeeder(WebDataFeeder *feeder)
{
m_feeder = feeder;
}

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
DataRecver *dr = new DataRecver();
MainWindow *mw = new MainWindow();

if(dr->init()) {
QObject::connect(dr->displayer, &Displayer3D::closed, &a, &QApplication::quit);
if(mw->init()) {
mw->show();
QObject::connect(mw->displayer, &Displayer3D::closed, &a, &QApplication::quit);
int result = a.exec();
return result;
}
Expand Down
Loading

0 comments on commit 425ec75

Please sign in to comment.