Skip to content
Permalink
Browse files

[FEATURE][layouts] Don't draw diagonals on line border grid style when a

margin is set

Instead, split this behaviour off into a new "Line border (Nautical)"
grid style. It's a very specific type of effect and won't always
be desirable when using margins with the line border style.
  • Loading branch information
nyalldawson committed Dec 6, 2018
1 parent 3838ef3 commit 11258c05b040706872f8d7d84b33aba8d77e99d5
@@ -202,7 +202,8 @@ An individual grid which is drawn above the map content in a
InteriorTicks,
ExteriorTicks,
InteriorExteriorTicks,
LineBorder
LineBorder,
LineBorderNautical
};

enum FrameSideFlag
@@ -34,14 +34,25 @@ QgsLayoutMapGridWidget::QgsLayoutMapGridWidget( QgsLayoutItemMapGrid *mapGrid, Q
, mMapGrid( mapGrid )
{
setupUi( this );

mFrameStyleComboBox->addItem( tr( "No Frame" ), QgsLayoutItemMapGrid::NoFrame );
mFrameStyleComboBox->addItem( tr( "Zebra" ), QgsLayoutItemMapGrid::Zebra );
mFrameStyleComboBox->addItem( tr( "Interior Ticks" ), QgsLayoutItemMapGrid::InteriorTicks );
mFrameStyleComboBox->addItem( tr( "Exterior Ticks" ), QgsLayoutItemMapGrid::ExteriorTicks );
mFrameStyleComboBox->addItem( tr( "Interior and Exterior Ticks" ), QgsLayoutItemMapGrid::InteriorExteriorTicks );
mFrameStyleComboBox->addItem( tr( "Line Border" ), QgsLayoutItemMapGrid::LineBorder );
mFrameStyleComboBox->addItem( tr( "Line Border (Nautical)" ), QgsLayoutItemMapGrid::LineBorderNautical );

mGridFrameMarginSpinBox->setClearValue( 0 );

connect( mIntervalXSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsLayoutMapGridWidget::mIntervalXSpinBox_editingFinished );
connect( mIntervalYSpinBox, &QgsDoubleSpinBox::editingFinished, this, &QgsLayoutMapGridWidget::mIntervalYSpinBox_editingFinished );
connect( mOffsetXSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mOffsetXSpinBox_valueChanged );
connect( mOffsetYSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mOffsetYSpinBox_valueChanged );
connect( mCrossWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mCrossWidthSpinBox_valueChanged );
connect( mFrameWidthSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mFrameWidthSpinBox_valueChanged );
connect( mGridFrameMarginSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mGridFrameMarginSpinBox_valueChanged );
connect( mFrameStyleComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged );
connect( mFrameStyleComboBox, static_cast<void ( QComboBox::* )( int )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged );
connect( mGridFramePenSizeSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutMapGridWidget::mGridFramePenSizeSpinBox_valueChanged );
connect( mGridFramePenColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFramePenColorButton_colorChanged );
connect( mGridFrameFill1ColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutMapGridWidget::mGridFrameFill1ColorButton_colorChanged );
@@ -522,30 +533,22 @@ void QgsLayoutMapGridWidget::setGridItems()
mFrameWidthSpinBox->setValue( mMapGrid->frameWidth() );
mGridFrameMarginSpinBox->setValue( mMapGrid->gridFrameMargin() );
QgsLayoutItemMapGrid::FrameStyle gridFrameStyle = mMapGrid->frameStyle();
mFrameStyleComboBox->setCurrentIndex( mFrameStyleComboBox->findData( gridFrameStyle ) );
switch ( gridFrameStyle )
{
case QgsLayoutItemMapGrid::Zebra:
mFrameStyleComboBox->setCurrentIndex( 1 );
toggleFrameControls( true, true, true );
break;
case QgsLayoutItemMapGrid::InteriorTicks:
mFrameStyleComboBox->setCurrentIndex( 2 );
toggleFrameControls( true, false, true );
break;
case QgsLayoutItemMapGrid::ExteriorTicks:
mFrameStyleComboBox->setCurrentIndex( 3 );
toggleFrameControls( true, false, true );
break;
case QgsLayoutItemMapGrid::InteriorExteriorTicks:
mFrameStyleComboBox->setCurrentIndex( 4 );
toggleFrameControls( true, false, true );
break;
case QgsLayoutItemMapGrid::LineBorder:
mFrameStyleComboBox->setCurrentIndex( 5 );
case QgsLayoutItemMapGrid::LineBorderNautical:
toggleFrameControls( true, false, false );
break;
default:
mFrameStyleComboBox->setCurrentIndex( 0 );
case QgsLayoutItemMapGrid::NoFrame:
toggleFrameControls( false, false, false );
break;
}
@@ -838,43 +841,33 @@ void QgsLayoutMapGridWidget::mGridFrameFill2ColorButton_colorChanged( const QCol
mMap->endCommand();
}

void QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged( const QString &text )
void QgsLayoutMapGridWidget::mFrameStyleComboBox_currentIndexChanged( int )
{
if ( !mMapGrid || !mMap )
{
return;
}

QgsLayoutItemMapGrid::FrameStyle style = static_cast< QgsLayoutItemMapGrid::FrameStyle >( mFrameStyleComboBox->currentData().toInt() );
mMap->beginCommand( tr( "Change Frame Style" ) );
if ( text == tr( "Zebra" ) )
{
mMapGrid->setFrameStyle( QgsLayoutItemMapGrid::Zebra );
toggleFrameControls( true, true, true );
}
else if ( text == tr( "Interior ticks" ) )
{
mMapGrid->setFrameStyle( QgsLayoutItemMapGrid::InteriorTicks );
toggleFrameControls( true, false, true );
}
else if ( text == tr( "Exterior ticks" ) )
{
mMapGrid->setFrameStyle( QgsLayoutItemMapGrid::ExteriorTicks );
toggleFrameControls( true, false, true );
}
else if ( text == tr( "Interior and exterior ticks" ) )
{
mMapGrid->setFrameStyle( QgsLayoutItemMapGrid::InteriorExteriorTicks );
toggleFrameControls( true, false, true );
}
else if ( text == tr( "Line border" ) )
mMapGrid->setFrameStyle( style );
switch ( style )
{
mMapGrid->setFrameStyle( QgsLayoutItemMapGrid::LineBorder );
toggleFrameControls( true, false, false );
}
else //no frame
{
mMapGrid->setFrameStyle( QgsLayoutItemMapGrid::NoFrame );
toggleFrameControls( false, false, false );
case QgsLayoutItemMapGrid::Zebra:
toggleFrameControls( true, true, true );
break;
case QgsLayoutItemMapGrid::InteriorTicks:
case QgsLayoutItemMapGrid::ExteriorTicks:
case QgsLayoutItemMapGrid::InteriorExteriorTicks:
toggleFrameControls( true, false, true );
break;
case QgsLayoutItemMapGrid::LineBorder:
case QgsLayoutItemMapGrid::LineBorderNautical:
toggleFrameControls( true, false, false );
break;
case QgsLayoutItemMapGrid::NoFrame:
toggleFrameControls( false, false, false );
break;
}
mMap->updateBoundingRect();
mMap->update();
@@ -43,7 +43,7 @@ class QgsLayoutMapGridWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLay
void mCrossWidthSpinBox_valueChanged( double val );
void mFrameWidthSpinBox_valueChanged( double val );
void mGridFrameMarginSpinBox_valueChanged( double val );
void mFrameStyleComboBox_currentIndexChanged( const QString &text );
void mFrameStyleComboBox_currentIndexChanged( int );
void mGridFramePenSizeSpinBox_valueChanged( double d );
void mGridFramePenColorButton_colorChanged( const QColor &newColor );
void mGridFrameFill1ColorButton_colorChanged( const QColor &newColor );
@@ -784,6 +784,7 @@ void QgsLayoutItemMapGrid::drawGridFrameBorder( QPainter *p, const QMap< double,
break;

case QgsLayoutItemMapGrid::LineBorder:
case QgsLayoutItemMapGrid::LineBorderNautical:
drawGridFrameLineBorder( p, border, extension );
break;

@@ -972,12 +973,14 @@ void QgsLayoutItemMapGrid::drawGridFrameLineBorder( QPainter *p, QgsLayoutItemMa
p->setBrush( Qt::NoBrush );
p->setPen( framePen );

const bool drawDiagonals = mGridFrameStyle == LineBorderNautical && !qgsDoubleNear( mGridFrameMargin, 0.0 );

switch ( border )
{
case QgsLayoutItemMapGrid::Left:
p->drawLine( QLineF( 0 - mGridFrameMargin, 0 - mGridFrameMargin, 0 - mGridFrameMargin, mMap->rect().height() + mGridFrameMargin ) );
//corner left-top
if ( !qgsDoubleNear( mGridFrameMargin, 0.0 ) )
if ( drawDiagonals )
{
const double X1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0;
const double Y1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0;
@@ -987,7 +990,7 @@ void QgsLayoutItemMapGrid::drawGridFrameLineBorder( QPainter *p, QgsLayoutItemMa
case QgsLayoutItemMapGrid::Right:
p->drawLine( QLineF( mMap->rect().width() + mGridFrameMargin, 0 - mGridFrameMargin, mMap->rect().width() + mGridFrameMargin, mMap->rect().height() + mGridFrameMargin ) );
//corner right-bottom
if ( !qgsDoubleNear( mGridFrameMargin, 0.0 ) )
if ( drawDiagonals )
{
const double X1 = mMap->rect().width() + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
const double Y1 = mMap->rect().height() + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
@@ -997,7 +1000,7 @@ void QgsLayoutItemMapGrid::drawGridFrameLineBorder( QPainter *p, QgsLayoutItemMa
case QgsLayoutItemMapGrid::Top:
p->drawLine( QLineF( 0 - mGridFrameMargin, 0 - mGridFrameMargin, mMap->rect().width() + mGridFrameMargin, 0 - mGridFrameMargin ) );
//corner right-top
if ( !qgsDoubleNear( mGridFrameMargin, 0.0 ) )
if ( drawDiagonals )
{
const double X1 = mMap->rect().width() + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
const double Y1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0 ;
@@ -1007,7 +1010,7 @@ void QgsLayoutItemMapGrid::drawGridFrameLineBorder( QPainter *p, QgsLayoutItemMa
case QgsLayoutItemMapGrid::Bottom:
p->drawLine( QLineF( 0 - mGridFrameMargin, mMap->rect().height() + mGridFrameMargin, mMap->rect().width() + mGridFrameMargin, mMap->rect().height() + mGridFrameMargin ) );
//corner left-bottom
if ( !qgsDoubleNear( mGridFrameMargin, 0.0 ) )
if ( drawDiagonals )
{
const double X1 = 0 - mGridFrameMargin + mGridFramePenThickness / 2.0 ;
const double Y1 = mMap->rect().height() + mGridFrameMargin - mGridFramePenThickness / 2.0 ;
@@ -1055,13 +1058,22 @@ void QgsLayoutItemMapGrid::drawCoordinateAnnotation( QPainter *p, QPointF pos, c
int rotation = 0;

double gridFrameDistance = 0;
if ( mGridFrameStyle != QgsLayoutItemMapGrid::NoFrame && mGridFrameStyle != QgsLayoutItemMapGrid::LineBorder )
{
gridFrameDistance = mGridFrameWidth;
}
if ( mGridFrameStyle == QgsLayoutItemMapGrid::Zebra || mGridFrameStyle == QgsLayoutItemMapGrid::LineBorder )
switch ( mGridFrameStyle )
{
gridFrameDistance += ( mGridFramePenThickness / 2.0 );
case InteriorTicks:
case ExteriorTicks:
case InteriorExteriorTicks:
gridFrameDistance = mGridFrameWidth;
break;

case QgsLayoutItemMapGrid::Zebra:
case QgsLayoutItemMapGrid::LineBorder:
case QgsLayoutItemMapGrid::LineBorderNautical:
gridFrameDistance += ( mGridFramePenThickness / 2.0 );
break;

case QgsLayoutItemMapGrid::NoFrame:
break;
}

if ( frameBorder == QgsLayoutItemMapGrid::Left )
@@ -232,7 +232,8 @@ class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
InteriorTicks, //!< Tick markers drawn inside map frame
ExteriorTicks, //!< Tick markers drawn outside map frame
InteriorExteriorTicks, //!< Tick markers drawn both inside and outside the map frame
LineBorder //!< Simple solid line frame
LineBorder, //!< Simple solid line frame
LineBorderNautical //!< Simple solid line frame, with nautical style diagonals on corners
};

/**
@@ -49,7 +49,7 @@
<x>0</x>
<y>0</y>
<width>389</width>
<height>1417</height>
<height>1452</height>
</rect>
</property>
<property name="sizePolicy">
@@ -444,38 +444,7 @@
</layout>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mFrameStyleComboBox">
<item>
<property name="text">
<string>No frame</string>
</property>
</item>
<item>
<property name="text">
<string>Zebra</string>
</property>
</item>
<item>
<property name="text">
<string>Interior ticks</string>
</property>
</item>
<item>
<property name="text">
<string>Exterior ticks</string>
</property>
</item>
<item>
<property name="text">
<string>Interior and exterior ticks</string>
</property>
</item>
<item>
<property name="text">
<string>Line border</string>
</property>
</item>
</widget>
<widget class="QComboBox" name="mFrameStyleComboBox"/>
</item>
<item row="1" column="1" colspan="2">
<widget class="QgsDoubleSpinBox" name="mFrameWidthSpinBox">
@@ -893,6 +862,10 @@
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 11258c0

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