Skip to content

Commit aa3e40a

Browse files
committedDec 28, 2013
[FEATURE][composer] Add controls for changing zebra frame colors and line thickness, fix output of zebra style grids (fix #8767)
1 parent afbd2ac commit aa3e40a

File tree

8 files changed

+347
-57
lines changed

8 files changed

+347
-57
lines changed
 

‎python/core/composer/qgscomposermap.sip

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,32 @@ class QgsComposerMap : QgsComposerItem
247247
@note: this function was added in version 1.9*/
248248
void setGridFrameWidth( double w );
249249
double gridFrameWidth() const;
250+
251+
/**Set grid frame pen thickness
252+
@note: this function was added in version 2.1*/
253+
void setGridFramePenSize( double w );
254+
double gridFramePenSize() const;
255+
256+
/**Sets pen color for grid frame
257+
@note: this function was added in version 2.1*/
258+
void setGridFramePenColor( const QColor& c );
259+
/**Get pen color for grid frame
260+
@note: this function was added in version 2.1*/
261+
QColor gridFramePenColor() const;
262+
263+
/**Sets first fill color for grid zebra frame
264+
@note: this function was added in version 2.1*/
265+
void setGridFrameFillColor1( const QColor& c );
266+
/**Get first fill color for grid zebra frame
267+
@note: this function was added in version 2.1*/
268+
QColor gridFrameFillColor1() const;
269+
270+
/**Sets second fill color for grid zebra frame
271+
@note: this function was added in version 2.1*/
272+
void setGridFrameFillColor2( const QColor& c );
273+
/**Get second fill color for grid zebra frame
274+
@note: this function was added in version 2.1*/
275+
QColor gridFrameFillColor2() const;
250276

251277
/** Returns the grid's blending mode
252278
@note added in version 2.0*/

‎src/app/composer/qgscomposermapwidget.cpp

Lines changed: 89 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
6161
mAnnotationFormatComboBox->insertItem( 1, tr( "DegreeMinute" ) );
6262
mAnnotationFormatComboBox->insertItem( 2, tr( "DegreeMinuteSecond" ) );
6363

64+
mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
65+
mAnnotationFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
66+
6467
insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
6568
insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
6669
insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
@@ -74,9 +77,22 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
7477
mFrameStyleComboBox->insertItem( 0, tr( "No frame" ) );
7578
mFrameStyleComboBox->insertItem( 1, tr( "Zebra" ) );
7679

80+
mGridFramePenColorButton->setColorDialogTitle( tr( "Select grid frame color" ) );
81+
mGridFramePenColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
82+
mGridFrameFill1ColorButton->setColorDialogTitle( tr( "Select grid frame fill color" ) );
83+
mGridFrameFill1ColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
84+
mGridFrameFill2ColorButton->setColorDialogTitle( tr( "Select grid frame fill color" ) );
85+
mGridFrameFill2ColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
86+
87+
//set initial state of frame style controls
88+
toggleFrameControls( false );
89+
7790
connect( mGridCheckBox, SIGNAL( toggled( bool ) ),
7891
mDrawAnnotationCheckableGroupBox, SLOT( setEnabled( bool ) ) );
7992

93+
connect( mFrameStyleComboBox, SIGNAL( currentIndexChanged( QString ) ),
94+
this, SLOT( frameStyleChanged( QString ) ) );
95+
8096
if ( composerMap )
8197
{
8298
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
@@ -339,14 +355,20 @@ void QgsComposerMapWidget::updateGuiElements()
339355

340356
//grid frame
341357
mFrameWidthSpinBox->setValue( mComposerMap->gridFrameWidth() );
358+
mGridFramePenSizeSpinBox->setValue( mComposerMap->gridFramePenSize() );
359+
mGridFramePenColorButton->setColor( mComposerMap->gridFramePenColor() );
360+
mGridFrameFill1ColorButton->setColor( mComposerMap->gridFrameFillColor1() );
361+
mGridFrameFill2ColorButton->setColor( mComposerMap->gridFrameFillColor2() );
342362
QgsComposerMap::GridFrameStyle gridFrameStyle = mComposerMap->gridFrameStyle();
343363
if ( gridFrameStyle == QgsComposerMap::Zebra )
344364
{
345365
mFrameStyleComboBox->setCurrentIndex( mFrameStyleComboBox->findText( tr( "Zebra" ) ) );
366+
toggleFrameControls( true );
346367
}
347368
else //NoGridFrame
348369
{
349370
mFrameStyleComboBox->setCurrentIndex( mFrameStyleComboBox->findText( tr( "No frame" ) ) );
371+
toggleFrameControls( false );
350372
}
351373

352374
//grid blend mode
@@ -369,8 +391,6 @@ void QgsComposerMapWidget::updateGuiElements()
369391
initAnnotationDirectionBox( mAnnotationDirectionComboBoxBottom, mComposerMap->gridAnnotationDirection( QgsComposerMap::Bottom ) );
370392

371393
mAnnotationFontColorButton->setColor( mComposerMap->annotationFontColor() );
372-
mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
373-
mAnnotationFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
374394

375395
mDistanceToMapFrameSpinBox->setValue( mComposerMap->annotationFrameDistance() );
376396

@@ -454,6 +474,10 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
454474
mDrawCanvasItemsCheckBox->blockSignals( b );
455475
mFrameStyleComboBox->blockSignals( b );
456476
mFrameWidthSpinBox->blockSignals( b );
477+
mGridFramePenSizeSpinBox->blockSignals( b );
478+
mGridFramePenColorButton->blockSignals( b );
479+
mGridFrameFill1ColorButton->blockSignals( b );
480+
mGridFrameFill2ColorButton->blockSignals( b );
457481
mOverviewFrameMapComboBox->blockSignals( b );
458482
mOverviewFrameStyleButton->blockSignals( b );
459483
mOverviewBlendModeComboBox->blockSignals( b );
@@ -880,8 +904,23 @@ void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int valu
880904
mComposerMap->endCommand();
881905
}
882906

907+
void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled )
908+
{
909+
//set status of frame controls
910+
mFrameWidthSpinBox->setEnabled( frameEnabled );
911+
mGridFramePenSizeSpinBox->setEnabled( frameEnabled );
912+
mGridFramePenColorButton->setEnabled( frameEnabled );
913+
mGridFrameFill1ColorButton->setEnabled( frameEnabled );
914+
mGridFrameFill2ColorButton->setEnabled( frameEnabled );
915+
mFrameWidthLabel->setEnabled( frameEnabled );
916+
mFramePenLabel->setEnabled( frameEnabled );
917+
mFrameFillLabel->setEnabled( frameEnabled );
918+
}
919+
883920
void QgsComposerMapWidget::on_mFrameStyleComboBox_currentIndexChanged( const QString& text )
884921
{
922+
toggleFrameControls( text != tr( "No frame" ) );
923+
885924
if ( !mComposerMap )
886925
{
887926
return;
@@ -913,6 +952,54 @@ void QgsComposerMapWidget::on_mFrameWidthSpinBox_valueChanged( double d )
913952
}
914953
}
915954

955+
void QgsComposerMapWidget::on_mGridFramePenSizeSpinBox_valueChanged( double d )
956+
{
957+
if ( mComposerMap )
958+
{
959+
mComposerMap->beginCommand( tr( "Changed grid frame line thickness" ) );
960+
mComposerMap->setGridFramePenSize( d );
961+
mComposerMap->updateBoundingRect();
962+
mComposerMap->update();
963+
mComposerMap->endCommand();
964+
}
965+
}
966+
967+
void QgsComposerMapWidget::on_mGridFramePenColorButton_colorChanged( const QColor& newColor )
968+
{
969+
if ( !mComposerMap )
970+
{
971+
return;
972+
}
973+
mComposerMap->beginCommand( tr( "Grid frame color changed" ) );
974+
mComposerMap->setGridFramePenColor( newColor );
975+
mComposerMap->update();
976+
mComposerMap->endCommand();
977+
}
978+
979+
void QgsComposerMapWidget::on_mGridFrameFill1ColorButton_colorChanged( const QColor& newColor )
980+
{
981+
if ( !mComposerMap )
982+
{
983+
return;
984+
}
985+
mComposerMap->beginCommand( tr( "Grid frame first fill color changed" ) );
986+
mComposerMap->setGridFrameFillColor1( newColor );
987+
mComposerMap->update();
988+
mComposerMap->endCommand();
989+
}
990+
991+
void QgsComposerMapWidget::on_mGridFrameFill2ColorButton_colorChanged( const QColor& newColor )
992+
{
993+
if ( !mComposerMap )
994+
{
995+
return;
996+
}
997+
mComposerMap->beginCommand( tr( "Grid frame second fill color changed" ) );
998+
mComposerMap->setGridFrameFillColor2( newColor );
999+
mComposerMap->update();
1000+
mComposerMap->endCommand();
1001+
}
1002+
9161003
void QgsComposerMapWidget::showEvent( QShowEvent * event )
9171004
{
9181005
refreshMapComboBox();

‎src/app/composer/qgscomposermapwidget.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
8585

8686
void on_mFrameStyleComboBox_currentIndexChanged( const QString& text );
8787
void on_mFrameWidthSpinBox_valueChanged( double d );
88+
void on_mGridFramePenSizeSpinBox_valueChanged( double d );
89+
void on_mGridFramePenColorButton_colorChanged( const QColor& newColor );
90+
void on_mGridFrameFill1ColorButton_colorChanged( const QColor& newColor );
91+
void on_mGridFrameFill2ColorButton_colorChanged( const QColor& newColor );
8892

8993
protected:
9094
void showEvent( QShowEvent * event );
@@ -122,6 +126,9 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
122126

123127
/**Updates the map combo box with the current composer map ids*/
124128
void refreshMapComboBox();
129+
130+
/**Enables/disables grid frame related controls*/
131+
void toggleFrameControls( bool frameEnabled );
125132
};
126133

127134
#endif

‎src/core/composer/qgscomposermap.cpp

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
4949
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
5050
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
5151
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
52+
mGridFramePenThickness( 0.5 ), mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
5253
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
5354
{
5455
mComposition = composition;
@@ -105,8 +106,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
105106
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
106107
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
107108
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
108-
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
109-
mMapCanvas( 0 ), mDrawCanvasItems( true )
109+
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mGridFramePenThickness( 0.5 ),
110+
mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
111+
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
110112
{
111113
mOverviewFrameMapSymbol = 0;
112114
mGridLineSymbol = 0;
@@ -865,6 +867,28 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
865867
gridElem.setAttribute( "crossLength", qgsDoubleToString( mCrossLength ) );
866868
gridElem.setAttribute( "gridFrameStyle", mGridFrameStyle );
867869
gridElem.setAttribute( "gridFrameWidth", qgsDoubleToString( mGridFrameWidth ) );
870+
gridElem.setAttribute( "gridFramePenThickness", qgsDoubleToString( mGridFramePenThickness ) );
871+
//grid frame pen color
872+
QDomElement framePenColorElem = doc.createElement( "framePenColor" );
873+
framePenColorElem.setAttribute( "red", mGridFramePenColor.red() );
874+
framePenColorElem.setAttribute( "green", mGridFramePenColor.green() );
875+
framePenColorElem.setAttribute( "blue", mGridFramePenColor.blue() );
876+
framePenColorElem.setAttribute( "alpha", mGridFramePenColor.alpha() );
877+
gridElem.appendChild( framePenColorElem );
878+
//grid frame fill colors
879+
QDomElement frameFillColor1Elem = doc.createElement( "frameFillColor1" );
880+
frameFillColor1Elem.setAttribute( "red", mGridFrameFillColor1.red() );
881+
frameFillColor1Elem.setAttribute( "green", mGridFrameFillColor1.green() );
882+
frameFillColor1Elem.setAttribute( "blue", mGridFrameFillColor1.blue() );
883+
frameFillColor1Elem.setAttribute( "alpha", mGridFrameFillColor1.alpha() );
884+
gridElem.appendChild( frameFillColor1Elem );
885+
QDomElement frameFillColor2Elem = doc.createElement( "frameFillColor2" );
886+
frameFillColor2Elem.setAttribute( "red", mGridFrameFillColor2.red() );
887+
frameFillColor2Elem.setAttribute( "green", mGridFrameFillColor2.green() );
888+
frameFillColor2Elem.setAttribute( "blue", mGridFrameFillColor2.blue() );
889+
frameFillColor2Elem.setAttribute( "alpha", mGridFrameFillColor2.alpha() );
890+
gridElem.appendChild( frameFillColor2Elem );
891+
868892
gridElem.setAttribute( "gridBlendMode", QgsMapRenderer::getBlendModeEnum( mGridBlendMode ) );
869893
QDomElement gridLineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mGridLineSymbol, doc );
870894
gridElem.appendChild( gridLineStyleElem );
@@ -889,6 +913,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
889913
annotationFontColorElem.setAttribute( "red", mGridAnnotationFontColor.red() );
890914
annotationFontColorElem.setAttribute( "green", mGridAnnotationFontColor.green() );
891915
annotationFontColorElem.setAttribute( "blue", mGridAnnotationFontColor.blue() );
916+
annotationFontColorElem.setAttribute( "alpha", mGridAnnotationFontColor.alpha() );
892917
annotationElem.appendChild( annotationFontColorElem );
893918

894919
gridElem.appendChild( annotationElem );
@@ -1027,6 +1052,54 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
10271052
mCrossLength = gridElem.attribute( "crossLength", "3" ).toDouble();
10281053
mGridFrameStyle = ( QgsComposerMap::GridFrameStyle )gridElem.attribute( "gridFrameStyle", "0" ).toInt();
10291054
mGridFrameWidth = gridElem.attribute( "gridFrameWidth", "2.0" ).toDouble();
1055+
mGridFramePenThickness = gridElem.attribute( "gridFramePenThickness", "0.5" ).toDouble();
1056+
1057+
//grid frame pen color
1058+
QDomNodeList gridFramePenColorList = gridElem.elementsByTagName( "framePenColor" );
1059+
if ( gridFramePenColorList.size() > 0 )
1060+
{
1061+
QDomElement penColorElem = gridFramePenColorList.at( 0 ).toElement();
1062+
int red = penColorElem.attribute( "red", "0" ).toInt();
1063+
int green = penColorElem.attribute( "green", "0" ).toInt();
1064+
int blue = penColorElem.attribute( "blue", "0" ).toInt();
1065+
int alpha = penColorElem.attribute( "alpha", "255" ).toInt();
1066+
mGridFramePenColor = QColor( red, green, blue, alpha );
1067+
}
1068+
else
1069+
{
1070+
mGridFramePenColor = QColor( 0, 0, 0 );
1071+
}
1072+
//grid frame fill color 1
1073+
QDomNodeList gridFrameFillColor1List = gridElem.elementsByTagName( "frameFillColor1" );
1074+
if ( gridFrameFillColor1List.size() > 0 )
1075+
{
1076+
QDomElement fillColorElem = gridFrameFillColor1List.at( 0 ).toElement();
1077+
int red = fillColorElem.attribute( "red", "0" ).toInt();
1078+
int green = fillColorElem.attribute( "green", "0" ).toInt();
1079+
int blue = fillColorElem.attribute( "blue", "0" ).toInt();
1080+
int alpha = fillColorElem.attribute( "alpha", "255" ).toInt();
1081+
mGridFrameFillColor1 = QColor( red, green, blue, alpha );
1082+
}
1083+
else
1084+
{
1085+
mGridFrameFillColor1 = Qt::white;
1086+
}
1087+
//grid frame fill color 2
1088+
QDomNodeList gridFrameFillColor2List = gridElem.elementsByTagName( "frameFillColor2" );
1089+
if ( gridFrameFillColor2List.size() > 0 )
1090+
{
1091+
QDomElement fillColorElem = gridFrameFillColor2List.at( 0 ).toElement();
1092+
int red = fillColorElem.attribute( "red", "0" ).toInt();
1093+
int green = fillColorElem.attribute( "green", "0" ).toInt();
1094+
int blue = fillColorElem.attribute( "blue", "0" ).toInt();
1095+
int alpha = fillColorElem.attribute( "alpha", "255" ).toInt();
1096+
mGridFrameFillColor2 = QColor( red, green, blue, alpha );
1097+
}
1098+
else
1099+
{
1100+
mGridFrameFillColor2 = Qt::black;
1101+
}
1102+
10301103
setGridBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) gridElem.attribute( "gridBlendMode", "0" ).toUInt() ) );
10311104

10321105
QDomElement gridSymbolElem = gridElem.firstChildElement( "symbol" );
@@ -1070,7 +1143,8 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
10701143
int red = fontColorElem.attribute( "red", "0" ).toInt();
10711144
int green = fontColorElem.attribute( "green", "0" ).toInt();
10721145
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
1073-
mGridAnnotationFontColor = QColor( red, green, blue );
1146+
int alpha = fontColorElem.attribute( "alpha", "255" ).toInt();
1147+
mGridAnnotationFontColor = QColor( red, green, blue, alpha );
10741148
}
10751149
else
10761150
{
@@ -1268,7 +1342,7 @@ void QgsComposerMap::drawGridLine( const QLineF& line, QPainter* p )
12681342
void QgsComposerMap::drawGridFrameBorder( QPainter* p, const QMap< double, double >& borderPos, Border border )
12691343
{
12701344
double currentCoord = - mGridFrameWidth;
1271-
bool white = true;
1345+
bool color1 = true;
12721346
double x = 0;
12731347
double y = 0;
12741348
double width = 0;
@@ -1287,10 +1361,15 @@ void QgsComposerMap::drawGridFrameBorder( QPainter* p, const QMap< double, doubl
12871361
pos.insert( rect().width() + mGridFrameWidth, rect().width() + mGridFrameWidth );
12881362
}
12891363

1364+
//set pen to current frame pen
1365+
QPen framePen = QPen( mGridFramePenColor );
1366+
framePen.setWidthF( mGridFramePenThickness );
1367+
p->setPen( framePen );
1368+
12901369
QMap< double, double >::const_iterator posIt = pos.constBegin();
12911370
for ( ; posIt != pos.constEnd(); ++posIt )
12921371
{
1293-
p->setBrush( QBrush( white ? Qt::white : Qt::black ) );
1372+
p->setBrush( QBrush( color1 ? mGridFrameFillColor1 : mGridFrameFillColor2 ) );
12941373
if ( border == Left || border == Right )
12951374
{
12961375
height = posIt.key() - currentCoord;
@@ -1307,7 +1386,7 @@ void QgsComposerMap::drawGridFrameBorder( QPainter* p, const QMap< double, doubl
13071386
}
13081387
p->drawRect( QRectF( x, y, width, height ) );
13091388
currentCoord = posIt.key();
1310-
white = !white;
1389+
color1 = !color1;
13111390
}
13121391
}
13131392

@@ -1347,7 +1426,7 @@ void QgsComposerMap::drawCoordinateAnnotation( QPainter* p, const QPointF& pos,
13471426
double ypos = pos.y();
13481427
int rotation = 0;
13491428

1350-
double gridFrameDistance = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth;
1429+
double gridFrameDistance = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth + ( mGridFramePenThickness / 2.0 );
13511430

13521431
if ( frameBorder == Left )
13531432
{
@@ -1801,7 +1880,7 @@ double QgsComposerMap::maxExtension() const
18011880
}
18021881

18031882
//grid frame
1804-
double gridFrameDist = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth;
1883+
double gridFrameDist = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth + ( mGridFramePenThickness / 2.0 );
18051884
return maxExtension + mAnnotationFrameDistance + gridFrameDist;
18061885
}
18071886

0 commit comments

Comments
 (0)
Please sign in to comment.