-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathqwt_plot_layout.cpp
More file actions
817 lines (684 loc) · 23.7 KB
/
qwt_plot_layout.cpp
File metadata and controls
817 lines (684 loc) · 23.7 KB
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
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
* Qwt Widget Library
* Copyright (C) 1997 Josef Wilgen
* Copyright (C) 2002 Uwe Rathmann
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Qwt License, Version 1.0
*****************************************************************************/
#include "qwt_plot_layout.h"
#include "qwt_text.h"
#include "qwt_text_label.h"
#include "qwt_plot_canvas.h"
#include "qwt_scale_widget.h"
#include "qwt_legend.h"
#include <qscrollbar.h>
#include <qmath.h>
class QwtPlotLayout::LayoutData
{
public:
void init( const QwtPlot *, const QRectF &rect );
struct t_legendData
{
int vScrollBarWidth;
int hScrollBarHeight;
QSize hint;
} legend;
struct t_titleData
{
QwtText text;
int frameWidth;
} title;
struct t_scaleData
{
const QwtScaleWidget *scaleWidget;
QFont scaleFont;
int baseLineOffset;
int tickOffset;
int dimWithoutTitle;
bool isEnabled;
} scale[QwtPlot::axisCnt];
struct t_canvasData
{
int frameWidth;
} canvas;
};
/*
Extract all layout relevant data from the plot components
*/
void QwtPlotLayout::LayoutData::init( const QwtPlot *plot, const QRectF &rect )
{
// legend
if ( plot->plotLayout()->legendPosition() != QwtPlot::ExternalLegend
&& plot->legend() )
{
legend.vScrollBarWidth =
plot->legend()->verticalScrollBar()->sizeHint().width();
legend.hScrollBarHeight =
plot->legend()->horizontalScrollBar()->sizeHint().height();
const QSize hint = plot->legend()->sizeHint();
int w = qMin( hint.width(), ( int )rect.width() );
int h = plot->legend()->heightForWidth( w );
if ( h == 0 )
h = hint.height();
if ( h > rect.height() )
w += legend.vScrollBarWidth;
legend.hint = QSize( w, h );
}
// title
title.frameWidth = 0;
title.text = QwtText();
if ( plot->titleLabel() )
{
const QwtTextLabel *label = plot->titleLabel();
title.text = label->text();
if ( !( title.text.testPaintAttribute( QwtText::PaintUsingTextFont ) ) )
title.text.setFont( label->font() );
title.frameWidth = plot->titleLabel()->frameWidth();
}
// scales
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
if ( plot->axisEnabled( axis ) )
{
const QwtScaleWidget *scaleWidget = plot->axisWidget( axis );
scale[axis].isEnabled = true;
scale[axis].scaleWidget = scaleWidget;
scale[axis].scaleFont = scaleWidget->font();
scale[axis].baseLineOffset = scaleWidget->margin();
scale[axis].tickOffset = scaleWidget->margin();
scale[axis].tickOffset +=
( int )scaleWidget->scaleDraw()->maxTickLength();
scale[axis].dimWithoutTitle = scaleWidget->dimForLength(
QWIDGETSIZE_MAX, scale[axis].scaleFont );
if ( !scaleWidget->title().isEmpty() )
{
scale[axis].dimWithoutTitle -=
scaleWidget->titleHeightForWidth( QWIDGETSIZE_MAX );
}
}
else
{
scale[axis].isEnabled = false;
scale[axis].baseLineOffset = 0;
scale[axis].tickOffset = 0;
scale[axis].dimWithoutTitle = 0;
}
}
// canvas
canvas.frameWidth = plot->canvas()->frameWidth();
}
class QwtPlotLayout::PrivateData
{
public:
PrivateData():
spacing( 5 )
{
}
QRectF titleRect;
QRectF legendRect;
QRectF scaleRect[QwtPlot::axisCnt];
QRectF canvasRect;
QwtPlotLayout::LayoutData layoutData;
QwtPlot::LegendPosition legendPos;
double legendRatio;
unsigned int spacing;
};
/*!
\brief Constructor
*/
QwtPlotLayout::QwtPlotLayout()
{
d_data = new PrivateData;
setLegendPosition( QwtPlot::BottomLegend );
invalidate();
}
//! Destructor
QwtPlotLayout::~QwtPlotLayout()
{
delete d_data;
}
/*!
Change the spacing of the plot. The spacing is the distance
between the plot components.
\param spacing new spacing
\sa setMargin(), spacing()
*/
void QwtPlotLayout::setSpacing( int spacing )
{
d_data->spacing = qMax( 0, spacing );
}
/*!
\return spacing
\sa margin(), setSpacing()
*/
int QwtPlotLayout::spacing() const
{
return d_data->spacing;
}
/*!
\brief Specify the position of the legend
\param pos The legend's position.
\param ratio Ratio between legend and the bounding rect
of title, canvas and axes. The legend will be shrinked
if it would need more space than the given ratio.
The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
it will be reset to the default ratio.
The default vertical/horizontal ratio is 0.33/0.5.
\sa QwtPlot::setLegendPosition()
*/
void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos, double ratio )
{
if ( ratio > 1.0 )
ratio = 1.0;
switch ( pos )
{
case QwtPlot::TopLegend:
case QwtPlot::BottomLegend:
if ( ratio <= 0.0 )
ratio = 0.33;
d_data->legendRatio = ratio;
d_data->legendPos = pos;
break;
case QwtPlot::LeftLegend:
case QwtPlot::RightLegend:
if ( ratio <= 0.0 )
ratio = 0.5;
d_data->legendRatio = ratio;
d_data->legendPos = pos;
break;
case QwtPlot::ExternalLegend:
d_data->legendRatio = ratio; // meaningless
d_data->legendPos = pos;
default:
break;
}
}
/*!
\brief Specify the position of the legend
\param pos The legend's position. Valid values are
\c QwtPlot::LeftLegend, \c QwtPlot::RightLegend,
\c QwtPlot::TopLegend, \c QwtPlot::BottomLegend.
\sa QwtPlot::setLegendPosition()
*/
void QwtPlotLayout::setLegendPosition( QwtPlot::LegendPosition pos )
{
setLegendPosition( pos, 0.0 );
}
/*!
\return Position of the legend
\sa setLegendPosition(), QwtPlot::setLegendPosition(),
QwtPlot::legendPosition()
*/
QwtPlot::LegendPosition QwtPlotLayout::legendPosition() const
{
return d_data->legendPos;
}
/*!
Specify the relative size of the legend in the plot
\param ratio Ratio between legend and the bounding rect
of title, canvas and axes. The legend will be shrinked
if it would need more space than the given ratio.
The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0
it will be reset to the default ratio.
The default vertical/horizontal ratio is 0.33/0.5.
*/
void QwtPlotLayout::setLegendRatio( double ratio )
{
setLegendPosition( legendPosition(), ratio );
}
/*!
\return The relative size of the legend in the plot.
\sa setLegendPosition()
*/
double QwtPlotLayout::legendRatio() const
{
return d_data->legendRatio;
}
/*!
\return Geometry for the title
\sa activate(), invalidate()
*/
const QRectF &QwtPlotLayout::titleRect() const
{
return d_data->titleRect;
}
/*!
\return Geometry for the legend
\sa activate(), invalidate()
*/
const QRectF &QwtPlotLayout::legendRect() const
{
return d_data->legendRect;
}
/*!
\param axis Axis index
\return Geometry for the scale
\sa activate(), invalidate()
*/
const QRectF &QwtPlotLayout::scaleRect( int axis ) const
{
if ( axis < 0 || axis >= QwtPlot::axisCnt )
{
static QRectF dummyRect;
return dummyRect;
}
return d_data->scaleRect[axis];
}
/*!
\return Geometry for the canvas
\sa activate(), invalidate()
*/
const QRectF &QwtPlotLayout::canvasRect() const
{
return d_data->canvasRect;
}
/*!
Invalidate the geometry of all components.
\sa activate()
*/
void QwtPlotLayout::invalidate()
{
d_data->titleRect = d_data->legendRect = d_data->canvasRect = QRect();
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
d_data->scaleRect[axis] = QRect();
}
/*!
\brief Return a minimum size hint
\sa QwtPlot::minimumSizeHint()
*/
QSize QwtPlotLayout::minimumSizeHint( const QwtPlot *plot ) const
{
class ScaleData
{
public:
ScaleData()
{
w = h = tickOffset = 0;
}
int w;
int h;
int tickOffset;
} scaleData[QwtPlot::axisCnt];
int axis;
for ( axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
if ( plot->axisEnabled( axis ) )
{
const QwtScaleWidget *scl = plot->axisWidget( axis );
ScaleData &sd = scaleData[axis];
const QSize hint = scl->minimumSizeHint();
sd.w = hint.width();
sd.h = hint.height();
sd.tickOffset = scl->margin();
sd.tickOffset += scl->scaleDraw()->maxTickLength();
}
}
const QwtPlotCanvas *canvas = plot->canvas();
const QSize minCanvasSize = canvas->minimumSize();
int w = scaleData[QwtPlot::yLeft].w + scaleData[QwtPlot::yRight].w;
int cw = qMax( scaleData[QwtPlot::xBottom].w, scaleData[QwtPlot::xTop].w )
+ 2 * ( canvas->frameWidth() + 1 );
w += qMax( cw, minCanvasSize.width() );
int h = scaleData[QwtPlot::xBottom].h + scaleData[QwtPlot::xTop].h;
int ch = qMax( scaleData[QwtPlot::yLeft].h, scaleData[QwtPlot::yRight].h )
+ 2 * ( canvas->frameWidth() + 1 );
h += qMax( ch, minCanvasSize.height() );
const QwtTextLabel *title = plot->titleLabel();
if ( title && !title->text().isEmpty() )
{
// If only QwtPlot::yLeft or QwtPlot::yRight is showing,
// we center on the plot canvas.
const bool centerOnCanvas = !( plot->axisEnabled( QwtPlot::yLeft )
&& plot->axisEnabled( QwtPlot::yRight ) );
int titleW = w;
if ( centerOnCanvas )
{
titleW -= scaleData[QwtPlot::yLeft].w
+ scaleData[QwtPlot::yRight].w;
}
int titleH = title->heightForWidth( titleW );
if ( titleH > titleW ) // Compensate for a long title
{
w = titleW = titleH;
if ( centerOnCanvas )
{
w += scaleData[QwtPlot::yLeft].w
+ scaleData[QwtPlot::yRight].w;
}
titleH = title->heightForWidth( titleW );
}
h += titleH + d_data->spacing;
}
// Compute the legend contribution
const QwtLegend *legend = plot->legend();
if ( d_data->legendPos != QwtPlot::ExternalLegend
&& legend && !legend->isEmpty() )
{
if ( d_data->legendPos == QwtPlot::LeftLegend
|| d_data->legendPos == QwtPlot::RightLegend )
{
int legendW = legend->sizeHint().width();
int legendH = legend->heightForWidth( legendW );
if ( legend->frameWidth() > 0 )
w += d_data->spacing;
if ( legendH > h )
legendW += legend->verticalScrollBar()->sizeHint().height();
if ( d_data->legendRatio < 1.0 )
legendW = qMin( legendW, int( w / ( 1.0 - d_data->legendRatio ) ) );
w += legendW + d_data->spacing;
}
else // QwtPlot::Top, QwtPlot::Bottom
{
int legendW = qMin( legend->sizeHint().width(), w );
int legendH = legend->heightForWidth( legendW );
if ( legend->frameWidth() > 0 )
h += d_data->spacing;
if ( d_data->legendRatio < 1.0 )
legendH = qMin( legendH, int( h / ( 1.0 - d_data->legendRatio ) ) );
h += legendH + d_data->spacing;
}
}
return QSize( w, h );
}
/*!
Find the geometry for the legend
\param rect Rectangle where to place the legend
\return Geometry for the legend
*/
QRectF QwtPlotLayout::layoutLegend( const QRectF &rect ) const
{
const QSize hint( d_data->layoutData.legend.hint );
int dim;
if ( d_data->legendPos == QwtPlot::LeftLegend
|| d_data->legendPos == QwtPlot::RightLegend )
{
// We don't allow vertical legends to take more than
// half of the available space.
dim = qMin( hint.width(), int( rect.width() * d_data->legendRatio ) );
if ( hint.height() > rect.height() )
{
// The legend will need additional
// space for the vertical scrollbar.
dim += d_data->layoutData.legend.vScrollBarWidth;
}
}
else
{
dim = qMin( hint.height(), int( rect.height() * d_data->legendRatio ) );
dim = qMax( dim, d_data->layoutData.legend.hScrollBarHeight );
}
QRectF legendRect = rect;
switch ( d_data->legendPos )
{
case QwtPlot::LeftLegend:
legendRect.setWidth( dim );
break;
case QwtPlot::RightLegend:
legendRect.setX( rect.right() - dim );
legendRect.setWidth( dim );
break;
case QwtPlot::TopLegend:
legendRect.setHeight( dim );
break;
case QwtPlot::BottomLegend:
legendRect.setY( rect.bottom() - dim );
legendRect.setHeight( dim );
break;
case QwtPlot::ExternalLegend:
break;
}
return legendRect;
}
/*!
Align the legend to the canvas
\param canvasRect Geometry of the canvas
\param legendRect Maximum geometry for the legend
\return Geometry for the aligned legend
*/
QRectF QwtPlotLayout::alignLegend( const QRectF &canvasRect,
const QRectF &legendRect ) const
{
QRectF alignedRect = legendRect;
if ( d_data->legendPos == QwtPlot::BottomLegend
|| d_data->legendPos == QwtPlot::TopLegend )
{
if ( d_data->layoutData.legend.hint.width() < canvasRect.width() )
{
alignedRect.setX( canvasRect.x() );
alignedRect.setWidth( canvasRect.width() );
}
}
else
{
if ( d_data->layoutData.legend.hint.height() < canvasRect.height() )
{
alignedRect.setY( canvasRect.y() );
alignedRect.setHeight( canvasRect.height() );
}
}
return alignedRect;
}
/*!
Expand all line breaks in text labels, and calculate the height
of their widgets in orientation of the text.
\param rect Bounding rect for title, axes and canvas.
\param dimTitle Expanded height of the title widget
\param dimAxis Expanded heights of the axis in axis orientation.
*/
void QwtPlotLayout::expandLineBreaks( const QRectF &rect,
int &dimTitle, int dimAxis[QwtPlot::axisCnt] ) const
{
dimTitle = 0;
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
dimAxis[axis] = 0;
int backboneOffset = d_data->layoutData.canvas.frameWidth;
bool done = false;
while ( !done )
{
done = true;
// the size for the 4 axis depend on each other. Expanding
// the height of a horizontal axis will shrink the height
// for the vertical axis, shrinking the height of a vertical
// axis will result in a line break what will expand the
// width and results in shrinking the width of a horizontal
// axis what might result in a line break of a horizontal
// axis ... . So we loop as long until no size changes.
if ( !d_data->layoutData.title.text.isEmpty() )
{
int w = rect.width();
if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled
!= d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
{
// center to the canvas
w -= dimAxis[QwtPlot::yLeft] + dimAxis[QwtPlot::yRight];
}
int d = qCeil( d_data->layoutData.title.text.heightForWidth( w ) );
d += 2 * d_data->layoutData.title.frameWidth;
if ( d > dimTitle )
{
dimTitle = d;
done = false;
}
}
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
const struct LayoutData::t_scaleData &scaleData =
d_data->layoutData.scale[axis];
if ( scaleData.isEnabled )
{
int length;
if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
{
length = rect.width() - dimAxis[QwtPlot::yLeft]
- dimAxis[QwtPlot::yRight];
if ( dimAxis[QwtPlot::yRight] > 0 )
length -= 1;
length += qMin( dimAxis[QwtPlot::yLeft], -backboneOffset );
length += qMin( dimAxis[QwtPlot::yRight], -backboneOffset );
}
else // QwtPlot::yLeft, QwtPlot::yRight
{
length = rect.height() - dimAxis[QwtPlot::xTop]
- dimAxis[QwtPlot::xBottom];
length -= 1;
if ( dimAxis[QwtPlot::xBottom] <= 0 )
length -= 1;
if ( dimAxis[QwtPlot::xTop] <= 0 )
length -= 1;
if ( dimAxis[QwtPlot::xBottom] > 0 )
{
length += qMin(
d_data->layoutData.scale[QwtPlot::xBottom].tickOffset, -backboneOffset );
}
if ( dimAxis[QwtPlot::xTop] > 0 )
{
length += qMin(
d_data->layoutData.scale[QwtPlot::xTop].tickOffset, -backboneOffset );
}
if ( dimTitle > 0 )
length -= dimTitle + d_data->spacing;
}
int d = scaleData.dimWithoutTitle;
if ( !scaleData.scaleWidget->title().isEmpty() )
{
d += scaleData.scaleWidget->titleHeightForWidth( length );
}
if ( d > dimAxis[axis] )
{
dimAxis[axis] = d;
done = false;
}
}
}
}
}
/*!
\brief Recalculate the geometry of all components.
\param plot Plot to be layout
\param plotRect Rect where to place the components
\sa invalidate(), titleRect(),
legendRect(), scaleRect(), canvasRect()
*/
void QwtPlotLayout::activate( const QwtPlot *plot,
const QRectF &plotRect )
{
invalidate();
QRectF rect( plotRect ); // undistributed rest of the plot rect
// We extract all layout relevant data from the widgets,
// filter them through pfilter and save them to d_data->layoutData.
d_data->layoutData.init( plot, rect );
if ( d_data->legendPos != QwtPlot::ExternalLegend
&& plot->legend() && !plot->legend()->isEmpty() )
{
d_data->legendRect = layoutLegend( rect );
// subtract d_data->legendRect from rect
const QRegion region( rect.toRect() );
rect = region.subtract( d_data->legendRect.toRect() ).boundingRect();
switch ( d_data->legendPos )
{
case QwtPlot::LeftLegend:
rect.setLeft( rect.left() + d_data->spacing );
break;
case QwtPlot::RightLegend:
rect.setRight( rect.right() - d_data->spacing );
break;
case QwtPlot::TopLegend:
rect.setTop( rect.top() + d_data->spacing );
break;
case QwtPlot::BottomLegend:
rect.setBottom( rect.bottom() - d_data->spacing );
break;
case QwtPlot::ExternalLegend:
break; // suppress compiler warning
}
}
/*
+---+-----------+---+
| Title |
+---+-----------+---+
| | Axis | |
+---+-----------+---+
| A | | A |
| x | Canvas | x |
| i | | i |
| s | | s |
+---+-----------+---+
| | Axis | |
+---+-----------+---+
*/
// axes and title include text labels. The height of each
// label depends on its line breaks, that depend on the width
// for the label. A line break in a horizontal text will reduce
// the available width for vertical texts and vice versa.
// expandLineBreaks finds the height/width for title and axes
// including all line breaks.
int dimTitle, dimAxes[QwtPlot::axisCnt];
expandLineBreaks( rect, dimTitle, dimAxes );
if ( dimTitle > 0 )
{
d_data->titleRect = QRect( rect.x(), rect.y(),
rect.width(), dimTitle );
if ( d_data->layoutData.scale[QwtPlot::yLeft].isEnabled !=
d_data->layoutData.scale[QwtPlot::yRight].isEnabled )
{
// if only one of the y axes is missing we align
// the title centered to the canvas
d_data->titleRect.setX( rect.x() + dimAxes[QwtPlot::yLeft] );
d_data->titleRect.setWidth( rect.width()
- dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] );
}
// subtract title
rect.setTop( rect.top() + dimTitle + d_data->spacing );
}
d_data->canvasRect.setRect(
rect.x() + dimAxes[QwtPlot::yLeft],
rect.y() + dimAxes[QwtPlot::xTop],
rect.width() - dimAxes[QwtPlot::yRight] - dimAxes[QwtPlot::yLeft],
rect.height() - dimAxes[QwtPlot::xBottom] - dimAxes[QwtPlot::xTop] );
int fw = d_data->layoutData.canvas.frameWidth;
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
// set the rects for the axes
if ( dimAxes[axis] )
{
int dim = dimAxes[axis];
QRectF &scaleRect = d_data->scaleRect[axis];
switch ( axis )
{
case QwtPlot::yLeft:
scaleRect.setX( d_data->canvasRect.left() - dim );
scaleRect.setWidth( dim );
break;
case QwtPlot::yRight:
scaleRect.setX( d_data->canvasRect.right() );
scaleRect.setWidth( dim );
break;
case QwtPlot::xBottom:
scaleRect.setY( d_data->canvasRect.bottom() );
scaleRect.setHeight( dim );
break;
case QwtPlot::xTop:
scaleRect.setY( d_data->canvasRect.top() - dim );
scaleRect.setHeight( dim );
break;
}
if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
{
scaleRect.setLeft( d_data->canvasRect.left() + fw );
scaleRect.setRight( d_data->canvasRect.right() - fw - 1 );
}
else // QwtPlot::yLeft, QwtPlot::yRight
{
scaleRect.setTop( d_data->canvasRect.top() + fw );
scaleRect.setBottom( d_data->canvasRect.bottom() - fw - 1 );
}
}
}
if ( !d_data->legendRect.isEmpty() )
{
// We prefer to align the legend to the canvas - not to
// the complete plot - if possible.
d_data->legendRect = alignLegend( d_data->canvasRect, d_data->legendRect );
}
}