-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start on classes for snapping guide items
- Loading branch information
1 parent
3aa231e
commit db36440
Showing
9 changed files
with
426 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/layout/qgslayoutguidecollection.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsLayoutGuide | ||
{ | ||
%Docstring | ||
Contains the configuration for a single snap guide used by a layout. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslayoutguidecollection.h" | ||
%End | ||
public: | ||
|
||
enum Orientation | ||
{ | ||
Horizontal, | ||
Vertical, | ||
}; | ||
|
||
QgsLayoutGuide( QgsLayout *layout, Orientation orientation, const QgsLayoutMeasurement &position ); | ||
|
||
Orientation orientation() const; | ||
%Docstring | ||
Returns the guide's orientation. | ||
:rtype: Orientation | ||
%End | ||
|
||
QgsLayoutMeasurement position() const; | ||
%Docstring | ||
Returns the guide's position within the page. | ||
|
||
The position indicates either the horizontal or vertical position | ||
of the guide, depending on the guide's orientation(). | ||
|
||
.. seealso:: setPosition() | ||
:rtype: QgsLayoutMeasurement | ||
%End | ||
|
||
void setPosition( const QgsLayoutMeasurement &position ); | ||
%Docstring | ||
Sets the guide's ``position`` within the page. | ||
|
||
The ``position`` argument indicates either the horizontal or vertical position | ||
of the guide, depending on the guide's orientation(). | ||
|
||
.. seealso:: position() | ||
%End | ||
|
||
int page() const; | ||
%Docstring | ||
Returns the page number of the guide. | ||
|
||
Page numbering begins at 0. | ||
|
||
.. seealso:: setPage() | ||
:rtype: int | ||
%End | ||
|
||
void setPage( int page ); | ||
%Docstring | ||
Sets the ``page`` number of the guide. | ||
|
||
Page numbering begins at 0. | ||
|
||
.. seealso:: page() | ||
%End | ||
|
||
void update(); | ||
%Docstring | ||
Updates the position of the guide's line item. | ||
%End | ||
|
||
QGraphicsLineItem *item(); | ||
%Docstring | ||
Returns the guide's line item. | ||
:rtype: QGraphicsLineItem | ||
%End | ||
|
||
}; | ||
|
||
|
||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/core/layout/qgslayoutguidecollection.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/*************************************************************************** | ||
qgslayoutguidecollection.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 "qgslayoutguidecollection.h" | ||
#include "qgslayout.h" | ||
#include <QGraphicsLineItem> | ||
|
||
|
||
// | ||
// QgsLayoutGuide | ||
// | ||
|
||
QgsLayoutGuide::QgsLayoutGuide( QgsLayout *layout, Orientation orientation, const QgsLayoutMeasurement &position ) | ||
: mOrientation( orientation ) | ||
, mPosition( position ) | ||
, mLayout( layout ) | ||
, mLineItem( new QGraphicsLineItem() ) | ||
{ | ||
mLineItem->hide(); | ||
mLineItem->setZValue( QgsLayout::ZGuide ); | ||
mLayout->addItem( mLineItem.get() ); | ||
|
||
QPen linePen( Qt::SolidLine ); | ||
linePen.setColor( Qt::red ); | ||
// use a pen width of 0, since this activates a cosmetic pen | ||
// which doesn't scale with the composer and keeps a constant size | ||
linePen.setWidthF( 0 ); | ||
mLineItem->setPen( linePen ); | ||
} | ||
|
||
QgsLayoutMeasurement QgsLayoutGuide::position() const | ||
{ | ||
return mPosition; | ||
} | ||
|
||
void QgsLayoutGuide::setPosition( const QgsLayoutMeasurement &position ) | ||
{ | ||
mPosition = position; | ||
update(); | ||
} | ||
|
||
int QgsLayoutGuide::page() const | ||
{ | ||
return mPage; | ||
} | ||
|
||
void QgsLayoutGuide::setPage( int page ) | ||
{ | ||
mPage = page; | ||
update(); | ||
} | ||
|
||
void QgsLayoutGuide::update() | ||
{ | ||
// first find matching page | ||
if ( mPage >= mLayout->pageCollection()->pageCount() ) | ||
{ | ||
mLineItem->hide(); | ||
return; | ||
} | ||
|
||
QgsLayoutItemPage *page = mLayout->pageCollection()->page( mPage ); | ||
mLineItem->setParentItem( page ); | ||
double layoutPos = mLayout->convertToLayoutUnits( mPosition ); | ||
switch ( mOrientation ) | ||
{ | ||
case Horizontal: | ||
if ( layoutPos > page->rect().width() ) | ||
{ | ||
mLineItem->hide(); | ||
} | ||
else | ||
{ | ||
mLineItem->setLine( 0, layoutPos, page->rect().width(), layoutPos ); | ||
mLineItem->show(); | ||
} | ||
|
||
break; | ||
|
||
case Vertical: | ||
if ( layoutPos > page->rect().height() ) | ||
{ | ||
mLineItem->hide(); | ||
} | ||
else | ||
{ | ||
mLineItem->setLine( layoutPos, 0, layoutPos, page->rect().height() ); | ||
mLineItem->show(); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
|
||
QGraphicsLineItem *QgsLayoutGuide::item() | ||
{ | ||
return mLineItem.get(); | ||
} | ||
|
||
QgsLayoutGuide::Orientation QgsLayoutGuide::orientation() const | ||
{ | ||
return mOrientation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/*************************************************************************** | ||
qgslayoutguidecollection.h | ||
-------------------------- | ||
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. * | ||
* * | ||
***************************************************************************/ | ||
#ifndef QGSLAYOUTGUIDECOLLECTION_H | ||
#define QGSLAYOUTGUIDECOLLECTION_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgslayoutmeasurement.h" | ||
#include "qgslayoutpoint.h" | ||
#include <QPen> | ||
#include <memory> | ||
|
||
class QgsLayout; | ||
class QGraphicsLineItem; | ||
|
||
/** | ||
* \ingroup core | ||
* \class QgsLayoutGuide | ||
* \brief Contains the configuration for a single snap guide used by a layout. | ||
* \since QGIS 3.0 | ||
*/ | ||
class CORE_EXPORT QgsLayoutGuide | ||
{ | ||
|
||
public: | ||
|
||
//! Guide orientation | ||
enum Orientation | ||
{ | ||
Horizontal, //!< Horizontal guide | ||
Vertical, //!< Vertical guide | ||
}; | ||
|
||
QgsLayoutGuide( QgsLayout *layout, Orientation orientation, const QgsLayoutMeasurement &position ); | ||
|
||
/** | ||
* Returns the guide's orientation. | ||
*/ | ||
Orientation orientation() const; | ||
|
||
/** | ||
* Returns the guide's position within the page. | ||
* | ||
* The position indicates either the horizontal or vertical position | ||
* of the guide, depending on the guide's orientation(). | ||
* | ||
* \see setPosition() | ||
*/ | ||
QgsLayoutMeasurement position() const; | ||
|
||
/** | ||
* Sets the guide's \a position within the page. | ||
* | ||
* The \a position argument indicates either the horizontal or vertical position | ||
* of the guide, depending on the guide's orientation(). | ||
* | ||
* \see position() | ||
*/ | ||
void setPosition( const QgsLayoutMeasurement &position ); | ||
|
||
/** | ||
* Returns the page number of the guide. | ||
* | ||
* Page numbering begins at 0. | ||
* | ||
* \see setPage() | ||
*/ | ||
int page() const; | ||
|
||
/** | ||
* Sets the \a page number of the guide. | ||
* | ||
* Page numbering begins at 0. | ||
* | ||
* \see page() | ||
*/ | ||
void setPage( int page ); | ||
|
||
/** | ||
* Updates the position of the guide's line item. | ||
*/ | ||
void update(); | ||
|
||
/** | ||
* Returns the guide's line item. | ||
*/ | ||
QGraphicsLineItem *item(); | ||
|
||
private: | ||
|
||
Orientation mOrientation = Vertical; | ||
|
||
//! Horizontal/vertical position of guide on page | ||
QgsLayoutMeasurement mPosition; | ||
|
||
//! Page number, 0 index based | ||
int mPage = 0; | ||
|
||
QgsLayout *mLayout = nullptr; | ||
|
||
//! Line item used in scene for guide | ||
std::shared_ptr< QGraphicsLineItem > mLineItem; | ||
}; | ||
|
||
|
||
|
||
#endif //QGSLAYOUTGUIDECOLLECTION_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.