├── LICENSE ├── README.md ├── TrackPlayback.pro ├── help.cpp ├── help.h ├── help.ui ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── mainwindow.ui ├── mapchannel.cpp └── mapchannel.h /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TrackReplay 2 | A track playback software for csv file developed by QT 3 | 4 | Focus here: https://blog.csdn.net/qq_43015524/article/details/122674408?spm=1001.2014.3001.5501 5 | -------------------------------------------------------------------------------- /TrackPlayback.pro: -------------------------------------------------------------------------------- 1 | #------------------------------------------------- 2 | # 3 | # Project created by QtCreator 2019-07-24T15:44:47 4 | # 5 | #------------------------------------------------- 6 | 7 | QT += core gui 8 | QT += webenginewidgets 9 | 10 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 11 | 12 | TARGET = TrackPlayback 13 | TEMPLATE = app 14 | 15 | # The following define makes your compiler emit warnings if you use 16 | # any feature of Qt which has been marked as deprecated (the exact warnings 17 | # depend on your compiler). Please consult the documentation of the 18 | # deprecated API in order to know how to port your code away from it. 19 | DEFINES += QT_DEPRECATED_WARNINGS 20 | 21 | # You can also make your code fail to compile if you use deprecated APIs. 22 | # In order to do so, uncomment the following line. 23 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 24 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 25 | 26 | CONFIG += c++11 27 | 28 | SOURCES += \ 29 | main.cpp \ 30 | mainwindow.cpp \ 31 | mapchannel.cpp \ 32 | help.cpp 33 | 34 | HEADERS += \ 35 | mainwindow.h \ 36 | mapchannel.h \ 37 | help.h 38 | 39 | FORMS += \ 40 | mainwindow.ui \ 41 | help.ui 42 | 43 | # Default rules for deployment. 44 | qnx: target.path = /tmp/$${TARGET}/bin 45 | else: unix:!android: target.path = /opt/$${TARGET}/bin 46 | !isEmpty(target.path): INSTALLS += target 47 | -------------------------------------------------------------------------------- /help.cpp: -------------------------------------------------------------------------------- 1 | #include "help.h" 2 | #include "ui_help.h" 3 | 4 | Help::Help(QWidget *parent) : 5 | QWidget(parent), 6 | ui(new Ui::Help) 7 | { 8 | ui->setupUi(this); 9 | this->setAttribute(Qt::WA_QuitOnClose,false); 10 | } 11 | 12 | Help::~Help() 13 | { 14 | delete ui; 15 | } 16 | -------------------------------------------------------------------------------- /help.h: -------------------------------------------------------------------------------- 1 | #ifndef HELP_H 2 | #define HELP_H 3 | 4 | #include 5 | 6 | namespace Ui { 7 | class Help; 8 | } 9 | 10 | class Help : public QWidget 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit Help(QWidget *parent = nullptr); 16 | ~Help(); 17 | 18 | private: 19 | Ui::Help *ui; 20 | }; 21 | 22 | #endif // HELP_H 23 | -------------------------------------------------------------------------------- /help.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Help 4 | 5 | 6 | 7 | 0 8 | 0 9 | 600 10 | 350 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 21 | 600 22 | 350 23 | 24 | 25 | 26 | 27 | 600 28 | 350 29 | 30 | 31 | 32 | Help 33 | 34 | 35 | 36 | 37 | 38 | QFrame::NoFrame 39 | 40 | 41 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> 42 | <html><head><meta name="qrichtext" content="1" /><style type="text/css"> 43 | p, li { white-space: pre-wrap; } 44 | </style></head><body style=" font-family:'SimSun'; font-size:9pt; font-weight:400; font-style:normal;"> 45 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt;">本软件只可对CSV格式的轨迹数据进行回放:</span></p> 46 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt;">1.点击“打开文件”按钮进行CSV文件选择;</span></p> 47 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt;">2.在“数据结构”中调整数据所在的列索引,索引从0开始;</span></p> 48 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt;">3.在“实时数据”中可观察对应数字是否正确;</span></p> 49 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt;">4.点击“开始回放”可在地图上动态显示轨迹;</span></p> 50 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt;">5.播放速度在回放过程中可随时可调整,默认1秒一行;</span></p> 51 | <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:12pt;"><br /></p> 52 | <p align="right" style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:12pt;">—— Made by LC</span></p></body></html> 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | MainWindow w; 8 | w.show(); 9 | 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include "ui_mainwindow.h" 3 | #include 4 | #include 5 | 6 | MainWindow::MainWindow(QWidget *parent) : 7 | QMainWindow(parent), 8 | ui(new Ui::MainWindow) 9 | { 10 | ui -> setupUi(this); 11 | 12 | mapWidgetInit(); 13 | 14 | timer0 = new QTimer(this); 15 | connect(this->timer0,&QTimer::timeout,this,&MainWindow::updateTrack); 16 | this -> ui -> pushButton_start -> setEnabled(false); 17 | this -> ui -> comboBox_times_vel -> setEnabled(false); 18 | 19 | help = new Help(); 20 | } 21 | 22 | MainWindow::~MainWindow() 23 | { 24 | delete help; 25 | channel -> deregisterObject(mapChannel); 26 | delete ui; 27 | } 28 | 29 | void MainWindow::mapWidgetInit() 30 | { 31 | channel = new QWebChannel(this); 32 | mapChannel = new MapChannel(this); 33 | channel -> registerObject("passId",mapChannel); 34 | this -> ui -> widget_map -> page() -> setWebChannel(channel); 35 | this -> ui -> widget_map -> load(QUrl("file:///./onlinemap/map.html")); 36 | connect(mapChannel,&MapChannel::reloadMapClicked,this,&MainWindow::reloadMap); 37 | 38 | connect(mapChannel,&MapChannel::pointsCome,[](int index, double lng, double lat){ 39 | qDebug()< mapChannel -> clearTrack(); 58 | 59 | QTextStream in(&file); 60 | while (!in.atEnd()) 61 | { 62 | QString line = in.readLine(); 63 | lines.append(line); 64 | } 65 | file.close(); 66 | LineLength = lines.length(); 67 | 68 | QString line = lines.at(0); 69 | QStringList subs = line.split(","); 70 | this -> ui -> label_time_value -> setText(subs.at(timeCol)); 71 | this -> ui -> label_lng_value -> setText(subs.at(lngCol)); 72 | this -> ui -> label_lat_value -> setText(subs.at(latCol)); 73 | this -> ui -> label_yaw_value -> setText(subs.at(yawCol)); 74 | mapChannel -> panTo(subs.at(lngCol).toDouble(),subs.at(latCol).toDouble()); 75 | 76 | return true; 77 | } 78 | else { 79 | return false; 80 | } 81 | } 82 | 83 | 84 | void MainWindow::updateTrack() 85 | { 86 | if(LineIndex < LineLength) 87 | { 88 | QString line = lines.at(LineIndex); 89 | line = line.trimmed(); 90 | QStringList subs = line.split(","); 91 | 92 | double lng = subs.at(lngCol).toDouble(); 93 | double lat = subs.at(latCol).toDouble(); 94 | double yaw = subs.at(yawCol).toDouble(); 95 | mapChannel->updateBoatPos(lng,lat,yaw); 96 | this -> ui -> label_time_value -> setText(subs.at(timeCol)); 97 | this -> ui -> label_lng_value -> setText(subs.at(lngCol)); 98 | this -> ui -> label_lat_value -> setText(subs.at(latCol)); 99 | this -> ui -> label_yaw_value -> setText(subs.at(yawCol)); 100 | 101 | LineIndex++; 102 | } 103 | else 104 | { 105 | this -> timer0 -> stop(); 106 | this -> ui -> pushButton_start -> setText("开始回放"); 107 | this -> ui -> pushButton_start -> setEnabled(false); 108 | this -> ui -> comboBox_times_vel -> setEnabled(false); 109 | } 110 | } 111 | 112 | void MainWindow::on_pushButton_open_file_clicked() 113 | { 114 | timeCol = this -> ui -> spinBox_time_col -> value(); 115 | lngCol = this -> ui -> spinBox_lng_col -> value(); 116 | latCol = this -> ui -> spinBox_lat_col -> value(); 117 | yawCol = this -> ui -> spinBox_yaw_col -> value(); 118 | 119 | if(readfromfile()) 120 | { 121 | QMessageBox::information(this,"成功","文件打开成功,请检查实时数据是否正确!"); 122 | this -> ui -> pushButton_start -> setEnabled(true); 123 | this -> ui -> comboBox_times_vel -> setEnabled(true); 124 | } 125 | else { 126 | //this->close(); 127 | QMessageBox::critical(this,"错误","文件打开失败,请重试!"); 128 | } 129 | } 130 | 131 | void MainWindow::on_pushButton_start_clicked() //开始 132 | { 133 | if(this -> ui -> pushButton_start -> text() == "开始回放") 134 | { 135 | switch(this -> ui -> comboBox_times_vel -> currentIndex()) 136 | { 137 | case 0: 138 | this -> TimersVel = 1; 139 | break; 140 | case 1: 141 | this -> TimersVel = 1.25; 142 | break; 143 | case 2: 144 | this -> TimersVel = 1.5; 145 | break; 146 | case 3: 147 | this -> TimersVel = 2; 148 | break; 149 | case 4: 150 | this -> TimersVel = 3; 151 | break; 152 | case 5: 153 | this -> TimersVel = 5; 154 | break; 155 | case 6: 156 | this -> TimersVel = 10; 157 | break; 158 | case 7: 159 | this -> TimersVel = 15; 160 | break; 161 | default: 162 | break; 163 | } 164 | this -> timer0 -> start(int(1000/TimersVel)); 165 | this -> ui -> pushButton_start -> setText("停止回放"); 166 | } 167 | else { 168 | this -> timer0 -> stop(); 169 | this -> ui -> pushButton_start -> setText("开始回放"); 170 | } 171 | } 172 | 173 | void MainWindow::on_comboBox_times_vel_currentIndexChanged(int index) 174 | { 175 | switch(index) 176 | { 177 | case 0: 178 | this -> TimersVel = 1; 179 | break; 180 | case 1: 181 | this -> TimersVel = 1.25; 182 | break; 183 | case 2: 184 | this -> TimersVel = 1.5; 185 | break; 186 | case 3: 187 | this -> TimersVel = 2; 188 | break; 189 | case 4: 190 | this -> TimersVel = 3; 191 | break; 192 | case 5: 193 | this -> TimersVel = 5; 194 | break; 195 | case 6: 196 | this -> TimersVel = 10; 197 | break; 198 | case 7: 199 | this -> TimersVel = 15; 200 | break; 201 | default: 202 | break; 203 | } 204 | if(this -> ui -> pushButton_start -> text() == "停止回放") 205 | this -> timer0 ->start(int(1000/TimersVel)); 206 | } 207 | 208 | void MainWindow::on_spinBox_time_col_valueChanged(int arg1) 209 | { 210 | timeCol = arg1; 211 | QString line = lines.at(0); 212 | QStringList subs = line.split(","); 213 | this -> ui -> label_time_value -> setText(subs.at(timeCol)); 214 | } 215 | 216 | void MainWindow::on_spinBox_lng_col_valueChanged(int arg1) 217 | { 218 | lngCol = arg1; 219 | QString line = lines.at(0); 220 | QStringList subs = line.split(","); 221 | this -> ui -> label_lng_value -> setText(subs.at(lngCol)); 222 | mapChannel -> panTo(subs.at(lngCol).toDouble(),subs.at(latCol).toDouble()); 223 | } 224 | 225 | void MainWindow::on_spinBox_lat_col_valueChanged(int arg1) 226 | { 227 | latCol = arg1; 228 | QString line = lines.at(0); 229 | QStringList subs = line.split(","); 230 | this -> ui -> label_lat_value -> setText(subs.at(latCol)); 231 | mapChannel -> panTo(subs.at(lngCol).toDouble(),subs.at(latCol).toDouble()); 232 | } 233 | 234 | void MainWindow::on_spinBox_yaw_col_valueChanged(int arg1) 235 | { 236 | yawCol = arg1; 237 | QString line = lines.at(0); 238 | QStringList subs = line.split(","); 239 | this -> ui -> label_yaw_value -> setText(subs.at(yawCol)); 240 | } 241 | 242 | void MainWindow::reloadMap() 243 | { 244 | this -> ui -> widget_map -> load(QUrl("file:///./onlinemap/map.html")); 245 | } 246 | 247 | void MainWindow::on_pushButton_open_desired_track_file_clicked() 248 | { 249 | QString path = QFileDialog::getOpenFileName(this,"Open Json Task",QDir::currentPath()+"/task","JSON File(*.json)"); 250 | QFile jsonFile(path); 251 | if(!jsonFile.open(QIODevice::ReadOnly)) 252 | { 253 | QMessageBox::information(this,"提示","Json文件打开失败,请重试"); 254 | return; 255 | } 256 | 257 | QJsonParseError jsonError; 258 | QJsonDocument jsonDoc(QJsonDocument::fromJson(jsonFile.readAll(),&jsonError)); 259 | jsonFile.close(); 260 | if(jsonError.error != QJsonParseError::NoError) 261 | { 262 | QMessageBox::information(this,"提示",QString("Json解析失败,错误代码:%1,%2").arg(jsonError.error).arg(jsonError.errorString())); 263 | return; 264 | } 265 | 266 | QJsonObject rootObj = jsonDoc.object(); 267 | 268 | 269 | mapChannel->clearWaypoints(); 270 | int pointsNum=0; 271 | if(rootObj.contains("pointsNum")) 272 | { 273 | QJsonValue pointsNumValue = rootObj.value("pointsNum"); 274 | if(pointsNumValue.isDouble()) 275 | pointsNum = pointsNumValue.toInt(); 276 | else{ 277 | QMessageBox::information(this,"提示","Json中pointsNum类型错误!"); 278 | return; 279 | } 280 | }else{ 281 | QMessageBox::information(this,"提示","Json中无pointsNum!"); 282 | return; 283 | } 284 | if(rootObj.contains("waypoints")) 285 | { 286 | QVector lng(pointsNum); 287 | QVector lat(pointsNum); 288 | QJsonValue waypointsValue = rootObj.value("waypoints"); 289 | if(waypointsValue.isObject()) 290 | { 291 | QJsonObject waypointsObject = waypointsValue.toObject(); 292 | for (int i=0; iaddPoint(lng[i],lat[i]); 308 | }else{ 309 | QMessageBox::information(this,"提示","Json中waypoints不是JsonObject!"); 310 | return; 311 | } 312 | }else{ 313 | QMessageBox::information(this,"提示","Json中无waypoints!"); 314 | return; 315 | } 316 | } 317 | void MainWindow::on_pushButton_help_clicked() 318 | { 319 | help->show(); 320 | } 321 | -------------------------------------------------------------------------------- /mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #if _MSC_VER >= 1600 5 | #pragma execution_character_set("utf-8") 6 | #endif 7 | 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "mapchannel.h" 23 | #include "help.h" 24 | 25 | namespace Ui { 26 | class MainWindow; 27 | } 28 | 29 | class MainWindow : public QMainWindow 30 | { 31 | Q_OBJECT 32 | 33 | public: 34 | explicit MainWindow(QWidget *parent = nullptr); 35 | ~MainWindow(); 36 | bool readfromfile(); 37 | 38 | signals: 39 | void update(int); 40 | 41 | private slots: 42 | void updateTrack(); 43 | void reloadMap(); 44 | 45 | private slots: 46 | 47 | void on_pushButton_open_file_clicked(); 48 | 49 | void on_pushButton_start_clicked(); 50 | 51 | void on_comboBox_times_vel_currentIndexChanged(int index); 52 | 53 | void on_spinBox_time_col_valueChanged(int arg1); 54 | 55 | void on_spinBox_lng_col_valueChanged(int arg1); 56 | 57 | void on_spinBox_lat_col_valueChanged(int arg1); 58 | 59 | void on_spinBox_yaw_col_valueChanged(int arg1); 60 | 61 | void on_pushButton_open_desired_track_file_clicked(); 62 | 63 | void on_pushButton_help_clicked(); 64 | 65 | private: 66 | Ui::MainWindow *ui; 67 | 68 | 69 | void mapWidgetInit(); 70 | QWebChannel *channel; 71 | MapChannel *mapChannel; 72 | 73 | QList lines; 74 | QTimer* timer0; 75 | int LineIndex; 76 | int LineLength; 77 | int timeCol; 78 | int lngCol; 79 | int latCol; 80 | int yawCol; 81 | 82 | double TimersVel; 83 | 84 | Help *help; 85 | }; 86 | 87 | #endif // MAINWINDOW_H 88 | -------------------------------------------------------------------------------- /mainwindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | MainWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 1400 10 | 900 11 | 12 | 13 | 14 | Track Replay 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 打开文件 29 | 30 | 31 | 32 | 33 | 34 | 35 | 开始回放 36 | 37 | 38 | 39 | 40 | 41 | 42 | 期望轨迹 43 | 44 | 45 | 46 | 47 | 48 | 49 | 播放速度: 50 | 51 | 52 | Qt::AlignCenter 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | ×1 61 | 62 | 63 | 64 | 65 | ×1.25 66 | 67 | 68 | 69 | 70 | ×1.5 71 | 72 | 73 | 74 | 75 | ×2 76 | 77 | 78 | 79 | 80 | ×3 81 | 82 | 83 | 84 | 85 | ×5 86 | 87 | 88 | 89 | 90 | ×10 91 | 92 | 93 | 94 | 95 | ×15 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 帮助 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 数据结构 113 | 114 | 115 | Qt::AlignCenter 116 | 117 | 118 | 119 | 120 | 121 | 122 | 0 123 | 0 124 | 125 | 126 | 127 | 13 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 0 136 | 0 137 | 138 | 139 | 140 | 1 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 0 149 | 0 150 | 151 | 152 | 153 | 纬度: 154 | 155 | 156 | Qt::AlignCenter 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 0 165 | 0 166 | 167 | 168 | 169 | 2 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 0 178 | 0 179 | 180 | 181 | 182 | 时间: 183 | 184 | 185 | Qt::AlignCenter 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 0 194 | 0 195 | 196 | 197 | 198 | 经度: 199 | 200 | 201 | Qt::AlignCenter 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 0 210 | 0 211 | 212 | 213 | 214 | 艏向: 215 | 216 | 217 | Qt::AlignCenter 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 0 226 | 0 227 | 228 | 229 | 230 | 5 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 0 239 | 0 240 | 241 | 242 | 243 | 数据名称 244 | 245 | 246 | Qt::AlignCenter 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 0 255 | 0 256 | 257 | 258 | 259 | 数据位置 260 | 261 | 262 | Qt::AlignCenter 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 实时数据 273 | 274 | 275 | Qt::AlignCenter 276 | 277 | 278 | false 279 | 280 | 281 | false 282 | 283 | 284 | 285 | 286 | 287 | 数据名称 288 | 289 | 290 | Qt::AlignCenter 291 | 292 | 293 | 294 | 295 | 296 | 297 | 实时数值 298 | 299 | 300 | Qt::AlignCenter 301 | 302 | 303 | 304 | 305 | 306 | 307 | 时间: 308 | 309 | 310 | Qt::AlignCenter 311 | 312 | 313 | 314 | 315 | 316 | 317 | 经度: 318 | 319 | 320 | Qt::AlignCenter 321 | 322 | 323 | 324 | 325 | 326 | 327 | 纬度: 328 | 329 | 330 | Qt::AlignCenter 331 | 332 | 333 | 334 | 335 | 336 | 337 | 艏向: 338 | 339 | 340 | Qt::AlignCenter 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 0 383 | 0 384 | 1400 385 | 17 386 | 387 | 388 | 389 | 390 | 391 | Curve 392 | 393 | 394 | 395 | 396 | 397 | 398 | QWebEngineView 399 | QWidget 400 |
qwebengineview.h
401 | 1 402 |
403 |
404 | 405 | 406 |
407 | -------------------------------------------------------------------------------- /mapchannel.cpp: -------------------------------------------------------------------------------- 1 | #include "mapchannel.h" 2 | 3 | MapChannel::MapChannel(QObject *parent) : QObject(parent) 4 | { 5 | 6 | } 7 | 8 | void MapChannel::getMousePoint(double lng, double lat) 9 | { 10 | emit mousePointChanged(lng,lat); 11 | } 12 | 13 | void MapChannel::addPoint(double lng, double lat) 14 | { 15 | emit addPointClicked(lng,lat); 16 | } 17 | 18 | void MapChannel::movePoint(int id, double lng, double lat) 19 | { 20 | emit movePointClicked(id,lng,lat); 21 | } 22 | 23 | void MapChannel::transTask(int type, int len) 24 | { 25 | emit taskCome(type,len); 26 | } 27 | 28 | void MapChannel::transPoints(int id, double lng, double lat) 29 | { 30 | emit pointsCome(id,lng,lat); 31 | } 32 | 33 | void MapChannel::updateBoatPos(double lng, double lat, double course) 34 | { 35 | emit boatPosUpdated(lng,lat,course); 36 | } 37 | 38 | void MapChannel::reloadMap() 39 | { 40 | emit reloadMapClicked(); 41 | } 42 | 43 | void MapChannel::setOrigin(double lng, double lat) 44 | { 45 | emit setOriginPoint(lng,lat); 46 | } 47 | 48 | void MapChannel::clearWaypoints() 49 | { 50 | emit clearWaypointsClicked(); 51 | } 52 | 53 | void MapChannel::clearAll() 54 | { 55 | emit clearAllClicked(); 56 | } 57 | 58 | void MapChannel::addFencePoint(double lng, double lat) 59 | { 60 | emit addFencePointClicked(lng,lat); 61 | } 62 | 63 | void MapChannel::addFence() 64 | { 65 | emit addFenceClicked(); 66 | } 67 | 68 | void MapChannel::clearFence() 69 | { 70 | emit clearFenceClicked(); 71 | } 72 | 73 | void MapChannel::panTo(double lng, double lat) 74 | { 75 | emit panToClicked(lng,lat); 76 | } 77 | 78 | void MapChannel::clearTrack() 79 | { 80 | emit clearTrackClicked(); 81 | } 82 | -------------------------------------------------------------------------------- /mapchannel.h: -------------------------------------------------------------------------------- 1 | #ifndef MAPCHANNEL_H 2 | #define MAPCHANNEL_H 3 | 4 | #include 5 | 6 | class MapChannel : public QObject 7 | { 8 | Q_OBJECT 9 | public: 10 | explicit MapChannel(QObject *parent = nullptr); 11 | 12 | /*MainWindow 调用*/ 13 | void addPoint(double lng, double lat); 14 | void movePoint(int id, double lng, double lat); 15 | void updateBoatPos(double lng, double lat, double course); 16 | void setOrigin(double lng, double lat); 17 | void addFencePoint(double,double); 18 | void addFence(); 19 | void clearFence(); 20 | void clearWaypoints(); 21 | void clearTrack(); 22 | void panTo(double,double); 23 | 24 | signals: 25 | 26 | /*MapChannel -> MainWindow*/ 27 | void mousePointChanged(double, double); 28 | void reloadMapClicked(); 29 | void taskCome(int,int); 30 | void pointsCome(int,double,double); 31 | 32 | /*MapChannel -> html*/ 33 | void addPointClicked(double,double); 34 | void movePointClicked(int,double,double); 35 | void setOriginPoint(double,double); 36 | void boatPosUpdated(double,double,double); 37 | void addFencePointClicked(double,double); 38 | void addFenceClicked(); 39 | void clearFenceClicked(); 40 | void clearWaypointsClicked(); 41 | void clearAllClicked(); 42 | void clearTrackClicked(); 43 | void panToClicked(double,double); 44 | 45 | public slots: 46 | /*html调用*/ 47 | void getMousePoint(double lng, double lat); 48 | void reloadMap(); 49 | void transTask(int type, int len); 50 | void transPoints(int id, double lng, double lat); 51 | 52 | /*MainWindow 调用*/ 53 | void clearAll(); 54 | }; 55 | 56 | #endif // MAPCHANNEL_H 57 | --------------------------------------------------------------------------------