@@ -234,6 +234,7 @@ bool QgsLayoutItemMapGrid::writeXml( QDomElement &elem, QDomDocument &doc, const
234
234
mapGridElem.setAttribute ( QStringLiteral ( " gridFrameStyle" ), mGridFrameStyle );
235
235
mapGridElem.setAttribute ( QStringLiteral ( " gridFrameSideFlags" ), mGridFrameSides );
236
236
mapGridElem.setAttribute ( QStringLiteral ( " gridFrameWidth" ), qgsDoubleToString ( mGridFrameWidth ) );
237
+ mapGridElem.setAttribute ( QStringLiteral ( " gridFrameMargin" ), qgsDoubleToString ( mGridFrameMargin ) );
237
238
mapGridElem.setAttribute ( QStringLiteral ( " gridFramePenThickness" ), qgsDoubleToString ( mGridFramePenThickness ) );
238
239
mapGridElem.setAttribute ( QStringLiteral ( " gridFramePenColor" ), QgsSymbolLayerUtils::encodeColor ( mGridFramePenColor ) );
239
240
mapGridElem.setAttribute ( QStringLiteral ( " frameFillColor1" ), QgsSymbolLayerUtils::encodeColor ( mGridFrameFillColor1 ) );
@@ -294,6 +295,7 @@ bool QgsLayoutItemMapGrid::readXml( const QDomElement &itemElem, const QDomDocum
294
295
mGridFrameStyle = static_cast < QgsLayoutItemMapGrid::FrameStyle >( itemElem.attribute ( QStringLiteral ( " gridFrameStyle" ), QStringLiteral ( " 0" ) ).toInt () );
295
296
mGridFrameSides = static_cast < QgsLayoutItemMapGrid::FrameSideFlags >( itemElem.attribute ( QStringLiteral ( " gridFrameSideFlags" ), QStringLiteral ( " 15" ) ).toInt () );
296
297
mGridFrameWidth = itemElem.attribute ( QStringLiteral ( " gridFrameWidth" ), QStringLiteral ( " 2.0" ) ).toDouble ();
298
+ mGridFrameMargin = itemElem.attribute ( QStringLiteral ( " gridFrameMargin" ), QStringLiteral ( " 0.0" ) ).toDouble ();
297
299
mGridFramePenThickness = itemElem.attribute ( QStringLiteral ( " gridFramePenThickness" ), QStringLiteral ( " 0.3" ) ).toDouble ();
298
300
mGridFramePenColor = QgsSymbolLayerUtils::decodeColor ( itemElem.attribute ( QStringLiteral ( " gridFramePenColor" ), QStringLiteral ( " 0,0,0" ) ) );
299
301
mGridFrameFillColor1 = QgsSymbolLayerUtils::decodeColor ( itemElem.attribute ( QStringLiteral ( " frameFillColor1" ), QStringLiteral ( " 255,255,255,255" ) ) );
@@ -800,21 +802,23 @@ void QgsLayoutItemMapGrid::drawGridFrameZebraBorder( QPainter *p, const QMap< do
800
802
801
803
if ( extension )
802
804
{
803
- *extension = mGridFrameWidth + mGridFramePenThickness / 2.0 ;
805
+ *extension = mGridFrameMargin + mGridFrameWidth + mGridFramePenThickness / 2.0 ;
804
806
return ;
805
807
}
806
808
807
809
QMap< double , double > pos = borderPos;
808
810
809
- double currentCoord = 0 ;
811
+ double currentCoord = 0.0 ;
810
812
if ( ( border == QgsLayoutItemMapGrid::Left || border == QgsLayoutItemMapGrid::Right ) && testFrameSideFlag ( QgsLayoutItemMapGrid::FrameTop ) )
811
813
{
812
- currentCoord = - mGridFrameWidth ;
814
+ // currentCoord = - (mGridFrameWidth + mGridFrameMargin);
815
+ currentCoord = -mGridFramePenThickness / 2.0 ;
813
816
pos.insert ( 0 , 0 );
814
817
}
815
818
else if ( ( border == QgsLayoutItemMapGrid::Top || border == QgsLayoutItemMapGrid::Bottom ) && testFrameSideFlag ( QgsLayoutItemMapGrid::FrameLeft ) )
816
819
{
817
- currentCoord = - mGridFrameWidth ;
820
+ // currentCoord = - (mGridFrameWidth + mGridFrameMargin);
821
+ currentCoord = -mGridFramePenThickness / 2.0 ;
818
822
pos.insert ( 0 , 0 );
819
823
}
820
824
bool color1 = true ;
@@ -828,15 +832,17 @@ void QgsLayoutItemMapGrid::drawGridFrameZebraBorder( QPainter *p, const QMap< do
828
832
pos.insert ( mMap ->rect ().height (), mMap ->rect ().height () );
829
833
if ( testFrameSideFlag ( QgsLayoutItemMapGrid::FrameBottom ) )
830
834
{
831
- pos.insert ( mMap ->rect ().height () + mGridFrameWidth , mMap ->rect ().height () + mGridFrameWidth );
835
+ // pos.insert( mMap->rect().height() + mGridFrameWidth, mMap->rect().height() + mGridFrameWidth );
836
+ pos.insert ( mMap ->rect ().height (), mMap ->rect ().height () );
832
837
}
833
838
}
834
839
else if ( border == QgsLayoutItemMapGrid::Top || border == QgsLayoutItemMapGrid::Bottom )
835
840
{
836
841
pos.insert ( mMap ->rect ().width (), mMap ->rect ().width () );
837
842
if ( testFrameSideFlag ( QgsLayoutItemMapGrid::FrameRight ) )
838
843
{
839
- pos.insert ( mMap ->rect ().width () + mGridFrameWidth , mMap ->rect ().width () + mGridFrameWidth );
844
+ // pos.insert( mMap->rect().width() + mGridFrameWidth, mMap->rect().width() + mGridFrameWidth );
845
+ pos.insert ( mMap ->rect ().width (), mMap ->rect ().width () );
840
846
}
841
847
}
842
848
@@ -854,20 +860,27 @@ void QgsLayoutItemMapGrid::drawGridFrameZebraBorder( QPainter *p, const QMap< do
854
860
{
855
861
height = posIt.key () - currentCoord;
856
862
width = mGridFrameWidth ;
857
- x = ( border == QgsLayoutItemMapGrid::Left ) ? -mGridFrameWidth : mMap ->rect ().width ();
863
+ x = ( border == QgsLayoutItemMapGrid::Left ) ? -( mGridFrameWidth + mGridFrameMargin ) : mMap ->rect ().width () + mGridFrameMargin ;
858
864
y = currentCoord;
859
865
}
860
866
else // top or bottom
861
867
{
862
868
height = mGridFrameWidth ;
863
869
width = posIt.key () - currentCoord;
864
870
x = currentCoord;
865
- y = ( border == QgsLayoutItemMapGrid::Top ) ? -mGridFrameWidth : mMap ->rect ().height ();
871
+ y = ( border == QgsLayoutItemMapGrid::Top ) ? -( mGridFrameWidth + mGridFrameMargin ) : mMap ->rect ().height () + mGridFrameMargin ;
866
872
}
867
873
p->drawRect ( QRectF ( x, y, width, height ) );
868
874
currentCoord = posIt.key ();
869
875
color1 = !color1;
870
876
}
877
+ // draw corners
878
+ width = height = ( mGridFrameWidth + mGridFrameMargin ) ;
879
+ p->setBrush ( QBrush ( mGridFrameFillColor1 ) );
880
+ p->drawRect ( QRectF ( -( mGridFrameWidth + mGridFrameMargin ), -( mGridFrameWidth + mGridFrameMargin ), width, height ) );
881
+ p->drawRect ( QRectF ( mMap ->rect ().width (), -( mGridFrameWidth + mGridFrameMargin ), width, height ) );
882
+ p->drawRect ( QRectF ( -( mGridFrameWidth + mGridFrameMargin ), mMap ->rect ().height (), width, height ) );
883
+ p->drawRect ( QRectF ( mMap ->rect ().width (), mMap ->rect ().height (), width, height ) );
871
884
}
872
885
873
886
void QgsLayoutItemMapGrid::drawGridFrameTicks ( QPainter *p, const QMap< double , double > &borderPos, QgsLayoutItemMapGrid::BorderSide border, double *extension ) const
@@ -880,7 +893,7 @@ void QgsLayoutItemMapGrid::drawGridFrameTicks( QPainter *p, const QMap< double,
880
893
if ( extension )
881
894
{
882
895
if ( mGridFrameStyle != QgsLayoutItemMapGrid::InteriorTicks )
883
- *extension = mGridFrameWidth ;
896
+ *extension = mGridFrameMargin + mGridFrameWidth ;
884
897
return ;
885
898
}
886
899
@@ -906,17 +919,17 @@ void QgsLayoutItemMapGrid::drawGridFrameTicks( QPainter *p, const QMap< double,
906
919
if ( mGridFrameStyle == QgsLayoutItemMapGrid::InteriorTicks )
907
920
{
908
921
width = mGridFrameWidth ;
909
- x = ( border == QgsLayoutItemMapGrid::Left ) ? 0 : mMap ->rect ().width () - mGridFrameWidth ;
922
+ x = ( border == QgsLayoutItemMapGrid::Left ) ? 0 - mGridFrameMargin : mMap ->rect ().width () - mGridFrameWidth + mGridFrameMargin ;
910
923
}
911
924
else if ( mGridFrameStyle == QgsLayoutItemMapGrid::ExteriorTicks )
912
925
{
913
926
width = mGridFrameWidth ;
914
- x = ( border == QgsLayoutItemMapGrid::Left ) ? - mGridFrameWidth : mMap ->rect ().width ();
927
+ x = ( border == QgsLayoutItemMapGrid::Left ) ? - mGridFrameWidth - mGridFrameMargin : mMap ->rect ().width () + mGridFrameMargin ;
915
928
}
916
929
else if ( mGridFrameStyle == QgsLayoutItemMapGrid::InteriorExteriorTicks )
917
930
{
918
931
width = mGridFrameWidth * 2 ;
919
- x = ( border == QgsLayoutItemMapGrid::Left ) ? - mGridFrameWidth : mMap ->rect ().width () - mGridFrameWidth ;
932
+ x = ( border == QgsLayoutItemMapGrid::Left ) ? - mGridFrameWidth - mGridFrameMargin : mMap ->rect ().width () - mGridFrameWidth + mGridFrameMargin ;
920
933
}
921
934
}
922
935
else // top or bottom
@@ -926,17 +939,17 @@ void QgsLayoutItemMapGrid::drawGridFrameTicks( QPainter *p, const QMap< double,
926
939
if ( mGridFrameStyle == QgsLayoutItemMapGrid::InteriorTicks )
927
940
{
928
941
height = mGridFrameWidth ;
929
- y = ( border == QgsLayoutItemMapGrid::Top ) ? 0 : mMap ->rect ().height () - mGridFrameWidth ;
942
+ y = ( border == QgsLayoutItemMapGrid::Top ) ? 0 - mGridFrameMargin : mMap ->rect ().height () - mGridFrameWidth + mGridFrameMargin ;
930
943
}
931
944
else if ( mGridFrameStyle == QgsLayoutItemMapGrid::ExteriorTicks )
932
945
{
933
946
height = mGridFrameWidth ;
934
- y = ( border == QgsLayoutItemMapGrid::Top ) ? -mGridFrameWidth : mMap ->rect ().height ();
947
+ y = ( border == QgsLayoutItemMapGrid::Top ) ? -mGridFrameWidth - mGridFrameMargin : mMap ->rect ().height () + mGridFrameMargin ;
935
948
}
936
949
else if ( mGridFrameStyle == QgsLayoutItemMapGrid::InteriorExteriorTicks )
937
950
{
938
951
height = mGridFrameWidth * 2 ;
939
- y = ( border == QgsLayoutItemMapGrid::Top ) ? -mGridFrameWidth : mMap ->rect ().height () - mGridFrameWidth ;
952
+ y = ( border == QgsLayoutItemMapGrid::Top ) ? -mGridFrameWidth - mGridFrameMargin : mMap ->rect ().height () - mGridFrameWidth + mGridFrameMargin ;
940
953
}
941
954
}
942
955
p->drawLine ( QLineF ( x, y, x + width, y + height ) );
@@ -952,7 +965,7 @@ void QgsLayoutItemMapGrid::drawGridFrameLineBorder( QPainter *p, QgsLayoutItemMa
952
965
953
966
if ( extension )
954
967
{
955
- *extension = mGridFramePenThickness / 2.0 ;
968
+ *extension = mGridFrameMargin + mGridFramePenThickness / 2.0 ;
956
969
return ;
957
970
}
958
971
@@ -966,16 +979,44 @@ void QgsLayoutItemMapGrid::drawGridFrameLineBorder( QPainter *p, QgsLayoutItemMa
966
979
switch ( border )
967
980
{
968
981
case QgsLayoutItemMapGrid::Left:
969
- p->drawLine ( QLineF ( 0 , 0 , 0 , mMap ->rect ().height () ) );
982
+ p->drawLine ( QLineF ( 0 - mGridFrameMargin , 0 - mGridFrameMargin , 0 - mGridFrameMargin , mMap ->rect ().height () + mGridFrameMargin ) );
983
+ // corner left-top
984
+ if ( mGridFrameMargin != 0 )
985
+ {
986
+ const double X1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0 ;
987
+ const double Y1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0 ;
988
+ p->drawLine ( QLineF ( 0 , 0 , X1, Y1 ) );
989
+ }
970
990
break ;
971
991
case QgsLayoutItemMapGrid::Right:
972
- p->drawLine ( QLineF ( mMap ->rect ().width (), 0 , mMap ->rect ().width (), mMap ->rect ().height () ) );
992
+ p->drawLine ( QLineF ( mMap ->rect ().width () + mGridFrameMargin , 0 - mGridFrameMargin , mMap ->rect ().width () + mGridFrameMargin , mMap ->rect ().height () + mGridFrameMargin ) );
993
+ // corner right-bottom
994
+ if ( mGridFrameMargin != 0 )
995
+ {
996
+ const double X1 = mMap ->rect ().width () + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
997
+ const double Y1 = mMap ->rect ().height () + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
998
+ p->drawLine ( QLineF ( mMap ->rect ().width (), mMap ->rect ().height (), X1, Y1 ) );
999
+ }
973
1000
break ;
974
1001
case QgsLayoutItemMapGrid::Top:
975
- p->drawLine ( QLineF ( 0 , 0 , mMap ->rect ().width (), 0 ) );
1002
+ p->drawLine ( QLineF ( 0 - mGridFrameMargin , 0 - mGridFrameMargin , mMap ->rect ().width () + mGridFrameMargin , 0 - mGridFrameMargin ) );
1003
+ // corner right-top
1004
+ if ( mGridFrameMargin != 0 )
1005
+ {
1006
+ const double X1 = mMap ->rect ().width () + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
1007
+ const double Y1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0 ;
1008
+ p->drawLine ( QLineF ( mMap ->rect ().width (), 0 , X1, Y1 ) );
1009
+ }
976
1010
break ;
977
1011
case QgsLayoutItemMapGrid::Bottom:
978
- p->drawLine ( QLineF ( 0 , mMap ->rect ().height (), mMap ->rect ().width (), mMap ->rect ().height () ) );
1012
+ p->drawLine ( QLineF ( 0 - mGridFrameMargin , mMap ->rect ().height () + mGridFrameMargin , mMap ->rect ().width () + mGridFrameMargin , mMap ->rect ().height () + mGridFrameMargin ) );
1013
+ // corner left-bottom
1014
+ if ( mGridFrameMargin != 0 )
1015
+ {
1016
+ const double X1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0 ;
1017
+ const double Y1 = mMap ->rect ().height () + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
1018
+ p->drawLine ( QLineF ( 0 , mMap ->rect ().height (), X1, Y1 ) );
1019
+ }
979
1020
break ;
980
1021
}
981
1022
}
@@ -1684,7 +1725,7 @@ int QgsLayoutItemMapGrid::xGridLinesCrsTransform( const QgsRectangle &bbox, cons
1684
1725
catch ( QgsCsException &cse )
1685
1726
{
1686
1727
Q_UNUSED ( cse );
1687
- QgsDebugMsg ( QStringLiteral ( " Caught CRS exception %1" ).arg ( cse.what () ) );
1728
+ QgsDebugMsg ( QString ( " Caught CRS exception %1" ).arg ( cse.what () ) );
1688
1729
}
1689
1730
1690
1731
currentX += step;
@@ -1760,7 +1801,7 @@ int QgsLayoutItemMapGrid::yGridLinesCrsTransform( const QgsRectangle &bbox, cons
1760
1801
catch ( QgsCsException &cse )
1761
1802
{
1762
1803
Q_UNUSED ( cse );
1763
- QgsDebugMsg ( QStringLiteral ( " Caught CRS exception %1" ).arg ( cse.what () ) );
1804
+ QgsDebugMsg ( QString ( " Caught CRS exception %1" ).arg ( cse.what () ) );
1764
1805
}
1765
1806
1766
1807
currentY += step;
0 commit comments