mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Automatic creation of composer legend symbol item icon
This commit is contained in:
parent
fda50ede01
commit
9dd7c73cd0
@ -166,6 +166,18 @@ QgsComposerSymbolV2Item::~QgsComposerSymbolV2Item()
|
||||
delete mSymbolV2;
|
||||
}
|
||||
|
||||
QVariant QgsComposerSymbolV2Item::data( int role ) const
|
||||
{
|
||||
if ( role == Qt::DecorationRole )
|
||||
{
|
||||
if ( mIcon.isNull() )
|
||||
mIcon = QgsSymbolLayerV2Utils::symbolPreviewIcon( mSymbolV2, QSize( 30, 30 ) );
|
||||
return mIcon;
|
||||
}
|
||||
else
|
||||
return QgsComposerBaseSymbolItem::data( role );
|
||||
}
|
||||
|
||||
QStandardItem* QgsComposerSymbolV2Item::clone() const
|
||||
{
|
||||
QgsComposerSymbolV2Item* cloneItem = new QgsComposerSymbolV2Item();
|
||||
|
@ -129,9 +129,13 @@ class CORE_EXPORT QgsComposerSymbolV2Item : public QgsComposerBaseSymbolItem
|
||||
public:
|
||||
QgsComposerSymbolV2Item();
|
||||
QgsComposerSymbolV2Item( const QString& text );
|
||||
//! @deprecated
|
||||
QgsComposerSymbolV2Item( const QIcon& icon, const QString& text );
|
||||
virtual ~QgsComposerSymbolV2Item();
|
||||
|
||||
//! lazy creation of icon
|
||||
virtual QVariant data( int role ) const;
|
||||
|
||||
virtual QStandardItem* clone() const;
|
||||
|
||||
virtual void writeXML( QDomElement& elem, QDomDocument& doc ) const;
|
||||
@ -149,6 +153,7 @@ class CORE_EXPORT QgsComposerSymbolV2Item : public QgsComposerBaseSymbolItem
|
||||
|
||||
private:
|
||||
QgsSymbolV2* mSymbolV2;
|
||||
mutable QIcon mIcon;
|
||||
};
|
||||
|
||||
class CORE_EXPORT QgsComposerRasterSymbolItem : public QgsComposerBaseSymbolItem
|
||||
@ -228,6 +233,10 @@ class CORE_EXPORT QgsComposerGroupItem: public QgsComposerLegendItem
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Item used for 2nd column of the legend model for layers and groups to indicate
|
||||
* style of the item (e.g. hidden, group, sub-group)
|
||||
*/
|
||||
class CORE_EXPORT QgsComposerStyleItem: public QStandardItem
|
||||
{
|
||||
public:
|
||||
|
@ -206,10 +206,6 @@ int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLa
|
||||
currentSymbolItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
|
||||
if ( symbolIt->second )
|
||||
{
|
||||
if ( mHasTopLevelWindow ) //only use QIcon / QPixmap if we have a running x-server
|
||||
{
|
||||
currentSymbolItem->setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolIt->second, QSize( 30, 30 ) ) );
|
||||
}
|
||||
currentSymbolItem->setSymbolV2( symbolIt->second->clone() );
|
||||
}
|
||||
layerItem->setChild( row, 0, currentSymbolItem );
|
||||
@ -220,10 +216,6 @@ int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLa
|
||||
else
|
||||
{
|
||||
QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( "" );
|
||||
if ( mHasTopLevelWindow ) //only use QIcon / QPixmap if we have a running x-server
|
||||
{
|
||||
currentSymbolItem->setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolIt->second, QSize( 30, 30 ) ) );
|
||||
}
|
||||
currentSymbolItem->setSymbolV2( symbolIt->second->clone() );
|
||||
layerItem->setChild( row, 0, currentSymbolItem );
|
||||
currentSymbolItem->setText( symbolIt->first );
|
||||
|
@ -194,6 +194,66 @@ QList<QgsLayerTreeModelLegendNode*> QgsDefaultVectorLayerLegend::createLayerTree
|
||||
return nodes;
|
||||
}
|
||||
|
||||
/*
|
||||
#include "qgscomposerlegenditem.h"
|
||||
|
||||
QList<QgsComposerBaseSymbolItem*> QgsDefaultVectorLayerLegend::createLegendModelItems( QgsComposerLayerItem* layerItem )
|
||||
{
|
||||
QList<QgsComposerBaseSymbolItem*> items;
|
||||
|
||||
QgsFeatureRendererV2* renderer = mLayer->rendererV2();
|
||||
if ( !renderer )
|
||||
return items;
|
||||
|
||||
if ( layerItem->showFeatureCount() )
|
||||
{
|
||||
if ( !mLayer->countSymbolFeatures() )
|
||||
{
|
||||
QgsDebugMsg( "Cannot get feature counts" );
|
||||
}
|
||||
}
|
||||
|
||||
double scaleDenominator = -1;
|
||||
QString rule;
|
||||
// TODO: new method for legend symbol items (symbol + label + scale + rule)
|
||||
QgsLegendSymbolList lst = renderer->legendSymbolItems( scaleDenominator, rule );
|
||||
QgsLegendSymbolList::const_iterator symbolIt = lst.constBegin();
|
||||
int row = 0;
|
||||
for ( ; symbolIt != lst.constEnd(); ++symbolIt )
|
||||
{
|
||||
if ( scaleDenominator == -1 && rule.isEmpty() )
|
||||
{
|
||||
QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( QString() );
|
||||
|
||||
// Get userText from old item if exists
|
||||
QgsComposerSymbolV2Item* oldSymbolItem = dynamic_cast<QgsComposerSymbolV2Item*>( layerItem->child( row, 0 ) );
|
||||
if ( oldSymbolItem )
|
||||
{
|
||||
currentSymbolItem->setUserText( oldSymbolItem->userText() );
|
||||
}
|
||||
|
||||
currentSymbolItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
|
||||
if ( symbolIt->second )
|
||||
{
|
||||
currentSymbolItem->setSymbolV2( symbolIt->second->clone() );
|
||||
}
|
||||
layerItem->setChild( row, 0, currentSymbolItem );
|
||||
|
||||
// updateSymbolV2ItemText needs layer set
|
||||
updateSymbolV2ItemText( currentSymbolItem );
|
||||
}
|
||||
else
|
||||
{
|
||||
QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( QString() );
|
||||
currentSymbolItem->setSymbolV2( symbolIt->second->clone() );
|
||||
layerItem->setChild( row, 0, currentSymbolItem );
|
||||
currentSymbolItem->setText( symbolIt->first );
|
||||
}
|
||||
|
||||
row++;
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
|
@ -102,6 +102,8 @@ class CORE_EXPORT QgsSimpleLegendNode : public QgsLayerTreeModelLegendNode
|
||||
QIcon mIcon;
|
||||
};
|
||||
|
||||
class QgsComposerLayerItem;
|
||||
class QgsComposerBaseSymbolItem;
|
||||
|
||||
/**
|
||||
* The QgsMapLayerLegend class is abstract interface for implementations
|
||||
@ -125,8 +127,11 @@ class CORE_EXPORT QgsMapLayerLegend : public QObject
|
||||
|
||||
// TODO: support for layer tree view delegates
|
||||
|
||||
// TODO: support for legend renderer
|
||||
|
||||
/**
|
||||
* Return list of legend model items to be used in QgsLegendRenderer.
|
||||
* Ownership is transferred to the caller.
|
||||
*/
|
||||
virtual QList<QgsComposerBaseSymbolItem*> createLegendModelItems( QgsComposerLayerItem* layerItem ) { Q_UNUSED( layerItem ); return QList<QgsComposerBaseSymbolItem*>(); }
|
||||
|
||||
//! Create new legend implementation for vector layer
|
||||
static QgsMapLayerLegend* defaultVectorLegend( QgsVectorLayer* vl );
|
||||
@ -153,6 +158,8 @@ class CORE_EXPORT QgsDefaultVectorLayerLegend : public QgsMapLayerLegend
|
||||
|
||||
virtual QList<QgsLayerTreeModelLegendNode*> createLayerTreeModelLegendNodes( QgsLayerTreeLayer* nodeLayer );
|
||||
|
||||
//virtual QList<QgsComposerBaseSymbolItem*> createLegendModelItems( QgsComposerLayerItem* layerItem );
|
||||
|
||||
private:
|
||||
QgsVectorLayer* mLayer;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user