Skip to content
Permalink
Browse files

[FEATURE?] Close composers instead of deleting them. Added composer m…

…anager dialog to manage the existing composer instances

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12087 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 11, 2009
1 parent 6206903 commit ece3cd97d381324e6df965e505683a16230399b8
@@ -77,6 +77,7 @@ SET(QGIS_APP_SRCS
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 @@ SET (QGIS_APP_MOC_HDRS
composer/qgscomposeritemwidget.h
composer/qgscomposerlabelwidget.h
composer/qgscomposerlegendwidget.h
composer/qgscomposermanager.h
composer/qgscomposermapwidget.h
composer/qgscomposerpicturewidget.h
composer/qgscomposerscalebarwidget.h
@@ -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 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& id ): QMainWindow(), mId
toggleActionGroup->addAction( mActionSelectMoveItem );
toggleActionGroup->setExclusive( true );

setWindowTitle( mId );

mActionAddNewMap->setCheckable( true );
mActionAddNewLabel->setCheckable( true );
mActionAddNewLegend->setCheckable( true );
@@ -185,6 +184,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& id ): QMainWindow(), mId
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::open( void )

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 @@ void QgsComposer::showEvent( QShowEvent *event )
}
#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( QDomDocument& doc )
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 QDomDocument& doc )

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 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
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 )
@@ -46,7 +46,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
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 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

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 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! 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 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase

void setSelectionTool();

private slots:

//! Raise, unminimize and activate this window
void activate();

@@ -250,8 +246,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! 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;

0 comments on commit ece3cd9

Please sign in to comment.
You can’t perform that action at this time.