Skip to content
Permalink
Browse files

Restore rulers in layout designer

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 06976d0 commit 28cd9addab48cd21d59c3527e60eb04db7553705
@@ -278,6 +278,7 @@
%Include layertree/qgslayertreeviewdefaultactions.sip
%Include layout/qgslayoutdesignerinterface.sip
%Include layout/qgslayoutitemguiregistry.sip
%Include layout/qgslayoutruler.sip
%Include layout/qgslayoutview.sip
%Include layout/qgslayoutviewtool.sip
%Include layout/qgslayoutviewtooladditem.sip
@@ -0,0 +1,90 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutruler.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/



class QgsLayoutRuler: QWidget
{
%Docstring
A custom ruler widget for use with QgsLayoutView, displaying the
current zoom and position of the visible layout and for interacting
with guides in a layout.

.. versionadded:: 3.0
%End

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

explicit QgsLayoutRuler( QWidget *parent /TransferThis/ = 0, Qt::Orientation orientation = Qt::Horizontal );
%Docstring
Constructor for QgsLayoutRuler, with the specified ``parent`` widget and ``orientation``.
%End

virtual QSize minimumSizeHint() const;


void setSceneTransform( const QTransform &transform );
%Docstring
Sets the current scene ``transform``. This is usually the transform set for a view
showing the associated scene, in order to synchronize the view's display of
the scene with the rulers.
%End

QgsLayoutView *layoutView();
%Docstring
Returns the current layout view associated with the ruler.
.. seealso:: setLayoutView()
:rtype: QgsLayoutView
%End

void setLayoutView( QgsLayoutView *view );
%Docstring
Sets the current layout ``view`` to synchronize the ruler with.
.. seealso:: layoutView()
%End

int rulerSize() const;
%Docstring
Returns the ruler size (either the height of a horizontal ruler or the
width of a vertical rule).
:rtype: int
%End

public slots:

void setCursorPosition( QPointF position );
%Docstring
Updates the ``position`` of the marker showing the current mouse position within
the view.
``position`` is in layout coordinates.
%End

protected:
virtual void paintEvent( QPaintEvent *event );

virtual void mouseMoveEvent( QMouseEvent *event );


signals:
void cursorPosChanged( QPointF );
%Docstring
Is emitted when mouse cursor coordinates change
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutruler.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -78,6 +78,18 @@ class QgsLayoutView: QGraphicsView
Sets the zoom ``level`` for the view, where a zoom level of 1.0 corresponds to 100%.
%End

void setHorizontalRuler( QgsLayoutRuler *ruler );
%Docstring
Sets a horizontal ``ruler`` to synchronize with the view state.
.. seealso:: setVerticalRuler()
%End

void setVerticalRuler( QgsLayoutRuler *ruler );
%Docstring
Sets a vertical ``ruler`` to synchronize with the view state.
.. seealso:: setHorizontalRuler()
%End

public slots:

void zoomFull();
@@ -122,6 +134,14 @@ class QgsLayoutView: QGraphicsView

void emitZoomLevelChanged();

void updateRulers();
%Docstring
Updates associated rulers after view extent or zoom has changed.
This should be called after calling any of the QGraphicsView
base class methods which alter the view's zoom level or extent,
i.e. QGraphicsView.fitInView().
%End

signals:

void layoutSet( QgsLayout *layout );
@@ -28,6 +28,7 @@
#include "qgslayoutviewtoolselect.h"
#include "qgsgui.h"
#include "qgslayoutitemguiregistry.h"
#include "qgslayoutruler.h"
#include <QShortcut>
#include <QComboBox>
#include <QLineEdit>
@@ -88,11 +89,22 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
centralWidget()->layout()->setSpacing( 0 );
centralWidget()->layout()->setMargin( 0 );
centralWidget()->layout()->setContentsMargins( 0, 0, 0, 0 );

mHorizontalRuler = new QgsLayoutRuler( nullptr, Qt::Horizontal );
mVerticalRuler = new QgsLayoutRuler( nullptr, Qt::Vertical );
mRulerLayoutFix = new QWidget();
mRulerLayoutFix->setAttribute( Qt::WA_NoMousePropagation );
mRulerLayoutFix->setBackgroundRole( QPalette::Window );
mRulerLayoutFix->setFixedSize( mVerticalRuler->rulerSize(), mHorizontalRuler->rulerSize() );
viewLayout->addWidget( mRulerLayoutFix, 0, 0 );
viewLayout->addWidget( mHorizontalRuler, 0, 1 );
viewLayout->addWidget( mVerticalRuler, 1, 0 );

mView = new QgsLayoutView();
//mView->setMapCanvas( mQgis->mapCanvas() );
mView->setContentsMargins( 0, 0, 0, 0 );
//mView->setHorizontalRuler( mHorizontalRuler );
//mView->setVerticalRuler( mVerticalRuler );
mView->setHorizontalRuler( mHorizontalRuler );
mView->setVerticalRuler( mVerticalRuler );
viewLayout->addWidget( mView, 1, 1 );
//view does not accept focus via tab
mView->setFocusPolicy( Qt::ClickFocus );
@@ -186,6 +198,9 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mView->setFocus();
connect( mView, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutDesignerDialog::updateStatusZoom );
connect( mView, &QgsLayoutView::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );
//also listen out for position updates from the horizontal/vertical rulers
connect( mHorizontalRuler, &QgsLayoutRuler::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );
connect( mVerticalRuler, &QgsLayoutRuler::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );

restoreWindowState();
}
@@ -26,6 +26,7 @@ class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QgsLayoutRuler;
class QComboBox;
class QSlider;
class QLabel;
@@ -133,6 +134,9 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
QActionGroup *mToolsActionGroup = nullptr;

QgsLayoutView *mView = nullptr;
QgsLayoutRuler *mHorizontalRuler = nullptr;
QgsLayoutRuler *mVerticalRuler = nullptr;
QWidget *mRulerLayoutFix = nullptr;

//! Combobox in status bar which shows/adjusts current zoom level
QComboBox *mStatusZoomCombo = nullptr;
@@ -159,6 +159,7 @@ SET(QGIS_GUI_SRCS
layertree/qgslayertreeviewdefaultactions.cpp

layout/qgslayoutitemguiregistry.cpp
layout/qgslayoutruler.cpp
layout/qgslayoutview.cpp
layout/qgslayoutviewmouseevent.cpp
layout/qgslayoutviewrubberband.cpp
@@ -634,6 +635,7 @@ SET(QGIS_GUI_MOC_HDRS

layout/qgslayoutdesignerinterface.h
layout/qgslayoutitemguiregistry.h
layout/qgslayoutruler.h
layout/qgslayoutview.h
layout/qgslayoutviewtool.h
layout/qgslayoutviewtooladditem.h

0 comments on commit 28cd9ad

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