Skip to content

Commit

Permalink
[composer] Add simple line border frame style for composer map
Browse files Browse the repository at this point in the history
grids (sponsored by NIWA, New Zealand)
  • Loading branch information
nyalldawson committed Sep 3, 2014
1 parent 1e113d6 commit 52c519e
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 20 deletions.
42 changes: 26 additions & 16 deletions src/app/composer/qgscomposermapwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ QgsComposerMapWidget::QgsComposerMapWidget( QgsComposerMap* composerMap ): QgsCo
mGridFrameFill2ColorButton->setShowNoColor( true );

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

if ( composerMap )
{
Expand Down Expand Up @@ -695,15 +695,15 @@ void QgsComposerMapWidget::blockAllSignals( bool b )
blockOverviewItemsSignals( b );
}

void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled, bool frameFillEnabled )
void QgsComposerMapWidget::toggleFrameControls( bool frameEnabled, bool frameFillEnabled, bool frameSizeEnabled )
{
//set status of frame controls
mFrameWidthSpinBox->setEnabled( frameEnabled );
mFrameWidthSpinBox->setEnabled( frameSizeEnabled );
mGridFramePenSizeSpinBox->setEnabled( frameEnabled );
mGridFramePenColorButton->setEnabled( frameEnabled );
mGridFrameFill1ColorButton->setEnabled( frameFillEnabled );
mGridFrameFill2ColorButton->setEnabled( frameFillEnabled );
mFrameWidthLabel->setEnabled( frameEnabled );
mFrameWidthLabel->setEnabled( frameSizeEnabled );
mFramePenLabel->setEnabled( frameEnabled );
mFrameFillLabel->setEnabled( frameFillEnabled );
mCheckGridLeftSide->setEnabled( frameEnabled );
Expand Down Expand Up @@ -836,10 +836,11 @@ void QgsComposerMapWidget::handleChangedAnnotationDirection( QgsComposerMap::Bor
{
grid->setGridAnnotationDirection( QgsComposerMap::Horizontal, border );
}
else //Vertical
else if ( text == tr( "Vertical" ) )
{
grid->setGridAnnotationDirection( QgsComposerMap::Vertical, border );
}

mComposerMap->updateBoundingRect();
mComposerMap->update();
mComposerMap->endCommand();
Expand Down Expand Up @@ -877,7 +878,7 @@ void QgsComposerMapWidget::initAnnotationDirectionBox( QComboBox* c, QgsComposer
{
c->setCurrentIndex( c->findText( tr( "Vertical" ) ) );
}
else //horizontal
else if ( dir == QgsComposerMap::Horizontal )
{
c->setCurrentIndex( c->findText( tr( "Horizontal" ) ) );
}
Expand Down Expand Up @@ -1214,23 +1215,27 @@ void QgsComposerMapWidget::setGridItems( const QgsComposerMapGrid* grid )
{
case QgsComposerMap::Zebra:
mFrameStyleComboBox->setCurrentIndex( 1 );
toggleFrameControls( true, true );
toggleFrameControls( true, true, true );
break;
case QgsComposerMap::InteriorTicks:
mFrameStyleComboBox->setCurrentIndex( 2 );
toggleFrameControls( true, false );
toggleFrameControls( true, false, true );
break;
case QgsComposerMap::ExteriorTicks:
mFrameStyleComboBox->setCurrentIndex( 3 );
toggleFrameControls( true, false );
toggleFrameControls( true, false, true );
break;
case QgsComposerMap::InteriorExteriorTicks:
mFrameStyleComboBox->setCurrentIndex( 4 );
toggleFrameControls( true, false );
toggleFrameControls( true, false, true );
break;
case QgsComposerMap::LineBorder:
mFrameStyleComboBox->setCurrentIndex( 5 );
toggleFrameControls( true, false, false );
break;
default:
mFrameStyleComboBox->setCurrentIndex( 0 );
toggleFrameControls( false, false );
toggleFrameControls( false, false, false );
break;
}

Expand Down Expand Up @@ -1571,27 +1576,32 @@ void QgsComposerMapWidget::on_mFrameStyleComboBox_currentIndexChanged( const QSt
if ( text == tr( "Zebra" ) )
{
grid->setGridFrameStyle( QgsComposerMap::Zebra );
toggleFrameControls( true, true );
toggleFrameControls( true, true, true );
}
else if ( text == tr( "Interior ticks" ) )
{
grid->setGridFrameStyle( QgsComposerMap::InteriorTicks );
toggleFrameControls( true, false );
toggleFrameControls( true, false, true );
}
else if ( text == tr( "Exterior ticks" ) )
{
grid->setGridFrameStyle( QgsComposerMap::ExteriorTicks );
toggleFrameControls( true, false );
toggleFrameControls( true, false, true );
}
else if ( text == tr( "Interior and exterior ticks" ) )
{
grid->setGridFrameStyle( QgsComposerMap::InteriorExteriorTicks );
toggleFrameControls( true, false );
toggleFrameControls( true, false, true );
}
else if ( text == tr( "Line border" ) )
{
grid->setGridFrameStyle( QgsComposerMap::LineBorder );
toggleFrameControls( true, false, false );
}
else //no frame
{
grid->setGridFrameStyle( QgsComposerMap::NoGridFrame );
toggleFrameControls( false, false );
toggleFrameControls( false, false, false );
}
mComposerMap->updateBoundingRect();
mComposerMap->update();
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposermapwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class QgsComposerMapWidget: public QgsComposerItemBaseWidget, private Ui::QgsCom
void refreshMapComboBox();

/**Enables/disables grid frame related controls*/
void toggleFrameControls( bool frameEnabled , bool frameFillEnabled );
void toggleFrameControls( bool frameEnabled , bool frameFillEnabled, bool frameSizeEnabled );

/**Enables or disables the atlas margin and predefined scales radio depending on the atlas coverage layer type*/
void toggleAtlasScalingOptionsByLayerType();
Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposermap.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
Zebra, // black/white pattern
InteriorTicks,
ExteriorTicks,
InteriorExteriorTicks
InteriorExteriorTicks,
LineBorder
};

/**Enum for different frame borders*/
Expand Down
39 changes: 37 additions & 2 deletions src/core/composer/qgscomposermapgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ void QgsComposerMapGrid::drawGridFrameBorder( QPainter* p, const QMap< double, d
drawGridFrameTicks( p, borderPos, border );
break;

case QgsComposerMap::LineBorder:
drawGridFrameLineBorder( p, border );
break;

case QgsComposerMap::NoGridFrame:
break;
}
Expand Down Expand Up @@ -728,6 +732,37 @@ void QgsComposerMapGrid::drawGridFrameTicks( QPainter* p, const QMap< double, do
}
}

void QgsComposerMapGrid::drawGridFrameLineBorder( QPainter* p, QgsComposerMap::Border border ) const
{
if ( !mComposerMap )
{
return;
}

//set pen to current frame pen
QPen framePen = QPen( mGridFramePenColor );
framePen.setWidthF( mGridFramePenThickness );
framePen.setCapStyle( Qt::SquareCap );
p->setBrush( Qt::NoBrush );
p->setPen( framePen );

switch ( border )
{
case QgsComposerMap::Left:
p->drawLine( QLineF( 0, 0, 0, mComposerMap->rect().height() ) );
break;
case QgsComposerMap::Right:
p->drawLine( QLineF( mComposerMap->rect().width(), 0, mComposerMap->rect().width(), mComposerMap->rect().height() ) );
break;
case QgsComposerMap::Top:
p->drawLine( QLineF( 0, 0, mComposerMap->rect().width(), 0 ) );
break;
case QgsComposerMap::Bottom:
p->drawLine( QLineF( 0, mComposerMap->rect().height(), mComposerMap->rect().width(), mComposerMap->rect().height() ) );
break;
}
}

void QgsComposerMapGrid::drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines ) const
{
if ( !p )
Expand Down Expand Up @@ -768,11 +803,11 @@ void QgsComposerMapGrid::drawCoordinateAnnotation( QPainter* p, const QPointF& p
int rotation = 0;

double gridFrameDistance = 0;
if ( mGridFrameStyle != QgsComposerMap::NoGridFrame )
if ( mGridFrameStyle != QgsComposerMap::NoGridFrame && mGridFrameStyle != QgsComposerMap::LineBorder )
{
gridFrameDistance = mGridFrameWidth;
}
if ( mGridFrameStyle == QgsComposerMap::Zebra )
if ( mGridFrameStyle == QgsComposerMap::Zebra || mGridFrameStyle == QgsComposerMap::LineBorder )
{
gridFrameDistance += ( mGridFramePenThickness / 2.0 );
}
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposermapgrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ class CORE_EXPORT QgsComposerMapGrid
void drawGridMarker( const QPointF &point, QgsRenderContext &context ) const;
void drawGridFrameZebraBorder( QPainter *p, const QMap<double, double> &borderPos, QgsComposerMap::Border border ) const;
void drawGridFrameTicks( QPainter *p, const QMap<double, double> &borderPos, QgsComposerMap::Border border ) const;
void drawGridFrameLineBorder( QPainter *p, QgsComposerMap::Border border ) const;
};

#endif // QGSCOMPOSERMAPGRID_H
5 changes: 5 additions & 0 deletions src/ui/qgscomposermapwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@
<string>Interior and exterior ticks</string>
</property>
</item>
<item>
<property name="text">
<string>Line border</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1" colspan="2">
Expand Down
54 changes: 54 additions & 0 deletions tests/src/core/testqgscomposermapgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class TestQgsComposerMapGrid: public QObject
void exteriorTicksAnnotated(); //test exterior tick mode with annotations
void interiorExteriorTicks(); //test interior & exterior tick mode
void interiorExteriorTicksAnnotated(); //test interior & exterior tick mode with annotations
void lineBorder(); //test line border frame mode
void lineBorderAnnotated(); //test line border frame with annotations

private:
QgsComposition* mComposition;
Expand Down Expand Up @@ -399,6 +401,58 @@ void TestQgsComposerMapGrid::interiorExteriorTicksAnnotated()
mComposerMap->setShowGridAnnotation( false );
}

void TestQgsComposerMapGrid::lineBorder()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );

mComposerMap->setGridFrameStyle( QgsComposerMap::LineBorder );
mComposerMap->setGridFrameWidth( 10 );
mComposerMap->setGridFramePenSize( 1 );
mComposerMap->setGridFramePenColor( Qt::black );
mComposerMap->setGridEnabled( true );
mComposerMap->setGridStyle( QgsComposerMap::FrameAnnotationsOnly );

QgsCompositionChecker checker( "composermap_lineborder", mComposition );
bool testResult = checker.testComposition( mReport, 0, 100 );
QVERIFY( testResult );

mComposerMap->setGridFrameStyle( QgsComposerMap::NoGridFrame );
}

void TestQgsComposerMapGrid::lineBorderAnnotated()
{
mComposerMap->setNewExtent( QgsRectangle( 781662.375, 3339523.125, 793062.375, 3345223.125 ) );

mComposerMap->setGridFrameStyle( QgsComposerMap::LineBorder );
mComposerMap->setGridFrameWidth( 10 );
mComposerMap->setGridFramePenSize( 1 );
mComposerMap->setGridFramePenColor( Qt::black );
mComposerMap->setGridEnabled( true );
mComposerMap->setGridStyle( QgsComposerMap::FrameAnnotationsOnly );
mComposerMap->setShowGridAnnotation( true );
mComposerMap->setAnnotationFontColor( Qt::black );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame, QgsComposerMap::Left );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame, QgsComposerMap::Right );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame, QgsComposerMap::Top );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::InsideMapFrame, QgsComposerMap::Bottom );

QgsCompositionChecker checker( "composermap_lineborder_annotated", mComposition );
bool testResult = checker.testComposition( mReport, 0, 100 );
QVERIFY( testResult );

mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Left );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Right );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Top );
mComposerMap->setGridAnnotationPosition( QgsComposerMap::OutsideMapFrame, QgsComposerMap::Bottom );

QgsCompositionChecker checker2( "composermap_lineborder_annotated2", mComposition );
bool testResult2 = checker2.testComposition( mReport, 0, 100 );
QVERIFY( testResult2 );

mComposerMap->setGridFrameStyle( QgsComposerMap::NoGridFrame );
mComposerMap->setShowGridAnnotation( false );
}



QTEST_MAIN( TestQgsComposerMapGrid )
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 52c519e

Please sign in to comment.