Skip to content
Permalink
Browse files

Show composer maps on demand after project loading

  • Loading branch information
mhugent committed May 16, 2011
1 parent 03a2fe7 commit ad95cce7068f4480dc5802b13a57c959dd891535
@@ -253,6 +253,9 @@ class QgsComposerItem: QObject, QGraphicsRectItem

double rotation() const;

/**Updates item, with the possibility to do custom update for subclasses*/
virtual void updateItem();

public slots:
virtual void setRotation( double r);

@@ -94,7 +94,7 @@ class QgsComposerMap : QgsComposerItem
/**Sets new Extent and changes width, height (and implicitely also scale)*/
void setNewExtent( const QgsRectangle& extent );

PreviewMode previewMode();
PreviewMode previewMode() const;
void setPreviewMode( PreviewMode m );

/**Getter for flag that determines if the stored layer set should be used or the current layer set of the qgis mapcanvas
@@ -222,6 +222,10 @@ class QgsComposerMap : QgsComposerItem
void setCrossLength(double l);
double crossLength();

void setMapRotation( double r );

void updateItem();

public slots:

/**Called if map canvas has changed*/
@@ -1123,6 +1123,22 @@ void QgsComposer::resizeEvent( QResizeEvent *e )
saveWindowState();
}

void QgsComposer::showEvent( QShowEvent* event )
{
if ( event->spontaneous() ) //event from the window system
{
//go through maps and restore original preview modes (show on demand after loading from project file)
QMap< QgsComposerMap*, QgsComposerMap::PreviewMode >::iterator mapIt = mMapsToRestore.begin();
for ( ; mapIt != mMapsToRestore.end(); ++mapIt )
{
mapIt.key()->setPreviewMode( mapIt.value() );
mapIt.key()->cache();
mapIt.key()->update();
}
mMapsToRestore.clear();
}
}

void QgsComposer::saveWindowState()
{
QSettings settings;
@@ -1169,6 +1185,14 @@ void QgsComposer::writeXML( QDomNode& parentNode, QDomDocument& doc )
QDomElement composerElem = doc.createElement( "Composer" );
composerElem.setAttribute( "title", mTitle );

//change preview mode of minimised / hidden maps (show contents only on demand)
QMap< QgsComposerMap*, QgsComposerMap::PreviewMode >::iterator mapIt = mMapsToRestore.begin();
for ( ; mapIt != mMapsToRestore.end(); ++mapIt )
{
mapIt.key()->setPreviewMode( mapIt.value() );
}
mMapsToRestore.clear();

//store if composer is open or closed
if ( isVisible() )
{
@@ -1283,6 +1307,20 @@ void QgsComposer::readXML( const QDomElement& composerElem, const QDomDocument&
QDomElement currentComposerMapElem = composerMapList.at( i ).toElement();
QgsComposerMap* newMap = new QgsComposerMap( mComposition );
newMap->readXML( currentComposerMapElem, doc );

if ( fromTemplate ) //show map directly if loaded from template
{
newMap->updateItem();
}
else //show map only on demand if loaded from project
{
if ( newMap->previewMode() != QgsComposerMap::Rectangle )
{
mMapsToRestore.insert( newMap, newMap->previewMode() );
newMap->setPreviewMode( QgsComposerMap::Rectangle );
}
}

addComposerMap( newMap );
mComposition->addItem( newMap );
mComposition->update();
@@ -1518,6 +1556,12 @@ void QgsComposer::deleteItem( QgsComposerItem* item )
//the item itself is not deleted here (usually, this is done in the destructor of QgsAddRemoveItemCommand)
delete( it.value() );
mItemWidgetMap.remove( it.key() );

QgsComposerMap* map = dynamic_cast<QgsComposerMap*>( item );
if ( map )
{
mMapsToRestore.remove( map );
}
}

void QgsComposer::setSelectionTool()
@@ -18,15 +18,14 @@
#ifndef QGSCOMPOSER_H
#define QGSCOMPOSER_H
#include "ui_qgscomposerbase.h"
#include "qgscomposeritem.h"
#include "qgscomposermap.h"
#include "qgscontexthelp.h"
#include <QPrinter>

class QgisApp;
class QgsComposerArrow;
class QgsComposerLabel;
class QgsComposerLegend;
class QgsComposerMap;
class QgsComposerPicture;
class QgsComposerScaleBar;
class QgsComposerShape;
@@ -93,6 +92,8 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Resize event
virtual void resizeEvent( QResizeEvent * );

virtual void showEvent( QShowEvent* event );

#ifdef Q_WS_MAC
//! Change event (update window menu on ActivationChange)
virtual void changeEvent( QEvent * );
@@ -321,6 +322,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QPrinter mPrinter;

QUndoView* mUndoView;

//! We load composer map content from project xml only on demand. Therefore we need to store the real preview mode type
QMap< QgsComposerMap*, QgsComposerMap::PreviewMode > mMapsToRestore;
};

#endif
@@ -568,6 +568,7 @@ void QgsComposerItem::changeItemRectangle( const QPointF& currentPosition, const
changeComposerItem->setSceneRect( QRectF( originalItem->transform().dx() + moveRectX,
originalItem->transform().dy() + moveRectY,
originalItem->rect().width(), originalItem->rect().height() ) );
changeComposerItem->updateItem();
}
}
return;
@@ -587,6 +588,7 @@ void QgsComposerItem::changeItemRectangle( const QPointF& currentPosition, const
{
changeComposerItem->setSceneRect( QRectF( originalItem->transform().dx() + mx, originalItem->transform().dy() + my,
originalItem->rect().width() + rx, originalItem->rect().height() + ry ) );
changeComposerItem->updateItem();
}
}

@@ -217,6 +217,9 @@ class CORE_EXPORT QgsComposerItem: public QObject, public QGraphicsRectItem

double rotation() const {return mRotation;}

/**Updates item, with the possibility to do custom update for subclasses*/
virtual void updateItem() { QGraphicsRectItem::update(); }

public slots:
virtual void setRotation( double r );
void repaint();
@@ -390,6 +390,10 @@ void QgsComposerMap::resize( double dx, double dy )
QRectF currentRect = rect();
QRectF newSceneRect = QRectF( transform().dx(), transform().dy(), currentRect.width() + dx, currentRect.height() + dy );
setSceneRect( newSceneRect );
if ( mPreviewMode != QgsComposerMap::Rectangle )
{
cache();
}
}

void QgsComposerMap::moveContent( double dx, double dy )
@@ -489,10 +493,6 @@ void QgsComposerMap::setSceneRect( const QRectF& rectangle )
mExtent = QgsRectangle( mExtent.xMinimum(), mExtent.yMinimum(), mExtent.xMaximum(), mExtent.yMinimum() + newHeight );
mCacheUpdated = false;

if ( mPreviewMode != Rectangle )
{
cache();
}
updateBoundingRect();
update();
emit itemChanged();
@@ -513,6 +513,10 @@ void QgsComposerMap::setNewExtent( const QgsRectangle& extent )
double newHeight = currentRect.width() * extent.height() / extent.width();

setSceneRect( QRectF( transform().dx(), transform().dy(), currentRect.width(), newHeight ) );
if ( mPreviewMode != QgsComposerMap::Rectangle )
{
cache();
}
}

void QgsComposerMap::setNewScale( double scaleDenominator )
@@ -545,6 +549,15 @@ void QgsComposerMap::setMapRotation( double r )
emit rotationChanged( r );
}

void QgsComposerMap::updateItem()
{
if ( mPreviewMode != QgsComposerMap::Rectangle && !mCacheUpdated )
{
cache();
}
QgsComposerItem::updateItem();
}

bool QgsComposerMap::containsWMSLayer() const
{
if ( !mMapRenderer )
@@ -125,7 +125,7 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
/**Sets new Extent and changes width, height (and implicitely also scale)*/
void setNewExtent( const QgsRectangle& extent );

PreviewMode previewMode() {return mPreviewMode;}
PreviewMode previewMode() const {return mPreviewMode;}
void setPreviewMode( PreviewMode m ) {mPreviewMode = m;}

/**Getter for flag that determines if the stored layer set should be used or the current layer set of the qgis mapcanvas
@@ -254,6 +254,8 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem

void setMapRotation( double r );

void updateItem();

/**Sets canvas pointer (necessary to query and draw map canvas items)*/
void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }

0 comments on commit ad95cce

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