/
simulationexperimentviewinformationgraphpanelandgraphswidget.cpp
1272 lines (920 loc) · 53.5 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 "graphpanelwidget.h"
#include "i18ninterface.h"
#include "sedmlsupport.h"
#include "simulation.h"
#include "simulationexperimentviewinformationgraphpanelandgraphswidget.h"
#include "simulationexperimentviewsimulationwidget.h"
#include "simulationexperimentviewwidget.h"
//==============================================================================
#include <QColorDialog>
#include <QFileInfo>
#include <QHeaderView>
#include <QMenu>
#include <QScrollBar>
#include <QSettings>
//==============================================================================
#include "qwt_symbol.h"
//==============================================================================
namespace OpenCOR {
namespace SimulationExperimentView {
//==============================================================================
SimulationExperimentViewInformationGraphPanelAndGraphsWidget::SimulationExperimentViewInformationGraphPanelAndGraphsWidget(SimulationExperimentViewWidget *pViewWidget,
SimulationExperimentViewSimulationWidget *pSimulationWidget,
QWidget *pParent) :
QStackedWidget(pParent),
Core::CommonWidget(pParent),
mMode(Graphs),
mViewWidget(pViewWidget),
mSimulationWidget(pSimulationWidget),
mGraphPanels(QMap<Core::PropertyEditorWidget *, GraphPanelWidget::GraphPanelWidget *>()),
mGraphPanelPropertyEditors(QMap<GraphPanelWidget::GraphPanelWidget *, Core::PropertyEditorWidget *>()),
mGraphsPropertyEditors(QMap<GraphPanelWidget::GraphPanelWidget *, Core::PropertyEditorWidget *>()),
mGraphPanelPropertyEditor(0),
mGraphsPropertyEditor(0),
mGraphs(QMap<Core::Property *, GraphPanelWidget::GraphPanelPlotGraph *>()),
mGraphProperties(QMap<GraphPanelWidget::GraphPanelPlotGraph *, Core::Property *>()),
mParameterActions(QMap<QAction *, CellMLSupport::CellmlFileRuntimeParameter *>()),
mRenamedModelListValues(QMap<QString, QString>()),
mGraphPanelHorizontalScrollBarValue(0),
mGraphsHorizontalScrollBarValue(0)
{
// Create our context menus and populate our main context menu
mContextMenu = new QMenu(this);
mParametersContextMenu = new QMenu(this);
mAddGraphAction = Core::newAction(this);
mRemoveCurrentGraphAction = Core::newAction(this);
mRemoveAllGraphsAction = Core::newAction(this);
mSelectAllGraphsAction = Core::newAction(this);
mUnselectAllGraphsAction = Core::newAction(this);
mSelectColorAction = Core::newAction(this);
connect(mAddGraphAction, SIGNAL(triggered(bool)),
this, SLOT(addGraph()));
connect(mRemoveCurrentGraphAction, SIGNAL(triggered(bool)),
this, SLOT(removeCurrentGraph()));
connect(mRemoveAllGraphsAction, SIGNAL(triggered(bool)),
this, SLOT(removeAllGraphs()));
connect(mSelectAllGraphsAction, SIGNAL(triggered(bool)),
this, SLOT(selectAllGraphs()));
connect(mUnselectAllGraphsAction, SIGNAL(triggered(bool)),
this, SLOT(unselectAllGraphs()));
connect(mSelectColorAction, SIGNAL(triggered(bool)),
this, SLOT(selectColor()));
mContextMenu->addAction(mAddGraphAction);
mContextMenu->addSeparator();
mContextMenu->addAction(mRemoveCurrentGraphAction);
mContextMenu->addAction(mRemoveAllGraphsAction);
mContextMenu->addSeparator();
mContextMenu->addAction(mSelectAllGraphsAction);
mContextMenu->addAction(mUnselectAllGraphsAction);
mContextMenu->addSeparator();
mContextMenu->addAction(mSelectColorAction);
// Some further initialisations that are done as part of retranslating the
// GUI (so that they can be updated when changing languages)
retranslateUi();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::retranslateUi()
{
// Retranslate our actions
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(mSelectColorAction, tr("Select Colour..."),
tr("Select a colour"));
// Retranslate all our property editors
foreach (Core::PropertyEditorWidget *graphPanelPropertyEditor, mGraphPanelPropertyEditors)
graphPanelPropertyEditor->retranslateUi();
foreach (Core::PropertyEditorWidget *graphsPropertyEditor, mGraphsPropertyEditors)
graphsPropertyEditor->retranslateUi();
// Retranslate the contents of our graph panel property editors
foreach (Core::PropertyEditorWidget *graphPanelPropertyEditor, mGraphPanelPropertyEditors) {
graphPanelPropertyEditor->properties()[0]->setName(tr("Colour"));
graphPanelPropertyEditor->properties()[1]->setName(tr("Font size"));
graphPanelPropertyEditor->properties()[2]->setName(tr("Grid lines"));
graphPanelPropertyEditor->properties()[2]->properties()[0]->setName(tr("Style"));
graphPanelPropertyEditor->properties()[2]->properties()[1]->setName(tr("Width"));
graphPanelPropertyEditor->properties()[2]->properties()[2]->setName(tr("Colour"));
graphPanelPropertyEditor->properties()[3]->setName(tr("Logarithmic X axis"));
graphPanelPropertyEditor->properties()[4]->setName(tr("Logarithmic Y axis"));
graphPanelPropertyEditor->properties()[5]->setName(tr("Point coordinates"));
graphPanelPropertyEditor->properties()[5]->properties()[0]->setName(tr("Style"));
graphPanelPropertyEditor->properties()[5]->properties()[1]->setName(tr("Width"));
graphPanelPropertyEditor->properties()[5]->properties()[2]->setName(tr("Colour"));
graphPanelPropertyEditor->properties()[5]->properties()[3]->setName(tr("Font colour"));
graphPanelPropertyEditor->properties()[6]->setName(tr("Zoom region"));
graphPanelPropertyEditor->properties()[6]->properties()[0]->setName(tr("Style"));
graphPanelPropertyEditor->properties()[6]->properties()[1]->setName(tr("Width"));
graphPanelPropertyEditor->properties()[6]->properties()[2]->setName(tr("Colour"));
graphPanelPropertyEditor->properties()[6]->properties()[3]->setName(tr("Filled"));
graphPanelPropertyEditor->properties()[6]->properties()[4]->setName(tr("Fill colour"));
}
// 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)
{
// Populate our parameters context menu
populateParametersContextMenu(pSimulation->runtime());
// Update our graphs information
updateAllGraphsInfo();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::finalize()
{
// Clear our parameters context menu
mParametersContextMenu->clear();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::initialize(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const bool &pActive)
{
// 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 && !mGraphsPropertyEditor) {
// 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);
// Populate our graph panel property editor
populateGraphPanelPropertyEditor();
// We want our own context menu for our graphs property editor
mGraphsPropertyEditor->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mGraphsPropertyEditor, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showGraphsContextMenu(const QPoint &)));
// Keep track of changes to our property editors' horizontal bar's value
connect(mGraphPanelPropertyEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(graphPanelPropertyEditorHorizontalScrollBarValueChanged(const int &)));
connect(mGraphsPropertyEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(graphsPropertyEditorHorizontalScrollBarValueChanged(const int &)));
// Keep track of changes to columns' width
connect(mGraphPanelPropertyEditor->header(), SIGNAL(sectionResized(int, int, int)),
this, SIGNAL(graphPanelHeaderSectionResized(const int &, const int &, const int &)));
connect(mGraphsPropertyEditor->header(), SIGNAL(sectionResized(int, int, int)),
this, SIGNAL(graphsHeaderSectionResized(const int &, const int &, const int &)));
// Keep track of when the user changes a property value
//---ISSUE1426--- CHECK WHETHER WE NEED TO HANDLE THAT SIGNAL FOR OUR GRAPH
// PANEL EDITOR...
connect(mGraphsPropertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphsPropertyChanged(Core::Property *)));
// Add our new graphs property editor to ourselves
addWidget(mGraphPanelPropertyEditor);
addWidget(mGraphsPropertyEditor);
// Keep track of the link between our existing graph panel and our new
// graphs property editor
mGraphPanels.insert(mGraphsPropertyEditor, pGraphPanel);
mGraphPanelPropertyEditors.insert(pGraphPanel, mGraphPanelPropertyEditor);
mGraphsPropertyEditors.insert(pGraphPanel, mGraphsPropertyEditor);
}
// Set the value of our property editors' horizontal scroll bar
mGraphPanelPropertyEditor->horizontalScrollBar()->setValue(mGraphPanelHorizontalScrollBarValue);
mGraphsPropertyEditor->horizontalScrollBar()->setValue(mGraphsHorizontalScrollBarValue);
// Make sure that our 'new' property editors' columns' width is the same as
// that of our 'old' property editors
if (oldGraphPanelPropertyEditor && oldGraphsPropertyEditor) {
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));
}
// 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 == 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::finalize(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel)
{
// Remove track of the link betwen our graph panel and our graphs property
// editor
mGraphPanels.remove(mGraphsPropertyEditors.value(pGraphPanel));
mGraphPanelPropertyEditors.remove(pGraphPanel);
mGraphsPropertyEditors.remove(pGraphPanel);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::addGraph(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel,
OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *pGraph,
const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphProperties &pGraphProperties)
{
// Make sure that we have a graphs property editor
Core::PropertyEditorWidget *graphsPropertyEditor = mGraphsPropertyEditors.value(pGraphPanel);
if (!graphsPropertyEditor)
return;
// Create a section for our newly added graph
Core::Property *graphProperty = graphsPropertyEditor->addSectionProperty();
graphProperty->setCheckable(true);
graphProperty->setChecked(true);
// 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: 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)...
disconnect(graphsPropertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphsPropertyChanged(Core::Property *)));
graphsPropertyEditor->addListProperty(graphProperty);
graphsPropertyEditor->addStringProperty(pGraph->parameterX()?
static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(pGraph->parameterX())->fullyFormattedName():
Core::UnknownValue,
graphProperty);
graphsPropertyEditor->addStringProperty(pGraph->parameterY()?
static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(pGraph->parameterY())->fullyFormattedName():
Core::UnknownValue,
graphProperty);
// Create some line properties for our graph
Core::Property *lineProperty = graphsPropertyEditor->addSectionProperty(graphProperty);
graphsPropertyEditor->addListProperty(SEDMLSupport::lineStyles(),
SEDMLSupport::lineStyleValue((pGraphProperties.lineStyle() > Qt::DashDotDotLine)?
Qt::SolidLine:
pGraphProperties.lineStyle()),
lineProperty);
graphsPropertyEditor->addDoubleGt0Property(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::symbolStyleValue((pGraphProperties.symbolStyle() <= QwtSymbol::DTriangle)?
pGraphProperties.symbolStyle()+1:
((pGraphProperties.symbolStyle() >= QwtSymbol::Cross) && (pGraphProperties.symbolStyle() <= QwtSymbol::Star1))?
pGraphProperties.symbolStyle()-2:
QwtSymbol::NoSymbol),
symbolProperty);
graphsPropertyEditor->addIntegerGt0Property(pGraphProperties.symbolSize(), symbolProperty);
graphsPropertyEditor->addColorProperty(pGraphProperties.symbolColor(), symbolProperty);
graphsPropertyEditor->addBooleanProperty(pGraphProperties.symbolFilled(), symbolProperty);
graphsPropertyEditor->addColorProperty(pGraphProperties.symbolFillColor(), symbolProperty);
connect(graphsPropertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphsPropertyChanged(Core::Property *)));
// Update the information about our new graph
updateGraphsInfo(graphProperty);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::removeGraphs(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &pGraphs)
{
// Make sure that we have a graphs property editor
Core::PropertyEditorWidget *graphsPropertyEditor = mGraphsPropertyEditors.value(pGraphPanel);
if (!graphsPropertyEditor)
return;
// Remove the graph properties associated with the given graphs, as well as
// their trace
foreach (GraphPanelWidget::GraphPanelPlotGraph *graph, pGraphs) {
Core::Property *property = mGraphProperties.value(graph);
graphsPropertyEditor->removeProperty(property);
mGraphs.remove(property);
mGraphProperties.remove(graph);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::addGraph()
{
// Ask the graph panel associated with our current graphs property editor to
// add an 'empty' graph
mGraphPanels.value(mGraphsPropertyEditor)->addGraph(new GraphPanelWidget::GraphPanelPlotGraph());
}
//==============================================================================
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 the graphs
mGraphPanels.value(mGraphsPropertyEditor)->removeGraphs(mGraphs.values());
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectAllGraphs(const 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, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphsPropertyChanged(Core::Property *)));
foreach (Core::Property *property, mGraphProperties)
property->setChecked(pSelect);
foreach (GraphPanelWidget::GraphPanelPlotGraph *graph, mGraphs)
graph->setSelected(pSelect);
if (mGraphs.count())
emit graphsUpdated(mGraphs.values());
connect(mGraphsPropertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphsPropertyChanged(Core::Property *)));
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectAllGraphs()
{
// Select all the graphs
selectAllGraphs(true);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::unselectAllGraphs()
{
// Unselect all the graphs
selectAllGraphs(false);
}
//==============================================================================
bool SimulationExperimentViewInformationGraphPanelAndGraphsWidget::rootProperty(Core::Property *pProperty) const
{
// Return whether the given property is a root property
return (pProperty->type() == Core::Property::Section)
&& !pProperty->parentProperty() && pProperty->isCheckable();
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::selectColor()
{
// Select a colour and assign it to the current property
QColorDialog colorDialog(mGraphsPropertyEditor->currentProperty()->colorValue(), this);
colorDialog.setOption(QColorDialog::ShowAlphaChannel);
colorDialog.setWindowTitle(tr("Select Colour"));
if (colorDialog.exec()) {
Core::Property *crtProperty = mGraphsPropertyEditor->currentProperty();
crtProperty->setColorValue(colorDialog.currentColor());
}
}
//==============================================================================
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
foreach (const QString &origModelListValue, mRenamedModelListValues.keys()) {
QString oldModelListValue = mRenamedModelListValues.value(origModelListValue);
if (!oldModelListValue.compare(oldModelListValue)) {
QString newModelListValue = modelListValue(pNewFileName);
if (!origModelListValue.compare(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)
return;
// Ask our graphs property editor to finish editing
mGraphsPropertyEditor->finishEditing();
}
//==============================================================================
static const auto PropertySeparator = QStringLiteral(" | ");
//==============================================================================
Core::Properties SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphProperties(GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const QString &pFileName) const
{
// Retrieve and return all the graph properties associated with the given
// graph and file name, if any
Core::Properties res = Core::Properties();
Core::PropertyEditorWidget *graphsPropertyEditor = mGraphsPropertyEditors.value(pGraphPanel);
if (graphsPropertyEditor) {
foreach (Core::Property *property, graphsPropertyEditor->properties()) {
// The property should be returned if it is checked (i.e. a selected
// graph) and have 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
if (property->isChecked()) {
QString modelPropertyValue = property->properties().first()->value();
if ( !modelPropertyValue.compare(tr("Current"))
|| !modelPropertyValue.split(PropertySeparator).last().compare(pFileName)) {
res << property;
}
}
}
}
return res;
}
//==============================================================================
SimulationExperimentViewInformationGraphPanelAndGraphsWidget::Mode SimulationExperimentViewInformationGraphPanelAndGraphsWidget::mode() const
{
// Return our mode
return mMode;
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::setMode(const Mode &pMode)
{
// Set our mode
if (pMode != mMode) {
mMode = pMode;
// Set our graph panel or graphs property editor as our current
// widget
setCurrentWidget((pMode == GraphPanel)?mGraphPanelPropertyEditor:mGraphsPropertyEditor);
// Let people know about our change of modes
emit graphPanelGraphsModeChanged(pMode);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::setGraphPanelColumnWidth(const int &pIndex,
const int &pColumnWidth)
{
// Make sure that we have a graph panel property editor
if (!mGraphPanelPropertyEditor)
return;
// Set the width of the given column
mGraphPanelPropertyEditor->setColumnWidth(pIndex, pColumnWidth);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::setGraphsColumnWidth(const int &pIndex,
const int &pColumnWidth)
{
// Make sure that we have a graphs property editor
if (!mGraphsPropertyEditor)
return;
// Set the width of the given column
mGraphsPropertyEditor->setColumnWidth(pIndex, pColumnWidth);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::showGraphsContextMenu(const QPoint &pPosition) const
{
Q_UNUSED(pPosition);
// Make sure that we have a graphs property editor
if (!mGraphsPropertyEditor)
return;
// Retrieve our current property, if any
Core::Property *crtProperty = mGraphsPropertyEditor->currentProperty();
// Update the enabled state of some of our actions
mRemoveCurrentGraphAction->setEnabled(crtProperty);
mRemoveAllGraphsAction->setEnabled(!mGraphsPropertyEditor->properties().isEmpty());
bool canSelectAllGraphs = false;
bool canUnselectAllGraphs = false;
foreach (Core::Property *property, mGraphProperties) {
bool graphSelected = property->isChecked();
canSelectAllGraphs = canSelectAllGraphs || !graphSelected;
canUnselectAllGraphs = canUnselectAllGraphs || graphSelected;
}
mSelectAllGraphsAction->setEnabled(canSelectAllGraphs);
mUnselectAllGraphsAction->setEnabled(canUnselectAllGraphs);
mSelectColorAction->setVisible( crtProperty
&& (crtProperty->type() == Core::Property::Color));
// Show the context menu, or not, depending on the type of property we are
// dealing with, if any
if ( crtProperty
&& ( !crtProperty->name().compare(tr("X"))
|| !crtProperty->name().compare(tr("Y")))) {
mParametersContextMenu->exec(QCursor::pos());
} else {
mContextMenu->exec(QCursor::pos());
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphPanelPropertyEditorHorizontalScrollBarValueChanged(const int &pValue)
{
// Keep track of the graph panel property editor's horizontal scroll bar
// value
mGraphPanelHorizontalScrollBarValue = pValue;
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphsPropertyEditorHorizontalScrollBarValueChanged(const int &pValue)
{
// Keep track of the graphs property editor's horizontal scroll bar value
mGraphsHorizontalScrollBarValue = pValue;
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::populateGraphPanelPropertyEditor()
{
// Populate our graph panel property editor
mGraphPanelPropertyEditor->addColorProperty();
mGraphPanelPropertyEditor->addDoubleGt0Property();
Core::Property *gridLinesProperty = mGraphPanelPropertyEditor->addSectionProperty();
mGraphPanelPropertyEditor->addListProperty(SEDMLSupport::lineStyles(), gridLinesProperty);
mGraphPanelPropertyEditor->addDoubleGt0Property(gridLinesProperty);
mGraphPanelPropertyEditor->addColorProperty(gridLinesProperty);
mGraphPanelPropertyEditor->addBooleanProperty();
mGraphPanelPropertyEditor->addBooleanProperty();
Core::Property *pointCoordinatesProperty = mGraphPanelPropertyEditor->addSectionProperty();
mGraphPanelPropertyEditor->addListProperty(SEDMLSupport::lineStyles(), pointCoordinatesProperty);
mGraphPanelPropertyEditor->addDoubleGt0Property(pointCoordinatesProperty);
mGraphPanelPropertyEditor->addColorProperty(pointCoordinatesProperty);
mGraphPanelPropertyEditor->addColorProperty(pointCoordinatesProperty);
Core::Property *zoomRegionProperty = mGraphPanelPropertyEditor->addSectionProperty();
mGraphPanelPropertyEditor->addListProperty(SEDMLSupport::lineStyles(), zoomRegionProperty);
mGraphPanelPropertyEditor->addDoubleGt0Property(zoomRegionProperty);
mGraphPanelPropertyEditor->addColorProperty(zoomRegionProperty);
mGraphPanelPropertyEditor->addBooleanProperty(zoomRegionProperty);
mGraphPanelPropertyEditor->addColorProperty(zoomRegionProperty);
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::populateParametersContextMenu(CellMLSupport::CellmlFileRuntime *pRuntime)
{
// Populate our parameters context menu with the contents of our main
// context menu
mParametersContextMenu->addActions(mContextMenu->actions());
mParametersContextMenu->addSeparator();
// Now, add our model parameters to it
QString componentHierarchy = QString();
QMenu *componentMenu = 0;
foreach (CellMLSupport::CellmlFileRuntimeParameter *parameter, pRuntime->parameters()) {
// Check whether the current parameter is in the same component
// hierarchy as the previous one
QString crtComponentHierarchy = parameter->formattedComponentHierarchy();
if (crtComponentHierarchy.compare(componentHierarchy)) {
// The current parameter is in a different component hierarchy, so
// create a new menu hierarchy for our 'new' component, reusing
// existing menus, whenever possible
QMenu *parentComponentMenu = mParametersContextMenu;
foreach (const QString &component, parameter->componentHierarchy()) {
// Check whether we already have a menu for our current
// component
componentMenu = 0;
foreach (QObject *object, parentComponentMenu->children()) {
QMenu *subMenu = qobject_cast<QMenu *>(object);
if (subMenu && !subMenu->menuAction()->text().compare(component)) {
componentMenu = subMenu;
break;
}
}
// Create a new menu for our current component, if none could be
// found
if (!componentMenu) {
componentMenu = new QMenu(component, parentComponentMenu);
parentComponentMenu->addMenu(componentMenu);
}
// Get ready for the next component in our component hierarchy
parentComponentMenu = componentMenu;
}
// Keep track of the new component hierarchy
componentHierarchy = crtComponentHierarchy;
}
// Make sure that we have a 'current' component menu
// Note: this should never happen, but we never know...
if (!componentMenu)
continue;
// Add the current parameter to the 'current' component menu
QAction *parameterAction = componentMenu->addAction(parameter->icon(),
parameter->formattedName());
// Create a connection to handle the parameter value update
connect(parameterAction, SIGNAL(triggered(bool)),
this, SLOT(updateParameterValue()));
// Keep track of the parameter associated with our model parameter
// action
mParameterActions.insert(parameterAction, parameter);
}
}
//==============================================================================
bool SimulationExperimentViewInformationGraphPanelAndGraphsWidget::checkParameter(CellMLSupport::CellmlFileRuntime *pRuntime,
GraphPanelWidget::GraphPanelPlotGraph *pGraph,
Core::Property *pParameterProperty,
const bool &pParameterX) const
{
// Check that the information held by the given property corresponds to
// an existing parameter in our runtime
CellMLSupport::CellmlFileRuntimeParameter *res = 0;
if (pRuntime) {
// Retrieve the component and parameter of the property
QStringList info = pParameterProperty->value().split('.');
QStringList componentHierarchy = info;
componentHierarchy.removeLast();
// Determine the degree of our parameter, if any
QString parameterName = info.last();
int parameterDegree = parameterName.length();
parameterName.replace('\'', QString());
parameterDegree -= parameterName.length();
// Check whether we can find our property among our runtime's parameters
foreach (CellMLSupport::CellmlFileRuntimeParameter *parameter, pRuntime->parameters()) {
if ( (parameter->componentHierarchy() == componentHierarchy)
&& !parameter->name().compare(parameterName)
&& (parameter->degree() == parameterDegree)) {
res = parameter;
break;
}
}
}
// Update our parameter property based on whether it corresponds to an
// existing parameter in our runtime
static const QIcon BlankIcon = QIcon(":/SimulationExperimentView/blank.png");
static const QIcon WarningIcon = QIcon(":/oxygen/status/task-attention.png");
pParameterProperty->setIcon(res?BlankIcon:WarningIcon);
pParameterProperty->setExtraInfo(res?
QString():
pRuntime?
tr("does not exist"):
tr("no runtime"));
// Keep track of the existing parameter, if any, to which our property
// corresponds
if (pParameterX)
pGraph->setParameterX(res);
else
pGraph->setParameterY(res);
return res;
}
//==============================================================================
QString SimulationExperimentViewInformationGraphPanelAndGraphsWidget::modelListValue(const QString &pFileName) const
{
// Return the model list value for the given file name
return QFileInfo(pFileName).fileName()+PropertySeparator+pFileName;
}
//==============================================================================
void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::updateGraphInfo(Core::Property *pProperty)
{
// Make sure that we have a property
if (!pProperty)
return;
// Update the model property's icon, based on the value of the model
// property, and determine the file name against which we have to check our
// X and Y properties
static const QIcon LockedIcon = QIcon(":/oxygen/status/object-locked.png");
static const QIcon UnlockedIcon = QIcon(":/oxygen/status/object-unlocked.png");
GraphPanelWidget::GraphPanelPlotGraph *graph = mGraphs.value(pProperty);
QString propertyFileName = pProperty->properties()[0]->value();
QString fileName = mSimulationWidget->fileName();
if (!propertyFileName.compare(tr("Current"))) {
pProperty->properties()[0]->setIcon(UnlockedIcon);
} else {
pProperty->properties()[0]->setIcon(LockedIcon);
fileName = propertyFileName.split(PropertySeparator).last();
}
// Check that the parameters represented by the value of the X and Y
// properties exist for the current/selected model
// Note: we absolutely want to check the parameter (so that an icon can be
// assigned to its corresponding property) , hence the order of our &&
// tests when setting graphOk...
bool graphOk = true;
CellMLSupport::CellmlFileRuntime *runtime = mViewWidget->runtime(fileName);
CellMLSupport::CellmlFileRuntimeParameter *oldParameterX = static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(graph->parameterX());
CellMLSupport::CellmlFileRuntimeParameter *oldParameterY = static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(graph->parameterY());
graphOk = checkParameter(runtime, graph, pProperty->properties()[1], true) && graphOk;
graphOk = checkParameter(runtime, graph, pProperty->properties()[2], false) && graphOk;
// Update our section's name, if possible
// Note: indeed, when populating ourselves, updateGraphInfo() gets called
// (through graphsPropertyChanged()), yet we don't want to (and can't)
// do what follows if not all the properties are available...
pProperty->setName( pProperty->properties()[1]->value()
+PropertySeparator
+pProperty->properties()[2]->value());