Skip to content
Permalink
Browse files
update composer legend on layer level
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9190 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Aug 27, 2008
1 parent 01ebd30 commit 8949da81d477a5f6416b46a97878e4ff5bbd450c
@@ -340,3 +340,42 @@ void QgsComposerLegendWidget::on_mEditPushButton_clicked()
mLegend->update();
}
}

void QgsComposerLegendWidget::on_mUpdatePushButton_clicked()
{
//get current item
QStandardItemModel* itemModel = dynamic_cast<QStandardItemModel*>( mItemTreeView->model() );
if ( !itemModel )
{
return;
}

//get current item
QModelIndex currentIndex = mItemTreeView->currentIndex();
if ( !currentIndex.isValid() )
{
return;
}

QStandardItem* currentItem = itemModel->itemFromIndex( currentIndex );
if ( !currentItem )
{
return;
}

QModelIndex parentIndex = currentIndex.parent();
if ( !parentIndex.isValid() ) // a layer item
{
QString mapLayerId = currentItem->data().toString();
mLegend->model()->updateLayer(mapLayerId);
mLegend->update();
}
}

void QgsComposerLegendWidget::on_mUpdateAllPushButton_clicked()
{
if(mLegend)
{
mLegend->updateLegend();
}
}
@@ -52,6 +52,8 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
void on_mMoveUpPushButton_clicked();
void on_mRemovePushButton_clicked();
void on_mEditPushButton_clicked();
void on_mUpdatePushButton_clicked();
void on_mUpdateAllPushButton_clicked();

private:
QgsComposerLegendWidget();
@@ -438,6 +438,13 @@ QFont QgsComposerLegend::itemFont() const
return mItemFont;
}

void QgsComposerLegend::updateLegend()
{
mLegendModel.setLayerSet(layerIdList());
adjustBoxSize();
update();
}

bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc )
{
if ( elem.isNull() )
@@ -78,6 +78,9 @@ class CORE_EXPORT QgsComposerLegend: public QObject, public QgsComposerItem
double symbolHeight() const {return mSymbolHeight;}
void setSymbolHeight( double h ) {mSymbolHeight = h;}

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

/** stores state in Dom node
* @param elem is Dom element corresponding to 'Composer' tag
* @param temp write template file
@@ -230,6 +230,7 @@ void QgsLegendModel::removeAllSymbols()
mSymbols.clear();
}

#if 0
void QgsLegendModel::updateLayerEntries( const QStringList& newLayerIds )
{
if ( !invisibleRootItem() )
@@ -276,6 +277,57 @@ void QgsLegendModel::updateLayerEntries( const QStringList& newLayerIds )

mLayerIds = newLayerIds;
}
#endif //0

void QgsLegendModel::updateLayer(const QString& layerId)
{
//find layer item
QStandardItem* layerItem = 0;
QStandardItem* currentLayerItem = 0;

int numRootItems = rowCount();
for ( int i = 0; i < numRootItems ; ++i )
{
currentLayerItem = item( i );
if ( !currentLayerItem )
{
continue;
}

QString currentId = currentLayerItem->data().toString();
if ( currentId == layerId )
{
layerItem = currentLayerItem;
break;
}
}

if(layerItem)
{
QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer(layerId);
if(mapLayer)
{
//delete all the entries under layer item
for(int i = rowCount() - 1; i >= 0; --i)
{
layerItem->removeRow(i);
}

//and add the new ones...
switch(mapLayer->type())
{
case QgsMapLayer::VECTOR:
addVectorLayerItems(layerItem, mapLayer);
break;
case QgsMapLayer::RASTER:
addRasterLayerItem(layerItem, mapLayer);
break;
default:
break;
}
}
}
}

void QgsLegendModel::removeLayer( const QString& layerId )
{
@@ -41,7 +41,10 @@ class CORE_EXPORT QgsLegendModel: public QStandardItemModel

void setLayerSet( const QStringList& layerIds );
/**Apply added or removed layers to the model*/
void updateLayerEntries( const QStringList& newLayerIds );
//void updateLayerEntries( const QStringList& newLayerIds );

/**Updates the symbology of a single layer*/
void updateLayer(const QString& layerId);

bool writeXML( QDomElement& composerLegendElem, QDomDocument& doc );
bool readXML( const QDomElement& legendModelElem, const QDomDocument& doc );
@@ -5,8 +5,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>496</width>
<height>626</height>
<width>560</width>
<height>537</height>
</rect>
</property>
<property name="sizePolicy" >
@@ -183,19 +183,20 @@
</widget>
</item>
<item row="0" column="4" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
<widget class="QPushButton" name="mUpdatePushButton" >
<property name="text" >
<string>update</string>
</property>
<property name="sizeHint" >
<size>
<width>121</width>
<height>33</height>
</size>
</widget>
</item>
<item row="0" column="5" >
<widget class="QPushButton" name="mUpdateAllPushButton" >
<property name="text" >
<string>update all</string>
</property>
</spacer>
</widget>
</item>
<item row="1" column="0" colspan="5" >
<item row="1" column="0" colspan="6" >
<widget class="QTreeView" name="mItemTreeView" >
<property name="headerHidden" stdset="0" >
<bool>true</bool>

0 comments on commit 8949da8

Please sign in to comment.