Skip to content
Permalink
Browse files

[FEATURE][composer] Add options for controlling which sides of

the map a grid frame is drawn (sponsored by NIWA, New Zealand)
  • Loading branch information
nyalldawson committed Sep 3, 2014
1 parent dc27e13 commit a433d4cdd7aec1bb7ad90066c5a56282431ad4a1
@@ -706,6 +706,10 @@ void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled )
mFrameWidthLabel->setEnabled( frameEnabled );
mFramePenLabel->setEnabled( frameEnabled );
mFrameFillLabel->setEnabled( frameEnabled );
mCheckGridLeftSide->setEnabled( frameEnabled );
mCheckGridRightSide->setEnabled( frameEnabled );
mCheckGridTopSide->setEnabled( frameEnabled );
mCheckGridBottomSide->setEnabled( frameEnabled );
}

void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()
@@ -1109,6 +1113,10 @@ void QgsComposerMapWidget::blockGridItemsSignals( bool block )
mGridFrameFill1ColorButton->blockSignals( block );
mGridFrameFill2ColorButton->blockSignals( block );
mGridBlendComboBox->blockSignals( block );
mCheckGridLeftSide->blockSignals( block );
mCheckGridRightSide->blockSignals( block );
mCheckGridTopSide->blockSignals( block );
mCheckGridBottomSide->blockSignals( block );

//grid annotation
mDrawAnnotationGroupBox->blockSignals( block );
@@ -1212,6 +1220,11 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
toggleFrameControls( false );
}

mCheckGridLeftSide->setChecked( grid->testGridFrameSideFlag( QgsComposerMapGrid::FrameLeft ) );
mCheckGridRightSide->setChecked( grid->testGridFrameSideFlag( QgsComposerMapGrid::FrameRight ) );
mCheckGridTopSide->setChecked( grid->testGridFrameSideFlag( QgsComposerMapGrid::FrameTop ) );
mCheckGridBottomSide->setChecked( grid->testGridFrameSideFlag( QgsComposerMapGrid::FrameBottom ) );

//line style
updateGridLineSymbolMarker( grid );
//marker style
@@ -1419,6 +1432,62 @@ void QgsComposerMapWidget::on_mFrameWidthSpinBox_valueChanged( double val )
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mCheckGridLeftSide_toggled( bool checked )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid )
{
return;
}

mComposerMap->beginCommand( tr( "Frame left side changed" ) );
grid->setGridFrameSideFlag( QgsComposerMapGrid::FrameLeft, checked );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mCheckGridRightSide_toggled( bool checked )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid )
{
return;
}

mComposerMap->beginCommand( tr( "Frame right side changed" ) );
grid->setGridFrameSideFlag( QgsComposerMapGrid::FrameRight, checked );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mCheckGridTopSide_toggled( bool checked )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid )
{
return;
}

mComposerMap->beginCommand( tr( "Frame top side changed" ) );
grid->setGridFrameSideFlag( QgsComposerMapGrid::FrameTop, checked );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mCheckGridBottomSide_toggled( bool checked )
{
QgsComposerMapGrid* grid = currentGrid();
if ( !grid )
{
return;
}

mComposerMap->beginCommand( tr( "Frame bottom side changed" ) );
grid->setGridFrameSideFlag( QgsComposerMapGrid::FrameBottom, checked );
mComposerMap->update();
mComposerMap->endCommand();
}

void QgsComposerMapWidget::on_mGridFramePenSizeSpinBox_valueChanged( double d )
{
QgsComposerMapGrid* grid = currentGrid();
@@ -92,6 +92,10 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
void on_mMapGridCRSButton_clicked();
void on_mMapGridUnitComboBox_currentIndexChanged( const QString& text );
void on_mGridBlendComboBox_currentIndexChanged( int index );
void on_mCheckGridLeftSide_toggled( bool checked );
void on_mCheckGridRightSide_toggled( bool checked );
void on_mCheckGridTopSide_toggled( bool checked );
void on_mCheckGridBottomSide_toggled( bool checked );

void on_mDrawAnnotationGroupBox_toggled( bool state );
//annotation position
@@ -55,6 +55,8 @@ QgsComposerMapGrid::QgsComposerMapGrid( const QString& name, QgsComposerMap* map
mBottomGridAnnotationDirection( QgsComposerMap::Horizontal ),
mGridAnnotationFormat( QgsComposerMap::Decimal ),
mGridFrameStyle( QgsComposerMap::NoGridFrame ),
mGridFrameSides( QgsComposerMapGrid::FrameLeft | QgsComposerMapGrid::FrameRight |
QgsComposerMapGrid::FrameTop | QgsComposerMapGrid::FrameBottom ),
mGridFrameWidth( 2.0 ),
mGridFramePenThickness( 0.5 ),
mGridFramePenColor( QColor( 0, 0, 0 ) ),
@@ -176,6 +178,7 @@ bool QgsComposerMapGrid::writeXML( QDomElement& elem, QDomDocument& doc ) const
mapGridElem.appendChild( markerStyleElem );

mapGridElem.setAttribute( "gridFrameStyle", mGridFrameStyle );
mapGridElem.setAttribute( "gridFrameSideFlags", mGridFrameSides );
mapGridElem.setAttribute( "gridFrameWidth", qgsDoubleToString( mGridFrameWidth ) );
mapGridElem.setAttribute( "gridFramePenThickness", qgsDoubleToString( mGridFramePenThickness ) );
mapGridElem.setAttribute( "gridFramePenColor", QgsSymbolLayerV2Utils::encodeColor( mGridFramePenColor ) );
@@ -227,6 +230,7 @@ bool QgsComposerMapGrid::readXML( const QDomElement& itemElem, const QDomDocumen
mGridOffsetY = itemElem.attribute( "offsetY", "0" ).toDouble();
mCrossLength = itemElem.attribute( "crossLength", "3" ).toDouble();
mGridFrameStyle = ( QgsComposerMap::GridFrameStyle )itemElem.attribute( "gridFrameStyle", "0" ).toInt();
mGridFrameSides = ( QgsComposerMapGrid::GridFrameSideFlags )itemElem.attribute( "gridFrameSideFlags", "15" ).toInt();
mGridFrameWidth = itemElem.attribute( "gridFrameWidth", "2.0" ).toDouble();
mGridFramePenThickness = itemElem.attribute( "gridFramePenThickness", "0.5" ).toDouble();
mGridFramePenColor = QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "gridFramePenColor", "0,0,0" ) );
@@ -531,11 +535,22 @@ void QgsComposerMapGrid::drawGridFrame( QPainter* p, const QList< QPair< double,

sortGridLinesOnBorders( hLines, vLines, leftGridFrame, rightGridFrame, topGridFrame, bottomGridFrame );

drawGridFrameBorder( p, leftGridFrame, QgsComposerMap::Left );
drawGridFrameBorder( p, rightGridFrame, QgsComposerMap::Right );
drawGridFrameBorder( p, topGridFrame, QgsComposerMap::Top );
drawGridFrameBorder( p, bottomGridFrame, QgsComposerMap::Bottom );

if ( testGridFrameSideFlag( QgsComposerMapGrid::FrameLeft ) )
{
drawGridFrameBorder( p, leftGridFrame, QgsComposerMap::Left );
}
if ( testGridFrameSideFlag( QgsComposerMapGrid::FrameRight ) )
{
drawGridFrameBorder( p, rightGridFrame, QgsComposerMap::Right );
}
if ( testGridFrameSideFlag( QgsComposerMapGrid::FrameTop ) )
{
drawGridFrameBorder( p, topGridFrame, QgsComposerMap::Top );
}
if ( testGridFrameSideFlag( QgsComposerMapGrid::FrameBottom ) )
{
drawGridFrameBorder( p, bottomGridFrame, QgsComposerMap::Bottom );
}
p->restore();
}

@@ -577,24 +592,40 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
return;
}

double currentCoord = - mGridFrameWidth;
QMap< double, double > pos = borderPos;

double currentCoord = 0;
if (( border == QgsComposerMap::Left || border == QgsComposerMap::Right ) && testGridFrameSideFlag( QgsComposerMapGrid::FrameTop ) )
{
currentCoord = - mGridFrameWidth;
pos.insert( 0, 0 );
}
else if (( border == QgsComposerMap::Top || border == QgsComposerMap::Bottom ) && testGridFrameSideFlag( QgsComposerMapGrid::FrameLeft ) )
{
currentCoord = - mGridFrameWidth;
pos.insert( 0, 0 );
}
bool color1 = true;
double x = 0;
double y = 0;
double width = 0;
double height = 0;

QMap< double, double > pos = borderPos;
pos.insert( 0, 0 );
if ( border == QgsComposerMap::Left || border == QgsComposerMap::Right )
{
pos.insert( mComposerMap->rect().height(), mComposerMap->rect().height() );
pos.insert( mComposerMap->rect().height() + mGridFrameWidth, mComposerMap->rect().height() + mGridFrameWidth );
if ( testGridFrameSideFlag( QgsComposerMapGrid::FrameBottom ) )
{
pos.insert( mComposerMap->rect().height() + mGridFrameWidth, mComposerMap->rect().height() + mGridFrameWidth );
}
}
else //top or bottom
else if ( border == QgsComposerMap::Top || border == QgsComposerMap::Bottom )
{
pos.insert( mComposerMap->rect().width(), mComposerMap->rect().width() );
pos.insert( mComposerMap->rect().width() + mGridFrameWidth, mComposerMap->rect().width() + mGridFrameWidth );
if ( testGridFrameSideFlag( QgsComposerMapGrid::FrameRight ) )
{
pos.insert( mComposerMap->rect().width() + mGridFrameWidth, mComposerMap->rect().width() + mGridFrameWidth );
}
}

//set pen to current frame pen
@@ -667,10 +698,14 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
double ypos = pos.y();
int rotation = 0;

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

if ( frameBorder == QgsComposerMap::Left )
{
if ( !testGridFrameSideFlag( QgsComposerMapGrid::FrameLeft ) )
{
gridFrameDistance = 0;
}

if ( mLeftGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
{
@@ -708,6 +743,11 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
}
else if ( frameBorder == QgsComposerMap::Right )
{
if ( !testGridFrameSideFlag( QgsComposerMapGrid::FrameRight ) )
{
gridFrameDistance = 0;
}

if ( mRightGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
{
if ( mRightGridAnnotationDirection == QgsComposerMap::Vertical || mRightGridAnnotationDirection == QgsComposerMap::BoundaryDirection )
@@ -743,6 +783,11 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
}
else if ( frameBorder == QgsComposerMap::Bottom )
{
if ( !testGridFrameSideFlag( QgsComposerMapGrid::FrameBottom ) )
{
gridFrameDistance = 0;
}

if ( mBottomGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
{
if ( mBottomGridAnnotationDirection == QgsComposerMap::Horizontal || mBottomGridAnnotationDirection == QgsComposerMap::BoundaryDirection )
@@ -778,6 +823,11 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
}
else //Top
{
if ( !testGridFrameSideFlag( QgsComposerMapGrid::FrameTop ) )
{
gridFrameDistance = 0;
}

if ( mTopGridAnnotationPosition == QgsComposerMap::InsideMapFrame )
{
if ( mTopGridAnnotationDirection == QgsComposerMap::Horizontal || mTopGridAnnotationDirection == QgsComposerMap::BoundaryDirection )
@@ -1317,6 +1367,29 @@ QgsComposerMap::GridAnnotationDirection QgsComposerMapGrid::gridAnnotationDirect
return mLeftGridAnnotationDirection;
}

void QgsComposerMapGrid::setGridFrameSideFlags( GridFrameSideFlags flags )
{
mGridFrameSides = flags;
}

void QgsComposerMapGrid::setGridFrameSideFlag( QgsComposerMapGrid::GridFrameSideFlag flag, bool on )
{
if ( on )
mGridFrameSides |= flag;
else
mGridFrameSides &= ~flag;
}

QgsComposerMapGrid::GridFrameSideFlags QgsComposerMapGrid::gridFrameSideFlags() const
{
return mGridFrameSides;
}

bool QgsComposerMapGrid::testGridFrameSideFlag( QgsComposerMapGrid::GridFrameSideFlag flag ) const
{
return mGridFrameSides.testFlag( flag );
}

void QgsComposerMapGrid::setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection d )
{
mLeftGridAnnotationDirection = d;
@@ -152,6 +152,21 @@ class CORE_EXPORT QgsComposerMapGrid
void setGridFrameStyle( QgsComposerMap::GridFrameStyle style ) { mGridFrameStyle = style; }
QgsComposerMap::GridFrameStyle gridFrameStyle() const { return mGridFrameStyle; }

//! Enumeration of flags that adjust which side of the map the frame is drawn on
enum GridFrameSideFlag
{
FrameLeft = 0x01,
FrameRight = 0x02,
FrameTop = 0x04,
FrameBottom = 0x08
};
Q_DECLARE_FLAGS( GridFrameSideFlags, GridFrameSideFlag )

void setGridFrameSideFlags( GridFrameSideFlags flags );
void setGridFrameSideFlag( GridFrameSideFlag flag, bool on = true );
GridFrameSideFlags gridFrameSideFlags() const;
bool testGridFrameSideFlag( GridFrameSideFlag flag ) const;

/**Set grid frame width
@note: this function was added in version 1.9*/
void setGridFrameWidth( double w ) { mGridFrameWidth = w; }
@@ -257,6 +272,7 @@ class CORE_EXPORT QgsComposerMapGrid
QgsComposerMap::GridAnnotationDirection mBottomGridAnnotationDirection;
QgsComposerMap::GridAnnotationFormat mGridAnnotationFormat;
QgsComposerMap::GridFrameStyle mGridFrameStyle;
GridFrameSideFlags mGridFrameSides;
double mGridFrameWidth;
double mGridFramePenThickness;
QColor mGridFramePenColor;

0 comments on commit a433d4c

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