Skip to content

Commit 43c2805

Browse files
committedApr 25, 2013
add ramp count to selection info label
1 parent 8218baf commit 43c2805

File tree

3 files changed

+47
-8
lines changed

3 files changed

+47
-8
lines changed
 

‎src/core/symbology-ng/qgscptcityarchive.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,22 @@ int QgsCptCityDataItem::rowCount()
555555
// populate();
556556
return mChildren.size();
557557
}
558+
559+
int QgsCptCityDataItem::leafCount() const
560+
{
561+
if ( !mPopulated )
562+
return 0;
563+
564+
int count = 0;
565+
foreach ( QgsCptCityDataItem *child, mChildren )
566+
{
567+
if ( child )
568+
count += child->leafCount();
569+
}
570+
return count;
571+
}
572+
573+
558574
bool QgsCptCityDataItem::hasChildren()
559575
{
560576
return ( mPopulated ? mChildren.count() > 0 : true );
@@ -833,6 +849,7 @@ QgsCptCityCollectionItem::~QgsCptCityCollectionItem()
833849
QVector< QgsCptCityDataItem* > QgsCptCityCollectionItem::childrenRamps( bool recursive )
834850
{
835851
QVector< QgsCptCityDataItem* > rampItems;
852+
QVector< QgsCptCityDataItem* > deleteItems;
836853

837854
populate();
838855

@@ -853,13 +870,24 @@ QVector< QgsCptCityDataItem* > QgsCptCityCollectionItem::childrenRamps( bool rec
853870
rampItem->init();
854871
if ( rampItem->isValid() )
855872
rampItems << rampItem;
856-
// should also delete item from parent, but we are in a loop now
873+
else
874+
deleteItems << rampItem;
857875
}
858876
else
859877
{
860878
QgsDebugMsg( "invalid item " + childItem->path() );
861879
}
862880
}
881+
882+
// delete items - this is not efficient, but only happens once
883+
foreach ( QgsCptCityDataItem* deleteItem, deleteItems )
884+
{
885+
int i = mChildren.indexOf( deleteItem );
886+
if ( i != -1 )
887+
mChildren.remove( i );
888+
delete deleteItem;
889+
}
890+
863891
return rampItems;
864892
}
865893

@@ -1178,7 +1206,12 @@ QVector<QgsCptCityDataItem*> QgsCptCitySelectionItem::createChildren()
11781206
QgsCptCityDataItem* childItem =
11791207
QgsCptCityDirectoryItem::dataItem( this, childPath, childPath );
11801208
if ( childItem )
1181-
children << childItem;
1209+
{
1210+
if ( childItem->isValid() )
1211+
children << childItem;
1212+
else
1213+
delete childItem;
1214+
}
11821215
}
11831216
else
11841217
{

‎src/core/symbology-ng/qgscptcityarchive.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject
101101
bool hasChildren();
102102

103103
int rowCount();
104+
// retrieve total count of "leaf" items (all children which are end nodes)
105+
virtual int leafCount() const;
104106

105107
//
106108

@@ -205,6 +207,7 @@ class CORE_EXPORT QgsCptCityColorRampItem : public QgsCptCityDataItem
205207
// --- reimplemented from QgsCptCityDataItem ---
206208

207209
virtual bool equal( const QgsCptCityDataItem *other );
210+
virtual int leafCount() const { return 1; }
208211

209212
// --- New virtual methods for layer item derived classes ---
210213
const QgsCptCityColorRampV2& ramp() const { return mRamp; }

‎src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
/////////
3131

32+
// TODO
33+
// - remove dialog or add help as help button
34+
// - fix Diverging children when first show Selections
35+
// - fix crash on Diverging?
36+
3237
class TreeFilterProxyModel : public QSortFilterProxyModel
3338
{
3439
// Q_OBJECT
@@ -285,26 +290,24 @@ void QgsCptCityColorRampV2Dialog::updateTreeView( QgsCptCityDataItem *item, bool
285290
lblSchemeName->setText( "" );
286291
populateVariants();
287292
}
293+
updateListWidget( item );
288294
lblSchemePath->setText( item->path() );
289-
lblCollectionInfo->setText( item->info() );
295+
lblCollectionInfo->setText( QString( "%1 (%2)" ).arg( item->info() ).arg( item->leafCount() ) );
290296
updateCopyingInfo( mArchive->copyingInfo( mArchive->copyingFileName( item->path() ) ) );
291-
updateListWidget( item );
292297
}
293298
else if ( item->type() == QgsCptCityDataItem::Selection )
294299
{
295300
lblSchemePath->setText( "" );
296-
// lblCollectionName->setText( item->path() );
297-
lblCollectionInfo->setText( item->info() );
298301
clearCopyingInfo( );
299302
updateListWidget( item );
303+
lblCollectionInfo->setText( QString( "%1 (%2)" ).arg( item->info() ).arg( item->leafCount() ) );
300304
}
301305
else if ( item->type() == QgsCptCityDataItem::AllRamps )
302306
{
303307
lblSchemePath->setText( "" );
304-
// lblCollectionName->setText( item->path() );
305308
clearCopyingInfo( );
306309
updateListWidget( item );
307-
lblCollectionInfo->setText( tr( "All Ramps (%1)" ).arg( item->rowCount() ) );
310+
lblCollectionInfo->setText( tr( "All Ramps (%1)" ).arg( item->leafCount() ) );
308311
}
309312
else
310313
{

0 commit comments

Comments
 (0)