├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── deploy ├── linux │ ├── appimage │ │ ├── deploy.sh │ │ └── qUART.desktop │ ├── deploy_all.sh │ └── flatpak │ │ ├── deploy.sh │ │ ├── io.github.ilya_sotnikov.qUART.desktop │ │ └── io.github.ilya_sotnikov.qUART.yml ├── retag.sh └── windows │ └── deploy.sh ├── icons ├── actionAppendToPlotBlack.png ├── actionAppendToPlotWhite.png ├── actionAppendToSpectrumBlack.png ├── actionAppendToSpectrumWhite.png ├── actionChartTypeBlack.png ├── actionChartTypeWhite.png ├── actionClearBlack.png ├── actionClearWhite.png ├── actionConnectBlack.png ├── actionConnectWhite.png ├── actionDisconnectBlack.png ├── actionDisconnectWhite.png ├── actionHideMarkerBlack.png ├── actionHideMarkerWhite.png ├── actionResetZoomBlack.png ├── actionResetZoomWhite.png ├── app.png └── icons.qrc ├── lib ├── CMakeLists.txt └── qcustomplot │ └── CMakeLists.txt └── src ├── CMakeLists.txt ├── chart.cpp ├── chart.h ├── chartdatacontainer.cpp ├── chartdatacontainer.h ├── customaction.cpp ├── customaction.h ├── customgraph.cpp ├── customgraph.h ├── customplot.cpp ├── customplot.h ├── datasettingsdialog.cpp ├── datasettingsdialog.h ├── main.cpp ├── mainwindow.cpp ├── mainwindow.h ├── portsettingsdialog.cpp ├── portsettingsdialog.h ├── portsinfodialog.cpp ├── portsinfodialog.h ├── serialtransceiver.cpp ├── serialtransceiver.h ├── textwidget.cpp ├── textwidget.h └── themeinfo.h /.gitignore: -------------------------------------------------------------------------------- 1 | .cache 2 | .clang-format 3 | .flatpak-builder 4 | build* 5 | compile_commands.json 6 | todo.txt 7 | *.flatpak 8 | io.github.ilya_sotnikov 9 | *.AppImage 10 | AppDir 11 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.24) 2 | 3 | project(qUART VERSION 0.1 LANGUAGES CXX) 4 | 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | set(CMAKE_CXX_EXTENSIONS OFF) 8 | 9 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 10 | 11 | set(QT_VERSION_MAJOR 6) 12 | 13 | set(CMAKE_AUTORCC ON) 14 | 15 | find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) 16 | qt_standard_project_setup() 17 | 18 | # QCustomPlot 19 | set(QCUSTOMPLOT_SRC_DIR "") 20 | 21 | add_subdirectory(lib) 22 | add_subdirectory(src) 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # qUART 2 | Real-time graph and spectrum (of values, not amplitudes) serial plotter written in Qt6 and QCustomPlot. 3 | 4 | ## Screenshots 5 | 6 | ### Data representation 7 | | Plot | Spec | 8 | | --- | --- | 9 | | ![plot](https://github.com/ilya-sotnikov/qUART/assets/93074662/6db5cbd7-3270-4cf9-bebd-8e14cb34ac47) | ![spectrum](https://github.com/ilya-sotnikov/qUART/assets/93074662/3dd3f165-c832-42e7-809e-4dc748378c19) | 10 | 11 | ### Settings 12 | 13 | | Conf | Info | Data | 14 | | --- | --- | --- | 15 | | ![conf](https://github.com/ilya-sotnikov/qUART/assets/93074662/cd44bc96-aa0e-49cf-bbcc-9b37ff730c1e) | ![info](https://github.com/ilya-sotnikov/qUART/assets/93074662/aac73184-8d13-484f-9542-d0f8dfedfc14) | ![data](https://github.com/ilya-sotnikov/qUART/assets/93074662/ec9eb716-a51d-4c41-b061-200ae6988947) | 16 | 17 | ## Controls 18 | 19 | - LMB to drag (chart or axes) 20 | - mouse wheel to zoom (chart or axes) 21 | - RMB to select zoom 22 | - enter to send a number (0x__ for hex, 0b__ for binary), it will send the number with the minimum possible byte count (1, 2, 4 or 8) 23 | - enter to send a string 24 | 25 | ## License 26 | - qUART is licensed under GPL-3.0 27 | - Qt 6 is licensed under LGPL-3.0 28 | - QCustomPlot is licensed under GPL-3.0 29 | - Material Symbols are licensed under Apache-2.0 30 | 31 | ## Features 32 | - show all available ports (name, location, manufacturer, serial number, vendor and product identifiers) 33 | - configure the port (baud rate, data bits, parity, stop bits, flow control) 34 | - write a number to the serial port (can be signed or unsigned, in hex, binary or decimal, 8, 16, 32, 64 bit) 35 | - write a string to the serial port (with or without a newline) 36 | - save and restore settings 37 | - data representation as a plot/spectrum 38 | - show the last n points 39 | - turn off appending to the plot or the spectrum if not needed 40 | - data types 41 | - u8, u16, u32, u64 (unsigned) 42 | - i8, i16, i32, i64 (signed) 43 | - f32, f64 (float and double) 44 | - ASCII (text) 45 | - change the byte order 46 | - little-endian 47 | - big-endian 48 | - select any value on the chart 49 | - zoom (mouse wheel or RMB), navigate 50 | - toggle between log and linear scale 51 | - enable and disable autoscaling for both axes 52 | - save and open plot/spectrum data 53 | - clear the chart 54 | - save the chart as an image 55 | - set a custom chart update interval 56 | 57 | ## Append to plot/spectrum 58 | 59 | You can turn off appending to the plot or the spectrum. 60 | 61 | If you don't need information about the data sequence, you can turn off appending to the plot. It can save a lot of memory. 62 | 63 | However, if you are in the "Show last N points" mode, the latest data for the spectrum is recreated from the latest plot data, that's why data will always be appended there. But the program will only kepp the latest plot data. 64 | 65 | If you don't need information about the frequency distribution of the data, you can turn off appending to the spectrum. 66 | 67 | ## Installation 68 | 69 | Prebuilt executables are in the latest release. 70 | 71 | ### GNU/Linux x86-64 72 | 73 | Flatpak bundle: 74 | 75 | `flatpak install qUART-linux_x86-64.flatpak` 76 | 77 | AppImage: 78 | 79 | `chmod u+x qUART-linux_x86-64.AppImage` 80 | 81 | `./qUART-linux_x86-64.AppImage` 82 | 83 | You can build qUART yourself, the process is very simple. See the build instructions. 84 | 85 | ### Windows 10 or later 86 | 87 | For Windows x86-64 there is a zip archive. Just unpack it and run qUART.exe. 88 | 89 | ## Build instructions 90 | You can build it in all OSs where Qt6 is available. 91 | 92 | Dependencies: 93 | - Qt6 (base, QSerialPort) 94 | - QCustomPlot (can be downloaded automatically) 95 | 96 | Install them using a package manager or using the Qt installer. 97 | 98 | If you have already downloaded QCustomPlot you can set `QCUSTOMPLOT_SRC_PATH` in CMakeLists.txt, otherwise it will download it automatically. 99 | 100 | 1. `git clone https://github.com/ilya-sotnikov/qUART` 101 | 2. `cd qUART` 102 | 3. `mkdir build && cd build` 103 | 4. `cmake -DCMAKE_BUILD_TYPE=Release -G Ninja .. && cmake --build .` 104 | 5. `cmake --install .` 105 | 106 | ## Contributing 107 | Feel free to add features or fix bugs. This project uses the Qt code style, you can use the .clang-format file from [here](https://code.qt.io/cgit/qt/qt5.git/tree/_clang-format). 108 | 109 | Debug build uses sanitizers (address, undefined, leak) by default. 110 | -------------------------------------------------------------------------------- /deploy/linux/appimage/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | name="qUART" 6 | 7 | deploy_dir=`pwd` 8 | 9 | root_dir=$(pwd)/../../../ 10 | 11 | rm -rf AppDir 12 | 13 | mkdir -p ${root_dir}/build-release 14 | cd ${root_dir}/build-release 15 | 16 | cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -G Ninja .. && 17 | cmake --build . && 18 | cmake --install . --prefix ${deploy_dir}/AppDir 19 | 20 | cd ${deploy_dir} 21 | 22 | rm -f ${name}*.AppImage 23 | 24 | if [ ! -f "linuxdeploy-x86_64.AppImage" ]; then 25 | wget https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage 26 | chmod u+x linuxdeploy*.AppImage 27 | fi 28 | 29 | if [ ! -f "linuxdeploy-plugin-qt-x86_64.AppImage" ]; then 30 | wget https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage 31 | chmod u+x linuxdeploy*.AppImage 32 | fi 33 | 34 | QMAKE=qmake6 ./linuxdeploy-x86_64.AppImage --appdir AppDir -e AppDir/bin/${name} -i ${root_dir}/icons/app.png -d ${deploy_dir}/${name}.desktop --plugin qt --output appimage 35 | cp $(find . -name "${name}*.AppImage") "${name}-linux_x86-64.AppImage" 36 | -------------------------------------------------------------------------------- /deploy/linux/appimage/qUART.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=qUART 3 | Type=Application 4 | Categories=Development 5 | Exec=qUART 6 | Icon=app 7 | Terminal=false 8 | -------------------------------------------------------------------------------- /deploy/linux/deploy_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | name="qUART" 6 | 7 | cd flatpak 8 | ./deploy.sh 9 | cp ${name}-linux*.flatpak .. 10 | cd .. 11 | 12 | cd appimage 13 | ./deploy.sh 14 | cp ${name}-linux*.AppImage .. 15 | cd .. 16 | -------------------------------------------------------------------------------- /deploy/linux/flatpak/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | repo="io.github.ilya_sotnikov" 6 | name="qUART" 7 | app="${repo}.${name}" 8 | 9 | flatpak-builder ${name} --repo ${repo} --install-deps-from=flathub --force-clean --ccache ${app}.yml 10 | 11 | flatpak build-bundle ${repo} ${name}-linux_x86-64.flatpak ${app} --runtime-repo=https://flathub.org/repo/flathub.flatpakrepo 12 | -------------------------------------------------------------------------------- /deploy/linux/flatpak/io.github.ilya_sotnikov.qUART.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=qUART 3 | Type=Application 4 | Categories=Development 5 | Exec=qUART 6 | Icon=io.github.ilya_sotnikov.qUART 7 | Terminal=false 8 | -------------------------------------------------------------------------------- /deploy/linux/flatpak/io.github.ilya_sotnikov.qUART.yml: -------------------------------------------------------------------------------- 1 | app-id: io.github.ilya_sotnikov.qUART 2 | runtime: org.kde.Platform 3 | runtime-version: '6.4' 4 | sdk: org.kde.Sdk 5 | command: qUART 6 | finish-args: 7 | - --socket=wayland 8 | - --socket=x11 9 | - --device=dri 10 | - --device=all 11 | - --filesystem=home 12 | modules: 13 | - name: qUART 14 | buildsystem: cmake-ninja 15 | build-options: 16 | build-args: 17 | - --share=network 18 | config-opts: 19 | - -DCMAKE_BUILD_TYPE=Release 20 | build-commands: 21 | - mkdir -p /app/share/applications 22 | - cp io.github.ilya_sotnikov.qUART.desktop /app/share/applications/ 23 | - mkdir -p /app/share/icons/hicolor/48x48/apps 24 | - cp app.png /app/share/icons/hicolor/48x48/apps/io.github.ilya_sotnikov.qUART.png 25 | sources: 26 | - type: git 27 | url: https://github.com/ilya-sotnikov/qUART 28 | branch: main 29 | - type: file 30 | path: io.github.ilya_sotnikov.qUART.desktop 31 | - type: file 32 | path: ../../../icons/app.png 33 | -------------------------------------------------------------------------------- /deploy/retag.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | git tag -d latest 4 | git push --delete origin latest 5 | git tag -m latest latest 6 | git push origin latest 7 | 8 | firefox 'https://github.com/ilya-sotnikov/qUART/releases/new?tag=latest&title=Latest&body=Latest+release' 9 | -------------------------------------------------------------------------------- /deploy/windows/deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | name="qUART" 4 | 5 | deploy_dir=`pwd` 6 | 7 | mkdir -p ${name} 8 | 9 | mkdir -p ../../build-release 10 | cd ../../build-release 11 | cmake -DCMAKE_BUILD_TYPE=Release .. && cmake --build . 12 | 13 | cp ${name}.exe ${deploy_dir}/${name} 14 | cd ${deploy_dir}/${name} 15 | windeployqt-qt6 ${name}.exe 16 | ldd ${name}.exe | grep -Eiv 'system32|winsxs' | awk '{print $3}' | xargs cp -u -t . 17 | if [ -f "${deploy_dir}/${name}-windows_x86-64.zip" ]; then 18 | 7z u ${deploy_dir}/${name}-windows_x86-64.zip * 19 | else 20 | 7z a ${deploy_dir}/${name}-windows_x86-64.zip * 21 | fi 22 | 23 | cd ${deploy_dir} 24 | -------------------------------------------------------------------------------- /icons/actionAppendToPlotBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionAppendToPlotBlack.png -------------------------------------------------------------------------------- /icons/actionAppendToPlotWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionAppendToPlotWhite.png -------------------------------------------------------------------------------- /icons/actionAppendToSpectrumBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionAppendToSpectrumBlack.png -------------------------------------------------------------------------------- /icons/actionAppendToSpectrumWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionAppendToSpectrumWhite.png -------------------------------------------------------------------------------- /icons/actionChartTypeBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionChartTypeBlack.png -------------------------------------------------------------------------------- /icons/actionChartTypeWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionChartTypeWhite.png -------------------------------------------------------------------------------- /icons/actionClearBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionClearBlack.png -------------------------------------------------------------------------------- /icons/actionClearWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionClearWhite.png -------------------------------------------------------------------------------- /icons/actionConnectBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionConnectBlack.png -------------------------------------------------------------------------------- /icons/actionConnectWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionConnectWhite.png -------------------------------------------------------------------------------- /icons/actionDisconnectBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionDisconnectBlack.png -------------------------------------------------------------------------------- /icons/actionDisconnectWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionDisconnectWhite.png -------------------------------------------------------------------------------- /icons/actionHideMarkerBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionHideMarkerBlack.png -------------------------------------------------------------------------------- /icons/actionHideMarkerWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionHideMarkerWhite.png -------------------------------------------------------------------------------- /icons/actionResetZoomBlack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionResetZoomBlack.png -------------------------------------------------------------------------------- /icons/actionResetZoomWhite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/actionResetZoomWhite.png -------------------------------------------------------------------------------- /icons/app.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ilya-sotnikov/qUART/d4ef75938457588449f70cfdf09993e23818edfe/icons/app.png -------------------------------------------------------------------------------- /icons/icons.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | actionConnectBlack.png 4 | actionConnectWhite.png 5 | actionDisconnectBlack.png 6 | actionDisconnectWhite.png 7 | actionClearBlack.png 8 | actionClearWhite.png 9 | actionChartTypeBlack.png 10 | actionChartTypeWhite.png 11 | actionResetZoomBlack.png 12 | actionResetZoomWhite.png 13 | actionHideMarkerBlack.png 14 | actionHideMarkerWhite.png 15 | actionAppendToPlotBlack.png 16 | actionAppendToPlotWhite.png 17 | actionAppendToSpectrumBlack.png 18 | actionAppendToSpectrumWhite.png 19 | app.png 20 | 21 | 22 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | 3 | if(NOT EXISTS ${QCUSTOMPLOT_SRC_DIR}) 4 | FetchContent_Declare( 5 | QCustomPlot 6 | URL https://www.qcustomplot.com/release/2.1.1/QCustomPlot-source.tar.gz 7 | ) 8 | endif() 9 | 10 | add_subdirectory(qcustomplot) 11 | -------------------------------------------------------------------------------- /lib/qcustomplot/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (NOT EXISTS ${QCUSTOMPLOT_SRC_DIR}) 2 | FetchContent_MakeAvailable(QCustomPlot) 3 | set(QCUSTOMPLOT_SRC_DIR ${qcustomplot_SOURCE_DIR}) 4 | endif() 5 | 6 | find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) 7 | 8 | add_library(QCustomPlot STATIC) 9 | find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Gui PrintSupport) 10 | target_include_directories(QCustomPlot PUBLIC ${QCUSTOMPLOT_SRC_DIR}) 11 | target_sources(QCustomPlot PRIVATE 12 | ${QCUSTOMPLOT_SRC_DIR}/qcustomplot.cpp 13 | ${QCUSTOMPLOT_SRC_DIR}/qcustomplot.h 14 | ) 15 | target_link_libraries(QCustomPlot PRIVATE 16 | Qt${QT_VERSION_MAJOR}::Core 17 | Qt${QT_VERSION_MAJOR}::Gui 18 | Qt${QT_VERSION_MAJOR}::PrintSupport 19 | ) 20 | 21 | if(MSVC) 22 | target_compile_options(QCustomPlot PRIVATE /W4) 23 | else() 24 | target_compile_options(QCustomPlot PRIVATE -Wall -Wextra) 25 | set(SANITIZERS "-fsanitize=address,undefined,leak") 26 | target_compile_options(QCustomPlot PRIVATE "$<$:${SANITIZERS}>") 27 | target_link_options(QCustomPlot PRIVATE "$<$:${SANITIZERS}>") 28 | endif() 29 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) 2 | find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS SerialPort) 3 | 4 | set(PROJECT_SOURCES 5 | main.cpp 6 | mainwindow.h 7 | mainwindow.cpp 8 | chart.h 9 | chart.cpp 10 | customgraph.h 11 | customgraph.cpp 12 | chartdatacontainer.h 13 | chartdatacontainer.cpp 14 | serialtransceiver.h 15 | serialtransceiver.cpp 16 | portsettingsdialog.h 17 | portsettingsdialog.cpp 18 | datasettingsdialog.h 19 | datasettingsdialog.cpp 20 | portsinfodialog.h 21 | portsinfodialog.cpp 22 | textwidget.h 23 | textwidget.cpp 24 | customaction.h 25 | customaction.cpp 26 | themeinfo.h 27 | customplot.h 28 | customplot.cpp 29 | ${CMAKE_CURRENT_SOURCE_DIR}/../icons/icons.qrc 30 | ) 31 | 32 | qt_add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) 33 | 34 | target_link_libraries(${PROJECT_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::SerialPort QCustomPlot) 35 | 36 | set_target_properties(${PROJECT_NAME} PROPERTIES 37 | MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com 38 | MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} 39 | MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} 40 | MACOSX_BUNDLE TRUE 41 | WIN32_EXECUTABLE TRUE 42 | ) 43 | 44 | if(MSVC) 45 | target_compile_options(${PROJECT_NAME} PRIVATE /W4) 46 | else() 47 | target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) 48 | set(SANITIZERS "-fsanitize=address,undefined") 49 | target_compile_options(${PROJECT_NAME} PRIVATE "$<$:${SANITIZERS}>") 50 | target_link_options(${PROJECT_NAME} PRIVATE "$<$:${SANITIZERS}>") 51 | endif() 52 | 53 | add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD 54 | COMMAND ${CMAKE_COMMAND} -E copy 55 | ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_BINARY_DIR}/../compile_commands.json) 56 | 57 | install(TARGETS ${PROJECT_NAME} 58 | BUNDLE DESTINATION . 59 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} 60 | ) 61 | 62 | qt_generate_deploy_app_script( 63 | TARGET ${PROJECT_NAME} 64 | FILENAME_VARIABLE deploy_script 65 | NO_UNSUPPORTED_PLATFORM_ERROR 66 | ) 67 | 68 | install(SCRIPT ${deploy_script}) 69 | -------------------------------------------------------------------------------- /src/chart.cpp: -------------------------------------------------------------------------------- 1 | #include "chart.h" 2 | 3 | Chart::Chart(QWidget *parent) : QWidget{ parent } 4 | { 5 | const auto layout{ new QHBoxLayout{ this } }; 6 | layout->addWidget(customPlot); 7 | 8 | customPlot->replot(); 9 | 10 | timer->setInterval(updateInterval); 11 | timer->start(); 12 | 13 | connect(graph, qOverload(&QCPGraph::selectionChanged), this, 14 | &Chart::updateSelectedPoint); 15 | 16 | connect(timer, &QTimer::timeout, this, [this]() { 17 | if (needsUpdate) { 18 | needsUpdate = false; 19 | updateChart(); 20 | } 21 | }); 22 | 23 | connect(customPlot, &QCustomPlot::mousePress, this, [this](const QMouseEvent *event) { 24 | if (event->button() == Qt::RightButton) 25 | customPlot->setSelectionRectMode(QCP::SelectionRectMode::srmZoom); 26 | else 27 | customPlot->setSelectionRectMode(QCP::SelectionRectMode::srmNone); 28 | }); 29 | } 30 | 31 | /** 32 | * @brief Updates the data on the chart, rescales axes if needed, updates the selection and replots 33 | * 34 | */ 35 | void Chart::updateChart() 36 | { 37 | if (chartType == ChartType::plot) { 38 | graph->setData(chartDataContainer.getPlotLast()); 39 | if (autoscaleX) 40 | graph->rescalePlotKeyAxis(); 41 | if (autoscaleY) 42 | graph->rescalePlotValueAxis(); 43 | } else if (chartType == ChartType::spectrum) { 44 | graph->setData(chartDataContainer.getSpectrumLast()); 45 | if (autoscaleX) 46 | graph->rescaleSpectrumKeyAxis(); 47 | if (autoscaleY) 48 | graph->rescaleSpectrumValueAxis(); 49 | } 50 | 51 | const auto selection{ graph->selection() }; 52 | if (!selection.isEmpty()) 53 | updateSelectedPoint(selection); 54 | 55 | customPlot->replot(); 56 | } 57 | 58 | /** 59 | * @brief Changes the chart type and updates the chart 60 | * 61 | * If the current type is spectrum, it changes type to plot and vice versa. 62 | * 63 | */ 64 | void Chart::changeType() 65 | { 66 | setAutoscale(true, true); 67 | 68 | if (chartType == ChartType::spectrum) { 69 | chartType = ChartType::plot; 70 | graph->setLineStyle(QCPGraph::lsLine); 71 | graph->keyAxis()->setTickLengthIn(defaultTickLength); 72 | graph->keyAxis()->setSubTickLengthIn(defaultSubTickLength); 73 | } else if (chartType == ChartType::plot) { 74 | chartType = ChartType::spectrum; 75 | graph->setLineStyle(QCPGraph::lsImpulse); 76 | graph->keyAxis()->setTickLengthIn(0); 77 | graph->keyAxis()->setSubTickLengthIn(0); 78 | } 79 | 80 | customPlot->deselectAll(); 81 | 82 | needsUpdate = true; 83 | } 84 | 85 | /** 86 | * @brief Deletes all data and updates the chart 87 | * 88 | */ 89 | void Chart::clear() 90 | { 91 | chartDataContainer.clear(); 92 | needsUpdate = true; 93 | } 94 | 95 | /** 96 | * @brief Adds data to the chart 97 | * 98 | * @param receivedData 99 | * 100 | */ 101 | void Chart::addData(const QSharedPointer> receivedData) 102 | { 103 | chartDataContainer.append(*receivedData, appendToPlot, appendToSpectrum); 104 | needsUpdate = true; 105 | } 106 | 107 | /** 108 | * @brief Sets spectrumData to raw data, useful when loading data from a file 109 | * 110 | * @param rawData 111 | * 112 | */ 113 | void Chart::setRawSpectrumData(const QCPGraphDataContainer &rawData) 114 | { 115 | chartDataContainer.setRawSpectrumData(rawData); 116 | needsUpdate = true; 117 | } 118 | 119 | /** 120 | * @brief Sets autoscaling for both axes, rescales them and replots 121 | * 122 | */ 123 | void Chart::resetZoom() 124 | { 125 | setAutoscale(true, true); 126 | needsUpdate = true; 127 | } 128 | 129 | /** 130 | * @brief Updates the selected data point from its coordinates and emits a signal 131 | * 132 | * @param selection 133 | * 134 | */ 135 | void Chart::updateSelectedPoint(const QCPDataSelection &selection) 136 | { 137 | if (selection.isEmpty()) 138 | return; 139 | 140 | const auto chartX{ selection.dataRange().begin() }; 141 | QPointF selectedPoint{}; 142 | selectedPoint.setX(chartX); 143 | 144 | QCPGraphDataContainer::const_iterator pointIter; 145 | if (chartType == ChartType::plot) 146 | pointIter = chartDataContainer.getPlotLast()->at(chartX); 147 | else if (chartType == ChartType::spectrum) 148 | pointIter = chartDataContainer.getSpectrumLast()->at(chartX); 149 | 150 | selectedPoint.setX(pointIter->mainKey()); 151 | selectedPoint.setY(pointIter->mainValue()); 152 | 153 | emit selectedPointChanged(selectedPoint); 154 | } 155 | 156 | /** 157 | * @brief Sets update interval of a chart 158 | * 159 | * @param msec Update interval in milliseconds 160 | */ 161 | void Chart::setUpdateInterval(const int msec) const 162 | { 163 | customPlot->deselectAll(); 164 | 165 | timer->stop(); 166 | timer->setInterval(msec); 167 | timer->start(); 168 | } 169 | 170 | /** 171 | * @brief Sets value axis scaling (log or linear) 172 | * 173 | * @param log If true then log, otherwise linear 174 | */ 175 | void Chart::setLogarithmic(const bool log) 176 | { 177 | if (log) { 178 | customPlot->yAxis->setScaleType(QCPAxis::stLogarithmic); 179 | customPlot->yAxis->setTicker(QSharedPointer::create()); 180 | } else { 181 | customPlot->yAxis->setScaleType(QCPAxis::stLinear); 182 | customPlot->yAxis->setTicker(QSharedPointer::create()); 183 | } 184 | 185 | needsUpdate = true; 186 | }; 187 | 188 | /** 189 | * @brief Enables or disables autoscaling for both axes 190 | * 191 | * @param autoscaleX 192 | * @param autoscaleY 193 | * 194 | */ 195 | void Chart::setAutoscale(const bool autoscaleX, const bool autoscaleY) 196 | { 197 | setAutoscaleX(autoscaleX); 198 | setAutoscaleY(autoscaleY); 199 | }; 200 | 201 | /** 202 | * @brief Enables or disables autoscaling for the X axis (keys) 203 | * 204 | * @param autoscale 205 | * 206 | */ 207 | void Chart::setAutoscaleX(const bool autoscale) 208 | { 209 | const auto prevAutoScaleX{ autoscaleX }; 210 | autoscaleX = autoscale; 211 | 212 | needsUpdate = true; 213 | 214 | if ((prevAutoScaleX != autoscaleX)) 215 | emit autoscaleChanged(autoscaleX, autoscaleY); 216 | } 217 | 218 | /** 219 | * @brief Enables or disables autoscaling for the Y axis (values) 220 | * 221 | * @param autoscale 222 | * 223 | */ 224 | void Chart::setAutoscaleY(const bool autoscale) 225 | { 226 | const auto prevAutoScaleY{ autoscaleY }; 227 | autoscaleY = autoscale; 228 | 229 | needsUpdate = true; 230 | 231 | if ((prevAutoScaleY != autoscaleY)) 232 | emit autoscaleChanged(autoscaleX, autoscaleY); 233 | } 234 | -------------------------------------------------------------------------------- /src/chart.h: -------------------------------------------------------------------------------- 1 | #ifndef CHART_H 2 | #define CHART_H 3 | 4 | #include "chartdatacontainer.h" 5 | #include "customgraph.h" 6 | #include "customplot.h" 7 | 8 | #include "qcustomplot.h" 9 | #include 10 | 11 | /** 12 | * @brief Displays a chart (in plot mode or spectrum mode) 13 | * 14 | */ 15 | class Chart : public QWidget 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit Chart(QWidget *parent = nullptr); 21 | 22 | enum ChartType { plot, spectrum }; 23 | Q_ENUM(ChartType) 24 | auto getChartType() const { return chartType; } 25 | const auto &getPlotData() const { return chartDataContainer.getPlot(); } 26 | const auto &getSpectrumData() const { return chartDataContainer.getSpectrum(); } 27 | void updateChart(); 28 | void changeType(); 29 | void clear(); 30 | void setRawSpectrumData(const QCPGraphDataContainer &rawData); 31 | void setUpdateInterval(int msec) const; 32 | auto getUpdateInterval() const { return updateInterval; } 33 | void requestUpdate() { needsUpdate = true; } 34 | auto getAutoScaleX() const { return autoscaleX; } 35 | auto getAutoScaleY() const { return autoscaleY; } 36 | 37 | private: 38 | CustomPlot *customPlot{ new CustomPlot{ this } }; 39 | CustomGraph *graph{ new CustomGraph{ customPlot->xAxis, customPlot->yAxis } }; 40 | Chart::ChartType chartType{ ChartType::plot }; 41 | ChartDataContainer chartDataContainer; 42 | QTimer *timer{ new QTimer{ this } }; 43 | bool appendToPlot{ true }; 44 | bool appendToSpectrum{ true }; 45 | bool autoscaleX{ true }; 46 | bool autoscaleY{ true }; 47 | int updateInterval{ 33 }; 48 | bool needsUpdate{ false }; 49 | const int defaultTickLength{ graph->keyAxis()->tickLengthIn() }; 50 | const int defaultSubTickLength{ graph->keyAxis()->subTickLengthIn() }; 51 | 52 | public slots: 53 | void resetZoom(); 54 | void addData(const QSharedPointer> receivedData); 55 | void setAppendToPlot(const bool state) { appendToPlot = state; } 56 | void setAppendToSpectrum(const bool state) { appendToSpectrum = state; } 57 | void setLogarithmic(const bool log); 58 | void setAutoscale(const bool autoscaleX, const bool autoscaleY); 59 | void setAutoscaleX(const bool autoscale); 60 | void setAutoscaleY(const bool autoscale); 61 | void setShowLastPoints(const qsizetype n) 62 | { 63 | chartDataContainer.setLastPointsCount(n); 64 | needsUpdate = true; 65 | } 66 | 67 | private slots: 68 | void updateSelectedPoint(const QCPDataSelection &selection); 69 | 70 | signals: 71 | void selectedPointChanged(const QPointF selectedPoint); 72 | void autoscaleChanged(const bool autoscaleX, const bool autoscaleY); 73 | }; 74 | 75 | #endif // CHART_H 76 | -------------------------------------------------------------------------------- /src/chartdatacontainer.cpp: -------------------------------------------------------------------------------- 1 | #include "chartdatacontainer.h" 2 | 3 | #include 4 | 5 | /** 6 | * @brief Clears all data 7 | * 8 | */ 9 | void ChartDataContainer::clear() 10 | { 11 | plotData->clear(); 12 | plotDataLast->clear(); 13 | spectrumData->clear(); 14 | spectrumDataLast->clear(); 15 | currentPlotDataCount = 0; 16 | } 17 | 18 | /** 19 | * @brief Appends data to the plot and spectrum 20 | * 21 | * Note that the last spectrum values are recreated from the last plot values so if 22 | * appendSpectrum == true then the data is always added to the plotDataLast 23 | * 24 | * @param data Data to be appended 25 | * @param appendToPlot 26 | * @param appendToSpectrum 27 | * 28 | */ 29 | void ChartDataContainer::append(const QList &data, const bool appendToPlot, 30 | const bool appendToSpectrum) 31 | { 32 | appendPlot(data, appendToPlot, appendToPlot || appendToSpectrum); 33 | appendSpectrum(data, appendToSpectrum, appendToSpectrum); 34 | } 35 | 36 | /** 37 | * @brief Appends a value to the spectrum container 38 | * 39 | * @param value The value to be appended 40 | * @param spectrumContainer 41 | * 42 | */ 43 | void ChartDataContainer::appendSpectrumValue(const double value, 44 | QCPGraphDataContainer &spectrumContainer) const 45 | { 46 | const auto it{ std::lower_bound(spectrumContainer.begin(), spectrumContainer.end(), 47 | QCPGraphData::fromSortKey(value), 48 | qcpLessThanSortKey) }; 49 | if ((it != spectrumContainer.end()) && (it->mainKey() == value)) 50 | ++it->value; 51 | else 52 | spectrumContainer.add(QCPGraphData{ value, 1 }); 53 | } 54 | 55 | /** 56 | * @brief Appends data to the spectrum data container 57 | * 58 | * @param data Data to be appended 59 | * @param append 60 | * @param appendToLast 61 | * 62 | */ 63 | void ChartDataContainer::appendSpectrum(const QList &data, const bool append, 64 | const bool appendToLast) const 65 | { 66 | if (!append && !appendToLast) 67 | return; 68 | 69 | if (append) { 70 | for (const auto x : data) 71 | appendSpectrumValue(x, *spectrumData); 72 | } 73 | 74 | if (appendToLast) { 75 | if (lastPointsCount <= 0) 76 | return; 77 | 78 | spectrumDataLast->clear(); 79 | 80 | for (const auto point : *plotDataLast) 81 | appendSpectrumValue(point.mainValue(), *spectrumDataLast); 82 | } 83 | } 84 | 85 | /** 86 | * @brief Sets spectrumData to raw data, useful when loading data from a file 87 | * 88 | * @param rawData 89 | * 90 | */ 91 | void ChartDataContainer::setRawSpectrumData(const QCPGraphDataContainer &rawData) 92 | { 93 | clear(); 94 | spectrumData->set(rawData); 95 | } 96 | 97 | /** 98 | * @brief Appends data to the plot data container 99 | * 100 | * @param data Data to be appended 101 | * @param append 102 | * @param appendToLast 103 | * 104 | */ 105 | void ChartDataContainer::appendPlot(const QList &data, const bool append, 106 | const bool appendToLast) 107 | { 108 | if (!append && !appendToLast) 109 | return; 110 | 111 | const auto dataSize{ data.size() }; 112 | for (qsizetype i{ 0 }; i < dataSize; ++i) { 113 | const auto key{ static_cast(i + currentPlotDataCount) }; 114 | const auto value{ data.at(i) }; 115 | 116 | if (append) 117 | plotData->add(QCPGraphData{ key, value }); 118 | 119 | if (appendToLast) 120 | plotDataLast->add(QCPGraphData{ key, value }); 121 | } 122 | 123 | if (append || appendToLast) 124 | currentPlotDataCount += dataSize; 125 | 126 | if (lastPointsCount <= 0) 127 | return; 128 | 129 | qsizetype deleteCnt{ plotDataLast->size() - lastPointsCount }; 130 | if (deleteCnt > 0) { 131 | while (deleteCnt-- > 0) 132 | plotDataLast->remove(plotDataLast->begin()->sortKey()); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/chartdatacontainer.h: -------------------------------------------------------------------------------- 1 | #ifndef CHARTDATACONTAINER_H 2 | #define CHARTDATACONTAINER_H 3 | 4 | #include "qcustomplot.h" 5 | #include 6 | 7 | /** 8 | * @brief A data container for a plot and a spectrum 9 | * 10 | */ 11 | class ChartDataContainer 12 | { 13 | public: 14 | void append(const QList &data, const bool appendToPlot, const bool appendToSpectrum); 15 | void setRawSpectrumData(const QCPGraphDataContainer &rawData); 16 | void clear(); 17 | 18 | const auto &getPlot() const { return plotData; } 19 | const auto &getSpectrum() const { return spectrumData; } 20 | auto getLastPointsCount() const { return lastPointsCount; }; 21 | auto setLastPointsCount(qsizetype n) { lastPointsCount = n; }; 22 | const auto &getPlotLast() const { return (lastPointsCount < 0) ? plotData : plotDataLast; }; 23 | const auto &getSpectrumLast() const 24 | { 25 | return (lastPointsCount < 0) ? spectrumData : spectrumDataLast; 26 | }; 27 | 28 | private: 29 | void appendPlot(const QList &data, const bool append, const bool appendToLast); 30 | void appendSpectrum(const QList &data, const bool append, const bool appendToLast) const; 31 | void appendSpectrumValue(const double value, QCPGraphDataContainer &spectrumContainer) const; 32 | 33 | qsizetype lastPointsCount{ -1 }; 34 | qreal currentPlotDataCount{ 0 }; 35 | QSharedPointer plotData{ 36 | QSharedPointer::create() 37 | }; 38 | QSharedPointer plotDataLast{ 39 | QSharedPointer::create() 40 | }; 41 | QSharedPointer spectrumData{ 42 | QSharedPointer::create() 43 | }; 44 | QSharedPointer spectrumDataLast{ 45 | QSharedPointer::create() 46 | }; 47 | }; 48 | 49 | #endif // CHARTDATACONTAINER_H 50 | -------------------------------------------------------------------------------- /src/customaction.cpp: -------------------------------------------------------------------------------- 1 | #include "customaction.h" 2 | #include "themeinfo.h" 3 | 4 | #include 5 | 6 | using namespace Qt::Literals::StringLiterals; 7 | 8 | /** 9 | * @brief Sets a shortcut and optionally updates the tooltip 10 | * 11 | * @param shortcut 12 | * @param showInTooltip 13 | */ 14 | void CustomAction::setShortcut(const QKeySequence &shortcut, bool showInTooltip) 15 | { 16 | QAction::setShortcut(shortcut); 17 | if (showInTooltip) 18 | setToolTip(toolTip() + u" ("_s + shortcut.toString() + u")"_s); 19 | } 20 | 21 | /** 22 | * @brief Sets a black or white icon depending on the theme 23 | * 24 | * @param fileName 25 | */ 26 | void CustomAction::setIconWithTheme(const QString &fileName) 27 | { 28 | const QFileInfo file{ fileName }; 29 | const auto name{ file.baseName() }; 30 | const auto extension{ file.suffix() }; 31 | const auto fileNameWithTheme{ name + (ThemeInfo::isDarkTheme() ? u"White."_s : u"Black."_s) 32 | + extension }; 33 | setIcon(QIcon{ fileNameWithTheme }); 34 | } 35 | -------------------------------------------------------------------------------- /src/customaction.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMACTION_H 2 | #define CUSTOMACTION_H 3 | 4 | #include 5 | 6 | class CustomAction : public QAction 7 | { 8 | public: 9 | using QAction::QAction; 10 | using QAction::setShortcut; 11 | void setShortcut(const QKeySequence &shortcut, bool showInTooltip); 12 | void setIconWithTheme(const QString &fileName); 13 | }; 14 | 15 | #endif // CUSTOMACTION_H 16 | -------------------------------------------------------------------------------- /src/customgraph.cpp: -------------------------------------------------------------------------------- 1 | #include "customgraph.h" 2 | #include "themeinfo.h" 3 | 4 | CustomGraph::CustomGraph(QCPAxis *keyAxis, QCPAxis *valueAxis) : QCPGraph{ keyAxis, valueAxis } 5 | { 6 | constexpr qreal lineWidth{ 1 }; 7 | constexpr qreal plotScatterSize{ 10 }; 8 | constexpr auto plotSelectionColor{ QColor{ 80, 80, 255 } }; 9 | 10 | setSelectable(QCP::stSingleData); 11 | setPen(QPen{ QBrush{ Qt::black }, lineWidth }); 12 | setScatterStyle(QCPScatterStyle{ QCPScatterStyle::ssCross, Qt::transparent, plotScatterSize }); 13 | selectionDecorator()->setScatterStyle(QCPScatterStyle{ 14 | QCPScatterStyle::ssCross, QPen{ QBrush{ plotSelectionColor }, lineWidth + 1 }, 15 | QBrush{ plotSelectionColor }, plotScatterSize }); 16 | setPen(QPen{ ThemeInfo::windowTextColor() }); 17 | } 18 | 19 | /** 20 | * @brief Calculates the distance between the selected point's key and the data on the chart 21 | * 22 | * This is mostly copied from the QCustomPlot with only 2 differences: 23 | * 1. The distance is calculated only by the X coordinate (key) 24 | * 2. It doesn't calculate distance to graph line 25 | * 26 | * @param pixelPoint The point 27 | * @param closestData An iterator which will point to the closest data point from the chart 28 | * @return The distance between the point's X and the closes data point's X 29 | */ 30 | double CustomGraph::pointDistance(const QPointF &pixelPoint, 31 | QCPGraphDataContainer::const_iterator &closestData) const 32 | { 33 | closestData = mDataContainer->constEnd(); 34 | if (mDataContainer->isEmpty()) 35 | return -1.0; 36 | if (mLineStyle == lsNone && mScatterStyle.isNone()) 37 | return -1.0; 38 | 39 | // calculate minimum distances to graph data points and find closestData iterator: 40 | double minDistAbs = (std::numeric_limits::max)(); 41 | // determine which key range comes into question, taking selection tolerance around pos into 42 | // account: 43 | double posKeyMin, posKeyMax, dummy; 44 | pixelsToCoords( 45 | pixelPoint 46 | - QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), 47 | posKeyMin, dummy); 48 | pixelsToCoords( 49 | pixelPoint 50 | + QPointF(mParentPlot->selectionTolerance(), mParentPlot->selectionTolerance()), 51 | posKeyMax, dummy); 52 | if (posKeyMin > posKeyMax) 53 | qSwap(posKeyMin, posKeyMax); 54 | // iterate over found data points and then choose the one with the shortest distance to pos: 55 | QCPGraphDataContainer::const_iterator begin = mDataContainer->findBegin(posKeyMin, true); 56 | QCPGraphDataContainer::const_iterator end = mDataContainer->findEnd(posKeyMax, true); 57 | for (QCPGraphDataContainer::const_iterator it = begin; it != end; ++it) { 58 | // const double currentDistSqr = 59 | // QCPVector2D(coordsToPixels(it->key, it->value) - pixelPoint).lengthSquared(); 60 | const double currentDistAbs = qAbs(keyAxis()->coordToPixel(it->key) - pixelPoint.x()); 61 | if (currentDistAbs < minDistAbs) { 62 | minDistAbs = currentDistAbs; 63 | closestData = it; 64 | } 65 | } 66 | 67 | // calculate distance to graph line if there is one (if so, will probably be smaller than 68 | // distance to closest data point): 69 | // if (mLineStyle != lsNone) { 70 | // // line displayed, calculate distance to line segments: 71 | // QVector lineData; 72 | // getLines(&lineData, 73 | // QCPDataRange(0, dataCount())); // don't limit data range further since with 74 | // sharp 75 | // // data spikes, line segments may be closer to 76 | // test 77 | // // point than segments with closer key 78 | // coordinate 79 | // QCPVector2D p(pixelPoint); 80 | // const int step = mLineStyle == lsImpulse ? 2 : 1; 81 | // for (int i = 0; i < lineData.size() - 1; i += step) { 82 | // const double currentDistSqr = 83 | // p.distanceSquaredToLine(lineData.at(i), lineData.at(i + 1)); 84 | // if (currentDistSqr < minDistSqr) 85 | // minDistSqr = currentDistSqr; 86 | // } 87 | // } 88 | 89 | return minDistAbs; 90 | } 91 | 92 | /** 93 | * @brief This function is used to decide whether a click hits a layerable object or not 94 | * 95 | * This is entirely copied from the QCustomPlot without any modifications just to call overriden 96 | * non-virtual pointDistance method above instead of QCPGraph::pointDistance 97 | * 98 | * @param pos A point in pixel coordinates on the QCustomPlot surface 99 | * @param onlySelectable If true and the object is not selectable, -1.0 is returned 100 | * @param details An optional output parameter, every layerable subclass may place anything here 101 | * @return The shortest pixel distance of this point to the object, if the object is either 102 | * invisible or the distance couldn't be determined, -1.0 is returned 103 | * 104 | */ 105 | double CustomGraph::selectTest(const QPointF &pos, bool onlySelectable, QVariant *details) const 106 | { 107 | if ((onlySelectable && mSelectable == QCP::stNone) || mDataContainer->isEmpty()) 108 | return -1; 109 | if (!mKeyAxis || !mValueAxis) 110 | return -1; 111 | 112 | if (mKeyAxis.data()->axisRect()->rect().contains(pos.toPoint()) 113 | || mParentPlot->interactions().testFlag(QCP::iSelectPlottablesBeyondAxisRect)) { 114 | QCPGraphDataContainer::const_iterator closestDataPoint = mDataContainer->constEnd(); 115 | double result = pointDistance(pos, closestDataPoint); 116 | if (details) { 117 | int pointIndex = int(closestDataPoint - mDataContainer->constBegin()); 118 | details->setValue(QCPDataSelection(QCPDataRange(pointIndex, pointIndex + 1))); 119 | } 120 | return result; 121 | } else 122 | return -1; 123 | } 124 | 125 | /** 126 | * @brief Rescales the key axis of the spectrum so the whole spectrum is visible 127 | * 128 | * @param onlyEnlarge If true don't shrink axis 129 | */ 130 | void CustomGraph::rescaleSpectrumKeyAxis(bool onlyEnlarge) 131 | { 132 | if (dataCount() == 0) 133 | return; 134 | 135 | rescaleKeyAxis(onlyEnlarge); 136 | auto keyRange{ keyAxis()->range() }; 137 | keyRange.expand(keyRange.lower - 10); 138 | keyRange.expand(keyRange.upper + 10); 139 | keyAxis()->setRange(keyRange); 140 | }; 141 | 142 | /** 143 | * @brief Rescales the value axis of the spectrum so the whole spectrum is visible. 144 | * 145 | * @param onlyEnlarge If true don't shrink axis 146 | * @param inKeyRange If true then only the data points which are in the currently visible axis 147 | * range are considered. 148 | */ 149 | void CustomGraph::rescaleSpectrumValueAxis(bool onlyEnlarge, bool inKeyRange) 150 | { 151 | if (dataCount() == 0) 152 | return; 153 | 154 | // a hack for rescaleValueAxis in case of !QCPRange::validRange(newRange) 155 | valueAxis()->setRange(QCPRange{ 0, 2 }); 156 | rescaleValueAxis(onlyEnlarge, inKeyRange); 157 | auto valueRange{ valueAxis()->range() }; 158 | if (valueAxis()->scaleType() == QCPAxis::stLinear) { 159 | valueRange.expand(0); 160 | valueRange.expand(valueRange.upper + 1); 161 | } else { // log 162 | valueRange.expand(0.1); 163 | valueRange.expand(100); 164 | } 165 | valueAxis()->setRange(valueRange); 166 | } 167 | -------------------------------------------------------------------------------- /src/customgraph.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMGRAPH_H 2 | #define CUSTOMGRAPH_H 3 | 4 | #include "qcustomplot.h" 5 | 6 | class CustomGraph : public QCPGraph 7 | { 8 | public: 9 | explicit CustomGraph(QCPAxis *keyAxis, QCPAxis *valueAxis); 10 | 11 | void rescalePlotKeyAxis(bool onlyEnlarge = false) { rescaleKeyAxis(onlyEnlarge); }; 12 | void rescalePlotValueAxis(bool onlyEnlarge = false, bool inKeyRange = false) 13 | { 14 | rescaleValueAxis(onlyEnlarge, inKeyRange); 15 | }; 16 | void rescaleSpectrumKeyAxis(bool onlyEnlarge = false); 17 | void rescaleSpectrumValueAxis(bool onlyEnlarge = false, bool inKeyRange = false); 18 | 19 | protected: 20 | using QCPGraph::QCPGraph; 21 | double pointDistance(const QPointF &pixelPoint, 22 | QCPGraphDataContainer::const_iterator &closestData) const; 23 | virtual double selectTest(const QPointF &pos, bool onlySelectable, 24 | QVariant *details = nullptr) const Q_DECL_OVERRIDE; 25 | }; 26 | 27 | #endif // CUSTOMGRAPH_H 28 | -------------------------------------------------------------------------------- /src/customplot.cpp: -------------------------------------------------------------------------------- 1 | #include "customplot.h" 2 | #include "themeinfo.h" 3 | 4 | CustomPlot::CustomPlot(QWidget *parent) : QCustomPlot{ parent } 5 | { 6 | setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables); 7 | setSelectionTolerance(20); 8 | setAntialiasedElements(QCP::aePlottables); 9 | 10 | const auto themeWindowColor{ ThemeInfo::windowColor() }; 11 | const auto themeWindowTextColor{ ThemeInfo::windowTextColor() }; 12 | 13 | setBackground(QBrush{ themeWindowColor }); 14 | xAxis->setBasePen(QPen{ themeWindowTextColor }); 15 | xAxis->setTickPen(QPen{ themeWindowTextColor }); 16 | xAxis->setSubTickPen(QPen{ themeWindowTextColor }); 17 | xAxis->setLabelColor(themeWindowTextColor); 18 | xAxis->setTickLabelColor(themeWindowTextColor); 19 | 20 | yAxis->setBasePen(QPen{ themeWindowTextColor }); 21 | yAxis->setTickPen(QPen{ themeWindowTextColor }); 22 | yAxis->setSubTickPen(QPen{ themeWindowTextColor }); 23 | yAxis->setLabelColor(themeWindowTextColor); 24 | yAxis->setTickLabelColor(themeWindowTextColor); 25 | } 26 | -------------------------------------------------------------------------------- /src/customplot.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOMPLOT_H 2 | #define CUSTOMPLOT_H 3 | 4 | #include "qcustomplot.h" 5 | 6 | class CustomPlot : public QCustomPlot 7 | { 8 | public: 9 | explicit CustomPlot(QWidget *parent = nullptr); 10 | }; 11 | 12 | #endif // CUSTOMPLOT_H 13 | -------------------------------------------------------------------------------- /src/datasettingsdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "datasettingsdialog.h" 2 | #include "serialtransceiver.h" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace Qt::Literals::StringLiterals; 11 | 12 | DataSettingsDialog::DataSettingsDialog(QWidget *parent) : QDialog{ parent } 13 | { 14 | const auto layout{ new QVBoxLayout{ this } }; 15 | 16 | const auto buttonBox{ new QDialogButtonBox{ QDialogButtonBox::Cancel | QDialogButtonBox::Ok, 17 | Qt::Horizontal, this } }; 18 | 19 | const auto settingsBox{ new QGroupBox{ u"Data settings"_s } }; 20 | const auto settingsLayout{ new QGridLayout{ settingsBox } }; 21 | 22 | const auto dataFormatLabel{ new QLabel{ u"Data format"_s } }; 23 | dataTypeBox->addItem(u"ASCII"_s, SerialTransceiver::DataTypes::ascii); 24 | dataTypeBox->addItem(u"unsigned 8 bit"_s, SerialTransceiver::DataTypes::u8); 25 | dataTypeBox->addItem(u"unsigned 16 bit"_s, SerialTransceiver::DataTypes::u16); 26 | dataTypeBox->addItem(u"unsigned 32 bit"_s, SerialTransceiver::DataTypes::u32); 27 | dataTypeBox->addItem(u"unsigned 64 bit"_s, SerialTransceiver::DataTypes::u64); 28 | dataTypeBox->addItem(u"signed 8 bit"_s, SerialTransceiver::DataTypes::i8); 29 | dataTypeBox->addItem(u"signed 16 bit"_s, SerialTransceiver::DataTypes::i16); 30 | dataTypeBox->addItem(u"signed 32 bit"_s, SerialTransceiver::DataTypes::i32); 31 | dataTypeBox->addItem(u"signed 64 bit"_s, SerialTransceiver::DataTypes::i64); 32 | dataTypeBox->addItem(u"float 32 bit"_s, SerialTransceiver::DataTypes::f32); 33 | dataTypeBox->addItem(u"double 64 bit"_s, SerialTransceiver::DataTypes::f64); 34 | settingsLayout->addWidget(dataFormatLabel, 0, 0); 35 | settingsLayout->addWidget(dataTypeBox, 0, 1); 36 | 37 | const auto byteOrderLabel{ new QLabel{ u"Byte order (for numeric)"_s } }; 38 | byteOrderBox->addItem(u"little-endian"_s, QDataStream::LittleEndian); 39 | byteOrderBox->addItem(u"big-endian"_s, QDataStream::BigEndian); 40 | settingsLayout->addWidget(byteOrderLabel, 1, 0); 41 | settingsLayout->addWidget(byteOrderBox, 1, 1); 42 | 43 | layout->addWidget(settingsBox, 0, Qt::AlignTop); 44 | layout->addWidget(buttonBox, 0, Qt::AlignBottom); 45 | 46 | setWindowTitle(u"Data settings"_s); 47 | setModal(true); 48 | 49 | loadSettings(); 50 | 51 | connect(buttonBox, &QDialogButtonBox::accepted, this, &DataSettingsDialog::ok); 52 | connect(buttonBox, &QDialogButtonBox::rejected, this, &DataSettingsDialog::cancel); 53 | } 54 | 55 | /** 56 | * @brief Updates the current settings according to the selected settings 57 | * 58 | */ 59 | void DataSettingsDialog::updateSettings() 60 | { 61 | settings.dataType = dataTypeBox->currentData().value(); 62 | settings.byteOrder = byteOrderBox->currentData().value(); 63 | } 64 | 65 | /** 66 | * @brief Updates the combo box current index according to the data 67 | * 68 | * @tparam T Data type 69 | * @param comboBox QComboBox to be updated 70 | * @param data Data from QComboBox 71 | */ 72 | template 73 | void DataSettingsDialog::updateIndex(QComboBox *const comboBox, const T data) const 74 | { 75 | const auto index{ comboBox->findData(data) }; 76 | if (index != -1) 77 | comboBox->setCurrentIndex(index); 78 | } 79 | 80 | /** 81 | * @brief Updates indexes of all combo boxes 82 | * 83 | */ 84 | void DataSettingsDialog::updateIndexes() const 85 | { 86 | updateIndex(dataTypeBox, settings.dataType); 87 | updateIndex(byteOrderBox, settings.byteOrder); 88 | } 89 | 90 | /** 91 | * @brief Loads settings from a file 92 | * 93 | */ 94 | void DataSettingsDialog::loadSettings() 95 | { 96 | QSettings settingsFile; 97 | settingsFile.beginGroup(u"data"_s); 98 | settings.dataType = static_cast( 99 | settingsFile.value(u"type"_s, SerialTransceiver::DataTypes::ascii).toInt()); 100 | settings.byteOrder = static_cast( 101 | settingsFile.value(u"byteOrder"_s, QDataStream::LittleEndian).toInt()); 102 | settingsFile.endGroup(); 103 | } 104 | 105 | /** 106 | * @brief Saves settings to a file 107 | * 108 | */ 109 | void DataSettingsDialog::saveSettings() const 110 | { 111 | QSettings settingsFile; 112 | 113 | settingsFile.beginGroup(u"data"_s); 114 | settingsFile.setValue(u"type"_s, settings.dataType); 115 | settingsFile.setValue(u"byteOrder"_s, settings.byteOrder); 116 | settingsFile.endGroup(); 117 | } 118 | 119 | /** 120 | * @brief Updates the current settings, saves them to a file and hides DataSettingsDialog 121 | * 122 | */ 123 | void DataSettingsDialog::ok() 124 | { 125 | 126 | updateSettings(); 127 | saveSettings(); 128 | hide(); 129 | } 130 | 131 | /** 132 | * @brief Hides DataSettingsDialog without changing anything 133 | * 134 | */ 135 | void DataSettingsDialog::cancel() 136 | { 137 | hide(); 138 | } 139 | -------------------------------------------------------------------------------- /src/datasettingsdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DATASETTINGSDIALOG_H 2 | #define DATASETTINGSDIALOG_H 3 | 4 | #include "serialtransceiver.h" 5 | 6 | #include 7 | #include 8 | 9 | /** 10 | * @brief A dialog with data settings (data type and byte order) 11 | * 12 | */ 13 | class DataSettingsDialog : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | explicit DataSettingsDialog(QWidget *parent = nullptr); 19 | 20 | struct Settings 21 | { 22 | QDataStream::ByteOrder byteOrder{ QDataStream::LittleEndian }; 23 | SerialTransceiver::DataTypes dataType{ SerialTransceiver::DataTypes::ascii }; 24 | }; 25 | 26 | auto getSettings() const { return settings; }; 27 | 28 | public slots: 29 | void showDialog() 30 | { 31 | updateIndexes(); 32 | show(); 33 | } 34 | 35 | private: 36 | Settings settings; 37 | QComboBox *dataTypeBox{ new QComboBox{ this } }; 38 | QComboBox *byteOrderBox{ new QComboBox{ this } }; 39 | 40 | void saveSettings() const; 41 | void loadSettings(); 42 | void updateSettings(); 43 | template 44 | void updateIndex(QComboBox *const comboBox, const T data) const; 45 | void updateIndexes() const; 46 | 47 | private slots: 48 | void ok(); 49 | void cancel(); 50 | }; 51 | 52 | #endif // DATASETTINGSDIALOG_H 53 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | using namespace Qt::Literals::StringLiterals; 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | const QApplication a{ argc, argv }; 8 | 9 | QCoreApplication::setOrganizationName(u"qUART"_s); 10 | QCoreApplication::setApplicationName(u"qUART"_s); 11 | 12 | MainWindow w; 13 | w.show(); 14 | return a.exec(); 15 | } 16 | -------------------------------------------------------------------------------- /src/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | using namespace Qt::Literals::StringLiterals; 4 | 5 | MainWindow::MainWindow(QWidget *parent) : QMainWindow{ parent } 6 | { 7 | setMinimumSize(QSize{ 800, 600 }); 8 | setWindowTitle(u"qUART"_s); 9 | setWindowIcon(QIcon{ u":app.png"_s }); 10 | 11 | const auto menuBar{ new QMenuBar{ this } }; 12 | const auto menuFile{ new QMenu{ u"File"_s, menuBar } }; 13 | const auto menuSettings{ new QMenu{ u"Settings"_s, menuBar } }; 14 | const auto menuHelp{ new CustomAction{ u"Help"_s, menuBar } }; 15 | setMenuBar(menuBar); 16 | 17 | setStatusBar(statusBar); 18 | 19 | actionConnect->setIconWithTheme(u":actionConnect.png"_s); 20 | actionConnect->setShortcut(QKeySequence{ u"Alt+C"_s }, true); 21 | actionDisconnect->setIconWithTheme(u":actionDisconnect.png"_s); 22 | actionDisconnect->setShortcut(QKeySequence{ u"Alt+D"_s }, true); 23 | actionClear->setIconWithTheme(u":actionClear.png"_s); 24 | actionClear->setShortcut(QKeySequence{ u"Ctrl+L"_s }, true); 25 | actionChartType->setIconWithTheme(u":actionChartType.png"_s); 26 | actionChartType->setShortcut(QKeySequence{ u"Ctrl+T"_s }, true); 27 | actionResetZoom->setIconWithTheme(u":actionResetZoom.png"_s); 28 | actionResetZoom->setShortcut(QKeySequence{ u"Ctrl+R"_s }, true); 29 | actionAppendToPlot->setIconWithTheme(u":actionAppendToPlot.png"_s); 30 | actionAppendToPlot->setCheckable(true); 31 | actionAppendToPlot->setChecked(true); 32 | actionAppendToSpectrum->setIconWithTheme(u":actionAppendToSpectrum.png"_s); 33 | actionAppendToSpectrum->setCheckable(true); 34 | actionAppendToSpectrum->setChecked(true); 35 | 36 | const auto toolBar{ new QToolBar{ this } }; 37 | addToolBar(Qt::TopToolBarArea, toolBar); 38 | 39 | menuBar->addAction(menuFile->menuAction()); 40 | menuBar->addAction(menuSettings->menuAction()); 41 | menuBar->addAction(menuHelp); 42 | menuFile->addAction(actionSavePlot); 43 | menuFile->addAction(actionOpenPlot); 44 | menuFile->addAction(actionSaveSpectrum); 45 | menuFile->addAction(actionOpenSpectrum); 46 | menuFile->addAction(actionSaveImage); 47 | menuSettings->addAction(actionPortSettings); 48 | menuSettings->addAction(actionDataSettings); 49 | menuSettings->addSeparator(); 50 | toolBar->addAction(actionConnect); 51 | toolBar->addAction(actionDisconnect); 52 | toolBar->addAction(actionClear); 53 | toolBar->addAction(actionChartType); 54 | toolBar->addAction(actionResetZoom); 55 | toolBar->addAction(actionAppendToPlot); 56 | toolBar->addAction(actionAppendToSpectrum); 57 | 58 | const auto sidePanel{ new QGroupBox }; 59 | sidePanel->setTitle(u"Side panel"_s); 60 | 61 | const auto sidePanelLayout{ new QVBoxLayout }; 62 | 63 | const auto lastPointsLabel{ new QLabel{ u"Show last N points:"_s } }; 64 | sidePanelLayout->addWidget(lastPointsLabel); 65 | const auto lastPointsLineEdit{ new QLineEdit }; 66 | lastPointsLineEdit->setToolTip(u"Empty means show all data"_s); 67 | sidePanelLayout->addWidget(lastPointsLineEdit); 68 | 69 | const auto updateIntervalLabel{ new QLabel{ u"Update interval (ms):"_s } }; 70 | sidePanelLayout->addWidget(updateIntervalLabel); 71 | sidePanelLayout->addWidget(updateIntervalLineEdit); 72 | 73 | sidePanelLayout->addWidget(logScaleCheckBox); 74 | 75 | const auto autoscaleLabel{ new QLabel{ u"Autoscale:"_s } }; 76 | sidePanelLayout->addWidget(autoscaleLabel); 77 | const auto autoscaleLayout{ new QHBoxLayout{} }; 78 | autoscaleLayout->addWidget(autoscaleCheckboxX); 79 | autoscaleCheckboxX->setChecked(chart->getAutoScaleX()); 80 | autoscaleCheckboxY->setChecked(chart->getAutoScaleY()); 81 | autoscaleLayout->addWidget(autoscaleCheckboxY); 82 | sidePanelLayout->addLayout(autoscaleLayout); 83 | 84 | const auto sendNumLabel{ new QLabel{ u"Send a number:"_s } }; 85 | sidePanelLayout->addWidget(sendNumLabel); 86 | sendNumLineEdit->setToolTip(u"0x__ for hex, 0b__ for binary, Enter to send"_s); 87 | sendNumLineEdit->setEnabled(false); 88 | sidePanelLayout->addWidget(sendNumLineEdit); 89 | sidePanelLayout->addWidget(sendSignedCheckBox); 90 | sendSignedCheckBox->setEnabled(false); 91 | 92 | const auto sendStringLabel{ new QLabel{ u"Send a string:"_s } }; 93 | sidePanelLayout->addWidget(sendStringLabel); 94 | sendStringLineEdit->setToolTip(u"Enter to send"_s); 95 | sendStringLineEdit->setEnabled(false); 96 | sidePanelLayout->addWidget(sendStringLineEdit); 97 | sidePanelLayout->addWidget(sendStringNewlineCheckBox); 98 | sendStringNewlineCheckBox->setEnabled(false); 99 | sendStringNewlineCheckBox->setCheckState(Qt::Checked); 100 | 101 | sidePanelLayout->addStretch(); 102 | sidePanel->setLayout(sidePanelLayout); 103 | 104 | const auto windowLayout{ new QHBoxLayout }; 105 | windowLayout->addWidget(sidePanel, 0); 106 | windowLayout->addWidget(chart, 1); 107 | 108 | const auto window{ new QWidget }; 109 | window->setLayout(windowLayout); 110 | setCentralWidget(window); 111 | 112 | actionConnect->setEnabled(true); 113 | actionDisconnect->setEnabled(false); 114 | actionPortSettings->setEnabled(true); 115 | 116 | statusBar->addPermanentWidget(chartTypeWidget); 117 | if (chart->getChartType() == Chart::ChartType::plot) 118 | chartTypeWidget->setText(u"Chart type: Plot"_s); 119 | else if (chart->getChartType() == Chart::ChartType::spectrum) 120 | chartTypeWidget->setText(u"Chart type: Spectrum"_s); 121 | 122 | connect(serialTransceiver, &SerialTransceiver::newDataAvailable, chart, &Chart::addData); 123 | connect(actionConnect, &QAction::triggered, this, &MainWindow::serialConnect); 124 | connect(actionDisconnect, &QAction::triggered, this, &MainWindow::serialDisconnect); 125 | connect(actionClear, &QAction::triggered, this, [this]() { chart->clear(); }); 126 | connect(actionChartType, &QAction::triggered, chart, &Chart::changeType); 127 | connect(actionChartType, &QAction::triggered, this, &MainWindow::chartTypeChanged); 128 | connect(actionResetZoom, &QAction::triggered, chart, &Chart::resetZoom); 129 | connect(actionAppendToPlot, &QAction::toggled, chart, &Chart::setAppendToPlot); 130 | connect(actionAppendToSpectrum, &QAction::toggled, chart, &Chart::setAppendToPlot); 131 | 132 | connect(actionSavePlot, &QAction::triggered, this, &MainWindow::savePlotData); 133 | connect(actionOpenPlot, &QAction::triggered, this, &MainWindow::openPlotData); 134 | connect(actionSaveSpectrum, &QAction::triggered, this, &MainWindow::saveSpectrumData); 135 | connect(actionOpenSpectrum, &QAction::triggered, this, &MainWindow::openSpectrumData); 136 | connect(actionSaveImage, &QAction::triggered, this, &MainWindow::saveImage); 137 | connect(actionPortSettings, &QAction::triggered, portSettingsDialog, 138 | &PortSettingsDialog::showDialog); 139 | connect(actionDataSettings, &QAction::triggered, dataSettingsDialog, 140 | &DataSettingsDialog::showDialog); 141 | 142 | connect(chart, &Chart::selectedPointChanged, this, &MainWindow::updateSelectedPoint); 143 | 144 | connect(lastPointsLineEdit, &QLineEdit::textChanged, this, [this](const QString &text) { 145 | bool ok; 146 | const auto n{ text.toLongLong(&ok, 0) }; 147 | 148 | if (ok) 149 | chart->setShowLastPoints(n); 150 | else 151 | chart->setShowLastPoints(-1); 152 | }); 153 | 154 | connect(sendNumLineEdit, &QLineEdit::returnPressed, this, [this]() { 155 | const auto numString{ sendNumLineEdit->text() }; 156 | const bool isSigned{ sendSignedCheckBox->isChecked() }; 157 | serialTransceiver->writeNumber(numString, isSigned); 158 | }); 159 | 160 | connect(sendStringLineEdit, &QLineEdit::returnPressed, this, [this]() { 161 | const auto string{ sendStringLineEdit->text() }; 162 | const bool appendNewline{ sendStringNewlineCheckBox->isChecked() }; 163 | serialTransceiver->writeString(string, appendNewline); 164 | }); 165 | 166 | connect(updateIntervalLineEdit, &QLineEdit::textChanged, this, [this]() { 167 | bool ok; 168 | const auto ms{ updateIntervalLineEdit->text().toInt(&ok) }; 169 | if (ok) 170 | chart->setUpdateInterval(ms); 171 | }); 172 | 173 | connect(chart, &Chart::autoscaleChanged, this, 174 | [this](const bool autoscaleX, const bool autoscaleY) { 175 | autoscaleCheckboxX->setChecked(autoscaleX); 176 | autoscaleCheckboxY->setChecked(autoscaleY); 177 | }); 178 | 179 | connect(logScaleCheckBox, &QCheckBox::stateChanged, chart, &Chart::setLogarithmic); 180 | connect(autoscaleCheckboxX, &QCheckBox::stateChanged, chart, &Chart::setAutoscaleX); 181 | connect(autoscaleCheckboxY, &QCheckBox::stateChanged, chart, &Chart::setAutoscaleY); 182 | 183 | connect(menuHelp, &QAction::triggered, this, [this]() { 184 | const auto helpString{ u"License:\n"_s 185 | u"qUART is licensed under GPL-3.0\n"_s 186 | u"Qt 6 is licensed under LGPL-3.0\n"_s 187 | u"QCustomPlot is licensed under GPL-3.0\n"_s 188 | u"Material Symbols are licensed under Apache-2.0\n\n"_s 189 | u"GitHub:\n"_s 190 | u"https://github.com/ilya-sotnikov/qUART"_s }; 191 | QMessageBox::information(this, u"Help"_s, helpString); 192 | }); 193 | } 194 | 195 | /** 196 | * @brief Connects to the serial port with specified parameters from PortSettingsDialog 197 | * 198 | * Additionally, it disables several actions which shouldn't be executed while 199 | * new data is received. If failed to connect, pop up a message box with an 200 | * error. 201 | * 202 | */ 203 | void MainWindow::serialConnect() 204 | { 205 | const auto &serialSettings{ portSettingsDialog->getSettings() }; 206 | const auto dataSettings{ dataSettingsDialog->getSettings() }; 207 | serialTransceiver->setDataType(dataSettings.dataType); 208 | serialTransceiver->setByteOrder(dataSettings.byteOrder); 209 | serialTransceiver->setPortName(serialSettings.name); 210 | serialTransceiver->setBaudRate(serialSettings.baudRate); 211 | serialTransceiver->setDataBits(serialSettings.dataBits); 212 | serialTransceiver->setParity(serialSettings.parity); 213 | serialTransceiver->setStopBits(serialSettings.stopBits); 214 | serialTransceiver->setFlowControl(serialSettings.flowControl); 215 | if (serialTransceiver->serialOpen()) { 216 | actionConnect->setEnabled(false); 217 | actionDisconnect->setEnabled(true); 218 | actionPortSettings->setEnabled(false); 219 | actionDataSettings->setEnabled(false); 220 | actionOpenPlot->setEnabled(false); 221 | actionSavePlot->setEnabled(false); 222 | actionOpenSpectrum->setEnabled(false); 223 | actionSaveSpectrum->setEnabled(false); 224 | actionSaveImage->setEnabled(false); 225 | sendNumLineEdit->setEnabled(true); 226 | sendSignedCheckBox->setEnabled(true); 227 | sendStringLineEdit->setEnabled(true); 228 | sendStringNewlineCheckBox->setEnabled(true); 229 | } else { 230 | QMessageBox::warning(this, u"Warning"_s, serialTransceiver->errorString()); 231 | } 232 | } 233 | 234 | /** 235 | * @brief Disconnects from the serial port 236 | * 237 | * Additionally, it reenables several actions which are safe to execute 238 | * while the serial port is disconnected. 239 | * 240 | */ 241 | void MainWindow::serialDisconnect() const 242 | { 243 | serialTransceiver->serialClose(); 244 | actionConnect->setEnabled(true); 245 | actionDisconnect->setEnabled(false); 246 | actionPortSettings->setEnabled(true); 247 | actionDataSettings->setEnabled(true); 248 | actionOpenPlot->setEnabled(true); 249 | actionSavePlot->setEnabled(true); 250 | actionOpenSpectrum->setEnabled(true); 251 | actionSaveSpectrum->setEnabled(true); 252 | actionSaveImage->setEnabled(true); 253 | sendNumLineEdit->setEnabled(false); 254 | sendSignedCheckBox->setEnabled(false); 255 | sendStringLineEdit->setEnabled(false); 256 | sendStringNewlineCheckBox->setEnabled(false); 257 | } 258 | 259 | /** 260 | * @brief Saves the chart to an png image 261 | * 262 | */ 263 | void MainWindow::saveImage() 264 | { 265 | auto fileName{ createFileDialog(QFileDialog::AcceptSave, u"Images (*.png)"_s, u"png"_s) }; 266 | if (fileName.isEmpty()) 267 | return; 268 | QPixmap pixMap{ chart->grab() }; 269 | pixMap.save(fileName, "PNG"); 270 | } 271 | 272 | /** 273 | * @brief A helper function to create a file dialog with specified parameters 274 | * 275 | * This function can be used to create an open dialog or save dialog 276 | * with the file extension filter and default file suffix. 277 | * 278 | * @param acceptMode 279 | * @param nameFilter 280 | * @param defaultSuffix 281 | * @return QString The selected file name or empty string if none was selected 282 | 283 | */ 284 | QString MainWindow::createFileDialog(QFileDialog::AcceptMode acceptMode, const QString &nameFilter, 285 | const QString &defaultSuffix) 286 | { 287 | QFileDialog fileDialog{ this }; 288 | fileDialog.setAcceptMode(acceptMode); 289 | fileDialog.setNameFilter(nameFilter); 290 | fileDialog.setDefaultSuffix(defaultSuffix); 291 | if (!fileDialog.exec() || fileDialog.selectedFiles().isEmpty()) 292 | return u""_s; 293 | else 294 | return fileDialog.selectedFiles().at(0); 295 | } 296 | 297 | /** 298 | * @brief A helper function to open a file and create a QTextStream on it 299 | * 300 | * It uses a custom deleter which deletes the attached file when the stream is deleted 301 | * 302 | * @param fileName 303 | * @param fileFlags 304 | * @return std::unique_ptr to QTextStream or nullptr if can't open a file 305 | */ 306 | std::unique_ptr> 307 | MainWindow::openFileStream(const QString &fileName, QIODevice::OpenMode fileFlags) 308 | { 309 | const auto file{ new QFile{ fileName } }; 310 | const auto fileDeleter{ [file](QTextStream *stream) { 311 | delete stream; 312 | file->deleteLater(); 313 | } }; 314 | if (!file->open(fileFlags)) { 315 | QMessageBox::warning(this, u"Warning"_s, file->errorString()); 316 | file->deleteLater(); 317 | return { nullptr }; 318 | } else { 319 | return { new QTextStream{ file }, fileDeleter }; 320 | } 321 | } 322 | 323 | /** 324 | * @brief Saves data from the chart to a text file 325 | * 326 | * Saved data depends on the current chart type (chart or spectrum). 327 | * 328 | */ 329 | void MainWindow::savePlotData() 330 | { 331 | const auto fileName{ createFileDialog(QFileDialog::AcceptSave, u"Text files (*.txt)"_s, 332 | u"txt"_s) }; 333 | if (fileName.isEmpty()) 334 | return; 335 | 336 | auto stream{ openFileStream(fileName, QIODevice::WriteOnly | QIODevice::Text) }; 337 | if (stream.get() == nullptr) 338 | return; 339 | 340 | const auto dataList{ chart->getPlotData() }; 341 | for (const auto &data : *dataList) 342 | *stream << QString::number(data.mainValue()) << u"\n"_s; 343 | } 344 | 345 | void MainWindow::saveSpectrumData() 346 | { 347 | const auto fileName{ createFileDialog(QFileDialog::AcceptSave, u"Text files (*.txt)"_s, 348 | u"txt"_s) }; 349 | if (fileName.isEmpty()) 350 | return; 351 | 352 | auto stream{ openFileStream(fileName, QIODevice::WriteOnly | QIODevice::Text) }; 353 | if (stream.get() == nullptr) 354 | return; 355 | 356 | const auto dataList{ chart->getSpectrumData() }; 357 | const auto dataEnd{ dataList->constEnd() }; 358 | for (auto it{ dataList->constBegin() }; it != dataEnd; ++it) 359 | *stream << QString::number(it->mainKey()) << u" "_s << QString::number(it->mainValue()) 360 | << u"\n"_s; 361 | } 362 | 363 | /** 364 | * @brief Opens the text file and displays plot data from it 365 | * 366 | */ 367 | void MainWindow::openPlotData() 368 | { 369 | const auto fileName{ createFileDialog(QFileDialog::AcceptOpen, u"Text files (*.txt)"_s, 370 | u"txt"_s) }; 371 | if (fileName.isEmpty()) 372 | return; 373 | 374 | auto stream{ openFileStream(fileName, QIODevice::ReadOnly | QIODevice::Text) }; 375 | if (stream.get() == nullptr) 376 | return; 377 | 378 | chart->clear(); 379 | const auto dataList{ QSharedPointer>::create() }; 380 | bool ok; 381 | qreal num; 382 | const auto warningMsg{ u"Can't read plot data at line "_s }; 383 | quint64 lineCount{ 0 }; 384 | while (!stream->atEnd()) { 385 | num = stream->readLine().toDouble(&ok); 386 | if (!ok) { 387 | QMessageBox::warning(this, u"Warning"_s, warningMsg + QString::number(lineCount)); 388 | return; 389 | } 390 | 391 | dataList->append(num); 392 | 393 | ++lineCount; 394 | } 395 | chart->addData(dataList); 396 | } 397 | 398 | /** 399 | * @brief Opens the text file and displays spectrum data from it 400 | * 401 | */ 402 | void MainWindow::openSpectrumData() 403 | { 404 | const auto fileName{ createFileDialog(QFileDialog::AcceptOpen, u"Text files (*.txt)"_s, 405 | u"txt"_s) }; 406 | if (fileName.isEmpty()) 407 | return; 408 | 409 | auto stream{ openFileStream(fileName, QIODevice::ReadOnly | QIODevice::Text) }; 410 | if (stream.get() == nullptr) 411 | return; 412 | 413 | chart->clear(); 414 | QCPGraphDataContainer data; 415 | QStringList xy; 416 | qreal x; 417 | qreal y; 418 | bool ok; 419 | quint64 lineNumber{ 0 }; 420 | const auto warningMsg{ u"Can't read spectrum data at line "_s }; 421 | while (!stream->atEnd()) { 422 | xy = stream->readLine().split(QRegularExpression{ u"\\s+"_s }, Qt::SkipEmptyParts); 423 | if (xy.empty() || (xy.size() < 2)) { 424 | QMessageBox::warning(this, u"Warning"_s, warningMsg + QString::number(lineNumber)); 425 | return; 426 | } 427 | 428 | x = xy.at(0).toDouble(&ok); 429 | if (!ok) { 430 | QMessageBox::warning(this, u"Warning"_s, warningMsg + QString::number(lineNumber)); 431 | return; 432 | } 433 | 434 | y = xy.at(1).toDouble(&ok); 435 | if (!ok) { 436 | QMessageBox::warning(this, u"Warning"_s, warningMsg + QString::number(lineNumber)); 437 | return; 438 | } 439 | 440 | data.add(QCPGraphData{ x, y }); 441 | 442 | ++lineNumber; 443 | } 444 | chart->setRawSpectrumData(data); 445 | } 446 | 447 | /** 448 | * @brief Updates the status bar chart type indicator (plot or spectrum) 449 | * 450 | */ 451 | void MainWindow::chartTypeChanged() const 452 | { 453 | const auto chartType{ chart->getChartType() }; 454 | if (chartType == Chart::ChartType::plot) 455 | chartTypeWidget->setText(u"Chart type: Plot"_s); 456 | else if (chartType == Chart::ChartType::spectrum) 457 | chartTypeWidget->setText(u"Chart type: Spectrum"_s); 458 | } 459 | 460 | /** 461 | * @brief Updates the message in the status bar with the selected point 462 | * 463 | * @param point 464 | */ 465 | void MainWindow::updateSelectedPoint(const QPointF point) const 466 | { 467 | QString msg{ u"x: "_s }; 468 | msg += QString::number(point.x()); 469 | msg += u" y: "_s; 470 | msg += QString::number(point.y()); 471 | statusBar->showMessage(msg); 472 | } 473 | -------------------------------------------------------------------------------- /src/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include "chart.h" 5 | #include "datasettingsdialog.h" 6 | #include "portsettingsdialog.h" 7 | #include "serialtransceiver.h" 8 | #include "textwidget.h" 9 | #include "customaction.h" 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | class MainWindow : public QMainWindow 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | explicit MainWindow(QWidget *parent = nullptr); 21 | 22 | private: 23 | Chart *chart{ new Chart{ this } }; 24 | PortSettingsDialog *portSettingsDialog{ new PortSettingsDialog{ this } }; 25 | DataSettingsDialog *dataSettingsDialog{ new DataSettingsDialog{ this } }; 26 | SerialTransceiver *serialTransceiver{ new SerialTransceiver{ this } }; 27 | TextWidget *chartTypeWidget{ new TextWidget{ this } }; 28 | QStatusBar *statusBar{ new QStatusBar{ this } }; 29 | 30 | CustomAction *actionConnect{ new CustomAction{ "Connect", this } }; 31 | CustomAction *actionDisconnect{ new CustomAction{ "Disconnect", this } }; 32 | CustomAction *actionPortSettings{ new CustomAction{ "Port", this } }; 33 | CustomAction *actionClear{ new CustomAction{ "Clear", this } }; 34 | CustomAction *actionSaveImage{ new CustomAction{ "Save Image", this } }; 35 | CustomAction *actionSavePlot{ new CustomAction{ "Save Plot", this } }; 36 | CustomAction *actionOpenPlot{ new CustomAction{ "Open Plot", this } }; 37 | CustomAction *actionSaveSpectrum{ new CustomAction{ "Save Spectrum", this } }; 38 | CustomAction *actionOpenSpectrum{ new CustomAction{ "Open Spectrum", this } }; 39 | CustomAction *actionDataSettings{ new CustomAction{ "Data", this } }; 40 | CustomAction *actionChartType{ new CustomAction{ "Chart type", this } }; 41 | CustomAction *actionResetZoom{ new CustomAction{ "Reset zoom", this } }; 42 | CustomAction *actionAppendToPlot{ new CustomAction{ "Append to plot", this } }; 43 | CustomAction *actionAppendToSpectrum{ new CustomAction{ "Append to spectrum", this } }; 44 | QLineEdit *sendNumLineEdit{ new QLineEdit{ this } }; 45 | QCheckBox *sendSignedCheckBox{ new QCheckBox{ "Signed" } }; 46 | QLineEdit *sendStringLineEdit{ new QLineEdit{ this } }; 47 | QCheckBox *sendStringNewlineCheckBox{ new QCheckBox{ "Newline" } }; 48 | QLineEdit *updateIntervalLineEdit{ new QLineEdit{ QString::number(chart->getUpdateInterval()), 49 | this } }; 50 | QCheckBox *logScaleCheckBox{ new QCheckBox{ "Log scale" } }; 51 | QCheckBox *autoscaleCheckboxX{ new QCheckBox{ "X" } }; 52 | QCheckBox *autoscaleCheckboxY{ new QCheckBox{ "Y" } }; 53 | 54 | QString createFileDialog(const QFileDialog::AcceptMode acceptMode, const QString &nameFilter, 55 | const QString &defaultSuffix); 56 | std::unique_ptr> 57 | openFileStream(const QString &fileName, QIODevice::OpenMode flags); 58 | 59 | private slots: 60 | void serialConnect(); 61 | void serialDisconnect() const; 62 | void saveImage(); 63 | void savePlotData(); 64 | void openPlotData(); 65 | void saveSpectrumData(); 66 | void openSpectrumData(); 67 | void chartTypeChanged() const; 68 | void updateSelectedPoint(const QPointF point) const; 69 | }; 70 | #endif // MAINWINDOW_H 71 | -------------------------------------------------------------------------------- /src/portsettingsdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "portsettingsdialog.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace Qt::Literals::StringLiterals; 12 | 13 | PortSettingsDialog::PortSettingsDialog(QWidget *parent) : QDialog{ parent } 14 | { 15 | const auto layout{ new QVBoxLayout{ this } }; 16 | const auto buttonBox{ new QDialogButtonBox{ QDialogButtonBox::Cancel | QDialogButtonBox::Ok, 17 | Qt::Horizontal, this } }; 18 | 19 | const auto settingsBox{ new QGroupBox{ u"Serial port configuration"_s } }; 20 | 21 | const auto settingsLayout{ new QGridLayout{ settingsBox } }; 22 | 23 | const auto portsInfoLabel{ new QLabel{ u"Ports info"_s } }; 24 | settingsLayout->addWidget(portsInfoLabel, 0, 0); 25 | const auto portsInfoButton{ new QPushButton{ u"Show"_s } }; 26 | settingsLayout->addWidget(portsInfoButton, 0, 1); 27 | 28 | const auto serialPortLabel{ new QLabel{ u"Serial port"_s } }; 29 | settingsLayout->addWidget(serialPortLabel, 1, 0); 30 | settingsLayout->addWidget(serialPortBox, 1, 1); 31 | 32 | const auto baudRateLabel{ new QLabel{ u"Baud rate"_s } }; 33 | settingsLayout->addWidget(baudRateLabel, 2, 0); 34 | settingsLayout->addWidget(baudRateBox, 2, 1); 35 | 36 | const auto dataBitsLabel{ new QLabel{ u"Data bits"_s } }; 37 | settingsLayout->addWidget(dataBitsLabel, 3, 0); 38 | settingsLayout->addWidget(dataBitsBox, 3, 1); 39 | 40 | const auto parityLabel{ new QLabel{ u"Parity"_s } }; 41 | settingsLayout->addWidget(parityLabel, 4, 0); 42 | settingsLayout->addWidget(parityBox, 4, 1); 43 | 44 | const auto stopBitsLabel{ new QLabel{ u"Stop bits"_s } }; 45 | settingsLayout->addWidget(stopBitsLabel, 5, 0); 46 | settingsLayout->addWidget(stopBitsBox, 5, 1); 47 | 48 | const auto flowControlLabel{ new QLabel{ u"Flow control"_s } }; 49 | settingsLayout->addWidget(flowControlLabel, 6, 0); 50 | settingsLayout->addWidget(flowControlBox, 6, 1); 51 | 52 | layout->addWidget(settingsBox, 0, Qt::AlignTop); 53 | layout->addWidget(buttonBox, 0, Qt::AlignBottom); 54 | 55 | setWindowTitle(u"Port settings"_s); 56 | setModal(true); 57 | 58 | connect(portsInfoButton, &QPushButton::pressed, portsInfoDialog, &PortsInfoDialog::show); 59 | connect(buttonBox, &QDialogButtonBox::accepted, this, &PortSettingsDialog::ok); 60 | connect(buttonBox, &QDialogButtonBox::rejected, this, &PortSettingsDialog::cancel); 61 | connect(serialPortBox, &QComboBox::currentIndexChanged, this, 62 | &PortSettingsDialog::checkCustomPath); 63 | enumeratePorts(); 64 | fillSettings(); 65 | loadSettings(); 66 | } 67 | 68 | /** 69 | * @brief Fills PortSettingsDialog settings 70 | * 71 | */ 72 | void PortSettingsDialog::fillSettings() const 73 | { 74 | baudRateBox->addItem(u"1200"_s, QSerialPort::Baud1200); 75 | baudRateBox->addItem(u"2400"_s, QSerialPort::Baud2400); 76 | baudRateBox->addItem(u"4800"_s, QSerialPort::Baud4800); 77 | baudRateBox->addItem(u"9600"_s, QSerialPort::Baud9600); 78 | baudRateBox->addItem(u"19200"_s, QSerialPort::Baud19200); 79 | baudRateBox->addItem(u"38400"_s, QSerialPort::Baud38400); 80 | baudRateBox->addItem(u"57600"_s, QSerialPort::Baud57600); 81 | baudRateBox->addItem(u"115200"_s, QSerialPort::Baud115200); 82 | 83 | dataBitsBox->addItem(u"5"_s, QSerialPort::Data5); 84 | dataBitsBox->addItem(u"6"_s, QSerialPort::Data6); 85 | dataBitsBox->addItem(u"7"_s, QSerialPort::Data7); 86 | dataBitsBox->addItem(u"8"_s, QSerialPort::Data8); 87 | 88 | parityBox->addItem(u"None"_s, QSerialPort::NoParity); 89 | parityBox->addItem(u"Even"_s, QSerialPort::EvenParity); 90 | parityBox->addItem(u"Odd"_s, QSerialPort::OddParity); 91 | parityBox->addItem(u"Mark"_s, QSerialPort::MarkParity); 92 | parityBox->addItem(u"Space"_s, QSerialPort::SpaceParity); 93 | 94 | stopBitsBox->addItem(u"1"_s, QSerialPort::OneStop); 95 | #ifdef Q_OS_WIN 96 | stopBitsBox->addItem(u"1.5"_s, QSerialPort::OneAndHalfStop); 97 | #endif 98 | stopBitsBox->addItem(u"2"_s, QSerialPort::TwoStop); 99 | 100 | flowControlBox->addItem(u"None"_s, QSerialPort::NoFlowControl); 101 | flowControlBox->addItem(u"RTS/CTS"_s, QSerialPort::HardwareControl); 102 | flowControlBox->addItem(u"XON/XOFF"_s, QSerialPort::SoftwareControl); 103 | } 104 | 105 | /** 106 | * @brief Enumerates available serial ports 107 | * 108 | * Note that if you connect a new serial port you must restart the program. 109 | * 110 | */ 111 | void PortSettingsDialog::enumeratePorts() const 112 | { 113 | serialPortBox->clear(); 114 | const auto ports{ QSerialPortInfo::availablePorts() }; 115 | for (const auto &port : ports) { 116 | serialPortBox->addItem(port.portName(), port.portName()); 117 | } 118 | serialPortBox->addItem(u"Custom"_s); 119 | } 120 | 121 | /** 122 | * @brief Allows to type in a custom serial port name 123 | * 124 | * @param index An index to check 125 | */ 126 | void PortSettingsDialog::checkCustomPath(const int index) const 127 | { 128 | const auto isCustomPath{ serialPortBox->itemData(index).isNull() }; 129 | serialPortBox->setEditable(isCustomPath); 130 | if (isCustomPath) 131 | serialPortBox->clearEditText(); 132 | } 133 | 134 | /** 135 | * @brief Updates the current settings according to the selected settings 136 | * 137 | */ 138 | void PortSettingsDialog::updateSettings() 139 | { 140 | settings.name = serialPortBox->currentText(); 141 | settings.baudRate = baudRateBox->currentData().value(); 142 | settings.dataBits = dataBitsBox->currentData().value(); 143 | settings.parity = parityBox->currentData().value(); 144 | settings.stopBits = stopBitsBox->currentData().value(); 145 | settings.flowControl = flowControlBox->currentData().value(); 146 | } 147 | 148 | /** 149 | * @brief Updates the combo box current index according to the data 150 | * 151 | */ 152 | template 153 | void PortSettingsDialog::updateIndex(QComboBox *const comboBox, const T data) const 154 | { 155 | const auto index{ comboBox->findData(data) }; 156 | if (index != -1) 157 | comboBox->setCurrentIndex(index); 158 | } 159 | 160 | /** 161 | * @brief Updates indexes of all combo boxes 162 | * 163 | */ 164 | void PortSettingsDialog::updateIndexes() const 165 | { 166 | const auto portNameIndex{ serialPortBox->findData(settings.name) }; 167 | if (portNameIndex == -1) { 168 | serialPortBox->setEditable(true); 169 | serialPortBox->setEditText(settings.name); 170 | } else { 171 | serialPortBox->setCurrentIndex(portNameIndex); 172 | } 173 | 174 | updateIndex(baudRateBox, settings.baudRate); 175 | updateIndex(dataBitsBox, settings.dataBits); 176 | updateIndex(parityBox, settings.parity); 177 | updateIndex(stopBitsBox, settings.stopBits); 178 | updateIndex(flowControlBox, settings.flowControl); 179 | } 180 | 181 | /** 182 | * @brief Loads settings from a file 183 | * 184 | */ 185 | void PortSettingsDialog::loadSettings() 186 | { 187 | QSettings settingsFile; 188 | 189 | settingsFile.beginGroup(u"port"_s); 190 | 191 | settings.name = settingsFile.value(u"name"_s, u""_s).toString(); 192 | settings.baudRate = static_cast( 193 | settingsFile.value(u"baudRate"_s, u"9600"_s).toInt()); 194 | settings.dataBits = 195 | static_cast(settingsFile.value(u"dataBits"_s, u"8"_s).toInt()); 196 | settings.parity = 197 | static_cast(settingsFile.value(u"parity"_s, u"0"_s).toInt()); 198 | settings.stopBits = 199 | static_cast(settingsFile.value(u"stopBits"_s, u"1"_s).toInt()); 200 | settings.flowControl = static_cast( 201 | settingsFile.value(u"flowControl"_s, u"0"_s).toInt()); 202 | 203 | settingsFile.endGroup(); 204 | } 205 | 206 | /** 207 | * @brief Saves serial port settings to a file 208 | * 209 | */ 210 | void PortSettingsDialog::saveSettings() const 211 | { 212 | QSettings settingsFile; 213 | 214 | settingsFile.beginGroup(u"port"_s); 215 | settingsFile.setValue(u"name"_s, settings.name); 216 | settingsFile.setValue(u"baudRate"_s, settings.baudRate); 217 | settingsFile.setValue(u"dataBits"_s, settings.dataBits); 218 | settingsFile.setValue(u"parity"_s, settings.parity); 219 | settingsFile.setValue(u"stopBits"_s, settings.stopBits); 220 | settingsFile.setValue(u"flowControl"_s, settings.flowControl); 221 | settingsFile.endGroup(); 222 | } 223 | 224 | /** 225 | * @brief Updates the current settings, saves them to a file and hides PortSettingsDialog 226 | * 227 | */ 228 | void PortSettingsDialog::ok() 229 | { 230 | updateSettings(); 231 | saveSettings(); 232 | hide(); 233 | } 234 | 235 | /** 236 | * @brief Hides PortSettingsDialog without updating the current settings 237 | * 238 | */ 239 | void PortSettingsDialog::cancel() 240 | { 241 | hide(); 242 | } 243 | -------------------------------------------------------------------------------- /src/portsettingsdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTSETTINGSDIALOG_H 2 | #define PORTSETTINGSDIALOG_H 3 | 4 | #include "portsinfodialog.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | class PortSettingsDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit PortSettingsDialog(QWidget *parent = nullptr); 16 | 17 | struct Settings 18 | { 19 | QString name; 20 | QSerialPort::BaudRate baudRate; 21 | QSerialPort::DataBits dataBits; 22 | QSerialPort::Parity parity; 23 | QSerialPort::StopBits stopBits; 24 | QSerialPort::FlowControl flowControl; 25 | }; 26 | const auto &getSettings() const { return settings; }; 27 | 28 | public slots: 29 | void showDialog() 30 | { 31 | updateIndexes(); 32 | show(); 33 | } 34 | 35 | private: 36 | PortsInfoDialog *portsInfoDialog{ new PortsInfoDialog{ this } }; 37 | Settings settings; 38 | QComboBox *serialPortBox{ new QComboBox{ this } }; 39 | QComboBox *baudRateBox{ new QComboBox{ this } }; 40 | QComboBox *dataBitsBox{ new QComboBox{ this } }; 41 | QComboBox *parityBox{ new QComboBox{ this } }; 42 | QComboBox *stopBitsBox{ new QComboBox{ this } }; 43 | QComboBox *flowControlBox{ new QComboBox{ this } }; 44 | 45 | void fillSettings() const; 46 | void enumeratePorts() const; 47 | void checkCustomPath(const int index) const; 48 | void updateSettings(); 49 | void loadSettings(); 50 | void saveSettings() const; 51 | template 52 | void updateIndex(QComboBox *const comboBox, const T data) const; 53 | void updateIndexes() const; 54 | 55 | private slots: 56 | void ok(); 57 | void cancel(); 58 | }; 59 | 60 | #endif // PORTSETTINGSDIALOG_H 61 | -------------------------------------------------------------------------------- /src/portsinfodialog.cpp: -------------------------------------------------------------------------------- 1 | #include "portsinfodialog.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | using namespace Qt::Literals::StringLiterals; 9 | 10 | PortsInfoDialog::PortsInfoDialog(QWidget *parent) : QDialog{ parent } 11 | { 12 | const auto scroll{ new QScrollArea{ this } }; 13 | const auto widget{ new QWidget{ this } }; 14 | scroll->setWidget(widget); 15 | scroll->setWidgetResizable(true); 16 | const auto layout{ new QVBoxLayout{ widget } }; 17 | 18 | const auto portsInfo{ QSerialPortInfo::availablePorts() }; 19 | for (const auto &info : portsInfo) { 20 | const QString infoStr{ 21 | u"Port: "_s + info.portName() + u"\n"_s + u"Location: "_s + info.systemLocation() 22 | + u"\n"_s + u"Manufacturer: "_s + info.manufacturer() + u"\n"_s + u"Serial number: "_s 23 | + info.serialNumber() + u"\n"_s + u"Vendor identifier: "_s 24 | + (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : u""_s) 25 | + u"\n"_s + u"Product identifier: "_s 26 | + (info.hasProductIdentifier() ? QString::number(info.productIdentifier(), 16) : u""_s) 27 | + u"\n"_s 28 | }; 29 | const auto label{ new QLabel{ infoStr, this } }; 30 | layout->addWidget(label); 31 | } 32 | 33 | const auto dialogLayout{ new QVBoxLayout{ this } }; 34 | dialogLayout->addWidget(scroll); 35 | setWindowTitle(u"Ports info"_s); 36 | } 37 | -------------------------------------------------------------------------------- /src/portsinfodialog.h: -------------------------------------------------------------------------------- 1 | #ifndef PORTSINFODIALOG_H 2 | #define PORTSINFODIALOG_H 3 | 4 | #include 5 | 6 | /** 7 | * @brief A dialog with information about all available serial ports 8 | * 9 | */ 10 | class PortsInfoDialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | explicit PortsInfoDialog(QWidget *parent = nullptr); 16 | }; 17 | 18 | #endif // PORTSINFODIALOG_H 19 | -------------------------------------------------------------------------------- /src/serialtransceiver.cpp: -------------------------------------------------------------------------------- 1 | #include "serialtransceiver.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace Qt::Literals::StringLiterals; 7 | 8 | template 9 | static constexpr auto CanTypeFitValue(const U value); 10 | 11 | template 12 | static void writeSmallestToByteArray(QByteArray &byteArray, const T num, 13 | const QDataStream::ByteOrder byteOrder); 14 | 15 | SerialTransceiver::SerialTransceiver(QObject *parent) : QObject{ parent } 16 | { 17 | connect(serialPort, &QSerialPort::readyRead, this, &SerialTransceiver::receiveData); 18 | } 19 | 20 | /** 21 | * @brief Opens the serial port and returns connection status (bool) 22 | * 23 | * @return A connection status 24 | * 25 | */ 26 | bool SerialTransceiver::serialOpen() 27 | { 28 | const bool isOpen{ serialPort->open(QIODevice::ReadWrite) }; 29 | 30 | if (isOpen) { 31 | serialPort->clear(); 32 | bufferArray.clear(); 33 | } 34 | 35 | return isOpen; 36 | } 37 | 38 | /** 39 | * @brief Closes the serial port 40 | * 41 | */ 42 | void SerialTransceiver::serialClose() 43 | { 44 | if (serialPort->isOpen()) 45 | serialPort->close(); 46 | bufferArray.clear(); 47 | } 48 | 49 | // #define BUG_0xff 50 | 51 | /** 52 | * @brief Deserializes byte array according to the current data type 53 | * 54 | * On my previous Linux machine (both Arch and Debian) there was a nasty bug. 55 | * If a serial port has received 0xff, it always had a duplicate next to it. 56 | * I've tried multiple port settings, virtual serial ports, the bug was still 57 | * there. Can't reproduce it on Windows but decided to leave a hacky solution. 58 | * I don't know if it's a bug in Qt. 59 | * If you have this problem, uncomment BUG_0xff above 60 | * 61 | * @tparam T A data type to deserialize 62 | * @param byteArray An array with raw data 63 | * @param dataList A data list to append to 64 | * 65 | */ 66 | template 67 | void SerialTransceiver::deserializeByteArray(QByteArray &byteArray, QList &dataList) 68 | { 69 | #ifdef BUG_0xff 70 | for (qsizetype i = 0; i < byteArray->size(); ++i) { 71 | if (byteArray->at(i) == static_cast(0xff)) 72 | byteArray->remove(i++, 1); 73 | } 74 | #endif 75 | 76 | byteArray.append(bufferArray); 77 | bufferArray.clear(); 78 | 79 | qsizetype byteArraySize{ byteArray.size() }; 80 | const quint8 byteCnt{ static_cast(byteArraySize % sizeof(T)) }; 81 | 82 | bufferArray = byteArray.last(byteCnt); 83 | byteArray.chop(byteCnt); 84 | 85 | T data; 86 | QDataStream dataStream{ &byteArray, QIODevice::ReadOnly }; 87 | 88 | // since data is received in reverse order 89 | if (byteOrder == QDataStream::LittleEndian) 90 | dataStream.setByteOrder(QDataStream::BigEndian); 91 | else 92 | dataStream.setByteOrder(QDataStream::LittleEndian); 93 | 94 | if (dataType == DataTypes::f32) 95 | dataStream.setFloatingPointPrecision(QDataStream::SinglePrecision); 96 | while (!dataStream.atEnd()) { 97 | dataStream >> data; 98 | dataList.append(data); 99 | } 100 | } 101 | 102 | /** 103 | * @brief Receives data according to the current data type 104 | * 105 | * The received data is deserialized according to the current 106 | * dataType and the newDataAvailable signal is emitted 107 | * 108 | */ 109 | void SerialTransceiver::receiveData() 110 | { 111 | auto byteArray{ serialPort->readAll() }; 112 | 113 | QList dataList; 114 | 115 | switch (dataType) { 116 | case DataTypes::u8: 117 | deserializeByteArray(byteArray, dataList); 118 | break; 119 | case DataTypes::u16: 120 | deserializeByteArray(byteArray, dataList); 121 | break; 122 | case DataTypes::u32: 123 | deserializeByteArray(byteArray, dataList); 124 | break; 125 | case DataTypes::u64: 126 | deserializeByteArray(byteArray, dataList); 127 | break; 128 | case DataTypes::i8: 129 | deserializeByteArray(byteArray, dataList); 130 | break; 131 | case DataTypes::i16: 132 | deserializeByteArray(byteArray, dataList); 133 | break; 134 | case DataTypes::i32: 135 | deserializeByteArray(byteArray, dataList); 136 | break; 137 | case DataTypes::i64: 138 | deserializeByteArray(byteArray, dataList); 139 | break; 140 | case DataTypes::f32: 141 | deserializeByteArray(byteArray, dataList); 142 | break; 143 | case DataTypes::f64: 144 | deserializeByteArray(byteArray, dataList); 145 | break; 146 | case DataTypes::ascii: { 147 | auto containsSeparator{ false }; 148 | 149 | byteArray.prepend(bufferArray); 150 | bufferArray.clear(); 151 | 152 | for (const auto byte : qAsConst(byteArray)) { 153 | if (QChar::isSpace(byte)) { 154 | containsSeparator = true; 155 | break; 156 | } 157 | } 158 | if (!containsSeparator) 159 | bufferArray.prepend(byteArray); 160 | else { 161 | double num; 162 | bool ok; 163 | if (!QChar::isSpace(byteArray.back())) { 164 | for (auto i{ byteArray.size() - 1 }; i > 0; --i) { 165 | if (QChar::isSpace(byteArray.at(i))) { 166 | bufferArray.prepend(byteArray.last(byteArray.size() - i)); 167 | byteArray.truncate(i); 168 | } 169 | } 170 | } 171 | const auto stringList{ QString{ byteArray }.split(QRegularExpression{ u"\\s+"_s }, 172 | Qt::SkipEmptyParts) }; 173 | for (const auto &str : stringList) { 174 | num = str.toDouble(&ok); 175 | if (ok) 176 | dataList.append(num); 177 | } 178 | } 179 | break; 180 | } 181 | } 182 | 183 | if (!dataList.isEmpty()) { 184 | const auto dataShared{ QSharedPointer>::create(dataList) }; 185 | emit newDataAvailable(dataShared); 186 | } 187 | } 188 | 189 | /** 190 | * @brief Checks if a type can fit a numeric value 191 | * 192 | * @tparam T A type 193 | * @tparam U A value's type 194 | * @param value A numeric value 195 | * @return True if can fit, otherwise false 196 | */ 197 | template 198 | static constexpr auto CanTypeFitValue(const U value) 199 | { 200 | return ((value > static_cast(0)) == (static_cast(value) > static_cast(0))) 201 | && (static_cast(static_cast(value)) == value); 202 | } 203 | 204 | /** 205 | * @brief Writes a number to the byteArray with the smallest possible type 206 | * 207 | * @tparam T A number's type 208 | * @param byteArray An array to write to 209 | * @param num A number 210 | * @param byteOrder Endianness (little-endian or big-endian) 211 | */ 212 | template 213 | static void writeSmallestToByteArray(QByteArray &byteArray, const T num, 214 | const QDataStream::ByteOrder byteOrder) 215 | { 216 | auto dataStream{ QDataStream{ &byteArray, QIODeviceBase::WriteOnly } }; 217 | dataStream.setByteOrder(byteOrder); 218 | 219 | if (std::is_signed_v) { 220 | if (CanTypeFitValue(num)) 221 | dataStream << static_cast(num); 222 | else if (CanTypeFitValue(num)) 223 | dataStream << static_cast(num); 224 | else if (CanTypeFitValue(num)) 225 | dataStream << static_cast(num); 226 | else 227 | dataStream << num; 228 | } else { 229 | if (CanTypeFitValue(num)) 230 | dataStream << static_cast(num); 231 | else if (CanTypeFitValue(num)) 232 | dataStream << static_cast(num); 233 | else if (CanTypeFitValue(num)) 234 | dataStream << static_cast(num); 235 | else 236 | dataStream << num; 237 | } 238 | } 239 | 240 | /** 241 | * @brief Writes a number to the serial port 242 | * 243 | * @param numString A string with a number 244 | * @param isSigned Whether the number is signed or not 245 | * @return The number of bytes that were written 246 | * 247 | */ 248 | qint64 SerialTransceiver::writeNumber(const QString &numString, bool isSigned) const 249 | { 250 | QByteArray byteArray; 251 | qint64 numSigned; 252 | quint64 numUnsigned; 253 | bool ok; 254 | 255 | if (isSigned) 256 | numSigned = numString.toLongLong(&ok, 0); 257 | else 258 | numUnsigned = numString.toULongLong(&ok, 0); 259 | 260 | if (ok) { 261 | if (isSigned) 262 | writeSmallestToByteArray(byteArray, numSigned, byteOrder); 263 | else 264 | writeSmallestToByteArray(byteArray, numUnsigned, byteOrder); 265 | 266 | return serialPort->write(byteArray); 267 | } else { 268 | return 0; 269 | } 270 | } 271 | 272 | /** 273 | * @brief Writes a string to the serial port 274 | * 275 | * @param string A string to be written 276 | * @param appendNewline Append a new line at the end of the string or not 277 | * @return The number of bytes that were written 278 | * 279 | */ 280 | qint64 SerialTransceiver::writeString(const QString &string, bool appendNewline) const 281 | { 282 | auto byteArray{ string.toUtf8() }; 283 | 284 | if (appendNewline) 285 | byteArray.append('\n'); 286 | 287 | return serialPort->write(byteArray); 288 | } 289 | -------------------------------------------------------------------------------- /src/serialtransceiver.h: -------------------------------------------------------------------------------- 1 | #ifndef SERIALTRANSCEIVER_H 2 | #define SERIALTRANSCEIVER_H 3 | 4 | #include 5 | 6 | class SerialTransceiver : public QObject 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | explicit SerialTransceiver(QObject *parent = nullptr); 12 | bool serialOpen(); 13 | void serialClose(); 14 | 15 | enum DataTypes { ascii, u8, u16, u32, u64, i8, i16, i32, i64, f32, f64 }; 16 | Q_ENUM(DataTypes) 17 | 18 | auto errorString() const { return serialPort->errorString(); }; 19 | auto setPortName(const QString &name) { return serialPort->setPortName(name); }; 20 | auto setDataBits(QSerialPort::DataBits dataBits) { return serialPort->setDataBits(dataBits); }; 21 | auto setParity(QSerialPort::Parity parity) { return serialPort->setParity(parity); }; 22 | auto setStopBits(QSerialPort::StopBits stopBits) { return serialPort->setStopBits(stopBits); } 23 | auto setFlowControl(QSerialPort::FlowControl flowControl) 24 | { 25 | return serialPort->setFlowControl(flowControl); 26 | }; 27 | auto setBaudRate(qint32 baudRate, 28 | QSerialPort::Directions directions = QSerialPort::AllDirections) 29 | { 30 | return serialPort->setBaudRate(baudRate, directions); 31 | }; 32 | void setDataType(DataTypes dataType) 33 | { 34 | bufferArray.clear(); 35 | this->dataType = dataType; 36 | } 37 | void setByteOrder(QDataStream::ByteOrder byteOrder) 38 | { 39 | bufferArray.clear(); 40 | this->byteOrder = byteOrder; 41 | } 42 | 43 | qint64 writeNumber(const QString &numString, bool isSigned) const; 44 | qint64 writeString(const QString &string, bool appendNewline) const; 45 | 46 | private: 47 | QSerialPort *serialPort{ new QSerialPort{ this } }; 48 | QByteArray bufferArray; 49 | DataTypes dataType{ DataTypes::ascii }; 50 | QDataStream::ByteOrder byteOrder{ QDataStream::LittleEndian }; 51 | 52 | template 53 | void deserializeByteArray(QByteArray &byteArray, QList &dataList); 54 | 55 | private slots: 56 | void receiveData(); 57 | 58 | signals: 59 | void newDataAvailable(const QSharedPointer> dataList); 60 | }; 61 | 62 | #endif // SERIALTRANSCEIVER_H 63 | -------------------------------------------------------------------------------- /src/textwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "textwidget.h" 2 | 3 | #include 4 | 5 | /** 6 | * @brief Constructs a new TextWidget object 7 | * 8 | * @param parent 9 | * @param text Text to be displayed in the status bar 10 | */ 11 | TextWidget::TextWidget(QWidget *parent, const QString &text) 12 | : QWidget{ parent }, label{ new QLabel{ text, this } } 13 | { 14 | const auto layout{ new QHBoxLayout{ this } }; 15 | layout->addWidget(label); 16 | } 17 | -------------------------------------------------------------------------------- /src/textwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef TEXTWIDGET_H 2 | #define TEXTWIDGET_H 3 | 4 | #include 5 | 6 | /** 7 | * @brief Text widget to display in the status bar 8 | * 9 | */ 10 | class TextWidget : public QWidget 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit TextWidget(QWidget *parent = nullptr, const QString &text = ""); 15 | void setText(const QString &text) const { label->setText(text); }; 16 | 17 | private: 18 | QLabel *label{ nullptr }; 19 | }; 20 | 21 | #endif // TEXTWIDGET_H 22 | -------------------------------------------------------------------------------- /src/themeinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef THEMEINFO_H 2 | #define THEMEINFO_H 3 | 4 | #include 5 | 6 | namespace ThemeInfo { 7 | 8 | inline auto windowColor() { return QPalette{}.color(QPalette::Window); } 9 | 10 | inline auto windowTextColor() { return QPalette{}.color(QPalette::WindowText); } 11 | 12 | inline bool isDarkTheme() { 13 | const QPalette defaultPalette; 14 | return defaultPalette.color(QPalette::WindowText).lightness() 15 | > defaultPalette.color(QPalette::Window).lightness(); 16 | } 17 | 18 | } // ThemeInfo 19 | 20 | #endif // THEMEINFO_H 21 | --------------------------------------------------------------------------------