Skip to content

Commit

Permalink
Shell layout designer dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 3, 2017
1 parent 18b2b52 commit 4f21afa
Show file tree
Hide file tree
Showing 18 changed files with 704 additions and 3 deletions.
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/gui/editorwidgets/core
${CMAKE_SOURCE_DIR}/src/gui/effects
${CMAKE_SOURCE_DIR}/src/gui/layertree
${CMAKE_SOURCE_DIR}/src/gui/layout
${CMAKE_SOURCE_DIR}/src/gui/locator
${CMAKE_SOURCE_DIR}/src/plugins

Expand Down
5 changes: 5 additions & 0 deletions python/core/layout/qgslayoutitem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ Return correct graphics item type.
@param painter destination QPainter
%End

virtual void draw( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) = 0;
%Docstring
Draws the item's contents on a specified ``painter``.
%End

};


Expand Down
1 change: 1 addition & 0 deletions python/gui/gui_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
%Include layertree/qgslayertreemapcanvasbridge.sip
%Include layertree/qgslayertreeview.sip
%Include layertree/qgslayertreeviewdefaultactions.sip
%Include layout/qgslayoutdesignerinterface.sip
%Include locator/qgslocator.sip
%Include locator/qgslocatorfilter.sip
%Include locator/qgslocatorwidget.sip
Expand Down
57 changes: 57 additions & 0 deletions python/gui/layout/qgslayoutdesignerinterface.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutdesignerinterface.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutDesignerInterface: QObject
{
%Docstring
A common interface for layout designer dialogs and widgets.

Provides a common interface and stable API for layout designer dialogs and widgets.
This interface can be used by plugins and scripts to interact with
open layout designer dialogs.

.. versionadded:: 3.0
%End

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

QgsLayoutDesignerInterface( QObject *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsLayoutDesignerInterface.
%End

virtual ~QgsLayoutDesignerInterface();

virtual QgsLayout *layout() = 0;
%Docstring
Returns the layout displayed in the designer.
:rtype: QgsLayout
%End

public slots:

virtual void close() = 0;
%Docstring
Closes the layout designer.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/layout/qgslayoutdesignerinterface.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
17 changes: 17 additions & 0 deletions python/gui/qgisinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,23 @@ Adds a widget to the user input tool bar.
.. seealso:: openComposer()
%End

virtual QList<QgsLayoutDesignerInterface *> openLayoutDesigners() = 0;
%Docstring
Returns all currently open layout designers.
.. versionadded:: 3.0
:rtype: list of QgsLayoutDesignerInterface
%End

virtual QgsLayoutDesignerInterface *openLayoutDesigner( QgsLayout *layout ) = 0;
%Docstring
Opens a new layout designer dialog for the specified ``layout``, or
brings an already open designer window to the foreground if one
is already created for the layout.
.. versionadded:: 3.0
.. seealso:: closeComposer()
:rtype: QgsLayoutDesignerInterface
%End

virtual void showOptionsDialog( QWidget *parent = 0, const QString &currentPage = QString() ) = 0;
%Docstring
Opens the options dialog. The ``currentPage`` argument can be used to force
Expand Down
7 changes: 7 additions & 0 deletions src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ SET(QGIS_APP_SRCS
composer/qgscompositionwidget.cpp
composer/qgsatlascompositionwidget.cpp

layout/qgslayoutdesignerdialog.cpp

locator/qgsinbuiltlocatorfilters.cpp
locator/qgslocatoroptionswidget.cpp

Expand Down Expand Up @@ -337,6 +339,8 @@ SET (QGIS_APP_MOC_HDRS
composer/qgscompositionwidget.h
composer/qgsatlascompositionwidget.h

layout/qgslayoutdesignerdialog.h

locator/qgsinbuiltlocatorfilters.h
locator/qgslocatoroptionswidget.h

Expand Down Expand Up @@ -484,6 +488,7 @@ ENDIF(PEDANTIC)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src/app
${CMAKE_SOURCE_DIR}/src/app/composer
${CMAKE_SOURCE_DIR}/src/app/layout
${CMAKE_SOURCE_DIR}/src/app/pluginmanager
${CMAKE_SOURCE_DIR}/src/app/gps
${CMAKE_SOURCE_DIR}/src/app/openstreetmap
Expand Down Expand Up @@ -544,6 +549,7 @@ INCLUDE_DIRECTORIES(
../core/composer
../core/dxf
../core/geometry
../core/layout
../core/metadata
../core/layertree
../core/providers/memory
Expand All @@ -558,6 +564,7 @@ INCLUDE_DIRECTORIES(
../gui/editorwidgets
../gui/editorwidgets/core
../gui/layertree
../gui/layout
../plugins
../python
gps
Expand Down
150 changes: 150 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/***************************************************************************
qgslayoutdesignerdialog.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 "qgslayoutdesignerdialog.h"
#include "qgssettings.h"
#include "qgisapp.h"
#include "qgslogger.h"

QgsAppLayoutDesignerInterface::QgsAppLayoutDesignerInterface( QgsLayoutDesignerDialog *dialog )
: QgsLayoutDesignerInterface( dialog )
, mDesigner( dialog )
{}

QgsLayout *QgsAppLayoutDesignerInterface::layout()
{
return mDesigner->currentLayout();
}

void QgsAppLayoutDesignerInterface::close()
{
mDesigner->close();
}


QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFlags flags )
: QMainWindow( parent, flags )
, mInterface( new QgsAppLayoutDesignerInterface( this ) )
{
QgsSettings settings;
int size = settings.value( QStringLiteral( "IconSize" ), QGIS_ICON_SIZE ).toInt();
setIconSize( QSize( size, size ) );
setStyleSheet( QgisApp::instance()->styleSheet() );
setWindowTitle( tr( "QGIS Layout Designer" ) );

setupUi( this );

setAttribute( Qt::WA_DeleteOnClose );
#if QT_VERSION >= 0x050600
setDockOptions( dockOptions() | QMainWindow::GroupedDragging ) ;
#endif

connect( mActionClose, &QAction::triggered, this, &QWidget::close );

restoreWindowState();
}

QgsAppLayoutDesignerInterface *QgsLayoutDesignerDialog::iface()
{
return mInterface;
}

QgsLayout *QgsLayoutDesignerDialog::currentLayout()
{
return mLayout;
}

void QgsLayoutDesignerDialog::setCurrentLayout( QgsLayout *layout )
{
mLayout = layout;

}

void QgsLayoutDesignerDialog::setIconSizes( int size )
{
//Set the icon size of for all the toolbars created in the future.
setIconSize( QSize( size, size ) );

//Change all current icon sizes.
QList<QToolBar *> toolbars = findChildren<QToolBar *>();
Q_FOREACH ( QToolBar *toolbar, toolbars )
{
toolbar->setIconSize( QSize( size, size ) );
}
}

void QgsLayoutDesignerDialog::open()
{
show();
activate();
#if 0 // TODO
zoomFull(); // zoomFull() does not work properly until we have called show()
if ( mView )
{
mView->updateRulers();
}
#endif
}

void QgsLayoutDesignerDialog::activate()
{
// bool shown = isVisible();
show();
raise();
setWindowState( windowState() & ~Qt::WindowMinimized );
activateWindow();

#if 0 // TODO
if ( !shown )
{
on_mActionZoomAll_triggered();
}
#endif
}

void QgsLayoutDesignerDialog::closeEvent( QCloseEvent * )
{
emit aboutToClose();
saveWindowState();
}

void QgsLayoutDesignerDialog::saveWindowState()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "LayoutDesigner/geometry" ), saveGeometry() );
// store the toolbar/dock widget settings using Qt settings API
settings.setValue( QStringLiteral( "LayoutDesigner/state" ), saveState() );
}

void QgsLayoutDesignerDialog::restoreWindowState()
{
// restore the toolbar and dock widgets positions using Qt settings API
QgsSettings settings;

//TODO - defaults
if ( !restoreState( settings.value( QStringLiteral( "LayoutDesigner/state" ) /*, QByteArray::fromRawData( ( char * )defaultComposerUIstate, sizeof defaultComposerUIstate ) */ ).toByteArray() ) )
{
QgsDebugMsg( "restore of layout UI state failed" );
}
// restore window geometry
if ( !restoreGeometry( settings.value( QStringLiteral( "LayoutDesigner/geometry" ) /*, QByteArray::fromRawData( ( char * )defaultComposerUIgeometry, sizeof defaultComposerUIgeometry ) */ ).toByteArray() ) )
{
QgsDebugMsg( "restore of layout UI geometry failed" );
}
}


Loading

0 comments on commit 4f21afa

Please sign in to comment.