Skip to content
Permalink
Browse files

[FEATURE][composer] Add controls for changing zebra frame colors and …

…line thickness, fix output of zebra style grids (fix #8767)
  • Loading branch information
nyalldawson committed Dec 28, 2013
1 parent afbd2ac commit aa3e40a0ebfaab34d3405dcbee5a9d72dfb9ab89
@@ -247,6 +247,32 @@ class QgsComposerMap : QgsComposerItem
@note: this function was added in version 1.9*/
void setGridFrameWidth( double w );
double gridFrameWidth() const;

/**Set grid frame pen thickness
@note: this function was added in version 2.1*/
void setGridFramePenSize( double w );
double gridFramePenSize() const;

/**Sets pen color for grid frame
@note: this function was added in version 2.1*/
void setGridFramePenColor( const QColor& c );
/**Get pen color for grid frame
@note: this function was added in version 2.1*/
QColor gridFramePenColor() const;

/**Sets first fill color for grid zebra frame
@note: this function was added in version 2.1*/
void setGridFrameFillColor1( const QColor& c );
/**Get first fill color for grid zebra frame
@note: this function was added in version 2.1*/
QColor gridFrameFillColor1() const;

/**Sets second fill color for grid zebra frame
@note: this function was added in version 2.1*/
void setGridFrameFillColor2( const QColor& c );
/**Get second fill color for grid zebra frame
@note: this function was added in version 2.1*/
QColor gridFrameFillColor2() const;

/** Returns the grid's blending mode
@note added in version 2.0*/
@@ -61,6 +61,9 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
mAnnotationFormatComboBox->insertItem( 1, tr( "DegreeMinute" ) );
mAnnotationFormatComboBox->insertItem( 2, tr( "DegreeMinuteSecond" ) );

mAnnotationFontColorButton->setColorDialogTitle( tr( "Select font color" ) );
mAnnotationFontColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );

insertAnnotationPositionEntries( mAnnotationPositionLeftComboBox );
insertAnnotationPositionEntries( mAnnotationPositionRightComboBox );
insertAnnotationPositionEntries( mAnnotationPositionTopComboBox );
@@ -74,9 +77,22 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QWidg
mFrameStyleComboBox->insertItem( 0, tr( "No frame" ) );
mFrameStyleComboBox->insertItem( 1, tr( "Zebra" ) );

mGridFramePenColorButton->setColorDialogTitle( tr( "Select grid frame color" ) );
mGridFramePenColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mGridFrameFill1ColorButton->setColorDialogTitle( tr( "Select grid frame fill color" ) );
mGridFrameFill1ColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
mGridFrameFill2ColorButton->setColorDialogTitle( tr( "Select grid frame fill color" ) );
mGridFrameFill2ColorButton->setColorDialogOptions( QColorDialog::ShowAlphaChannel );

//set initial state of frame style controls
toggleFrameControls( false );

connect( mGridCheckBox, SIGNAL( toggled( bool ) ),
mDrawAnnotationCheckableGroupBox, SLOT( setEnabled( bool ) ) );

connect( mFrameStyleComboBox, SIGNAL( currentIndexChanged( QString ) ),
this, SLOT( frameStyleChanged( QString ) ) );

if ( composerMap )
{
connect( composerMap, SIGNAL( itemChanged() ), this, SLOT( setGuiElementValues() ) );
@@ -339,14 +355,20 @@ void QgsComposerMapWidget::updateGuiElements()

//grid frame
mFrameWidthSpinBox->setValue( mComposerMap->gridFrameWidth() );
mGridFramePenSizeSpinBox->setValue( mComposerMap->gridFramePenSize() );
mGridFramePenColorButton->setColor( mComposerMap->gridFramePenColor() );
mGridFrameFill1ColorButton->setColor( mComposerMap->gridFrameFillColor1() );
mGridFrameFill2ColorButton->setColor( mComposerMap->gridFrameFillColor2() );
QgsComposerMap::GridFrameStyle gridFrameStyle = mComposerMap->gridFrameStyle();
if ( gridFrameStyle == QgsComposerMap::Zebra )
{
mFrameStyleComboBox->setCurrentIndex( mFrameStyleComboBox->findText( tr( "Zebra" ) ) );
toggleFrameControls( true );
}
else //NoGridFrame
{
mFrameStyleComboBox->setCurrentIndex( mFrameStyleComboBox->findText( tr( "No frame" ) ) );
toggleFrameControls( false );
}

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

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

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

@@ -454,6 +474,10 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mDrawCanvasItemsCheckBox->blockSignals( b );
mFrameStyleComboBox->blockSignals( b );
mFrameWidthSpinBox->blockSignals( b );
mGridFramePenSizeSpinBox->blockSignals( b );
mGridFramePenColorButton->blockSignals( b );
mGridFrameFill1ColorButton->blockSignals( b );
mGridFrameFill2ColorButton->blockSignals( b );
mOverviewFrameMapComboBox->blockSignals( b );
mOverviewFrameStyleButton->blockSignals( b );
mOverviewBlendModeComboBox->blockSignals( b );
@@ -880,8 +904,23 @@ void QgsComposerMapWidget::on_mCoordinatePrecisionSpinBox_valueChanged( int valu
mComposerMap->endCommand();
}

void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled )
{
//set status of frame controls
mFrameWidthSpinBox->setEnabled( frameEnabled );
mGridFramePenSizeSpinBox->setEnabled( frameEnabled );
mGridFramePenColorButton->setEnabled( frameEnabled );
mGridFrameFill1ColorButton->setEnabled( frameEnabled );
mGridFrameFill2ColorButton->setEnabled( frameEnabled );
mFrameWidthLabel->setEnabled( frameEnabled );
mFramePenLabel->setEnabled( frameEnabled );
mFrameFillLabel->setEnabled( frameEnabled );
}

void QgsComposerMapWidget::on_mFrameStyleComboBox_currentIndexChanged( const QString& text )
{
toggleFrameControls( text != tr( "No frame" ) );

if ( !mComposerMap )
{
return;
@@ -913,6 +952,54 @@ void QgsComposerMapWidget::on_mFrameWidthSpinBox_valueChanged( double d )
}
}

void QgsComposerMapWidget::on_mGridFramePenSizeSpinBox_valueChanged( double d )
{
if ( mComposerMap )
{
mComposerMap->beginCommand( tr( "Changed grid frame line thickness" ) );
mComposerMap->setGridFramePenSize( d );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}
}

void QgsComposerMapWidget::on_mGridFramePenColorButton_colorChanged( const QColor& newColor )
{
if ( !mComposerMap )
{
return;
}
mComposerMap->beginCommand( tr( "Grid frame color changed" ) );
mComposerMap->setGridFramePenColor( newColor );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridFrameFill1ColorButton_colorChanged( const QColor& newColor )
{
if ( !mComposerMap )
{
return;
}
mComposerMap->beginCommand( tr( "Grid frame first fill color changed" ) );
mComposerMap->setGridFrameFillColor1( newColor );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridFrameFill2ColorButton_colorChanged( const QColor& newColor )
{
if ( !mComposerMap )
{
return;
}
mComposerMap->beginCommand( tr( "Grid frame second fill color changed" ) );
mComposerMap->setGridFrameFillColor2( newColor );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::showEvent( QShowEvent * event )
{
refreshMapComboBox();
@@ -85,6 +85,10 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase

void on_mFrameStyleComboBox_currentIndexChanged( const QString& text );
void on_mFrameWidthSpinBox_valueChanged( double d );
void on_mGridFramePenSizeSpinBox_valueChanged( double d );
void on_mGridFramePenColorButton_colorChanged( const QColor& newColor );
void on_mGridFrameFill1ColorButton_colorChanged( const QColor& newColor );
void on_mGridFrameFill2ColorButton_colorChanged( const QColor& newColor );

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

/**Updates the map combo box with the current composer map ids*/
void refreshMapComboBox();

/**Enables/disables grid frame related controls*/
void toggleFrameControls( bool frameEnabled );
};

#endif
@@ -49,6 +49,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ),
mGridFramePenThickness( 0.5 ), mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
{
mComposition = composition;
@@ -105,8 +106,9 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
mLeftGridAnnotationPosition( OutsideMapFrame ), mRightGridAnnotationPosition( OutsideMapFrame ),
mTopGridAnnotationPosition( OutsideMapFrame ), mBottomGridAnnotationPosition( OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ),
mLeftGridAnnotationDirection( Horizontal ), mRightGridAnnotationDirection( Horizontal ), mTopGridAnnotationDirection( Horizontal ),
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ),
mMapCanvas( 0 ), mDrawCanvasItems( true )
mBottomGridAnnotationDirection( Horizontal ), mGridFrameStyle( NoGridFrame ), mGridFrameWidth( 2.0 ), mGridFramePenThickness( 0.5 ),
mGridFramePenColor( QColor( 0, 0, 0 ) ), mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ),
mCrossLength( 3 ), mMapCanvas( 0 ), mDrawCanvasItems( true )
{
mOverviewFrameMapSymbol = 0;
mGridLineSymbol = 0;
@@ -865,6 +867,28 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
gridElem.setAttribute( "crossLength", qgsDoubleToString( mCrossLength ) );
gridElem.setAttribute( "gridFrameStyle", mGridFrameStyle );
gridElem.setAttribute( "gridFrameWidth", qgsDoubleToString( mGridFrameWidth ) );
gridElem.setAttribute( "gridFramePenThickness", qgsDoubleToString( mGridFramePenThickness ) );
//grid frame pen color
QDomElement framePenColorElem = doc.createElement( "framePenColor" );
framePenColorElem.setAttribute( "red", mGridFramePenColor.red() );
framePenColorElem.setAttribute( "green", mGridFramePenColor.green() );
framePenColorElem.setAttribute( "blue", mGridFramePenColor.blue() );
framePenColorElem.setAttribute( "alpha", mGridFramePenColor.alpha() );
gridElem.appendChild( framePenColorElem );
//grid frame fill colors
QDomElement frameFillColor1Elem = doc.createElement( "frameFillColor1" );
frameFillColor1Elem.setAttribute( "red", mGridFrameFillColor1.red() );
frameFillColor1Elem.setAttribute( "green", mGridFrameFillColor1.green() );
frameFillColor1Elem.setAttribute( "blue", mGridFrameFillColor1.blue() );
frameFillColor1Elem.setAttribute( "alpha", mGridFrameFillColor1.alpha() );
gridElem.appendChild( frameFillColor1Elem );
QDomElement frameFillColor2Elem = doc.createElement( "frameFillColor2" );
frameFillColor2Elem.setAttribute( "red", mGridFrameFillColor2.red() );
frameFillColor2Elem.setAttribute( "green", mGridFrameFillColor2.green() );
frameFillColor2Elem.setAttribute( "blue", mGridFrameFillColor2.blue() );
frameFillColor2Elem.setAttribute( "alpha", mGridFrameFillColor2.alpha() );
gridElem.appendChild( frameFillColor2Elem );

gridElem.setAttribute( "gridBlendMode", QgsMapRenderer::getBlendModeEnum( mGridBlendMode ) );
QDomElement gridLineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mGridLineSymbol, doc );
gridElem.appendChild( gridLineStyleElem );
@@ -889,6 +913,7 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
annotationFontColorElem.setAttribute( "red", mGridAnnotationFontColor.red() );
annotationFontColorElem.setAttribute( "green", mGridAnnotationFontColor.green() );
annotationFontColorElem.setAttribute( "blue", mGridAnnotationFontColor.blue() );
annotationFontColorElem.setAttribute( "alpha", mGridAnnotationFontColor.alpha() );
annotationElem.appendChild( annotationFontColorElem );

gridElem.appendChild( annotationElem );
@@ -1027,6 +1052,54 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mCrossLength = gridElem.attribute( "crossLength", "3" ).toDouble();
mGridFrameStyle = ( QgsComposerMap::GridFrameStyle )gridElem.attribute( "gridFrameStyle", "0" ).toInt();
mGridFrameWidth = gridElem.attribute( "gridFrameWidth", "2.0" ).toDouble();
mGridFramePenThickness = gridElem.attribute( "gridFramePenThickness", "0.5" ).toDouble();

//grid frame pen color
QDomNodeList gridFramePenColorList = gridElem.elementsByTagName( "framePenColor" );
if ( gridFramePenColorList.size() > 0 )
{
QDomElement penColorElem = gridFramePenColorList.at( 0 ).toElement();
int red = penColorElem.attribute( "red", "0" ).toInt();
int green = penColorElem.attribute( "green", "0" ).toInt();
int blue = penColorElem.attribute( "blue", "0" ).toInt();
int alpha = penColorElem.attribute( "alpha", "255" ).toInt();
mGridFramePenColor = QColor( red, green, blue, alpha );
}
else
{
mGridFramePenColor = QColor( 0, 0, 0 );
}
//grid frame fill color 1
QDomNodeList gridFrameFillColor1List = gridElem.elementsByTagName( "frameFillColor1" );
if ( gridFrameFillColor1List.size() > 0 )
{
QDomElement fillColorElem = gridFrameFillColor1List.at( 0 ).toElement();
int red = fillColorElem.attribute( "red", "0" ).toInt();
int green = fillColorElem.attribute( "green", "0" ).toInt();
int blue = fillColorElem.attribute( "blue", "0" ).toInt();
int alpha = fillColorElem.attribute( "alpha", "255" ).toInt();
mGridFrameFillColor1 = QColor( red, green, blue, alpha );
}
else
{
mGridFrameFillColor1 = Qt::white;
}
//grid frame fill color 2
QDomNodeList gridFrameFillColor2List = gridElem.elementsByTagName( "frameFillColor2" );
if ( gridFrameFillColor2List.size() > 0 )
{
QDomElement fillColorElem = gridFrameFillColor2List.at( 0 ).toElement();
int red = fillColorElem.attribute( "red", "0" ).toInt();
int green = fillColorElem.attribute( "green", "0" ).toInt();
int blue = fillColorElem.attribute( "blue", "0" ).toInt();
int alpha = fillColorElem.attribute( "alpha", "255" ).toInt();
mGridFrameFillColor2 = QColor( red, green, blue, alpha );
}
else
{
mGridFrameFillColor2 = Qt::black;
}

setGridBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) gridElem.attribute( "gridBlendMode", "0" ).toUInt() ) );

QDomElement gridSymbolElem = gridElem.firstChildElement( "symbol" );
@@ -1070,7 +1143,8 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
int red = fontColorElem.attribute( "red", "0" ).toInt();
int green = fontColorElem.attribute( "green", "0" ).toInt();
int blue = fontColorElem.attribute( "blue", "0" ).toInt();
mGridAnnotationFontColor = QColor( red, green, blue );
int alpha = fontColorElem.attribute( "alpha", "255" ).toInt();
mGridAnnotationFontColor = QColor( red, green, blue, alpha );
}
else
{
@@ -1268,7 +1342,7 @@ void QgsComposerMap::drawGridLine( const QLineF& line, QPainter* p )
void QgsComposerMap::drawGridFrameBorder( QPainter* p, const QMap< double, double >& borderPos, Border border )
{
double currentCoord = - mGridFrameWidth;
bool white = true;
bool color1 = true;
double x = 0;
double y = 0;
double width = 0;
@@ -1287,10 +1361,15 @@ void QgsComposerMap::drawGridFrameBorder( QPainter* p, const QMap< double, doubl
pos.insert( rect().width() + mGridFrameWidth, rect().width() + mGridFrameWidth );
}

//set pen to current frame pen
QPen framePen = QPen( mGridFramePenColor );
framePen.setWidthF( mGridFramePenThickness );
p->setPen( framePen );

QMap< double, double >::const_iterator posIt = pos.constBegin();
for ( ; posIt != pos.constEnd(); ++posIt )
{
p->setBrush( QBrush( white ? Qt::white : Qt::black ) );
p->setBrush( QBrush( color1 ? mGridFrameFillColor1 : mGridFrameFillColor2 ) );
if ( border == Left || border == Right )
{
height = posIt.key() - currentCoord;
@@ -1307,7 +1386,7 @@ void QgsComposerMap::drawGridFrameBorder( QPainter* p, const QMap< double, doubl
}
p->drawRect( QRectF( x, y, width, height ) );
currentCoord = posIt.key();
white = !white;
color1 = !color1;
}
}

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

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

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

//grid frame
double gridFrameDist = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth;
double gridFrameDist = ( mGridFrameStyle == NoGridFrame ) ? 0 : mGridFrameWidth + ( mGridFramePenThickness / 2.0 );
return maxExtension + mAnnotationFrameDistance + gridFrameDist;
}

0 comments on commit aa3e40a

Please sign in to comment.
You can’t perform that action at this time.