diff --git a/python/core/qgsbrowsermodel.sip b/python/core/qgsbrowsermodel.sip index f93c35bb62f..cfe825ac5a1 100644 --- a/python/core/qgsbrowsermodel.sip +++ b/python/core/qgsbrowsermodel.sip @@ -96,6 +96,8 @@ class QgsBrowserModel : QAbstractItemModel void removeFavourite( const QModelIndex &index ); void updateProjectHome(); + void hidePath( QgsDataItem *item ); + protected: // populates the model void addRootItems(); diff --git a/src/app/qgsbrowserdockwidget.cpp b/src/app/qgsbrowserdockwidget.cpp index 01a681ad202..35755b5e6a0 100644 --- a/src/app/qgsbrowserdockwidget.cpp +++ b/src/app/qgsbrowserdockwidget.cpp @@ -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() ); diff --git a/src/app/qgsbrowserdockwidget.h b/src/app/qgsbrowserdockwidget.h index b1302b0a1c7..be30ffd2dfa 100644 --- a/src/app/qgsbrowserdockwidget.h +++ b/src/app/qgsbrowserdockwidget.h @@ -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 ); diff --git a/src/app/qgsoptions.cpp b/src/app/qgsoptions.cpp index 15f68fad671..9be752ca188 100644 --- a/src/app/qgsoptions.cpp +++ b/src/app/qgsoptions.cpp @@ -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(); diff --git a/src/app/qgsoptions.h b/src/app/qgsoptions.h index c8098b9059d..eae3cb99a4f 100644 --- a/src/app/qgsoptions.h +++ b/src/app/qgsoptions.h @@ -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(); diff --git a/src/core/qgsbrowsermodel.cpp b/src/core/qgsbrowsermodel.cpp index 2f6655fb28c..b5e89731bb6 100644 --- a/src/core/qgsbrowsermodel.cpp +++ b/src/core/qgsbrowsermodel.cpp @@ -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(); + } +} diff --git a/src/core/qgsbrowsermodel.h b/src/core/qgsbrowsermodel.h index fe1544e0c0b..7716460fab9 100644 --- a/src/core/qgsbrowsermodel.h +++ b/src/core/qgsbrowsermodel.h @@ -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(); diff --git a/src/core/qgsdataitem.cpp b/src/core/qgsdataitem.cpp index e6a8814cdc4..701730152e1 100644 --- a/src/core/qgsdataitem.cpp +++ b/src/core/qgsdataitem.cpp @@ -787,10 +787,14 @@ QVector 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 ) ); diff --git a/src/core/qgsdataitem.h b/src/core/qgsdataitem.h index 3d86da62b03..cb405efa17d 100644 --- a/src/core/qgsdataitem.h +++ b/src/core/qgsdataitem.h @@ -409,6 +409,8 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem //! @note deprecated since 2.10 - use QgsDataItemProviderRegistry Q_DECL_DEPRECATED static QVector mLibraries; + static bool hiddenPath( QString path ); + public slots: virtual void childrenCreated() override; void directoryChanged(); diff --git a/src/ui/qgsoptionsbase.ui b/src/ui/qgsoptionsbase.ui index caeddc34de1..9ef57d65833 100644 --- a/src/ui/qgsoptionsbase.ui +++ b/src/ui/qgsoptionsbase.ui @@ -6,8 +6,8 @@ 0 0 - 800 - 600 + 780 + 629 @@ -310,8 +310,8 @@ 0 0 - 610 - 670 + 607 + 582 @@ -948,8 +948,8 @@ 0 0 - 655 - 1057 + 601 + 1014 @@ -1376,8 +1376,8 @@ 0 0 - 626 - 549 + 618 + 702 @@ -1653,6 +1653,52 @@ + + + + Hideen Browser Path + + + + + + Paths hidden from browser panel + + + + + + + Qt::Horizontal + + + + 31 + 20 + + + + + + + + + 0 + 120 + + + + + + + + Remove + + + + + + @@ -1693,8 +1739,8 @@ 0 0 - 728 - 802 + 548 + 675 @@ -2332,8 +2378,8 @@ 0 0 - 171 - 258 + 129 + 231 @@ -2428,8 +2474,8 @@ 0 0 - 526 - 327 + 453 + 281 @@ -2757,8 +2803,8 @@ 0 0 - 684 - 602 + 538 + 527 @@ -3243,8 +3289,8 @@ 0 0 - 504 - 307 + 381 + 271 @@ -3439,8 +3485,8 @@ 0 0 - 501 - 640 + 374 + 537 @@ -3930,8 +3976,8 @@ 0 0 - 462 - 372 + 345 + 350 @@ -4060,8 +4106,8 @@ 0 0 - 565 - 647 + 416 + 595 @@ -4297,8 +4343,8 @@ 0 0 - 300 - 226 + 225 + 201 @@ -4397,8 +4443,8 @@ 0 0 - 531 - 705 + 389 + 634