/
graphpanelswidget.cpp
357 lines (245 loc) · 12 KB
/
graphpanelswidget.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
/*******************************************************************************
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/>.
*******************************************************************************/
//==============================================================================
// Graph panels widget
//==============================================================================
#include "corecliutils.h"
#include "coreguiutils.h"
#include "graphpanelswidget.h"
#include "i18ninterface.h"
//==============================================================================
#include <QAction>
#include <QSettings>
//==============================================================================
#include "sedmlapibegin.h"
#include "sedml/SedDocument.h"
#include "sedmlapiend.h"
//==============================================================================
namespace OpenCOR {
namespace GraphPanelWidget {
//==============================================================================
GraphPanelsWidget::GraphPanelsWidget(QWidget *pParent) :
Core::SplitterWidget(pParent),
mGraphPanels(GraphPanelWidgets()),
mActiveGraphPanel(0)
{
// Set our orientation
setOrientation(Qt::Vertical);
// Create our actions
mSynchronizeXAxisAction = Core::newAction(true, this);
mSynchronizeYAxisAction = Core::newAction(true, this);
connect(mSynchronizeXAxisAction, SIGNAL(triggered(bool)),
this, SLOT(synchronizeXAxis()));
connect(mSynchronizeYAxisAction, SIGNAL(triggered(bool)),
this, SLOT(synchronizeYAxis()));
}
//==============================================================================
void GraphPanelsWidget::retranslateUi()
{
// Retranslate our actions
I18nInterface::retranslateAction(mSynchronizeXAxisAction, tr("Synchonise X Axis"),
tr("Synchronise the X axis of all graph panels"));
I18nInterface::retranslateAction(mSynchronizeYAxisAction, tr("Synchonise Y Axis"),
tr("Synchronise the Y axis of all graph panels"));
// Retranslate all our graph panels
foreach (GraphPanelWidget *graphPanel, mGraphPanels)
graphPanel->retranslateUi();
}
//==============================================================================
void GraphPanelsWidget::initialize()
{
// Create a default graph panel, if none exists
if (mGraphPanels.isEmpty())
addGraphPanel();
}
//==============================================================================
GraphPanelWidgets GraphPanelsWidget::graphPanels() const
{
// Return our graph panels
return mGraphPanels;
}
//==============================================================================
GraphPanelWidget * GraphPanelsWidget::activeGraphPanel() const
{
// Return our active graph panel
return mActiveGraphPanel;
}
//==============================================================================
GraphPanelWidget * GraphPanelsWidget::addGraphPanel(const bool &pActive)
{
// Keep track of the graph panels' original size
QIntList origSizes = sizes();
// Retrieve the active graph panel's plot, if any, which will be used to
// synchronise axes, if needed
GraphPanelPlotWidget *activeGraphPanelPlot = mActiveGraphPanel?mActiveGraphPanel->plot():0;
// Create a new graph panel, add it to ourselves and keep track of it
GraphPanelWidget *res = new GraphPanelWidget(mGraphPanels,
mSynchronizeXAxisAction,
mSynchronizeYAxisAction,
this);
mGraphPanels << res;
// Resize the graph panels, thus making sure that their size is what it
// should be
double scalingFactor = double(mGraphPanels.count()-1)/mGraphPanels.count();
for (int i = 0, iMax = origSizes.count(); i < iMax; ++i)
origSizes[i] *= scalingFactor;
setSizes(origSizes << height()/mGraphPanels.count());
// Keep track of whenever a graph panel gets activated
connect(res, SIGNAL(activated(OpenCOR::GraphPanelWidget::GraphPanelWidget *)),
this, SIGNAL(graphPanelActivated(OpenCOR::GraphPanelWidget::GraphPanelWidget *)));
connect(res, SIGNAL(activated(OpenCOR::GraphPanelWidget::GraphPanelWidget *)),
this, SLOT(updateGraphPanels(OpenCOR::GraphPanelWidget::GraphPanelWidget *)));
// Keep track of the addition and removal of a graph
connect(res, SIGNAL(graphAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphProperties &)),
this, SIGNAL(graphAdded(OpenCOR::GraphPanelWidget::GraphPanelWidget *, OpenCOR::GraphPanelWidget::GraphPanelPlotGraph *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphProperties &)));
connect(res, SIGNAL(graphsRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)),
this, SIGNAL(graphsRemoved(OpenCOR::GraphPanelWidget::GraphPanelWidget *, const OpenCOR::GraphPanelWidget::GraphPanelPlotGraphs &)));
// In/activate the graph panel
res->setActive(pActive);
// Let people know that we have added a graph panel
emit graphPanelAdded(res, pActive);
// Let people know whether graph panels can be removed
emit removeGraphPanelsEnabled(mGraphPanels.count() > 1);
// Synchronise the axes of our graph panels, if needed, and ensure that they
// are all aligned with one another by forcing the setting of the axes of
// our active graph panel
// Note: at startup, activeGraphPanelPlot is (obviously) null, hence we use
// our newly created graph panel's plot instead...
if (!activeGraphPanelPlot)
activeGraphPanelPlot = mActiveGraphPanel->plot();
activeGraphPanelPlot->setAxes(activeGraphPanelPlot->minX(),
activeGraphPanelPlot->maxX(),
activeGraphPanelPlot->minY(),
activeGraphPanelPlot->maxY(),
true, true, true, true, true);
// Return our newly created graph panel
return res;
}
//==============================================================================
bool GraphPanelsWidget::removeGraphPanel(GraphPanelWidget *pGraphPanel)
{
if (!pGraphPanel)
return false;
// Retrieve the index of the given graph panel
int index = mGraphPanels.indexOf(pGraphPanel);
// Let people know that we have removed it (or, rather, about to remove it)
// Note: we let people know before we actually delete the graph panel,
// because some people interested in that signal might have used the
// pointer to keep track of some information, as is done in
// SimulationExperimentViewInformationGraphsWidget for example...
emit graphPanelRemoved(pGraphPanel);
// Remove all tracks
// Note: mActiveGraphPanel will automatically get updated when another graph
// panel gets selected...
mGraphPanels.removeOne(pGraphPanel);
// Now, we can delete our graph panel
delete pGraphPanel;
// Let people know whether graph panels can be removed
emit removeGraphPanelsEnabled(mGraphPanels.count() > 1);
// Activate the next graph panel or the last one available, if any
if (index < mGraphPanels.count()) {
// There is a next graph panel, so activate it
mGraphPanels[index]->setActive(true);
} else {
// We were dealing with the last graph panel, so just activate the new
// last graph panel
mGraphPanels[mGraphPanels.count()-1]->setActive(true);
}
// Ask our first graph panel's plot, if any, to align itself against its
// neighbours
if (!mGraphPanels.isEmpty()) {
mActiveGraphPanel->plot()->forceAlignWithNeighbors();
return true;
} else {
return false;
}
}
//==============================================================================
bool GraphPanelsWidget::removeCurrentGraphPanel()
{
// Make sure that we don't have only one graph panel left
if (mGraphPanels.count() == 1)
return false;
// Remove the current graph panel
return removeGraphPanel(mActiveGraphPanel);
}
//==============================================================================
void GraphPanelsWidget::removeAllGraphPanels()
{
// Make sure that we don't have only one graph panel left
if (mGraphPanels.count() == 1)
return;
// Remove all the graph panels but one
// Note: the one we keep is the very first one since it may be the user's
// most important graph panel...
while (mGraphPanels.count() > 1)
removeGraphPanel(mGraphPanels.last());
}
//==============================================================================
void GraphPanelsWidget::setActiveGraphPanel(GraphPanelWidget *pGraphPanel)
{
// Make sure that we own the given graph panel
if (!mGraphPanels.contains(pGraphPanel))
return;
// Make the given graph panel the active one
pGraphPanel->setActive(true, true);
}
//==============================================================================
void GraphPanelsWidget::updateGraphPanels(OpenCOR::GraphPanelWidget::GraphPanelWidget *pGraphPanel)
{
// Keep track of the newly activated graph panel
mActiveGraphPanel = pGraphPanel;
// Inactivate all the other graph panels
foreach (GraphPanelWidget *graphPanel, mGraphPanels) {
if (graphPanel != pGraphPanel) {
// We are not dealing with the graph panel that just got activated,
// so inactivate it
graphPanel->setActive(false);
}
}
}
//==============================================================================
void GraphPanelsWidget::synchronizeXAxis()
{
// Synchronise the X axis of our graph panels, if needed, by forcing the
// setting of the axes of our active graph panel
if (mSynchronizeXAxisAction->isChecked()) {
GraphPanelPlotWidget *activeGraphPanelPlot = mActiveGraphPanel->plot();
activeGraphPanelPlot->setAxes(activeGraphPanelPlot->minX(),
activeGraphPanelPlot->maxX(),
activeGraphPanelPlot->minY(),
activeGraphPanelPlot->maxY(),
true, true, true, true, false);
}
}
//==============================================================================
void GraphPanelsWidget::synchronizeYAxis()
{
// Synchronise the Y axis of our graph panels, if needed, by forcing the
// setting of the axes of our active graph panel
if (mSynchronizeYAxisAction->isChecked()) {
GraphPanelPlotWidget *activeGraphPanelPlot = mActiveGraphPanel->plot();
activeGraphPanelPlot->setAxes(activeGraphPanelPlot->minX(),
activeGraphPanelPlot->maxX(),
activeGraphPanelPlot->minY(),
activeGraphPanelPlot->maxY(),
true, true, true, false, true);
}
}
//==============================================================================
} // namespace GraphPanelWidget
} // namespace OpenCOR
//==============================================================================
// End of file
//==============================================================================