Skip to content
Permalink
Browse files

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 36bb4bef697b497045390166a4e3974a20f71d30
@@ -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();
@@ -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
@@ -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,
@@ -162,6 +162,10 @@ QgsCptCityColorRampV2Dialog::QgsCptCityColorRampV2Dialog( QgsCptCityColorRampV2*
if ( found )
buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true );
}
else
{
updateRamp();
}

tabBar->blockSignals( false );

@@ -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 );
@@ -334,7 +347,9 @@ void QgsCptCityColorRampV2Dialog::on_tabBar_currentChanged( int index )
mArchiveViewType = QgsCptCityBrowserModel::Authors;
}

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


@@ -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 );
@@ -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
@@ -568,6 +585,7 @@ bool QgsCptCityColorRampV2Dialog::eventFilter( QObject *obj, QEvent *event )

bool QgsCptCityColorRampV2Dialog::updateRamp()
{
QgsDebugMsg( "Entered" );
mListWidget->clear();
mListRamps.clear();
cboVariantName->clear();
@@ -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 )
@@ -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 )
@@ -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 );
@@ -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;

0 comments on commit 36bb4be

Please sign in to comment.
You can’t perform that action at this time.