tianzhendong
2 years ago
commit
d4bb513d23
21 changed files with 2091 additions and 0 deletions
@ -0,0 +1,12 @@ |
|||
Build/ |
|||
*.user |
|||
# *.dll |
|||
*.a |
|||
|
|||
Makefile |
|||
lib*.so* |
|||
|
|||
|
|||
.idea/ |
|||
*build*/ |
|||
miniblink-20230412/ |
@ -0,0 +1,71 @@ |
|||
cmake_minimum_required(VERSION 3.5) |
|||
|
|||
PROJECT(Map LANGUAGES CXX) |
|||
|
|||
set(CMAKE_CXX_STANDARD 17) |
|||
|
|||
if(WIN32) |
|||
MESSAGE(STATUS "WIN32") |
|||
set(CMAKE_PREFIX_PATH "C:/DevelopEnv/Qt/5.15.2/mingw81_64") |
|||
set(QT_VERSION "5.15.2") |
|||
elseif(UNIX) |
|||
MESSAGE(STATUS "UNIX") |
|||
set(CMAKE_PREFIX_PATH "/home/tian/Qt5.12.3/5.12.3/gcc_64") |
|||
# solve program: undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' |
|||
set(QT_VERSION "5.12.3") |
|||
set(CMAKE_CXX_FLAGS -pthread) |
|||
endif() |
|||
|
|||
set(CMAKE_INCLUDE_CURRENT_DIR ON) |
|||
|
|||
set(CMAKE_AUTOUIC ON) |
|||
set(CMAKE_AUTOMOC ON) |
|||
set(CMAKE_AUTORCC ON) |
|||
|
|||
# 添加用到的qt库 |
|||
find_package(Qt5 COMPONENTS |
|||
Core |
|||
Gui |
|||
Widgets |
|||
Websockets |
|||
LinguistTools |
|||
REQUIRED) |
|||
|
|||
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) #设置可执行文件生成目录 |
|||
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/Libs) #设置链接库生成目录 |
|||
|
|||
include_directories(${PROJECT_SOURCE_DIR}/src) |
|||
|
|||
FILE(GLOB_RECURSE APP_HEADER ${PROJECT_SOURCE_DIR}/Src/*.h) |
|||
FILE(GLOB_RECURSE APP_SRC ${PROJECT_SOURCE_DIR}/Src/*.cpp) |
|||
FILE(GLOB_RECURSE FORMS ${PROJECT_SOURCE_DIR}/Src/*.ui) |
|||
FILE(GLOB_RECURSE RESOURCE_FILES ${PROJECT_SOURCE_DIR}/resources/*.qrc ${PROJECT_SOURCE_DIR}/resources/*.rc) |
|||
|
|||
# 翻译 |
|||
# 初始化要使用的列表 |
|||
set(TS_FILES) |
|||
set(QM_FILES) |
|||
set(PROJECT_SOURCES ${APP_SRC} ${COMMONMODULE_SRC} ${DATA_SRC} ${DECODEROUTE_SRC} ${FILEOPERATOR_SRC} ${OVERLOAD_SRC} ${PLOT_SRC} ${PYTHONPLOT_SRC} ${MATLABPLOT_SRC} ${UI_SRC} |
|||
${FORMS}) |
|||
# 将要生成的翻译文件添加到列表中 |
|||
list(APPEND TS_FILES ${CMAKE_CURRENT_SOURCE_DIR}/FlightDataAnalysis_zh.ts) |
|||
# 设置翻译文件的生成路径,如果不指定就会生成在CMakeFiles的目录里 |
|||
set_source_files_properties(${TS_FILES} |
|||
PROPERTIES OUTPUT_LOCATION ${CMAKE_CURRENT_SOURCE_DIR} |
|||
) |
|||
qt5_create_translation(QM_FILES ${TS_FILES} ${PROJECT_SOURCES}) |
|||
# 添加更新翻译的目标 |
|||
add_custom_target(lupdate_task DEPENDS ${TS_FILES}) |
|||
# 添加发布翻译的目标 |
|||
add_custom_target(lrelease_task DEPENDS ${QM_FILES}) |
|||
|
|||
SET(CMAKE_BUILD_TYPE "Release") |
|||
add_executable(${PROJECT_NAME} ${APP_SRC} ${APP_HEADER} |
|||
${FORMS} ${RESOURCE_FILES} ${TS_FILES}) |
|||
|
|||
target_link_libraries(${PROJECT_NAME} |
|||
Qt5::Core |
|||
Qt5::Gui |
|||
Qt5::Widgets |
|||
Qt5::WebSockets |
|||
) |
@ -0,0 +1,32 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!DOCTYPE TS> |
|||
<TS version="2.1" language="zh_CN"> |
|||
<context> |
|||
<name>MapWidget</name> |
|||
<message> |
|||
<location filename="src/mapwidget.ui" line="14"/> |
|||
<source>Form</source> |
|||
<translation type="unfinished"></translation> |
|||
</message> |
|||
<message> |
|||
<location filename="src/mapwidget.ui" line="41"/> |
|||
<source>GroupBox</source> |
|||
<translation type="unfinished"></translation> |
|||
</message> |
|||
<message> |
|||
<location filename="src/mapwidget.ui" line="47"/> |
|||
<source>serverListen</source> |
|||
<translation type="unfinished"></translation> |
|||
</message> |
|||
<message> |
|||
<location filename="src/mapwidget.ui" line="54"/> |
|||
<source>CallWMTS</source> |
|||
<translation type="unfinished"></translation> |
|||
</message> |
|||
<message> |
|||
<location filename="src/mapwidget.ui" line="61"/> |
|||
<source>PushButton</source> |
|||
<translation type="unfinished"></translation> |
|||
</message> |
|||
</context> |
|||
</TS> |
@ -0,0 +1,32 @@ |
|||
QT += core gui websockets |
|||
|
|||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets |
|||
|
|||
CONFIG += c++17 |
|||
|
|||
# You can make your code fail to compile if it uses deprecated APIs. |
|||
# In order to do so, uncomment the following line. |
|||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 |
|||
|
|||
INCLUDEPATH += $$PWD |
|||
SOURCES += \ |
|||
$$PWD/src/main.cpp \ |
|||
$$PWD/src/mapwidget.cpp \ |
|||
$$PWD/src/webwidget.cpp |
|||
|
|||
HEADERS += \ |
|||
$$PWD/src/mapwidget.h \ |
|||
$$PWD/src/webwidget.h |
|||
|
|||
FORMS += \ |
|||
$$PWD/src/mapwidget.ui |
|||
|
|||
# Default rules for deployment. |
|||
qnx: target.path = /tmp/$${TARGET}/bin |
|||
else: unix:!android: target.path = /opt/$${TARGET}/bin |
|||
!isEmpty(target.path): INSTALLS += target |
|||
|
|||
RC_ICONS += $$PWD/resources/map.ico |
|||
|
|||
RESOURCES += \ |
|||
resources/icons.qrc |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -0,0 +1 @@ |
|||
IDI_ICON1 ICON DISCARDABLE "map.ico" |
@ -0,0 +1,7 @@ |
|||
<RCC> |
|||
<qresource prefix="/"> |
|||
<file>map.svg</file> |
|||
<file>map-black.svg</file> |
|||
<file>map-blue.svg</file> |
|||
</qresource> |
|||
</RCC> |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 9.6 KiB |
After Width: | Height: | Size: 1.4 KiB |
@ -0,0 +1,31 @@ |
|||
#include "wke.h" |
|||
#include "mapwidget.h" |
|||
|
|||
#include <QApplication> |
|||
#include <QFile> |
|||
|
|||
int main(int argc, char *argv[]) |
|||
{ |
|||
QApplication a(argc, argv); |
|||
wkeSetWkeDllPath(L"node.dll"); |
|||
wkeInitialize(); |
|||
/* webView在头文件里面声明了是一个wkeWebView类型
|
|||
wkeCreateWebWindow是创建一个带真实窗口的wkeWebView |
|||
第一个参数wkeWindowType type: |
|||
WKE_WINDOW_TYPE_POPUP: 普通窗口 |
|||
WKE_WINDOW_TYPE_TRANSPARENT:透明窗口。mb内部通过layer window实现 |
|||
WKE_WINDOW_TYPE_CONTROL: 嵌入在父窗口里的子窗口。此时parent需要被设置 |
|||
第二个参数是依附parent窗口的句柄, 在QT里面可以调用窗口的winID()方法获取 |
|||
*/ |
|||
MapWidget w; |
|||
|
|||
w.show(); |
|||
// WebWidget *w = new WebWidget("www.baidu.com");
|
|||
|
|||
|
|||
int ret = a.exec(); |
|||
wkeFinalize(); |
|||
return ret; |
|||
|
|||
|
|||
} |
@ -0,0 +1,103 @@ |
|||
#include "mapwidget.h" |
|||
#include "ui_mapwidget.h" |
|||
|
|||
#include <QWebSocket> |
|||
|
|||
MapWidget::MapWidget(QWidget *parent) : |
|||
QWidget(parent), |
|||
ui(new Ui::MapWidget) |
|||
{ |
|||
ui->setupUi(this); |
|||
|
|||
this->showMaximized(); |
|||
m_pWebWidget = new WebWidget("D:/4_Code/Leaflet/demo.html", this); |
|||
ui->verticalLayout->addWidget(m_pWebWidget); |
|||
} |
|||
|
|||
MapWidget::~MapWidget() |
|||
{ |
|||
delete ui; |
|||
} |
|||
|
|||
void MapWidget::on_btn_callWmts_clicked() |
|||
{ |
|||
m_pWebWidget->callJsFunction("printInformation", "tian"); |
|||
return; |
|||
m_pWebWidget->startWmts(); |
|||
} |
|||
|
|||
|
|||
void MapWidget::on_btn_server_clicked() |
|||
{ |
|||
if(!m_pWebSocketServer) |
|||
{ |
|||
//构造:QWebSocketServer(const QString& serverName,QWebSocketServer::SslMode secureMode,QObject *parent=nullptr)
|
|||
//使用给定的serverName构造一个新的QWebSocketServer。
|
|||
//该服务器名称将在HTTP握手阶段被用来识别服务器。它可以为空,此时不会将服务器名称发送给客户端。
|
|||
//SslMode指示服务器是通过wss(SecureMode)还是ws(NonSecureMode)运行
|
|||
//QWebSocketServer::SecureMode服务器以安全模式运行(通过wss)
|
|||
m_pWebSocketServer = new QWebSocketServer("Server", QWebSocketServer::NonSecureMode, this); |
|||
} |
|||
// QHostAddress address = QHostAddress("127.0.0.1");
|
|||
int port = 12345; |
|||
QString s; |
|||
if(!m_pWebSocketServer->listen(QHostAddress::Any, port)) |
|||
{ |
|||
s = "websocket listen error"; |
|||
} |
|||
else |
|||
{ |
|||
s = QString("websocket listen on port %1").arg(port); |
|||
connect(m_pWebSocketServer, &QWebSocketServer::newConnection, this, &MapWidget::onNewConnection); |
|||
connect(m_pWebSocketServer, &QWebSocketServer::closed, this, &MapWidget::onWebSocketClosed); |
|||
} |
|||
qDebug() << s; |
|||
m_pWebWidget->callJsFunction("printInformation", s); |
|||
} |
|||
|
|||
void MapWidget::onNewConnection() |
|||
{ |
|||
QWebSocket *socket = m_pWebSocketServer->nextPendingConnection(); |
|||
if(!socket) |
|||
return; |
|||
clientList.push_back(socket); |
|||
qDebug() << QString("[New Connect] Address:%1 Port:%2") |
|||
.arg(socket->peerAddress().toString()) |
|||
.arg(socket->peerPort()); |
|||
|
|||
//收到消息
|
|||
connect(socket, &QWebSocket::textMessageReceived, this, [&](const QString & msg) |
|||
{ |
|||
qDebug() << msg; |
|||
m_pWebWidget->callJsFunction(msg); |
|||
}); |
|||
//发送消息
|
|||
connect(this, &MapWidget::doSendMessage, socket, &QWebSocket::sendTextMessage); |
|||
//断开连接,释放
|
|||
connect(socket, &QWebSocket::disconnected, this, [&, socket]() |
|||
{ |
|||
clientList.removeAll(socket); |
|||
socket->deleteLater(); |
|||
}); |
|||
|
|||
} |
|||
|
|||
void MapWidget::onWebSocketClosed() |
|||
{ |
|||
|
|||
} |
|||
|
|||
|
|||
void MapWidget::on_pushButton_clicked() |
|||
{ |
|||
static int cnt = 0; |
|||
emit doSendMessage(QString("send message %1").arg(cnt++)); |
|||
} |
|||
|
|||
|
|||
void MapWidget::on_btn_clear_clicked() |
|||
{ |
|||
static int cnt1 = 3; |
|||
m_pWebWidget->callJsFunction("clearOneLine", QString::number(cnt1--)); |
|||
} |
|||
|
@ -0,0 +1,46 @@ |
|||
#ifndef MAPWIDGET_H |
|||
#define MAPWIDGET_H |
|||
|
|||
#include <QWebSocketServer> |
|||
#include <QWidget> |
|||
#include "webwidget.h" |
|||
|
|||
namespace Ui |
|||
{ |
|||
class MapWidget; |
|||
} |
|||
|
|||
class MapWidget : public QWidget |
|||
{ |
|||
Q_OBJECT |
|||
|
|||
public: |
|||
explicit MapWidget(QWidget *parent = nullptr); |
|||
~MapWidget(); |
|||
|
|||
signals: |
|||
void doSendMessage(const QString & s); |
|||
|
|||
private slots: |
|||
void on_btn_callWmts_clicked(); |
|||
|
|||
void on_btn_server_clicked(); |
|||
|
|||
void onNewConnection(); |
|||
|
|||
void onWebSocketClosed(); |
|||
|
|||
void on_pushButton_clicked(); |
|||
|
|||
void on_btn_clear_clicked(); |
|||
|
|||
private: |
|||
Ui::MapWidget *ui; |
|||
|
|||
WebWidget * m_pWebWidget = nullptr; |
|||
|
|||
QWebSocketServer *m_pWebSocketServer = nullptr; |
|||
QList<QWebSocket*> clientList; |
|||
}; |
|||
|
|||
#endif // MAPWIDGET_H
|
@ -0,0 +1,79 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<ui version="4.0"> |
|||
<class>MapWidget</class> |
|||
<widget class="QWidget" name="MapWidget"> |
|||
<property name="geometry"> |
|||
<rect> |
|||
<x>0</x> |
|||
<y>0</y> |
|||
<width>1386</width> |
|||
<height>1030</height> |
|||
</rect> |
|||
</property> |
|||
<property name="windowTitle"> |
|||
<string>Form</string> |
|||
</property> |
|||
<layout class="QGridLayout" name="gridLayout_3"> |
|||
<item row="0" column="0"> |
|||
<widget class="QWidget" name="widget" native="true"> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>0</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<layout class="QGridLayout" name="gridLayout"> |
|||
<item row="0" column="0"> |
|||
<layout class="QVBoxLayout" name="verticalLayout"/> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
</item> |
|||
<item row="0" column="1"> |
|||
<widget class="QGroupBox" name="groupBox"> |
|||
<property name="sizePolicy"> |
|||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred"> |
|||
<horstretch>0</horstretch> |
|||
<verstretch>0</verstretch> |
|||
</sizepolicy> |
|||
</property> |
|||
<property name="title"> |
|||
<string>GroupBox</string> |
|||
</property> |
|||
<layout class="QGridLayout" name="gridLayout_2"> |
|||
<item row="2" column="0"> |
|||
<widget class="QPushButton" name="pushButton"> |
|||
<property name="text"> |
|||
<string>PushButton</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="1" column="0"> |
|||
<widget class="QPushButton" name="btn_server"> |
|||
<property name="text"> |
|||
<string>serverListen</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="0" column="0"> |
|||
<widget class="QPushButton" name="btn_callWmts"> |
|||
<property name="text"> |
|||
<string>CallWMTS</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
<item row="3" column="0"> |
|||
<widget class="QPushButton" name="btn_clear"> |
|||
<property name="text"> |
|||
<string>清除所有曲线</string> |
|||
</property> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
</item> |
|||
</layout> |
|||
</widget> |
|||
<resources/> |
|||
<connections/> |
|||
</ui> |
@ -0,0 +1,77 @@ |
|||
#include "webwidget.h" |
|||
#include "qapplication.h" |
|||
#include <QHBoxLayout> |
|||
#include <QDebug> |
|||
WebWidget::WebWidget(const QString& url, QWidget *_parent) : QWidget(_parent) |
|||
{ |
|||
webView = wkeCreateWebWindow(WKE_WINDOW_TYPE_CONTROL, (HWND)_parent->winId(), 0, 0, this->width(), this->height()); |
|||
wkeShowWindow(webView, TRUE); |
|||
QString _sUrl = url; |
|||
if(_sUrl.isEmpty()) |
|||
_sUrl = "www.baidu.com"; |
|||
wkeLoadURL(webView, _sUrl.toUtf8()); |
|||
// connect()
|
|||
} |
|||
|
|||
WebWidget::~WebWidget() |
|||
{ |
|||
qDebug() << "in del"; |
|||
} |
|||
void WebWidget::loadUrl(const QString& url) |
|||
{ |
|||
QString _sUrl = url; |
|||
if(_sUrl.isEmpty()) |
|||
_sUrl = "www.baidu.com"; |
|||
wkeLoadURL(webView, _sUrl.toLocal8Bit().data()); |
|||
} |
|||
void WebWidget::resizeEvent(QResizeEvent *event) |
|||
{ |
|||
Q_UNUSED(event); |
|||
wkeResize(webView, this->width(), this->height()); |
|||
QPoint pos = this->mapToGlobal(QPoint(0, 0)); |
|||
wkeMoveWindow(webView, 0, 0, this->width() + pos.x(), this->height() + pos.y() / 2); |
|||
} |
|||
|
|||
void WebWidget::statusFeedbackSlot() |
|||
{ |
|||
|
|||
} |
|||
|
|||
void WebWidget::callJsFunction(const QString &sFunctionName, const QString &sPara) |
|||
{ |
|||
QString s = sFunctionName + "(\"" + sPara + "\");"; |
|||
wkeRunJS(webView, s.toUtf8()); |
|||
} |
|||
|
|||
void WebWidget::onMove() |
|||
{ |
|||
QPoint pos = this->mapToGlobal(QPoint(0, 0)); |
|||
wkeMoveWindow(webView, pos.x(), pos.y(), this->width(), this->height()); |
|||
} |
|||
|
|||
void WebWidget::slotProcessQuit(int, QProcess::ExitStatus ) |
|||
{ |
|||
if(m_pWmtsProcess) |
|||
{ |
|||
disconnect(m_pWmtsProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotProcessQuit(int, QProcess::ExitStatus))); |
|||
// 负责进程间通信
|
|||
disconnect(m_pWmtsProcess, &QProcess::readyReadStandardError, this, &WebWidget::statusFeedbackSlot); |
|||
disconnect(m_pWmtsProcess, &QProcess::readyReadStandardOutput, this, &WebWidget::statusFeedbackSlot); |
|||
m_pWmtsProcess->deleteLater(); |
|||
m_pWmtsProcess = nullptr; |
|||
} |
|||
} |
|||
|
|||
void WebWidget::startWmts() |
|||
{ |
|||
if(m_pWmtsProcess != nullptr) |
|||
return; |
|||
m_pWmtsProcess = new QProcess; |
|||
QString path = QCoreApplication::applicationDirPath(); |
|||
m_pWmtsProcess->setProgram(path + "/wmts.exe"); |
|||
m_pWmtsProcess->start(QProcess::ReadWrite); |
|||
connect(m_pWmtsProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotProcessQuit(int, QProcess::ExitStatus))); |
|||
// 负责进程间通信
|
|||
connect(m_pWmtsProcess, &QProcess::readyReadStandardError, this, &WebWidget::statusFeedbackSlot); |
|||
connect(m_pWmtsProcess, &QProcess::readyReadStandardOutput, this, &WebWidget::statusFeedbackSlot); |
|||
} |
@ -0,0 +1,49 @@ |
|||
#ifndef WEBWIDGET_H |
|||
#define WEBWIDGET_H |
|||
|
|||
#include <QWidget> |
|||
#include <QResizeEvent> |
|||
#include <QFileInfo> |
|||
#include "wke.h" |
|||
#include <QProcess> |
|||
|
|||
class WebWidget : public QWidget |
|||
{ |
|||
Q_OBJECT |
|||
public: |
|||
explicit WebWidget(const QString& url = "", QWidget *parent = 0); |
|||
~WebWidget(); |
|||
|
|||
/**
|
|||
* @brief loadUrl 打开网页 |
|||
* @param url 网页url |
|||
*/ |
|||
void loadUrl(const QString &url); |
|||
|
|||
void onMove(); |
|||
|
|||
void startWmts(); |
|||
|
|||
/**
|
|||
* @brief callJsFunction 调用js中的函数 |
|||
* @param sFunctionName 函数名称 |
|||
* @param sPara 函数参数,如数值a和b,传入形式为QString("%1,%2").arg(a).arg(b) |
|||
*/ |
|||
void callJsFunction(const QString &sFunctionName, const QString &sPara = ""); |
|||
signals: |
|||
|
|||
protected: |
|||
void resizeEvent(QResizeEvent *event); |
|||
|
|||
public slots: |
|||
void statusFeedbackSlot(); |
|||
|
|||
void slotProcessQuit(int exitCode, QProcess::ExitStatus stuts); |
|||
|
|||
private: |
|||
wkeWebView webView; |
|||
|
|||
QProcess *m_pWmtsProcess = nullptr; |
|||
}; |
|||
|
|||
#endif // WEBWIDGET_H
|
File diff suppressed because it is too large
Binary file not shown.
Loading…
Reference in new issue