Skip to content

Commit

Permalink
Restore rulers in layout designer
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 06976d0 commit 28cd9ad
Show file tree
Hide file tree
Showing 14 changed files with 781 additions and 9 deletions.
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
90 changes: 90 additions & 0 deletions python/gui/layout/qgslayoutruler.sip
Original file line number Diff line number Diff line change
@@ -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 *
************************************************************************/
20 changes: 20 additions & 0 deletions python/gui/layout/qgslayoutview.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand Down
19 changes: 17 additions & 2 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "qgslayoutviewtoolselect.h"
#include "qgsgui.h"
#include "qgslayoutitemguiregistry.h"
#include "qgslayoutruler.h"
#include <QShortcut>
#include <QComboBox>
#include <QLineEdit>
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QgsLayoutRuler;
class QComboBox;
class QSlider;
class QLabel;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 28cd9ad

Please sign in to comment.