/
simulationexperimentviewinformationgraphpanelandgraphswidget.cpp
1759 lines (1241 loc) · 70.3 KB
/
simulationexperimentviewinformationgraphpanelandgraphswidget.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
/*******************************************************************************
Copyright (C) The University of Auckland
OpenCOR is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenCOR is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*******************************************************************************/
//==============================================================================
// Simulation Experiment view information graph panel and graphs widget
//==============================================================================
#include "cellmlfileruntime.h"
#include "coreguiutils.h"
#include "filemanager.h"
#include "i18ninterface.h"
#include "preferencesinterface.h"
#include "sedmlsupport.h"
#include "simulation.h"
#include "simulationexperimentviewinformationgraphpanelandgraphswidget.h"
#include "simulationexperimentviewsimulationwidget.h"
#include "simulationexperimentviewwidget.h"
//==============================================================================
#include <QFileInfo>
#include <QHeaderView>
#include <QMenu>
#include <QScrollBar>
#include <QSettings>
//==============================================================================
#include "qwtbegin.h"
#include "qwt_symbol.h"
#include "qwtend.h"
//==============================================================================
namespace OpenCOR {
namespace SimulationExperimentView {
//==============================================================================
SimulationExperimentViewInformationGraphPanelAndGraphsWidget::SimulationExperimentViewInformationGraphPanelAndGraphsWidget(SimulationExperimentViewWidget *pViewWidget,
SimulationExperimentViewSimulationWidget *pSimulationWidget,
QWidget *pParent) :
QStackedWidget(pParent),
Core::CommonWidget(this),
mViewWidget(pViewWidget),
mSimulationWidget(pSimulationWidget)
{
// Create our graph panel context menu and populate it
mGraphPanelContextMenu = new QMenu(this);
mSelectGraphPanelColorAction = Core::newAction(this);
connect(mSelectGraphPanelColorAction, &QAction::triggered,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectGraphPanelColor);
mGraphPanelContextMenu->addAction(mSelectGraphPanelColorAction);
// Create our graph context menus and populate our main graph context menu
mGraphContextMenu = new QMenu(this);
mGraphParametersContextMenu = new QMenu(this);
mAddGraphAction = Core::newAction(this);
mRemoveCurrentGraphAction = Core::newAction(this);
mRemoveAllGraphsAction = Core::newAction(this);
mSelectAllGraphsAction = Core::newAction(this);
mUnselectAllGraphsAction = Core::newAction(this);
mSelectGraphColorAction = Core::newAction(this);
connect(mAddGraphAction, &QAction::triggered,
this, QOverload<>::of(&SimulationExperimentViewInformationGraphPanelAndGraphsWidget::addGraph));
connect(mRemoveCurrentGraphAction, &QAction::triggered,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::removeCurrentGraph);
connect(mRemoveAllGraphsAction, &QAction::triggered,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::removeAllGraphs);
connect(mSelectAllGraphsAction, &QAction::triggered,
this, QOverload<>::of(&SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectAllGraphs));
connect(mUnselectAllGraphsAction, &QAction::triggered,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::unselectAllGraphs);
connect(mSelectGraphColorAction, &QAction::triggered,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectGraphColor);
mGraphContextMenu->addAction(mAddGraphAction);
mGraphContextMenu->addSeparator();
mGraphContextMenu->addAction(mRemoveCurrentGraphAction);
mGraphContextMenu->addAction(mRemoveAllGraphsAction);
mGraphContextMenu->addSeparator();
mGraphContextMenu->addAction(mSelectAllGraphsAction);
mGraphContextMenu->addAction(mUnselectAllGraphsAction);
mGraphContextMenu->addSeparator();
mGraphContextMenu->addAction(mSelectGraphColorAction);
// Some further initialisations that are done as part of retranslating the
// GUI (so that they can be updated when changing languages)
retranslateUi();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::retranslateGraphPanelPropertyEditor(Core::PropertyEditorWidget *pGraphPanelPropertyEditor)
{
// Retranslate the contents of the given graph panel property editor
Core::Properties graphPanelProperties = pGraphPanelPropertyEditor->properties();
graphPanelProperties[0]->setName(tr("Background colour"));
graphPanelProperties[1]->setName(tr("Font size"));
graphPanelProperties[2]->setName(tr("Foreground colour"));
// Grid lines
Core::Properties gridLinesProperties = graphPanelProperties[3]->properties();
graphPanelProperties[3]->setName(tr("Grid lines"));
gridLinesProperties[0]->setName(tr("Style"));
gridLinesProperties[1]->setName(tr("Width"));
gridLinesProperties[2]->setName(tr("Colour"));
// Legend
graphPanelProperties[4]->setName(tr("Legend"));
// Point coordinates
Core::Properties pointCoordinatesProperties = graphPanelProperties[5]->properties();
graphPanelProperties[5]->setName(tr("Point coordinates"));
pointCoordinatesProperties[0]->setName(tr("Style"));
pointCoordinatesProperties[1]->setName(tr("Width"));
pointCoordinatesProperties[2]->setName(tr("Colour"));
pointCoordinatesProperties[3]->setName(tr("Font colour"));
// Surrounding area
Core::Properties surroundingAreaProperties = graphPanelProperties[6]->properties();
graphPanelProperties[6]->setName(tr("Surrounding area"));
surroundingAreaProperties[0]->setName(tr("Background colour"));
surroundingAreaProperties[1]->setName(tr("Foreground colour"));
// Title
graphPanelProperties[7]->setName(tr("Title"));
// X axis
Core::Properties xAxisProperties = graphPanelProperties[8]->properties();
graphPanelProperties[8]->setName(tr("X axis"));
xAxisProperties[0]->setName(tr("Logarithmic scale"));
xAxisProperties[1]->setName(tr("Title"));
// Y axis
Core::Properties yAxisProperties = graphPanelProperties[9]->properties();
graphPanelProperties[9]->setName(tr("Y axis"));
yAxisProperties[0]->setName(tr("Logarithmic scale"));
yAxisProperties[1]->setName(tr("Title"));
// Zoom region
Core::Properties zoomRegionProperties = graphPanelProperties[10]->properties();
graphPanelProperties[10]->setName(tr("Zoom region"));
zoomRegionProperties[0]->setName(tr("Style"));
zoomRegionProperties[1]->setName(tr("Width"));
zoomRegionProperties[2]->setName(tr("Colour"));
zoomRegionProperties[3]->setName(tr("Font colour"));
zoomRegionProperties[4]->setName(tr("Filled"));
zoomRegionProperties[5]->setName(tr("Fill colour"));
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::retranslateUi()
{
// Retranslate our actions
I18nInterface::retranslateAction(mSelectGraphPanelColorAction, tr("Select Colour..."),
tr("Select a colour"));
I18nInterface::retranslateAction(mAddGraphAction, tr("Add Graph"),
tr("Add a graph"));
I18nInterface::retranslateAction(mRemoveCurrentGraphAction, tr("Remove Current Graph"),
tr("Remove the current graph"));
I18nInterface::retranslateAction(mRemoveAllGraphsAction, tr("Remove All Graphs"),
tr("Remove all the graphs"));
I18nInterface::retranslateAction(mSelectAllGraphsAction, tr("Select All Graphs"),
tr("Select all the graphs"));
I18nInterface::retranslateAction(mUnselectAllGraphsAction, tr("Unselect All Graphs"),
tr("Unselect all the graphs"));
I18nInterface::retranslateAction(mSelectGraphColorAction, tr("Select Colour..."),
tr("Select a colour"));
// Retranslate all our property editors
for (auto graphPanelPropertyEditor : mGraphPanelPropertyEditors.values()) {
graphPanelPropertyEditor->retranslateUi();
}
for (auto graphsPropertyEditor : mGraphsPropertyEditors.values()) {
graphsPropertyEditor->retranslateUi();
}
// Retranslate the contents of our graph panel property editors
for (auto graphPanelPropertyEditor : mGraphPanelPropertyEditors.values()) {
retranslateGraphPanelPropertyEditor(graphPanelPropertyEditor);
}
// Retranslate the information about our graphs properties
// Note: no need to do this for all our property editors (i.e. call
// updateAllGraphsInfo()) since this will automatically be done when
// selecting another graph panel. So, instead, we just do this for our
// current graph panel...
updateGraphsInfo();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::initialize(SimulationSupport::Simulation *pSimulation)
{
// Keep track of the simulation
mSimulation = pSimulation;
// Populate our graph parameters context menu
populateGraphParametersContextMenu(pSimulation->runtime());
// Update our graphs information
updateAllGraphsInfo();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::finalize()
{
// Clear our graph parameters context menu and the the parameters associated
// with our model parameter actions
mGraphParametersContextMenu->clear();
mParameterActions.clear();
// Remove all our graphs' runs
for (auto graph : mGraphs.values()) {
graph->removeRuns();
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::importData(DataStore::DataStoreImportData *pImportData)
{
// Create our general import menu, if needed
if (mImportMenu == nullptr) {
mImportMenu = new QMenu("imports", mGraphParametersContextMenu);
mGraphParametersContextMenu->addMenu(mImportMenu);
}
// Create our import sub-menu
auto importSubMenu = new QMenu(pImportData->hierarchy().last(), mImportMenu);
mImportMenu->addMenu(importSubMenu);
// Populate our import sub-menu with the given data
for (auto parameter : mSimulation->runtime()->dataParameters(mSimulation->data()->data(pImportData->importDataStore()))) {
QAction *parameterAction = importSubMenu->addAction(CellMLSupport::CellmlFileRuntimeParameter::icon(parameter->type()),
parameter->formattedName());
// Create a connection to handle the parameter value update
connect(parameterAction, &QAction::triggered,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::updateParameterValue);
// Keep track of the parameter associated with our parameter action
mParameterActions.insert(parameterAction, parameter);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::initialize(GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const GraphPanelWidget::GraphPanelWidgetProperties &pGraphPanelWidgetProperties,
bool pActive,
bool pCustomize)
{
// Retrieve the graph panel and graphs property editors for the given file
// name or create some, if none exists
Core::PropertyEditorWidget *oldGraphPanelPropertyEditor = mGraphPanelPropertyEditor;
Core::PropertyEditorWidget *oldGraphsPropertyEditor = mGraphsPropertyEditor;
mGraphPanelPropertyEditor = mGraphPanelPropertyEditors.value(pGraphPanel);
mGraphsPropertyEditor = mGraphsPropertyEditors.value(pGraphPanel);
if ((mGraphPanelPropertyEditor == nullptr) && (mGraphsPropertyEditor == nullptr)) {
// No graph panel and graphs property editors exist for the given graph
// panel, so create some
mGraphPanelPropertyEditor = new Core::PropertyEditorWidget(false, false, this);
mGraphsPropertyEditor = new Core::PropertyEditorWidget(false, false, this);
// Keep track of the link between our existing graph panel and our new
// graph panel and graphs property editors
mGraphPanels.insert(mGraphPanelPropertyEditor, pGraphPanel);
mGraphPanels.insert(mGraphsPropertyEditor, pGraphPanel);
mGraphPanelPropertyEditors.insert(pGraphPanel, mGraphPanelPropertyEditor);
mGraphsPropertyEditors.insert(pGraphPanel, mGraphsPropertyEditor);
// Customise our corresponding graph panel with our preferences, if
// required
if (pCustomize) {
GraphPanelWidget::GraphPanelPlotWidget *graphPanelPlot = pGraphPanel->plot();
graphPanelPlot->setBackgroundColor(pGraphPanelWidgetProperties.backgroundColor());
graphPanelPlot->setForegroundColor(pGraphPanelWidgetProperties.foregroundColor());
graphPanelPlot->setLegendActive(pGraphPanelWidgetProperties.legend());
}
// Populate our graph panel property editor
populateGraphPanelPropertyEditor();
// We want our own context menu for our graph panel and graphs property
// editors
mGraphPanelPropertyEditor->setContextMenuPolicy(Qt::CustomContextMenu);
mGraphsPropertyEditor->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mGraphPanelPropertyEditor, &Core::PropertyEditorWidget::customContextMenuRequested,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::showGraphPanelContextMenu);
connect(mGraphsPropertyEditor, &Core::PropertyEditorWidget::customContextMenuRequested,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::showGraphsContextMenu);
// Keep track of changes to columns' width
connect(mGraphPanelPropertyEditor->header(), &QHeaderView::sectionResized,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphPanelHeaderSectionResized);
connect(mGraphsPropertyEditor->header(), &QHeaderView::sectionResized,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsHeaderSectionResized);
// Keep track of changes to the expanded/collapsed state of a property
// Note: we only need to do this for our graph panel property editor
// since graphs are really unique to a graph panel...
connect(mGraphPanelPropertyEditor, &Core::PropertyEditorWidget::expanded,
this, QOverload<const QModelIndex &>::of(&SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphPanelSectionExpanded));
connect(mGraphPanelPropertyEditor, &Core::PropertyEditorWidget::collapsed,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphPanelSectionCollapsed);
// Keep track of when the user changes a property value
connect(mGraphPanelPropertyEditor, &Core::PropertyEditorWidget::propertyChanged,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphPanelPropertyChanged);
connect(mGraphsPropertyEditor, &Core::PropertyEditorWidget::propertyChanged,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsPropertyChanged);
// Add our new graphs property editor to ourselves
addWidget(mGraphPanelPropertyEditor);
addWidget(mGraphsPropertyEditor);
}
// Make sure that our 'new' property editors' columns' width is the same as
// that of our 'old' property editors, and that the expanded state of our
// graph panel editor's sections is properly set
// Note: the only reason we check mGraphPanelPropertyEditor and
// mGraphsPropertyEditor is to keep Xcode happy...
if ( (oldGraphPanelPropertyEditor != nullptr) && (oldGraphsPropertyEditor != nullptr)
&& (mGraphPanelPropertyEditor != nullptr) && (mGraphsPropertyEditor != nullptr)) {
for (int i = 0, iMax = oldGraphPanelPropertyEditor->header()->count(); i < iMax; ++i) {
mGraphPanelPropertyEditor->setColumnWidth(i, oldGraphPanelPropertyEditor->columnWidth(i));
}
for (int i = 0, iMax = oldGraphsPropertyEditor->header()->count(); i < iMax; ++i) {
mGraphsPropertyEditor->setColumnWidth(i, oldGraphsPropertyEditor->columnWidth(i));
}
for (int i = 0, iMax = oldGraphPanelPropertyEditor->model()->rowCount(); i < iMax; ++i) {
mGraphPanelPropertyEditor->setExpanded(mGraphPanelPropertyEditor->model()->index(i, 0),
oldGraphPanelPropertyEditor->isExpanded(oldGraphPanelPropertyEditor->model()->index(i, 0)));
}
}
// Set our retrieved graph panel or graphs property editor as our current
// widget, but only if the corresponding graph panel has been been made
// active
if (pActive) {
setCurrentWidget((mMode == Mode::GraphPanel)?mGraphPanelPropertyEditor:mGraphsPropertyEditor);
}
// Update our graphs information
// Note: this is in case the user changed the locale and then switched to a
// different graph panel...
updateAllGraphsInfo();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::initialize(GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const GraphPanelWidget::GraphPanelWidgetProperties &pGraphPanelWidgetProperties,
bool pActive)
{
// Initialise the given graph panel
initialize(pGraphPanel, pGraphPanelWidgetProperties, pActive, true);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::initialize(GraphPanelWidget::GraphPanelWidget *pGraphPanel)
{
// Initialise the given graph panel
initialize(pGraphPanel, GraphPanelWidget::GraphPanelWidgetProperties(), true, false);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::finalize(GraphPanelWidget::GraphPanelWidget *pGraphPanel)
{
// Remove all the graphs associated with the given graph panel
pGraphPanel->removeAllGraphs();
// Remove track of the link betwen our graph panel and our graph panel and
// graphs property editors
Core::PropertyEditorWidget *graphPanelPropertyEditor = mGraphPanelPropertyEditors.value(pGraphPanel);
Core::PropertyEditorWidget *graphsPropertyEditor = mGraphsPropertyEditors.value(pGraphPanel);
if ( (graphPanelPropertyEditor == mGraphPanelPropertyEditor)
&& (graphsPropertyEditor == mGraphsPropertyEditor)) {
mGraphPanelPropertyEditor = nullptr;
mGraphsPropertyEditor = nullptr;
}
mGraphPanels.remove(graphPanelPropertyEditor);
mGraphPanels.remove(graphsPropertyEditor);
mGraphPanelPropertyEditors.remove(pGraphPanel);
mGraphsPropertyEditors.remove(pGraphPanel);
removeWidget(graphPanelPropertyEditor);
removeWidget(graphsPropertyEditor);
delete graphPanelPropertyEditor;
delete graphsPropertyEditor;
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::addGraph(GraphPanelWidget::GraphPanelWidget *pGraphPanel,
GraphPanelWidget::GraphPanelPlotGraph *pGraph,
const GraphPanelWidget::GraphPanelPlotGraphProperties &pGraphProperties)
{
// Make sure that we have a graphs property editor
Core::PropertyEditorWidget *graphsPropertyEditor = mGraphsPropertyEditors.value(pGraphPanel);
if (graphsPropertyEditor == nullptr) {
return;
}
// Create a section for our newly added graph
Core::Property *graphProperty = graphsPropertyEditor->addSectionProperty();
graphProperty->setCheckable(true);
graphProperty->setChecked(pGraphProperties.isSelected());
// Keep track of the link between our given graph and our graph property
mGraphs.insert(graphProperty, pGraph);
mGraphProperties.insert(pGraph, graphProperty);
// Create some graph properties
// Note #1: to add properties will result in the propertyChanged() signal
// being emitted, but we don't want to handle that signal (at
// least, not when creating a graph since not everyting may be set
// yet, so this might cause more problems than anything), so we
// must disconnect ourselves from it before adding the properties
// (and then reconnect ourselves to it once we are done)...
// Note #2: our graph properties have or can have an icon, but not our title
// property, so give it a blank icon so that it is properly aligned
// with our other properties...
disconnect(graphsPropertyEditor, &Core::PropertyEditorWidget::propertyChanged,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsPropertyChanged);
graphsPropertyEditor->addListProperty(graphProperty);
graphsPropertyEditor->addStringProperty(pGraphProperties.title(), graphProperty);
graphsPropertyEditor->addStringProperty((pGraph->parameterX() != nullptr)?
static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(pGraph->parameterX())->fullyFormattedName():
Core::UnknownValue,
graphProperty);
graphsPropertyEditor->addStringProperty((pGraph->parameterY() != nullptr)?
static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(pGraph->parameterY())->fullyFormattedName():
Core::UnknownValue,
graphProperty);
static const QIcon BlankIcon = QIcon(":/SimulationExperimentView/blank.png");
graphProperty->properties()[1]->setIcon(BlankIcon);
// Create some line properties for our graph
Core::Property *lineProperty = graphsPropertyEditor->addSectionProperty(graphProperty);
graphsPropertyEditor->addListProperty(SEDMLSupport::lineStyles(),
SEDMLSupport::stringLineStyle(pGraphProperties.lineStyle()),
lineProperty);
graphsPropertyEditor->addIntegerGt0Property(pGraphProperties.lineWidth(), lineProperty);
graphsPropertyEditor->addColorProperty(pGraphProperties.lineColor(), lineProperty);
// Create some symbol properties for our graph
Core::Property *symbolProperty = graphsPropertyEditor->addSectionProperty(graphProperty);
graphsPropertyEditor->addListProperty(SEDMLSupport::symbolStyles(),
SEDMLSupport::stringSymbolStyle(pGraphProperties.symbolStyle()),
symbolProperty);
graphsPropertyEditor->addIntegerGt0Property(pGraphProperties.symbolSize(), symbolProperty);
graphsPropertyEditor->addColorProperty(pGraphProperties.symbolColor(), symbolProperty);
graphsPropertyEditor->addBooleanProperty(pGraphProperties.symbolFilled(), symbolProperty);
graphsPropertyEditor->addColorProperty(pGraphProperties.symbolFillColor(), symbolProperty);
// Keep track of changes to our new graph
connect(graphsPropertyEditor, &Core::PropertyEditorWidget::propertyChanged,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsPropertyChanged);
// Update the information about our new graph
updateGraphsInfo(graphProperty);
// Make sure that the selected state of our new graph is taken into account
// Note: this must be done after the call to updateGraphsInfo() above
// otherwise our new graph's visible state won't be properly set...
graphsPropertyChanged(graphProperty);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::removeGraphs(GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const GraphPanelWidget::GraphPanelPlotGraphs &pGraphs)
{
// Make sure that we have a graphs property editor
Core::PropertyEditorWidget *graphsPropertyEditor = mGraphsPropertyEditors.value(pGraphPanel);
if (graphsPropertyEditor == nullptr) {
return;
}
// Remove the graph properties associated with the given graphs, as well as
// their trace
for (auto graph : pGraphs) {
Core::Property *property = mGraphProperties.value(graph);
graphsPropertyEditor->removeProperty(property);
mGraphs.remove(property);
mGraphProperties.remove(graph);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::toggleGraph(GraphPanelWidget::GraphPanelPlotGraph *pGraph)
{
// Toggle our graph property
Core::Property *graphProperty = mGraphProperties.value(pGraph);
graphProperty->setChecked(!graphProperty->isChecked());
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::toggleLegend()
{
// Toggle our legend property
Core::Property *legendProperty = mGraphPanelPropertyEditor->properties()[4];
legendProperty->setBooleanValue(!legendProperty->booleanValue());
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::toggleLogarithmicXAxis()
{
// Toggle our logarithmic X axis property
Core::Property *logarithmicXAxisProperty = mGraphPanelPropertyEditor->properties()[8]->properties()[0];
logarithmicXAxisProperty->setBooleanValue(!logarithmicXAxisProperty->booleanValue());
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::toggleLogarithmicYAxis()
{
// Toggle our logarithmic Y axis property
Core::Property *logarithmicYAxisProperty = mGraphPanelPropertyEditor->properties()[9]->properties()[0];
logarithmicYAxisProperty->setBooleanValue(!logarithmicYAxisProperty->booleanValue());
}
//==============================================================================
bool SimulationExperimentViewInformationGraphPanelAndGraphsWidget::rootProperty(Core::Property *pProperty) const
{
// Return whether the given property is a root property
return (pProperty->type() == Core::Property::Type::Section)
&& (pProperty->parentProperty() == nullptr) && pProperty->isCheckable();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectGraphPanelColor()
{
// Select a colour for the current property
mGraphPanelPropertyEditor->currentProperty()->setColorValue();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::addGraph()
{
// Ask the graph panel associated with our current graphs property editor to
// add an 'empty' graph
GraphPanelWidget::GraphPanelWidget * graphPanel = mGraphPanels.value(mGraphsPropertyEditor);
auto graph = new GraphPanelWidget::GraphPanelPlotGraph(graphPanel);
graphPanel->addGraph(graph, mSimulationWidget->defaultGraphProperties(graph->color()));
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::removeCurrentGraph()
{
// Ask the graph panel associated with our current graphs property editor to
// remove the current graph
mGraphPanels.value(mGraphsPropertyEditor)->removeGraphs(GraphPanelWidget::GraphPanelPlotGraphs() << mGraphs.value(mGraphsPropertyEditor->currentProperty()));
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::removeAllGraphs()
{
// Ask the graph panel associated with our current graphs property editor to
// remove all its graphs
mGraphPanels.value(mGraphsPropertyEditor)->removeAllGraphs();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectAllGraphs(bool pSelect)
{
// (Un)select all the graphs
// Note: normally, we would only update the checked state of our graph
// properties, which would in turn update the selected state of our
// graphs and let people know that they have been updated. Now, the
// problem with this is that every single graph is going to be shown/
// hidden indivdually. So, if we have loads of graphs with many data
// points, then it's going to be slow. So, instead, we disconnect the
// propertyChanged() signal, update the checked state of our graph
// properties as well as the selected state of our graphs, and then
// let people know that all the graphs have been updated...
disconnect(mGraphsPropertyEditor, &Core::PropertyEditorWidget::propertyChanged,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsPropertyChanged);
GraphPanelWidget::GraphPanelPlotGraphs graphs = GraphPanelWidget::GraphPanelPlotGraphs();
for (auto property : mGraphsPropertyEditor->properties()) {
property->setChecked(pSelect);
GraphPanelWidget::GraphPanelPlotGraph *graph = mGraphs.value(property);
graphs << graph;
graph->setSelected(pSelect);
}
if (!graphs.isEmpty()) {
emit graphsUpdated(graphs);
}
connect(mGraphsPropertyEditor, &Core::PropertyEditorWidget::propertyChanged,
this, &SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsPropertyChanged);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectAllGraphs()
{
// Select all the graphs
selectAllGraphs(true);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::unselectAllGraphs()
{
// Unselect all the graphs
selectAllGraphs(false);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectGraphColor()
{
// Select a colour for the current property
mGraphsPropertyEditor->currentProperty()->setColorValue();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::fileRenamed(const QString &pOldFileName,
const QString &pNewFileName)
{
// Keep track of the renamed model list value (so that we can take advantage
// of it in our calls to updateGraphsInfo() in updateAllGraphsInfo())
QString oldModelListValue = modelListValue(pOldFileName);
if (mRenamedModelListValues.values().contains(oldModelListValue)) {
// A previous model list value has been renamed again, so find its
// original value and update its new renamed version, if needed
for (const auto &origModelListValue : mRenamedModelListValues.keys()) {
QString renamedOrigModelListValue = mRenamedModelListValues.value(origModelListValue);
if (renamedOrigModelListValue == oldModelListValue) {
QString newModelListValue = modelListValue(pNewFileName);
if (origModelListValue == newModelListValue) {
// A model list value has been re-renamed to its original
// value, so stop tracking it
mRenamedModelListValues.remove(origModelListValue);
} else {
mRenamedModelListValues.insert(origModelListValue, newModelListValue);
}
break;
}
}
} else {
// Not a renamed model list value that we know, so just keep track of it
mRenamedModelListValues.insert(oldModelListValue, modelListValue(pNewFileName));
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::updateGui()
{
// Update our graphs information
// Note: this is useful, for example, if we created a graph for a file that
// has not yet been selected, in which case the graph will initially
// be invalid, but it should become valid after we have switched to
// that file and back...
updateAllGraphsInfo();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::finishEditing()
{
// Make sure that we have a graphs property editor
if (mGraphsPropertyEditor == nullptr) {
return;
}
// Ask our graphs property editor to finish editing
mGraphsPropertyEditor->finishEditing();
}
//==============================================================================
Core::PropertyEditorWidget * SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphPanelPropertyEditor(GraphPanelWidget::GraphPanelWidget *pGraphPanel) const
{
// Retrieve and return the graph panel property editor associated with the
// given graph panel
return mGraphPanelPropertyEditors.value(pGraphPanel);
}
//==============================================================================
Core::PropertyEditorWidget * SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsPropertyEditor(GraphPanelWidget::GraphPanelWidget *pGraphPanel) const
{
// Retrieve and return the graphs property editor associated with the given
// graph panel
return mGraphsPropertyEditors.value(pGraphPanel);
}
//==============================================================================
static const char *PropertySeparator = " | ";
//==============================================================================
Core::Properties SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsProperties(GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const QString &pFileName) const
{
// Retrieve and return all the graph properties associated with the given
// graph panel and file name, if any
Core::Properties res = Core::Properties();
for (auto property : mGraphsPropertyEditors.value(pGraphPanel)->properties()) {
// The property should be returned if its first sub-property (i.e. to
// which model the graph applies) has either a value of "Current" or
// that of the given file name
QString modelPropertyValue = property->properties().first()->value();
if ( (modelPropertyValue == tr("Current"))
|| (modelPropertyValue.split(PropertySeparator).last() == pFileName)) {
res << property;
}
}
return res;
}
//==============================================================================
SimulationExperimentViewInformationGraphPanelAndGraphsWidget::Mode SimulationExperimentViewInformationGraphPanelAndGraphsWidget::mode() const
{
// Return our mode
return mMode;
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::setMode(Mode pMode)
{
// Set our mode
if (pMode != mMode) {
mMode = pMode;
// Set our graph panel or graphs property editor as our current widget,
// if we have one (i.e. the model could be compiled)
Core::PropertyEditorWidget *propertyEditor = (pMode == Mode::GraphPanel)?mGraphPanelPropertyEditor:mGraphsPropertyEditor;
if (propertyEditor != nullptr) {
setCurrentWidget(propertyEditor);
}
// Let people know about our change of modes
emit graphPanelGraphsModeChanged(pMode);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::setGraphPanelColumnWidth(int pIndex,
int pColumnWidth)
{
// Make sure that we have a graph panel property editor
if (mGraphPanelPropertyEditor == nullptr) {
return;
}
// Set the width of the given column
mGraphPanelPropertyEditor->setColumnWidth(pIndex, pColumnWidth);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::setGraphsColumnWidth(int pIndex,
int pColumnWidth)
{
// Make sure that we have a graphs property editor
if (mGraphsPropertyEditor == nullptr) {
return;
}
// Set the width of the given column
mGraphsPropertyEditor->setColumnWidth(pIndex, pColumnWidth);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::setGraphPanelSectionExpanded(int pSection,
bool pExpanded)
{
// Make sure that we have a graph panel property editor
if (mGraphPanelPropertyEditor == nullptr) {
return;
}
// Expand/collapse the given section
mGraphPanelPropertyEditor->setExpanded(mGraphPanelPropertyEditor->model()->index(pSection, 0), pExpanded);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::reinitialize(GraphPanelWidget::GraphPanelWidget *pGraphPanel)
{
// Reinitialise ourselves
finalize(pGraphPanel);
initialize(pGraphPanel);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::showGraphPanelContextMenu(const QPoint &pPosition) const
{
Q_UNUSED(pPosition)
// Make sure that we have a graph panel property editor
if (mGraphPanelPropertyEditor == nullptr) {
return;
}
// Show the graph panel context menu, or not, depending on the type of
// property we are dealing with, if any
Core::Property *crtProperty = mGraphPanelPropertyEditor->currentProperty();
if ( (crtProperty != nullptr)
&& (crtProperty->type() == Core::Property::Type::Color)) {
mGraphPanelContextMenu->exec(QCursor::pos());
}