[QGIS Commit] r12087 - in trunk/qgis/src: app app/composer ui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Nov 11 12:05:17 EST 2009


Author: mhugent
Date: 2009-11-11 12:05:16 -0500 (Wed, 11 Nov 2009)
New Revision: 12087

Added:
   trunk/qgis/src/app/composer/qgscomposermanager.cpp
   trunk/qgis/src/app/composer/qgscomposermanager.h
   trunk/qgis/src/ui/qgscomposermanagerbase.ui
Modified:
   trunk/qgis/src/app/CMakeLists.txt
   trunk/qgis/src/app/composer/qgscomposer.cpp
   trunk/qgis/src/app/composer/qgscomposer.h
   trunk/qgis/src/app/composer/qgscomposermapwidget.cpp
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/app/qgisapp.h
   trunk/qgis/src/app/qgisappinterface.cpp
   trunk/qgis/src/ui/qgscomposerbase.ui
Log:
[FEATURE?] Close composers instead of deleting them. Added composer manager dialog to manage the existing composer instances

Modified: trunk/qgis/src/app/CMakeLists.txt
===================================================================
--- trunk/qgis/src/app/CMakeLists.txt	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/app/CMakeLists.txt	2009-11-11 17:05:16 UTC (rev 12087)
@@ -77,6 +77,7 @@
   composer/qgscomposeritemwidget.cpp
   composer/qgscomposerlabelwidget.cpp
   composer/qgscomposerpicturewidget.cpp
+  composer/qgscomposermanager.cpp
   composer/qgscomposermapwidget.cpp
   composer/qgscomposerscalebarwidget.cpp
   composer/qgscomposerlegenditemdialog.cpp
@@ -174,6 +175,7 @@
   composer/qgscomposeritemwidget.h
   composer/qgscomposerlabelwidget.h
   composer/qgscomposerlegendwidget.h
+  composer/qgscomposermanager.h
   composer/qgscomposermapwidget.h
   composer/qgscomposerpicturewidget.h
   composer/qgscomposerscalebarwidget.h

Modified: trunk/qgis/src/app/composer/qgscomposer.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.cpp	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/app/composer/qgscomposer.cpp	2009-11-11 17:05:16 UTC (rev 12087)
@@ -65,11 +65,12 @@
 #include <QSizeGrip>
 #include "qgslogger.h"
 
-QgsComposer::QgsComposer( QgisApp *qgis, const QString& id ): QMainWindow(), mId( id )
+QgsComposer::QgsComposer( QgisApp *qgis, const QString& title ): QMainWindow(), mTitle( title )
 {
   setupUi( this );
-  setAttribute( Qt::WA_DeleteOnClose );
+  setWindowTitle( mTitle );
   setupTheme();
+  QObject::connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( close() ) );
 
   QToolButton* orderingToolButton = new QToolButton( this );
   orderingToolButton->setPopupMode( QToolButton::InstantPopup );
@@ -107,8 +108,6 @@
   toggleActionGroup->addAction( mActionSelectMoveItem );
   toggleActionGroup->setExclusive( true );
 
-  setWindowTitle( mId );
-
   mActionAddNewMap->setCheckable( true );
   mActionAddNewLabel->setCheckable( true );
   mActionAddNewLegend->setCheckable( true );
@@ -185,6 +184,7 @@
   connectSlots();
 
   mComposition  = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
+  mComposition->setParent(mView);
   mView->setComposition( mComposition );
 
   QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mCompositionOptionsFrame, mComposition );
@@ -297,31 +297,12 @@
 
 void QgsComposer::activate()
 {
+  show();
   raise();
   setWindowState( windowState() & ~Qt::WindowMinimized );
   activateWindow();
 }
 
-void QgsComposer::closeEvent( QCloseEvent *event )
-{
-  if ( QMessageBox::warning( 0, tr( "Remove composer?" ), tr( "Do you really want to remove the composer instance '%1'?" ).arg( mId ), QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) == QMessageBox::Ok )
-  {
-    mQgis->checkOutComposer( this );
-    event->accept();
-  }
-  else
-  {
-    event->ignore();
-  }
-#if 0
-  QMainWindow::closeEvent( event );
-  if ( event->isAccepted() )
-  {
-    QgisApp::instance()->removeWindow( mWindowAction );
-  }
-#endif //0
-}
-
 #ifdef Q_WS_MAC
 void QgsComposer::changeEvent( QEvent* event )
 {
@@ -351,6 +332,12 @@
 }
 #endif
 
+void QgsComposer::setTitle( const QString& title )
+{
+  mTitle = title;
+  setWindowTitle( mTitle );
+}
+
 void QgsComposer::showCompositionOptions( QWidget *w )
 {
   QWidget* currentWidget = mItemStackedWidget->currentWidget();
@@ -1024,7 +1011,7 @@
 void QgsComposer::writeXML( QDomNode& parentNode, QDomDocument& doc )
 {
   QDomElement composerElem = doc.createElement( "Composer" );
-  composerElem.setAttribute( "id", mId );
+  composerElem.setAttribute( "title", mTitle );
   parentNode.appendChild( composerElem );
 
   //store composer items:
@@ -1055,14 +1042,16 @@
 
 void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument& doc )
 {
-  mId = composerElem.attribute( "id", "" );
-  setWindowTitle( mId );
-
   // Create action to select this window
   delete mWindowAction;
   mWindowAction = new QAction( windowTitle(), this );
   connect( mWindowAction, SIGNAL( triggered() ), this, SLOT( activate() ) );
 
+  if ( composerElem.hasAttribute( "title" ) )
+  {
+    setTitle( composerElem.attribute( "title", tr( "Composer" ) ) );
+  }
+
   //delete composer view and composition
   delete mView;
   mView = 0;
@@ -1187,148 +1176,6 @@
   setSelectionTool();
 }
 
-#if 0
-void QgsComposer::readXML( const QDomDocument& doc )
-{
-  //look for Composer element
-  QDomNodeList nl = doc.elementsByTagName( "Composer" );
-  if ( nl.size() < 1 )
-  {
-    return; //nothing to do...
-  }
-  QDomElement composerElem = nl.at( 0 ).toElement();
-  mId = composerElem.attribute( "id", "" );
-
-  //look for Composition element
-  QDomNodeList cnl = composerElem.elementsByTagName( "Composition" );
-  if ( cnl.size() < 1 )
-  {
-    return; //nothing to do
-  }
-
-
-  //delete composer view and composition
-  delete mView;
-  mView = 0;
-  //delete every child of mViewFrame
-  QObjectList viewFrameChildren = mViewFrame->children();
-  QObjectList::iterator it = viewFrameChildren.begin();
-  for ( ; it != viewFrameChildren.end(); ++it )
-  {
-    delete( *it );
-  }
-  //delete composition widget
-  QgsCompositionWidget* oldCompositionWidget = qobject_cast<QgsCompositionWidget *>( mCompositionOptionsFrame->children().at( 0 ) );
-  delete oldCompositionWidget;
-  delete mCompositionOptionsLayout;
-  mCompositionOptionsLayout = 0;
-
-  QDomElement compositionElem = cnl.at( 0 ).toElement();
-
-  //todo: move in function because duplicated code with constructor
-  mView = new QgsComposerView( mViewFrame );
-  connectSlots();
-
-  mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );
-  mComposition->readXML( compositionElem, doc );
-
-  QGridLayout *l = new QGridLayout( mViewFrame );
-  l->setMargin( 0 );
-  l->addWidget( mView, 0, 0 );
-
-  //create compositionwidget
-  QgsCompositionWidget* compositionWidget = new QgsCompositionWidget( mCompositionOptionsFrame, mComposition );
-  QObject::connect( mComposition, SIGNAL( paperSizeChanged() ), compositionWidget, SLOT( displayCompositionWidthHeight() ) );
-  compositionWidget->show();
-
-  mCompositionOptionsLayout = new QGridLayout( mCompositionOptionsFrame );
-  mCompositionOptionsLayout->setMargin( 0 );
-  mCompositionOptionsLayout->addWidget( compositionWidget );
-
-  //read and restore all the items
-
-  //composer labels
-  QDomNodeList composerLabelList = composerElem.elementsByTagName( "ComposerLabel" );
-  for ( int i = 0; i < composerLabelList.size(); ++i )
-  {
-    QDomElement currentComposerLabelElem = composerLabelList.at( i ).toElement();
-    QgsComposerLabel* newLabel = new QgsComposerLabel( mComposition );
-    newLabel->readXML( currentComposerLabelElem, doc );
-    addComposerLabel( newLabel );
-    mComposition->addItem( newLabel );
-    mComposition->update();
-    mComposition->clearSelection();
-    newLabel->setSelected( true );
-    showItemOptions( newLabel );
-  }
-
-  //composer maps
-  QDomNodeList composerMapList = composerElem.elementsByTagName( "ComposerMap" );
-  for ( int i = 0; i < composerMapList.size(); ++i )
-  {
-    QDomElement currentComposerMapElem = composerMapList.at( i ).toElement();
-    QgsComposerMap* newMap = new QgsComposerMap( mComposition );
-    newMap->readXML( currentComposerMapElem, doc );
-    addComposerMap( newMap );
-    mComposition->addItem( newMap );
-    mComposition->update();
-    mComposition->clearSelection();
-    newMap->setSelected( true );
-    showItemOptions( newMap );
-  }
-
-  //composer scalebars
-  QDomNodeList composerScaleBarList = composerElem.elementsByTagName( "ComposerScaleBar" );
-  for ( int i = 0; i < composerScaleBarList.size(); ++i )
-  {
-    QDomElement currentScaleBarElem = composerScaleBarList.at( i ).toElement();
-    QgsComposerScaleBar* newScaleBar = new QgsComposerScaleBar( mComposition );
-    newScaleBar->readXML( currentScaleBarElem, doc );
-    addComposerScaleBar( newScaleBar );
-    mComposition->addItem( newScaleBar );
-    mComposition->update();
-    mComposition->clearSelection();
-    newScaleBar->setSelected( true );
-    showItemOptions( newScaleBar );
-  }
-
-  //composer legends
-  QDomNodeList composerLegendList = composerElem.elementsByTagName( "ComposerLegend" );
-  for ( int i = 0; i < composerLegendList.size(); ++i )
-  {
-    QDomElement currentLegendElem = composerLegendList.at( i ).toElement();
-    QgsComposerLegend* newLegend = new QgsComposerLegend( mComposition );
-    newLegend->readXML( currentLegendElem, doc );
-    addComposerLegend( newLegend );
-    mComposition->addItem( newLegend );
-    mComposition->update();
-    mComposition->clearSelection();
-    newLegend->setSelected( true );
-    showItemOptions( newLegend );
-  }
-
-  //composer pictures
-  QDomNodeList composerPictureList = composerElem.elementsByTagName( "ComposerPicture" );
-  for ( int i = 0; i < composerPictureList.size(); ++i )
-  {
-    QDomElement currentPictureElem = composerPictureList.at( i ).toElement();
-    QgsComposerPicture* newPicture = new QgsComposerPicture( mComposition );
-    newPicture->readXML( currentPictureElem, doc );
-    addComposerPicture( newPicture );
-    mComposition->addItem( newPicture );
-    mComposition->update();
-    mComposition->clearSelection();
-    newPicture->setSelected( true );
-    showItemOptions( newPicture );
-  }
-
-  mComposition->sortZList();
-  mView->setComposition( mComposition );
-
-  setSelectionTool();
-}
-#endif //0
-
 void QgsComposer::addComposerMap( QgsComposerMap* map )
 {
   if ( !map )

Modified: trunk/qgis/src/app/composer/qgscomposer.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposer.h	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/app/composer/qgscomposer.h	2009-11-11 17:05:16 UTC (rev 12087)
@@ -46,7 +46,7 @@
     Q_OBJECT
 
   public:
-    QgsComposer( QgisApp *qgis, const QString& id );
+    QgsComposer( QgisApp *qgis, const QString& title );
     ~QgsComposer();
 
     //! Set the pixmap / icons on the toolbar buttons
@@ -75,7 +75,8 @@
 
     QAction* windowAction() {return mWindowAction;}
 
-    QString id() const {return mId;}
+    const QString& title() const {return mTitle;}
+    void setTitle( const QString& title );
 
   protected:
     //! Move event
@@ -84,9 +85,6 @@
     //! Resize event
     virtual void resizeEvent( QResizeEvent * );
 
-    //! Close event (remove window from menu)
-    virtual void closeEvent( QCloseEvent * );
-
 #ifdef Q_WS_MAC
     //! Change event (update window menu on ActivationChange)
     virtual void changeEvent( QEvent * );
@@ -225,8 +223,6 @@
 
     void setSelectionTool();
 
-  private slots:
-
     //! Raise, unminimize and activate this window
     void activate();
 
@@ -250,8 +246,8 @@
     //! Writes state under DOM element
     void writeXML( QDomNode& parentNode, QDomDocument& doc );
 
-    /**Identification string*/
-    QString mId;
+    /**Composer title*/
+    QString mTitle;
 
     //! Pointer to composer view
     QgsComposerView *mView;

Added: trunk/qgis/src/app/composer/qgscomposermanager.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermanager.cpp	                        (rev 0)
+++ trunk/qgis/src/app/composer/qgscomposermanager.cpp	2009-11-11 17:05:16 UTC (rev 12087)
@@ -0,0 +1,159 @@
+/***************************************************************************
+                              qgscomposermanager.cpp
+                             ------------------------
+    begin                : September 11 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco at hugis dot net
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   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 "qgscomposermanager.h"
+#include "qgisapp.h"
+#include "qgscomposer.h"
+#include <QInputDialog>
+#include <QListWidgetItem>
+#include <QMessageBox>
+
+QgsComposerManager::QgsComposerManager(QgisApp* app, QWidget * parent, Qt::WindowFlags f): QDialog(parent, f), mQgisApp(app)
+{
+    setupUi(this);
+    connect(mButtonBox, SIGNAL(rejected()), this, SLOT(close()));
+    initialize();
+}
+
+QgsComposerManager::~QgsComposerManager()
+{
+
+}
+
+void QgsComposerManager::initialize()
+{
+    if(!mQgisApp)
+    {
+        return;
+    }
+
+    QSet<QgsComposer*> composers = mQgisApp->printComposers();
+    QSet<QgsComposer*>::const_iterator it = composers.constBegin();
+    for(; it != composers.constEnd(); ++it)
+    {
+        QListWidgetItem* item = new QListWidgetItem((*it)->title(), mComposerListWidget);
+        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
+        mItemComposerMap.insert(item, *it);
+    }
+}
+
+void QgsComposerManager::on_mAddButton_clicked()
+{
+    if(!mQgisApp)
+    {
+        return;
+    }
+    QgsComposer* newComposer = mQgisApp->createNewComposer();
+    if(!newComposer)
+    {
+        return;
+    }
+    QListWidgetItem* item = new QListWidgetItem(newComposer->title(), mComposerListWidget);
+    item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
+    mItemComposerMap.insert(item, newComposer);
+}
+
+void QgsComposerManager::on_mRemoveButton_clicked()
+{
+    if(!mQgisApp)
+    {
+        return;
+    }
+
+    QListWidgetItem* item = mComposerListWidget->currentItem();
+    if(!item)
+    {
+        return;
+    }
+
+    //ask for confirmation
+    if(QMessageBox::warning(0, tr("Remove composer"), tr("Do you really want to remove the map composer '%1'?").arg(item->text()), QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok)
+    {
+        return;
+    }
+
+    //delete composer
+    QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find(item);
+    if(it != mItemComposerMap.end())
+    {
+        mQgisApp->deleteComposer(it.value());
+    }
+    mItemComposerMap.remove(item);
+    mComposerListWidget->removeItemWidget(item);
+    //and remove the list widget row
+    delete (mComposerListWidget->takeItem(mComposerListWidget->row(item)));
+}
+
+void QgsComposerManager::on_mShowPushButton_clicked()
+{
+    if(!mQgisApp)
+    {
+        return;
+    }
+
+    QListWidgetItem* item = mComposerListWidget->currentItem();
+    if(!item)
+    {
+        return;
+    }
+
+    //delete composer
+    QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find(item);
+    if(it != mItemComposerMap.end())
+    {
+        it.value()->show();
+        it.value()->activate();
+        it.value()->stackUnder(this);
+    }
+}
+
+void QgsComposerManager::on_mRenamePushButton_clicked()
+{
+    QListWidgetItem* item = mComposerListWidget->currentItem();
+    if(!item)
+    {
+        return;
+    }
+
+    QString currentTitle;
+    QgsComposer* currentComposer = 0;
+    QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find(item);
+    if(it != mItemComposerMap.end())
+    {
+        currentComposer = it.value();
+        currentTitle = it.value()->title();
+    }
+    else
+    {
+        return;
+    }
+    QString newTitle = QInputDialog::getText(0, tr("Change title"), tr("Title"), QLineEdit::Normal, currentTitle );
+    if(newTitle.isNull())
+    {
+        return;
+    }
+    currentComposer->setTitle(newTitle);
+    item->setText(newTitle);
+}
+
+void QgsComposerManager::on_mComposerListWidget_itemChanged( QListWidgetItem * item )
+{
+    QMap<QListWidgetItem*, QgsComposer*>::iterator it = mItemComposerMap.find(item);
+    if(it != mItemComposerMap.end())
+    {
+        it.value()->setTitle(item->text());
+    }
+}

Added: trunk/qgis/src/app/composer/qgscomposermanager.h
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermanager.h	                        (rev 0)
+++ trunk/qgis/src/app/composer/qgscomposermanager.h	2009-11-11 17:05:16 UTC (rev 12087)
@@ -0,0 +1,51 @@
+/***************************************************************************
+                              qgscomposermanager.h
+                             ------------------------
+    begin                : September 11 2009
+    copyright            : (C) 2009 by Marco Hugentobler
+    email                : marco at hugis dot net
+ ***************************************************************************/
+/***************************************************************************
+ *                                                                         *
+ *   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 QGSCOMPOSERMANAGER_H
+#define QGSCOMPOSERMANAGER_H
+
+#include "ui_qgscomposermanagerbase.h"
+
+class QgisApp;
+class QListWidgetItem;
+class QgsComposer;
+
+/**A dialog that shows the existing composer instances. Lets the user add new \
+instances and change title of existing ones*/
+class QgsComposerManager: public QDialog, private Ui::QgsComposerManagerBase
+{
+    Q_OBJECT
+    public:
+        QgsComposerManager(QgisApp* app, QWidget * parent = 0, Qt::WindowFlags f = 0);
+        ~QgsComposerManager();
+
+
+    private:
+        QgisApp* mQgisApp;
+        /**Stores the relation between items and composer pointers */
+        QMap<QListWidgetItem*, QgsComposer*> mItemComposerMap;
+        /**Enters the composer instances and created the item-composer map*/
+        void initialize();
+
+    private slots:
+        void on_mAddButton_clicked();
+        void on_mRemoveButton_clicked();
+        void on_mShowPushButton_clicked();
+        void on_mRenamePushButton_clicked();
+        void on_mComposerListWidget_itemChanged( QListWidgetItem * item );
+};
+
+#endif // QGSCOMPOSERMANAGER_H

Modified: trunk/qgis/src/app/composer/qgscomposermapwidget.cpp
===================================================================
--- trunk/qgis/src/app/composer/qgscomposermapwidget.cpp	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/app/composer/qgscomposermapwidget.cpp	2009-11-11 17:05:16 UTC (rev 12087)
@@ -55,15 +55,13 @@
   mAnnotationDirectionComboBox->insertItem( 1, tr( "Vertical" ) );
   mAnnotationDirectionComboBox->insertItem( 2, tr( "Horizontal and Vertical" ) );
   mAnnotationDirectionComboBox->insertItem( 2, tr( "Boundary direction" ) );
-
-  blockAllSignals( false );
-
   if ( composerMap )
   {
     connect( composerMap, SIGNAL( extentChanged() ), this, SLOT( updateSettingsNoSignals() ) );
   }
 
   updateGuiElements();
+  blockAllSignals( false );
 }
 
 QgsComposerMapWidget::~QgsComposerMapWidget()

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/app/qgisapp.cpp	2009-11-11 17:05:16 UTC (rev 12087)
@@ -94,6 +94,7 @@
 #include "qgsbookmarks.h"
 #include "qgsclipboard.h"
 #include "qgscomposer.h"
+#include "qgscomposermanager.h"
 #include "qgsconfigureshortcutsdialog.h"
 #include "qgscoordinatetransform.h"
 #include "qgscursors.h"
@@ -592,11 +593,15 @@
   mActionSaveMapAsImage->setStatusTip( tr( "Save map as image" ) );
   connect( mActionSaveMapAsImage, SIGNAL( triggered() ), this, SLOT( saveMapAsImage() ) );
 
-  mActionNewPrintComposer = new QAction( getThemeIcon( "mActionFilePrint.png" ), tr( "&New Print Composer" ), this );
+  mActionNewPrintComposer = new QAction( getThemeIcon( "mActionNewComposer.png" ), tr( "&New Print Composer" ), this );
   shortcuts->registerAction( mActionNewPrintComposer, tr( "Ctrl+P", "New Print Composer" ) );
   mActionNewPrintComposer->setStatusTip( tr( "New Print Composer" ) );
   connect( mActionNewPrintComposer, SIGNAL( triggered() ), this, SLOT( newPrintComposer() ) );
 
+  mActionShowComposerManager = new QAction( getThemeIcon( "mActionFilePrint.png" ), tr( "Composer manager..." ), this );
+  mActionShowComposerManager->setStatusTip( tr( "Composer manager" ) );
+  connect( mActionShowComposerManager, SIGNAL( triggered() ), this, SLOT( showComposerManager() ) );
+
   mActionExit = new QAction( getThemeIcon( "mActionFileExit.png" ), tr( "Exit" ), this );
   shortcuts->registerAction( mActionExit, tr( "Ctrl+Q", "Exit QGIS" ) );
   mActionExit->setStatusTip( tr( "Exit QGIS" ) );
@@ -1174,6 +1179,7 @@
   }
 
   mFileMenu->addAction( mActionNewPrintComposer );
+  mFileMenu->addAction( mActionShowComposerManager );
   mPrintComposersMenu = mFileMenu->addMenu( tr( "Print Composers" ) );
   mActionFileSeparator4 = mFileMenu->addSeparator();
 
@@ -1374,6 +1380,7 @@
   mFileToolBar->addAction( mActionSaveProject );
   mFileToolBar->addAction( mActionSaveProjectAs );
   mFileToolBar->addAction( mActionNewPrintComposer );
+  mFileToolBar->addAction( mActionShowComposerManager );
   mToolbarMenu->addAction( mFileToolBar->toggleViewAction() );
   //
   // Layer Toolbar
@@ -1641,6 +1648,7 @@
   mActionSaveProject->setIcon( getThemeIcon( "/mActionFileSave.png" ) );
   mActionSaveProjectAs->setIcon( getThemeIcon( "/mActionFileSaveAs.png" ) );
   mActionNewPrintComposer->setIcon( getThemeIcon( "/mActionNewComposer.png" ) );
+  mActionShowComposerManager->setIcon( getThemeIcon( "/mActionFilePrint.png" ) );
   mActionSaveMapAsImage->setIcon( getThemeIcon( "/mActionSaveMapAsImage.png" ) );
   mActionExit->setIcon( getThemeIcon( "/mActionFileExit.png" ) );
   mActionAddOgrLayer->setIcon( getThemeIcon( "/mActionAddOgrLayer.png" ) );
@@ -1709,10 +1717,10 @@
   mActionAddToOverview->setIcon( getThemeIcon( "/mActionInOverview.png" ) );
 
   //change themes of all composers
-  QMap<QString, QgsComposer*>::iterator composerIt = mPrintComposers.begin();
+  QSet<QgsComposer*>::iterator composerIt = mPrintComposers.begin();
   for ( ; composerIt != mPrintComposers.end(); ++composerIt )
   {
-    composerIt.value()->setupTheme();
+    ( *composerIt )->setupTheme();
   }
 
   emit currentThemeChanged( theThemeName );
@@ -3701,18 +3709,15 @@
     return;
   }
 
-  //ask user about name
-  mLastComposerId++;
-  QString composerId = QString( tr("Map Composer %1").arg( mLastComposerId ) );
-  //create new composer object
-  QgsComposer* newComposerObject = new QgsComposer( this, composerId );
-  //add it to the map of existing print composers
-  mPrintComposers.insert( composerId, newComposerObject );
-  //and place action into print composers menu
-  mPrintComposersMenu->addAction( newComposerObject->windowAction() );
-  newComposerObject->open();
+  createNewComposer();
 }
 
+void QgisApp::showComposerManager()
+{
+  QgsComposerManager m( this, 0, Qt::WindowStaysOnTopHint );
+  m.exec();
+}
+
 void QgisApp::saveMapAsImage()
 {
   //create a map to hold the QImageIO names and the filter names
@@ -4191,25 +4196,25 @@
   return unionGeom;
 }
 
-QList<QgsComposer*> QgisApp::printComposers()
+QgsComposer* QgisApp::createNewComposer()
 {
-  QList<QgsComposer*> composerList;
-  QMap<QString, QgsComposer*>::iterator it = mPrintComposers.begin();
-  for ( ; it != mPrintComposers.end(); ++it )
-  {
-    composerList.push_back( it.value() );
-  }
-  return composerList;
+  //ask user about name
+  mLastComposerId++;
+  //create new composer object
+  QgsComposer* newComposerObject = new QgsComposer( this, tr( "Composer %1" ).arg( mLastComposerId ) );
+  //add it to the map of existing print composers
+  mPrintComposers.insert( newComposerObject );
+  //and place action into print composers menu
+  mPrintComposersMenu->addAction( newComposerObject->windowAction() );
+  newComposerObject->open();
+  return newComposerObject;
 }
 
-void QgisApp::checkOutComposer( QgsComposer* c )
+void QgisApp::deleteComposer( QgsComposer* c )
 {
-  if ( !c )
-  {
-    return;
-  }
-  mPrintComposers.remove( c->id() );
+  mPrintComposers.remove( c );
   mPrintComposersMenu->removeAction( c->windowAction() );
+  delete c;
 }
 
 bool QgisApp::loadComposersFromProject( const QString& projectFilePath )
@@ -4231,24 +4236,23 @@
   QDomNodeList composerNodes = projectDom.elementsByTagName( "Composer" );
   for ( int i = 0; i < composerNodes.size(); ++i )
   {
-    QgsComposer* composer = new QgsComposer( this, "" );
+    ++mLastComposerId;
+    QgsComposer* composer = new QgsComposer( this, tr( "Composer %1" ).arg( mLastComposerId ) );
     composer->readXML( composerNodes.at( i ).toElement(), projectDom );
-    mPrintComposers.insert( composer->id(), composer );
+    mPrintComposers.insert( composer );
     mPrintComposersMenu->addAction( composer->windowAction() );
     composer->showMinimized();
     composer->zoomFull();
   }
-  mLastComposerId = composerNodes.size();
-
   return true;
 }
 
 void QgisApp::deletePrintComposers()
 {
-  QMap<QString, QgsComposer*>::iterator it = mPrintComposers.begin();
+  QSet<QgsComposer*>::iterator it = mPrintComposers.begin();
   for ( ; it != mPrintComposers.end(); ++it )
   {
-    delete it.value();
+    delete( *it );
   }
   mPrintComposers.clear();
   mLastComposerId = 0;

Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/app/qgisapp.h	2009-11-11 17:05:16 UTC (rev 12087)
@@ -195,11 +195,13 @@
     void removeWindow( QAction *action );
 
     /**Returns the print composers*/
-    QList<QgsComposer*> printComposers();
-    /**Unregisters a composer instance but does _not_ delete it. This method is usually called from within QgsComposer::closeEvent before
-    the composer deletes itself using the Qt::WA_DeleteOnClose flag*/
-    void checkOutComposer( QgsComposer* c );
+    QSet<QgsComposer*> printComposers() const {return mPrintComposers;}
+    /**Creates a new composer and returns a pointer to it*/
+    QgsComposer* createNewComposer();
+    /**Deletes a composer and removes entry from Set*/
+    void deleteComposer( QgsComposer* c );
 
+
     //! Actions to be inserted in menus and toolbars
     QAction *actionNewProject() { return mActionNewProject; }
     QAction *actionOpenProject() { return mActionOpenProject; }
@@ -450,6 +452,7 @@
     void newVectorLayer();
     //! Print the current map view frame
     void newPrintComposer();
+    void showComposerManager();
     //! Add all loaded layers into the overview - overides qgisappbase method
     void addAllToOverview();
     //! Remove all loaded layers from the overview - overides qgisappbase method
@@ -727,6 +730,7 @@
     QAction *mActionProjectProperties;
     QAction *mActionFileSeparator3;
     QAction *mActionNewPrintComposer;
+    QAction *mActionShowComposerManager;
     QAction *mActionFileSeparator4;
     QAction *mActionExit;
 
@@ -947,7 +951,7 @@
     //! list of recently opened/saved project files
     QStringList mRecentProjectPaths;
     //! Print composers of this project, accessible by id string
-    QMap<QString, QgsComposer*> mPrintComposers;
+    QSet<QgsComposer*> mPrintComposers;
     //! How to determine the number of decimal places used to
     //! display the mouse position
     bool mMousePrecisionAutomatic;

Modified: trunk/qgis/src/app/qgisappinterface.cpp
===================================================================
--- trunk/qgis/src/app/qgisappinterface.cpp	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/app/qgisappinterface.cpp	2009-11-11 17:05:16 UTC (rev 12087)
@@ -152,9 +152,9 @@
   QList<QgsComposerView*> composerViewList;
   if ( qgis )
   {
-    QList<QgsComposer*> composerList = qgis->printComposers();
-    QList<QgsComposer*>::iterator it = composerList.begin();
-    for ( ; it != composerList.end(); ++it )
+    const QSet<QgsComposer*> composerList = qgis->printComposers();
+    QSet<QgsComposer*>::const_iterator it = composerList.constBegin();
+    for ( ; it != composerList.constEnd(); ++it )
     {
       if ( *it )
       {

Modified: trunk/qgis/src/ui/qgscomposerbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposerbase.ui	2009-11-11 10:38:40 UTC (rev 12086)
+++ trunk/qgis/src/ui/qgscomposerbase.ui	2009-11-11 17:05:16 UTC (rev 12087)
@@ -20,8 +20,8 @@
    <property name="mouseTracking">
     <bool>true</bool>
    </property>
-   <layout class="QGridLayout">
-    <item row="1" column="0">
+   <layout class="QGridLayout" name="gridLayout">
+    <item row="0" column="0">
      <widget class="QSplitter" name="mSplitter">
       <property name="mouseTracking">
        <bool>true</bool>
@@ -133,6 +133,13 @@
       </widget>
      </widget>
     </item>
+    <item row="1" column="0">
+     <widget class="QDialogButtonBox" name="mButtonBox">
+      <property name="standardButtons">
+       <set>QDialogButtonBox::Close</set>
+      </property>
+     </widget>
+    </item>
    </layout>
   </widget>
   <widget class="QToolBar" name="toolBar">

Added: trunk/qgis/src/ui/qgscomposermanagerbase.ui
===================================================================
--- trunk/qgis/src/ui/qgscomposermanagerbase.ui	                        (rev 0)
+++ trunk/qgis/src/ui/qgscomposermanagerbase.ui	2009-11-11 17:05:16 UTC (rev 12087)
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>QgsComposerManagerBase</class>
+ <widget class="QDialog" name="QgsComposerManagerBase">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>333</width>
+    <height>198</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Composer manager</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0" rowspan="5">
+    <widget class="QListWidget" name="mComposerListWidget"/>
+   </item>
+   <item row="0" column="1">
+    <widget class="QPushButton" name="mAddButton">
+     <property name="text">
+      <string>Add</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="QPushButton" name="mRemoveButton">
+     <property name="text">
+      <string>Remove</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1">
+    <widget class="QPushButton" name="mRenamePushButton">
+     <property name="text">
+      <string>Rename</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1">
+    <widget class="QPushButton" name="mShowPushButton">
+     <property name="text">
+      <string>Show</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="1">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>50</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="5" column="0" colspan="2">
+    <widget class="QDialogButtonBox" name="mButtonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Close</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>mButtonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>QgsComposerManagerBase</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>251</x>
+     <y>193</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>mButtonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>QgsComposerManagerBase</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>251</x>
+     <y>193</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>



More information about the QGIS-commit mailing list