Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Allow hiding paths from the browser panel
  • Loading branch information
NathanW2 committed Dec 11, 2015
1 parent d1c0634 commit d021100
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 28 deletions.
2 changes: 2 additions & 0 deletions python/core/qgsbrowsermodel.sip
Expand Up @@ -96,6 +96,8 @@ class QgsBrowserModel : QAbstractItemModel
void removeFavourite( const QModelIndex &index );
void updateProjectHome();

void hidePath( QgsDataItem *item );

protected:
// populates the model
void addRootItems();
Expand Down
14 changes: 14 additions & 0 deletions src/app/qgsbrowserdockwidget.cpp
Expand Up @@ -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",
Expand Down Expand Up @@ -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() );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsbrowserdockwidget.h
Expand Up @@ -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 );
Expand Down
26 changes: 26 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsoptions.h
Expand Up @@ -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();
Expand Down
33 changes: 33 additions & 0 deletions src/core/qgsbrowsermodel.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/core/qgsbrowsermodel.h
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsdataitem.cpp
Expand Up @@ -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

Expand Down Expand Up @@ -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 ) );
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsdataitem.h
Expand Up @@ -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();
Expand Down

0 comments on commit d021100

Please sign in to comment.