Skip to content

Commit

Permalink
add All Ramps items in tree widget
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed Nov 17, 2012
1 parent 145fca4 commit 063f4de
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 19 deletions.
86 changes: 70 additions & 16 deletions src/core/symbology-ng/qgscptcityarchive.cpp
Expand Up @@ -46,7 +46,8 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
: mArchiveName( archiveName ), mBaseDir( baseDir )
{
QgsDebugMsg( "archiveName = " + archiveName + " baseDir = " + baseDir );
// make root items

// make Author items
QgsCptCityDirectoryItem* dirItem = 0;
foreach ( QString path, QDir( mBaseDir ).entryList( QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name ) )
{
Expand All @@ -61,21 +62,29 @@ QgsCptCityArchive::QgsCptCityArchive( QString archiveName, QString baseDir )
}

// make selection items
QgsCptCitySelectionItem* item = 0;
QgsCptCitySelectionItem* selItem = 0;
QDir seldir( mBaseDir + QDir::separator() + "selections" );
QgsDebugMsg( "populating selection from " + seldir.path() );
foreach ( QString selfile, seldir.entryList( QStringList( "*.xml" ), QDir::Files ) )
{
QgsDebugMsg( "file= " + seldir.path() + "/" + selfile );
item = new QgsCptCitySelectionItem( NULL, QFileInfo( selfile ).baseName(),
seldir.dirName() + QDir::separator() + selfile );
selItem = new QgsCptCitySelectionItem( NULL, QFileInfo( selfile ).baseName(),
seldir.dirName() + QDir::separator() + selfile );
//TODO remove item if there are no children (e.g. esri in qgis-sel)
if ( item->isValid() )
mSelectionItems << item;
if ( selItem->isValid() )
mSelectionItems << selItem;
else
delete item;
delete selItem;
}

// make "All Ramps items" (which will contain all ramps without hierarchy)
QgsCptCityAllRampsItem* allRampsItem;
allRampsItem = new QgsCptCityAllRampsItem( NULL, QObject::tr( "All Ramps" ),
mRootItems );
mRootItems.prepend( allRampsItem );
allRampsItem = new QgsCptCityAllRampsItem( NULL, QObject::tr( "All Ramps" ),
mSelectionItems );
mSelectionItems.prepend( allRampsItem );
}

QgsCptCityArchive::~QgsCptCityArchive( )
Expand Down Expand Up @@ -860,7 +869,7 @@ QgsCptCityDirectoryItem::QgsCptCityDirectoryItem( QgsCptCityDataItem* parent,
: QgsCptCityCollectionItem( parent, name, path )
{
mType = Directory;
mValid = QDir( QgsCptCityArchive::defaultBaseDir() ).exists();
mValid = QDir( QgsCptCityArchive::defaultBaseDir() + QDir::separator() + mPath ).exists();
if ( ! mValid )
{
QgsDebugMsg( "created invalid dir item, path = " + QgsCptCityArchive::defaultBaseDir()
Expand Down Expand Up @@ -1140,7 +1149,9 @@ QgsCptCitySelectionItem::QgsCptCitySelectionItem( QgsCptCityDataItem* parent,
: QgsCptCityCollectionItem( parent, name, path )
{
mType = Selection;
parseXML();
mValid = ! path.isNull();
if ( mValid )
parseXML();
}

QgsCptCitySelectionItem::~QgsCptCitySelectionItem()
Expand Down Expand Up @@ -1257,6 +1268,38 @@ bool QgsCptCitySelectionItem::equal( const QgsCptCityDataItem *other )
return ( path() == other->path() );
}

//-----------------------------------------------------------------------
QgsCptCityAllRampsItem::QgsCptCityAllRampsItem( QgsCptCityDataItem* parent,
QString name, QVector<QgsCptCityDataItem*> items )
: QgsCptCityCollectionItem( parent, name, QString() ), mItems( items )
{
mType = AllRamps;
mValid = true;
// populate();
}

QgsCptCityAllRampsItem::~QgsCptCityAllRampsItem()
{
}

QVector<QgsCptCityDataItem*> QgsCptCityAllRampsItem::createChildren()
{
if ( ! mValid )
return QVector<QgsCptCityDataItem*>();

QVector<QgsCptCityDataItem*> children;

// add children ramps of each item
foreach ( QgsCptCityDataItem* item, mItems )
{
QgsCptCityCollectionItem* colItem = dynamic_cast< QgsCptCityCollectionItem* >( item );
if ( colItem )
children += colItem->childrenRamps( true );
}

return children;
}

//-----------------------------------------------------------------------

QgsCptCityBrowserModel::QgsCptCityBrowserModel( QObject *parent,
Expand Down Expand Up @@ -1343,12 +1386,11 @@ QVariant QgsCptCityBrowserModel::data( const QModelIndex &index, int role ) cons
return item->icon( mIconSize );
}
else if ( role == Qt::FontRole &&
( item->type() == QgsCptCityDataItem::Directory ||
item->type() == QgsCptCityDataItem::Selection ) )
( dynamic_cast< QgsCptCityCollectionItem* >( item ) != 0 ) )
{
// collectionitems are larger and bold
QFont font;
// font.setPointSize( font.pointSize() + 1 );
font.setPointSize( 11 ); //FIXME why is the font so small?
font.setBold( true );
return font;
}
Expand Down Expand Up @@ -1418,7 +1460,11 @@ QModelIndex QgsCptCityBrowserModel::findPath( QString path )
{
foundChild = false; // assume that the next child item will not be found

for ( int i = 0; i < rowCount( theIndex ); i++ )
int i = 0;
// if root skip first item "All Ramps"
if ( itemPath.isEmpty() )
i = 1;
for ( ; i < rowCount( theIndex ); i++ )
{
QModelIndex idx = index( i, 0, theIndex );
QgsCptCityDataItem *item = dataItem( idx );
Expand Down Expand Up @@ -1587,9 +1633,17 @@ bool QgsCptCityBrowserModel::canFetchMore( const QModelIndex & parent ) const
QgsCptCityDataItem* item = dataItem( parent );
// fetch all items initially so we know which items have children
// (nicer looking and less confusing)
if ( item )
item->populate();
return ( item && ! item->isPopulated() );

if ( ! item )
return false;

// except for "All Ramps" - this is populated when clicked on
if ( item->type() == QgsCptCityDataItem::AllRamps )
return false;

item->populate();

return ( ! item->isPopulated() );
}

void QgsCptCityBrowserModel::fetchMore( const QModelIndex & parent )
Expand Down
17 changes: 16 additions & 1 deletion src/core/symbology-ng/qgscptcityarchive.h
Expand Up @@ -90,7 +90,8 @@ class CORE_EXPORT QgsCptCityDataItem : public QObject
ColorRamp,
Collection,
Directory,
Selection
Selection,
AllRamps
};

QgsCptCityDataItem( QgsCptCityDataItem::Type type, QgsCptCityDataItem* parent,
Expand Down Expand Up @@ -277,6 +278,20 @@ class CORE_EXPORT QgsCptCitySelectionItem : public QgsCptCityCollectionItem
QStringList mSelectionsList;
};

/** An "All ramps item", which contains all items in a flat hierarchy */
class CORE_EXPORT QgsCptCityAllRampsItem : public QgsCptCityCollectionItem
{
Q_OBJECT
public:
QgsCptCityAllRampsItem( QgsCptCityDataItem* parent, QString name,
QVector<QgsCptCityDataItem*> items );
~QgsCptCityAllRampsItem();

QVector<QgsCptCityDataItem*> createChildren();

protected:
QVector<QgsCptCityDataItem*> mItems;
};


class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
Expand Down
15 changes: 13 additions & 2 deletions src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp
Expand Up @@ -161,7 +161,7 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*

tabBar->blockSignals( false );

connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished( int ) ) );
connect( this, SIGNAL( finished( int ) ), this, SLOT( onFinished() ) );

// TODO - remove this when basic archive is complete
if ( mArchive->archiveName() == DEFAULT_CPTCITY_ARCHIVE )
Expand Down Expand Up @@ -264,6 +264,7 @@ void QgsCptCityColorRampV2Dialog::on_mTreeView_clicked( const QModelIndex &index
QgsCptCityDataItem *item = mModel->dataItem( sourceIndex );
if ( ! item )
return;
QgsDebugMsg( QString( "item %1 clicked" ).arg( item->name() ) );
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
updateTreeView( item );
}
Expand Down Expand Up @@ -297,6 +298,14 @@ void QgsCptCityColorRampV2Dialog::updateTreeView( QgsCptCityDataItem *item, bool
clearCopyingInfo( );
updateListWidget( item );
}
else if ( item->type() == QgsCptCityDataItem::AllRamps )
{
lblSchemePath->setText( "" );
// lblCollectionName->setText( item->path() );
clearCopyingInfo( );
updateListWidget( item );
lblCollectionInfo->setText( tr( "All Ramps (%1)" ).arg( item->rowCount() ) );
}
else
{
QgsDebugMsg( QString( "item %1 has invalid type %2" ).arg( item->path() ).arg(( int )item->type() ) );
Expand Down Expand Up @@ -565,9 +574,11 @@ bool QgsCptCityColorRampV2Dialog::updateRamp()
mListWidget->clear();
mListRamps.clear();
cboVariantName->clear();
updatePreview( true );
clearCopyingInfo( );
lblCollectionInfo->clear();

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );
updatePreview( true );

QgsDebugMsg( "schemeName= " + mRamp->schemeName() );
if ( mRamp->schemeName() == "" )
Expand Down

0 comments on commit 063f4de

Please sign in to comment.