Skip to content

Commit 038acbc

Browse files
committedNov 6, 2012
vector feature counts moved to vector layer, enabled feature counts in composer legend, fixes #6237
1 parent 4b789b8 commit 038acbc

12 files changed

+295
-77
lines changed
 

‎images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<file>themes/default/mActionSimplify.png</file>
164164
<file>themes/default/mActionSplitFeatures.png</file>
165165
<file>themes/default/mActionSplitFeatures.svg</file>
166+
<file>themes/default/mActionSum.png</file>
166167
<file>themes/default/mActionTextAnnotation.png</file>
167168
<file>themes/default/mActionToggleEditing.png</file>
168169
<file>themes/default/mActionUndo.png</file>

‎images/themes/default/mActionSum.png

697 Bytes
Loading

‎src/app/composer/qgscomposerlegendwidget.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include "qgscomposerlegendwidget.h"
1919
#include "qgscomposerlegend.h"
20+
#include "qgscomposerlegenditem.h"
2021
#include "qgscomposerlegenditemdialog.h"
2122
#include "qgscomposerlegendlayersdialog.h"
2223
#include "qgscomposeritemwidget.h"
@@ -26,8 +27,10 @@
2627
#include "qgsapplegendinterface.h"
2728
#include "qgisapp.h"
2829
#include "qgsmapcanvas.h"
30+
#include "qgsmaplayerregistry.h"
2931
#include "qgsmaprenderer.h"
3032
#include "qgsapplication.h"
33+
#include "qgsvectorlayer.h"
3134

3235
#include <QMessageBox>
3336

@@ -41,6 +44,7 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
4144
mRemoveToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyRemove.png" ) ) );
4245
mMoveUpToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyUp.png" ) ) );
4346
mMoveDownToolButton->setIcon( QIcon( QgsApplication::iconPath( "symbologyDown.png" ) ) );
47+
mCountToolButton->setIcon( QIcon( QgsApplication::iconPath( "mActionSum.png" ) ) );
4448

4549
//add widget for item properties
4650
QgsComposerItemWidget* itemPropertiesWidget = new QgsComposerItemWidget( this, legend );
@@ -59,6 +63,9 @@ QgsComposerLegendWidget::QgsComposerLegendWidget( QgsComposerLegend* legend ): m
5963

6064
setGuiElements();
6165
connect( mItemTreeView, SIGNAL( itemChanged() ), this, SLOT( setGuiElements() ) );
66+
67+
connect( mItemTreeView->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ),
68+
this, SLOT( selectedChanged( const QModelIndex &, const QModelIndex & ) ) );
6269
}
6370

6471
QgsComposerLegendWidget::QgsComposerLegendWidget(): mLegend( 0 )
@@ -612,6 +619,52 @@ void QgsComposerLegendWidget::on_mUpdatePushButton_clicked()
612619
mLegend->endCommand();
613620
}
614621

622+
void QgsComposerLegendWidget::on_mCountToolButton_clicked( bool checked )
623+
{
624+
QgsDebugMsg( "Entered." );
625+
if ( !mLegend )
626+
{
627+
return;
628+
}
629+
630+
//get current item
631+
QStandardItemModel* itemModel = qobject_cast<QStandardItemModel *>( mItemTreeView->model() );
632+
if ( !itemModel )
633+
{
634+
return;
635+
}
636+
637+
//get current item
638+
QModelIndex currentIndex = mItemTreeView->currentIndex();
639+
if ( !currentIndex.isValid() )
640+
{
641+
return;
642+
}
643+
644+
QStandardItem* currentItem = itemModel->itemFromIndex( currentIndex );
645+
if ( !currentItem )
646+
{
647+
return;
648+
}
649+
650+
QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem *>( currentItem );
651+
652+
if ( !layerItem )
653+
{
654+
return;
655+
}
656+
657+
mLegend->beginCommand( tr( "Legend updated" ) );
658+
layerItem->setShowFeatureCount( checked );
659+
if ( mLegend->model() )
660+
{
661+
mLegend->model()->updateItem( currentItem );
662+
}
663+
mLegend->update();
664+
mLegend->adjustBoxSize();
665+
mLegend->endCommand();
666+
}
667+
615668
void QgsComposerLegendWidget::on_mUpdateAllPushButton_clicked()
616669
{
617670
updateLegend();
@@ -715,3 +768,27 @@ void QgsComposerLegendWidget::showEvent( QShowEvent * event )
715768
refreshMapComboBox();
716769
QWidget::showEvent( event );
717770
}
771+
772+
void QgsComposerLegendWidget::selectedChanged( const QModelIndex & current, const QModelIndex & previous )
773+
{
774+
Q_UNUSED( previous );
775+
QgsDebugMsg( "Entered" );
776+
777+
mCountToolButton->setChecked( false );
778+
mCountToolButton->setEnabled( false );
779+
780+
QStandardItemModel* itemModel = qobject_cast<QStandardItemModel *>( mItemTreeView->model() );
781+
if ( !itemModel ) return;
782+
783+
QStandardItem* currentItem = itemModel->itemFromIndex( current );
784+
if ( !currentItem ) return;
785+
786+
QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem *>( currentItem );
787+
if ( !layerItem ) return;
788+
789+
QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( layerItem->layerID() ) );
790+
if ( !vectorLayer ) return;
791+
792+
mCountToolButton->setChecked( layerItem->showFeatureCount() );
793+
mCountToolButton->setEnabled( true );
794+
}

‎src/app/composer/qgscomposerlegendwidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ class QgsComposerLegendWidget: public QWidget, private Ui::QgsComposerLegendWidg
6161
void on_mRemoveToolButton_clicked();
6262
void on_mAddToolButton_clicked();
6363
void on_mEditPushButton_clicked();
64+
void on_mCountToolButton_clicked( bool checked );
6465
void on_mUpdatePushButton_clicked();
6566
void on_mUpdateAllPushButton_clicked();
6667
void on_mAddGroupButton_clicked();
6768

69+
void selectedChanged( const QModelIndex & current, const QModelIndex & previous );
70+
6871
protected:
6972
void showEvent( QShowEvent * event );
7073

‎src/app/legend/qgslegendlayer.cpp

Lines changed: 13 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ QgsLegendLayer::QgsLegendLayer( QgsMapLayer* layer )
5151
, mLyr( layer )
5252
, mDrawingOrder( -1 )
5353
, mShowFeatureCount( false )
54-
, mFeatureCount( -1 )
5554
{
5655
mType = LEGEND_LAYER;
5756

@@ -558,12 +557,13 @@ QgsMapCanvasLayer& QgsLegendLayer::canvasLayer()
558557
return mLyr;
559558
}
560559

561-
QString QgsLegendLayer::label() const
560+
QString QgsLegendLayer::label()
562561
{
563562
QString name = mLyr.layer()->name();
564-
if ( mShowFeatureCount && mFeatureCount >= 0 )
563+
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( mLyr.layer() );
564+
if ( mShowFeatureCount && vlayer && vlayer->featureCount() >= 0 )
565565
{
566-
name += QString( " [%1]" ).arg( mFeatureCount );
566+
name += QString( " [%1]" ).arg( vlayer->featureCount() );
567567
}
568568
return name;
569569
}
@@ -585,7 +585,7 @@ void QgsLegendLayer::afterEdit()
585585
layerNameChanged();
586586
}
587587

588-
QString QgsLegendLayer::layerName() const
588+
QString QgsLegendLayer::layerName()
589589
{
590590
// The text could be edited (Rename), in that case we have to return the new name
591591
if ( text( 0 ) != label() && text( 0 ) != mLyr.layer()->name() )
@@ -618,7 +618,6 @@ void QgsLegendLayer::updateAfterLayerModification( bool onlyGeomChanged )
618618

619619
void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLayer* layer )
620620
{
621-
mFeatureCount = -1;
622621
if ( !layer )
623622
{
624623
return;
@@ -629,70 +628,29 @@ void QgsLegendLayer::updateItemListCountV2( SymbologyList& itemList, QgsVectorLa
629628
{
630629
return;
631630
}
632-
QgsRenderContext dummyContext;
633-
renderer->startRender( dummyContext, layer );
634631

635-
//create map holding the symbol count
636-
QMap< QgsSymbolV2*, int > symbolCountMap;
637-
QgsLegendSymbolList symbolList = renderer->legendSymbolItems();
638-
QgsLegendSymbolList::const_iterator symbolIt = symbolList.constBegin();
639-
for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
640-
{
641-
symbolCountMap.insert( symbolIt->second, 0 );
642-
}
643-
644-
//go through all features and count the number of occurrences
645-
int nFeatures = layer->pendingFeatureCount();
646-
QProgressDialog p( tr( "Updating feature count for layer %1" ).arg( layer->name() ), tr( "Abort" ), 0, nFeatures );
647-
p.setWindowModality( Qt::WindowModal );
648-
int featuresCounted = 0;
649-
650-
layer->select( layer->pendingAllAttributesList(), QgsRectangle(), false, false );
651-
QgsFeature f;
652-
653-
// Renderer (rule based) may depend on context scale, with scale is ignored if 0
654-
QgsRenderContext renderContext;
655-
renderContext.setRendererScale( 0 );
656-
renderer->startRender( renderContext, layer );
657-
658-
while ( layer->nextFeature( f ) )
632+
// Count features
633+
if ( !layer->countSymbolFeatures() )
659634
{
660-
QgsSymbolV2List symbolList = renderer->symbolsForFeature( f );
661-
for ( QgsSymbolV2List::iterator symbolIt = symbolList.begin(); symbolIt != symbolList.end(); ++symbolIt )
662-
{
663-
symbolCountMap[*symbolIt] += 1;
664-
}
665-
++featuresCounted;
666-
if ( featuresCounted % 50 == 0 )
667-
{
668-
if ( featuresCounted > nFeatures ) //sometimes the feature count is not correct
669-
{
670-
p.setMaximum( 0 );
671-
}
672-
p.setValue( featuresCounted );
673-
if ( p.wasCanceled() )
674-
{
675-
mFeatureCount = -1;
676-
return;
677-
}
678-
}
679-
mFeatureCount++;
635+
QgsDebugMsg( "Cannot get feature counts" );
636+
return;
680637
}
681-
renderer->stopRender( renderContext );
682-
p.setValue( nFeatures );
683638

684639
QMap<QString, QPixmap> itemMap;
685640
SymbologyList::const_iterator symbologyIt = itemList.constBegin();
686641
for ( ; symbologyIt != itemList.constEnd(); ++ symbologyIt )
687642
{
688643
itemMap.insert( symbologyIt->first, symbologyIt->second );
689644
}
645+
690646
itemList.clear();
691647

648+
QgsLegendSymbolList symbolList = renderer->legendSymbolItems();
649+
QgsLegendSymbolList::const_iterator symbolIt = symbolList.constBegin();
692650
symbolIt = symbolList.constBegin();
693651
for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
694652
{
695-
itemList.push_back( qMakePair( symbolIt->first + " [" + QString::number( symbolCountMap[symbolIt->second] ) + "]", itemMap[symbolIt->first] ) );
653+
itemList.push_back( qMakePair( symbolIt->first + " [" + QString::number( layer->featureCount( symbolIt->second ) ) + "]", itemMap[symbolIt->first] ) );
696654
}
697655
}
698656

‎src/app/legend/qgslegendlayer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class QgsLegendLayer : public QgsLegendItem
7676
int drawingOrder() const { return mDrawingOrder; }
7777

7878
/** Get layer name currently set in legend */
79-
QString layerName() const;
79+
QString layerName();
8080

8181
/**Called before edit*/
8282
void beforeEdit();
@@ -130,7 +130,7 @@ class QgsLegendLayer : public QgsLegendItem
130130
void setupFont();
131131

132132
/** Label, may be layer name or layer name + [feature count] */
133-
QString label() const;
133+
QString label();
134134

135135
protected:
136136

@@ -142,9 +142,6 @@ class QgsLegendLayer : public QgsLegendItem
142142

143143
/**True if number of features per legend class should is shown in the legend items*/
144144
bool mShowFeatureCount;
145-
146-
/** Last vector features count, -1 if not counted */
147-
int mFeatureCount;
148145
};
149146

150147
#endif

‎src/core/composer/qgscomposerlegenditem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,12 @@ void QgsComposerRasterSymbolItem::readXML( const QDomElement& itemElem, bool xSe
288288
////////////////////QgsComposerLayerItem
289289

290290
QgsComposerLayerItem::QgsComposerLayerItem(): QgsComposerLegendItem()
291+
, mShowFeatureCount( false )
291292
{
292293
}
293294

294295
QgsComposerLayerItem::QgsComposerLayerItem( const QString& text ): QgsComposerLegendItem( text )
296+
, mShowFeatureCount( false )
295297
{
296298
}
297299

@@ -312,6 +314,7 @@ void QgsComposerLayerItem::writeXML( QDomElement& elem, QDomDocument& doc ) cons
312314
QDomElement layerItemElem = doc.createElement( "LayerItem" );
313315
layerItemElem.setAttribute( "layerId", mLayerID );
314316
layerItemElem.setAttribute( "text", text() );
317+
layerItemElem.setAttribute( "showFeatureCount", showFeatureCount() );
315318
writeXMLChildren( layerItemElem, doc );
316319
elem.appendChild( layerItemElem );
317320
}
@@ -324,6 +327,7 @@ void QgsComposerLayerItem::readXML( const QDomElement& itemElem, bool xServerAva
324327
}
325328
setText( itemElem.attribute( "text", "" ) );
326329
setLayerID( itemElem.attribute( "layerId", "" ) );
330+
setShowFeatureCount( itemElem.attribute( "showFeatureCount", "" ) == "1" ? true : false );
327331

328332
//now call readXML for all the child items
329333
QDomNodeList childList = itemElem.childNodes();

‎src/core/composer/qgscomposerlegenditem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,13 @@ class CORE_EXPORT QgsComposerLayerItem: public QgsComposerLegendItem
148148
void setLayerID( const QString& id ) { mLayerID = id; }
149149
QString layerID() const { return mLayerID; }
150150

151+
void setShowFeatureCount( bool show ) { mShowFeatureCount = show; }
152+
bool showFeatureCount() const { return mShowFeatureCount; }
153+
151154
private:
152155
QString mLayerID;
156+
// Show vector feature counts
157+
bool mShowFeatureCount;
153158
};
154159

155160
class CORE_EXPORT QgsComposerGroupItem: public QgsComposerLegendItem

‎src/core/composer/qgslegendmodel.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ QStandardItem* QgsLegendModel::addGroup( QString text, int position )
136136

137137
int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer )
138138
{
139-
if ( !layerItem || !vlayer )
139+
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem );
140+
141+
if ( !layerItem || !lItem || !vlayer )
140142
{
141143
return 1;
142144
}
@@ -147,11 +149,24 @@ int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLa
147149
return 2;
148150
}
149151

152+
if ( lItem->showFeatureCount() )
153+
{
154+
if ( !vlayer->countSymbolFeatures() )
155+
{
156+
QgsDebugMsg( "Cannot get feature counts" );
157+
}
158+
}
159+
150160
QgsLegendSymbolList lst = renderer->legendSymbolItems();
151161
QgsLegendSymbolList::const_iterator symbolIt = lst.constBegin();
152162
for ( ; symbolIt != lst.constEnd(); ++symbolIt )
153163
{
154-
QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( symbolIt->first );
164+
QString label = symbolIt->first;
165+
if ( lItem->showFeatureCount() )
166+
{
167+
label += QString( " [%1]" ).arg( vlayer->featureCount( symbolIt->second ) );
168+
}
169+
QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( label );
155170
currentSymbolItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
156171
if ( symbolIt->second )
157172
{
@@ -282,6 +297,7 @@ void QgsLegendModel::updateItem( QStandardItem* item )
282297

283298
void QgsLegendModel::updateLayer( QStandardItem* layerItem )
284299
{
300+
QgsDebugMsg( "Entered." );
285301
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem );
286302
if ( lItem )
287303
{
@@ -295,10 +311,16 @@ void QgsLegendModel::updateLayer( QStandardItem* layerItem )
295311
lItem->removeRow( i );
296312
}
297313

314+
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
315+
298316
//set layer name as item text
299-
layerItem->setText( mapLayer->name() );
317+
QString label = mapLayer->name();
318+
if ( vLayer && lItem->showFeatureCount() )
319+
{
320+
label += QString( " [%1]" ).arg( vLayer->featureCount() );
321+
}
322+
layerItem->setText( label );
300323

301-
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
302324
if ( vLayer )
303325
{
304326
if ( vLayer->isUsingRendererV2() )

‎src/core/qgsvectorlayer.cpp

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <QPainter>
2828
#include <QPainterPath>
2929
#include <QPolygonF>
30+
#include <QProgressDialog>
3031
#include <QSettings>
3132
#include <QString>
3233
#include <QDomNode>
@@ -106,6 +107,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,
106107
, mDiagramRenderer( 0 )
107108
, mDiagramLayerSettings( 0 )
108109
, mValidExtent( false )
110+
, mSymbolFeatureCounted( false )
109111
{
110112
mActions = new QgsAttributeAction( this );
111113

@@ -1451,8 +1453,6 @@ QgsRectangle QgsVectorLayer::boundingBoxOfSelected()
14511453
return retval;
14521454
}
14531455

1454-
1455-
14561456
long QgsVectorLayer::featureCount() const
14571457
{
14581458
if ( !mDataProvider )
@@ -1464,6 +1464,82 @@ long QgsVectorLayer::featureCount() const
14641464
return mDataProvider->featureCount();
14651465
}
14661466

1467+
long QgsVectorLayer::featureCount( QgsSymbolV2* symbol )
1468+
{
1469+
if ( !mSymbolFeatureCounted ) return -1;
1470+
return mSymbolFeatureCountMap.value( symbol );
1471+
}
1472+
1473+
bool QgsVectorLayer::countSymbolFeatures( bool showProgress )
1474+
{
1475+
if ( mSymbolFeatureCounted ) return true;
1476+
mSymbolFeatureCountMap.clear();
1477+
1478+
if ( !mDataProvider )
1479+
{
1480+
QgsDebugMsg( "invoked with null mDataProvider" );
1481+
return false;
1482+
}
1483+
if ( !mRendererV2 )
1484+
{
1485+
QgsDebugMsg( "invoked with null mRendererV2" );
1486+
return false;
1487+
}
1488+
1489+
QgsLegendSymbolList symbolList = mRendererV2->legendSymbolItems();
1490+
QgsLegendSymbolList::const_iterator symbolIt = symbolList.constBegin();
1491+
1492+
for ( ; symbolIt != symbolList.constEnd(); ++symbolIt )
1493+
{
1494+
mSymbolFeatureCountMap.insert( symbolIt->second, 0 );
1495+
}
1496+
1497+
long nFeatures = pendingFeatureCount();
1498+
QProgressDialog progressDialog( tr( "Updating feature count for layer %1" ).arg( name() ), tr( "Abort" ), 0, nFeatures );
1499+
progressDialog.setWindowModality( Qt::WindowModal );
1500+
int featuresCounted = 0;
1501+
1502+
select( pendingAllAttributesList(), QgsRectangle(), false, false );
1503+
QgsFeature f;
1504+
1505+
// Renderer (rule based) may depend on context scale, with scale is ignored if 0
1506+
QgsRenderContext renderContext;
1507+
renderContext.setRendererScale( 0 );
1508+
mRendererV2->startRender( renderContext, this );
1509+
1510+
while ( nextFeature( f ) )
1511+
{
1512+
QgsSymbolV2List featureSymbolList = mRendererV2->symbolsForFeature( f );
1513+
for ( QgsSymbolV2List::iterator symbolIt = featureSymbolList.begin(); symbolIt != featureSymbolList.end(); ++symbolIt )
1514+
{
1515+
mSymbolFeatureCountMap[*symbolIt] += 1;
1516+
}
1517+
++featuresCounted;
1518+
1519+
if ( showProgress )
1520+
{
1521+
if ( featuresCounted % 50 == 0 )
1522+
{
1523+
if ( featuresCounted > nFeatures ) //sometimes the feature count is not correct
1524+
{
1525+
progressDialog.setMaximum( 0 );
1526+
}
1527+
progressDialog.setValue( featuresCounted );
1528+
if ( progressDialog.wasCanceled() )
1529+
{
1530+
mSymbolFeatureCountMap.clear();
1531+
mRendererV2->stopRender( renderContext );
1532+
return false;
1533+
}
1534+
}
1535+
}
1536+
}
1537+
mRendererV2->stopRender( renderContext );
1538+
progressDialog.setValue( nFeatures );
1539+
mSymbolFeatureCounted = true;
1540+
return true;
1541+
}
1542+
14671543
long QgsVectorLayer::updateFeatureCount() const
14681544
{
14691545
return -1;
@@ -4926,6 +5002,8 @@ void QgsVectorLayer::setRendererV2( QgsFeatureRendererV2 *r )
49265002
setUsingRendererV2( true );
49275003
delete mRendererV2;
49285004
mRendererV2 = r;
5005+
mSymbolFeatureCounted = false;
5006+
mSymbolFeatureCountMap.clear();
49295007
}
49305008
}
49315009
bool QgsVectorLayer::isUsingRendererV2()

‎src/core/qgsvectorlayer.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class QgsVectorLayerJoinBuffer;
4949
class QgsFeatureRendererV2;
5050
class QgsDiagramRendererV2;
5151
class QgsDiagramLayerSettings;
52+
class QgsSymbolV2;
5253

5354
typedef QList<int> QgsAttributeList;
5455
typedef QSet<int> QgsAttributeIds;
@@ -417,6 +418,21 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
417418
*/
418419
virtual long featureCount() const;
419420

421+
/**
422+
* Number of features rendered with specified symbol. Features must be first
423+
* calculated by countSymbolFeatures()
424+
* @param symbol the symbol
425+
* @return number of features rendered by symbol or -1 if failed or counts are not available
426+
*/
427+
long featureCount( QgsSymbolV2* symbol );
428+
429+
/**
430+
* Count features for symbols. Feature counts may be get by featureCount( QgsSymbolV2*).
431+
* @param showProgress show progress dialog
432+
* @return true if calculated, false if failed or was canceled by user
433+
*/
434+
bool countSymbolFeatures( bool showProgress = true );
435+
420436
/** This function does nothing useful, it's kept only for compatibility.
421437
* @todo to be removed
422438
*/
@@ -1165,6 +1181,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
11651181
QgsDiagramLayerSettings *mDiagramLayerSettings;
11661182

11671183
bool mValidExtent;
1184+
1185+
// Features in renderer classes counted
1186+
bool mSymbolFeatureCounted;
1187+
1188+
// Feature counts for each renderer symbol
1189+
QMap<QgsSymbolV2*, long> mSymbolFeatureCountMap;
11681190
};
11691191

11701192
#endif

‎src/ui/qgscomposerlegendwidgetbase.ui

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
<item row="0" column="0">
4545
<widget class="QToolBox" name="toolBox">
4646
<property name="currentIndex">
47-
<number>0</number>
47+
<number>1</number>
4848
</property>
4949
<widget class="QWidget" name="page">
5050
<property name="geometry">
5151
<rect>
5252
<x>0</x>
5353
<y>0</y>
54-
<width>374</width>
55-
<height>549</height>
54+
<width>370</width>
55+
<height>467</height>
5656
</rect>
5757
</property>
5858
<attribute name="label">
@@ -220,8 +220,8 @@
220220
<rect>
221221
<x>0</x>
222222
<y>0</y>
223-
<width>393</width>
224-
<height>162</height>
223+
<width>427</width>
224+
<height>401</height>
225225
</rect>
226226
</property>
227227
<attribute name="label">
@@ -244,7 +244,7 @@
244244
</property>
245245
</widget>
246246
</item>
247-
<item row="1" column="0" colspan="9">
247+
<item row="1" column="0" colspan="10">
248248
<widget class="QTreeView" name="mItemTreeView">
249249
<property name="sizePolicy">
250250
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
@@ -264,6 +264,9 @@
264264
<attribute name="headerVisible">
265265
<bool>false</bool>
266266
</attribute>
267+
<attribute name="headerVisible">
268+
<bool>false</bool>
269+
</attribute>
267270
</widget>
268271
</item>
269272
<item row="2" column="0">
@@ -277,6 +280,10 @@
277280
<property name="text">
278281
<string/>
279282
</property>
283+
<property name="icon">
284+
<iconset resource="../../images/images.qrc">
285+
<normaloff>:/images/themes/default/mActionArrowDown.png</normaloff>:/images/themes/default/mActionArrowDown.png</iconset>
286+
</property>
280287
<property name="iconSize">
281288
<size>
282289
<width>24</width>
@@ -290,6 +297,10 @@
290297
<property name="text">
291298
<string/>
292299
</property>
300+
<property name="icon">
301+
<iconset resource="../../images/images.qrc">
302+
<normaloff>:/images/themes/default/mActionArrowUp.png</normaloff>:/images/themes/default/mActionArrowUp.png</iconset>
303+
</property>
293304
<property name="iconSize">
294305
<size>
295306
<width>24</width>
@@ -303,6 +314,10 @@
303314
<property name="text">
304315
<string/>
305316
</property>
317+
<property name="icon">
318+
<iconset resource="../../images/images.qrc">
319+
<normaloff>:/images/themes/default/mActionSignPlus.png</normaloff>:/images/themes/default/mActionSignPlus.png</iconset>
320+
</property>
306321
<property name="iconSize">
307322
<size>
308323
<width>24</width>
@@ -316,6 +331,10 @@
316331
<property name="text">
317332
<string/>
318333
</property>
334+
<property name="icon">
335+
<iconset resource="../../images/images.qrc">
336+
<normaloff>:/images/themes/default/mActionSignMinus.png</normaloff>:/images/themes/default/mActionSignMinus.png</iconset>
337+
</property>
319338
<property name="iconSize">
320339
<size>
321340
<width>24</width>
@@ -329,6 +348,10 @@
329348
<property name="text">
330349
<string/>
331350
</property>
351+
<property name="icon">
352+
<iconset resource="../../images/images.qrc">
353+
<normaloff>:/images/themes/default/symbologyEdit.png</normaloff>:/images/themes/default/symbologyEdit.png</iconset>
354+
</property>
332355
<property name="iconSize">
333356
<size>
334357
<width>24</width>
@@ -337,7 +360,7 @@
337360
</property>
338361
</widget>
339362
</item>
340-
<item row="2" column="5">
363+
<item row="2" column="6">
341364
<widget class="QToolButton" name="mUpdatePushButton">
342365
<property name="text">
343366
<string>Update</string>
@@ -350,14 +373,14 @@
350373
</property>
351374
</widget>
352375
</item>
353-
<item row="2" column="6">
376+
<item row="2" column="7">
354377
<widget class="QToolButton" name="mUpdateAllPushButton">
355378
<property name="text">
356379
<string>All</string>
357380
</property>
358381
</widget>
359382
</item>
360-
<item row="2" column="8">
383+
<item row="2" column="9">
361384
<spacer name="horizontalSpacer">
362385
<property name="orientation">
363386
<enum>Qt::Horizontal</enum>
@@ -370,13 +393,39 @@
370393
</property>
371394
</spacer>
372395
</item>
373-
<item row="2" column="7">
396+
<item row="2" column="8">
374397
<widget class="QToolButton" name="mAddGroupButton">
375398
<property name="text">
376399
<string>Add group</string>
377400
</property>
378401
</widget>
379402
</item>
403+
<item row="2" column="5">
404+
<widget class="QToolButton" name="mCountToolButton">
405+
<property name="enabled">
406+
<bool>false</bool>
407+
</property>
408+
<property name="toolTip">
409+
<string>Show feature count for each class of vector layer.</string>
410+
</property>
411+
<property name="text">
412+
<string/>
413+
</property>
414+
<property name="icon">
415+
<iconset resource="../../images/images.qrc">
416+
<normaloff>:/images/themes/default/mActionSum.png</normaloff>:/images/themes/default/mActionSum.png</iconset>
417+
</property>
418+
<property name="iconSize">
419+
<size>
420+
<width>24</width>
421+
<height>24</height>
422+
</size>
423+
</property>
424+
<property name="checkable">
425+
<bool>true</bool>
426+
</property>
427+
</widget>
428+
</item>
380429
</layout>
381430
</widget>
382431
</widget>
@@ -410,6 +459,8 @@
410459
<tabstop>mUpdateAllPushButton</tabstop>
411460
<tabstop>mAddGroupButton</tabstop>
412461
</tabstops>
413-
<resources/>
462+
<resources>
463+
<include location="../../images/images.qrc"/>
464+
</resources>
414465
<connections/>
415466
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.