Skip to content
Permalink
Browse files
[composer] Rework interface composer methods
Since composer windows are now only created on demand, and
destroyed when the window is closed, the old interface methods
no longer apply. The new interface methods openComposers(),
openComposer(), closeComposer(), composerOpened(),
composerWillBeClosed() and composerClosed() are similar, but
only apply to composer windows when they are exist (i.e.
are currently open).

To access all compositions from a project, the project's
layoutManager() should be used instead.

Additionally, the new interface methods work with
QgsComposerInterface objects instead of QgsComposerView
objects. This should allow future hooks for plugins to interact
with open composer windows in a more useful way.
  • Loading branch information
nyalldawson committed Mar 21, 2017
1 parent b408952 commit 3aef32a191e9de412a232fee3cde44a6c3fbc132
@@ -365,6 +365,14 @@ QgisInterface {#qgis_api_break_3_0_QgisInterface}
- fileMenu() has been removed, use projectMenu() instead.
- actionRemoveLayer was removed as it no longer exists.
- actionTouch was removed, as the corresponding action no longer exists (see notes on QgsMapToolTouch)
- activeComposers(), createNewComposer(), duplicateComposer(), deleteComposer(), composerAdded(),
composerWillBeRemoved(), composerRemoved() were all removed. Composer windows are now only created
on demand, and destroyed when the window is closed. The new interface methods openComposers(),
openComposer(), closeComposer(), composerOpened(), composerWillBeClosed() and composerClosed()
are similar, but only apply to composer windows when they are exist. To access all compositions
from a project, the new QgsProject.instance().layoutManager() class should be used instead.
Additionally, the new interface methods work with QgsComposerInterface objects instead
of QgsComposerView objects.


QgsAbstractGeometry {#qgis_api_break_3_0_QgsAbstractGeometry}
@@ -210,28 +210,10 @@ class QgisInterface : QObject
/** Adds a widget to the user input tool bar.*/
virtual void addUserInputWidget( QWidget* widget ) = 0;

/** Return mainwindows / composer views of running composer instances (currently only one) */
virtual QList<QgsComposerView*> activeComposers() = 0;
virtual QList<QgsComposerInterface *> openComposers() = 0;
virtual QgsComposerInterface *openComposer( QgsComposition *composition ) = 0;
virtual void closeComposer( QgsComposition *composition ) = 0;

/** Create a new composer
* @param title window title for new composer (one will be generated if empty)
* @return pointer to composer's view
* @note new composer window will be shown and activated
*/
virtual QgsComposerView* createNewComposer( const QString& title = QString() ) = 0;

/** Duplicate an existing parent composer from composer view
* @param composerView pointer to existing composer view
* @param title window title for duplicated composer (one will be generated if empty)
* @return pointer to duplicate composer's view
* @note duplicate composer window will be hidden until loaded, then shown and activated
*/
virtual QgsComposerView* duplicateComposer( QgsComposerView* composerView, const QString& title = QString() ) = 0;

/** Deletes parent composer of composer view, after closing composer window */
virtual void deleteComposer( QgsComposerView* composerView ) = 0;

/** Return changeable options built from settings and/or defaults */
virtual QMap<QString, QVariant> defaultStyleSheetOptions() = 0;

/** Generate stylesheet
@@ -527,29 +509,10 @@ class QgisInterface : QObject
virtual int messageTimeout() = 0;

signals:
/** Emitted whenever current (selected) layer changes.
* The pointer to layer can be null if no layer is selected
*/
void currentLayerChanged( QgsMapLayer * layer );

/**
* This signal is emitted when a new composer instance has been created
*/
void composerAdded( QgsComposerView* v );

/**
* This signal is emitted before a new composer instance is going to be removed
*/
void composerWillBeRemoved( QgsComposerView* v );

/** This signal is emitted when a composer instance has been removed
* @note added in version 2.9
*/
void composerRemoved( QgsComposerView* v );

/**
* This signal is emitted when the initialization is complete
*/
void currentLayerChanged( QgsMapLayer *layer );
void composerOpened( QgsComposerInterface *composer );
void composerWillBeClosed( QgsComposerInterface *composer );
void composerClosed( QgsComposerInterface *composer );
void initializationCompleted();
/** Emitted when a project file is successfully read
* @note
@@ -4,9 +4,12 @@ class QgsComposerInterface: QObject
#include <qgscomposerinterface.h>
%End
public:
QgsComposerInterface( QObject* parent /TransferThis/ = 0 );
QgsComposerInterface( QObject *parent /TransferThis/ = 0 );

virtual ~QgsComposerInterface();
virtual QgsComposerView* view() = 0;
virtual QgsComposition* composition() = 0;
virtual QgsComposerView *view() = 0;
virtual QgsComposition *composition() = 0;
virtual void close() = 0;

};

@@ -3923,3 +3923,8 @@ QgsComposition *QgsAppComposerInterface::composition()
{
return mComposer->composition();
}

void QgsAppComposerInterface::close()
{
mComposer->close();
}
@@ -72,6 +72,7 @@ class QgsAppComposerInterface : public QgsComposerInterface
QgsAppComposerInterface( QgsComposer *composer );
QgsComposerView *view() override;
QgsComposition *composition() override;
void close() override;

private:

@@ -43,8 +43,8 @@ QgsComposerManager::QgsComposerManager( QWidget *parent, Qt::WindowFlags f ): QD
mComposerListWidget->setItemDelegate( new QgsComposerNameDelegate( mComposerListWidget ) );

connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( close() ) );
connect( QgisApp::instance(), &QgisApp::composerAdded, this, &QgsComposerManager::refreshComposers );
connect( QgisApp::instance(), &QgisApp::composerRemoved, this, &QgsComposerManager::refreshComposers );
//connect( QgisApp::instance(), &QgisApp::composerAdded, this, &QgsComposerManager::refreshComposers );
//connect( QgisApp::instance(), &QgisApp::composerRemoved, this, &QgsComposerManager::refreshComposers );

connect( mComposerListWidget, SIGNAL( itemSelectionChanged() ), this, SLOT( toggleButtons() ) );

@@ -7003,26 +7003,26 @@ QgsComposer *QgisApp::openComposer( QgsComposition *composition )
QgsComposer *newComposerObject = new QgsComposer( composition );
connect( newComposerObject, &QgsComposer::aboutToClose, this, [this, newComposerObject]
{
emit composerWillBeRemoved( newComposerObject->view() );
emit composerWillBeClosed( newComposerObject->interface() );
mPrintComposers.remove( newComposerObject );
emit composerRemoved( newComposerObject->view() );
emit composerClosed( newComposerObject->interface() );
} );

//add it to the map of existing print composers
mPrintComposers.insert( newComposerObject );

newComposerObject->open();
emit composerAdded( newComposerObject->view() );
emit composerOpened( newComposerObject->interface() );
connect( newComposerObject, &QgsComposer::atlasPreviewFeatureChanged, this, &QgisApp::refreshMapCanvas );

return newComposerObject;
}

void QgisApp::deleteComposer( QgsComposer *c )
{
emit composerWillBeRemoved( c->view() );
emit composerWillBeClosed( c->interface() );
mPrintComposers.remove( c );
emit composerRemoved( c->view() );
emit composerClosed( c->interface() );
delete c;
}

@@ -7052,9 +7052,9 @@ void QgisApp::deletePrintComposers()
while ( it != mPrintComposers.end() )
{
QgsComposer *c = ( *it );
emit composerWillBeRemoved( c->view() );
emit composerWillBeClosed( c->interface() );
it = mPrintComposers.erase( it );
emit composerRemoved( c->view() );
emit composerClosed( c->interface() );
delete ( c );
}
}
@@ -7091,9 +7091,9 @@ void QgisApp::compositionAboutToBeRemoved( const QString &name )
{
if ( composer->composition()->name() == name )
{
emit composerWillBeRemoved( composer->view() );
emit composerWillBeClosed( composer->interface() );
mPrintComposers.remove( composer );
emit composerRemoved( composer->view() );
emit composerClosed( composer->interface() );
delete composer;
return;
}
@@ -46,6 +46,7 @@ class QgsAuthManager;
class QgsBookmarks;
class QgsClipboard;
class QgsComposer;
class QgsComposerInterface;
class QgsComposition;
class QgsComposerManager;
class QgsComposerView;
@@ -1480,17 +1481,21 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
* can change there tool button icons. */
void currentThemeChanged( const QString & );

/** This signal is emitted when a new composer instance has been created
*/
void composerAdded( QgsComposerView *v );
/**
* This signal is emitted when a new composer window is opened
*/
void composerOpened( QgsComposerInterface *composer );

/** This signal is emitted before a new composer instance is going to be removed
*/
void composerWillBeRemoved( QgsComposerView *v );
/**
* This signal is emitted before a composer window is going to be closed
* and deleted.
*/
void composerWillBeClosed( QgsComposerInterface *composer );

/** This signal is emitted when a composer instance has been removed
@note added in version 2.3*/
void composerRemoved( QgsComposerView *v );
/**
* This signal is emitted when a composer window has been closed.
*/
void composerClosed( QgsComposerInterface *composer );

//! This signal is emitted when QGIS' initialization is complete
void initializationCompleted();
@@ -55,9 +55,9 @@ QgisAppInterface::QgisAppInterface( QgisApp *_qgis )
this, SIGNAL( currentLayerChanged( QgsMapLayer * ) ) );
connect( qgis, SIGNAL( currentThemeChanged( QString ) ),
this, SIGNAL( currentThemeChanged( QString ) ) );
connect( qgis, &QgisApp::composerAdded, this, &QgisAppInterface::composerAdded );
connect( qgis, &QgisApp::composerWillBeRemoved, this, &QgisAppInterface::composerWillBeRemoved );
connect( qgis, &QgisApp::composerRemoved, this, &QgisAppInterface::composerRemoved );
connect( qgis, &QgisApp::composerOpened, this, &QgisAppInterface::composerOpened );
connect( qgis, &QgisApp::composerWillBeClosed, this, &QgisAppInterface::composerWillBeClosed );
connect( qgis, &QgisApp::composerClosed, this, &QgisAppInterface::composerClosed );
connect( qgis, SIGNAL( initializationCompleted() ),
this, SIGNAL( initializationCompleted() ) );
connect( qgis, SIGNAL( newProject() ),
@@ -369,9 +369,9 @@ void QgisAppInterface::addUserInputWidget( QWidget *widget )
qgis->addUserInputWidget( widget );
}

QList<QgsComposerView *> QgisAppInterface::activeComposers()
QList<QgsComposerInterface *> QgisAppInterface::openComposers()
{
QList<QgsComposerView *> composerViewList;
QList<QgsComposerInterface *> composerInterfaceList;
if ( qgis )
{
const QSet<QgsComposer *> composerList = qgis->printComposers();
@@ -380,53 +380,42 @@ QList<QgsComposerView *> QgisAppInterface::activeComposers()
{
if ( *it )
{
QgsComposerView *v = ( *it )->view();
QgsComposerInterface *v = ( *it )->interface();
if ( v )
{
composerViewList.push_back( v );
composerInterfaceList << v;
}
}
}
}
return composerViewList;
return composerInterfaceList;
}

QgsComposerView *QgisAppInterface::createNewComposer( const QString &title )
QgsComposerInterface *QgisAppInterface::openComposer( QgsComposition *composition )
{
QgsComposer *composerObj = nullptr;
composerObj = qgis->createNewComposer( title );
QgsComposer *composerObj = qgis->openComposer( composition );
if ( composerObj )
{
return composerObj->view();
return composerObj->interface();
}
return nullptr;
}

QgsComposerView *QgisAppInterface::duplicateComposer( QgsComposerView *composerView, const QString &title )
void QgisAppInterface::closeComposer( QgsComposition *composition )
{
QgsComposer *composerObj = nullptr;
composerObj = qobject_cast<QgsComposer *>( composerView->composerWindow() );
if ( composerObj )
if ( qgis )
{
QgsComposer *dupComposer = qgis->duplicateComposer( composerObj, title );
if ( dupComposer )
const QSet<QgsComposer *> composerList = qgis->printComposers();
QSet<QgsComposer *>::const_iterator it = composerList.constBegin();
for ( ; it != composerList.constEnd(); ++it )
{
return dupComposer->view();
if ( *it && ( *it )->composition() == composition )
{
( *it )->close();
return;
}
}
}
return nullptr;
}

void QgisAppInterface::deleteComposer( QgsComposerView *composerView )
{
composerView->composerWindow()->close();

QgsComposer *composerObj = nullptr;
composerObj = qobject_cast<QgsComposer *>( composerView->composerWindow() );
if ( composerObj )
{
qgis->deleteComposer( composerObj );
}
}

QMap<QString, QVariant> QgisAppInterface::defaultStyleSheetOptions()
@@ -205,30 +205,9 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
//! Adds a widget to the user input tool bar.
void addUserInputWidget( QWidget *widget ) override;

// ### QGIS 3: return QgsComposer*, not QgsComposerView*
QList<QgsComposerView *> activeComposers() override;

// ### QGIS 3: return QgsComposer*, not QgsComposerView*

/** Create a new composer
* @param title window title for new composer (one will be generated if empty)
* @return pointer to composer's view
* @note new composer window will be shown and activated
*/
QgsComposerView *createNewComposer( const QString &title = QString() ) override;

// ### QGIS 3: return QgsComposer*, not QgsComposerView*

/** Duplicate an existing parent composer from composer view
* @param composerView pointer to existing composer view
* @param title window title for duplicated composer (one will be generated if empty)
* @return pointer to duplicate composer's view
* @note duplicate composer window will be hidden until loaded, then shown and activated
*/
QgsComposerView *duplicateComposer( QgsComposerView *composerView, const QString &title = QString() ) override;

//! Deletes parent composer of composer view, after closing composer window
void deleteComposer( QgsComposerView *composerView ) override;
QList<QgsComposerInterface *> openComposers() override;
QgsComposerInterface *openComposer( QgsComposition *composition ) override;
void closeComposer( QgsComposition *composition ) override;

//! Return changeable options built from settings and/or defaults
QMap<QString, QVariant> defaultStyleSheetOptions() override;

0 comments on commit 3aef32a

Please sign in to comment.