Skip to content

Commit

Permalink
Start on layout snapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 7, 2017
1 parent b42c055 commit 361dd31
Show file tree
Hide file tree
Showing 13 changed files with 327 additions and 150 deletions.
1 change: 1 addition & 0 deletions python/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions python/core/layout/qgslayout.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 0 additions & 67 deletions python/core/layout/qgslayoutcontext.sip
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ class QgsLayoutContext
typedef QFlags<QgsLayoutContext::Flag> Flags;


enum GridStyle
{
GridLines,
GridDots,
GridCrosses
};

QgsLayoutContext();

void setFlags( const QgsLayoutContext::Flags flags );
Expand Down Expand Up @@ -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

};


Expand Down
100 changes: 100 additions & 0 deletions python/core/layout/qgslayoutsnapper.sip
Original file line number Diff line number Diff line change
@@ -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 *
************************************************************************/
2 changes: 2 additions & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/core/layout/qgslayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "qgis_core.h"
#include <QGraphicsScene>
#include "qgslayoutcontext.h"
#include "qgslayoutsnapper.h"
#include "qgsexpressioncontextgenerator.h"
#include "qgslayoutpagecollection.h"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 1 addition & 5 deletions src/core/layout/qgslayoutcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
68 changes: 0 additions & 68 deletions src/core/layout/qgslayoutcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

/**
Expand Down Expand Up @@ -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;
Expand All @@ -217,10 +153,6 @@ class CORE_EXPORT QgsLayoutContext

QgsLayoutMeasurementConverter mMeasurementConverter;

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

};

Expand Down
Loading

0 comments on commit 361dd31

Please sign in to comment.