Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
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
1073
1074
1075
1076
1077
1078
1079
1080
1081
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
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
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
1148
1149
1150
1151
1152
1153
1154
1155
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
1185
1186
1187
1188
1189
1190
1191
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
int fw = 0;
if ( !(options & IgnoreFrames) )
fw = d_data->layoutData.canvas.frameWidth;
if ( scaleRect[QwtPlot::xBottom].isValid() &&
scaleRect[QwtPlot::xTop].isValid() )
{
for ( int axis = QwtPlot::xBottom; axis <= QwtPlot::xTop; axis++ )
{
scaleRect[axis].setLeft(canvasRect.left() + fw
- d_data->layoutData.scale[axis].start);
scaleRect[axis].setRight(canvasRect.right() - fw - 1
+ d_data->layoutData.scale[axis].end);
}
}
if ( scaleRect[QwtPlot::yLeft].isValid() &&
scaleRect[QwtPlot::yRight].isValid() )
{
for ( int axis = QwtPlot::yLeft; axis <= QwtPlot::yRight; axis++ )
{
scaleRect[axis].setTop(canvasRect.top() + fw
- d_data->layoutData.scale[axis].start);
scaleRect[axis].setBottom(canvasRect.bottom() - fw - 1
+ d_data->layoutData.scale[axis].end);
}
}
}
}
/*!
\brief Recalculate the geometry of all components.
\param plot Plot to be layout
\param plotRect Rect where to place the components
\param options Options
\sa invalidate(), titleRect(),
legendRect(), scaleRect(), canvasRect()
*/
void QwtPlotLayout::activate(const QwtPlot *plot,
const QRect &plotRect, int options)
{
invalidate();
QRect rect(plotRect); // undistributed rest of the plot rect
if ( !(options & IgnoreMargin) )
{
// subtract the margin
rect.setRect(
rect.x() + d_data->margin,
rect.y() + d_data->margin,
rect.width() - 2 * d_data->margin,
rect.height() - 2 * d_data->margin
);
}
// 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 (!(options & IgnoreLegend)
&& d_data->legendPos != QwtPlot::ExternalLegend
&& plot->legend() && !plot->legend()->isEmpty() )
{
d_data->legendRect = layoutLegend(options, rect);
// subtract d_data->legendRect from rect
const QRegion region(rect);
rect = region.subtract(d_data->legendRect).boundingRect();
if ( d_data->layoutData.legend.frameWidth &&
!(options & IgnoreFrames ) )
{
// In case of a frame we have to insert a spacing.
// Otherwise the leading of the font separates
// legend and scale/canvas
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
}
}
}
#ifdef __GNUC__
#endif
/*
+---+-----------+---+
| 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(options, 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]);
for ( int axis = 0; axis < QwtPlot::axisCnt; axis++ )
{
// set the rects for the axes
if ( dimAxes[axis] )
{
int dim = dimAxes[axis];
QRect &scaleRect = d_data->scaleRect[axis];
scaleRect = d_data->canvasRect;
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() + 1);
scaleRect.setWidth(dim);
break;
case QwtPlot::xBottom:
scaleRect.setY(d_data->canvasRect.bottom() + 1);
scaleRect.setHeight(dim);
break;
case QwtPlot::xTop:
scaleRect.setY(d_data->canvasRect.top() - dim);
scaleRect.setHeight(dim);
break;
}
#if QT_VERSION < 0x040000
scaleRect = scaleRect.normalize();
#else
scaleRect = scaleRect.normalized();
#endif
}
}
// +---+-----------+---+
// | <- 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);
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);
}
}