Skip to content

Commit

Permalink
Add a zoom tool to designer dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 41b98aa commit 7974597
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
9 changes: 9 additions & 0 deletions python/gui/layout/qgslayoutdesignerinterface.sip
Expand Up @@ -36,9 +36,18 @@ class QgsLayoutDesignerInterface: QObject
virtual QgsLayout *layout() = 0;
%Docstring
Returns the layout displayed in the designer.
.. seealso:: view()
:rtype: QgsLayout
%End


virtual QgsLayoutView *view() = 0;
%Docstring
Returns the layout view utilized by the designer.
.. seealso:: layout()
:rtype: QgsLayoutView
%End

public slots:

virtual void close() = 0;
Expand Down
31 changes: 29 additions & 2 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -20,9 +20,11 @@
#include "qgssettings.h"
#include "qgisapp.h"
#include "qgslogger.h"
#include "qgslayout.h"
#include "qgslayoutview.h"
#include "qgslayoutviewtooladditem.h"
#include "qgslayoutviewtoolpan.h"
#include "qgslayoutviewtoolzoom.h"

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
Expand All @@ -34,6 +36,11 @@ QgsLayout *QgsAppLayoutDesignerInterface::layout()
return mDesigner->currentLayout();
}

QgsLayoutView *QgsAppLayoutDesignerInterface::view()
{
return mDesigner->view();
}

void QgsAppLayoutDesignerInterface::close()
{
mDesigner->close();
Expand Down Expand Up @@ -95,6 +102,11 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mPanTool->setAction( mActionPan );
mToolsActionGroup->addAction( mActionPan );
connect( mActionPan, &QAction::triggered, mPanTool, [ = ] { mView->setTool( mPanTool ); } );
mZoomTool = new QgsLayoutViewToolZoom( mView );
mZoomTool->setAction( mActionZoomTool );
mToolsActionGroup->addAction( mActionZoomTool );
connect( mActionZoomTool, &QAction::triggered, mZoomTool, [ = ] { mView->setTool( mZoomTool ); } );


restoreWindowState();
}
Expand Down Expand Up @@ -132,8 +144,10 @@ void QgsLayoutDesignerDialog::open()
{
show();
activate();
#if 0 // TODO
zoomFull(); // zoomFull() does not work properly until we have called show()

#if 0 // TODO

if ( mView )
{
mView->updateRulers();
Expand All @@ -157,6 +171,14 @@ void QgsLayoutDesignerDialog::activate()
#endif
}

void QgsLayoutDesignerDialog::zoomFull()
{
if ( mView )
{
mView->fitInView( mLayout->sceneRect(), Qt::KeepAspectRatio );
}
}

void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
{
emit aboutToClose();
Expand All @@ -173,13 +195,18 @@ void QgsLayoutDesignerDialog::itemTypeAdded( int type, const QString &name )
action->setIcon( QgsApplication::layoutItemRegistry()->itemMetadata( type )->icon() );
mToolsActionGroup->addAction( action );
mItemMenu->addAction( action );
mItemToolbar->addAction( action );
mToolsToolbar->addAction( action );
connect( action, &QAction::triggered, this, [this, type]()
{
activateNewItemCreationTool( type );
} );
}

QgsLayoutView *QgsLayoutDesignerDialog::view()
{
return mView;
}

void QgsLayoutDesignerDialog::saveWindowState()
{
QgsSettings settings;
Expand Down
15 changes: 14 additions & 1 deletion src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -24,6 +24,7 @@ class QgsLayoutDesignerDialog;
class QgsLayoutView;
class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;

class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
Expand All @@ -32,6 +33,7 @@ class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
public:
QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog );
QgsLayout *layout() override;
QgsLayoutView *view() override;

public slots:

Expand Down Expand Up @@ -65,6 +67,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
QgsLayout *currentLayout();

/**
* Returns the layout view utilized by the designer.
*/
QgsLayoutView *view();

/**
* Sets the current \a layout to edit in the designer.
* \see currentLayout()
Expand All @@ -76,6 +83,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void setIconSizes( int size );


public slots:

/**
Expand All @@ -88,6 +96,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void activate();

/**
* Zooms to show full layout.
*/
void zoomFull();

signals:

/**
Expand All @@ -114,8 +127,8 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
QgsLayoutView *mView = nullptr;

QgsLayoutViewToolAddItem *mAddItemTool = nullptr;

QgsLayoutViewToolPan *mPanTool = nullptr;
QgsLayoutViewToolZoom *mZoomTool = nullptr;


//! Save window state
Expand Down
9 changes: 9 additions & 0 deletions src/gui/layout/qgslayoutdesignerinterface.h
Expand Up @@ -21,6 +21,7 @@
#include <QObject>

class QgsLayout;
class QgsLayoutView;

/** \ingroup gui
* \class QgsLayoutDesignerInterface
Expand Down Expand Up @@ -49,9 +50,17 @@ class GUI_EXPORT QgsLayoutDesignerInterface: public QObject

/**
* Returns the layout displayed in the designer.
* \see view()
*/
virtual QgsLayout *layout() = 0;


/**
* Returns the layout view utilized by the designer.
* \see layout()
*/
virtual QgsLayoutView *view() = 0;

public slots:

/**
Expand Down
23 changes: 21 additions & 2 deletions src/ui/layout/qgslayoutdesignerbase.ui
Expand Up @@ -62,9 +62,8 @@
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
<addaction name="mActionPan"/>
</widget>
<widget class="QToolBar" name="mItemToolbar">
<widget class="QToolBar" name="mToolsToolbar">
<property name="windowTitle">
<string>Toolbox</string>
</property>
Expand All @@ -74,6 +73,8 @@
<attribute name="toolBarBreak">
<bool>true</bool>
</attribute>
<addaction name="mActionPan"/>
<addaction name="mActionZoomTool"/>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
Expand Down Expand Up @@ -124,6 +125,24 @@
<string>P</string>
</property>
</action>
<action name="mActionZoomTool">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomToArea.svg</normaloff>:/images/themes/default/mActionZoomToArea.svg</iconset>
</property>
<property name="text">
<string>Zoom</string>
</property>
<property name="toolTip">
<string>Zoom</string>
</property>
<property name="shortcut">
<string>Z</string>
</property>
</action>
</widget>
<resources>
<include location="../../../images/images.qrc"/>
Expand Down

0 comments on commit 7974597

Please sign in to comment.