Newer
Older
\param options Layout options
\param canvasRect Geometry of the canvas ( IN/OUT )
\param scaleRect Geometries of the scales ( IN/OUT )
\sa Options
void QwtPlotLayout::alignScales( Options options,
QRectF &canvasRect, QRectF scaleRect[QwtPlot::axisCnt] ) const
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
}
if ( !( options & IgnoreFrames ) )
{
backboneOffset[axis] +=
d_data->layoutData.canvas.contentsMargins[axis];
}
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
if ( !scaleRect[axis].isValid() )
continue;
const int startDist = d_data->layoutData.scale[axis].start;
const int endDist = d_data->layoutData.scale[axis].end;
if ( axis == QwtPlot::xTop || axis == QwtPlot::xBottom )
{
const QRectF &leftScaleRect = scaleRect[QwtPlot::yLeft];
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
if ( leftScaleRect.isValid() )
{
const double dx = leftOffset + leftScaleRect.width();
if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && dx < 0.0 )
{
/*
The axis needs more space than the width
of the left scale.
*/
const double cLeft = canvasRect.left(); // qreal -> double
canvasRect.setLeft( qMax( cLeft, axisRect.left() - dx ) );
}
else
{
const double minLeft = leftScaleRect.left();
const double left = axisRect.left() + leftOffset;
axisRect.setLeft( qMax( left, minLeft ) );
}
}
else
{
if ( d_data->alignCanvasToScales[QwtPlot::yLeft] && leftOffset < 0 )
{
canvasRect.setLeft( qMax( canvasRect.left(),
axisRect.left() - leftOffset ) );
}
else
{
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
if ( rightScaleRect.isValid() )
{
const double dx = rightOffset + rightScaleRect.width();
if ( d_data->alignCanvasToScales[QwtPlot::yRight] && dx < 0 )
{
/*
The axis needs more space than the width
of the right scale.
*/
const double cRight = canvasRect.right(); // qreal -> double
canvasRect.setRight( qMin( cRight, axisRect.right() + dx ) );
}
const double maxRight = rightScaleRect.right();
const double right = axisRect.right() - rightOffset;
axisRect.setRight( qMin( right, maxRight ) );
}
else
{
if ( d_data->alignCanvasToScales[QwtPlot::yRight] && rightOffset < 0 )
{
canvasRect.setRight( qMin( canvasRect.right(),
axisRect.right() + rightOffset ) );
}
else
{
}
else // QwtPlot::yLeft, QwtPlot::yRight
{
const QRectF &bottomScaleRect = scaleRect[QwtPlot::xBottom];
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
if ( bottomScaleRect.isValid() )
{
const double dy = bottomOffset + bottomScaleRect.height();
if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && dy < 0 )
{
/*
The axis needs more space than the height
of the bottom scale.
*/
const double cBottom = canvasRect.bottom(); // qreal -> double
canvasRect.setBottom( qMin( cBottom, axisRect.bottom() + dy ) );
}
else
{
const double maxBottom = bottomScaleRect.top() +
d_data->layoutData.scale[QwtPlot::xBottom].tickOffset;
const double bottom = axisRect.bottom() - bottomOffset;
axisRect.setBottom( qMin( bottom, maxBottom ) );
}
}
else
{
if ( d_data->alignCanvasToScales[QwtPlot::xBottom] && bottomOffset < 0 )
{
canvasRect.setBottom( qMin( canvasRect.bottom(),
axisRect.bottom() + bottomOffset ) );
}
else
{
const int topOffset = backboneOffset[QwtPlot::xTop] - startDist;
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
if ( topScaleRect.isValid() )
{
const double dy = topOffset + topScaleRect.height();
if ( d_data->alignCanvasToScales[QwtPlot::xTop] && dy < 0 )
{
/*
The axis needs more space than the height
of the top scale.
*/
const double cTop = canvasRect.top(); // qreal -> double
canvasRect.setTop( qMax( cTop, axisRect.top() - dy ) );
}
else
{
const double minTop = topScaleRect.bottom() -
d_data->layoutData.scale[QwtPlot::xTop].tickOffset;
const double top = axisRect.top() + topOffset;
axisRect.setTop( qMax( top, minTop ) );
}
}
else
{
if ( d_data->alignCanvasToScales[QwtPlot::xTop] && topOffset < 0 )
{
canvasRect.setTop( qMax( canvasRect.top(),
axisRect.top() - topOffset ) );
}
else
{
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
/*
The canvas has been aligned to the scale with largest
border distances. Now we have to realign the other scale.
*/
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
QRectF &sRect = scaleRect[axis];
if ( !sRect.isValid() )
continue;
if ( axis == QwtPlot::xBottom || axis == QwtPlot::xTop )
{
if ( d_data->alignCanvasToScales[QwtPlot::yLeft] )
{
double y = canvasRect.left() - d_data->layoutData.scale[axis].start;
if ( !( options & IgnoreFrames ) )
y += d_data->layoutData.canvas.contentsMargins[ QwtPlot::yLeft ];
sRect.setLeft( y );
}
if ( d_data->alignCanvasToScales[QwtPlot::yRight] )
{
double y = canvasRect.right() - 1 + d_data->layoutData.scale[axis].end;
if ( !( options & IgnoreFrames ) )
y -= d_data->layoutData.canvas.contentsMargins[ QwtPlot::yRight ];
sRect.setRight( y );
}
if ( d_data->alignCanvasToScales[ axis ] )
{
if ( axis == QwtPlot::xTop )
sRect.setBottom( canvasRect.top() );
else
sRect.setTop( canvasRect.bottom() );
else
{
if ( d_data->alignCanvasToScales[QwtPlot::xTop] )
{
double x = canvasRect.top() - d_data->layoutData.scale[axis].start;
if ( !( options & IgnoreFrames ) )
x += d_data->layoutData.canvas.contentsMargins[ QwtPlot::xTop ];
sRect.setTop( x );
}
if ( d_data->alignCanvasToScales[QwtPlot::xBottom] )
{
double x = canvasRect.bottom() - 1 + d_data->layoutData.scale[axis].end;
if ( !( options & IgnoreFrames ) )
x -= d_data->layoutData.canvas.contentsMargins[ QwtPlot::xBottom ];
sRect.setBottom( x );
}
if ( d_data->alignCanvasToScales[ axis ] )
{
if ( axis == QwtPlot::yLeft )
sRect.setRight( canvasRect.left() );
else
sRect.setLeft( canvasRect.right() );
\brief Recalculate the geometry of all components.
\param plotRect Rectangle where to place the components
\param options Layout options
void QwtPlotLayout::activate( const QwtPlot *plot,
const QRectF &plotRect, Options options )
QRectF rect( plotRect ); // undistributed rest of the plot rect
// We extract all layout relevant parameters from the widgets,
// and save them to d_data->layoutData.
if ( !( options & IgnoreLegend )
&& plot->legend() && !plot->legend()->isEmpty() )
{
d_data->legendRect = layoutLegend( options, rect );
const QRegion region( rect.toRect() );
rect = region.subtracted( d_data->legendRect.toRect() ).boundingRect();
break;
case QwtPlot::RightLegend:
break;
case QwtPlot::TopLegend:
break;
case QwtPlot::BottomLegend:
}
}
/*
+---+-----------+---+
| Title |
+---+-----------+---+
| | Axis | |
+---+-----------+---+
| A | | A |
| x | Canvas | x |
| i | | i |
| s | | s |
+---+-----------+---+
| | Axis | |
+---+-----------+---+
// title, footer and axes 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, footer and axes
int dimTitle, dimFooter, dimAxes[QwtPlot::axisCnt];
expandLineBreaks( options, rect, dimTitle, dimFooter, dimAxes );
if ( dimTitle > 0 )
{
d_data->titleRect.setRect(
rect.left(), rect.top(), rect.width(), dimTitle );
rect.setTop( d_data->titleRect.bottom() + d_data->spacing );
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.left() + dimAxes[QwtPlot::yLeft] );
d_data->titleRect.setWidth( rect.width()
- dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] );
if ( dimFooter > 0 )
{
d_data->footerRect.setRect(
rect.left(), rect.bottom() - dimFooter, rect.width(), dimFooter );
rect.setBottom( d_data->footerRect.top() - d_data->spacing );
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 footer centered to the canvas
d_data->footerRect.setX( rect.left() + dimAxes[QwtPlot::yLeft] );
d_data->footerRect.setWidth( rect.width()
- dimAxes[QwtPlot::yLeft] - dimAxes[QwtPlot::yRight] );
}
}
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] );
for ( int axis = 0; axis < QwtPlot::axisCnt; 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;
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
}
scaleRect = scaleRect.normalized();
}
}
// +---+-----------+---+
// | <- Axis -> |
// +-^-+-----------+-^-+
// | | | | | |
// | | | |
// | A | | A |
// | x | Canvas | x |
// | i | | i |
// | s | | s |
// | | | |
// | | | | | |
// +-V-+-----------+-V-+
// | <- Axis -> |
// +---+-----------+---+
// The ticks of the axes - not the labels above - should
// be aligned to the canvas. So we try to use the empty
// corners to extend the axes, so that the label texts
// left/right of the min/max ticks are moved into them.
alignScales( options, d_data->canvasRect, d_data->scaleRect );
// 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 );