Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Added possibility to keep the current layers in a composer …
…map even if further layers are added to the main map

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10963 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 21, 2009
1 parent 2061da4 commit b81773c
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 95 deletions.
32 changes: 32 additions & 0 deletions src/app/composer/qgscomposermapwidget.cpp
Expand Up @@ -252,6 +252,18 @@ void QgsComposerMapWidget::updateGuiElements()
mXMaxLineEdit->setText( QString::number( composerMapExtent.xMaximum(), 'f', 3 ) );
mYMinLineEdit->setText( QString::number( composerMapExtent.yMinimum(), 'f', 3 ) );
mYMaxLineEdit->setText( QString::number( composerMapExtent.yMaximum(), 'f', 3 ) );

//keep layer list check box
mKeepLayerListCheckBox->blockSignals(true);
if(mComposerMap->keepLayerSet())
{
mKeepLayerListCheckBox->setCheckState(Qt::Checked);
}
else
{
mKeepLayerListCheckBox->setCheckState(Qt::Unchecked);
}
mKeepLayerListCheckBox->blockSignals(false);
}
}

Expand Down Expand Up @@ -298,3 +310,23 @@ void QgsComposerMapWidget::on_mUpdatePreviewButton_clicked()

mUpdatePreviewButton->setEnabled( true );
}

void QgsComposerMapWidget::on_mKeepLayerListCheckBox_stateChanged(int state)
{
if(!mComposerMap)
{
return;
}

if(state == Qt::Checked)
{
mComposerMap->storeCurrentLayerSet();
mComposerMap->setKeepLayerSet(true);
}
else
{
QStringList emptyLayerSet;
mComposerMap->setLayerSet(emptyLayerSet);
mComposerMap->setKeepLayerSet(false);
}
}
1 change: 1 addition & 0 deletions src/app/composer/qgscomposermapwidget.h
Expand Up @@ -41,6 +41,7 @@ class QgsComposerMapWidget: public QWidget, private Ui::QgsComposerMapWidgetBase
void on_mScaleLineEdit_editingFinished();
void on_mSetToMapCanvasExtentButton_clicked();
void on_mUpdatePreviewButton_clicked();
void on_mKeepLayerListCheckBox_stateChanged(int state);

void on_mXMinLineEdit_editingFinished();
void on_mXMaxLineEdit_editingFinished();
Expand Down
87 changes: 84 additions & 3 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -42,7 +42,7 @@
int QgsComposerMap::mCurrentComposerId = 0;

QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
: QgsComposerItem( x, y, width, height, composition )
: QgsComposerItem( x, y, width, height, composition ), mKeepLayerSet(false)
{
mComposition = composition;
mMapRenderer = mComposition->mapRenderer();
Expand All @@ -69,7 +69,7 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
}

QgsComposerMap::QgsComposerMap( QgsComposition *composition )
: QgsComposerItem( 0, 0, 10, 10, composition )
: QgsComposerItem( 0, 0, 10, 10, composition ), mKeepLayerSet(false)
{
//Offset
mXOffset = 0.0;
Expand Down Expand Up @@ -113,7 +113,16 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
QgsMapRenderer theMapRenderer;
theMapRenderer.setExtent( extent );
theMapRenderer.setOutputSize( size, dpi );
theMapRenderer.setLayerSet( mMapRenderer->layerSet() );

//use stored layer set or read current set from main canvas
if(mKeepLayerSet)
{
theMapRenderer.setLayerSet(mLayerSet);
}
else
{
theMapRenderer.setLayerSet( mMapRenderer->layerSet() );
}
theMapRenderer.setProjectionsEnabled( mMapRenderer->hasCrsTransformEnabled() );
theMapRenderer.setDestinationSrs( mMapRenderer->destinationSrs() );

Expand Down Expand Up @@ -240,6 +249,7 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i

void QgsComposerMap::updateCachedImage( void )
{
syncLayerSet(); //layer list may have changed
mCacheUpdated = false;
cache();
QGraphicsRectItem::update();
Expand Down Expand Up @@ -489,6 +499,15 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerMapElem.setAttribute( "previewMode", "Rectangle" );
}

if(mKeepLayerSet)
{
composerMapElem.setAttribute( "keepLayerSet", "true");
}
else
{
composerMapElem.setAttribute( "keepLayerSet", "false");
}

//extent
QDomElement extentElem = doc.createElement( "Extent" );
extentElem.setAttribute( "xmin", QString::number( mExtent.xMinimum() ) );
Expand All @@ -497,6 +516,18 @@ bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
extentElem.setAttribute( "ymax", QString::number( mExtent.yMaximum() ) );
composerMapElem.appendChild( extentElem );

//layer set
QDomElement layerSetElem = doc.createElement( "LayerSet" );
QStringList::const_iterator layerIt = mLayerSet.constBegin();
for(; layerIt != mLayerSet.constEnd(); ++layerIt)
{
QDomElement layerElem = doc.createElement( "Layer" );
QDomText layerIdText = doc.createTextNode(*layerIt);
layerElem.appendChild(layerIdText);
layerSetElem.appendChild(layerElem);
}
composerMapElem.appendChild(layerSetElem);

#if 0
// why is saving the map changing anything about the cache?
mCacheUpdated = false;
Expand Down Expand Up @@ -545,6 +576,31 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d
mExtent = QgsRectangle( xmin, ymin, xmax, ymax );
}

//mKeepLayerSet flag
QString keepLayerSetFlag = itemElem.attribute( "keepLayerSet" );
if(keepLayerSetFlag.compare("true", Qt::CaseInsensitive) == 0)
{
mKeepLayerSet = true;
}
else
{
mKeepLayerSet = false;
}

//mLayerSet
QDomNodeList layerSetNodeList = itemElem.elementsByTagName("LayerSet");
QStringList layerSet;
if(layerSetNodeList.size() > 0)
{
QDomElement layerSetElem = layerSetNodeList.at(0).toElement();
QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName("Layer");
for(int i = 0; i < layerIdNodeList.size(); ++i)
{
layerSet << layerIdNodeList.at(i).toElement().text();
}
}
mLayerSet = layerSet;

mDrawing = false;
mNumCachedLayers = 0;
mCacheUpdated = false;
Expand All @@ -565,3 +621,28 @@ bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& d

return true;
}

void QgsComposerMap::storeCurrentLayerSet()
{
if(mMapRenderer)
{
mLayerSet = mMapRenderer->layerSet();
}
}

void QgsComposerMap::syncLayerSet()
{
if(mLayerSet.size() < 1 && !mMapRenderer)
{
return;
}

QStringList currentLayerSet = mMapRenderer->layerSet();
for(int i = mLayerSet.size() - 1; i >= 0; --i)
{
if(!currentLayerSet.contains(mLayerSet.at(i)))
{
mLayerSet.removeAt(i);
}
}
}
25 changes: 25 additions & 0 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -101,6 +101,22 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
PreviewMode previewMode() {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
@note this function was added in version 1.2*/
bool keepLayerSet() const {return mKeepLayerSet;}
/**Setter for flag that determines if the stored layer set should be used or the current layer set of the qgis mapcanvas
@note this function was added in version 1.2*/
void setKeepLayerSet(bool enabled) {mKeepLayerSet = enabled;}

/**Getter for stored layer set that is used if mKeepLayerSet is true
@note this function was added in version 1.2*/
QStringList layerSet() const {return mLayerSet;}
/**Setter for stored layer set that is used if mKeepLayerSet is true
@note this function was added in version 1.2*/
void setLayerSet(const QStringList& layerSet) {mLayerSet = layerSet;}
/**Stores the current layer set of the qgis mapcanvas in mLayerSet*/
void storeCurrentLayerSet();

// Set cache outdated
void setCacheUpdated( bool u = false );

Expand Down Expand Up @@ -176,11 +192,20 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
/**Offset in y direction for showing map cache image*/
double mYOffset;

/**Flag if layers to be displayed should be read from qgis canvas (true) or from stored list in mLayerSet (false)*/
bool mKeepLayerSet;

/**Stored layer list (used if layer live-link mKeepLayerSet is disabled)*/
QStringList mLayerSet;

/**For the generation of new unique ids*/
static int mCurrentComposerId;

/**Establishes signal/slot connection for update in case of layer change*/
void connectUpdateSlot();

/**Removes layer ids from mLayerSet that are no longer present in the qgis main map*/
void syncLayerSet();
};

#endif

0 comments on commit b81773c

Please sign in to comment.