Skip to content
Permalink
Browse files

[FEATURE] Allow hiding paths from the browser panel

  • Loading branch information
NathanW2 committed Dec 11, 2015
1 parent d1c0634 commit d021100e5ec994fc1750df50a6a3d5776cee2502
@@ -96,6 +96,8 @@ class QgsBrowserModel : QAbstractItemModel
void removeFavourite( const QModelIndex &index );
void updateProjectHome();

void hidePath( QgsDataItem *item );

protected:
// populates the model
void addRootItems();
@@ -395,6 +395,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
menu->addAction( tr( "Remove favourite" ), this, SLOT( removeFavourite() ) );
}
menu->addAction( tr( "Properties" ), this, SLOT( showProperties() ) );
menu->addAction( tr( "Hide from browser" ), this, SLOT( hideItem() ) );
QAction *action = menu->addAction( tr( "Fast scan this dir." ), this, SLOT( toggleFastScan() ) );
action->setCheckable( true );
action->setChecked( settings.value( "/qgis/scanItemsFastScanUris",
@@ -580,6 +581,19 @@ void QgsBrowserDockWidget::addSelectedLayers()
QApplication::restoreOverrideCursor();
}

void QgsBrowserDockWidget::hideItem()
{
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
QgsDataItem* item = mModel->dataItem( index );
if ( ! item )
return;

if ( item->type() == QgsDataItem::Directory )
{
mModel->hidePath( item );
}
}

void QgsBrowserDockWidget::showProperties()
{
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
@@ -128,6 +128,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows
void addCurrentLayer();
void addSelectedLayers();
void showProperties();
void hideItem();
void toggleFastScan();

void selectionChanged( const QItemSelection & selected, const QItemSelection & deselected );
@@ -258,6 +258,16 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
}
}

QStringList hiddenItems = settings.value( "/browser/hiddenPaths",
QStringList() ).toStringList();
QStringList::const_iterator pathIt = hiddenItems.constBegin();
for ( ; pathIt != hiddenItems.constEnd(); ++pathIt )
{
QListWidgetItem* newItem = new QListWidgetItem( mListHiddenBrowserPaths );
newItem->setText( *pathIt );
mListHiddenBrowserPaths->addItem( newItem );
}

//Network timeout
mNetworkTimeoutSpinBox->setValue( settings.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt() );
leUserAgent->setText( settings.value( "/qgis/networkAndProxy/userAgent", "Mozilla/5.0" ).toString() );
@@ -865,6 +875,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
mVariableEditor->reloadContext();
mVariableEditor->setEditableScopeIndex( 0 );



mAdvancedSettingsEditor->setSettingsObject( &settings );

// restore window and widget geometry/state
@@ -1040,6 +1052,13 @@ void QgsOptions::saveOptions()
}
settings.setValue( "composer/searchPathsForTemplates", myPaths );

QStringList paths;
for ( int i = 0; i < mListHiddenBrowserPaths->count(); ++i )
{
paths << mListHiddenBrowserPaths->item( i )->text();
}
settings.setValue( "/browser/hiddenPaths", paths );

//Network timeout
settings.setValue( "/qgis/networkAndProxy/networkTimeout", mNetworkTimeoutSpinBox->value() );
settings.setValue( "/qgis/networkAndProxy/userAgent", leUserAgent->text() );
@@ -1692,6 +1711,13 @@ void QgsOptions::on_mBtnAddSVGPath_clicked()
}
}

void QgsOptions::on_mBtnRemoveHiddenPath_clicked()
{
int currentRow = mListHiddenBrowserPaths->currentRow();
QListWidgetItem* itemToRemove = mListHiddenBrowserPaths->takeItem( currentRow );
delete itemToRemove;
}

void QgsOptions::on_mBtnRemoveSVGPath_clicked()
{
int currentRow = mListSVGPaths->currentRow();
@@ -155,6 +155,11 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
* used for finding SVG files. */
void on_mBtnRemoveSVGPath_clicked();

/* Let the user remove a path from the hidden path list
* for the browser */
void on_mBtnRemoveHiddenPath_clicked();


void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }

void on_mBrowseCacheDirectory_clicked();
@@ -112,6 +112,10 @@ void QgsBrowserModel::addRootItems()
Q_FOREACH ( const QFileInfo& drive, QDir::drives() )
{
QString path = drive.absolutePath();

if ( QgsDirectoryItem::hiddenPath( path ) )
continue;

QgsDirectoryItem *item = new QgsDirectoryItem( NULL, path, path );

connectItem( item );
@@ -529,3 +533,32 @@ void QgsBrowserModel::removeFavourite( const QModelIndex &index )

mFavourites->removeDirectory( item );
}

void QgsBrowserModel::hidePath( QgsDataItem *item )
{
QSettings settings;
QStringList hiddenItems = settings.value( "/browser/hiddenPaths",
QStringList() ).toStringList();
int idx = hiddenItems.indexOf( item->path() );
if ( idx != -1 )
{
hiddenItems.removeAt( idx );
}
else
{
hiddenItems << item->path();
}
settings.setValue( "/browser/hiddenPaths", hiddenItems );
if ( item->parent() )
{
item->parent()->deleteChildItem( item );
}
else
{
int i = mRootItems.indexOf( item );
emit beginRemoveRows( QModelIndex(), i, i );
mRootItems.remove( i );
item->deleteLater();
emit endRemoveRows();
}
}
@@ -138,6 +138,8 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
void removeFavourite( const QModelIndex &index );
void updateProjectHome();

void hidePath( QgsDataItem *item );

protected:
// populates the model
void addRootItems();
@@ -787,10 +787,14 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren()
deleteLater( children );
return children;
}

QString subdirPath = dir.absoluteFilePath( subdir );

QgsDebugMsgLevel( QString( "creating subdir: %1" ).arg( subdirPath ), 2 );

QString path = mPath + '/' + subdir; // may differ from subdirPath
if ( QgsDirectoryItem::hiddenPath( path ) )
continue;
QgsDirectoryItem *item = new QgsDirectoryItem( this, subdir, subdirPath, path );
// propagate signals up to top

@@ -880,6 +884,15 @@ void QgsDirectoryItem::directoryChanged()
}
}

bool QgsDirectoryItem::hiddenPath( QString path )
{
QSettings settings;
QStringList hiddenItems = settings.value( "/browser/hiddenPaths",
QStringList() ).toStringList();
int idx = hiddenItems.indexOf( path );
return ( idx > -1 );
}

void QgsDirectoryItem::childrenCreated()
{
QgsDebugMsg( QString( "mRefreshLater = %1" ).arg( mRefreshLater ) );
@@ -409,6 +409,8 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
//! @note deprecated since 2.10 - use QgsDataItemProviderRegistry
Q_DECL_DEPRECATED static QVector<QLibrary*> mLibraries;

static bool hiddenPath( QString path );

public slots:
virtual void childrenCreated() override;
void directoryChanged();

0 comments on commit d021100

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