Skip to content
Permalink
Browse files

Start on layout snapper

  • Loading branch information
nyalldawson committed Jul 23, 2017
1 parent b42c055 commit 361dd312bc63d2fd984ae3e04bdd8c591bbe2cc1
@@ -161,6 +161,7 @@
%Include layout/qgspagesizeregistry.sip
%Include layout/qgslayoutpoint.sip
%Include layout/qgslayoutsize.sip
%Include layout/qgslayoutsnapper.sip
%Include layout/qgslayoututils.sip
%Include metadata/qgslayermetadata.sip
%Include metadata/qgslayermetadatavalidator.sip
@@ -141,6 +141,14 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
%End


QgsLayoutSnapper &snapper();
%Docstring
Returns a reference to the layout's snapper, which stores handles layout snap grids and lines
and snapping points to the nearest matching point.
:rtype: QgsLayoutSnapper
%End


virtual QgsExpressionContext createExpressionContext() const;

%Docstring
@@ -30,13 +30,6 @@ class QgsLayoutContext
typedef QFlags<QgsLayoutContext::Flag> Flags;


enum GridStyle
{
GridLines,
GridDots,
GridCrosses
};

QgsLayoutContext();

void setFlags( const QgsLayoutContext::Flags flags );
@@ -138,66 +131,6 @@ class QgsLayoutContext
:rtype: bool
%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

};


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


class QgsLayoutSnapper
{
%Docstring
Manages snapping grids and preset snap lines in a layout, and handles
snapping points to the nearest grid coordinate/snap line when possible.
.. versionadded:: 3.0
%End

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

enum GridStyle
{
GridLines,
GridDots,
GridCrosses
};

QgsLayoutSnapper();

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

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutsnapper.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -362,6 +362,7 @@ SET(QGIS_CORE_SRCS
layout/qgslayoutmeasurementconverter.cpp
layout/qgslayoutobject.cpp
layout/qgslayoutpagecollection.cpp
layout/qgslayoutsnapper.cpp
layout/qgslayoututils.cpp
layout/qgspagesizeregistry.cpp
layout/qgslayoutpoint.cpp
@@ -940,6 +941,7 @@ SET(QGIS_CORE_HDRS
layout/qgspagesizeregistry.h
layout/qgslayoutpoint.h
layout/qgslayoutsize.h
layout/qgslayoutsnapper.h
layout/qgslayoututils.h

metadata/qgslayermetadata.h
@@ -19,6 +19,7 @@
#include "qgis_core.h"
#include <QGraphicsScene>
#include "qgslayoutcontext.h"
#include "qgslayoutsnapper.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgslayoutpagecollection.h"

@@ -154,6 +155,18 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext
*/
SIP_SKIP const QgsLayoutContext &context() const { return mContext; }

/**
* Returns a reference to the layout's snapper, which stores handles layout snap grids and lines
* and snapping points to the nearest matching point.
*/
QgsLayoutSnapper &snapper() { return mSnapper; }

/**
* Returns a reference to the layout's snapper, which stores handles layout snap grids and lines
* and snapping points to the nearest matching point.
*/
SIP_SKIP const QgsLayoutSnapper &snapper() const { return mSnapper; }

/**
* Creates an expression context relating to the layout's current state. The context includes
* scopes for global, project, layout and layout context properties.
@@ -262,6 +275,7 @@ class CORE_EXPORT QgsLayout : public QGraphicsScene, public QgsExpressionContext

QgsUnitTypes::LayoutUnit mUnits = QgsUnitTypes::LayoutMillimeters;
QgsLayoutContext mContext;
QgsLayoutSnapper mSnapper;

std::unique_ptr< QgsLayoutPageCollection > mPageCollection;

@@ -20,11 +20,7 @@

QgsLayoutContext::QgsLayoutContext()
: mFlags( FlagAntialiasing | FlagUseAdvancedEffects )
, mGridResolution( QgsLayoutMeasurement( 10 ) )
{
mGridPen = QPen( QColor( 190, 190, 190, 100 ), 0 );
mGridPen.setCosmetic( true );
}
{}

void QgsLayoutContext::setFlags( const QgsLayoutContext::Flags flags )
{
@@ -46,14 +46,6 @@ class CORE_EXPORT QgsLayoutContext
};
Q_DECLARE_FLAGS( Flags, Flag )

//! Style for drawing the page/snapping grid
enum GridStyle
{
GridLines, //! Solid lines
GridDots, //! Dots
GridCrosses //! Crosses
};

QgsLayoutContext();

/**
@@ -152,62 +144,6 @@ class CORE_EXPORT QgsLayoutContext
*/
bool gridVisible() const;

/**
* Sets the page/snap grid \a resolution.
* \see gridResolution()
* \see setGridOffset()
*/
void setGridResolution( const QgsLayoutMeasurement &resolution ) { mGridResolution = resolution; }

/**
* Returns the page/snap grid resolution.
* \see setGridResolution()
* \see gridOffset()
*/
QgsLayoutMeasurement gridResolution() const { return mGridResolution;}

/**
* Sets the \a offset of the page/snap grid.
* \see gridOffset()
* \see setGridResolution()
*/
void setGridOffset( const QgsLayoutPoint offset ) { mGridOffset = offset; }

/**
* Returns the offset of the page/snap grid.
* \see setGridOffset()
* \see gridResolution()
*/
QgsLayoutPoint gridOffset() const { return mGridOffset; }

/**
* Sets the \a pen used for drawing page/snap grids.
* \see gridPen()
* \see setGridStyle()
*/
void setGridPen( const QPen &pen ) { mGridPen = pen; }

/**
* Returns the pen used for drawing page/snap grids.
* \see setGridPen()
* \see gridStyle()
*/
QPen gridPen() const { return mGridPen; }

/**
* Sets the \a style used for drawing the page/snap grids.
* \see gridStyle()
* \see setGridPen()
*/
void setGridStyle( const GridStyle style ) { mGridStyle = style; }

/**
* Returns the style used for drawing the page/snap grids.
* \see setGridStyle()
* \see gridPen()
*/
GridStyle gridStyle() const { return mGridStyle; }

private:

Flags mFlags = 0;
@@ -217,10 +153,6 @@ class CORE_EXPORT QgsLayoutContext

QgsLayoutMeasurementConverter mMeasurementConverter;

QgsLayoutMeasurement mGridResolution;
QgsLayoutPoint mGridOffset;
QPen mGridPen;
GridStyle mGridStyle = GridLines;

};

0 comments on commit 361dd31

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