Skip to content
Permalink
Browse files
Add a basic interface for composer windows
Not much there yet, but it adds an interface with stable API
which can be used by plugins and scripts to interact with
composer windows.

Could be expanded in future to add hooks for toolbars, menus,
etc, allowing plugins to extend composer functionality.
  • Loading branch information
nyalldawson committed Mar 21, 2017
1 parent 148e2bc commit b408952815a147754cd6f6cbee19ae20f94584ee
@@ -44,6 +44,7 @@
%Include qgscolorschemelist.sip
%Include qgscolorswatchgrid.sip
%Include qgscolorwidgets.sip
%Include qgscomposerinterface.sip
%Include qgscomposeritemcombobox.sip
%Include qgscomposerruler.sip
%Include qgscomposerview.sip
@@ -0,0 +1,12 @@
class QgsComposerInterface: QObject
{
%TypeHeaderCode
#include <qgscomposerinterface.h>
%End
public:
QgsComposerInterface( QObject* parent /TransferThis/ = 0 );
virtual ~QgsComposerInterface();
virtual QgsComposerView* view() = 0;
virtual QgsComposition* composition() = 0;
};

@@ -104,6 +104,7 @@

QgsComposer::QgsComposer( QgsComposition *composition )
: QMainWindow()
, mInterface( new QgsAppComposerInterface( this ) )
, mComposition( composition )
, mQgis( QgisApp::instance() )
{
@@ -676,6 +677,11 @@ QgsComposer::~QgsComposer()
delete mPrinter;
}

QgsComposerInterface *QgsComposer::interface()
{
return mInterface;
}

void QgsComposer::setupTheme()
{
//now set all the icons - getThemeIcon will fall back to default theme if its
@@ -3898,3 +3904,22 @@ QPrinter *QgsComposer::printer()
return mPrinter;
}


//
// QgsAppComposerInterface
//

QgsAppComposerInterface::QgsAppComposerInterface( QgsComposer *composer )
: QgsComposerInterface( composer )
, mComposer( composer )
{}

QgsComposerView *QgsAppComposerInterface::view()
{
return mComposer->view();
}

QgsComposition *QgsAppComposerInterface::composition()
{
return mComposer->composition();
}
@@ -20,6 +20,7 @@

#include "qgspanelwidget.h"
#include "qgsvectorlayer.h"
#include "qgscomposerinterface.h"

class QgisApp;
class QgsComposerArrow;
@@ -61,6 +62,21 @@ class QComboBox;
class QLabel;
class QTreeView;
class QPrinter;
class QgsComposer;

class QgsAppComposerInterface : public QgsComposerInterface
{
Q_OBJECT

public:
QgsAppComposerInterface( QgsComposer *composer );
QgsComposerView *view() override;
QgsComposition *composition() override;

private:

QgsComposer *mComposer = nullptr;
};

/** \ingroup app
* \brief A gui for composing a printable map.
@@ -80,6 +96,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QgsComposer( QgsComposition *composition );
~QgsComposer();

QgsComposerInterface *interface();

//! Set the pixmap / icons on the toolbar buttons
void setupTheme();

@@ -515,6 +533,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

QPrinter *printer();

QgsAppComposerInterface *mInterface = nullptr;

//! Composer title
QString mTitle;

@@ -341,6 +341,7 @@ SET(QGIS_GUI_MOC_HDRS
qgscolorschemelist.h
qgscolorswatchgrid.h
qgscolorwidgets.h
qgscomposerinterface.h
qgscomposeritemcombobox.h
qgscomposerruler.h
qgscomposerview.h
@@ -0,0 +1,62 @@
/***************************************************************************
qgscomposerinterface.h
---------------------
Date : March 2017
Copyright : (C) 2017 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. *
* *
***************************************************************************/

#ifndef QGSCOMPOSERINTERFACE_H
#define QGSCOMPOSERINTERFACE_H

#include "qgis_gui.h"
#include <QObject>

class QgsComposerView;
class QgsComposition;

/** \ingroup gui
* \class QgsComposerInterface
* A common interface for composer dialogs.
*
* Provides a common interface and stable API for composer editor dialogs.
* This interface can be used by plugins and scripts to interact with
* open composer dialogs.
*
* \note added in QGIS 3.0
*/
class GUI_EXPORT QgsComposerInterface: public QObject
{
Q_OBJECT

public:

/**
* Constructor for QgsComposerInterface.
*/
QgsComposerInterface( QObject *parent = nullptr )
: QObject( parent )
{}

virtual ~QgsComposerInterface() = default;

/**
* Returns the composer's QgsComposerView editor widget.
*/
virtual QgsComposerView *view() = 0;

/**
* Returns the composition displated in the composer.
*/
virtual QgsComposition *composition() = 0;

};

#endif // QGSCOMPOSERINTERFACE_H

0 comments on commit b408952

Please sign in to comment.