Skip to content
Permalink
Browse files

resolve another conflict

  • Loading branch information
mhugent committed Jul 2, 2011
1 parent 86e63db commit 92df0292ccb2a74afd74880dddda7515682fa9ce
@@ -20,6 +20,7 @@
#include "qgscomposerlegenditemdialog.h"
#include "qgscomposerlegendlayersdialog.h"
#include "qgscomposeritemwidget.h"
#include "qgscomposermap.h"
#include <QFontDialog>

#include "qgsapplegendinterface.h"
@@ -88,6 +89,17 @@ void QgsComposerLegendWidget::setGuiElements()
{
mCheckBoxAutoUpdate->setChecked( mLegend->model()->autoUpdate() );
}
refreshMapComboBox();

const QgsComposerMap* map = mLegend->composerMap();
if ( map )
{
mMapComboBox->setCurrentIndex( mMapComboBox->findData( map->id() ) );
}
else
{
mMapComboBox->setCurrentIndex( mMapComboBox->findData( -1 ) );
}

blockAllSignals( false );
}
@@ -391,6 +403,43 @@ void QgsComposerLegendWidget::on_mCheckBoxAutoUpdate_stateChanged( int state )
}
}

void QgsComposerLegendWidget::on_mMapComboBox_currentIndexChanged( int index )
{
if ( !mLegend )
{
return;
}

QVariant itemData = mMapComboBox->itemData( index );
if ( itemData.type() == QVariant::Invalid )
{
return;
}

const QgsComposition* comp = mLegend->composition();
if ( !comp )
{
return;
}

int mapNr = itemData.toInt();
if ( mapNr < 0 )
{
mLegend->setComposerMap( 0 );
}
else
{
const QgsComposerMap* map = comp->getComposerMapById( mapNr );
if ( map )
{
mLegend->beginCommand( tr( "Legend map changed" ) );
mLegend->setComposerMap( map );
mLegend->update();
mLegend->endCommand();
}
}
}

void QgsComposerLegendWidget::on_mAddToolButton_clicked()
{
if ( !mLegend )
@@ -442,16 +491,21 @@ void QgsComposerLegendWidget::on_mRemoveToolButton_clicked()
return;
}

QModelIndex currentIndex = mItemTreeView->currentIndex();
if ( !currentIndex.isValid() )
mLegend->beginCommand( "Legend item removed" );

QItemSelectionModel* selectionModel = mItemTreeView->selectionModel();
if ( !selectionModel )
{
return;
}

QModelIndex parentIndex = currentIndex.parent();
QModelIndexList selection = selectionModel->selectedIndexes();
for ( int i = selection.size() - 1; i >= 0; --i )
{
QModelIndex parentIndex = selection.at( i ).parent();
itemModel->removeRow( selection.at( i ).row(), parentIndex );
}

mLegend->beginCommand( "Legend item removed" );
itemModel->removeRow( currentIndex.row(), parentIndex );
mLegend->adjustBoxSize();
mLegend->update();
mLegend->endCommand();
@@ -583,4 +637,47 @@ void QgsComposerLegendWidget::blockAllSignals( bool b )
{
mItemTreeView->blockSignals( b );
mCheckBoxAutoUpdate->blockSignals( b );
mMapComboBox->blockSignals( b );
}

void QgsComposerLegendWidget::refreshMapComboBox()
{
if ( !mLegend )
{
return;
}

const QgsComposition* composition = mLegend->composition();
if ( !composition )
{
return;
}

//save current entry
int currentMapId = mMapComboBox->itemData( mMapComboBox->currentIndex() ).toInt();
mMapComboBox->clear();

QList<const QgsComposerMap*> availableMaps = composition->composerMapItems();
QList<const QgsComposerMap*>::const_iterator mapItemIt = availableMaps.constBegin();
for ( ; mapItemIt != availableMaps.constEnd(); ++mapItemIt )
{
mMapComboBox->addItem( tr( "Map %1" ).arg(( *mapItemIt )->id() ), ( *mapItemIt )->id() );
}
mMapComboBox->addItem( tr( "None" ), -1 );

//the former entry is not there anymore
int entry = mMapComboBox->findData( currentMapId );
if ( entry == -1 )
{
}
else
{
mMapComboBox->setCurrentIndex( entry );
}
}

void QgsComposerLegendWidget::showEvent( QShowEvent * event )
{
refreshMapComboBox();
QWidget::showEvent( event );
}
@@ -51,6 +51,7 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mItemFontButton_clicked();
void on_mBoxSpaceSpinBox_valueChanged( double d );
void on_mCheckBoxAutoUpdate_stateChanged( int state );
void on_mMapComboBox_currentIndexChanged( int index );

//item manipulation
void on_mMoveDownToolButton_clicked();
@@ -62,13 +63,17 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mUpdateAllPushButton_clicked();
void on_mAddGroupButton_clicked();

protected:
void showEvent( QShowEvent * event );

private slots:
/**Sets GUI according to state of mLegend*/
void setGuiElements();

private:
QgsComposerLegendWidget();
void blockAllSignals( bool b );
void refreshMapComboBox();


QgsComposerLegend* mLegend;
@@ -17,6 +17,7 @@

#include "qgscomposerlegend.h"
#include "qgscomposerlegenditem.h"
#include "qgscomposermap.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaprenderer.h"
@@ -33,7 +34,7 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
, mBoxSpace( 2 )
, mLayerSpace( 2 )
, mSymbolSpace( 2 )
, mIconLabelSpace( 2 )
, mIconLabelSpace( 2 ), mComposerMap( 0 )
{
//QStringList idList = layerIdList();
//mLegendModel.setLayerSet( idList );
@@ -50,7 +51,7 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
connect( &mLegendModel, SIGNAL( layersChanged() ), this, SLOT( synchronizeWithModel() ) );
}

QgsComposerLegend::QgsComposerLegend(): QgsComposerItem( 0 )
QgsComposerLegend::QgsComposerLegend(): QgsComposerItem( 0 ), mComposerMap( 0 )
{

}
@@ -390,23 +391,49 @@ void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double curren
rasterScaleFactor = ( paintDevice->logicalDpiX() + paintDevice->logicalDpiY() ) / 2.0 / 25.4;
}

//consider relation to composer map for symbol sizes in mm
bool sizeInMapUnits = s->outputUnit() == QgsSymbolV2::MapUnit;
double mmPerMapUnit = 1;
if ( mComposerMap )
{
mmPerMapUnit = mComposerMap->mapUnitsToMM();
}
QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( s );

//Consider symbol size for point markers
double height = mSymbolHeight;
double width = mSymbolWidth;
if ( s->type() == QgsSymbolV2::Marker )
double size = 0;

if ( markerSymbol )
{
QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( s );
if ( markerSymbol )
size = markerSymbol->size();
height = size;
width = size;
if ( mComposerMap && sizeInMapUnits )
{
height = markerSymbol->size();
width = markerSymbol->size();
height *= mmPerMapUnit;
width *= mmPerMapUnit;
markerSymbol->setSize( width );
}
}

p->save();
p->translate( currentXPosition, currentYCoord );
p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );

if ( markerSymbol && sizeInMapUnits )
{
s->setOutputUnit( QgsSymbolV2::MM );
}
s->drawPreviewIcon( p, QSize( width * rasterScaleFactor, height * rasterScaleFactor ) );

if ( markerSymbol && sizeInMapUnits )
{
s->setOutputUnit( QgsSymbolV2::MapUnit );
markerSymbol->setSize( size );
}

p->restore();
currentXPosition += width;
symbolHeight = height;
@@ -605,6 +632,11 @@ bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
composerLegendElem.setAttribute( "symbolWidth", mSymbolWidth );
composerLegendElem.setAttribute( "symbolHeight", mSymbolHeight );

if ( mComposerMap )
{
composerLegendElem.setAttribute( "map", mComposerMap->id() );
}

//write model properties
mLegendModel.writeXML( composerLegendElem, doc );

@@ -655,6 +687,12 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
mSymbolWidth = itemElem.attribute( "symbolWidth", "7.0" ).toDouble();
mSymbolHeight = itemElem.attribute( "symbolHeight", "14.0" ).toDouble();

//composer map
if ( !itemElem.attribute( "map" ).isEmpty() )
{
mComposerMap = mComposition->getComposerMapById( itemElem.attribute( "map" ).toInt() );
}

//read model properties
QDomNodeList modelNodeList = itemElem.elementsByTagName( "Model" );
if ( modelNodeList.size() > 0 )
@@ -674,3 +712,15 @@ bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument
emit itemChanged();
return true;
}

void QgsComposerLegend::setComposerMap( const QgsComposerMap* map )
{
mComposerMap = map;
QObject::connect( map, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
}

void QgsComposerLegend::invalidateCurrentMap()
{
disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
mComposerMap = 0;
}
@@ -25,6 +25,7 @@ class QgsSymbol;
class QgsSymbolV2;
class QgsComposerGroupItem;
class QgsComposerLayerItem;
class QgsComposerMap;

/** \ingroup MapComposer
* A legend that can be placed onto a map composition
@@ -86,6 +87,9 @@ class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
double symbolHeight() const {return mSymbolHeight;}
void setSymbolHeight( double h ) {mSymbolHeight = h;}

void setComposerMap( const QgsComposerMap* map );
const QgsComposerMap* composerMap() const { return mComposerMap; }

/**Updates the model and all legend entries*/
void updateLegend();

@@ -104,6 +108,8 @@ class CORE_EXPORT QgsComposerLegend: public QgsComposerItem
public slots:
/**Data changed*/
void synchronizeWithModel();
/**Sets mCompositionMap to 0 if the map is deleted*/
void invalidateCurrentMap();

protected:
QString mTitle;
@@ -129,6 +135,9 @@ class CORE_EXPORT QgsComposerLegend: public QgsComposerItem

QgsLegendModel mLegendModel;

/**Reference to map (because symbols are sometimes in map units)*/
const QgsComposerMap* mComposerMap;


private:
QgsComposerLegend(); //forbidden
@@ -260,6 +260,9 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
bool drawCanvasItems() const { return mDrawCanvasItems; }

/**Returns the conversion factor map units -> mm*/
double mapUnitsToMM() const;

signals:
void extentChanged();

@@ -390,8 +393,6 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
void mapPolygon( QPolygonF& poly ) const;
/**Calculates the extent to request and the yShift of the top-left point in case of rotation.*/
void requestedExtent( QgsRectangle& extent ) const;
/**Returns the conversion factor map units -> mm*/
double mapUnitsToMM() const;
/**Scales a composer map shift (in MM) and rotates it by mRotation
@param xShift in: shift in x direction (in item units), out: xShift in map units
@param yShift in: shift in y direction (in item units), out: yShift in map units*/
@@ -544,7 +544,7 @@ void QgsComposerView::addComposerMap( QgsComposerMap* map )

void QgsComposerView::addComposerScaleBar( QgsComposerScaleBar* scaleBar )
{
//take first available map...
//take first available map
QList<const QgsComposerMap*> mapItemList = composition()->composerMapItems();
if ( mapItemList.size() > 0 )
{
@@ -561,6 +561,12 @@ void QgsComposerView::addComposerScaleBar( QgsComposerScaleBar* scaleBar )

void QgsComposerView::addComposerLegend( QgsComposerLegend* legend )
{
//take first available map
QList<const QgsComposerMap*> mapItemList = composition()->composerMapItems();
if ( mapItemList.size() > 0 )
{
legend->setComposerMap( mapItemList.at( 0 ) );
}
scene()->addItem( legend );
emit composerLegendAdded( legend );
scene()->clearSelection();

0 comments on commit 92df029

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