/
simulationexperimentviewinformationgraphswidget.cpp
1082 lines (774 loc) · 42.3 KB
/
simulationexperimentviewinformationgraphswidget.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 graphs widget
//==============================================================================
#include "cellmlfileruntime.h"
#include "coreguiutils.h"
#include "filemanager.h"
#include "graphpanelwidget.h"
#include "i18ninterface.h"
#include "simulation.h"
#include "simulationexperimentviewinformationgraphswidget.h"
#include "simulationexperimentviewsimulationwidget.h"
#include "simulationexperimentviewwidget.h"
//==============================================================================
#include <QFileInfo>
#include <QHeaderView>
#include <QMenu>
#include <QScrollBar>
#include <QSettings>
//==============================================================================
namespace OpenCOR {
namespace SimulationExperimentView {
//==============================================================================
SimulationExperimentViewInformationGraphsWidget::SimulationExperimentViewInformationGraphsWidget(SimulationExperimentViewWidget *pViewWidget,
SimulationExperimentViewSimulationWidget *pSimulationWidget,
QWidget *pParent) :
QStackedWidget(pParent),
Core::CommonWidget(this),
mViewWidget(pViewWidget),
mSimulationWidget(pSimulationWidget),
mGraphPanels(QMap<Core::PropertyEditorWidget *, GraphPanelWidget::GraphPanelWidget *>()),
mPropertyEditors(QMap<GraphPanelWidget::GraphPanelWidget *, Core::PropertyEditorWidget *>()),
mPropertyEditor(0),
mGraphs(QMap<Core::Property *, GraphPanelWidget::GraphPanelPlotGraph *>()),
mGraphProperties(QMap<GraphPanelWidget::GraphPanelPlotGraph *, Core::Property *>()),
mParameterActions(QMap<QAction *, CellMLSupport::CellmlFileRuntimeParameter *>()),
mRenamedModelListValues(QMap<QString, QString>()),
mHorizontalScrollBarValue(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);
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()));
mContextMenu->addAction(mAddGraphAction);
mContextMenu->addSeparator();
mContextMenu->addAction(mRemoveCurrentGraphAction);
mContextMenu->addAction(mRemoveAllGraphsAction);
mContextMenu->addSeparator();
mContextMenu->addAction(mSelectAllGraphsAction);
mContextMenu->addAction(mUnselectAllGraphsAction);
// Some further initialisations that are done as part of retranslating the
// GUI (so that they can be updated when changing languages)
retranslateUi();
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::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"));
// Retranslate all our property editors
foreach (Core::PropertyEditorWidget *propertyEditor, mPropertyEditors)
propertyEditor->retranslateUi();
// 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 SimulationExperimentViewInformationGraphsWidget::initialize(SimulationSupport::Simulation *pSimulation)
{
// Populate our parameters context menu
populateParametersContextMenu(pSimulation->runtime());
// Update our graphs information
updateAllGraphsInfo();
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::finalize()
{
// Clear our parameters context menu
mParametersContextMenu->clear();
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::initialize(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const bool &pActive)
{
// Retrieve the property editor for the given file name or create one, if
// none exists
Core::PropertyEditorWidget *oldPropertyEditor = mPropertyEditor;
mPropertyEditor = mPropertyEditors.value(pGraphPanel);
if (!mPropertyEditor) {
// No property editor exists for the given graph panel, so create one
mPropertyEditor = new Core::PropertyEditorWidget(false, false, this);
// We want our own context menu for our property editor
mPropertyEditor->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mPropertyEditor, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(propertyEditorContextMenu(const QPoint &)));
// Keep track of changes to the horizontal bar's value
connect(mPropertyEditor->horizontalScrollBar(), SIGNAL(valueChanged(int)),
this, SLOT(propertyEditorHorizontalScrollBarValueChanged(const int &)));
// Keep track of changes to columns' width
connect(mPropertyEditor->header(), SIGNAL(sectionResized(int, int, int)),
this, SLOT(propertyEditorSectionResized(const int &, const int &, const int &)));
// Keep track of when the user changes a property value
connect(mPropertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphChanged(Core::Property *)));
// Add our new property editor to ourselves
addWidget(mPropertyEditor);
// Keep track of the link between our existing graph panel and our new
// property editor
mGraphPanels.insert(mPropertyEditor, pGraphPanel);
mPropertyEditors.insert(pGraphPanel, mPropertyEditor);
}
// Set the value of the property editor's horizontal scroll bar
mPropertyEditor->horizontalScrollBar()->setValue(mHorizontalScrollBarValue);
// Make sure that our 'new' property editor's columns' width is the same as
// that of our 'old' property editor
if (oldPropertyEditor) {
for (int i = 0, iMax = oldPropertyEditor->header()->count(); i < iMax; ++i)
mPropertyEditor->setColumnWidth(i, oldPropertyEditor->columnWidth(i));
}
// Set our retrieved property editor as our current widget, but only if the
// corresponding graph panel has been been made active
if (pActive)
setCurrentWidget(mPropertyEditor);
// Update our graphs information
// Note: this is in case the user changed the locale and then switched to a
// different graph panel...
updateAllGraphsInfo();
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::finalize(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel)
{
// Remove track of the link betwen our graph panel and our property editor
mGraphPanels.remove(mPropertyEditors.value(pGraphPanel));
mPropertyEditors.remove(pGraphPanel);
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::addGraph(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel,
OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *pGraph)
{
// Make sure that we have a property editor
Core::PropertyEditorWidget *propertyEditor = mPropertyEditors.value(pGraphPanel);
if (!propertyEditor)
return;
// Create a section for our newly added graph
Core::Property *graphProperty = propertyEditor->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(propertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphChanged(Core::Property *)));
propertyEditor->addListProperty(graphProperty);
propertyEditor->addStringProperty(pGraph->parameterX()?
static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(pGraph->parameterX())->fullyFormattedName():
Core::UnknownValue,
graphProperty);
propertyEditor->addStringProperty(pGraph->parameterY()?
static_cast<CellMLSupport::CellmlFileRuntimeParameter *>(pGraph->parameterY())->fullyFormattedName():
Core::UnknownValue,
graphProperty);
// Create some line properties for our graph
Core::Property *lineProperty = propertyEditor->addSectionProperty(graphProperty);
propertyEditor->addListProperty(lineProperty);
propertyEditor->addStringProperty(Core::UnknownValue, lineProperty);
propertyEditor->addDoubleProperty(1.0, lineProperty);
// Create some symbol properties for our graph
Core::Property *symbolProperty = propertyEditor->addSectionProperty(graphProperty);
propertyEditor->addListProperty(symbolProperty);
propertyEditor->addBooleanProperty(symbolProperty);
propertyEditor->addStringProperty(Core::UnknownValue, symbolProperty);
propertyEditor->addStringProperty(Core::UnknownValue, symbolProperty);
connect(propertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphChanged(Core::Property *)));
// Update the information about our new graph
updateGraphsInfo(graphProperty);
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::removeGraphs(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel,
const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &pGraphs)
{
// Make sure that we have a property editor
Core::PropertyEditorWidget *propertyEditor = mPropertyEditors.value(pGraphPanel);
if (!propertyEditor)
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);
propertyEditor->removeProperty(property);
mGraphs.remove(property);
mGraphProperties.remove(graph);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::addGraph()
{
// Ask the graph panel associated with our current property editor to add an
// 'empty' graph
mGraphPanels.value(mPropertyEditor)->addGraph(new GraphPanelWidget::GraphPanelPlotGraph());
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::removeCurrentGraph()
{
// Ask the graph panel associated with our current property editor to remove
// the current graph
mGraphPanels.value(mPropertyEditor)->removeGraphs(GraphPanelWidget::GraphPanelPlotGraphs() << mGraphs.value(mPropertyEditor->currentProperty()));
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::removeAllGraphs()
{
// Ask the graph panel associated with our current property editor to remove
// all the graphs
mGraphPanels.value(mPropertyEditor)->removeGraphs(mGraphs.values());
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::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(mPropertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphChanged(Core::Property *)));
foreach (Core::Property *property, mGraphProperties)
property->setChecked(pSelect);
foreach (GraphPanelWidget::GraphPanelPlotGraph *graph, mGraphs)
graph->setSelected(pSelect);
if (mGraphs.count()) {
emit graphsUpdated(qobject_cast<GraphPanelWidget::GraphPanelPlotWidget *>(mGraphs.values().first()->plot()),
mGraphs.values());
}
connect(mPropertyEditor, SIGNAL(propertyChanged(Core::Property *)),
this, SLOT(graphChanged(Core::Property *)));
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::selectAllGraphs()
{
// Select all the graphs
selectAllGraphs(true);
}
//==============================================================================
bool SimulationExperimentViewInformationGraphsWidget::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 SimulationExperimentViewInformationGraphsWidget::unselectAllGraphs()
{
// Unselect all the graphs
selectAllGraphs(false);
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::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 SimulationExperimentViewInformationGraphsWidget::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 SimulationExperimentViewInformationGraphsWidget::finishEditing()
{
// Make sure that we have a property editor
if (!mPropertyEditor)
return;
// Ask our property editor to finish editing
mPropertyEditor->finishEditing();
}
//==============================================================================
static const auto PropertySeparator = QStringLiteral(" | ");
//==============================================================================
Core::Properties SimulationExperimentViewInformationGraphsWidget::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 *propertyEditor = mPropertyEditors.value(pGraphPanel);
if (propertyEditor) {
foreach (Core::Property *property, propertyEditor->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;
}
//==============================================================================
int SimulationExperimentViewInformationGraphsWidget::headerCount() const
{
// Return the number of headers in our property editors
return mPropertyEditor?mPropertyEditor->header()->count():0;
}
//==============================================================================
int SimulationExperimentViewInformationGraphsWidget::columnWidth(const int &pIndex) const
{
// Return the width of the given column
return mPropertyEditor?mPropertyEditor->columnWidth(pIndex):0;
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::setColumnWidth(const int &pIndex,
const int &pColumnWidth)
{
// Make sure that we have a property editor
if (!mPropertyEditor)
return;
// Return the width of the given column
mPropertyEditor->setColumnWidth(pIndex, pColumnWidth);
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::propertyEditorContextMenu(const QPoint &pPosition) const
{
Q_UNUSED(pPosition);
// Make sure that we have a property editor
if (!mPropertyEditor)
return;
// Retrieve our current property, if any
Core::Property *crtProperty = mPropertyEditor->currentProperty();
// Update the enabled state of some of our actions
mRemoveCurrentGraphAction->setEnabled(crtProperty);
mRemoveAllGraphsAction->setEnabled(!mPropertyEditor->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);
// 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 SimulationExperimentViewInformationGraphsWidget::propertyEditorHorizontalScrollBarValueChanged(const int &pValue)
{
// Keep track of the property editor's horizontal scroll bar value
mHorizontalScrollBarValue = pValue;
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::propertyEditorSectionResized(const int &pIndex,
const int &pOldSize,
const int &pNewSize)
{
Q_UNUSED(pOldSize);
// Let people know that a header section has been resized
emit headerSectionResized(pIndex, pOldSize, pNewSize);
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::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 SimulationExperimentViewInformationGraphsWidget::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 SimulationExperimentViewInformationGraphsWidget::modelListValue(const QString &pFileName) const
{
// Return the model list value for the given file name
return QFileInfo(pFileName).fileName()+PropertySeparator+pFileName;
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::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 graphChanged()), 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());
// Update the status (i.e. icon) of our (section) property
static const QIcon BlankIcon = QIcon(":/SimulationExperimentView/blank.png");
static const QIcon WarningIcon = QIcon(":/oxygen/status/task-attention.png");
pProperty->setIcon(graphOk?BlankIcon:WarningIcon);
// Update the file name with which the graph is associated
graph->setFileName(fileName);
// Update the graph itself
QPen oldGraphPen = graph->pen();
QPen graphPen = oldGraphPen;
int graphPenStyle = pProperty->properties()[3]->properties()[0]->listValues().indexOf(pProperty->properties()[3]->properties()[0]->listValue());
graphPen.setStyle((graphPenStyle == 5)?
Qt::NoPen:
Qt::PenStyle(Qt::SolidLine+graphPenStyle));
graphPen.setWidthF(pProperty->properties()[3]->properties()[2]->doubleValue());
graph->setPen(graphPen);
// Let people know if we consider that the graph has been updated
if ( (oldParameterX != graph->parameterX())
|| (oldParameterY != graph->parameterY())
|| (oldGraphPen != graphPen)) {
emit graphsUpdated(qobject_cast<GraphPanelWidget::GraphPanelPlotWidget *>(graph->plot()),
GraphPanelWidget::GraphPanelPlotGraphs() << graph);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::graphChanged(Core::Property *pProperty)
{
// Our graph has changed, which means that either it has been un/selected or
// that the value of one of its properties has changed
if (rootProperty(pProperty)) {
// The property associated with the graph is our root property, which
// means that the graph has been un/selected, so update its selected
// state and let people know that our graph has been updated
GraphPanelWidget::GraphPanelPlotGraph *graph = mGraphs.value(pProperty);
if (graph) {
graph->setSelected(pProperty->isChecked());
emit graphsUpdated(qobject_cast<GraphPanelWidget::GraphPanelPlotWidget *>(graph->plot()),
GraphPanelWidget::GraphPanelPlotGraphs() << graph);
}
} else {
// One of our graph properties has changed, so update its information
// Note: updateGraphInfo() will emit the graphsUpdated() signal, if
// needed...
Core::Property *graphProperty = pProperty->parentProperty();
while (graphProperty->parentProperty())
graphProperty = graphProperty->parentProperty();
updateGraphInfo(graphProperty);
}
}
//==============================================================================
void SimulationExperimentViewInformationGraphsWidget::updateGraphsInfo(Core::Property *pSectionProperty)
{
// Make sure that we have a property editor
if (!mPropertyEditor)
return;
// Make sure that no editing is in progress
finishEditing();
// Use the given section property or retrieve the ones for our current
// property editor
QList<Core::Property *> graphProperties = QList<Core::Property *>();
if (pSectionProperty) {
graphProperties << pSectionProperty;
} else {
foreach (Core::Property *property, mPropertyEditor->properties()) {
if (rootProperty(property))
graphProperties << property;
}
}
// Determine the model list values
QStringList modelListValues = QStringList();
foreach (const QString &fileName, mViewWidget->fileNames()) {
Core::File *file = Core::FileManager::instance()->file(fileName);
QString fileNameOrUrl = file->isLocal()?fileName:file->url();
modelListValues << modelListValue(fileNameOrUrl);
}
modelListValues.sort();
modelListValues.prepend(QString());
modelListValues.prepend(tr("Current"));
// Go through our graph properties and update (incl. retranslate) their
// information
foreach (Core::Property *graphProperty, graphProperties) {
// Set the label of our graph properties
graphProperty->properties()[0]->setName(tr("Model"));
graphProperty->properties()[1]->setName(tr("X"));
graphProperty->properties()[2]->setName(tr("Y"));
// Set the label of our graph line properties
graphProperty->properties()[3]->setName(tr("Line"));
graphProperty->properties()[3]->properties()[0]->setName(tr("Style"));
graphProperty->properties()[3]->properties()[0]->setListValues(QStringList() << tr("Solid")
<< tr("Dash")
<< tr("Dot")
<< tr("DashDot")
<< tr("DashDotDot")
<< tr("None"),
false);
graphProperty->properties()[3]->properties()[1]->setName(tr("Colour"));
graphProperty->properties()[3]->properties()[2]->setName(tr("Thickness"));
// Set the label of our graph symbol properties
graphProperty->properties()[4]->setName(tr("Symbol"));
graphProperty->properties()[4]->properties()[0]->setName(tr("Style"));
graphProperty->properties()[4]->properties()[0]->setListValues(QStringList() << tr("Square")
<< tr("Diamond")
<< tr("Triangle")
<< tr("Circle")
<< tr("Cross")
<< tr("Plus")
<< tr("Star")
<< tr("Inverted Triangle")
<< tr("Vertical Dash")
<< tr("None"),
false);
graphProperty->properties()[4]->properties()[1]->setName(tr("Filled"));
graphProperty->properties()[4]->properties()[2]->setName(tr("Colour"));
graphProperty->properties()[4]->properties()[3]->setName(tr("Fill colour"));
// Keep track of the current model value, so that we can safely update
// its list values and then select the correct model value back
QString oldModelValue = graphProperty->properties()[0]->value();
QString newModelValue = oldModelValue;
graphProperty->properties()[0]->setListValues(modelListValues, false);
// Note: we don't want setListValues() to emit a signal since one will