Skip to content
Permalink
Browse files
Restore opening existing composers
  • Loading branch information
nyalldawson committed Mar 21, 2017
1 parent 79a11dc commit b6c76186b42e20b7d11ffe8dc5d5c79ae053929b
Showing with 33 additions and 23 deletions.
  1. +4 −5 python/core/qgsproject.sip
  2. +2 −14 src/app/composer/qgscomposer.cpp
  3. +24 −4 src/app/qgisapp.cpp
  4. +3 −0 src/app/qgisapp.h
@@ -309,12 +309,11 @@ class QgsProject : QObject, QgsExpressionContextGenerator
@return home path of project (or QString::null if not set) */
QString homePath() const;

QgsRelationManager* relationManager() const;
QgsRelationManager *relationManager() const;

/** Return pointer to the root (invisible) node of the project's layer tree
* @note added in 2.4
*/
QgsLayerTreeGroup* layerTreeRoot() const;
//const QgsLayoutManager *layoutManager() const;
QgsLayoutManager *layoutManager();
QgsLayerTreeGroup *layerTreeRoot() const;

/** Return pointer to the helper class that synchronizes map layer registry with layer tree
* @note added in 2.4
@@ -102,12 +102,6 @@
#include "modeltest.h"
#endif

// sort function for QList<QAction*>, e.g. menu listings
static bool cmpByText_( QAction *a, QAction *b )
{
return QString::localeAwareCompare( a->text(), b->text() ) < 0;
}

QgsComposer::QgsComposer( QgsComposition *composition )
: QMainWindow()
, mComposition( composition )
@@ -817,6 +811,7 @@ void QgsComposer::connectOtherSlots()
void QgsComposer::open()
{
show();
activate();
zoomFull(); // zoomFull() does not work properly until we have called show()
if ( mView )
{
@@ -3683,14 +3678,7 @@ void QgsComposer::on_mActionPageSetup_triggered()

void QgsComposer::populatePrintComposersMenu()
{
mPrintComposersMenu->clear();
QList<QAction *> acts = mQgis->printComposersMenu()->actions();
if ( acts.size() > 1 )
{
// sort actions in case main app's aboutToShow slot has not yet
std::sort( acts.begin(), acts.end(), cmpByText_ );
}
mPrintComposersMenu->addActions( acts );
mQgis->populateComposerMenu( mPrintComposersMenu );
}

void QgsComposer::populateWindowMenu()
@@ -6992,6 +6992,17 @@ QgsComposer *QgisApp::createNewComposer( QString title )

QgsComposer *QgisApp::openComposer( QgsComposition *composition )
{
// maybe a composer already open for this composition
Q_FOREACH ( QgsComposer *composer, mPrintComposers )
{
if ( composer->composition() == composition )
{
composer->open();
return composer;
}
}

//nope, so make a new one
QgsComposer *newComposerObject = new QgsComposer( composition );
connect( newComposerObject, &QgsComposer::aboutToClose, this, [this, newComposerObject]
{
@@ -7054,19 +7065,28 @@ void QgisApp::deletePrintComposers()

void QgisApp::composerMenuAboutToShow()
{
mPrintComposersMenu->clear();
populateComposerMenu( mPrintComposersMenu );
}

void QgisApp::populateComposerMenu( QMenu *menu )
{
menu->clear();
QList<QAction *> acts;
Q_FOREACH ( QgsComposition *c, QgsProject::instance()->layoutManager()->compositions() )
{


QAction *a = new QAction( c->name(), menu );
connect( a, &QAction::triggered, this, [this, c]
{
openComposer( c );
} );
acts << a;
}
if ( acts.size() > 1 )
{
// sort actions by text
std::sort( acts.begin(), acts.end(), cmpByText_ );
}
mPrintComposersMenu->addActions( acts );
menu->addActions( acts );
}

void QgisApp::compositionAboutToBeRemoved( const QString &name )
@@ -279,6 +279,9 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
//! Get stylesheet builder object for app and print composers
QgisAppStyleSheet *styleSheetBuilder();

//! Populates a menu with actions for opening print composers
void populateComposerMenu( QMenu *menu );

//! Setup the toolbar popup menus for a given theme
void setupToolbarPopups( QString themeName );
//! Returns a pointer to the internal clipboard

0 comments on commit b6c7618

Please sign in to comment.