##// END OF EJS Templates
Merge pull request 159 from SCIQLOP-Initialisation develop...
leroux -
r244:390cce0166be merge
parent child
Show More
This diff has been collapsed as it changes many lines, (674 lines changed) Show them Hide them
@@ -0,0 +1,674
1 GNU GENERAL PUBLIC LICENSE
2 Version 3, 29 June 2007
3
4 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
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 <one line to give the program's name and a brief idea of what it does.>
635 Copyright (C) <year> <name of author>
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 <http://www.gnu.org/licenses/>.
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 <program> Copyright (C) <year> <name of author>
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 <http://www.gnu.org/licenses/>.
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 <http://www.gnu.org/philosophy/why-not-lgpl.html>.
@@ -0,0 +1,33
1 #ifndef SCIQLOP_VARIABLECACHECONTROLLER_H
2 #define SCIQLOP_VARIABLECACHECONTROLLER_H
3
4 #include <QObject>
5
6 #include <Data/SqpDateTime.h>
7
8 #include <Common/spimpl.h>
9
10 class Variable;
11
12 /// This class aims to store in the cash all of the dateTime already requested to the variable.
13 class VariableCacheController : public QObject {
14 Q_OBJECT
15 public:
16 explicit VariableCacheController(QObject *parent = 0);
17
18
19 void addDateTime(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
20
21 /// Return all of the SqpDataTime part of the dateTime whose are not in the cache
22 QVector<SqpDateTime> provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
23 const SqpDateTime &dateTime);
24
25
26 QVector<SqpDateTime> dateCacheList(std::shared_ptr<Variable> variable) const noexcept;
27
28 private:
29 class VariableCacheControllerPrivate;
30 spimpl::unique_impl_ptr<VariableCacheControllerPrivate> impl;
31 };
32
33 #endif // SCIQLOP_VARIABLECACHECONTROLLER_H
@@ -0,0 +1,173
1 #include "Variable/VariableCacheController.h"
2
3 #include "Variable/Variable.h"
4 #include <unordered_map>
5
6 struct VariableCacheController::VariableCacheControllerPrivate {
7
8 std::unordered_map<std::shared_ptr<Variable>, QVector<SqpDateTime> >
9 m_VariableToSqpDateTimeListMap;
10
11 void addInCacheDataByEnd(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
12 QVector<SqpDateTime> &notInCache, int cacheIndex,
13 double currentTStart);
14
15 void addInCacheDataByStart(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
16 QVector<SqpDateTime> &notInCache, int cacheIndex,
17 double currentTStart);
18
19
20 void addDateTimeRecurse(const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
21 int cacheIndex);
22 };
23
24
25 VariableCacheController::VariableCacheController(QObject *parent)
26 : QObject(parent), impl{spimpl::make_unique_impl<VariableCacheControllerPrivate>()}
27 {
28 }
29
30 void VariableCacheController::addDateTime(std::shared_ptr<Variable> variable,
31 const SqpDateTime &dateTime)
32 {
33 if (variable) {
34 auto findVariableIte = impl->m_VariableToSqpDateTimeListMap.find(variable);
35 if (findVariableIte == impl->m_VariableToSqpDateTimeListMap.end()) {
36 impl->m_VariableToSqpDateTimeListMap[variable].push_back(dateTime);
37 }
38 else {
39
40 // addDateTime modify the list<SqpDateTime> of the variable in a way to ensure
41 // that the list is ordered : l(0) < l(1). We assume also a < b
42 // (with a & b of type SqpDateTime) means ts(b) > te(a)
43
44 // The algorithm will try the merge of two interval:
45 // - dateTime will be compare with the first interval of the list:
46 // A: if it is inferior, it will be inserted and it's finished.
47 // B: if it is in intersection, it will be merge then the merged one
48 // will be compared to the next interval. The old one is remove from the list
49 // C: if it is superior, we do the same with the next interval of the list
50
51 int cacheIndex = 0;
52 impl->addDateTimeRecurse(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable),
53 cacheIndex);
54 }
55 }
56 }
57
58 QVector<SqpDateTime>
59 VariableCacheController::provideNotInCacheDateTimeList(std::shared_ptr<Variable> variable,
60 const SqpDateTime &dateTime)
61 {
62 auto notInCache = QVector<SqpDateTime>{};
63
64 // This algorithm is recursif. The idea is to localise the start time then the end time in the
65 // list of date time request associated to the variable
66 // We assume that the list is ordered in a way that l(0) < l(1). We assume also a < b
67 // (with a & b of type SqpDateTime) means ts(b) > te(a)
68
69 impl->addInCacheDataByStart(dateTime, impl->m_VariableToSqpDateTimeListMap.at(variable),
70 notInCache, 0, dateTime.m_TStart);
71
72 return notInCache;
73 }
74
75 QVector<SqpDateTime>
76 VariableCacheController::dateCacheList(std::shared_ptr<Variable> variable) const noexcept
77 {
78 return impl->m_VariableToSqpDateTimeListMap.at(variable);
79 }
80
81 void VariableCacheController::VariableCacheControllerPrivate::addDateTimeRecurse(
82 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList, int cacheIndex)
83 {
84 const auto dateTimeListSize = dateTimeList.count();
85 if (cacheIndex >= dateTimeListSize) {
86 dateTimeList.push_back(dateTime);
87 // there is no anymore interval to compore, we can just push_back it
88 return;
89 }
90
91 auto currentDateTime = dateTimeList[cacheIndex];
92
93 if (dateTime.m_TEnd < currentDateTime.m_TStart) {
94 // The compared one is < to current one compared, we can insert it
95 dateTimeList.insert(cacheIndex, dateTime);
96 }
97
98 else if (dateTime.m_TStart > currentDateTime.m_TEnd) {
99 // The compared one is > to current one compared we can comparet if to the next one
100 addDateTimeRecurse(dateTime, dateTimeList, ++cacheIndex);
101 }
102 else {
103 // Merge cases: we need to merge the two interval, remove the old one from the list then
104 // rerun the algo from this index with the merged interval
105 auto mTStart = std::min(dateTime.m_TStart, currentDateTime.m_TStart);
106 auto mTEnd = std::max(dateTime.m_TEnd, currentDateTime.m_TEnd);
107 auto mergeDateTime = SqpDateTime{mTStart, mTEnd};
108
109 dateTimeList.remove(cacheIndex);
110 addDateTimeRecurse(mergeDateTime, dateTimeList, cacheIndex);
111 }
112 }
113
114
115 void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByEnd(
116 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
117 QVector<SqpDateTime> &notInCache, int cacheIndex, double currentTStart)
118 {
119 const auto dateTimeListSize = dateTimeList.count();
120 if (cacheIndex >= dateTimeListSize) {
121 if (currentTStart < dateTime.m_TEnd) {
122
123 // te localised after all other interval: The last interval is [currentTsart, te]
124 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
125 }
126 return;
127 }
128
129 auto currentDateTimeJ = dateTimeList[cacheIndex];
130 if (dateTime.m_TEnd <= currentDateTimeJ.m_TStart) {
131 // te localised between to interval: The last interval is [currentTsart, te]
132 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
133 }
134 else {
135 notInCache.push_back(SqpDateTime{currentTStart, currentDateTimeJ.m_TStart});
136 if (dateTime.m_TEnd > currentDateTimeJ.m_TEnd) {
137 // te not localised before the current interval: we need to look at the next interval
138 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, ++cacheIndex,
139 currentDateTimeJ.m_TEnd);
140 }
141 }
142 }
143
144 void VariableCacheController::VariableCacheControllerPrivate::addInCacheDataByStart(
145 const SqpDateTime &dateTime, QVector<SqpDateTime> &dateTimeList,
146 QVector<SqpDateTime> &notInCache, int cacheIndex, double currentTStart)
147 {
148 const auto dateTimeListSize = dateTimeList.count();
149 if (cacheIndex >= dateTimeListSize) {
150 // ts localised after all other interval: The last interval is [ts, te]
151 notInCache.push_back(SqpDateTime{currentTStart, dateTime.m_TEnd});
152 return;
153 }
154
155 auto currentDateTimeI = dateTimeList[cacheIndex];
156 auto cacheIndexJ = cacheIndex;
157 if (currentTStart < currentDateTimeI.m_TStart) {
158
159 // ts localised between to interval: let's localized te
160 addInCacheDataByEnd(dateTime, dateTimeList, notInCache, cacheIndexJ, currentTStart);
161 }
162 else if (dateTime.m_TStart < currentDateTimeI.m_TEnd) {
163 // ts not localised before the current interval: we need to look at the next interval
164 // We can assume now current tstart is the last interval tend, because data between them are
165 // in the cache
166 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex,
167 currentDateTimeI.m_TEnd);
168 }
169 else {
170 // ts not localised before the current interval: we need to look at the next interval
171 addInCacheDataByStart(dateTime, dateTimeList, notInCache, ++cacheIndex, currentTStart);
172 }
173 }
@@ -0,0 +1,343
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
3
4 #include <QObject>
5 #include <QtTest>
6
7 #include <memory>
8
9 class TestVariableCacheController : public QObject {
10 Q_OBJECT
11
12 private slots:
13 void testProvideNotInCacheDateTimeList();
14
15 void testAddDateTime();
16 };
17
18
19 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
20 {
21 VariableCacheController variableCacheController{};
22
23 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
24 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
25 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
26 static_cast<double>(te0.toMSecsSinceEpoch())};
27
28 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
29 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
30 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
31 static_cast<double>(te1.toMSecsSinceEpoch())};
32
33 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
34 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
35 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
36 static_cast<double>(te2.toMSecsSinceEpoch())};
37
38 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
39
40 variableCacheController.addDateTime(var0, sqp0);
41 variableCacheController.addDateTime(var0, sqp1);
42 variableCacheController.addDateTime(var0, sqp2);
43
44 // first case [ts,te] < ts0
45 auto ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
46 auto te = QDateTime{QDate{2017, 01, 01}, QTime{2, 1, 0, 0}};
47 auto sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
48 static_cast<double>(te.toMSecsSinceEpoch())};
49
50
51 auto notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
52
53 QCOMPARE(notInCach.size(), 1);
54 auto notInCashSqp = notInCach.first();
55 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
56 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
57
58
59 // second case ts < ts0 && ts0 < te <= te0
60 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
61 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
62 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
63 static_cast<double>(te.toMSecsSinceEpoch())};
64
65
66 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
67
68 QCOMPARE(notInCach.size(), 1);
69 notInCashSqp = notInCach.first();
70 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
71 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
72
73 // 3th case ts < ts0 && te0 < te <= ts1
74 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
75 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
76 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
77 static_cast<double>(te.toMSecsSinceEpoch())};
78
79
80 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
81
82 QCOMPARE(notInCach.size(), 2);
83 notInCashSqp = notInCach.first();
84 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
85 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
86
87 notInCashSqp = notInCach.at(1);
88 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
89 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
90
91 // 4th case ts < ts0 && ts1 < te <= te1
92 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
93 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
94 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
95 static_cast<double>(te.toMSecsSinceEpoch())};
96
97
98 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
99
100 QCOMPARE(notInCach.size(), 2);
101 notInCashSqp = notInCach.first();
102 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
103 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
104
105 notInCashSqp = notInCach.at(1);
106 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
107 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
108
109 // 5th case ts < ts0 && te3 < te
110 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 0, 0, 0}};
111 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
112 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
113 static_cast<double>(te.toMSecsSinceEpoch())};
114
115
116 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
117
118 QCOMPARE(notInCach.size(), 4);
119 notInCashSqp = notInCach.first();
120 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
121 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts0.toMSecsSinceEpoch()));
122
123 notInCashSqp = notInCach.at(1);
124 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
125 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
126
127 notInCashSqp = notInCach.at(2);
128 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
129 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
130
131 notInCashSqp = notInCach.at(3);
132 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
133 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
134
135
136 // 6th case ts2 < ts
137 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 45, 0, 0}};
138 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
139 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
140 static_cast<double>(te.toMSecsSinceEpoch())};
141
142
143 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
144
145 QCOMPARE(notInCach.size(), 1);
146 notInCashSqp = notInCach.first();
147 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
148 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
149
150 // 7th case ts = te0 && te < ts1
151 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
152 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
153 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
154 static_cast<double>(te.toMSecsSinceEpoch())};
155
156
157 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
158
159 QCOMPARE(notInCach.size(), 1);
160 notInCashSqp = notInCach.first();
161 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
162 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
163
164 // 8th case ts0 < ts < te0 && te < ts1
165 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
166 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
167 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
168 static_cast<double>(te.toMSecsSinceEpoch())};
169
170
171 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
172
173 QCOMPARE(notInCach.size(), 1);
174 notInCashSqp = notInCach.first();
175 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
176 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
177
178 // 9th case ts0 < ts < te0 && ts1 < te < te1
179 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 30, 0}};
180 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 7, 0, 0}};
181 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
182 static_cast<double>(te.toMSecsSinceEpoch())};
183
184
185 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
186
187 QCOMPARE(notInCach.size(), 1);
188 notInCashSqp = notInCach.first();
189 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te0.toMSecsSinceEpoch()));
190 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
191
192 // 10th case te1 < ts < te < ts2
193 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 9, 0, 0}};
194 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
195 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
196 static_cast<double>(te.toMSecsSinceEpoch())};
197
198
199 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
200
201 QCOMPARE(notInCach.size(), 1);
202 notInCashSqp = notInCach.first();
203 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
204 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
205
206 // 11th case te0 < ts < ts1 && te3 < te
207 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
208 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 47, 0, 0}};
209 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
210 static_cast<double>(te.toMSecsSinceEpoch())};
211
212
213 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
214
215 QCOMPARE(notInCach.size(), 3);
216 notInCashSqp = notInCach.first();
217 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
218 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
219
220 notInCashSqp = notInCach.at(1);
221 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
222 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts2.toMSecsSinceEpoch()));
223
224 notInCashSqp = notInCach.at(2);
225 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te2.toMSecsSinceEpoch()));
226 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
227
228 // 12th case te0 < ts < ts1 && te3 < te
229 ts = QDateTime{QDate{2017, 01, 01}, QTime{2, 5, 0, 0}};
230 te = QDateTime{QDate{2017, 01, 01}, QTime{2, 10, 0, 0}};
231 sqp = SqpDateTime{static_cast<double>(ts.toMSecsSinceEpoch()),
232 static_cast<double>(te.toMSecsSinceEpoch())};
233
234 notInCach = variableCacheController.provideNotInCacheDateTimeList(var0, sqp);
235
236 QCOMPARE(notInCach.size(), 2);
237 notInCashSqp = notInCach.first();
238 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(ts.toMSecsSinceEpoch()));
239 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(ts1.toMSecsSinceEpoch()));
240
241 notInCashSqp = notInCach.at(1);
242 QCOMPARE(notInCashSqp.m_TStart, static_cast<double>(te1.toMSecsSinceEpoch()));
243 QCOMPARE(notInCashSqp.m_TEnd, static_cast<double>(te.toMSecsSinceEpoch()));
244 }
245
246
247 void TestVariableCacheController::testAddDateTime()
248 {
249 VariableCacheController variableCacheController{};
250
251 auto ts0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 3, 0, 0}};
252 auto te0 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
253 auto sqp0 = SqpDateTime{static_cast<double>(ts0.toMSecsSinceEpoch()),
254 static_cast<double>(te0.toMSecsSinceEpoch())};
255
256 auto ts1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
257 auto te1 = QDateTime{QDate{2017, 01, 01}, QTime{2, 8, 0, 0}};
258 auto sqp1 = SqpDateTime{static_cast<double>(ts1.toMSecsSinceEpoch()),
259 static_cast<double>(te1.toMSecsSinceEpoch())};
260
261 auto ts2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 18, 0, 0}};
262 auto te2 = QDateTime{QDate{2017, 01, 01}, QTime{2, 20, 0, 0}};
263 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
264 static_cast<double>(te2.toMSecsSinceEpoch())};
265
266 auto ts01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
267 auto te01 = QDateTime{QDate{2017, 01, 01}, QTime{2, 6, 0, 0}};
268 auto sqp01 = SqpDateTime{static_cast<double>(ts01.toMSecsSinceEpoch()),
269 static_cast<double>(te01.toMSecsSinceEpoch())};
270
271 auto ts3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 14, 0, 0}};
272 auto te3 = QDateTime{QDate{2017, 01, 01}, QTime{2, 16, 0, 0}};
273 auto sqp3 = SqpDateTime{static_cast<double>(ts3.toMSecsSinceEpoch()),
274 static_cast<double>(te3.toMSecsSinceEpoch())};
275
276 auto ts03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 4, 0, 0}};
277 auto te03 = QDateTime{QDate{2017, 01, 01}, QTime{2, 22, 0, 0}};
278 auto sqp03 = SqpDateTime{static_cast<double>(ts03.toMSecsSinceEpoch()),
279 static_cast<double>(te03.toMSecsSinceEpoch())};
280
281
282 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
283
284
285 // First case: add the first interval to the variable :sqp0
286 variableCacheController.addDateTime(var0, sqp0);
287 auto dateCacheList = variableCacheController.dateCacheList(var0);
288 QCOMPARE(dateCacheList.count(), 1);
289 auto dateCache = dateCacheList.at(0);
290 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
291 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
292
293 // 2nd case: add a second interval : sqp1 > sqp0
294 variableCacheController.addDateTime(var0, sqp1);
295 dateCacheList = variableCacheController.dateCacheList(var0);
296 QCOMPARE(dateCacheList.count(), 2);
297 dateCache = dateCacheList.at(0);
298 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
299 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te0.toMSecsSinceEpoch()));
300
301 dateCache = dateCacheList.at(1);
302 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts1.toMSecsSinceEpoch()));
303 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
304
305 // 3th case: merge sqp0 & sqp1 with sqp01
306 variableCacheController.addDateTime(var0, sqp01);
307 dateCacheList = variableCacheController.dateCacheList(var0);
308 QCOMPARE(dateCacheList.count(), 1);
309 dateCache = dateCacheList.at(0);
310 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
311 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
312
313
314 // 4th case: add a second interval : sqp1 > sqp0
315 variableCacheController.addDateTime(var0, sqp2);
316 variableCacheController.addDateTime(var0, sqp3);
317 dateCacheList = variableCacheController.dateCacheList(var0);
318 QCOMPARE(dateCacheList.count(), 3);
319 dateCache = dateCacheList.at(0);
320 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
321 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te1.toMSecsSinceEpoch()));
322
323 dateCache = dateCacheList.at(1);
324 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts3.toMSecsSinceEpoch()));
325 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te3.toMSecsSinceEpoch()));
326
327 dateCache = dateCacheList.at(2);
328 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts2.toMSecsSinceEpoch()));
329 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te2.toMSecsSinceEpoch()));
330
331
332 // 5th case: merge all interval
333 variableCacheController.addDateTime(var0, sqp03);
334 dateCacheList = variableCacheController.dateCacheList(var0);
335 QCOMPARE(dateCacheList.count(), 1);
336 dateCache = dateCacheList.at(0);
337 QCOMPARE(dateCache.m_TStart, static_cast<double>(ts0.toMSecsSinceEpoch()));
338 QCOMPARE(dateCache.m_TEnd, static_cast<double>(te03.toMSecsSinceEpoch()));
339 }
340
341
342 QTEST_MAIN(TestVariableCacheController)
343 #include "TestVariableCacheController.moc"
@@ -0,0 +1,59
1 #ifndef SCIQLOP_MENUBUILDER_H
2 #define SCIQLOP_MENUBUILDER_H
3
4 #include <QLoggingCategory>
5 #include <QMenu>
6 #include <QStack>
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_MenuBuilder)
9
10 /// Helper assigned to build a hierarchical menu
11 class MenuBuilder {
12 public:
13 /**
14 * Ctor
15 * @param menu the parent menu
16 */
17 explicit MenuBuilder(QMenu *menu);
18
19 /**
20 * Adds action to the current menu
21 * @param actionName the name of the action
22 * @param actionFunction the function that will be executed when the action is triggered
23 */
24 template <typename ActionFun>
25 void addAction(const QString &actionName, ActionFun actionFunction);
26
27 /**
28 * Adds a new menu to the current menu
29 * @param name the name of the menu
30 */
31 void addMenu(const QString &name);
32
33 /// Adds a separator to the current menu. The separator is added only if the menu already
34 /// contains entries
35 void addSeparator();
36
37 /// Closes the current menu
38 void closeMenu();
39
40 private:
41 /// @return the current menu (i.e. the top menu of the stack), nullptr if there is no menu
42 QMenu *currentMenu() const;
43
44 /// Stack of all menus currently opened
45 QStack<QMenu *> m_Menus{};
46 };
47
48 template <typename ActionFun>
49 void MenuBuilder::addAction(const QString &actionName, ActionFun actionFunction)
50 {
51 if (auto currMenu = currentMenu()) {
52 currMenu->addAction(actionName, actionFunction);
53 }
54 else {
55 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the action");
56 }
57 }
58
59 #endif // SCIQLOP_MENUBUILDER_H
1 NO CONTENT: new file 100644, binary diff hidden
NO CONTENT: new file 100644, binary diff hidden
@@ -0,0 +1,55
1 #include "Visualization/operations/MenuBuilder.h"
2
3 Q_LOGGING_CATEGORY(LOG_MenuBuilder, "MenuBuilder")
4
5 MenuBuilder::MenuBuilder(QMenu *menu)
6 {
7 if (menu) {
8 m_Menus.push(menu);
9 }
10 else {
11 qCCritical(LOG_MenuBuilder()) << QObject::tr("No parent menu has been defined");
12 }
13 }
14
15 void MenuBuilder::addMenu(const QString &name)
16 {
17 if (auto currMenu = currentMenu()) {
18 m_Menus.push(currMenu->addMenu(name));
19 }
20 else {
21 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the new menu");
22 }
23 }
24
25 void MenuBuilder::addSeparator()
26 {
27 if (auto currMenu = currentMenu()) {
28 if (!currMenu->isEmpty()) {
29 currMenu->addSeparator();
30 }
31 }
32 else {
33 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the separator");
34 }
35 }
36
37 void MenuBuilder::closeMenu()
38 {
39 if (!m_Menus.isEmpty()) {
40 if (auto closedMenu = m_Menus.pop()) {
41 // Purge menu : if the closed menu has no entries, we remove it from its parent (the
42 // current menu)
43 if (auto currMenu = currentMenu()) {
44 if (closedMenu->isEmpty()) {
45 currMenu->removeAction(closedMenu->menuAction());
46 }
47 }
48 }
49 }
50 }
51
52 QMenu *MenuBuilder::currentMenu() const
53 {
54 return !m_Menus.isEmpty() ? m_Menus.top() : nullptr;
55 }
@@ -1,1 +1,31
1 TODO No newline at end of file
1 ![](gui/resources/icones/sciqlop2PNG_1024.png){:.some-css-class style="width: 20%"}
2
3
4 # Overview
5
6 ** SciQLOP ** (**SCI**entific **Q**t application for **L**earning from **O**bservations of **P**lasmas) aims to be an ergonomic
7 and powerful tool enabling visualization and analysis of in-situ space plasma data. This goal rises some
8 challenges either technical and in the conception and the design.
9 The time resolution allowed by nowadays measurements imply the ability to plot millions of points just for
10 one sensor with no compromise on interactivity. Plots may stay responsive even with millions of points.
11 Being able to scroll, zoom, move and export the plots with the mouse are the minimal interactions expected by the user.
12 SciQLOP may also abstract the manipulation of physic data while providing contextual features such as
13 coordinate transform, physical quantity extraction from data.
14 That said increasing graphical features usually lead to slower software and more complex GUI. Keeping
15 SciQLOP lightweight and intuitive is one of the priorities to make it usable and competitive.
16
17
18 ## How to build
19
20 ```
21 git clone https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/SciQLOP_Repos/SciQLop
22 cd SciQLop
23 mkdir build && cd build
24 cmake ../
25 make
26
27 ```
28
29 ## How to contribute
30
31 Contact sciqlop@lpp.polytechnique.fr
@@ -1,56 +1,82
1 #ifndef SCIQLOP_ARRAYDATA_H
1 #ifndef SCIQLOP_ARRAYDATA_H
2 #define SCIQLOP_ARRAYDATA_H
2 #define SCIQLOP_ARRAYDATA_H
3
3
4 #include <QVector>
4 #include <QVector>
5
5
6 /**
6 /**
7 * @brief The ArrayData class represents a dataset for a data series.
7 * @brief The ArrayData class represents a dataset for a data series.
8 *
8 *
9 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
9 * A dataset can be unidimensional or two-dimensional. This property is determined by the Dim
10 * template-parameter.
10 * template-parameter.
11 *
11 *
12 * @tparam Dim the dimension of the ArrayData (one or two)
12 * @tparam Dim the dimension of the ArrayData (one or two)
13 * @sa IDataSeries
13 * @sa IDataSeries
14 */
14 */
15 template <int Dim>
15 template <int Dim>
16 class ArrayData {
16 class ArrayData {
17 public:
17 public:
18 /**
18 /**
19 * Ctor for a unidimensional ArrayData
19 * Ctor for a unidimensional ArrayData
20 * @param nbColumns the number of values the ArrayData will hold
20 * @param nbColumns the number of values the ArrayData will hold
21 */
21 */
22 template <int D = Dim, typename = std::enable_if_t<D == 1> >
22 template <int D = Dim, typename = std::enable_if_t<D == 1> >
23 explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}}
23 explicit ArrayData(int nbColumns) : m_Data{1, QVector<double>{}}
24 {
24 {
25 m_Data[0].resize(nbColumns);
25 m_Data[0].resize(nbColumns);
26 }
26 }
27
27
28 /**
28 /**
29 * Sets a data at a specified index. The index has to be valid to be effective
29 * Sets a data at a specified index. The index has to be valid to be effective
30 * @param index the index to which the data will be set
30 * @param index the index to which the data will be set
31 * @param data the data to set
31 * @param data the data to set
32 * @remarks this method is only available for a unidimensional ArrayData
32 * @remarks this method is only available for a unidimensional ArrayData
33 */
33 */
34 template <int D = Dim, typename = std::enable_if_t<D == 1> >
34 template <int D = Dim, typename = std::enable_if_t<D == 1> >
35 void setData(int index, double data) noexcept
35 void setData(int index, double data) noexcept
36 {
36 {
37 if (index >= 0 && index < m_Data.at(0).size()) {
37 if (index >= 0 && index < m_Data.at(0).size()) {
38 m_Data[0].replace(index, data);
38 m_Data[0].replace(index, data);
39 }
39 }
40 }
40 }
41
41
42 /**
42 /**
43 * @return the data as a vector
43 * @return the data as a vector
44 * @remarks this method is only available for a unidimensional ArrayData
44 * @remarks this method is only available for a unidimensional ArrayData
45 */
45 */
46 template <int D = Dim, typename = std::enable_if_t<D == 1> >
46 template <int D = Dim, typename = std::enable_if_t<D == 1> >
47 QVector<double> data() const noexcept
47 QVector<double> data() const noexcept
48 {
48 {
49 return m_Data.at(0);
49 return m_Data.at(0);
50 }
50 }
51
51
52 /**
53 * @return the data as a vector
54 * @remarks this method is only available for a unidimensional ArrayData
55 */
56 template <int D = Dim, typename = std::enable_if_t<D == 1> >
57 const QVector<double> &data(double tStart, double tEnd) const noexcept
58 {
59 return m_Data.at(tStart);
60 }
61
62 // TODO Comment
63 template <int D = Dim, typename = std::enable_if_t<D == 1> >
64 void merge(ArrayData<1> *arrayData)
65 {
66 if (!m_Data.empty()) {
67 m_Data[0] += arrayData->data();
68 }
69 }
70
71 template <int D = Dim, typename = std::enable_if_t<D == 1> >
72 int size()
73 {
74 return m_Data[0].size();
75 }
76
77
52 private:
78 private:
53 QVector<QVector<double> > m_Data;
79 QVector<QVector<double> > m_Data;
54 };
80 };
55
81
56 #endif // SCIQLOP_ARRAYDATA_H
82 #endif // SCIQLOP_ARRAYDATA_H
@@ -1,50 +1,59
1 #ifndef SCIQLOP_DATASERIES_H
1 #ifndef SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
2 #define SCIQLOP_DATASERIES_H
3
3
4 #include <Data/ArrayData.h>
4 #include <Data/ArrayData.h>
5 #include <Data/IDataSeries.h>
5 #include <Data/IDataSeries.h>
6
6
7 #include <memory>
7 #include <memory>
8
8
9 /**
9 /**
10 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
10 * @brief The DataSeries class is the base (abstract) implementation of IDataSeries.
11 *
11 *
12 * It proposes to set a dimension for the values ​​data
12 * It proposes to set a dimension for the values ​​data
13 *
13 *
14 * @tparam Dim The dimension of the values data
14 * @tparam Dim The dimension of the values data
15 *
15 *
16 */
16 */
17 template <int Dim>
17 template <int Dim>
18 class DataSeries : public IDataSeries {
18 class DataSeries : public IDataSeries {
19 public:
19 public:
20 /// @sa IDataSeries::xAxisData()
20 /// @sa IDataSeries::xAxisData()
21 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
21 std::shared_ptr<ArrayData<1> > xAxisData() override { return m_XAxisData; }
22
22
23 /// @sa IDataSeries::xAxisUnit()
23 /// @sa IDataSeries::xAxisUnit()
24 Unit xAxisUnit() const override { return m_XAxisUnit; }
24 Unit xAxisUnit() const override { return m_XAxisUnit; }
25
25
26 /// @return the values dataset
26 /// @return the values dataset
27 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
27 std::shared_ptr<ArrayData<Dim> > valuesData() const { return m_ValuesData; }
28
28
29 /// @sa IDataSeries::valuesUnit()
29 /// @sa IDataSeries::valuesUnit()
30 Unit valuesUnit() const override { return m_ValuesUnit; }
30 Unit valuesUnit() const override { return m_ValuesUnit; }
31
31
32 /// @sa IDataSeries::merge()
33 void merge(IDataSeries *dataSeries) override
34 {
35 if (auto dimDataSeries = dynamic_cast<DataSeries<Dim> *>(dataSeries)) {
36 m_XAxisData->merge(dimDataSeries->xAxisData().get());
37 m_ValuesData->merge(dimDataSeries->valuesData().get());
38 }
39 }
40
32 protected:
41 protected:
33 /// Protected ctor (DataSeries is abstract)
42 /// Protected ctor (DataSeries is abstract)
34 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
43 explicit DataSeries(std::shared_ptr<ArrayData<1> > xAxisData, const Unit &xAxisUnit,
35 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
44 std::shared_ptr<ArrayData<Dim> > valuesData, const Unit &valuesUnit)
36 : m_XAxisData{xAxisData},
45 : m_XAxisData{xAxisData},
37 m_XAxisUnit{xAxisUnit},
46 m_XAxisUnit{xAxisUnit},
38 m_ValuesData{valuesData},
47 m_ValuesData{valuesData},
39 m_ValuesUnit{valuesUnit}
48 m_ValuesUnit{valuesUnit}
40 {
49 {
41 }
50 }
42
51
43 private:
52 private:
44 std::shared_ptr<ArrayData<1> > m_XAxisData;
53 std::shared_ptr<ArrayData<1> > m_XAxisData;
45 Unit m_XAxisUnit;
54 Unit m_XAxisUnit;
46 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
55 std::shared_ptr<ArrayData<Dim> > m_ValuesData;
47 Unit m_ValuesUnit;
56 Unit m_ValuesUnit;
48 };
57 };
49
58
50 #endif // SCIQLOP_DATASERIES_H
59 #endif // SCIQLOP_DATASERIES_H
@@ -1,30 +1,39
1 #ifndef SCIQLOP_IDATAPROVIDER_H
1 #ifndef SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
2 #define SCIQLOP_IDATAPROVIDER_H
3
3
4 #include <memory>
4 #include <memory>
5
5
6 #include <QObject>
6 #include <QObject>
7
7
8 #include <Data/SqpDateTime.h>
9
8 class DataProviderParameters;
10 class DataProviderParameters;
9 class IDataSeries;
11 class IDataSeries;
10
12
11 /**
13 /**
12 * @brief The IDataProvider interface aims to declare a data provider.
14 * @brief The IDataProvider interface aims to declare a data provider.
13 *
15 *
14 * A data provider is an entity that generates data and returns it according to various parameters
16 * A data provider is an entity that generates data and returns it according to various parameters
15 * (time interval, product to retrieve the data, etc.)
17 * (time interval, product to retrieve the data, etc.)
16 *
18 *
17 * @sa IDataSeries
19 * @sa IDataSeries
18 */
20 */
19 class IDataProvider {
21 class IDataProvider : public QObject {
22
23 Q_OBJECT
20 public:
24 public:
21 virtual ~IDataProvider() noexcept = default;
25 virtual ~IDataProvider() noexcept = default;
22
26
23 virtual std::unique_ptr<IDataSeries>
27 virtual std::unique_ptr<IDataSeries>
24 retrieveData(const DataProviderParameters &parameters) const = 0;
28 retrieveData(const DataProviderParameters &parameters) const = 0;
25 };
26
29
30
31 virtual void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) = 0;
32
33 signals:
34 void dataProvided(std::shared_ptr<IDataSeries> dateSerie, SqpDateTime dateTime);
35 };
27 // Required for using shared_ptr in signals/slots
36 // Required for using shared_ptr in signals/slots
28 Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>)
37 Q_DECLARE_METATYPE(std::shared_ptr<IDataProvider>)
29
38
30 #endif // SCIQLOP_IDATAPROVIDER_H
39 #endif // SCIQLOP_IDATAPROVIDER_H
@@ -1,47 +1,54
1 #ifndef SCIQLOP_IDATASERIES_H
1 #ifndef SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
2 #define SCIQLOP_IDATASERIES_H
3
3
4 #include <QString>
5
4
6 #include <memory>
5 #include <memory>
7
6
7 #include <QObject>
8 #include <QString>
9
8 template <int Dim>
10 template <int Dim>
9 class ArrayData;
11 class ArrayData;
10
12
11 struct Unit {
13 struct Unit {
12 explicit Unit(const QString &name = {}, bool timeUnit = false)
14 explicit Unit(const QString &name = {}, bool timeUnit = false)
13 : m_Name{name}, m_TimeUnit{timeUnit}
15 : m_Name{name}, m_TimeUnit{timeUnit}
14 {
16 {
15 }
17 }
16
18
17 QString m_Name; ///< Unit name
19 QString m_Name; ///< Unit name
18 bool m_TimeUnit; ///< The unit is a unit of time
20 bool m_TimeUnit; ///< The unit is a unit of time
19 };
21 };
20
22
21 /**
23 /**
22 * @brief The IDataSeries aims to declare a data series.
24 * @brief The IDataSeries aims to declare a data series.
23 *
25 *
24 * A data series is an entity that contains at least :
26 * A data series is an entity that contains at least :
25 * - one dataset representing the x-axis
27 * - one dataset representing the x-axis
26 * - one dataset representing the values
28 * - one dataset representing the values
27 *
29 *
28 * Each dataset is represented by an ArrayData, and is associated with a unit.
30 * Each dataset is represented by an ArrayData, and is associated with a unit.
29 *
31 *
30 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
32 * An ArrayData can be unidimensional or two-dimensional, depending on the implementation of the
31 * IDataSeries. The x-axis dataset is always unidimensional.
33 * IDataSeries. The x-axis dataset is always unidimensional.
32 *
34 *
33 * @sa ArrayData
35 * @sa ArrayData
34 */
36 */
35 class IDataSeries {
37 class IDataSeries {
36 public:
38 public:
37 virtual ~IDataSeries() noexcept = default;
39 virtual ~IDataSeries() noexcept = default;
38
40
39 /// Returns the x-axis dataset
41 /// Returns the x-axis dataset
40 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
42 virtual std::shared_ptr<ArrayData<1> > xAxisData() = 0;
41
43
42 virtual Unit xAxisUnit() const = 0;
44 virtual Unit xAxisUnit() const = 0;
43
45
44 virtual Unit valuesUnit() const = 0;
46 virtual Unit valuesUnit() const = 0;
47
48 virtual void merge(IDataSeries *dataSeries) = 0;
45 };
49 };
46
50
51 // Required for using shared_ptr in signals/slots
52 Q_DECLARE_METATYPE(std::shared_ptr<IDataSeries>)
53
47 #endif // SCIQLOP_IDATASERIES_H
54 #endif // SCIQLOP_IDATASERIES_H
@@ -1,14 +1,23
1 #ifndef SCIQLOP_SQPDATETIME_H
1 #ifndef SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
2 #define SCIQLOP_SQPDATETIME_H
3
3
4 #include <QObject>
4 /**
5 /**
5 * @brief The SqpDateTime struct holds the information of time parameters
6 * @brief The SqpDateTime struct holds the information of time parameters
6 */
7 */
7 struct SqpDateTime {
8 struct SqpDateTime {
8 /// Start time
9 /// Start time
9 double m_TStart;
10 double m_TStart;
10 /// End time
11 /// End time
11 double m_TEnd;
12 double m_TEnd;
13
14 bool contains(const SqpDateTime &dateTime)
15 {
16 return (m_TStart <= dateTime.m_TStart && m_TEnd >= dateTime.m_TEnd);
17 }
12 };
18 };
13
19
20 // Required for using shared_ptr in signals/slots
21 Q_DECLARE_METATYPE(SqpDateTime)
22
14 #endif // SCIQLOP_SQPDATETIME_H
23 #endif // SCIQLOP_SQPDATETIME_H
@@ -1,35 +1,54
1 #ifndef SCIQLOP_VARIABLE_H
1 #ifndef SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
2 #define SCIQLOP_VARIABLE_H
3
3
4 #include <Common/spimpl.h>
4 #include <Data/SqpDateTime.h>
5
5
6
7 #include <QLoggingCategory>
6 #include <QObject>
8 #include <QObject>
7
9
10 #include <Common/spimpl.h>
11
12 Q_DECLARE_LOGGING_CATEGORY(LOG_Variable)
13
8 class IDataSeries;
14 class IDataSeries;
9 class QString;
15 class QString;
10
16
11 /**
17 /**
12 * @brief The Variable class represents a variable in SciQlop.
18 * @brief The Variable class represents a variable in SciQlop.
13 */
19 */
14 class Variable {
20 class Variable : public QObject {
21
22 Q_OBJECT
23
15 public:
24 public:
16 explicit Variable(const QString &name, const QString &unit, const QString &mission);
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
26 const SqpDateTime &dateTime);
17
27
18 QString name() const noexcept;
28 QString name() const noexcept;
19 QString mission() const noexcept;
29 QString mission() const noexcept;
20 QString unit() const noexcept;
30 QString unit() const noexcept;
21
31 SqpDateTime dateTime() const noexcept;
22 void addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
23
32
24 /// @return the data of the variable, nullptr if there is no data
33 /// @return the data of the variable, nullptr if there is no data
25 IDataSeries *dataSeries() const noexcept;
34 IDataSeries *dataSeries() const noexcept;
26
35
36 bool contains(SqpDateTime dateTime);
37 void setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept;
38
39 public slots:
40 void onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept;
41
42 signals:
43 void dataCacheUpdated();
44
45
27 private:
46 private:
28 class VariablePrivate;
47 class VariablePrivate;
29 spimpl::unique_impl_ptr<VariablePrivate> impl;
48 spimpl::unique_impl_ptr<VariablePrivate> impl;
30 };
49 };
31
50
32 // Required for using shared_ptr in signals/slots
51 // Required for using shared_ptr in signals/slots
33 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
52 Q_DECLARE_METATYPE(std::shared_ptr<Variable>)
34
53
35 #endif // SCIQLOP_VARIABLE_H
54 #endif // SCIQLOP_VARIABLE_H
@@ -1,51 +1,58
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
1 #ifndef SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
2 #define SCIQLOP_VARIABLECONTROLLER_H
3
3
4 #include <Data/SqpDateTime.h>
5
4 #include <QLoggingCategory>
6 #include <QLoggingCategory>
5 #include <QObject>
7 #include <QObject>
6
8
7 #include <Common/spimpl.h>
9 #include <Common/spimpl.h>
8
10
11
9 class IDataProvider;
12 class IDataProvider;
10 class TimeController;
13 class TimeController;
11 class Variable;
14 class Variable;
12 class VariableModel;
15 class VariableModel;
13
16
14 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
17 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableController)
15
18
16 /**
19 /**
17 * @brief The VariableController class aims to handle the variables in SciQlop.
20 * @brief The VariableController class aims to handle the variables in SciQlop.
18 */
21 */
19 class VariableController : public QObject {
22 class VariableController : public QObject {
20 Q_OBJECT
23 Q_OBJECT
21 public:
24 public:
22 explicit VariableController(QObject *parent = 0);
25 explicit VariableController(QObject *parent = 0);
23 virtual ~VariableController();
26 virtual ~VariableController();
24
27
25 VariableModel *variableModel() noexcept;
28 VariableModel *variableModel() noexcept;
26
29
27 void setTimeController(TimeController *timeController) noexcept;
30 void setTimeController(TimeController *timeController) noexcept;
28
31
32
33 /// Request the data loading of the variable whithin dateTime
34 void requestDataLoading(std::shared_ptr<Variable> variable, const SqpDateTime &dateTime);
35
29 signals:
36 signals:
30 /// Signal emitted when a variable has been created
37 /// Signal emitted when a variable has been created
31 void variableCreated(std::shared_ptr<Variable> variable);
38 void variableCreated(std::shared_ptr<Variable> variable);
32
39
33 public slots:
40 public slots:
34 /**
41 /**
35 * Creates a new variable and adds it to the model
42 * Creates a new variable and adds it to the model
36 * @param name the name of the new variable
43 * @param name the name of the new variable
37 * @param provider the data provider for the new variable
44 * @param provider the data provider for the new variable
38 */
45 */
39 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
46 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
40
47
41 void initialize();
48 void initialize();
42 void finalize();
49 void finalize();
43
50
44 private:
51 private:
45 void waitForFinish();
52 void waitForFinish();
46
53
47 class VariableControllerPrivate;
54 class VariableControllerPrivate;
48 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
55 spimpl::unique_impl_ptr<VariableControllerPrivate> impl;
49 };
56 };
50
57
51 #endif // SCIQLOP_VARIABLECONTROLLER_H
58 #endif // SCIQLOP_VARIABLECONTROLLER_H
@@ -1,44 +1,49
1 #ifndef SCIQLOP_VARIABLEMODEL_H
1 #ifndef SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
2 #define SCIQLOP_VARIABLEMODEL_H
3
3
4 #include <Common/spimpl.h>
4
5 #include <Data/SqpDateTime.h>
5
6
6 #include <QAbstractTableModel>
7 #include <QAbstractTableModel>
7 #include <QLoggingCategory>
8 #include <QLoggingCategory>
8
9
10 #include <Common/spimpl.h>
11
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
10
13
11 class IDataSeries;
14 class IDataSeries;
12 class Variable;
15 class Variable;
13
16
14 /**
17 /**
15 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
18 * @brief The VariableModel class aims to hold the variables that have been created in SciQlop
16 */
19 */
17 class VariableModel : public QAbstractTableModel {
20 class VariableModel : public QAbstractTableModel {
18 public:
21 public:
19 explicit VariableModel(QObject *parent = nullptr);
22 explicit VariableModel(QObject *parent = nullptr);
20
23
21 /**
24 /**
22 * Creates a new variable in the model
25 * Creates a new variable in the model
23 * @param name the name of the new variable
26 * @param name the name of the new variable
27 * @param dateTime the dateTime of the new variable
24 * @param defaultDataSeries the default data of the new variable
28 * @param defaultDataSeries the default data of the new variable
25 * @return the pointer to the new variable
29 * @return the pointer to the new variable
26 */
30 */
27 std::shared_ptr<Variable>
31 std::shared_ptr<Variable>
28 createVariable(const QString &name, std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
32 createVariable(const QString &name, const SqpDateTime &dateTime,
33 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
29
34
30 // /////////////////////////// //
35 // /////////////////////////// //
31 // QAbstractTableModel methods //
36 // QAbstractTableModel methods //
32 // /////////////////////////// //
37 // /////////////////////////// //
33 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
38 virtual int columnCount(const QModelIndex &parent = QModelIndex{}) const override;
34 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
39 virtual int rowCount(const QModelIndex &parent = QModelIndex{}) const override;
35 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
40 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
36 virtual QVariant headerData(int section, Qt::Orientation orientation,
41 virtual QVariant headerData(int section, Qt::Orientation orientation,
37 int role = Qt::DisplayRole) const override;
42 int role = Qt::DisplayRole) const override;
38
43
39 private:
44 private:
40 class VariableModelPrivate;
45 class VariableModelPrivate;
41 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
46 spimpl::unique_impl_ptr<VariableModelPrivate> impl;
42 };
47 };
43
48
44 #endif // SCIQLOP_VARIABLEMODEL_H
49 #endif // SCIQLOP_VARIABLEMODEL_H
@@ -1,48 +1,89
1 #include "Variable/Variable.h"
1 #include "Variable/Variable.h"
2
2
3 #include <Data/IDataSeries.h>
3 #include <Data/IDataSeries.h>
4 #include <Data/SqpDateTime.h>
5
6 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
4
7
5 struct Variable::VariablePrivate {
8 struct Variable::VariablePrivate {
6 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission)
9 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
7 : m_Name{name}, m_Unit{unit}, m_Mission{mission}, m_DataSeries{nullptr}
10 const SqpDateTime &dateTime)
11 : m_Name{name},
12 m_Unit{unit},
13 m_Mission{mission},
14 m_DateTime{dateTime},
15 m_DataSeries{nullptr}
8 {
16 {
9 }
17 }
10
18
11 QString m_Name;
19 QString m_Name;
12 QString m_Unit;
20 QString m_Unit;
13 QString m_Mission;
21 QString m_Mission;
22
23 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
14 std::unique_ptr<IDataSeries> m_DataSeries;
24 std::unique_ptr<IDataSeries> m_DataSeries;
15 };
25 };
16
26
17 Variable::Variable(const QString &name, const QString &unit, const QString &mission)
27 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
18 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission)}
28 const SqpDateTime &dateTime)
29 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
19 {
30 {
20 }
31 }
21
32
22 QString Variable::name() const noexcept
33 QString Variable::name() const noexcept
23 {
34 {
24 return impl->m_Name;
35 return impl->m_Name;
25 }
36 }
26
37
27 QString Variable::mission() const noexcept
38 QString Variable::mission() const noexcept
28 {
39 {
29 return impl->m_Mission;
40 return impl->m_Mission;
30 }
41 }
31
42
32 QString Variable::unit() const noexcept
43 QString Variable::unit() const noexcept
33 {
44 {
34 return impl->m_Unit;
45 return impl->m_Unit;
35 }
46 }
36
47
37 void Variable::addDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
48 SqpDateTime Variable::dateTime() const noexcept
49 {
50 return impl->m_DateTime;
51 }
52
53 void Variable::setDataSeries(std::unique_ptr<IDataSeries> dataSeries) noexcept
38 {
54 {
39 if (!impl->m_DataSeries) {
55 if (!impl->m_DataSeries) {
40 impl->m_DataSeries = std::move(dataSeries);
56 impl->m_DataSeries = std::move(dataSeries);
41 }
57 }
42 /// @todo : else, merge the two data series (if possible)
58 }
59
60 void Variable::onAddDataSeries(std::shared_ptr<IDataSeries> dataSeries) noexcept
61 {
62 if (impl->m_DataSeries) {
63 impl->m_DataSeries->merge(dataSeries.get());
64
65 emit dataCacheUpdated();
66 }
43 }
67 }
44
68
45 IDataSeries *Variable::dataSeries() const noexcept
69 IDataSeries *Variable::dataSeries() const noexcept
46 {
70 {
47 return impl->m_DataSeries.get();
71 return impl->m_DataSeries.get();
48 }
72 }
73
74 bool Variable::contains(SqpDateTime dateTime)
75 {
76 if (!impl->m_DateTime.contains(dateTime)) {
77 // The current variable dateTime isn't enough to display the dateTime requested.
78 // We have to update it to the new dateTime requested.
79 // the correspondant new data to display will be given by the cache if possible and the
80 // provider if necessary.
81 qCInfo(LOG_Variable()) << "NEW DATE NEEDED";
82
83 impl->m_DateTime = dateTime;
84
85 return false;
86 }
87
88 return true;
89 }
@@ -1,110 +1,164
1 #include <Variable/Variable.h>
2 #include <Variable/VariableCacheController.h>
1 #include <Variable/VariableController.h>
3 #include <Variable/VariableController.h>
2 #include <Variable/VariableModel.h>
4 #include <Variable/VariableModel.h>
3
5
4 #include <Data/DataProviderParameters.h>
6 #include <Data/DataProviderParameters.h>
5 #include <Data/IDataProvider.h>
7 #include <Data/IDataProvider.h>
6 #include <Data/IDataSeries.h>
8 #include <Data/IDataSeries.h>
7 #include <Time/TimeController.h>
9 #include <Time/TimeController.h>
8
10
9 #include <QDateTime>
11 #include <QDateTime>
12 #include <QElapsedTimer>
10 #include <QMutex>
13 #include <QMutex>
11 #include <QThread>
14 #include <QThread>
12
15
16 #include <unordered_map>
17
13 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
18 Q_LOGGING_CATEGORY(LOG_VariableController, "VariableController")
14
19
15 namespace {
20 namespace {
16
21
17 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
22 /// @todo Generates default dataseries, according to the provider passed in parameter. This method
18 /// will be deleted when the timerange is recovered from SciQlop
23 /// will be deleted when the timerange is recovered from SciQlop
19 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
24 std::unique_ptr<IDataSeries> generateDefaultDataSeries(const IDataProvider &provider,
20 const SqpDateTime &dateTime) noexcept
25 const SqpDateTime &dateTime) noexcept
21 {
26 {
22 auto parameters = DataProviderParameters{dateTime};
27 auto parameters = DataProviderParameters{dateTime};
23
28
24 return provider.retrieveData(parameters);
29 return provider.retrieveData(parameters);
25 }
30 }
26
31
27 } // namespace
32 } // namespace
28
33
29 struct VariableController::VariableControllerPrivate {
34 struct VariableController::VariableControllerPrivate {
30 explicit VariableControllerPrivate(VariableController *parent)
35 explicit VariableControllerPrivate(VariableController *parent)
31 : m_WorkingMutex{}, m_VariableModel{new VariableModel{parent}}
36 : m_WorkingMutex{},
37 m_VariableModel{new VariableModel{parent}},
38 m_VariableCacheController{std::make_unique<VariableCacheController>()}
32 {
39 {
33 }
40 }
34
41
35 QMutex m_WorkingMutex;
42 QMutex m_WorkingMutex;
36 /// Variable model. The VariableController has the ownership
43 /// Variable model. The VariableController has the ownership
37 VariableModel *m_VariableModel;
44 VariableModel *m_VariableModel;
38
45
46
39 TimeController *m_TimeController{nullptr};
47 TimeController *m_TimeController{nullptr};
48 std::unique_ptr<VariableCacheController> m_VariableCacheController;
49
50 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
51 m_VariableToProviderMap;
40 };
52 };
41
53
42 VariableController::VariableController(QObject *parent)
54 VariableController::VariableController(QObject *parent)
43 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
55 : QObject{parent}, impl{spimpl::make_unique_impl<VariableControllerPrivate>(this)}
44 {
56 {
45 qCDebug(LOG_VariableController()) << tr("VariableController construction")
57 qCDebug(LOG_VariableController()) << tr("VariableController construction")
46 << QThread::currentThread();
58 << QThread::currentThread();
47 }
59 }
48
60
49 VariableController::~VariableController()
61 VariableController::~VariableController()
50 {
62 {
51 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
63 qCDebug(LOG_VariableController()) << tr("VariableController destruction")
52 << QThread::currentThread();
64 << QThread::currentThread();
53 this->waitForFinish();
65 this->waitForFinish();
54 }
66 }
55
67
56 VariableModel *VariableController::variableModel() noexcept
68 VariableModel *VariableController::variableModel() noexcept
57 {
69 {
58 return impl->m_VariableModel;
70 return impl->m_VariableModel;
59 }
71 }
60
72
61 void VariableController::setTimeController(TimeController *timeController) noexcept
73 void VariableController::setTimeController(TimeController *timeController) noexcept
62 {
74 {
63 impl->m_TimeController = timeController;
75 impl->m_TimeController = timeController;
64 }
76 }
65
77
66 void VariableController::createVariable(const QString &name,
78 void VariableController::createVariable(const QString &name,
67 std::shared_ptr<IDataProvider> provider) noexcept
79 std::shared_ptr<IDataProvider> provider) noexcept
68 {
80 {
69 // TORM
70 // auto dateTime = SqpDateTime{
71 // // Remarks : we don't use toSecsSinceEpoch() here (method is for Qt 5.8 or above)
72 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 00}}.toMSecsSinceEpoch()
73 // / 1000.),
74 // static_cast<double>(QDateTime{QDate{2017, 01, 01}, QTime{12, 01}}.toMSecsSinceEpoch())
75 // / 1000.};
76
81
77 if (!impl->m_TimeController) {
82 if (!impl->m_TimeController) {
78 qCCritical(LOG_VariableController())
83 qCCritical(LOG_VariableController())
79 << tr("Impossible to create variable: The time controller is null");
84 << tr("Impossible to create variable: The time controller is null");
80 return;
85 return;
81 }
86 }
82
87
83
88
84 /// @todo : for the moment :
89 /// @todo : for the moment :
85 /// - the provider is only used to retrieve data from the variable for its initialization, but
90 /// - the provider is only used to retrieve data from the variable for its initialization, but
86 /// it will be retained later
91 /// it will be retained later
87 /// - default data are generated for the variable, without taking into account the timerange set
92 /// - default data are generated for the variable, without taking into account the timerange set
88 /// in sciqlop
93 /// in sciqlop
94 auto dateTime = impl->m_TimeController->dateTime();
89 if (auto newVariable = impl->m_VariableModel->createVariable(
95 if (auto newVariable = impl->m_VariableModel->createVariable(
90 name, generateDefaultDataSeries(*provider, impl->m_TimeController->dateTime()))) {
96 name, dateTime, generateDefaultDataSeries(*provider, dateTime))) {
97
98 // store the provider
99 impl->m_VariableToProviderMap[newVariable] = provider;
100 qRegisterMetaType<std::shared_ptr<IDataSeries> >();
101 qRegisterMetaType<SqpDateTime>();
102 connect(provider.get(), &IDataProvider::dataProvided, newVariable.get(),
103 &Variable::onAddDataSeries);
104
105
106 // store in cache
107 impl->m_VariableCacheController->addDateTime(newVariable, dateTime);
108
109 // notify the creation
91 emit variableCreated(newVariable);
110 emit variableCreated(newVariable);
92 }
111 }
93 }
112 }
94
113
114
115 void VariableController::requestDataLoading(std::shared_ptr<Variable> variable,
116 const SqpDateTime &dateTime)
117 {
118 // we want to load data of the variable for the dateTime.
119 // First we check if the cache contains some of them.
120 // For the other, we ask the provider to give them.
121 if (variable) {
122
123 QElapsedTimer timer;
124 timer.start();
125 qCInfo(LOG_VariableController()) << "The slow s0 operation took" << timer.elapsed()
126 << "milliseconds";
127 auto dateTimeListNotInCache
128 = impl->m_VariableCacheController->provideNotInCacheDateTimeList(variable, dateTime);
129 qCInfo(LOG_VariableController()) << "The slow s1 operation took" << timer.elapsed()
130 << "milliseconds";
131
132 // Ask the provider for each data on the dateTimeListNotInCache
133 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(dateTimeListNotInCache);
134
135 qCInfo(LOG_VariableController()) << "The slow s2 operation took" << timer.elapsed()
136 << "milliseconds";
137
138 // store in cache
139 impl->m_VariableCacheController->addDateTime(variable, dateTime);
140 qCInfo(LOG_VariableController()) << "The slow s3 operation took" << timer.elapsed()
141 << "milliseconds";
142 }
143 else {
144 qCCritical(LOG_VariableController()) << tr("Impossible to load data of a variable null");
145 }
146 }
147
148
95 void VariableController::initialize()
149 void VariableController::initialize()
96 {
150 {
97 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
151 qCDebug(LOG_VariableController()) << tr("VariableController init") << QThread::currentThread();
98 impl->m_WorkingMutex.lock();
152 impl->m_WorkingMutex.lock();
99 qCDebug(LOG_VariableController()) << tr("VariableController init END");
153 qCDebug(LOG_VariableController()) << tr("VariableController init END");
100 }
154 }
101
155
102 void VariableController::finalize()
156 void VariableController::finalize()
103 {
157 {
104 impl->m_WorkingMutex.unlock();
158 impl->m_WorkingMutex.unlock();
105 }
159 }
106
160
107 void VariableController::waitForFinish()
161 void VariableController::waitForFinish()
108 {
162 {
109 QMutexLocker locker{&impl->m_WorkingMutex};
163 QMutexLocker locker{&impl->m_WorkingMutex};
110 }
164 }
@@ -1,120 +1,120
1 #include <Variable/Variable.h>
1 #include <Variable/Variable.h>
2 #include <Variable/VariableModel.h>
2 #include <Variable/VariableModel.h>
3
3
4 #include <Data/IDataSeries.h>
4 #include <Data/IDataSeries.h>
5
5
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
7
7
8 namespace {
8 namespace {
9
9
10 // Column indexes
10 // Column indexes
11 const auto NAME_COLUMN = 0;
11 const auto NAME_COLUMN = 0;
12 const auto UNIT_COLUMN = 1;
12 const auto UNIT_COLUMN = 1;
13 const auto MISSION_COLUMN = 2;
13 const auto MISSION_COLUMN = 2;
14 const auto NB_COLUMNS = 3;
14 const auto NB_COLUMNS = 3;
15
15
16 } // namespace
16 } // namespace
17
17
18 struct VariableModel::VariableModelPrivate {
18 struct VariableModel::VariableModelPrivate {
19 /// Variables created in SciQlop
19 /// Variables created in SciQlop
20 std::vector<std::shared_ptr<Variable> > m_Variables;
20 std::vector<std::shared_ptr<Variable> > m_Variables;
21 };
21 };
22
22
23 VariableModel::VariableModel(QObject *parent)
23 VariableModel::VariableModel(QObject *parent)
24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
24 : QAbstractTableModel{parent}, impl{spimpl::make_unique_impl<VariableModelPrivate>()}
25 {
25 {
26 }
26 }
27
27
28 std::shared_ptr<Variable>
28 std::shared_ptr<Variable>
29 VariableModel::createVariable(const QString &name,
29 VariableModel::createVariable(const QString &name, const SqpDateTime &dateTime,
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
31 {
31 {
32 auto insertIndex = rowCount();
32 auto insertIndex = rowCount();
33 beginInsertRows({}, insertIndex, insertIndex);
33 beginInsertRows({}, insertIndex, insertIndex);
34
34
35 /// @todo For the moment, the other data of the variable is initialized with default values
35 /// @todo For the moment, the other data of the variable is initialized with default values
36 auto variable
36 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
37 = std::make_shared<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
37 QStringLiteral("mission"), dateTime);
38 variable->addDataSeries(std::move(defaultDataSeries));
38 variable->setDataSeries(std::move(defaultDataSeries));
39
39
40 impl->m_Variables.push_back(variable);
40 impl->m_Variables.push_back(variable);
41
41
42 endInsertRows();
42 endInsertRows();
43
43
44 return variable;
44 return variable;
45 }
45 }
46
46
47 int VariableModel::columnCount(const QModelIndex &parent) const
47 int VariableModel::columnCount(const QModelIndex &parent) const
48 {
48 {
49 Q_UNUSED(parent);
49 Q_UNUSED(parent);
50
50
51 return NB_COLUMNS;
51 return NB_COLUMNS;
52 }
52 }
53
53
54 int VariableModel::rowCount(const QModelIndex &parent) const
54 int VariableModel::rowCount(const QModelIndex &parent) const
55 {
55 {
56 Q_UNUSED(parent);
56 Q_UNUSED(parent);
57
57
58 return impl->m_Variables.size();
58 return impl->m_Variables.size();
59 }
59 }
60
60
61 QVariant VariableModel::data(const QModelIndex &index, int role) const
61 QVariant VariableModel::data(const QModelIndex &index, int role) const
62 {
62 {
63 if (!index.isValid()) {
63 if (!index.isValid()) {
64 return QVariant{};
64 return QVariant{};
65 }
65 }
66
66
67 if (index.row() < 0 || index.row() >= rowCount()) {
67 if (index.row() < 0 || index.row() >= rowCount()) {
68 return QVariant{};
68 return QVariant{};
69 }
69 }
70
70
71 if (role == Qt::DisplayRole) {
71 if (role == Qt::DisplayRole) {
72 if (auto variable = impl->m_Variables.at(index.row()).get()) {
72 if (auto variable = impl->m_Variables.at(index.row()).get()) {
73 switch (index.column()) {
73 switch (index.column()) {
74 case NAME_COLUMN:
74 case NAME_COLUMN:
75 return variable->name();
75 return variable->name();
76 case UNIT_COLUMN:
76 case UNIT_COLUMN:
77 return variable->unit();
77 return variable->unit();
78 case MISSION_COLUMN:
78 case MISSION_COLUMN:
79 return variable->mission();
79 return variable->mission();
80 default:
80 default:
81 // No action
81 // No action
82 break;
82 break;
83 }
83 }
84
84
85 qWarning(LOG_VariableModel())
85 qWarning(LOG_VariableModel())
86 << tr("Can't get data (unknown column %1)").arg(index.column());
86 << tr("Can't get data (unknown column %1)").arg(index.column());
87 }
87 }
88 else {
88 else {
89 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
89 qWarning(LOG_VariableModel()) << tr("Can't get data (no variable)");
90 }
90 }
91 }
91 }
92
92
93 return QVariant{};
93 return QVariant{};
94 }
94 }
95
95
96 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
96 QVariant VariableModel::headerData(int section, Qt::Orientation orientation, int role) const
97 {
97 {
98 if (role != Qt::DisplayRole) {
98 if (role != Qt::DisplayRole) {
99 return QVariant{};
99 return QVariant{};
100 }
100 }
101
101
102 if (orientation == Qt::Horizontal) {
102 if (orientation == Qt::Horizontal) {
103 switch (section) {
103 switch (section) {
104 case NAME_COLUMN:
104 case NAME_COLUMN:
105 return tr("Name");
105 return tr("Name");
106 case UNIT_COLUMN:
106 case UNIT_COLUMN:
107 return tr("Unit");
107 return tr("Unit");
108 case MISSION_COLUMN:
108 case MISSION_COLUMN:
109 return tr("Mission");
109 return tr("Mission");
110 default:
110 default:
111 // No action
111 // No action
112 break;
112 break;
113 }
113 }
114
114
115 qWarning(LOG_VariableModel())
115 qWarning(LOG_VariableModel())
116 << tr("Can't get header data (unknown column %1)").arg(section);
116 << tr("Can't get header data (unknown column %1)").arg(section);
117 }
117 }
118
118
119 return QVariant{};
119 return QVariant{};
120 }
120 }
@@ -1,128 +1,139
1 #
1 #
2 # use_clangformat.cmake
2 # use_clangformat.cmake
3 #
3 #
4 # The following functions are defined in this document:
4 # The following functions are defined in this document:
5 #
5 #
6
6
7 # ADD_CLANGFORMAT_TARGETS(<globExpression> ...
7 # ADD_CLANGFORMAT_TARGETS(<globExpression> ...
8 # [ADD_TO_ALL]
8 # [ADD_TO_ALL]
9 # [NAME <name>]
9 # [NAME <name>]
10 # [NAME_ALL <nameall>]
10 # [NAME_ALL <nameall>]
11 # [STYLE style]
11 # [STYLE style]
12 # [RECURSE])
12 # [RECURSE])
13 #
13 #
14 # Two custom targets will be created:
14 # Two custom targets will be created:
15 # * format_reports is run as part of the build, and is not rerun unless one of
15 # * format_reports is run as part of the build, and is not rerun unless one of
16 # the file formatted is modified (only created if ADD_TO_ALL is provided);
16 # the file formatted is modified (only created if ADD_TO_ALL is provided);
17 # * format must be explicitely called (make format) and is rerun even if the
17 # * format must be explicitely called (make format) and is rerun even if the
18 # files to format have not been modified. To achieve this behavior, the commands
18 # files to format have not been modified. To achieve this behavior, the commands
19 # used in this target pretend to produce a file without actually producing it.
19 # used in this target pretend to produce a file without actually producing it.
20 # Because the output file is not there after the run, the command will be rerun
20 # Because the output file is not there after the run, the command will be rerun
21 # again at the next target build.
21 # again at the next target build.
22 #
22 #
23 # If ADD_TO_ALL is provided then a target will be added to the default build
23 # If ADD_TO_ALL is provided then a target will be added to the default build
24 # targets so that each time a source file is compiled, it is formatted with
24 # targets so that each time a source file is compiled, it is formatted with
25 # clang-format.
25 # clang-format.
26 #
26 #
27 # NAME and NAME_ALL customize the name of the targets (format and format_reports
27 # NAME and NAME_ALL customize the name of the targets (format and format_reports
28 # by default respectively).
28 # by default respectively).
29 #
29 #
30 # STYLE sets the style used by clang-format (default to "file").
30 # STYLE sets the style used by clang-format (default to "file").
31 #
31 #
32 # RECURSE selects if the glob expressions should be applied recursively or not.
32 # RECURSE selects if the glob expressions should be applied recursively or not.
33 FUNCTION(ADD_CLANGFORMAT_TARGETS)
33 FUNCTION(ADD_CLANGFORMAT_TARGETS)
34 # Default values
34 # Default values
35 SET(target "format")
35 SET(target "format")
36 SET(target_all "format_all")
36 SET(target_all "format_all")
37 SET(style "file")
37 SET(style "file")
38 SET(recurse OFF)
38 SET(recurse OFF)
39 SET(addToAll OFF)
39 SET(addToAll OFF)
40 SET(globs)
40 SET(globs)
41
41
42 # Parse the options
42 # Parse the options
43 MATH(EXPR lastIdx "${ARGC} - 1")
43 MATH(EXPR lastIdx "${ARGC} - 1")
44 SET(i 0)
44 SET(i 0)
45 WHILE(i LESS ${ARGC})
45 WHILE(i LESS ${ARGC})
46 SET(arg "${ARGV${i}}")
46 SET(arg "${ARGV${i}}")
47 IF("${arg}" STREQUAL "ADD_TO_ALL")
47 IF("${arg}" STREQUAL "ADD_TO_ALL")
48 SET(addToAll ON)
48 SET(addToAll ON)
49 ELSEIF("${arg}" STREQUAL "NAME")
49 ELSEIF("${arg}" STREQUAL "NAME")
50 clangformat_incr(i)
50 clangformat_incr(i)
51 SET(target "${ARGV${i}}")
51 SET(target "${ARGV${i}}")
52 ELSEIF("${arg}" STREQUAL "NAME_ALL")
52 ELSEIF("${arg}" STREQUAL "NAME_ALL")
53 clangformat_incr(i)
53 clangformat_incr(i)
54 SET(target_all "${ARGV${i}}")
54 SET(target_all "${ARGV${i}}")
55 ELSEIF("${arg}" STREQUAL "STYLE")
55 ELSEIF("${arg}" STREQUAL "STYLE")
56 clangformat_incr(i)
56 clangformat_incr(i)
57 SET(style "${ARGV${i}}")
57 SET(style "${ARGV${i}}")
58 ELSEIF("${arg}" STREQUAL "RECURSE")
58 ELSEIF("${arg}" STREQUAL "RECURSE")
59 SET(recurse ON)
59 SET(recurse ON)
60 ELSE()
60 ELSE()
61 LIST(APPEND globs ${arg})
61 LIST(APPEND globs ${arg})
62 ENDIF()
62 ENDIF()
63 clangformat_incr(i)
63 clangformat_incr(i)
64 ENDWHILE()
64 ENDWHILE()
65
65
66
66 # Retrieve source files to format
67 # Retrieve source files to format
67 IF(recurse)
68 IF(recurse)
68 FILE(GLOB_RECURSE srcs ${globs})
69 FILE(GLOB_RECURSE srcs ${globs})
69 ELSE()
70 ELSE()
70 FILE(GLOB srcs ${globs})
71 FILE(GLOB srcs ${globs})
71 ENDIF()
72 ENDIF()
72
73
73 IF(NOT CLANGFORMAT_EXECUTABLE)
74 IF(NOT CLANGFORMAT_EXECUTABLE)
74 MESSAGE(FATAL_ERROR "Unable to find clang-format executable")
75 MESSAGE(FATAL_ERROR "Unable to find clang-format executable")
75 ENDIF()
76 ENDIF()
76
77
77 # Format each source file with clang-format
78 # Format each source file with clang-format
78 SET(touchedFiles)
79 SET(touchedFiles)
79 SET(fakedTouchedFiles)
80 SET(fakedTouchedFiles)
80 SET(reportNb 0)
81 SET(reportNb 0)
81 # Create the directory where the touched files will be saved
82 # Create the directory where the touched files will be saved
82 SET(formatDirectory "${CMAKE_CURRENT_BINARY_DIR}/format")
83 SET(formatDirectory "${CMAKE_CURRENT_BINARY_DIR}/format")
83 FILE(MAKE_DIRECTORY ${formatDirectory})
84 FILE(MAKE_DIRECTORY ${formatDirectory})
85 # STRING(REPLACE "*.ui" "" srcs ${srcs})
86 FOREACH(item ${globs})
87 STRING(REGEX MATCH ".*\.ui$" item ${item})
88 IF(item)
89 LIST(APPEND UIS ${item})
90 ENDIF(item)
91 ENDFOREACH(item ${globs})
92
93 LIST(REMOVE_ITEM srcs ${UIS})
94 message("format lang: ${srcs}" )
84 FOREACH (s ${srcs})
95 FOREACH (s ${srcs})
85 SET(touchedFile ${formatDirectory}/format_touchedfile_${reportNb})
96 SET(touchedFile ${formatDirectory}/format_touchedfile_${reportNb})
86 IF(addToAll)
97 IF(addToAll)
87 ADD_CUSTOM_COMMAND(
98 ADD_CUSTOM_COMMAND(
88 OUTPUT ${touchedFile}
99 OUTPUT ${touchedFile}
89 COMMAND ${CLANGFORMAT_EXECUTABLE}
100 COMMAND ${CLANGFORMAT_EXECUTABLE}
90 -style="${style}"
101 -style="${style}"
91 -i
102 -i
92 ${s}
103 ${s}
93 # Create a file so that this command is executed only if the source
104 # Create a file so that this command is executed only if the source
94 # file is modified
105 # file is modified
95 COMMAND ${CMAKE_COMMAND} -E touch ${touchedFile}
106 COMMAND ${CMAKE_COMMAND} -E touch ${touchedFile}
96 DEPENDS ${s}
107 DEPENDS ${s}
97 COMMENT "Formatting code with clang-format of ${s}"
108 COMMENT "Formatting code with clang-format of ${s}"
98 )
109 )
99 ENDIF()
110 ENDIF()
100
111
101 SET(fakedTouchedFile ${formatDirectory}/format_fakedtouchedfile_${reportNb})
112 SET(fakedTouchedFile ${formatDirectory}/format_fakedtouchedfile_${reportNb})
102 ADD_CUSTOM_COMMAND(
113 ADD_CUSTOM_COMMAND(
103 OUTPUT ${fakedTouchedFile}
114 OUTPUT ${fakedTouchedFile}
104 COMMAND ${CLANGFORMAT_EXECUTABLE}
115 COMMAND ${CLANGFORMAT_EXECUTABLE}
105 -style="${style}"
116 -style="${style}"
106 -i
117 -i
107 ${s}
118 ${s}
108 DEPENDS ${s}
119 DEPENDS ${s}
109 COMMENT "Formatting code with clang-format of ${s}"
120 COMMENT "Formatting code with clang-format of ${s}"
110 )
121 )
111
122
112 LIST(APPEND touchedFiles ${touchedFile})
123 LIST(APPEND touchedFiles ${touchedFile})
113 LIST(APPEND fakedTouchedFiles ${fakedTouchedFile})
124 LIST(APPEND fakedTouchedFiles ${fakedTouchedFile})
114 clangformat_incr(reportNb)
125 clangformat_incr(reportNb)
115 ENDFOREACH()
126 ENDFOREACH()
116
127
117 # Create the custom targets that will trigger the custom command created
128 # Create the custom targets that will trigger the custom command created
118 # previously
129 # previously
119 IF(addToAll)
130 IF(addToAll)
120 ADD_CUSTOM_TARGET(${target_all} ALL DEPENDS ${touchedFiles})
131 ADD_CUSTOM_TARGET(${target_all} ALL DEPENDS ${touchedFiles})
121 ENDIF()
132 ENDIF()
122 ADD_CUSTOM_TARGET(${target} DEPENDS ${fakedTouchedFiles})
133 ADD_CUSTOM_TARGET(${target} DEPENDS ${fakedTouchedFiles})
123
134
124 ENDFUNCTION(ADD_CLANGFORMAT_TARGETS)
135 ENDFUNCTION(ADD_CLANGFORMAT_TARGETS)
125
136
126 macro(clangformat_incr var_name)
137 macro(clangformat_incr var_name)
127 math(EXPR ${var_name} "${${var_name}} + 1")
138 math(EXPR ${var_name} "${${var_name}} + 1")
128 endmacro()
139 endmacro()
@@ -1,16 +1,19
1 # On ignore toutes les règles vera++ pour le fichier spimpl
1 # On ignore toutes les règles vera++ pour le fichier spimpl
2
2
3 .*IPSIS_S04_METHOD.*found: Q_DECLARE_LOGGING_CATEGORY.*
3 .*IPSIS_S04_METHOD.*found: Q_DECLARE_LOGGING_CATEGORY.*
4 .*IPSIS_S04_VARIABLE.*found: impl.*
4 .*IPSIS_S04_VARIABLE.*found: impl.*
5
5
6 # Ignore false positive relative to 'noexcept' keyword
6 # Ignore false positive relative to 'noexcept' keyword
7 .*IPSIS_S04_VARIABLE.*found: noexcept
7 .*IPSIS_S04_VARIABLE.*found: noexcept
8 .*IPSIS_S06.*found: noexcept
8 .*IPSIS_S06.*found: noexcept
9
9
10 # Ignore false positive relative to 'override' keyword
10 # Ignore false positive relative to 'override' keyword
11 .*IPSIS_S04_VARIABLE.*found: override
11 .*IPSIS_S04_VARIABLE.*found: override
12 .*IPSIS_S06.*found: override
12 .*IPSIS_S06.*found: override
13
13
14 # Ignore false positive relative to 'final' keyword
14 # Ignore false positive relative to 'final' keyword
15 .*IPSIS_S04_VARIABLE.*found: final
15 .*IPSIS_S04_VARIABLE.*found: final
16 .*IPSIS_S06.*found: final
16 .*IPSIS_S06.*found: final
17
18 # Ignore false positive relative to unnamed namespace
19 .*IPSIS_F13.*
@@ -1,38 +1,39
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
1 #ifndef SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
2 #define SCIQLOP_DATASOURCEWIDGET_H
3
3
4 #include <QWidget>
4 #include <QWidget>
5
5
6 namespace Ui {
6 namespace Ui {
7 class DataSourceWidget;
7 class DataSourceWidget;
8 } // Ui
8 } // Ui
9
9
10 class DataSourceItem;
10 class DataSourceItem;
11
11
12 /**
12 /**
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
13 * @brief The DataSourceWidget handles the graphical representation (as a tree) of the data sources
14 * attached to SciQlop.
14 * attached to SciQlop.
15 */
15 */
16 class DataSourceWidget : public QWidget {
16 class DataSourceWidget : public QWidget {
17 Q_OBJECT
17 Q_OBJECT
18
18
19 public:
19 public:
20 explicit DataSourceWidget(QWidget *parent = 0);
20 explicit DataSourceWidget(QWidget *parent = 0);
21 virtual ~DataSourceWidget() noexcept;
21
22
22 public slots:
23 public slots:
23 /**
24 /**
24 * Adds a data source. An item associated to the data source is created and then added to the
25 * Adds a data source. An item associated to the data source is created and then added to the
25 * representation tree
26 * representation tree
26 * @param dataSource the data source to add. The pointer has to be not null
27 * @param dataSource the data source to add. The pointer has to be not null
27 */
28 */
28 void addDataSource(DataSourceItem *dataSource) noexcept;
29 void addDataSource(DataSourceItem *dataSource) noexcept;
29
30
30 private:
31 private:
31 Ui::DataSourceWidget *ui;
32 Ui::DataSourceWidget *ui;
32
33
33 private slots:
34 private slots:
34 /// Slot called when right clicking on an item in the tree (displays a menu)
35 /// Slot called when right clicking on an item in the tree (displays a menu)
35 void onTreeMenuRequested(const QPoint &pos) noexcept;
36 void onTreeMenuRequested(const QPoint &pos) noexcept;
36 };
37 };
37
38
38 #endif // SCIQLOP_DATASOURCEWIDGET_H
39 #endif // SCIQLOP_DATASOURCEWIDGET_H
@@ -1,32 +1,38
1 #ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H
1 #ifndef SCIQLOP_GRAPHPLOTTABLESFACTORY_H
2 #define SCIQLOP_GRAPHPLOTTABLESFACTORY_H
2 #define SCIQLOP_GRAPHPLOTTABLESFACTORY_H
3
3
4 #include <Data/SqpDateTime.h>
5
4 #include <QLoggingCategory>
6 #include <QLoggingCategory>
5 #include <QVector>
7 #include <QVector>
6
8
7 #include <memory>
9 #include <memory>
8
10
9 Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory)
11 Q_DECLARE_LOGGING_CATEGORY(LOG_GraphPlottablesFactory)
10
12
13 class IDataSeries;
11 class QCPAbstractPlottable;
14 class QCPAbstractPlottable;
12 class QCustomPlot;
15 class QCustomPlot;
13 class Variable;
16 class Variable;
14
17
15 /**
18 /**
16 * @brief The GraphPlottablesFactory class aims to create the QCustomPlot components relative to a
19 * @brief The GraphPlottablesFactory class aims to create the QCustomPlot components relative to a
17 * variable, depending on the data series of this variable
20 * variable, depending on the data series of this variable
18 */
21 */
19 struct GraphPlottablesFactory {
22 struct GraphPlottablesFactory {
20 /**
23 /**
21 * Creates (if possible) the QCustomPlot components relative to the variable passed in
24 * Creates (if possible) the QCustomPlot components relative to the variable passed in
22 * parameter, and adds these to the plot passed in parameter.
25 * parameter, and adds these to the plot passed in parameter.
23 * @param variable the variable for which to create the components
26 * @param variable the variable for which to create the components
24 * @param plot the plot in which to add the created components. It takes ownership of these
27 * @param plot the plot in which to add the created components. It takes ownership of these
25 * components.
28 * components.
26 * @return the list of the components created
29 * @return the list of the components created
27 */
30 */
28 static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable,
31 static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable,
29 QCustomPlot &plot) noexcept;
32 QCustomPlot &plot) noexcept;
33
34 static void updateData(QVector<QCPAbstractPlottable *> plotableVect, IDataSeries *dataSeries,
35 const SqpDateTime &dateTime);
30 };
36 };
31
37
32 #endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H
38 #endif // SCIQLOP_GRAPHPLOTTABLESFACTORY_H
@@ -1,44 +1,56
1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
2 #define SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <QLoggingCategory>
6 #include <QWidget>
7 #include <QWidget>
7
8
8 #include <memory>
9 #include <memory>
9
10
10 #include <Common/spimpl.h>
11 #include <Common/spimpl.h>
11
12
13 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationGraphWidget)
14
15 class QCPRange;
12 class Variable;
16 class Variable;
13
17
14 namespace Ui {
18 namespace Ui {
15 class VisualizationGraphWidget;
19 class VisualizationGraphWidget;
16 } // namespace Ui
20 } // namespace Ui
17
21
18 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
22 class VisualizationGraphWidget : public QWidget, public IVisualizationWidget {
19 Q_OBJECT
23 Q_OBJECT
20
24
21 public:
25 public:
22 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
26 explicit VisualizationGraphWidget(const QString &name = {}, QWidget *parent = 0);
23 virtual ~VisualizationGraphWidget();
27 virtual ~VisualizationGraphWidget();
24
28
25 void addVariable(std::shared_ptr<Variable> variable);
29 void addVariable(std::shared_ptr<Variable> variable);
26
30
27 // IVisualizationWidget interface
31 // IVisualizationWidget interface
28 void accept(IVisualizationWidgetVisitor *visitor) override;
32 void accept(IVisualizationWidgetVisitor *visitor) override;
29 bool canDrop(const Variable &variable) const override;
33 bool canDrop(const Variable &variable) const override;
30 void close() override;
34 void close() override;
31 QString name() const;
35 QString name() const override;
36
37 void updateDisplay(std::shared_ptr<Variable> variable);
38
32
39
33 private:
40 private:
34 Ui::VisualizationGraphWidget *ui;
41 Ui::VisualizationGraphWidget *ui;
35
42
36 class VisualizationGraphWidgetPrivate;
43 class VisualizationGraphWidgetPrivate;
37 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
44 spimpl::unique_impl_ptr<VisualizationGraphWidgetPrivate> impl;
38
45
39 private slots:
46 private slots:
47
48 void onRangeChanged(const QCPRange &t1, const QCPRange &t2);
49
40 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
50 /// Slot called when a mouse wheel was made, to perform some processing before the zoom is done
41 void onMouseWheel(QWheelEvent *event) noexcept;
51 void onMouseWheel(QWheelEvent *event) noexcept;
52
53 void onDataCacheVariableUpdated();
42 };
54 };
43
55
44 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
56 #endif // SCIQLOP_VISUALIZATIONGRAPHWIDGET_H
@@ -1,51 +1,54
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
2 #define SCIQLOP_VISUALIZATIONTABWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <Common/spimpl.h>
6 #include <Common/spimpl.h>
7
7
8 #include <QLoggingCategory>
8 #include <QWidget>
9 #include <QWidget>
9
10
11 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationTabWidget)
12
10 class Variable;
13 class Variable;
11 class VisualizationZoneWidget;
14 class VisualizationZoneWidget;
12
15
13 namespace Ui {
16 namespace Ui {
14 class VisualizationTabWidget;
17 class VisualizationTabWidget;
15 } // namespace Ui
18 } // namespace Ui
16
19
17 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
20 class VisualizationTabWidget : public QWidget, public IVisualizationWidget {
18 Q_OBJECT
21 Q_OBJECT
19
22
20 public:
23 public:
21 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
24 explicit VisualizationTabWidget(const QString &name = {}, QWidget *parent = 0);
22 virtual ~VisualizationTabWidget();
25 virtual ~VisualizationTabWidget();
23
26
24 /// Add a zone widget
27 /// Add a zone widget
25 void addZone(VisualizationZoneWidget *zoneWidget);
28 void addZone(VisualizationZoneWidget *zoneWidget);
26
29
27 /**
30 /**
28 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
31 * Creates a zone using a variable. The variable will be displayed in a new graph of the new
29 * zone.
32 * zone.
30 * @param variable the variable for which to create the zone
33 * @param variable the variable for which to create the zone
31 * @return the pointer to the created zone
34 * @return the pointer to the created zone
32 */
35 */
33 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
36 VisualizationZoneWidget *createZone(std::shared_ptr<Variable> variable);
34
37
35 /// Remove a zone
38 /// Remove a zone
36 void removeZone(VisualizationZoneWidget *zone);
39 void removeZone(VisualizationZoneWidget *zone);
37
40
38 // IVisualizationWidget interface
41 // IVisualizationWidget interface
39 void accept(IVisualizationWidgetVisitor *visitor) override;
42 void accept(IVisualizationWidgetVisitor *visitor) override;
40 bool canDrop(const Variable &variable) const override;
43 bool canDrop(const Variable &variable) const override;
41 void close() override;
44 void close() override;
42 QString name() const override;
45 QString name() const override;
43
46
44 private:
47 private:
45 Ui::VisualizationTabWidget *ui;
48 Ui::VisualizationTabWidget *ui;
46
49
47 class VisualizationTabWidgetPrivate;
50 class VisualizationTabWidgetPrivate;
48 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
51 spimpl::unique_impl_ptr<VisualizationTabWidgetPrivate> impl;
49 };
52 };
50
53
51 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
54 #endif // SCIQLOP_VISUALIZATIONTABWIDGET_H
@@ -1,53 +1,53
1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONWIDGET_H
2 #define SCIQLOP_VISUALIZATIONWIDGET_H
2 #define SCIQLOP_VISUALIZATIONWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <QLoggingCategory>
6 #include <QLoggingCategory>
7 #include <QWidget>
7 #include <QWidget>
8
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
10
9 class Variable;
11 class Variable;
10 class VisualizationTabWidget;
12 class VisualizationTabWidget;
11
13
12 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationWidget)
13
14 namespace Ui {
14 namespace Ui {
15 class VisualizationWidget;
15 class VisualizationWidget;
16 } // namespace Ui
16 } // namespace Ui
17
17
18 class VisualizationWidget : public QWidget, public IVisualizationWidget {
18 class VisualizationWidget : public QWidget, public IVisualizationWidget {
19 Q_OBJECT
19 Q_OBJECT
20
20
21 public:
21 public:
22 explicit VisualizationWidget(QWidget *parent = 0);
22 explicit VisualizationWidget(QWidget *parent = 0);
23 virtual ~VisualizationWidget();
23 virtual ~VisualizationWidget();
24
24
25 /// Add a zone widget
25 /// Add a zone widget
26 virtual void addTab(VisualizationTabWidget *tabWidget);
26 virtual void addTab(VisualizationTabWidget *tabWidget);
27
27
28 /// Create a tab using a Variable
28 /// Create a tab using a Variable
29 VisualizationTabWidget *createTab();
29 VisualizationTabWidget *createTab();
30
30
31 /// Remove a tab
31 /// Remove a tab
32 void removeTab(VisualizationTabWidget *tab);
32 void removeTab(VisualizationTabWidget *tab);
33
33
34 // IVisualizationWidget interface
34 // IVisualizationWidget interface
35 void accept(IVisualizationWidgetVisitor *visitor) override;
35 void accept(IVisualizationWidgetVisitor *visitor) override;
36 bool canDrop(const Variable &variable) const override;
36 bool canDrop(const Variable &variable) const override;
37 void close() override;
37 void close() override;
38 QString name() const;
38 QString name() const override;
39
39
40 public slots:
40 public slots:
41 /**
41 /**
42 * Displays a variable in a new graph of a new zone of the current tab
42 * Displays a variable in a new graph of a new zone of the current tab
43 * @param variable the variable to display
43 * @param variable the variable to display
44 * @todo this is a temporary method that will be replaced by own actions for each type of
44 * @todo this is a temporary method that will be replaced by own actions for each type of
45 * visualization widget
45 * visualization widget
46 */
46 */
47 void displayVariable(std::shared_ptr<Variable> variable) noexcept;
47 void displayVariable(std::shared_ptr<Variable> variable) noexcept;
48
48
49 private:
49 private:
50 Ui::VisualizationWidget *ui;
50 Ui::VisualizationWidget *ui;
51 };
51 };
52
52
53 #endif // VISUALIZATIONWIDGET_H
53 #endif // VISUALIZATIONWIDGET_H
@@ -1,45 +1,48
1 #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H
1 #ifndef SCIQLOP_VISUALIZATIONZONEWIDGET_H
2 #define SCIQLOP_VISUALIZATIONZONEWIDGET_H
2 #define SCIQLOP_VISUALIZATIONZONEWIDGET_H
3
3
4 #include "Visualization/IVisualizationWidget.h"
4 #include "Visualization/IVisualizationWidget.h"
5
5
6 #include <QLoggingCategory>
6 #include <QWidget>
7 #include <QWidget>
7
8
9 Q_DECLARE_LOGGING_CATEGORY(LOG_VisualizationZoneWidget)
10
8 namespace Ui {
11 namespace Ui {
9 class VisualizationZoneWidget;
12 class VisualizationZoneWidget;
10 } // Ui
13 } // Ui
11
14
12 class Variable;
15 class Variable;
13 class VisualizationGraphWidget;
16 class VisualizationGraphWidget;
14
17
15 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
18 class VisualizationZoneWidget : public QWidget, public IVisualizationWidget {
16 Q_OBJECT
19 Q_OBJECT
17
20
18 public:
21 public:
19 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
22 explicit VisualizationZoneWidget(const QString &name = {}, QWidget *parent = 0);
20 virtual ~VisualizationZoneWidget();
23 virtual ~VisualizationZoneWidget();
21
24
22 /// Add a graph widget
25 /// Add a graph widget
23 void addGraph(VisualizationGraphWidget *graphWidget);
26 void addGraph(VisualizationGraphWidget *graphWidget);
24
27
25 /**
28 /**
26 * Creates a graph using a variable. The variable will be displayed in the new graph.
29 * Creates a graph using a variable. The variable will be displayed in the new graph.
27 * @param variable the variable for which to create the graph
30 * @param variable the variable for which to create the graph
28 * @return the pointer to the created graph
31 * @return the pointer to the created graph
29 */
32 */
30 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
33 VisualizationGraphWidget *createGraph(std::shared_ptr<Variable> variable);
31
34
32 /// Remove a graph
35 /// Remove a graph
33 void removeGraph(VisualizationGraphWidget *graph);
36 void removeGraph(VisualizationGraphWidget *graph);
34
37
35 // IVisualizationWidget interface
38 // IVisualizationWidget interface
36 void accept(IVisualizationWidgetVisitor *visitor) override;
39 void accept(IVisualizationWidgetVisitor *visitor) override;
37 bool canDrop(const Variable &variable) const override;
40 bool canDrop(const Variable &variable) const override;
38 void close() override;
41 void close() override;
39 QString name() const override;
42 QString name() const override;
40
43
41 private:
44 private:
42 Ui::VisualizationZoneWidget *ui;
45 Ui::VisualizationZoneWidget *ui;
43 };
46 };
44
47
45 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
48 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
@@ -1,72 +1,77
1 #include <DataSource/DataSourceWidget.h>
1 #include <DataSource/DataSourceWidget.h>
2
2
3 #include <ui_DataSourceWidget.h>
3 #include <ui_DataSourceWidget.h>
4
4
5 #include <DataSource/DataSourceItem.h>
5 #include <DataSource/DataSourceItem.h>
6 #include <DataSource/DataSourceTreeWidgetItem.h>
6 #include <DataSource/DataSourceTreeWidgetItem.h>
7
7
8 #include <QMenu>
8 #include <QMenu>
9
9
10 namespace {
10 namespace {
11
11
12 /// Number of columns displayed in the tree
12 /// Number of columns displayed in the tree
13 const auto TREE_NB_COLUMNS = 1;
13 const auto TREE_NB_COLUMNS = 1;
14
14
15 /// Header labels for the tree
15 /// Header labels for the tree
16 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
16 const auto TREE_HEADER_LABELS = QStringList{QObject::tr("Name")};
17
17
18 /**
18 /**
19 * Creates the item associated to a data source
19 * Creates the item associated to a data source
20 * @param dataSource the data source for which to create the item
20 * @param dataSource the data source for which to create the item
21 * @return the new item
21 * @return the new item
22 */
22 */
23 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
23 DataSourceTreeWidgetItem *createTreeWidgetItem(DataSourceItem *dataSource)
24 {
24 {
25 // Creates item for the data source
25 // Creates item for the data source
26 auto item = new DataSourceTreeWidgetItem{dataSource};
26 auto item = new DataSourceTreeWidgetItem{dataSource};
27
27
28 // Generates items for the children of the data source
28 // Generates items for the children of the data source
29 for (auto i = 0; i < dataSource->childCount(); ++i) {
29 for (auto i = 0; i < dataSource->childCount(); ++i) {
30 item->addChild(createTreeWidgetItem(dataSource->child(i)));
30 item->addChild(createTreeWidgetItem(dataSource->child(i)));
31 }
31 }
32
32
33 return item;
33 return item;
34 }
34 }
35
35
36 } // namespace
36 } // namespace
37
37
38 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
38 DataSourceWidget::DataSourceWidget(QWidget *parent) : QWidget{parent}, ui{new Ui::DataSourceWidget}
39 {
39 {
40 ui->setupUi(this);
40 ui->setupUi(this);
41
41
42 // Set tree properties
42 // Set tree properties
43 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
43 ui->treeWidget->setColumnCount(TREE_NB_COLUMNS);
44 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
44 ui->treeWidget->setHeaderLabels(TREE_HEADER_LABELS);
45 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
45 ui->treeWidget->setContextMenuPolicy(Qt::CustomContextMenu);
46
46
47 // Connection to show a menu when right clicking on the tree
47 // Connection to show a menu when right clicking on the tree
48 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
48 connect(ui->treeWidget, &QTreeWidget::customContextMenuRequested, this,
49 &DataSourceWidget::onTreeMenuRequested);
49 &DataSourceWidget::onTreeMenuRequested);
50 }
50 }
51
51
52 DataSourceWidget::~DataSourceWidget() noexcept
53 {
54 delete ui;
55 }
56
52 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
57 void DataSourceWidget::addDataSource(DataSourceItem *dataSource) noexcept
53 {
58 {
54 // Creates the item associated to the source and adds it to the tree widget. The tree widget
59 // Creates the item associated to the source and adds it to the tree widget. The tree widget
55 // takes the ownership of the item
60 // takes the ownership of the item
56 if (dataSource) {
61 if (dataSource) {
57 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
62 ui->treeWidget->addTopLevelItem(createTreeWidgetItem(dataSource));
58 }
63 }
59 }
64 }
60
65
61 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
66 void DataSourceWidget::onTreeMenuRequested(const QPoint &pos) noexcept
62 {
67 {
63 // Retrieves the selected item in the tree, and build the menu from its actions
68 // Retrieves the selected item in the tree, and build the menu from its actions
64 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
69 if (auto selectedItem = dynamic_cast<DataSourceTreeWidgetItem *>(ui->treeWidget->itemAt(pos))) {
65 QMenu treeMenu{};
70 QMenu treeMenu{};
66 treeMenu.addActions(selectedItem->actions());
71 treeMenu.addActions(selectedItem->actions());
67
72
68 if (!treeMenu.isEmpty()) {
73 if (!treeMenu.isEmpty()) {
69 treeMenu.exec(mapToGlobal(pos));
74 treeMenu.exec(mapToGlobal(pos));
70 }
75 }
71 }
76 }
72 }
77 }
@@ -1,91 +1,151
1 #include "Visualization/GraphPlottablesFactory.h"
1 #include "Visualization/GraphPlottablesFactory.h"
2 #include "Visualization/qcustomplot.h"
2 #include "Visualization/qcustomplot.h"
3
3
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <Variable/Variable.h>
6 #include <Variable/Variable.h>
7
7
8 #include <QElapsedTimer>
9
8 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
10 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
9
11
10 namespace {
12 namespace {
11
13
12 /// Format for datetimes on a axis
14 /// Format for datetimes on a axis
13 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
15 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
14
16
15 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
17 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
16 /// non-time data
18 /// non-time data
17 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
19 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
18 {
20 {
19 if (isTimeAxis) {
21 if (isTimeAxis) {
20 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
22 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
21 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
23 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
22
24
23 return dateTicker;
25 return dateTicker;
24 }
26 }
25 else {
27 else {
26 // default ticker
28 // default ticker
27 return QSharedPointer<QCPAxisTicker>::create();
29 return QSharedPointer<QCPAxisTicker>::create();
28 }
30 }
29 }
31 }
30
32
31 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot)
33 void updateScalarData(QCPAbstractPlottable *component, ScalarSeries &scalarSeries,
34 const SqpDateTime &dateTime)
35 {
36 QElapsedTimer timer;
37 timer.start();
38 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
39 // Clean the graph
40 qCDebug(LOG_GraphPlottablesFactory()) << "The slow s1 operation took" << timer.elapsed()
41 << "milliseconds";
42 // NAIVE approch
43 const auto &xData = scalarSeries.xAxisData()->data();
44 const auto &valuesData = scalarSeries.valuesData()->data();
45
46 auto xValue = QVector<double>();
47 auto vValue = QVector<double>();
48
49 const auto count = xData.count();
50 auto ite = 0;
51 for (auto i = 0; i < count; ++i) {
52 const auto x = xData.at(i);
53 if (x >= dateTime.m_TStart && x <= dateTime.m_TEnd) {
54 xValue.push_back(x);
55 vValue.push_back(valuesData.at(i));
56 ++ite;
57 }
58 }
59
60 qcpGraph->setData(xValue, vValue);
61
62 qCDebug(LOG_GraphPlottablesFactory()) << "The slow s2 operation took" << timer.elapsed()
63 << "milliseconds";
64 }
65 else {
66 /// @todo DEBUG
67 }
68 }
69
70 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot,
71 const SqpDateTime &dateTime)
32 {
72 {
33 auto component = plot.addGraph();
73 auto component = plot.addGraph();
34
74
35 if (component) {
75 if (component) {
36 // Graph data
76 // // Graph data
37 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
77 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
38 true);
78 true);
39
79
80 updateScalarData(component, scalarSeries, dateTime);
81
40 // Axes properties
82 // Axes properties
41 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
83 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
42 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
84 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
43
85
44 auto setAxisProperties = [](auto axis, const auto &unit) {
86 auto setAxisProperties = [](auto axis, const auto &unit) {
45 // label (unit name)
87 // label (unit name)
46 axis->setLabel(unit.m_Name);
88 axis->setLabel(unit.m_Name);
47
89
48 // ticker (depending on the type of unit)
90 // ticker (depending on the type of unit)
49 axis->setTicker(axisTicker(unit.m_TimeUnit));
91 axis->setTicker(axisTicker(unit.m_TimeUnit));
50 };
92 };
51 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
93 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
52 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
94 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
53
95
54 // Display all data
96 // Display all data
55 component->rescaleAxes();
97 component->rescaleAxes();
56
98
57 plot.replot();
99 plot.replot();
58 }
100 }
59 else {
101 else {
60 qCDebug(LOG_GraphPlottablesFactory())
102 qCDebug(LOG_GraphPlottablesFactory())
61 << QObject::tr("Can't create graph for the scalar series");
103 << QObject::tr("Can't create graph for the scalar series");
62 }
104 }
63
105
64 return component;
106 return component;
65 }
107 }
66
108
67 } // namespace
109 } // namespace
68
110
69 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(std::shared_ptr<Variable> variable,
111 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(std::shared_ptr<Variable> variable,
70 QCustomPlot &plot) noexcept
112 QCustomPlot &plot) noexcept
71 {
113 {
72 auto result = QVector<QCPAbstractPlottable *>{};
114 auto result = QVector<QCPAbstractPlottable *>{};
73
115
74 if (variable) {
116 if (variable) {
75 // Gets the data series of the variable to call the creation of the right components
117 // Gets the data series of the variable to call the creation of the right components
76 // according to its type
118 // according to its type
77 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
119 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
78 result.append(createScalarSeriesComponent(*scalarSeries, plot));
120 result.append(createScalarSeriesComponent(*scalarSeries, plot, variable->dateTime()));
79 }
121 }
80 else {
122 else {
81 qCDebug(LOG_GraphPlottablesFactory())
123 qCDebug(LOG_GraphPlottablesFactory())
82 << QObject::tr("Can't create graph plottables : unmanaged data series type");
124 << QObject::tr("Can't create graph plottables : unmanaged data series type");
83 }
125 }
84 }
126 }
85 else {
127 else {
86 qCDebug(LOG_GraphPlottablesFactory())
128 qCDebug(LOG_GraphPlottablesFactory())
87 << QObject::tr("Can't create graph plottables : the variable is null");
129 << QObject::tr("Can't create graph plottables : the variable is null");
88 }
130 }
89
131
90 return result;
132 return result;
91 }
133 }
134
135 void GraphPlottablesFactory::updateData(QVector<QCPAbstractPlottable *> plotableVect,
136 IDataSeries *dataSeries, const SqpDateTime &dateTime)
137 {
138 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(dataSeries)) {
139 if (plotableVect.size() == 1) {
140 updateScalarData(plotableVect.at(0), *scalarSeries, dateTime);
141 }
142 else {
143 qCCritical(LOG_GraphPlottablesFactory()) << QObject::tr(
144 "Can't update Data of a scalarSeries because there is not only one component "
145 "associated");
146 }
147 }
148 else {
149 /// @todo DEBUG
150 }
151 }
@@ -1,105 +1,165
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/GraphPlottablesFactory.h"
2 #include "Visualization/GraphPlottablesFactory.h"
3 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/IVisualizationWidgetVisitor.h"
4 #include "ui_VisualizationGraphWidget.h"
4 #include "ui_VisualizationGraphWidget.h"
5
5
6 #include <Data/ArrayData.h>
7 #include <Data/IDataSeries.h>
8 #include <SqpApplication.h>
6 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
10 #include <Variable/VariableController.h>
7
11
8 #include <unordered_map>
12 #include <unordered_map>
9
13
14 Q_LOGGING_CATEGORY(LOG_VisualizationGraphWidget, "VisualizationGraphWidget")
15
10 namespace {
16 namespace {
11
17
12 /// Key pressed to enable zoom on horizontal axis
18 /// Key pressed to enable zoom on horizontal axis
13 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
19 const auto HORIZONTAL_ZOOM_MODIFIER = Qt::NoModifier;
14
20
15 /// Key pressed to enable zoom on vertical axis
21 /// Key pressed to enable zoom on vertical axis
16 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
22 const auto VERTICAL_ZOOM_MODIFIER = Qt::ControlModifier;
17
23
18 } // namespace
24 } // namespace
19
25
20 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
26 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
21
27
22 // 1 variable -> n qcpplot
28 // 1 variable -> n qcpplot
23 std::unordered_map<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMap;
29 std::unordered_multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *>
30 m_VariableToPlotMultiMap;
24 };
31 };
25
32
26 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
33 VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget *parent)
27 : QWidget{parent},
34 : QWidget{parent},
28 ui{new Ui::VisualizationGraphWidget},
35 ui{new Ui::VisualizationGraphWidget},
29 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
36 impl{spimpl::make_unique_impl<VisualizationGraphWidgetPrivate>()}
30 {
37 {
31 ui->setupUi(this);
38 ui->setupUi(this);
32
39
33 // qcpplot title
40 // qcpplot title
34 ui->widget->plotLayout()->insertRow(0);
41 ui->widget->plotLayout()->insertRow(0);
35 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
42 ui->widget->plotLayout()->addElement(0, 0, new QCPTextElement{ui->widget, name});
36
43
37 // Set qcpplot properties :
44 // Set qcpplot properties :
38 // - Drag (on x-axis) and zoom are enabled
45 // - Drag (on x-axis) and zoom are enabled
39 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
46 // - Mouse wheel on qcpplot is intercepted to determine the zoom orientation
40 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
47 ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
41 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
48 ui->widget->axisRect()->setRangeDrag(Qt::Horizontal);
42 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
49 connect(ui->widget, &QCustomPlot::mouseWheel, this, &VisualizationGraphWidget::onMouseWheel);
50 connect(ui->widget->xAxis, static_cast<void (QCPAxis::*)(const QCPRange &, const QCPRange &)>(
51 &QCPAxis::rangeChanged),
52 this, &VisualizationGraphWidget::onRangeChanged);
43 }
53 }
44
54
55
45 VisualizationGraphWidget::~VisualizationGraphWidget()
56 VisualizationGraphWidget::~VisualizationGraphWidget()
46 {
57 {
47 delete ui;
58 delete ui;
48 }
59 }
49
60
50 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
61 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable)
51 {
62 {
52 // Uses delegate to create the qcpplot components according to the variable
63 // Uses delegate to create the qcpplot components according to the variable
53 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
64 auto createdPlottables = GraphPlottablesFactory::create(variable, *ui->widget);
54
65
55 for (auto createdPlottable : qAsConst(createdPlottables)) {
66 for (auto createdPlottable : qAsConst(createdPlottables)) {
56 impl->m_VariableToPlotMap.insert({variable, createdPlottable});
67 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
57 }
68 }
69
70 connect(variable.get(), SIGNAL(dataCacheUpdated()), this, SLOT(onDataCacheVariableUpdated()));
58 }
71 }
59
72
60 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
73 void VisualizationGraphWidget::accept(IVisualizationWidgetVisitor *visitor)
61 {
74 {
62 if (visitor) {
75 if (visitor) {
63 visitor->visit(this);
76 visitor->visit(this);
64 }
77 }
78 else {
79 qCCritical(LOG_VisualizationGraphWidget())
80 << tr("Can't visit widget : the visitor is null");
81 }
65 }
82 }
66
83
67 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
84 bool VisualizationGraphWidget::canDrop(const Variable &variable) const
68 {
85 {
69 /// @todo : for the moment, a graph can always accomodate a variable
86 /// @todo : for the moment, a graph can always accomodate a variable
70 Q_UNUSED(variable);
87 Q_UNUSED(variable);
71 return true;
88 return true;
72 }
89 }
73
90
74 void VisualizationGraphWidget::close()
91 void VisualizationGraphWidget::close()
75 {
92 {
76 // The main view cannot be directly closed.
93 // The main view cannot be directly closed.
77 return;
94 return;
78 }
95 }
79
96
80 QString VisualizationGraphWidget::name() const
97 QString VisualizationGraphWidget::name() const
81 {
98 {
82 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
99 if (auto title = dynamic_cast<QCPTextElement *>(ui->widget->plotLayout()->elementAt(0))) {
83 return title->text();
100 return title->text();
84 }
101 }
85 else {
102 else {
86 return QString{};
103 return QString{};
87 }
104 }
88 }
105 }
89
106
107 void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2)
108 {
109
110 qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged");
111
112 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
113 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
114 auto variable = it->first;
115 auto tolerance = 0.1 * (t2.upper - t2.lower);
116 auto dateTime = SqpDateTime{t2.lower - tolerance, t2.upper + tolerance};
117
118 qCInfo(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::onRangeChanged")
119 << variable->dataSeries()->xAxisData()->size();
120 if (!variable->contains(dateTime)) {
121 sqpApp->variableController().requestDataLoading(variable, dateTime);
122 }
123 }
124 }
125
90 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
126 void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept
91 {
127 {
92 auto zoomOrientations = QFlags<Qt::Orientation>{};
128 auto zoomOrientations = QFlags<Qt::Orientation>{};
93
129
94 // Lambda that enables a zoom orientation if the key modifier related to this orientation has
130 // Lambda that enables a zoom orientation if the key modifier related to this orientation has
95 // been pressed
131 // been pressed
96 auto enableOrientation
132 auto enableOrientation
97 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
133 = [&zoomOrientations, event](const auto &orientation, const auto &modifier) {
98 auto orientationEnabled = event->modifiers().testFlag(modifier);
134 auto orientationEnabled = event->modifiers().testFlag(modifier);
99 zoomOrientations.setFlag(orientation, orientationEnabled);
135 zoomOrientations.setFlag(orientation, orientationEnabled);
100 };
136 };
101 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
137 enableOrientation(Qt::Vertical, VERTICAL_ZOOM_MODIFIER);
102 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
138 enableOrientation(Qt::Horizontal, HORIZONTAL_ZOOM_MODIFIER);
103
139
104 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
140 ui->widget->axisRect()->setRangeZoom(zoomOrientations);
105 }
141 }
142
143 void VisualizationGraphWidget::onDataCacheVariableUpdated()
144 {
145 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
146 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
147 auto variable = it->first;
148 GraphPlottablesFactory::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
149 variable->dataSeries(), variable->dateTime());
150 }
151 }
152
153 void VisualizationGraphWidget::updateDisplay(std::shared_ptr<Variable> variable)
154 {
155 auto abstractPlotableItPair = impl->m_VariableToPlotMultiMap.equal_range(variable);
156
157 auto abstractPlotableVect = QVector<QCPAbstractPlottable *>{};
158
159 for (auto it = abstractPlotableItPair.first; it != abstractPlotableItPair.second; ++it) {
160 abstractPlotableVect.push_back(it->second);
161 }
162
163 GraphPlottablesFactory::updateData(abstractPlotableVect, variable->dataSeries(),
164 variable->dateTime());
165 }
@@ -1,99 +1,105
1 #include "Visualization/VisualizationTabWidget.h"
1 #include "Visualization/VisualizationTabWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "ui_VisualizationTabWidget.h"
3 #include "ui_VisualizationTabWidget.h"
4
4
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6
6
7 Q_LOGGING_CATEGORY(LOG_VisualizationTabWidget, "VisualizationTabWidget")
8
7 namespace {
9 namespace {
8
10
9 /// Generates a default name for a new zone, according to the number of zones already displayed in
11 /// Generates a default name for a new zone, according to the number of zones already displayed in
10 /// the tab
12 /// the tab
11 QString defaultZoneName(const QLayout &layout)
13 QString defaultZoneName(const QLayout &layout)
12 {
14 {
13 auto count = 0;
15 auto count = 0;
14 for (auto i = 0; i < layout.count(); ++i) {
16 for (auto i = 0; i < layout.count(); ++i) {
15 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
17 if (dynamic_cast<VisualizationZoneWidget *>(layout.itemAt(i)->widget())) {
16 count++;
18 count++;
17 }
19 }
18 }
20 }
19
21
20 return QObject::tr("Zone %1").arg(count + 1);
22 return QObject::tr("Zone %1").arg(count + 1);
21 }
23 }
22
24
23 } // namespace
25 } // namespace
24
26
25 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
27 struct VisualizationTabWidget::VisualizationTabWidgetPrivate {
26 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
28 explicit VisualizationTabWidgetPrivate(const QString &name) : m_Name{name} {}
27
29
28 QString m_Name;
30 QString m_Name;
29 };
31 };
30
32
31 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
33 VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *parent)
32 : QWidget{parent},
34 : QWidget{parent},
33 ui{new Ui::VisualizationTabWidget},
35 ui{new Ui::VisualizationTabWidget},
34 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
36 impl{spimpl::make_unique_impl<VisualizationTabWidgetPrivate>(name)}
35 {
37 {
36 ui->setupUi(this);
38 ui->setupUi(this);
37 }
39 }
38
40
39 VisualizationTabWidget::~VisualizationTabWidget()
41 VisualizationTabWidget::~VisualizationTabWidget()
40 {
42 {
41 delete ui;
43 delete ui;
42 }
44 }
43
45
44 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
46 void VisualizationTabWidget::addZone(VisualizationZoneWidget *zoneWidget)
45 {
47 {
46 this->layout()->addWidget(zoneWidget);
48 this->layout()->addWidget(zoneWidget);
47 }
49 }
48
50
49 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
51 VisualizationZoneWidget *VisualizationTabWidget::createZone(std::shared_ptr<Variable> variable)
50 {
52 {
51 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
53 auto zoneWidget = new VisualizationZoneWidget{defaultZoneName(*layout()), this};
52 this->addZone(zoneWidget);
54 this->addZone(zoneWidget);
53
55
54 // Creates a new graph into the zone
56 // Creates a new graph into the zone
55 zoneWidget->createGraph(variable);
57 zoneWidget->createGraph(variable);
56
58
57 return zoneWidget;
59 return zoneWidget;
58 }
60 }
59
61
60 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
62 void VisualizationTabWidget::removeZone(VisualizationZoneWidget *zone)
61 {
63 {
62 }
64 }
63
65
64 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
66 void VisualizationTabWidget::accept(IVisualizationWidgetVisitor *visitor)
65 {
67 {
66 if (visitor) {
68 if (visitor) {
67 visitor->visitEnter(this);
69 visitor->visitEnter(this);
68
70
69 // Apply visitor to zone children
71 // Apply visitor to zone children
70 for (auto i = 0; i < layout()->count(); ++i) {
72 for (auto i = 0; i < layout()->count(); ++i) {
71 if (auto item = layout()->itemAt(i)) {
73 if (auto item = layout()->itemAt(i)) {
74 // Widgets different from zones are not visited (no action)
72 if (auto visualizationZoneWidget
75 if (auto visualizationZoneWidget
73 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
76 = dynamic_cast<VisualizationZoneWidget *>(item->widget())) {
74 visualizationZoneWidget->accept(visitor);
77 visualizationZoneWidget->accept(visitor);
75 }
78 }
76 }
79 }
77 }
80 }
78
81
79 visitor->visitLeave(this);
82 visitor->visitLeave(this);
80 }
83 }
84 else {
85 qCCritical(LOG_VisualizationTabWidget()) << tr("Can't visit widget : the visitor is null");
86 }
81 }
87 }
82
88
83 bool VisualizationTabWidget::canDrop(const Variable &variable) const
89 bool VisualizationTabWidget::canDrop(const Variable &variable) const
84 {
90 {
85 // A tab can always accomodate a variable
91 // A tab can always accomodate a variable
86 Q_UNUSED(variable);
92 Q_UNUSED(variable);
87 return true;
93 return true;
88 }
94 }
89
95
90 void VisualizationTabWidget::close()
96 void VisualizationTabWidget::close()
91 {
97 {
92 // The main view cannot be directly closed.
98 // The main view cannot be directly closed.
93 return;
99 return;
94 }
100 }
95
101
96 QString VisualizationTabWidget::name() const
102 QString VisualizationTabWidget::name() const
97 {
103 {
98 return impl->m_Name;
104 return impl->m_Name;
99 }
105 }
@@ -1,132 +1,136
1 #include "Visualization/VisualizationWidget.h"
1 #include "Visualization/VisualizationWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/VisualizationGraphWidget.h"
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/qcustomplot.h"
6 #include "Visualization/qcustomplot.h"
7
7
8 #include "ui_VisualizationWidget.h"
8 #include "ui_VisualizationWidget.h"
9
9
10 #include <QToolButton>
10 #include <QToolButton>
11
11
12 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
12 Q_LOGGING_CATEGORY(LOG_VisualizationWidget, "VisualizationWidget")
13
13
14 VisualizationWidget::VisualizationWidget(QWidget *parent)
14 VisualizationWidget::VisualizationWidget(QWidget *parent)
15 : QWidget{parent}, ui{new Ui::VisualizationWidget}
15 : QWidget{parent}, ui{new Ui::VisualizationWidget}
16 {
16 {
17 ui->setupUi(this);
17 ui->setupUi(this);
18
18
19 auto addTabViewButton = new QToolButton{ui->tabWidget};
19 auto addTabViewButton = new QToolButton{ui->tabWidget};
20 addTabViewButton->setText(tr("Add View"));
20 addTabViewButton->setText(tr("Add View"));
21 addTabViewButton->setCursor(Qt::ArrowCursor);
21 addTabViewButton->setCursor(Qt::ArrowCursor);
22 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
22 ui->tabWidget->setCornerWidget(addTabViewButton, Qt::TopRightCorner);
23
23
24 auto enableMinimumCornerWidgetSize = [this](bool enable) {
24 auto enableMinimumCornerWidgetSize = [this](bool enable) {
25
25
26 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
26 auto tabViewCornerWidget = ui->tabWidget->cornerWidget();
27 auto width = enable ? tabViewCornerWidget->width() : 0;
27 auto width = enable ? tabViewCornerWidget->width() : 0;
28 auto height = enable ? tabViewCornerWidget->height() : 0;
28 auto height = enable ? tabViewCornerWidget->height() : 0;
29 tabViewCornerWidget->setMinimumHeight(height);
29 tabViewCornerWidget->setMinimumHeight(height);
30 tabViewCornerWidget->setMinimumWidth(width);
30 tabViewCornerWidget->setMinimumWidth(width);
31 ui->tabWidget->setMinimumHeight(height);
31 ui->tabWidget->setMinimumHeight(height);
32 ui->tabWidget->setMinimumWidth(width);
32 ui->tabWidget->setMinimumWidth(width);
33 };
33 };
34
34
35 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
35 auto addTabView = [this, enableMinimumCornerWidgetSize]() {
36 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
36 auto widget = new VisualizationTabWidget{QString{"View %1"}.arg(ui->tabWidget->count() + 1),
37 ui->tabWidget};
37 ui->tabWidget};
38 auto index = ui->tabWidget->addTab(widget, widget->name());
38 auto index = ui->tabWidget->addTab(widget, widget->name());
39 if (ui->tabWidget->count() > 0) {
39 if (ui->tabWidget->count() > 0) {
40 enableMinimumCornerWidgetSize(false);
40 enableMinimumCornerWidgetSize(false);
41 }
41 }
42 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
42 qCInfo(LOG_VisualizationWidget()) << tr("add the tab of index %1").arg(index);
43 };
43 };
44
44
45 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
45 auto removeTabView = [this, enableMinimumCornerWidgetSize](int index) {
46 if (ui->tabWidget->count() == 1) {
46 if (ui->tabWidget->count() == 1) {
47 enableMinimumCornerWidgetSize(true);
47 enableMinimumCornerWidgetSize(true);
48 }
48 }
49
49
50 ui->tabWidget->removeTab(index);
50 ui->tabWidget->removeTab(index);
51 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
51 qCInfo(LOG_VisualizationWidget()) << tr("remove the tab of index %1").arg(index);
52
52
53 };
53 };
54
54
55 ui->tabWidget->setTabsClosable(true);
55 ui->tabWidget->setTabsClosable(true);
56
56
57 connect(addTabViewButton, &QToolButton::clicked, addTabView);
57 connect(addTabViewButton, &QToolButton::clicked, addTabView);
58 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
58 connect(ui->tabWidget, &QTabWidget::tabCloseRequested, removeTabView);
59
59
60 // Adds default tab
60 // Adds default tab
61 addTabView();
61 addTabView();
62 }
62 }
63
63
64 VisualizationWidget::~VisualizationWidget()
64 VisualizationWidget::~VisualizationWidget()
65 {
65 {
66 delete ui;
66 delete ui;
67 }
67 }
68
68
69 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
69 void VisualizationWidget::addTab(VisualizationTabWidget *tabWidget)
70 {
70 {
71 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
71 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
72 // lambda function (in the constructor)
72 // lambda function (in the constructor)
73 }
73 }
74
74
75 VisualizationTabWidget *VisualizationWidget::createTab()
75 VisualizationTabWidget *VisualizationWidget::createTab()
76 {
76 {
77 }
77 }
78
78
79 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
79 void VisualizationWidget::removeTab(VisualizationTabWidget *tab)
80 {
80 {
81 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
81 // NOTE: check is this method has to be deleted because of its dupplicated version visible as
82 // lambda function (in the constructor)
82 // lambda function (in the constructor)
83 }
83 }
84
84
85 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
85 void VisualizationWidget::accept(IVisualizationWidgetVisitor *visitor)
86 {
86 {
87 if (visitor) {
87 if (visitor) {
88 visitor->visitEnter(this);
88 visitor->visitEnter(this);
89
89
90 // Apply visitor for tab children
90 // Apply visitor for tab children
91 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
91 for (auto i = 0; i < ui->tabWidget->count(); ++i) {
92 // Widgets different from tabs are not visited (no action)
92 if (auto visualizationTabWidget
93 if (auto visualizationTabWidget
93 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
94 = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->widget(i))) {
94 visualizationTabWidget->accept(visitor);
95 visualizationTabWidget->accept(visitor);
95 }
96 }
96 }
97 }
97
98
98 visitor->visitLeave(this);
99 visitor->visitLeave(this);
99 }
100 }
101 else {
102 qCCritical(LOG_VisualizationWidget()) << tr("Can't visit widget : the visitor is null");
103 }
100 }
104 }
101
105
102 bool VisualizationWidget::canDrop(const Variable &variable) const
106 bool VisualizationWidget::canDrop(const Variable &variable) const
103 {
107 {
104 // The main widget can never accomodate a variable
108 // The main widget can never accomodate a variable
105 Q_UNUSED(variable);
109 Q_UNUSED(variable);
106 return false;
110 return false;
107 }
111 }
108
112
109 void VisualizationWidget::close()
113 void VisualizationWidget::close()
110 {
114 {
111 // The main view cannot be directly closed.
115 // The main view cannot be directly closed.
112 return;
116 return;
113 }
117 }
114
118
115 QString VisualizationWidget::name() const
119 QString VisualizationWidget::name() const
116 {
120 {
117 return QStringLiteral("MainView");
121 return QStringLiteral("MainView");
118 }
122 }
119
123
120 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
124 void VisualizationWidget::displayVariable(std::shared_ptr<Variable> variable) noexcept
121 {
125 {
122 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
126 if (auto currentTab = dynamic_cast<VisualizationTabWidget *>(ui->tabWidget->currentWidget())) {
123 if (!currentTab->createZone(variable)) {
127 if (!currentTab->createZone(variable)) {
124 qCCritical(LOG_VisualizationWidget())
128 qCCritical(LOG_VisualizationWidget())
125 << tr("Can't display the variable : can't create a new zone in the current tab");
129 << tr("Can't display the variable : can't create a new zone in the current tab");
126 }
130 }
127 }
131 }
128 else {
132 else {
129 qCCritical(LOG_VisualizationWidget())
133 qCCritical(LOG_VisualizationWidget())
130 << tr("Can't display the variable : there is no current tab");
134 << tr("Can't display the variable : there is no current tab");
131 }
135 }
132 }
136 }
@@ -1,94 +1,100
1 #include "Visualization/VisualizationZoneWidget.h"
1 #include "Visualization/VisualizationZoneWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "ui_VisualizationZoneWidget.h"
3 #include "ui_VisualizationZoneWidget.h"
4
4
5 #include "Visualization/VisualizationGraphWidget.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6
6
7 Q_LOGGING_CATEGORY(LOG_VisualizationZoneWidget, "VisualizationZoneWidget")
8
7 namespace {
9 namespace {
8
10
9 /// Generates a default name for a new graph, according to the number of graphs already displayed in
11 /// Generates a default name for a new graph, according to the number of graphs already displayed in
10 /// the zone
12 /// the zone
11 QString defaultGraphName(const QLayout &layout)
13 QString defaultGraphName(const QLayout &layout)
12 {
14 {
13 auto count = 0;
15 auto count = 0;
14 for (auto i = 0; i < layout.count(); ++i) {
16 for (auto i = 0; i < layout.count(); ++i) {
15 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
17 if (dynamic_cast<VisualizationGraphWidget *>(layout.itemAt(i)->widget())) {
16 count++;
18 count++;
17 }
19 }
18 }
20 }
19
21
20 return QObject::tr("Graph %1").arg(count + 1);
22 return QObject::tr("Graph %1").arg(count + 1);
21 }
23 }
22
24
23 } // namespace
25 } // namespace
24
26
25 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
27 VisualizationZoneWidget::VisualizationZoneWidget(const QString &name, QWidget *parent)
26 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
28 : QWidget{parent}, ui{new Ui::VisualizationZoneWidget}
27 {
29 {
28 ui->setupUi(this);
30 ui->setupUi(this);
29
31
30 ui->zoneNameLabel->setText(name);
32 ui->zoneNameLabel->setText(name);
31 }
33 }
32
34
33 VisualizationZoneWidget::~VisualizationZoneWidget()
35 VisualizationZoneWidget::~VisualizationZoneWidget()
34 {
36 {
35 delete ui;
37 delete ui;
36 }
38 }
37
39
38 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
40 void VisualizationZoneWidget::addGraph(VisualizationGraphWidget *graphWidget)
39 {
41 {
40 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
42 ui->visualizationZoneFrame->layout()->addWidget(graphWidget);
41 }
43 }
42
44
43 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
45 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<Variable> variable)
44 {
46 {
45 auto graphWidget = new VisualizationGraphWidget{
47 auto graphWidget = new VisualizationGraphWidget{
46 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
48 defaultGraphName(*ui->visualizationZoneFrame->layout()), this};
47 this->addGraph(graphWidget);
49 this->addGraph(graphWidget);
48
50
49 graphWidget->addVariable(variable);
51 graphWidget->addVariable(variable);
50
52
51 return graphWidget;
53 return graphWidget;
52 }
54 }
53
55
54 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
56 void VisualizationZoneWidget::removeGraph(VisualizationGraphWidget *graph)
55 {
57 {
56 }
58 }
57
59
58 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
60 void VisualizationZoneWidget::accept(IVisualizationWidgetVisitor *visitor)
59 {
61 {
60 if (visitor) {
62 if (visitor) {
61 visitor->visitEnter(this);
63 visitor->visitEnter(this);
62
64
63 // Apply visitor to graph children
65 // Apply visitor to graph children
64 auto layout = ui->visualizationZoneFrame->layout();
66 auto layout = ui->visualizationZoneFrame->layout();
65 for (auto i = 0; i < layout->count(); ++i) {
67 for (auto i = 0; i < layout->count(); ++i) {
66 if (auto item = layout->itemAt(i)) {
68 if (auto item = layout->itemAt(i)) {
69 // Widgets different from graphs are not visited (no action)
67 if (auto visualizationGraphWidget
70 if (auto visualizationGraphWidget
68 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
71 = dynamic_cast<VisualizationGraphWidget *>(item->widget())) {
69 visualizationGraphWidget->accept(visitor);
72 visualizationGraphWidget->accept(visitor);
70 }
73 }
71 }
74 }
72 }
75 }
73
76
74 visitor->visitLeave(this);
77 visitor->visitLeave(this);
75 }
78 }
79 else {
80 qCCritical(LOG_VisualizationZoneWidget()) << tr("Can't visit widget : the visitor is null");
81 }
76 }
82 }
77
83
78 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
84 bool VisualizationZoneWidget::canDrop(const Variable &variable) const
79 {
85 {
80 // A tab can always accomodate a variable
86 // A tab can always accomodate a variable
81 Q_UNUSED(variable);
87 Q_UNUSED(variable);
82 return true;
88 return true;
83 }
89 }
84
90
85 void VisualizationZoneWidget::close()
91 void VisualizationZoneWidget::close()
86 {
92 {
87 // The main view cannot be directly closed.
93 // The main view cannot be directly closed.
88 return;
94 return;
89 }
95 }
90
96
91 QString VisualizationZoneWidget::name() const
97 QString VisualizationZoneWidget::name() const
92 {
98 {
93 return ui->zoneNameLabel->text();
99 return ui->zoneNameLabel->text();
94 }
100 }
@@ -1,200 +1,130
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
1 #include "Visualization/operations/GenerateVariableMenuOperation.h"
2 #include "Visualization/operations/MenuBuilder.h"
2
3
3 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationGraphWidget.h"
4 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationTabWidget.h"
5 #include "Visualization/VisualizationZoneWidget.h"
6 #include "Visualization/VisualizationZoneWidget.h"
6
7
7 #include <Variable/Variable.h>
8 #include <Variable/Variable.h>
8
9
9 #include <QMenu>
10 #include <QMenu>
10 #include <QStack>
11 #include <QStack>
11
12
12 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13 Q_LOGGING_CATEGORY(LOG_GenerateVariableMenuOperation, "GenerateVariableMenuOperation")
13
14
14 namespace {
15
16 /// Helper assigned to build the hierarchical menu associated with a variable
17 struct MenuBuilder {
18 /**
19 * Ctor
20 * @param menu the parent menu
21 */
22 explicit MenuBuilder(QMenu *menu)
23 {
24 if (menu) {
25 m_Menus.push(menu);
26 }
27 else {
28 qCCritical(LOG_GenerateVariableMenuOperation())
29 << QObject::tr("No parent menu has been defined");
30 }
31 }
32
33 /**
34 * Adds action to the current menu
35 * @param actionName the name of the action
36 * @param actionFunction the function that will be executed when the action is triggered
37 */
38 template <typename ActionFun>
39 void addAction(const QString &actionName, ActionFun actionFunction)
40 {
41 if (auto currMenu = currentMenu()) {
42 currMenu->addAction(actionName, actionFunction);
43 }
44 else {
45 qCCritical(LOG_GenerateVariableMenuOperation())
46 << QObject::tr("No current menu to attach the action");
47 }
48 }
49
50 /**
51 * Adds a new menu to the current menu
52 * @param name the name of the menu
53 */
54 void addMenu(const QString &name)
55 {
56 if (auto currMenu = currentMenu()) {
57 m_Menus.push(currMenu->addMenu(name));
58 }
59 else {
60 qCCritical(LOG_GenerateVariableMenuOperation())
61 << QObject::tr("No current menu to attach the new menu");
62 }
63 }
64
65 /// Adds a separator to the current menu. The separator is added only if the menu already
66 /// contains entries
67 void addSeparator()
68 {
69 if (auto currMenu = currentMenu()) {
70 if (!currMenu->isEmpty()) {
71 currMenu->addSeparator();
72 }
73 }
74 else {
75 qCCritical(LOG_GenerateVariableMenuOperation())
76 << QObject::tr("No current menu to attach the separator");
77 }
78 }
79
80 /// Closes the current menu
81 void closeMenu()
82 {
83 if (!m_Menus.isEmpty()) {
84 if (auto closedMenu = m_Menus.pop()) {
85 // Purge menu : if the closed menu has no entries, we remove it from its parent (the
86 // current menu)
87 if (auto currMenu = currentMenu()) {
88 if (closedMenu->isEmpty()) {
89 currMenu->removeAction(closedMenu->menuAction());
90 }
91 }
92 }
93 }
94 }
95
96 /// Gets the current menu (i.e. the top menu of the stack)
97 QMenu *currentMenu() const { return !m_Menus.isEmpty() ? m_Menus.top() : nullptr; }
98
99 /// Stack of all menus currently opened
100 QStack<QMenu *> m_Menus{};
101 };
102
103 } // namespace
104
105 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
15 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
106 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
16 explicit GenerateVariableMenuOperationPrivate(QMenu *menu, std::shared_ptr<Variable> variable)
107 : m_Variable{variable}, m_MenuBuilder{menu}
17 : m_Variable{variable}, m_MenuBuilder{menu}
108 {
18 {
109 }
19 }
110
20
111 void visitNodeEnter(const IVisualizationWidget &container)
21 void visitNodeEnter(const IVisualizationWidget &container)
112 {
22 {
113 // Opens a new menu associated to the node
23 // Opens a new menu associated to the node
114 m_MenuBuilder.addMenu(container.name());
24 m_MenuBuilder.addMenu(container.name());
115 }
25 }
116
26
117 template <typename ActionFun>
27 template <typename ActionFun>
118 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
28 void visitNodeLeave(const IVisualizationWidget &container, const QString &actionName,
119 ActionFun actionFunction)
29 ActionFun actionFunction)
120 {
30 {
121 if (m_Variable && container.canDrop(*m_Variable)) {
31 if (m_Variable && container.canDrop(*m_Variable)) {
122 m_MenuBuilder.addSeparator();
32 m_MenuBuilder.addSeparator();
123 m_MenuBuilder.addAction(actionName, actionFunction);
33 m_MenuBuilder.addAction(actionName, actionFunction);
124 }
34 }
125
35
126 // Closes the menu associated to the node
36 // Closes the menu associated to the node
127 m_MenuBuilder.closeMenu();
37 m_MenuBuilder.closeMenu();
128 }
38 }
129
39
130 template <typename ActionFun>
40 template <typename ActionFun>
131 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
41 void visitLeaf(const IVisualizationWidget &container, const QString &actionName,
132 ActionFun actionFunction)
42 ActionFun actionFunction)
133 {
43 {
134 if (m_Variable && container.canDrop(*m_Variable)) {
44 if (m_Variable && container.canDrop(*m_Variable)) {
135 m_MenuBuilder.addAction(actionName, actionFunction);
45 m_MenuBuilder.addAction(actionName, actionFunction);
136 }
46 }
137 }
47 }
138
48
139 std::shared_ptr<Variable> m_Variable;
49 std::shared_ptr<Variable> m_Variable;
140 MenuBuilder m_MenuBuilder;
50 MenuBuilder m_MenuBuilder;
141 };
51 };
142
52
143 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
53 GenerateVariableMenuOperation::GenerateVariableMenuOperation(QMenu *menu,
144 std::shared_ptr<Variable> variable)
54 std::shared_ptr<Variable> variable)
145 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
55 : impl{spimpl::make_unique_impl<GenerateVariableMenuOperationPrivate>(menu, variable)}
146 {
56 {
147 }
57 }
148
58
149 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
59 void GenerateVariableMenuOperation::visitEnter(VisualizationWidget *widget)
150 {
60 {
151 // VisualizationWidget is not intended to accommodate a variable
61 // VisualizationWidget is not intended to accommodate a variable
152 Q_UNUSED(widget)
62 Q_UNUSED(widget)
153 }
63 }
154
64
155 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
65 void GenerateVariableMenuOperation::visitLeave(VisualizationWidget *widget)
156 {
66 {
157 // VisualizationWidget is not intended to accommodate a variable
67 // VisualizationWidget is not intended to accommodate a variable
158 Q_UNUSED(widget)
68 Q_UNUSED(widget)
159 }
69 }
160
70
161 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
71 void GenerateVariableMenuOperation::visitEnter(VisualizationTabWidget *tabWidget)
162 {
72 {
163 if (tabWidget) {
73 if (tabWidget) {
164 impl->visitNodeEnter(*tabWidget);
74 impl->visitNodeEnter(*tabWidget);
165 }
75 }
76 else {
77 qCCritical(LOG_GenerateVariableMenuOperation(),
78 "Can't visit enter VisualizationTabWidget : the widget is null");
79 }
166 }
80 }
167
81
168 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
82 void GenerateVariableMenuOperation::visitLeave(VisualizationTabWidget *tabWidget)
169 {
83 {
170 if (tabWidget) {
84 if (tabWidget) {
171 impl->visitNodeLeave(
85 impl->visitNodeLeave(
172 *tabWidget, QObject::tr("Open in a new zone"),
86 *tabWidget, QObject::tr("Open in a new zone"),
173 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
87 [ var = impl->m_Variable, tabWidget ]() { tabWidget->createZone(var); });
174 }
88 }
89 else {
90 qCCritical(LOG_GenerateVariableMenuOperation(),
91 "Can't visit leave VisualizationTabWidget : the widget is null");
92 }
175 }
93 }
176
94
177 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
95 void GenerateVariableMenuOperation::visitEnter(VisualizationZoneWidget *zoneWidget)
178 {
96 {
179 if (zoneWidget) {
97 if (zoneWidget) {
180 impl->visitNodeEnter(*zoneWidget);
98 impl->visitNodeEnter(*zoneWidget);
181 }
99 }
100 else {
101 qCCritical(LOG_GenerateVariableMenuOperation(),
102 "Can't visit enter VisualizationZoneWidget : the widget is null");
103 }
182 }
104 }
183
105
184 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
106 void GenerateVariableMenuOperation::visitLeave(VisualizationZoneWidget *zoneWidget)
185 {
107 {
186 if (zoneWidget) {
108 if (zoneWidget) {
187 impl->visitNodeLeave(
109 impl->visitNodeLeave(
188 *zoneWidget, QObject::tr("Open in a new graph"),
110 *zoneWidget, QObject::tr("Open in a new graph"),
189 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
111 [ var = impl->m_Variable, zoneWidget ]() { zoneWidget->createGraph(var); });
190 }
112 }
113 else {
114 qCCritical(LOG_GenerateVariableMenuOperation(),
115 "Can't visit leave VisualizationZoneWidget : the widget is null");
116 }
191 }
117 }
192
118
193 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
119 void GenerateVariableMenuOperation::visit(VisualizationGraphWidget *graphWidget)
194 {
120 {
195 if (graphWidget) {
121 if (graphWidget) {
196 impl->visitLeaf(
122 impl->visitLeaf(
197 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
123 *graphWidget, QObject::tr("Open in %1").arg(graphWidget->name()),
198 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
124 [ var = impl->m_Variable, graphWidget ]() { graphWidget->addVariable(var); });
199 }
125 }
126 else {
127 qCCritical(LOG_GenerateVariableMenuOperation(),
128 "Can't visit VisualizationGraphWidget : the widget is null");
129 }
200 }
130 }
@@ -1,14 +1,9
1 \.h:\d+:.IPSIS_S04.*found: ui
1 \.h:\d+:.IPSIS_S04.*found: ui
2 qcustomplot\.h:\d+:.IPSIS
2 qcustomplot\.h:\d+:.IPSIS
3 qcustomplot\.cpp:\d+:.IPSIS
3 qcustomplot\.cpp:\d+:.IPSIS
4
4
5 # Ignore false positive relative to App macro
5 # Ignore false positive relative to App macro
6 SqpApplication\.h:\d+:.IPSIS_S03.*found: sqpApp
6 SqpApplication\.h:\d+:.IPSIS_S03.*found: sqpApp
7 SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp
7 SqpApplication\.h:\d+:.IPSIS_S04_VARIABLE.*found: sqpApp
8
8
9 # Ignore false positive relative to unnamed namespace
10 DataSourceTreeWidgetItem\.cpp:\d+:.*IPSIS_F13.*
11 GenerateVariableMenuOperation\.cpp:\d+:.*IPSIS_F13.*
12 VisualizationTabWidget\.cpp:\d+:.*IPSIS_F13.*
13 VisualizationZoneWidget\.cpp:\d+:.*IPSIS_F13.*
14
9
@@ -1,16 +1,26
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
1 #ifndef SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
2 #define SCIQLOP_COSINUSPROVIDER_H
3
3
4 #include <Data/IDataProvider.h>
4 #include <Data/IDataProvider.h>
5
5
6 #include <QLoggingCategory>
7
8 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
9
6 /**
10 /**
7 * @brief The CosinusProvider class is an example of how a data provider can generate data
11 * @brief The CosinusProvider class is an example of how a data provider can generate data
8 */
12 */
9 class CosinusProvider : public IDataProvider {
13 class CosinusProvider : public IDataProvider {
10 public:
14 public:
11 /// @sa IDataProvider::retrieveData()
15 /// @sa IDataProvider::retrieveData()
12 std::unique_ptr<IDataSeries>
16 std::unique_ptr<IDataSeries>
13 retrieveData(const DataProviderParameters &parameters) const override;
17 retrieveData(const DataProviderParameters &parameters) const override;
18
19 void requestDataLoading(const QVector<SqpDateTime> &dateTimeList) override;
20
21
22 private:
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
14 };
24 };
15
25
16 #endif // SCIQLOP_COSINUSPROVIDER_H
26 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -1,32 +1,71
1 #include "CosinusProvider.h"
1 #include "CosinusProvider.h"
2
2
3 #include <Data/DataProviderParameters.h>
3 #include <Data/DataProviderParameters.h>
4 #include <Data/ScalarSeries.h>
4 #include <Data/ScalarSeries.h>
5
5
6 #include <cmath>
6 #include <cmath>
7
7
8 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
9
8 std::unique_ptr<IDataSeries>
10 std::unique_ptr<IDataSeries>
9 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
11 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
10 {
12 {
11 auto dateTime = parameters.m_Time;
13 auto dateTime = parameters.m_Time;
12
14
13 // Gets the timerange from the parameters
15 // Gets the timerange from the parameters
14 auto start = dateTime.m_TStart;
16 auto start = dateTime.m_TStart;
15 auto end = dateTime.m_TEnd;
17 auto end = dateTime.m_TEnd;
16
18
17 // We assure that timerange is valid
19 // We assure that timerange is valid
18 if (end < start) {
20 if (end < start) {
19 std::swap(start, end);
21 std::swap(start, end);
20 }
22 }
21
23
22 // Generates scalar series containing cosinus values (one value per second)
24 // Generates scalar series containing cosinus values (one value per second)
23 auto scalarSeries
25 auto scalarSeries
24 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
26 = std::make_unique<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
25
27
26 auto dataIndex = 0;
28 auto dataIndex = 0;
27 for (auto time = start; time < end; ++time, ++dataIndex) {
29 for (auto time = start; time < end; ++time, ++dataIndex) {
28 scalarSeries->setData(dataIndex, time, std::cos(time));
30 scalarSeries->setData(dataIndex, time, std::cos(time));
29 }
31 }
30
32
31 return scalarSeries;
33 return scalarSeries;
32 }
34 }
35
36 void CosinusProvider::requestDataLoading(const QVector<SqpDateTime> &dateTimeList)
37 {
38 // NOTE: Try to use multithread if possible
39 foreach (const auto &dateTime, dateTimeList) {
40
41 auto scalarSeries = this->retrieveDataSeries(dateTime);
42
43 emit dataProvided(scalarSeries, dateTime);
44 }
45 }
46
47
48 std::shared_ptr<IDataSeries> CosinusProvider::retrieveDataSeries(const SqpDateTime &dateTime)
49 {
50
51 // Gets the timerange from the parameters
52 auto start = dateTime.m_TStart;
53 auto end = dateTime.m_TEnd;
54
55 // We assure that timerange is valid
56 if (end < start) {
57 std::swap(start, end);
58 }
59
60 // Generates scalar series containing cosinus values (one value per second)
61 auto scalarSeries
62 = std::make_shared<ScalarSeries>(end - start, Unit{QStringLiteral("t"), true}, Unit{});
63
64 auto dataIndex = 0;
65 for (auto time = start; time < end; ++time, ++dataIndex) {
66 scalarSeries->setData(dataIndex, time, std::cos(time));
67 }
68
69
70 return scalarSeries;
71 }
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now