-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.cpp
2857 lines (2499 loc) · 94.9 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* File: mainwindow.cpp
* Author: Rachel Bood
* Date: January 25, 2015.
* Version: 1.68
*
* Purpose: Implement the main window and functions called from there.
*
* Modification history:
* Jan 25, 2016 (JD V1.2):
* (a) Don't include TIFF and JPEG as file types to make the list shorter;
* assume (!) that the list also includes TIF and JPG.
* (b) TikZ: only output edge label font size if there is an edge label.
* (c) TikZ: only output edge thickness to ET_PREC_TIKZ digits.
* (d) TikZ: Only output vertex positions to VP_PREC_TIKZ digits.
* (e) TikZ: Merge the two (currently identical) code branches for drawing
* edges.
* (f) Factored out the "default" features in
* on_graphType_ComboBox_currentIndexChanged()) while fixing a
* bug where one or two weren't set when they should be.
* (g) Changed the minimum number of nodes to 1 for known graph types;
* tweaked some other similar parameters as well.
* For graphs read in from .grphc files, only display the UI control
* that (currently) do anything.
* (h) Changed some of the widget labels for the different types of
* graphs in on_graphType_ComboBox_currentIndexChanged().
* (i) Re-ordered file type drop-down list so to put the "text" outputs
* at the top.
* Feb 3, 2016 (JD V1.3)
* (a) Removed "GraphSettings.h" since it is not used.
* (b) Minor formatting cleanups.
* (c) Changed "Grapha" to "Graphic".
* Oct 11, 2019 (JD V1.4)
* (a) Allow blank lines and comments ([ \t]*#.*) in .grphc files.
* (b) Add some comments. Reformat a bit. Improve debug stmts.
* (c) Output a more informative and human-readable .grhpc file.
* Output the information as we compute it, rather than slowly
* constructing two big honkin' strings piece by piece and
* then outputting them.
* (d) Check for some error conditions and pop up a QErrorMessage in
* such cases.
* Oct 13, 2019 (JD V1.5)
* (a) Before this version, node labels and corresponding font sizes
* were not stored in the .grphc file. Go figure.
* (b) Look up TikZ-known colours (for TikZ output) and use those
* names rather than defining new colours for every coloured item.
* (c) When saving the graph, only do Linux-specific filename checks
* *after* confirming the selected filename is non-null.
* (d) Added some error checking when selecting files as possible
* graph-ic files, as well as checking contents of a graph-ic file.
* (e) Since node.{h,cpp} have been updated to allow superscripts as
* well as subscripts, and this allows the "edit" function to change
* vertex labels with subs/supers, the TikZ export has been changed
* to add '^{}' iff there is no '^' in the label. This adds a
* spurious (but apparently harmless) empty superscript to labels
* which have neither sub nor super.
* (f) Added a number of function comments.
* Oct 16, 2019 (JD V1.6)
* (a) When creating .grphc file, center graph on (0,0) so that when
* it is read back in it is centered (and thus accessible) in the
* preview pane. Ditto
* (b) Output coords (to .grphc file) using a %.<VP_PREC_GRPHC>f
* format, rather than the default %6g format, to avoid numbers
* like -5.68434e-14 (DAMHIKT) in the output file.
* Oct 16, 2019 (JD V1.7)
* (a) The original code was outputting (TikZ case) too many edge
* colour definitions, and in some cases they could be wrong.
* Fix that, and also add in the "well known colour" stuff from
* the nodes, as described in V1.5(b) above.
* (b) Only output the edge label and size if there is one.
* (c) Read edges from .grphc file with and without label info.
* Nov 10, 2019 (JD V1.8)
* (a) Output the label font size before label so that a space before the
* label doesn't need to be trimmed.
* Nov 10, 2019 (JD V1.9)
* (a) Fix apparently-erroneous use of logicalDotsPerInchX in the Y
* part of Create_Graph() (called in generate_Graph()).
* (b) Add some comments and some qDebug() statements.
* (c) Rename getWeightLabelSize() -> getLabelSize().
* (d) Rename "Weight" to "Label" for edge function names.
* (e) Do not call style_Graph() in generate_Graph() for "library"
* graphs, since doing so removes colour and size info. This is
* only a partial fix to the problem, since this mod takes away
* the ability to style a library graph. style_Graph() needs to
* be entirely rethought.
* (f) Add the rest of the "named" colours to lookupColour().
* (g) Remove a bunch of uninteresting output file types from the
* save dialog menu.
* Nov 16, 2019 (JD V1.10)
* (a) Refactor save_graph() because it is unwieldy large
* into itself + saveEdgelist() (step 1 of many!).
* (b) Formatting tweaks.
* Nov 17, 2019 (JD V1.11)
* (a) Move lookupColour() above where it is used and make it a
* non-class function.
* Nov 18, 2019 (JD V1.12)
* (a) Fixed the edit window so that it looks nicer and behaves
* (vis-a-vis vertical spacing) much nicer (changes in
* on_tabWidget_currentChanged()).
* Modify code which outputs "Edit Graph" tab to make the Label
* box wider, since that is the one which needs the space (at
* least when using sub- or superscripts).
* Also put stretch at the bottom so that the layout manager
* doesn't distribute extra space in ugly places.
* (b) Add connections between a node (or edge) and its label in the
* edit tab, so that when a node (or edge) is deleted (in delete
* mode) the label in its row in the Edit Graph tab is also
* deleted. (Everything else used to go, may as well do that
* too.)
* (c) Change "weight" to "label" in .grphc output edge comment.
* (d) Comment & formatting tweaking.
* Nov 19, 2019 (JD V1.13)
* (a) Factor out saveTikZ() from save_Graph().
* (b) Add findDefaults() as a first step to improving the TikZ
* output (which will set default styles at the top of each graph
* and only output differences for nodes/edges that are different).
* Nov 24, 2019 (JD V1.14)
* (a) Add a call on_graphType_ComboBox_currentIndexChanged(-1) the
* mainwindow constructor to initialize the "Create Graph" pane
* to a self-consistent shape. Modify on_graphType_...() to not
* whine when its arg is < 0.
* Nov 28, 2019 (JD V1.15)
* (a) Add dumpTikZ() and dumpGraphIc() functions and shortcuts (^T
* and ^G) to call them. dumpGraphIc() not yet implemented.
* (b) findDefaults(): changed default node diameter from 0.2 to
* (qreal)0.2 to correctly match the data type. Changed the
* floats to qreals in the hashes for the same reason.
* Also only change struct values from the initial defaults if
* there were actually observations in the corresponding hash table.
* (c) Improve saveTikZ() so that "nicer" TikZ code is output.
* Specifically, output default styles for nodes, edge lines and
* edge labels and when outputting individual nodes and edges
* only specify differences from the defaults.
* Also output things as we go, rather than creating a big
* honkin' string and outputting it at the end (can you say O(n^2)?).
* Nov 28, 2019 (JD V1.16)
* (a) Factor out saveGraphIc() from save_Graph().
* Use this to implement dumpGraphIc().
* Nov 29, 2019 (JD V1.17)
* (a) Rename "none" mode to "drag" mode, for less confusion.
* Dec 1, 2019 (JD V1.18)
* (a) Add qDeb() / DEBUG stuff.
* (b) Print out more screen resolution & size info.
* (c) Add comments, minor code clean-ups.
* Dec 6, 2019 (JD V1.19)
* (a) Rename generate_Freestyle_{Nodes,Edges} to {node,edge}ParamsUpdated
* to better reflect what those functions do.
* (b) Modify generate_Graph(), and the related connect() calls, to
* hand a parameter to generate_Graph() so that it knows which
* widget's change caused it to be called. This is the first
* step of fixing things so that specific features of library
* graphs can be styled without applying all styles, which
* otherwise destroys much of the content of a library graph.
* (c) Bug fix: nodeParamsUpdated() now passes the NodeLabelSize to
* ui->canvas->setUpNodeParams() where it should, not the nodeSize.
* (d) Clean up debug outputs a bit. Improve some comments.
* Dec 9, 2019 (JD V1.20)
* (a) Various comment and debug changes.
* (b) Change generate_Graph() to not pass height and width into to
* PreView::Create_Graph(). This is part of a large set of
* changes which will eventually allow library graphs to be styled.
* (c) Update call sequence to PV::Style_graph() as per changes there.
* (d) Obsessively re-order the cases in
* on_graphType_ComboBox_currentIndexChanged().
* Also set more constraints on the spinboxes so that we can't
* call generate_...() functions with meaningless parameters.
* Show both width and height for Dutch Windmill, in case someone
* wants one with non-unit aspect ratio.
* (e) Add on_numOfNodes1_valueChanged() to follow the actions of
* on_numOfNodes2_valueChanged() to avoid inconsistent parameters
* when numOfNodes1 is changed.
* Dec 12, 2019 (JD V1.21)
* (a) Save the screen DPI in a couple of static global vars & get it
* over with, rather than repeatedly calling the Qt functions.
* (b) Modify saveGraphIc() so that the coords in the .grphc file are
* in inches, not in pixels. (It should have been this way from
* day 1!)
* (c) Allow commas in labels.
* (d) Close the file descriptor upon discovering an error when
* reading a .grphc file.
* (e) (Re-)Implement the ability to style library graphs (with
* changes to preview.cpp). As of this version, the graph
* drawing widgets visible when a library graph is chosen do not
* have values related to the graph in the preview window. This
* needs to be dealt with in the fullness of time.
* (f) Show nodeLabel2 iff showing numOfNodes2.
* (g) The usual collection of debug statement improvements.
* Dec 15, 2019 (JD V1.22)
* (a) Modify on_graphType_ComboBox_currentIndexChanged() so that
* Prism gets the same treatment as Antiprism, vis-a-vis the
* behaviour of ui->numOfNodes1.
* Dec 15, 2019 (JD V1.23)
* (a) Replace font.setPixelSize() (which is a device-dependent
* thing) with font.setPointSize() (which is device-INdependent).
* This makes the fonts on Linux show up at a reasonable size
* even without env QT_AUTO_SCREEN_SCALE_FACTOR=1 and things look
* fine on macos as well.
* (b) Replace a bunch of printf()s with qDebu(); delete a number of others.
* May 11, 2020 (IC V1.24)
* (a) Changed the logical DPI variables to use physical DPI to correct
* scaling issues. (Only reliable with Qt V5.14.2 or higher)
* May 12, 2020 (IC V1.25)
* (a) Removed certain labels that were unnecessary after redesigning the ui.
* May 15, 2020 (IC V1.26)
* (a) Modified set_Font_Sizes() to be more readable and flexible if we decide
* to change font (sizes) at a later date.
* May 19, 2020 (IC V1.27)
* (a) Updated set_Font_Sizes() to use embeded font "arimo" as default font.
* May 25, 2020 (IC V1.28)
* (a) Removed setKeyStatusLabel() in favour of tooltips for each mode.
* (b) Added widget NumLabelStart which allows the user to start numbering
* nodes at a specified value instead of always 0.
* May 28, 2020 (IC V1.29)
* (a) Modified save_Graph() to use a white background for JPEG files.
* Jun 6, 2020 (IC V1.30)
* (a) Added set_Interface_Sizes() to fix sizing issues on monitors with
* different DPIs.
* Jun 9, 2020 (IC V1.31)
* (a) Converted the node and edge label size doublespinboxes into
* regular spinboxes and updated any relevant connect statements.
* Jun 10, 2020 (IC V1.32)
* (a) Added QSettings to save the window size on exit and load the size
* on startup. See saveSettings() and loadSettings()
* (b) Reimplemented closeEvent() to accommodate QSettings and prompt user to
* save graph if any exists on the canvas.
* (c) Added code to saveGraph() that supports saving default background
* colour of saved images. WIP
* Jun 17, 2020 (IC V1.33)
* (a) Updated on_tabWidget_currentChanged() to display merged graphs under a
* single set of headers as well as delete those headers if the graph is
* deleted.
* Jun 19, 2020 (IC V1.34)
* (a) Added multiple slots and appropriate connections for updating edit tab
* when graphs/nodes/edges are created.
* Jun 26, 2020 (IC V1.35)
* (a) Update some connections to take a node or edge param.
* (b) Fixed a bug that would set the colour to black if user exited the
* colour select window without selecting a colour.
* (c) Rename on_tabWidget_currentChanged(int) to updateEditTab(int).
* Do some UI tweaking there.
* (d) Implement addGraphToEditTab(), addNodeToEditTab() and
* addEdgeToEditTab().
* Jun 30, 2020 (IC V1.36)
* (a) Added another connection to refresh the preview pane with a new graph
* when the previous is dropped onto the canvas.
* Jul 3, 2020 (IC V1.37)
* (a) Added code so that the thickness of a node (the circle) can be
* changed. Added another connection to update the preview and
* params when the node thickness is adjusted.
* (b) Updated set_Font_Sizes() to include the new thickness widgets.
* Jul 7, 2020 (IC V1.38)
* (a) Added another connection to update the zoomDisplay after a zoom change.
* Jul 9, 2020 (IC V1.39)
* (a) Added another connection to update the edit tab after two graphs were
* joined.
* (b) Fixed a bug that allowed labels to be focusable on the preview pane.
* Jul 14, 2020 (IC V1.40)
* (a) Corrected an issue that was preventing custom graphs from being
* refreshed on the preview after being dropped onto the canvas.
* Jul 15, 2020 (IC V1.41)
* (a) Added node thickness widgets to the edit tab so that both node penwidth
* and diameter can be changed after leaving the preview pane.
* Jul 22, 2020 (IC V1.42)
* (b) Set the font of the zoomDisplay.
* (c) Add "N width" label and widget to edit tab; rearrange edit tab widgets.
* Jul 23, 2020 (IC V1.43)
* (a) Added another connection to update the edit tab after a graph is
* separated. (Replace itemDeleted() with graphSeparated().)
* Jul 24, 2020 (IC V1.44)
* (a) Added another connection to call clearCanvas when the clearCanvas
* button is pressed.
* Jul 29, 2020 (IC V1.45)
* (a) Installed event filters in updateEditTab(int) to send event
* handling to node.cpp and edge.cpp.
* Jul 31, 2020 (IC V1.46)
* (a) Added connections to somethingChanged() slot and bool promptSave that
* detects if any change has been made on the canvas since the last save
* and thus a new save prompt is needed on exit.
* (b) Add setting to allow the user to specify their physicalDPI
* setting, a la acroread.
* Aug 5, 2020 (IC V1.47)
* (a) Node thickness is now be included in the save code and is passed
* to nodeParam functions.
* THIS DEPRECATES PREVIOUS .grphc FILES and changes .tikz output.
* (b) Added updateDpiAndPreview slot and settingsDialog variable to be used
* in conjunction with the new settingsDialog window which allows the user
* to use a custom DPI value instead of the system default.
* (c) Renamed nodeSize widget to nodeDiameter and edgeSize widget to
* edgeThickness for clarity. Corresponding changes also in UI.
* (d) On exit, don't ask the user if the graph should be saved if it
* has not been changed since the last save.
* (e) In set_Font_Sizes() set the font of the clearCanvas button.
* Aug 7, 2020 (IC V1.48)
* (a) save_Graph() now uses the saved background colours from settingsDialog
* to colour saved graphs.
* Aug 11, 2020 (IC V1.49)
* (a) A zoom function was added to the canvas similar to the one for the
* preview so C_ZoomDisplay needs to be scaled in set_Interface_Sizes().
* (b) New connection for zoomChanged() signal.
* (c) Update preview when settings DPI is changed. Add
* updateDpiAndPreview() function.
* (d) Handraulically scale clearCanvas and zoomDisplay{,_2} widgets.
* Aug 12, 2020 (IC V1.50)
* (a) Cleaned up set_Interface_Sizes() to make the default scale code more
* readable. Currently, the scale is based on logicalDPI / 72 for apple
* and logicalDPI / 96 for any other machine.
* (b) Major code removal: addEdgeToEditTab(), addNodeToEditTab() and
* addGraphToEditTab() all went away.
* Aug 14, 2020 (IC V1.51)
* (a) Update call to setRotation() with new param.
* (b) Remove a now-bogus comment.
* Aug 21, 2020 (IC V1.52)
* (a) Added the ability to number edge labels similar to nodes. Edge labels
* can now have numbered subscripts or simply numbered labels and the user
* can specify the start number with EdgeNumLabelStart.
* (b) Widgets related to numbering slightly renamed to indicate whether they
* are related to an edge or a node for clarity.
* Aug 24, 2020 (IC V1.51)
* (a) Changed the wording on some edit tab labels for clarity.
* Aug 25, 2020 (IC V1.52)
* (a) Added a new basicGraphs category, circulant, so a new offsets widget
* was added. It only accepts input in the format "d,d,d" or "d d d"
* and occupies the same space as numOfNodes2.
* (c) For circulant graph, added connection for offsets widget and
* pass the offsets text to Create_Basic_Graph(). Set the
* offsets widget's font. Show or hide that widget as desired.
* (d) Deleted some old commented-out code.
* Aug 25, 2020 (IC V1.54)
* (a) Restrict the input for the offsets widget so users can't even
* enter invalid data.
* (b) When the offsets text is changed, a new graph is generated on
* the preview instead of simply styling the graph as new edges
* need to be added.
* Aug 26, 2020 (IC V1.55)
* (a) Removed offsets from the mainwindow.ui and instead initialize it in
* the constructor before moving it to the location of numOfNodes2.
* (b) Restructured updateEditTab slightly so that nodes are added to
* the edit tab before edges.
* (c) Added a new setting underneath the snapToGrid checkbox that lets the
* user specify the size of the grid cells when snapToGrid is on.
* A signal is sent to the canvas scene when the value changes.
* Aug 27, 2020 (IC + JD V1.56)
* (a) In select_custom_graph() fix the positioning of graphs whose width
* or height is equal to 0.
* (b) When a custom graph is read in, set the height and width widgets,
* as well as the node size widget, to values from the custom graph.
* (The node size is computed as the average of the actual node
* sizes, which is a so-so approximation to what we want.)
* This keeps the custom graph from magically changing size when, for
* example, the node fill colour is changed.
* (b) Removed redundant for loop from updateEditTab.
* (c) Moved the gridCellSize widget to settingsdialog as it made more sense
* there.
* (d) Moved clearCanvas to the layout above the canvas so it is out of the
* way of canvas graphs and adheres to a layout.
* Aug 28, 2020 (IC V1.57)
* (a) Update the connection for updateCellSize().
* (b) Improve the code which populates the edit tab.
* Oct 16, 2020 (JD V1.58)
* (a) Rename saveSettings() -> saveWinSizeSettings() to clarify.
* (b) Add some code to make the use of settings more robust.
* (c) Tidy white-space.
* Sep 4, 2020 (IC V1.59)
* (a) Lots of infrastructure added for the new canvas graph editing tab.
* There are now connections that call style_Canvas_Graph() with the
* appropriate ID of the widget that changed and all relevant widget
* information. Numerous on_clicked functions were added for the new
* colour widgets and checkboxes and set_Font_Sizes will now set the
* font for all widgets on the canvas graph tab.
* Sep 8, 2020 (IC V1.60)
* (a) Fixed a rotation issue related to the new select mode.
* Sep 9, 2020 (IC V1.61)
* (a) Changed the canvas change signals to slot into scheduleUpdate()
* instead of updateEditTab(). Currently, the edit tab should ONLY update
* when the user switches to it AND either a signal has been sent by
* canvasscene/view or a change was made on the canvas graph tab.
* (i.e. when ui->tabWidget->currentIndex() == 2 && updateNeeded == true)
* (b) Reintroduce the on_tabWidget_currentChanged() function, but
* with a much smaller job to do.
* Sep 10, 2020 (IC V1.62)
* (a) resetCanvasGraphTab() added to reset the widgets on the canvas graph
* to their defaults whenever the selectedList is cleared. It also resets
* any static variables used in style_Canvas_Graph().
* Sep 11, 2020 (IC V1.63)
* (a) somethingChanged() function now also calls updateCanvasGraphList()
* to populate the graph list on the canvas graph tab.
* Oct 17, 2020 (JD V1.64)
* (a) Replace a lot of code with colour.name().
* (b) Generic code tidying.
* Oct 18, 2020 (JD V1.65)
* (a) Change all possible "color"s to "colour"s.
* (b) Add an enum tab_IDs and fix missed change from last commit (where
* the edit nodes and edges tab changed from tab 1 to tab 2).
* (c) Clarify some names, such as there was formerly both edgeLabel
* (a QLabel) and EdgeLabel (a QLineEdit); "EdgeLabel" is now
* "edgeLabelEdit".
* (d) zoomDisplay_2 is now C_ZoomDisplay ('C' for canvas, the other
* zoom display is on the preview pane).
* (e) The changes to add a new tab with many widgets similar to the
* preview pane introduced many widgets whose names were the same
* as the preview pane widgets, but with _2 appended. All of
* these names were changed along the lines of this:
* nodeDiameter_2 -> cNodeDiameter
* where (unlike (d)) 'c' is from 'edit Canvas graph tab'.
* This required many analogous changes in mainwindow.ui.
* Even with all the name changes things are still not as clear
* as I would like.
* Oct 22, 2020 (JD V1.66)
* (a) Remove all functions that do I/O and put them in file-io.c.
* This required changing things a bit since the ui and parent
* widget are needed by some functions, and they are no longer in
* this class. Some related functions (e.g., dumpTikZ() and
* dumpGraphIc()) are still here to avoid the potential nuisance
* of mapping functions in another file to QShortcuts.
* (b) Update many comments.
* (c) Modify on_numOfNodes[12]_valueChanged() to (i) use the
* argument instead of a getter, and (ii) allow the second
* parameter to be 1/2 the first one (possibly not useful, but it
* doesn't hurt anything).
* (d) Fix closeEvent() so that if the user cancels from the "save"
* dialog the program does not exit.
* (e) Many names which had both '_' and camel-case were changed to
* just use camel case.
* (f) Rearranged the code which decides when to update the edit tab,
* eliminating one function.
* (g) Default to select mode for "edit canvas graph" and disable
* that mode elsewhere, since it is otherwise useless as of now.
* (h) Blocked many signals when widgets are programmatically
* changed, since these signals may cause generateGraph() to be
* called multiple times, and this may cause anomalous behaviour.
* Nov 14, 2020 (JD V1.67)
* (a) Use Graph::boundingBox() instead to boundingRect() to get a
* more accurate size of the graph for the Edit Canvas Graph tab.
* (b) Rename resetCanvasGraphTab() to resetEditCanvasGraphTabWidgets(),
* because it doesn't reset anything else there.
* Rename editCanvasTab to editCanvasGraphTab for added specificity.
* (c) Modify resetEditCanvasGraphTabWidgets() to (i) disable all the
* widgets (except colour pickers) in the Edit Canvas Graph tab
* if selectedList is empty, and (ii) to otherwise enable the
* desired widgets.
* (d) Improve the H & W values in the Edit Canvas Tab graph list by
* using graph->boundingBox() rather than boundingRect(), and by
* outputting them with g4 formats.
* (e) Add setEditCanvasGraphTabWidgets() so that canvasview() can
* change the widgets in this tab.
* (g) Only call updateCanvasGraphList() from somethingChanged() if
* the Edit Canvas Graph tab is visible. But now call
* updateCanvasGraphList() from on_tabWidget_currentChanged()
* when switching to the Edit Canvas Graph tab.
* See the comments in those functions for why this was needed.
* (h) Changed style_Canvas_Graph() so that (i) H and W don't both
* change when one is modified, (ii) joined and freestyle
* graphs scale properly.
* (i) Improve some comments.
* Nov 16, 2020 (JD V1.68)
* (a) Remove a now-bogus comment that was misleading enough to
* deserve a commit.
*/
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "file-io.h"
#include "edge.h"
#include "basicgraphs.h"
#include "colourlinecontroller.h"
#include "sizecontroller.h"
#include "labelcontroller.h"
#include "labelsizecontroller.h"
#include "colourfillcontroller.h"
#include <QDesktopWidget>
#include <QColorDialog>
#include <QGraphicsItem>
#include <QMessageBox>
#include <QShortcut>
#include <qmath.h>
#include <QErrorMessage>
#include <QCloseEvent>
// The tab order is set in mainwindow.ui. If it changes, so must this:
enum tab_IDs { previewTab = 0, editCanvasGraphTab, editNodesAndEdgesTab };
// The unit of these is points:
#define TITLE_SIZE 20
#define SUB_TITLE_SIZE 18
#define SUB_SUB_TITLE_SIZE 12
QSettings settings("Acadia", "Graphic");
qreal currentPhysicalDPI, currentPhysicalDPI_X, currentPhysicalDPI_Y;
static qreal screenLogicalDPI_X;
static bool updateNeeded = false;
static int previousRotation;
/*
* Name: saveGraph()
* Purpose: Map from a (parameterless) slot connected to an
* accelerator to a File_IO function which takes params.
* Arguments: None.
* Outputs: Nothing.
* Modifies: Everything File_IO::saveGraph() modifies.
* Returns: Return value of File_IO::save_Graph().
* Assumptions: None(?).
* Bugs: None known.
* Notes: Possibly a complex connect statement would obviate
* this function.
*/
bool
MainWindow::saveGraph()
{
return File_IO::saveGraph(&promptSave, this, ui);
}
/*
* Name: loadGraphicFile()
* Purpose: Map from a (parameterless) slot connected to an
* accelerator to a File_IO function which takes params.
* Arguments: None.
* Outputs: Nothing.
* Modifies: Everything File_IO::loadGraphicFile() modifies.
* Returns: Return value of File_IO::loadGraphicFile()..
* Assumptions: None(?).
* Bugs: None known.
* Notes: Possibly a complex connect statement would obviate
* this function.
*/
bool
MainWindow::loadGraphicFile()
{
return File_IO::loadGraphicFile(this, ui);
}
/*
* Name: MainWindow
* Purpose: Main window constructor
* Arguments: QWidget *
* Output: Nothing.
* Modifies: private MainWindow variables
* Returns: Nothing.
* Assumptions: ?
* Bugs: None known... so far.
* Notes: This is a cpp file used with the mainwindow.ui file
*/
MainWindow::MainWindow(QWidget * parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
File_IO::setFileDirectory(this);
ui->setupUi(this);
this->generateComboboxTitles();
connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveGraph()));
connect(ui->actionOpen_File, SIGNAL(triggered()),
this, SLOT(loadGraphicFile()));
// Ctrl-Q quits.
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Q), this, SLOT(close()));
// DEBUG HELP:
// Dump TikZ to stdout
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_T), this, SLOT(dumpTikZ()));
// Dump graph-ic code to stdout
new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G), this,
SLOT(dumpGraphIc()));
// Create an offsets widget to be used with the circulant graph type.
offsets = new QLineEdit;
offsets->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
offsets->setPlaceholderText("offsets");
offsets->setAlignment(Qt::AlignHCenter);
// Restrict the input for offsets lineEdit to the format "d,d,d" or "d d d"
// and move it to the same layout position as numOfNodes2.
QRegExp re = QRegExp("([1-9]\\d{0,1}(, ?| ))+");
QRegExpValidator * validator = new QRegExpValidator(re);
offsets->setValidator(validator);
// We want the offsets widget to be in the same row/column position as
// numOfNodes2.
int index = ui->gridLayout->indexOf(ui->numOfNodes2);
int row, col, rSpan, cSpan;
ui->gridLayout->getItemPosition(index, &row, &col, &rSpan, &cSpan);
ui->gridLayout->addWidget(offsets, row, col, Qt::AlignHCenter);
// The horrendous calls to connect() below were the simplest ones
// I (JD) could find which allow passing information about which
// UI widget was changed. I could have had a separate function for
// every widget, which then had just one line to call generateGraph()
// with an appropriate argument, but that is perhaps even more
// grotesque.
// Redraw the preview pane graph (if any) when these NODE
// parameters are modified:
connect(ui->nodeDiameter,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { generateGraph(nodeDiam_WGT); });
connect(ui->nodeThickness,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { generateGraph(nodeThickness_WGT); });
connect(ui->NodeLabel1,
(void(QLineEdit::*)(const QString &))&QLineEdit::textChanged,
this, [this]() { generateGraph(nodeLabel1_WGT); });
connect(ui->NodeLabel2,
(void(QLineEdit::*)(const QString &))&QLineEdit::textChanged,
this, [this]() { generateGraph(nodeLabel2_WGT); });
connect(ui->NodeLabelSize,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { generateGraph(nodeLabelSize_WGT); });
connect(ui->NodeNumLabelCheckBox,
(void(QCheckBox::*)(bool))&QCheckBox::clicked,
this, [this]() { generateGraph(nodeNumLabelCheckBox_WGT); });
connect(ui->NodeNumLabelStart,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { generateGraph(nodeNumLabelStart_WGT); });
connect(ui->NodeFillColour,
(void(QPushButton::*)(bool))&QPushButton::clicked,
this, [this]() { generateGraph(nodeFillColour_WGT); });
connect(ui->NodeOutlineColour,
(void(QPushButton::*)(bool))&QPushButton::clicked,
this, [this]() { generateGraph(nodeOutlineColour_WGT); });
// Redraw the preview pane graph (if any) when these EDGE
// parameters are modified:
connect(ui->edgeThickness,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { generateGraph(edgeThickness_WGT); });
connect(ui->edgeLabelEdit,
(void(QLineEdit::*)(const QString &))&QLineEdit::textChanged,
this, [this]() { generateGraph(edgeLabel_WGT); });
connect(ui->EdgeLabelSize,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { generateGraph(edgeLabelSize_WGT); });
connect(ui->EdgeNumLabelCheckBox,
(void(QCheckBox::*)(bool))&QCheckBox::clicked,
this, [this]() { generateGraph(edgeNumLabelCheckBox_WGT); });
connect(ui->EdgeNumLabelStart,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { generateGraph(edgeNumLabelStart_WGT); });
connect(ui->EdgeLineColour,
(void(QPushButton::*)(bool))&QPushButton::clicked,
this, [this]() { generateGraph(edgeLineColour_WGT); });
// Redraw the preview pane graph (if any) when these GRAPH
// parameters are modified:
connect(ui->graphRotation,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { generateGraph(graphRotation_WGT); });
connect(ui->complete_checkBox,
(void(QCheckBox::*)(bool))&QCheckBox::clicked,
this, [this]() { generateGraph(completeCheckBox_WGT); });
connect(ui->graphHeight,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { generateGraph(graphHeight_WGT); });
connect(ui->graphWidth,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { generateGraph(graphWidth_WGT); });
connect(ui->numOfNodes1,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { generateGraph(numOfNodes1_WGT); });
connect(ui->numOfNodes2,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { generateGraph(numOfNodes2_WGT); });
connect(ui->graphType_ComboBox,
(void(QComboBox::*)(int))&QComboBox::activated,
this, [this]() { generateGraph(graphTypeComboBox_WGT); });
connect(offsets,
(void(QLineEdit::*)(const QString &))&QLineEdit::textChanged,
this, [this]() { generateGraph(offsets_WGT); });
// When these NODE and EDGE parameters are changed, the updated
// values are passed to the canvas view, so that nodes and edges
// drawn in "Freestyle" mode are styled as per the settings in the
// "Create Graph" tab.
connect(ui->nodeDiameter, SIGNAL(valueChanged(double)),
this, SLOT(nodeParamsUpdated()));
connect(ui->nodeThickness, SIGNAL(valueChanged(double)),
this, SLOT(nodeParamsUpdated()));
connect(ui->NodeLabel1, SIGNAL(textChanged(QString)),
this, SLOT(nodeParamsUpdated()));
connect(ui->NodeLabel2, SIGNAL(textChanged(QString)),
this, SLOT(nodeParamsUpdated()));
connect(ui->NodeLabelSize, SIGNAL(valueChanged(int)),
this, SLOT(nodeParamsUpdated()));
connect(ui->NodeNumLabelCheckBox, SIGNAL(clicked(bool)),
this, SLOT(nodeParamsUpdated()));
connect(ui->NodeFillColour, SIGNAL(clicked(bool)),
this, SLOT(nodeParamsUpdated()));
connect(ui->NodeOutlineColour, SIGNAL(clicked(bool)),
this, SLOT(nodeParamsUpdated()));
connect(ui->edgeThickness, SIGNAL(valueChanged(double)),
this, SLOT(edgeParamsUpdated()));
connect(ui->edgeLabelEdit, SIGNAL(textChanged(QString)),
this, SLOT(edgeParamsUpdated()));
connect(ui->EdgeLabelSize, SIGNAL(valueChanged(int)),
this, SLOT(edgeParamsUpdated()));
connect(ui->EdgeNumLabelCheckBox, SIGNAL(clicked(bool)),
this, SLOT(edgeParamsUpdated()));
connect(ui->EdgeLineColour, SIGNAL(clicked(bool)),
this, SLOT(edgeParamsUpdated()));
// Yet more connections...
connect(ui->snapToGrid_checkBox, SIGNAL(clicked(bool)),
ui->canvas, SLOT(snapToGrid(bool)));
connect(ui->canvas, SIGNAL(resetDragMode()),
ui->dragMode_radioButton, SLOT(click()));
// These connects update the edit nodes and edges tab when the
// number of items on the canvas changes.
connect(ui->canvas->scene(), SIGNAL(graphDropped()),
this, SLOT(scheduleUpdate()));
connect(ui->canvas->scene(), SIGNAL(graphJoined()),
this, SLOT(scheduleUpdate()));
connect(ui->canvas->scene(), SIGNAL(graphSeparated()),
this, SLOT(scheduleUpdate()));
connect(ui->canvas, SIGNAL(nodeCreated()),
this, SLOT(scheduleUpdate()));
connect(ui->canvas, SIGNAL(edgeCreated()),
this, SLOT(scheduleUpdate()));
// This adds a new graph to the preview pane when the previous is
// dropped onto the canvas.
connect(ui->canvas->scene(), SIGNAL(graphDropped()),
this, SLOT(regenerateGraph()));
// Updates the zoomDisplays after zoomIn/zoomOut is called.
connect(ui->preview, SIGNAL(zoomChanged(QString)),
ui->zoomDisplay, SLOT(setText(QString)));
connect(ui->canvas, SIGNAL(zoomChanged(QString)),
ui->C_ZoomDisplay, SLOT(setText(QString)));
// Clears all items from the canvas:
connect(ui->clearCanvas, SIGNAL(clicked()),
ui->canvas, SLOT(clearCanvas()));
// Ask to save on exit if any changes were made on the canvas since
// last save and update the list of graphs on the canvas graph tab.
connect(ui->canvas->scene(), SIGNAL(somethingChanged()),
this, SLOT(somethingChanged()));
connect(ui->canvas, SIGNAL(nodeCreated()), this, SLOT(somethingChanged()));
connect(ui->canvas, SIGNAL(edgeCreated()), this, SLOT(somethingChanged()));
connect(ui->canvas->scene(), SIGNAL(graphDropped()),
this, SLOT(somethingChanged()));
connect(ui->canvas->scene(), SIGNAL(graphJoined()),
this, SLOT(somethingChanged()));
// The following connects relate to the Canvas Graph tab...
connect(ui->cNodeDiameter,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cNodeDiam_WGT); });
connect(ui->cNodeThickness,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cNodeThickness_WGT); });
connect(ui->cNodeLabel1,
(void(QLineEdit::*)(const QString &))&QLineEdit::textChanged,
this, [this]() { style_Canvas_Graph(cNodeLabel1_WGT); });
connect(ui->cNodeLabelSize,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cNodeLabelSize_WGT); });
connect(ui->cNodeNumLabelCheckBox,
(void(QCheckBox::*)(bool))&QCheckBox::clicked,
this, [this]() { style_Canvas_Graph(cNodeNumLabelCheckBox_WGT); });
connect(ui->cNodeNumLabelStart,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cNodeNumLabelStart_WGT); });
connect(ui->cNodeFillColour,
(void(QPushButton::*)(bool))&QPushButton::clicked,
this, [this]() { style_Canvas_Graph(cNodeFillColour_WGT); });
connect(ui->cNodeOutlineColour,
(void(QPushButton::*)(bool))&QPushButton::clicked,
this, [this]() { style_Canvas_Graph(cNodeOutlineColour_WGT); });
connect(ui->cEdgeThickness,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cEdgeThickness_WGT); });
connect(ui->cEdgeLabelEdit,
(void(QLineEdit::*)(const QString &))&QLineEdit::textChanged,
this, [this]() { style_Canvas_Graph(cEdgeLabel_WGT); });
connect(ui->cEdgeLabelSize,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cEdgeLabelSize_WGT); });
connect(ui->cEdgeNumLabelCheckBox,
(void(QCheckBox::*)(bool))&QCheckBox::clicked,
this, [this]() { style_Canvas_Graph(cEdgeNumLabelCheckBox_WGT); });
connect(ui->cEdgeNumLabelStart,
(void(QSpinBox::*)(int))&QSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cEdgeNumLabelStart_WGT); });
connect(ui->cEdgeLineColour,
(void(QPushButton::*)(bool))&QPushButton::clicked,
this, [this]() { style_Canvas_Graph(cEdgeLineColour_WGT); });
connect(ui->cGraphRotation,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cGraphRotation_WGT); });
connect(ui->cGraphHeight,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cGraphHeight_WGT); });
connect(ui->cGraphWidth,
(void(QDoubleSpinBox::*)(double))&QDoubleSpinBox::valueChanged,
this, [this]() { style_Canvas_Graph(cGraphWidth_WGT); });
// Reset appropriate widgets and variables whenever selectedList
// is changed. Note that this signal is emitted by various
// functions in canvasview.cpp.
connect(ui->canvas, SIGNAL(selectedListChanged()),
this, SLOT(resetEditCanvasGraphTabWidgets()));
// Initialize the canvas to be in "drag" mode.
ui->dragMode_radioButton->click();
// Initialize colour buttons.
QString s("background: #000000;" BUTTON_STYLE);
ui->EdgeLineColour->setStyleSheet(s);
ui->NodeOutlineColour->setStyleSheet(s);
ui->cEdgeLineColour->setStyleSheet(s);
ui->cNodeOutlineColour->setStyleSheet(s);
s = "background: #ffffff;" BUTTON_STYLE;
ui->NodeFillColour->setStyleSheet(s);
ui->cNodeFillColour->setStyleSheet(s);
edgeParamsUpdated();
nodeParamsUpdated();
// Initialize the canvas to enable snapToGrid feature when loaded.
ui->canvas->snapToGrid(ui->snapToGrid_checkBox->isChecked());
// Initialize font sizes for ui labels/widgets.
setFontSizes();
gridLayout = new QGridLayout();
ui->scrollAreaWidgetContents->setLayout(gridLayout);
// Initialize Create Graph pane to default values:
on_graphType_ComboBox_currentIndexChanged(-1);
QScreen * screen = QGuiApplication::primaryScreen();
if (settings.value("useDefaultResolution") == false)
{
currentPhysicalDPI = settings.value("customResolution").toReal();
currentPhysicalDPI_X = settings.value("customResolution").toReal();
currentPhysicalDPI_Y = settings.value("customResolution").toReal();
}
else
{
currentPhysicalDPI = screen->physicalDotsPerInch();
currentPhysicalDPI_X = screen->physicalDotsPerInchX();
currentPhysicalDPI_Y = screen->physicalDotsPerInchY();
}
screenLogicalDPI_X = screen->logicalDotsPerInchX();
loadWinSizeSettings();
// Unfortunately qreal QVariants can't convert... so we store an int...
int defaultDPI = screen->physicalDotsPerInch();
settings.setValue("defaultResolution", defaultDPI);
settingsDialog = new SettingsDialog(this);
connect(ui->actionGraph_settings, SIGNAL(triggered()),
settingsDialog, SLOT(open()));
connect(settingsDialog, SIGNAL(saveDone()),
this, SLOT(updateDpiAndPreview()));
connect(settingsDialog, SIGNAL(saveDone()),
ui->canvas->scene(), SLOT(updateCellSize()));
#ifdef DEBUG
// Info to help with dealing with HiDPI issues
printf("MW::MW: Logical DPI: (%.3f, %.3f)\nPhysical DPI: (%.3f, %.3f)\n",
screen->logicalDotsPerInchX(), screen->logicalDotsPerInchY(),
screen->physicalDotsPerInchX(), screen->physicalDotsPerInchY());
printf(" Physical size (mm): ht %.1f, wd %.3f\n",
screen->physicalSize().height(), screen->physicalSize().width());
printf(" Pixel resolution: %d, %d\n",
screen->size().height(), screen->size().width());
printf(" screen->devicePixelRatio: %.3f\n", screen->devicePixelRatio());
fflush(stdout);
#endif
}
/*
* Name: ~MainWindow
* Purpose: frees the memory of mainwindow
* Arguments: none
* Output: none
* Modifies: mainwindow
* Returns: none
* Assumptions: none
* Bugs: none...so far
* Notes: none
*/
MainWindow::~MainWindow()
{
delete ui;
}
/*
* Name: generateComboboxTitles()
* Purpose: Populate the list of graph types with the defined
* basic types, then add a separator, then call
* loadGraphicLibrary() to load the local graph library
* (if any).
* Arguments: None.
* Outputs: Nothing.
* Modifies: The ui->graphType_ComboBox
* Returns: Nothing.
* Assumptions: ui->graphType_ComboBox is set up.
* Bugs: ?
* Notes: None.
*/
void
MainWindow::generateComboboxTitles()
{
BasicGraphs * basicG = new BasicGraphs();
int i = 1;
while (i < BasicGraphs::Count)
ui->graphType_ComboBox->addItem(basicG->getGraphName(i++));
ui->graphType_ComboBox->insertSeparator(BasicGraphs::Count);
File_IO::loadGraphicLibrary(ui);
}
/*
* Name: somethingChanged()
* Purpose: Record the fact that something on the canvas changed.
* This is used so that we know whether or not a save
* dialog should be presented when the user quits the
* program.
* Arguments: None.
* Outputs: Nothing.
* Modifies: The promptSave flag and the list of canvas graphs.
* Returns: Nothing.
* Assumptions: None.
* Bugs: None, surely.
* Notes:
*/
void
MainWindow::somethingChanged()
{
promptSave = true;
// If we are not in this tab, no use updating it, since it is
// updated by on_tabWidget_currentChanged() when we switch to the
// edit canvas graph tab.
if (ui->tabWidget->currentIndex() == editCanvasGraphTab)
updateCanvasGraphList();
}
/*
* Name: styleGraph()
* Purpose: Update a basic graph when a preview tab widget changes.
* Arguments: None.
* Outputs: Nothing.
* Modifies: The graph in the preview scene.
* Returns: Nothing.
* Assumptions: ?
* Bugs: ?
* Notes: Do not call this on a non-basic graph, otherwise the
* colours, line thicknesses and node sizes are lost,
* since everything will be set to the current values of
* the UI boxes/sliders.
*/
void
MainWindow::styleGraph(enum widget_ID whatChanged)
{
qDeb() << "MW::styleGraph(WID " << whatChanged << ") called";
foreach (QGraphicsItem * item, ui->preview->scene()->items())
{
if (item->type() == Graph::Type)
{
Graph * graphItem = qgraphicsitem_cast<Graph *>(item);
ui->preview->Style_Graph(
graphItem,
ui->graphType_ComboBox->currentIndex(),
whatChanged,
ui->nodeDiameter->value(),