Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
cpt-city: show all ramps by default when opening dialog and changing …
…view types, unless a ramp has been selected
  • Loading branch information
etiennesky committed Sep 20, 2013
1 parent 391488a commit 36bb4be
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/core/symbology-ng/qgscptcityarchive.cpp
Expand Up @@ -860,7 +860,7 @@ QVector< QgsCptCityDataItem* > QgsCptCityCollectionItem::childrenRamps( bool rec
{
QgsCptCityCollectionItem* collectionItem = dynamic_cast<QgsCptCityCollectionItem*>( childItem );
QgsCptCityColorRampItem* rampItem = dynamic_cast<QgsCptCityColorRampItem*>( childItem );
QgsDebugMsg( QString( "child path= %1 coll= %2 ramp = %3" ).arg( childItem->path() ).arg( collectionItem != 0 ).arg( rampItem != 0 ) );
QgsDebugMsgLevel( QString( "child path= %1 coll= %2 ramp = %3" ).arg( childItem->path() ).arg( collectionItem != 0 ).arg( rampItem != 0 ), 2 );
if ( collectionItem && recursive )
{
collectionItem->populate();
Expand Down Expand Up @@ -1493,6 +1493,26 @@ QModelIndex QgsCptCityBrowserModel::findPath( QString path )

QgsDebugMsg( "path = " + path );

// special case if searching for first item "All Ramps", do not search into tree
if ( path.isEmpty() )
{
for ( int i = 0; i < rowCount( theIndex ); i++ )
{
QModelIndex idx = index( i, 0, theIndex );
QgsCptCityDataItem *item = dataItem( idx );
if ( !item )
return QModelIndex(); // an error occurred

itemPath = item->path();

if ( itemPath == path )
{
QgsDebugMsg( "Arrived " + itemPath );
return idx; // we have found the item we have been looking for
}
}
}

while ( foundChild )
{
foundChild = false; // assume that the next child item will not be found
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgscptcityarchive.h
Expand Up @@ -309,7 +309,7 @@ class CORE_EXPORT QgsCptCityBrowserModel : public QAbstractItemModel
{
Authors = 0,
Selections = 1,
List = 2
List = 2 // not used anymore
};

QgsCptCityBrowserModel( QObject* parent = 0,
Expand Down
37 changes: 37 additions & 0 deletions src/gui/symbology-ng/qgscptcitycolorrampv2dialog.cpp
Expand Up @@ -162,6 +162,10 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
if ( found )
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
}
else
{
updateRamp();
}

tabBar->blockSignals( false );

Expand Down Expand Up @@ -315,8 +319,17 @@ void QgsCptCityColorRampV2Dialog::on_mListWidget_itemClicked( QListWidgetItem *
}
}

void QgsCptCityColorRampV2Dialog::on_mListWidget_itemSelectionChanged()
{
if ( mListWidget->selectedItems().count() == 0 )
{
mRamp->setName( "", "" );
}
}

void QgsCptCityColorRampV2Dialog::on_tabBar_currentChanged( int index )
{
QgsDebugMsg( "Entered" );
if ( index == 0 )
{
setTreeModel( mSelectionsModel );
Expand All @@ -334,7 +347,9 @@ void QgsCptCityColorRampV2Dialog::on_tabBar_currentChanged( int index )
mArchiveViewType = QgsCptCityBrowserModel::Authors;
}

mListWidget->blockSignals( true );
updateRamp();
mListWidget->blockSignals( false );
}


Expand Down Expand Up @@ -506,6 +521,7 @@ bool QgsCptCityColorRampV2Dialog::saveAsGradientRamp() const

void QgsCptCityColorRampV2Dialog::updateListWidget( QgsCptCityDataItem *item )
{
mListWidget->blockSignals( true );
mListWidget->clear();
mListRamps.clear();
QgsCptCityCollectionItem* colItem = dynamic_cast<QgsCptCityCollectionItem*>( item );
Expand Down Expand Up @@ -535,6 +551,7 @@ void QgsCptCityColorRampV2Dialog::updateListWidget( QgsCptCityDataItem *item )
{
QgsDebugMsg( "invalid item" );
}
mListWidget->blockSignals( false );
}

// this function is for a svg preview, available if the svg files have been processed with svgx
Expand Down Expand Up @@ -568,6 +585,7 @@ bool QgsCptCityColorRampV2Dialog::eventFilter( QObject *obj, QEvent *event )

bool QgsCptCityColorRampV2Dialog::updateRamp()
{
QgsDebugMsg( "Entered" );
mListWidget->clear();
mListRamps.clear();
cboVariantName->clear();
Expand All @@ -579,12 +597,17 @@ bool QgsCptCityColorRampV2Dialog::updateRamp()

QgsDebugMsg( "schemeName= " + mRamp->schemeName() );
if ( mRamp->schemeName() == "" )
{
showAll();
return false;
}

// search for item in model
QModelIndex modelIndex = mModel->findPath( mRamp->schemeName() );
if ( modelIndex == QModelIndex() )
{
return false;
}
QgsCptCityColorRampItem* childItem =
dynamic_cast<QgsCptCityColorRampItem*>( mModel->dataItem( modelIndex ) );
if ( ! childItem )
Expand Down Expand Up @@ -628,8 +651,22 @@ bool QgsCptCityColorRampV2Dialog::updateRamp()
return false;
}

void QgsCptCityColorRampV2Dialog::showAll()
{
QModelIndex modelIndex = mModel->findPath( "" );
if ( modelIndex != QModelIndex() )
{
QModelIndex selIndex = mTreeFilter->mapFromSource( modelIndex );
mTreeView->setCurrentIndex( selIndex );
mTreeView->setExpanded( selIndex, true );
mTreeView->scrollTo( selIndex, QAbstractItemView::PositionAtCenter );
updateTreeView( mModel->dataItem( modelIndex ), false );
}
}

void QgsCptCityColorRampV2Dialog::setTreeModel( QgsCptCityBrowserModel* model )
{
QgsDebugMsg( "Entered" );
mModel = model;

if ( mTreeFilter )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgscptcitycolorrampv2dialog.h
Expand Up @@ -48,6 +48,7 @@ class GUI_EXPORT QgsCptCityColorRampV2Dialog : public QDialog, private Ui::QgsCp

void on_mTreeView_clicked( const QModelIndex & );
void on_mListWidget_itemClicked( QListWidgetItem * item );
void on_mListWidget_itemSelectionChanged();
void on_tabBar_currentChanged( int index );
void on_pbtnLicenseDetails_pressed();
void on_cboVariantName_currentIndexChanged( int index );
Expand All @@ -70,6 +71,7 @@ class GUI_EXPORT QgsCptCityColorRampV2Dialog : public QDialog, private Ui::QgsCp

/* void refreshModel( const QModelIndex& index ); */
bool updateRamp();
void showAll();
void setTreeModel( QgsCptCityBrowserModel* model );

QgsCptCityBrowserModel* mModel;
Expand Down

0 comments on commit 36bb4be

Please sign in to comment.