Skip to content

Commit 216ecab

Browse files
committed
More Python wrapper updates + fixes
1 parent b04199a commit 216ecab

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

python/core/composer/qgscomposerlegend.sip

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2+
/** \ingroup MapComposer
3+
* Item model implementation based on layer tree model for composer legend.
4+
* Overrides some functionality of QgsLayerTreeModel to better fit the needs of composer legend.
5+
*
6+
* @note added in 2.6
7+
*/
8+
class QgsLegendModelV2 : QgsLayerTreeModel
9+
{
10+
%TypeHeaderCode
11+
#include <qgscomposerlegend.h>
12+
%End
13+
14+
public:
15+
QgsLegendModelV2( QgsLayerTreeGroup* rootNode, QObject *parent /TransferThis/ = 0 );
16+
17+
QVariant data( const QModelIndex& index, int role ) const;
18+
19+
Qt::ItemFlags flags( const QModelIndex &index ) const;
20+
};
21+
22+
123
/** \ingroup MapComposer
224
* A legend that can be placed onto a map composition
325
*/
@@ -25,7 +47,16 @@ class QgsComposerLegend : QgsComposerItem
2547
void adjustBoxSize();
2648

2749
/**Returns pointer to the legend model*/
28-
QgsLegendModel* model();
50+
//! @note deprecated in 2.6 - use modelV2()
51+
QgsLegendModel* model() /Deprecated/;
52+
53+
//! @note added in 2.6
54+
QgsLegendModelV2* modelV2();
55+
56+
//! @note added in 2.6
57+
void setAutoUpdateModel( bool autoUpdate );
58+
//! @note added in 2.6
59+
bool autoUpdateModel() const;
2960

3061
//setters and getters
3162
void setTitle( const QString& t );

src/core/composer/qgscomposerlegend.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ class QgsLegendRenderer;
3434

3535

3636
/** \ingroup MapComposer
37-
* Item model implementation based on layer tree model for composer legend
37+
* Item model implementation based on layer tree model for composer legend.
38+
* Overrides some functionality of QgsLayerTreeModel to better fit the needs of composer legend.
39+
*
40+
* @note added in 2.6
3841
*/
39-
class QgsLegendModelV2 : public QgsLayerTreeModel
42+
class CORE_EXPORT QgsLegendModelV2 : public QgsLayerTreeModel
4043
{
4144
public:
4245
QgsLegendModelV2( QgsLayerTreeGroup* rootNode, QObject *parent = 0 );
@@ -71,7 +74,8 @@ class CORE_EXPORT QgsComposerLegend : public QgsComposerItem
7174
void adjustBoxSize();
7275

7376
/**Returns pointer to the legend model*/
74-
QgsLegendModel* model() {return &mLegendModel;}
77+
//! @note deprecated in 2.6 - use modelV2()
78+
Q_DECL_DEPRECATED QgsLegendModel* model() {return &mLegendModel;}
7579

7680
//! @note added in 2.6
7781
QgsLegendModelV2* modelV2() { return mLegendModel2; }

src/core/qgsmaplayerlegend.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ QList<QgsLayerTreeModelLegendNode*> QgsDefaultVectorLayerLegend::createLayerTree
195195
QSettings settings;
196196
if ( settings.value( "/qgis/showLegendClassifiers", false ).toBool() && !r->legendClassificationAttribute().isEmpty() )
197197
{
198-
nodes.append( new QgsSimpleLegendNode( nodeLayer, r->legendClassificationAttribute(), "_class_attribute_" ) );
198+
nodes.append( new QgsSimpleLegendNode( nodeLayer, r->legendClassificationAttribute() ) );
199199
}
200200

201201
foreach ( const QgsLegendSymbolItemV2& i, r->legendSymbolItemsV2() )
@@ -252,7 +252,7 @@ QList<QgsLayerTreeModelLegendNode*> QgsDefaultRasterLayerLegend::createLayerTree
252252
if ( count == max_count )
253253
{
254254
QString label = tr( "following %1 items\nnot displayed" ).arg( rasterItemList.size() - max_count );
255-
nodes << new QgsSimpleLegendNode( nodeLayer, label, "_more_items_" );
255+
nodes << new QgsSimpleLegendNode( nodeLayer, label );
256256
break;
257257
}
258258
}
@@ -279,11 +279,10 @@ QList<QgsLayerTreeModelLegendNode*> QgsDefaultPluginLayerLegend::createLayerTree
279279
if ( symbologyList.count() == 0 )
280280
return nodes;
281281

282-
int i = 0;
283282
typedef QPair<QString, QPixmap> XY;
284283
foreach ( XY item, symbologyList )
285284
{
286-
nodes << new QgsSimpleLegendNode( nodeLayer, item.first, QString::number( i++ ), QIcon( item.second ) );
285+
nodes << new QgsSimpleLegendNode( nodeLayer, item.first, QIcon( item.second ) );
287286
}
288287

289288
return nodes;

0 commit comments

Comments
 (0)