Skip to content
Permalink
Browse files

Code refactor - split grid appearance settings into their own class

  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent 55c7cc1 commit 0d0a3c2cdc6a6d0d076e9ba903fc7e944a754a59
@@ -156,6 +156,7 @@
%Include composer/qgscomposertexttable.sip
%Include composer/qgspaperitem.sip
%Include layout/qgslayoutcontext.sip
%Include layout/qgslayoutgridsettings.sip
%Include layout/qgslayoutmeasurement.sip
%Include layout/qgslayoutmeasurementconverter.sip
%Include layout/qgspagesizeregistry.sip
@@ -149,6 +149,14 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
%End


QgsLayoutGridSettings &gridSettings();
%Docstring
Returns a reference to the layout's grid settings, which stores settings relating
to grid appearance, spacing and offsets.
:rtype: QgsLayoutGridSettings
%End


virtual QgsExpressionContext createExpressionContext() const;

%Docstring
@@ -0,0 +1,103 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutgridsettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutGridSettings
{
%Docstring
Contains settings relating to the appearance, spacing and offset for layout grids.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgslayoutgridsettings.h"
%End
public:

enum Style
{
StyleLines,
StyleDots,
StyleCrosses
};

QgsLayoutGridSettings();
%Docstring
Constructor for QgsLayoutGridSettings.
%End

void setResolution( const QgsLayoutMeasurement &resolution );
%Docstring
Sets the page/snap grid ``resolution``.
.. seealso:: resolution()
.. seealso:: setOffset()
%End

QgsLayoutMeasurement resolution() const;
%Docstring
Returns the page/snap grid resolution.
.. seealso:: setResolution()
.. seealso:: offset()
:rtype: QgsLayoutMeasurement
%End

void setOffset( const QgsLayoutPoint offset );
%Docstring
Sets the ``offset`` of the page/snap grid.
.. seealso:: offset()
.. seealso:: setResolution()
%End

QgsLayoutPoint offset() const;
%Docstring
Returns the offset of the page/snap grid.
.. seealso:: setOffset()
.. seealso:: resolution()
:rtype: QgsLayoutPoint
%End

void setPen( const QPen &pen );
%Docstring
Sets the ``pen`` used for drawing page/snap grids.
.. seealso:: pen()
.. seealso:: setStyle()
%End

QPen pen() const;
%Docstring
Returns the pen used for drawing page/snap grids.
.. seealso:: setPen()
.. seealso:: style()
:rtype: QPen
%End

void setStyle( const Style style );
%Docstring
Sets the ``style`` used for drawing the page/snap grids.
.. seealso:: style()
.. seealso:: setPen()
%End

Style style() const;
%Docstring
Returns the style used for drawing the page/snap grids.
.. seealso:: setStyle()
.. seealso:: pen()
:rtype: Style
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutgridsettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -21,13 +21,6 @@ class QgsLayoutSnapper
%End
public:

enum GridStyle
{
GridLines,
GridDots,
GridCrosses
};

QgsLayoutSnapper( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutSnapper, attached to the specified ``layout``.
@@ -46,66 +39,6 @@ class QgsLayoutSnapper
:rtype: int
%End

void setGridResolution( const QgsLayoutMeasurement &resolution );
%Docstring
Sets the page/snap grid ``resolution``.
.. seealso:: gridResolution()
.. seealso:: setGridOffset()
%End

QgsLayoutMeasurement gridResolution() const;
%Docstring
Returns the page/snap grid resolution.
.. seealso:: setGridResolution()
.. seealso:: gridOffset()
:rtype: QgsLayoutMeasurement
%End

void setGridOffset( const QgsLayoutPoint offset );
%Docstring
Sets the ``offset`` of the page/snap grid.
.. seealso:: gridOffset()
.. seealso:: setGridResolution()
%End

QgsLayoutPoint gridOffset() const;
%Docstring
Returns the offset of the page/snap grid.
.. seealso:: setGridOffset()
.. seealso:: gridResolution()
:rtype: QgsLayoutPoint
%End

void setGridPen( const QPen &pen );
%Docstring
Sets the ``pen`` used for drawing page/snap grids.
.. seealso:: gridPen()
.. seealso:: setGridStyle()
%End

QPen gridPen() const;
%Docstring
Returns the pen used for drawing page/snap grids.
.. seealso:: setGridPen()
.. seealso:: gridStyle()
:rtype: QPen
%End

void setGridStyle( const GridStyle style );
%Docstring
Sets the ``style`` used for drawing the page/snap grids.
.. seealso:: gridStyle()
.. seealso:: setGridPen()
%End

GridStyle gridStyle() const;
%Docstring
Returns the style used for drawing the page/snap grids.
.. seealso:: setGridStyle()
.. seealso:: gridPen()
:rtype: GridStyle
%End

bool snapToGrid() const;
%Docstring
Returns true if snapping to grid is enabled.
@@ -47,51 +47,51 @@ void QgsLayoutPropertiesWidget::updateSnappingElements()
{
mSnapToleranceSpinBox->setValue( mLayout->snapper().snapTolerance() );

mGridSpacingUnitsCombo->setUnit( mLayout->snapper().gridResolution().units() );
mGridResolutionSpinBox->setValue( mLayout->snapper().gridResolution().length() );
mGridSpacingUnitsCombo->setUnit( mLayout->gridSettings().resolution().units() );
mGridResolutionSpinBox->setValue( mLayout->gridSettings().resolution().length() );

mGridOffsetUnitsComboBox->setUnit( mLayout->snapper().gridOffset().units() );
mOffsetXSpinBox->setValue( mLayout->snapper().gridOffset().x() );
mOffsetYSpinBox->setValue( mLayout->snapper().gridOffset().y() );
mGridOffsetUnitsComboBox->setUnit( mLayout->gridSettings().offset().units() );
mOffsetXSpinBox->setValue( mLayout->gridSettings().offset().x() );
mOffsetYSpinBox->setValue( mLayout->gridSettings().offset().y() );
}

void QgsLayoutPropertiesWidget::gridResolutionChanged( double d )
{
QgsLayoutMeasurement m = mLayout->snapper().gridResolution();
QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
m.setLength( d );
mLayout->snapper().setGridResolution( m );
mLayout->gridSettings().setResolution( m );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridResolutionUnitsChanged( QgsUnitTypes::LayoutUnit unit )
{
QgsLayoutMeasurement m = mLayout->snapper().gridResolution();
QgsLayoutMeasurement m = mLayout->gridSettings().resolution();
m.setUnits( unit );
mLayout->snapper().setGridResolution( m );
mLayout->gridSettings().setResolution( m );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridOffsetXChanged( double d )
{
QgsLayoutPoint o = mLayout->snapper().gridOffset();
QgsLayoutPoint o = mLayout->gridSettings().offset();
o.setX( d );
mLayout->snapper().setGridOffset( o );
mLayout->gridSettings().setOffset( o );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridOffsetYChanged( double d )
{
QgsLayoutPoint o = mLayout->snapper().gridOffset();
QgsLayoutPoint o = mLayout->gridSettings().offset();
o.setY( d );
mLayout->snapper().setGridOffset( o );
mLayout->gridSettings().setOffset( o );
mLayout->pageCollection()->redraw();
}

void QgsLayoutPropertiesWidget::gridOffsetUnitsChanged( QgsUnitTypes::LayoutUnit unit )
{
QgsLayoutPoint o = mLayout->snapper().gridOffset();
QgsLayoutPoint o = mLayout->gridSettings().offset();
o.setUnits( unit );
mLayout->snapper().setGridOffset( o );
mLayout->gridSettings().setOffset( o );
mLayout->pageCollection()->redraw();
}

@@ -353,6 +353,7 @@ SET(QGIS_CORE_SRCS

layout/qgslayout.cpp
layout/qgslayoutcontext.cpp
layout/qgslayoutgridsettings.cpp
layout/qgslayoutitem.cpp
layout/qgslayoutitemmap.cpp
layout/qgslayoutitempage.cpp
@@ -936,6 +937,7 @@ SET(QGIS_CORE_HDRS
composer/qgspaperitem.h

layout/qgslayoutcontext.h
layout/qgslayoutgridsettings.h
layout/qgslayoutmeasurement.h
layout/qgslayoutmeasurementconverter.h
layout/qgspagesizeregistry.h
@@ -22,6 +22,7 @@
#include "qgslayoutsnapper.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgslayoutpagecollection.h"
#include "qgslayoutgridsettings.h"

class QgsLayoutItemMap;

@@ -167,6 +168,18 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
*/
SIP_SKIP const QgsLayoutSnapper &snapper() const { return mSnapper; }

/**
* Returns a reference to the layout's grid settings, which stores settings relating
* to grid appearance, spacing and offsets.
*/
QgsLayoutGridSettings &gridSettings() { return mGridSettings; }

/**
* Returns a reference to the layout's grid settings, which stores settings relating
* to grid appearance, spacing and offsets.
*/
SIP_SKIP const QgsLayoutGridSettings &gridSettings() const { return mGridSettings; }

/**
* Creates an expression context relating to the layout's current state. The context includes
* scopes for global, project, layout and layout context properties.
@@ -276,6 +289,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
QgsUnitTypes::LayoutUnit mUnits = QgsUnitTypes::LayoutMillimeters;
QgsLayoutContext mContext;
QgsLayoutSnapper mSnapper;
QgsLayoutGridSettings mGridSettings;

std::unique_ptr< QgsLayoutPageCollection > mPageCollection;

@@ -0,0 +1,25 @@
/***************************************************************************
qgslayoutgridsettings.cpp
-------------------------
begin : July 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgslayoutgridsettings.h"

QgsLayoutGridSettings::QgsLayoutGridSettings()
: mGridResolution( QgsLayoutMeasurement( 10 ) )
{
mGridPen = QPen( QColor( 190, 190, 190, 100 ), 0 );
mGridPen.setCosmetic( true );
}

0 comments on commit 0d0a3c2

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