Skip to content
Permalink
Browse files

Add a zoom tool to designer dialog

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 41b98aa commit 7974597c0828fa952fafdd4ed7d0d2b06c3a303e
@@ -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;
@@ -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 )
@@ -34,6 +36,11 @@ QgsLayout *QgsAppLayoutDesignerInterface::layout()
return mDesigner->currentLayout();
}

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

void QgsAppLayoutDesignerInterface::close()
{
mDesigner->close();
@@ -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();
}
@@ -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();
@@ -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();
@@ -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;
@@ -24,6 +24,7 @@ class QgsLayoutDesignerDialog;
class QgsLayoutView;
class QgsLayoutViewToolAddItem;
class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;

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

public slots:

@@ -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()
@@ -76,6 +83,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
*/
void setIconSizes( int size );


public slots:

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

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

signals:

/**
@@ -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
@@ -21,6 +21,7 @@
#include <QObject>

class QgsLayout;
class QgsLayoutView;

/** \ingroup gui
* \class QgsLayoutDesignerInterface
@@ -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:

/**
@@ -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>
@@ -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">
@@ -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"/>

0 comments on commit 7974597

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