Skip to content

Commit

Permalink
add ramp count to selection info label
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Apr 25, 2013
1 parent 8218baf commit 43c2805
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 8 deletions.
37 changes: 35 additions & 2 deletions src/core/symbology-ng/qgscptcityarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,22 @@ int QgsCptCityDataItem::rowCount()
// populate();
return mChildren.size();
}

int QgsCptCityDataItem::leafCount() const
{
if ( !mPopulated )
return 0;

int count = 0;
foreach ( QgsCptCityDataItem *child, mChildren )
{
if ( child )
count += child->leafCount();
}
return count;
}


bool QgsCptCityDataItem::hasChildren()
{
return ( mPopulated ? mChildren.count() > 0 : true );
Expand Down Expand Up @@ -833,6 +849,7 @@ QgsCptCityCollectionItem::~QgsCptCityCollectionItem()
QVector< QgsCptCityDataItem* > QgsCptCityCollectionItem::childrenRamps( bool recursive )
{
QVector< QgsCptCityDataItem* > rampItems;
QVector< QgsCptCityDataItem* > deleteItems;

populate();

Expand All @@ -853,13 +870,24 @@ QVector< QgsCptCityDataItem* > QgsCptCityCollectionItem::childrenRamps( bool rec
rampItem->init();
if ( rampItem->isValid() )
rampItems << rampItem;
// should also delete item from parent, but we are in a loop now
else
deleteItems << rampItem;
}
else
{
QgsDebugMsg( "invalid item " + childItem->path() );
}
}

// delete items - this is not efficient, but only happens once
foreach ( QgsCptCityDataItem* deleteItem, deleteItems )
{
int i = mChildren.indexOf( deleteItem );
if ( i != -1 )
mChildren.remove( i );
delete deleteItem;
}

return rampItems;
}

Expand Down Expand Up @@ -1178,7 +1206,12 @@ QVector<QgsCptCityDataItem*> QgsCptCitySelectionItem::createChildren()
QgsCptCityDataItem* childItem =
QgsCptCityDirectoryItem::dataItem( this, childPath, childPath );
if ( childItem )
children << childItem;
{
if ( childItem->isValid() )
children << childItem;
else
delete childItem;
}
}
else
{
Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgscptcityarchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject
bool hasChildren();

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

//

Expand Down Expand Up @@ -205,6 +207,7 @@ class CORE_EXPORT QgsCptCityColorRampItem : public QgsCptCityDataItem
// --- reimplemented from QgsCptCityDataItem ---

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

// --- New virtual methods for layer item derived classes ---
const QgsCptCityColorRampV2& ramp() const { return mRamp; }
Expand Down
15 changes: 9 additions & 6 deletions src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@

/////////

// TODO
// - remove dialog or add help as help button
// - fix Diverging children when first show Selections
// - fix crash on Diverging?

class TreeFilterProxyModel : public QSortFilterProxyModel
{
// Q_OBJECT
Expand Down Expand Up @@ -285,26 +290,24 @@ void QgsCptCityColorRampV2Dialog::updateTreeView( QgsCptCityDataItem *item, bool
lblSchemeName->setText( "" );
populateVariants();
}
updateListWidget( item );
lblSchemePath->setText( item->path() );
lblCollectionInfo->setText( item->info() );
lblCollectionInfo->setText( QString( "%1 (%2)" ).arg( item->info() ).arg( item->leafCount() ) );
updateCopyingInfo( mArchive->copyingInfo( mArchive->copyingFileName( item->path() ) ) );
updateListWidget( item );
}
else if ( item->type() == QgsCptCityDataItem::Selection )
{
lblSchemePath->setText( "" );
// lblCollectionName->setText( item->path() );
lblCollectionInfo->setText( item->info() );
clearCopyingInfo( );
updateListWidget( item );
lblCollectionInfo->setText( QString( "%1 (%2)" ).arg( item->info() ).arg( item->leafCount() ) );
}
else if ( item->type() == QgsCptCityDataItem::AllRamps )
{
lblSchemePath->setText( "" );
// lblCollectionName->setText( item->path() );
clearCopyingInfo( );
updateListWidget( item );
lblCollectionInfo->setText( tr( "All Ramps (%1)" ).arg( item->rowCount() ) );
lblCollectionInfo->setText( tr( "All Ramps (%1)" ).arg( item->leafCount() ) );
}
else
{
Expand Down

0 comments on commit 43c2805

Please sign in to comment.