Skip to content
Permalink
Browse files

Add frame pen width, color, fill color1, fill color2 to composergrid

  • Loading branch information
mhugent committed Jul 10, 2014
1 parent b626f94 commit 3e7644050aad2519c531cbdebb83b343b5bd7a4d
@@ -617,7 +617,7 @@ void QgsComposerMapWidget::updateGuiElements()
}

populateDataDefinedButtons();

loadGridEntries();
blockAllSignals( false );
}

@@ -721,6 +721,7 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
mAnnotationDirectionComboBoxBottom->blockSignals( b );
mDistanceToMapFrameSpinBox->blockSignals( b );
mCoordinatePrecisionSpinBox->blockSignals( b );
mGridBlendComboBox->blockSignals( b );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -1210,6 +1211,10 @@ void QgsComposerMapWidget::setGridItemsEnabled( bool enabled )
mFrameStyleComboBox->setEnabled( enabled );
mFrameWidthSpinBox->setEnabled( enabled );
mGridLineStyleButton->setEnabled( enabled );
mGridFramePenSizeSpinBox->setEnabled( enabled );
mGridFramePenColorButton->setEnabled( enabled );
mGridFrameFill1ColorButton->setEnabled( enabled );
mGridFrameFill2ColorButton->setEnabled( enabled );
}

void QgsComposerMapWidget::blockGridItemsSignals( bool block )
@@ -1227,6 +1232,10 @@ void QgsComposerMapWidget::blockGridItemsSignals( bool block )
mGridLineStyleButton->blockSignals( block );
mGridTypeComboBox->blockSignals( block );
mMapGridUnitComboBox->blockSignals( block );
mGridFramePenSizeSpinBox->blockSignals( block );
mGridFramePenColorButton->blockSignals( block );
mGridFrameFill1ColorButton->blockSignals( block );
mGridFrameFill2ColorButton->blockSignals( block );

//grid annotation
mDrawAnnotationGroupBox->blockSignals( block );
@@ -1258,6 +1267,10 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
mOffsetYSpinBox->setValue( grid->gridOffsetY() );
mCrossWidthSpinBox->setValue( grid->crossLength() );
mFrameWidthSpinBox->setValue( grid->gridFrameWidth() );
mGridFramePenSizeSpinBox->setValue( grid->gridFramePenSize() );
mGridFramePenColorButton->setColor( grid->gridFramePenColor() );
mGridFrameFill1ColorButton->setColor( grid->gridFrameFillColor1() );
mGridFrameFill2ColorButton->setColor( grid->gridFrameFillColor2() );

QgsComposerMap::GridStyle gridStyle = grid->gridStyle();
if ( gridStyle == QgsComposerMap::Cross )
@@ -1284,6 +1297,8 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
//line style
updateLineSymbolMarker( grid );

mGridBlendComboBox->setBlendMode( grid->blendMode() );

mDrawAnnotationGroupBox->setChecked( grid->showGridAnnotation() );
initAnnotationPositionBox( mAnnotationPositionLeftComboBox, grid->gridAnnotationPosition( QgsComposerMap::Left ) );
initAnnotationPositionBox( mAnnotationPositionRightComboBox, grid->gridAnnotationPosition( QgsComposerMap::Right ) );
@@ -1436,6 +1451,63 @@ void QgsComposerMapWidget::on_mFrameWidthSpinBox_valueChanged( double val )
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridFramePenSizeSpinBox_valueChanged( double d )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid || !mComposerMap )
{
return;
}

mComposerMap->beginCommand( tr( "Changed grid frame line thickness" ) );
grid->setGridFramePenSize( d );
mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridFramePenColorButton_colorChanged( const QColor& newColor )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid || !mComposerMap )
{
return;
}

mComposerMap->beginCommand( tr( "Grid frame color changed" ) );
grid->setGridFramePenColor( newColor );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridFrameFill1ColorButton_colorChanged( const QColor& newColor )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid || !mComposerMap )
{
return;
}

mComposerMap->beginCommand( tr( "Grid frame first fill color changed" ) );
grid->setGridFrameFillColor1( newColor );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridFrameFill2ColorButton_colorChanged( const QColor& newColor )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid || !mComposerMap )
{
return;
}

mComposerMap->beginCommand( tr( "Grid frame second fill color changed" ) );
grid->setGridFrameFillColor2( newColor );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mFrameStyleComboBox_currentIndexChanged( const QString& text )
{
QgsComposerMapGrid* grid = currentGrid();
@@ -1484,6 +1556,20 @@ void QgsComposerMapWidget::on_mMapGridUnitComboBox_currentIndexChanged( const QS
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridBlendComboBox_currentIndexChanged( int index )
{
Q_UNUSED( index );
QgsComposerMapGrid* grid = currentGrid();
if ( grid )
{
mComposerMap->beginCommand( tr( "Grid blend mode changed" ) );
grid->setBlendMode( mGridBlendComboBox->blendMode() );
mComposerMap->update();
mComposerMap->endCommand();
}

}

void QgsComposerMapWidget::on_mGridTypeComboBox_currentIndexChanged( const QString& text )
{
QgsComposerMapGrid* grid = currentGrid();
@@ -84,9 +84,14 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
void on_mCrossWidthSpinBox_valueChanged( double val );
void on_mFrameWidthSpinBox_valueChanged( double val );
void on_mFrameStyleComboBox_currentIndexChanged( const QString& text );
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 );
void on_mGridTypeComboBox_currentIndexChanged( const QString& text );
void on_mMapGridCRSButton_clicked();
void on_mMapGridUnitComboBox_currentIndexChanged( const QString& text );
void on_mGridBlendComboBox_currentIndexChanged( int index );

void on_mDrawAnnotationGroupBox_toggled( bool state );
//annotation position
@@ -33,7 +33,8 @@ QgsComposerMapGrid::QgsComposerMapGrid( const QString& name, QgsComposerMap* map
mLeftGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ), mRightGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ), mTopGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ),
mBottomGridAnnotationPosition( QgsComposerMap::OutsideMapFrame ), mAnnotationFrameDistance( 1.0 ), mLeftGridAnnotationDirection( QgsComposerMap::Horizontal ),
mRightGridAnnotationDirection( QgsComposerMap::Horizontal ), mTopGridAnnotationDirection( QgsComposerMap::Horizontal ), mBottomGridAnnotationDirection( QgsComposerMap::Horizontal ), mGridAnnotationFormat( QgsComposerMap::Decimal ),
mGridFrameStyle( QgsComposerMap::NoGridFrame ), mGridFrameWidth( 2.0 ), mCrossLength( 3 ), mGridLineSymbol( 0 ), mGridUnit( MapUnit )
mGridFrameStyle( QgsComposerMap::NoGridFrame ), mGridFrameWidth( 2.0 ), mGridFramePenThickness( 0.5 ), mGridFramePenColor( QColor( 0, 0, 0 ) )
, mGridFrameFillColor1( Qt::white ), mGridFrameFillColor2( Qt::black ), mCrossLength( 3 ), mGridLineSymbol( 0 ), mGridUnit( MapUnit ), mBlendMode( QPainter::CompositionMode_SourceOver )
{
//debug
mGridLineSymbol = QgsLineSymbolV2::createSimple( QgsStringMap() );
@@ -112,9 +113,13 @@ bool QgsComposerMapGrid::writeXML( QDomElement& elem, QDomDocument& doc ) const
mapGridElem.setAttribute( "offsetX", qgsDoubleToString( mGridOffsetX ) );
mapGridElem.setAttribute( "offsetY", qgsDoubleToString( mGridOffsetY ) );
mapGridElem.setAttribute( "crossLength", qgsDoubleToString( mCrossLength ) );
QDomElement gridLineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mGridLineSymbol, doc );
mapGridElem.setAttribute( "gridFrameStyle", mGridFrameStyle );
mapGridElem.setAttribute( "gridFrameWidth", qgsDoubleToString( mGridFrameWidth ) );
QDomElement gridLineStyleElem = QgsSymbolLayerV2Utils::saveSymbol( QString(), mGridLineSymbol, doc );
mapGridElem.setAttribute( "gridFramePenThickness", qgsDoubleToString( mGridFramePenThickness ) );
mapGridElem.setAttribute( "gridFramePenColor", QgsSymbolLayerV2Utils::encodeColor( mGridFramePenColor ) );
mapGridElem.setAttribute( "frameFillColor1", QgsSymbolLayerV2Utils::encodeColor( mGridFrameFillColor1 ) );
mapGridElem.setAttribute( "frameFillColor2", QgsSymbolLayerV2Utils::encodeColor( mGridFrameFillColor2 ) );
if ( mCRS.isValid() )
{
mCRS.writeXML( mapGridElem, doc );
@@ -136,6 +141,7 @@ bool QgsComposerMapGrid::writeXML( QDomElement& elem, QDomDocument& doc ) const
mapGridElem.setAttribute( "annotationFontColor", QgsSymbolLayerV2Utils::encodeColor( mGridAnnotationFontColor ) );
mapGridElem.setAttribute( "annotationPrecision", mGridAnnotationPrecision );
mapGridElem.setAttribute( "unit", mGridUnit );
mapGridElem.setAttribute( "blendMode", mBlendMode );

elem.appendChild( mapGridElem );
return true;
@@ -162,6 +168,10 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
mCrossLength = itemElem.attribute( "crossLength", "3" ).toDouble();
mGridFrameStyle = ( QgsComposerMap::GridFrameStyle )itemElem.attribute( "gridFrameStyle", "0" ).toInt();
mGridFrameWidth = itemElem.attribute( "gridFrameWidth", "2.0" ).toDouble();
mGridFramePenThickness = itemElem.attribute( "gridFramePenThickness", "0.5" ).toDouble();
mGridFramePenColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "gridFramePenColor", "0,0,0" ) );
mGridFrameFillColor1 = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "frameFillColor1", "255,255,255,255" ) );
mGridFrameFillColor2 = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "frameFillColor2", "0,0,0,255" ) );
QDomElement gridSymbolElem = itemElem.firstChildElement( "symbol" );
delete mGridLineSymbol;
if ( gridSymbolElem.isNull( ) )
@@ -187,6 +197,7 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
{
mCRS = QgsCoordinateReferenceSystem();
}
mBlendMode = ( QPainter::CompositionMode )( itemElem.attribute( "blendMode", "0" ).toUInt() );

//annotation
mShowGridAnnotation = ( itemElem.attribute( "showAnnotation", "0" ) != "0" );
@@ -222,9 +233,6 @@ void QgsComposerMapGrid::drawGridCRSTransform( QPainter* painter ) const
return;
}

painter->save();
painter->setRenderHint( QPainter::Antialiasing );

//x grid lines
QList< QPair< double, QPolygonF > > xGridLines;
xGridLinesCRSTransform( crsBoundingRect, inverseTr, xGridLines );
@@ -267,7 +275,6 @@ void QgsComposerMapGrid::drawGridCRSTransform( QPainter* painter ) const
{
drawCoordinateAnnotations( painter, horizontalLines, verticalLines );
}
painter->restore();
}

void QgsComposerMapGrid::drawGrid( QPainter* p ) const
@@ -277,6 +284,10 @@ void QgsComposerMapGrid::drawGrid( QPainter* p ) const
return;
}

p->save();
p->setCompositionMode( mBlendMode );
p->setRenderHint( QPainter::Antialiasing );

//is grid in a different crs than map
const QgsMapSettings& ms = mComposerMap->composition()->mapSettings();
if ( mGridUnit == MapUnit && mCRS.isValid() && mCRS != ms.destinationCrs() )
@@ -359,6 +370,8 @@ void QgsComposerMapGrid::drawGrid( QPainter* p ) const
{
drawCoordinateAnnotations( p, horizontalLines, verticalLines );
}

p->restore();
}

void QgsComposerMapGrid::drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ) const
@@ -417,7 +430,7 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
}

double currentCoord = - mGridFrameWidth;
bool white = true;
bool color1 = true;
double x = 0;
double y = 0;
double width = 0;
@@ -436,10 +449,16 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
pos.insert( mComposerMap->rect().width() + mGridFrameWidth, mComposerMap->rect().width() + mGridFrameWidth );
}

//set pen to current frame pen
QPen framePen = QPen( mGridFramePenColor );
framePen.setWidthF( mGridFramePenThickness );
framePen.setJoinStyle( Qt::MiterJoin );
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 == QgsComposerMap::Left || border == QgsComposerMap::Right )
{
height = posIt.key() - currentCoord;
@@ -456,7 +475,7 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
}
p->drawRect( QRectF( x, y, width, height ) );
currentCoord = posIt.key();
white = !white;
color1 = !color1;
}
}

@@ -159,6 +159,32 @@ class CORE_EXPORT QgsComposerMapGrid
void setGridFrameWidth( double w ) { mGridFrameWidth = w; }
double gridFrameWidth() const { return mGridFrameWidth; }

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

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

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

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

/**Sets length of the cros segments (if grid style is cross)
@note this function was added in version 1.4*/
void setCrossLength( double l ) {mCrossLength = l;}
@@ -174,6 +200,9 @@ class CORE_EXPORT QgsComposerMapGrid
void setGridUnit( GridUnit u ) { mGridUnit = u; }
GridUnit gridUnit() const { return mGridUnit; }

void setBlendMode( QPainter::CompositionMode mode ) { mBlendMode = mode; }
QPainter::CompositionMode blendMode() const { return mBlendMode; }

double maxExtension() const;

private:
@@ -227,6 +256,10 @@ class CORE_EXPORT QgsComposerMapGrid
QgsComposerMap::GridAnnotationFormat mGridAnnotationFormat;
QgsComposerMap::GridFrameStyle mGridFrameStyle;
double mGridFrameWidth;
double mGridFramePenThickness;
QColor mGridFramePenColor;
QColor mGridFrameFillColor1;
QColor mGridFrameFillColor2;
double mCrossLength;

QgsLineSymbolV2* mGridLineSymbol;
@@ -235,6 +268,8 @@ class CORE_EXPORT QgsComposerMapGrid

GridUnit mGridUnit;

QPainter::CompositionMode mBlendMode;

/**Draws the map grid*/
void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ) const;
/**Draw coordinates for mGridAnnotationType Coordinate

0 comments on commit 3e76440

Please sign in to comment.