Skip to content

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed
 

‎src/gui/qgsmapcanvas.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,19 @@ void QgsMapCanvas::resizeEvent(QResizeEvent * e)
697697
int width = e->size().width(), height = e->size().height();
698698
// int width = visibleWidth(), height = visibleHeight();
699699
mCanvas->resize(width, height);
700-
700+
701+
// Adjust the size (in pixels) of that we draw by the margins in
702+
// the widget that the drawing eventually gets placed in. In my testing
703+
// the margin was 2 pixels on each border. Add 1 more pixel just to
704+
// be sure that the drawn map appears fully within the margins in
705+
// the widget.
706+
int top, bottom, right, left;
707+
getContentsMargins(&left, &top, &right, &bottom);
708+
width = width - (left + right + 1);
709+
height = height - (top + bottom + 1);
710+
701711
mMap->resize(/*e->size()*/ QSize(width,height));
702-
712+
703713
// notify canvas items of change
704714
updateCanvasItemsPositions();
705715

‎src/gui/qgsmaprender.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,10 @@ void QgsMapRender::adjustExtentToSize()
123123

124124
// calculate the translation and scaling parameters
125125
// mupp = map units per pixel
126-
double muppY = mExtent.height() / myHeight;
127-
double muppX = mExtent.width() / myWidth;
126+
double muppY = static_cast<double>(mExtent.height())
127+
/ static_cast<double>(myHeight);
128+
double muppX = static_cast<double>(mExtent.width())
129+
/ static_cast<double>(myWidth);
128130
mMupp = muppY > muppX ? muppY : muppX;
129131

130132
// calculate the actual extent of the mapCanvas
@@ -134,15 +136,15 @@ void QgsMapRender::adjustExtentToSize()
134136
{
135137
dymin = mExtent.yMin();
136138
dymax = mExtent.yMax();
137-
whitespace = ((myWidth * mMupp) - mExtent.width()) / 2;
139+
whitespace = ((myWidth * mMupp) - mExtent.width()) * 0.5;
138140
dxmin = mExtent.xMin() - whitespace;
139141
dxmax = mExtent.xMax() + whitespace;
140142
}
141143
else
142144
{
143145
dxmin = mExtent.xMin();
144146
dxmax = mExtent.xMax();
145-
whitespace = ((myHeight * mMupp) - mExtent.height()) / 2;
147+
whitespace = ((myHeight * mMupp) - mExtent.height()) * 0.5;
146148
dymin = mExtent.yMin() - whitespace;
147149
dymax = mExtent.yMax() + whitespace;
148150
}
@@ -165,7 +167,7 @@ void QgsMapRender::adjustExtentToSize()
165167
mExtent.setXmax(dxmax);
166168
mExtent.setYmin(dymin);
167169
mExtent.setYmax(dymax);
168-
170+
169171
// update the scale
170172
updateScale();
171173

0 commit comments

Comments
 (0)
Please sign in to comment.