Skip to content

Commit d021100

Browse files
committed
[FEATURE] Allow hiding paths from the browser panel
1 parent d1c0634 commit d021100

10 files changed

+172
-28
lines changed

python/core/qgsbrowsermodel.sip

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class QgsBrowserModel : QAbstractItemModel
9696
void removeFavourite( const QModelIndex &index );
9797
void updateProjectHome();
9898

99+
void hidePath( QgsDataItem *item );
100+
99101
protected:
100102
// populates the model
101103
void addRootItems();

src/app/qgsbrowserdockwidget.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ void QgsBrowserDockWidget::showContextMenu( const QPoint & pt )
395395
menu->addAction( tr( "Remove favourite" ), this, SLOT( removeFavourite() ) );
396396
}
397397
menu->addAction( tr( "Properties" ), this, SLOT( showProperties() ) );
398+
menu->addAction( tr( "Hide from browser" ), this, SLOT( hideItem() ) );
398399
QAction *action = menu->addAction( tr( "Fast scan this dir." ), this, SLOT( toggleFastScan() ) );
399400
action->setCheckable( true );
400401
action->setChecked( settings.value( "/qgis/scanItemsFastScanUris",
@@ -580,6 +581,19 @@ void QgsBrowserDockWidget::addSelectedLayers()
580581
QApplication::restoreOverrideCursor();
581582
}
582583

584+
void QgsBrowserDockWidget::hideItem()
585+
{
586+
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );
587+
QgsDataItem* item = mModel->dataItem( index );
588+
if ( ! item )
589+
return;
590+
591+
if ( item->type() == QgsDataItem::Directory )
592+
{
593+
mModel->hidePath( item );
594+
}
595+
}
596+
583597
void QgsBrowserDockWidget::showProperties()
584598
{
585599
QModelIndex index = mProxyModel->mapToSource( mBrowserView->currentIndex() );

src/app/qgsbrowserdockwidget.h

+1
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ class APP_EXPORT QgsBrowserDockWidget : public QDockWidget, private Ui::QgsBrows
128128
void addCurrentLayer();
129129
void addSelectedLayers();
130130
void showProperties();
131+
void hideItem();
131132
void toggleFastScan();
132133

133134
void selectionChanged( const QItemSelection & selected, const QItemSelection & deselected );

src/app/qgsoptions.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,16 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
258258
}
259259
}
260260

261+
QStringList hiddenItems = settings.value( "/browser/hiddenPaths",
262+
QStringList() ).toStringList();
263+
QStringList::const_iterator pathIt = hiddenItems.constBegin();
264+
for ( ; pathIt != hiddenItems.constEnd(); ++pathIt )
265+
{
266+
QListWidgetItem* newItem = new QListWidgetItem( mListHiddenBrowserPaths );
267+
newItem->setText( *pathIt );
268+
mListHiddenBrowserPaths->addItem( newItem );
269+
}
270+
261271
//Network timeout
262272
mNetworkTimeoutSpinBox->setValue( settings.value( "/qgis/networkAndProxy/networkTimeout", "60000" ).toInt() );
263273
leUserAgent->setText( settings.value( "/qgis/networkAndProxy/userAgent", "Mozilla/5.0" ).toString() );
@@ -865,6 +875,8 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) :
865875
mVariableEditor->reloadContext();
866876
mVariableEditor->setEditableScopeIndex( 0 );
867877

878+
879+
868880
mAdvancedSettingsEditor->setSettingsObject( &settings );
869881

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

1055+
QStringList paths;
1056+
for ( int i = 0; i < mListHiddenBrowserPaths->count(); ++i )
1057+
{
1058+
paths << mListHiddenBrowserPaths->item( i )->text();
1059+
}
1060+
settings.setValue( "/browser/hiddenPaths", paths );
1061+
10431062
//Network timeout
10441063
settings.setValue( "/qgis/networkAndProxy/networkTimeout", mNetworkTimeoutSpinBox->value() );
10451064
settings.setValue( "/qgis/networkAndProxy/userAgent", leUserAgent->text() );
@@ -1692,6 +1711,13 @@ void QgsOptions::on_mBtnAddSVGPath_clicked()
16921711
}
16931712
}
16941713

1714+
void QgsOptions::on_mBtnRemoveHiddenPath_clicked()
1715+
{
1716+
int currentRow = mListHiddenBrowserPaths->currentRow();
1717+
QListWidgetItem* itemToRemove = mListHiddenBrowserPaths->takeItem( currentRow );
1718+
delete itemToRemove;
1719+
}
1720+
16951721
void QgsOptions::on_mBtnRemoveSVGPath_clicked()
16961722
{
16971723
int currentRow = mListSVGPaths->currentRow();

src/app/qgsoptions.h

+5
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
155155
* used for finding SVG files. */
156156
void on_mBtnRemoveSVGPath_clicked();
157157

158+
/* Let the user remove a path from the hidden path list
159+
* for the browser */
160+
void on_mBtnRemoveHiddenPath_clicked();
161+
162+
158163
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
159164

160165
void on_mBrowseCacheDirectory_clicked();

src/core/qgsbrowsermodel.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ void QgsBrowserModel::addRootItems()
112112
Q_FOREACH ( const QFileInfo& drive, QDir::drives() )
113113
{
114114
QString path = drive.absolutePath();
115+
116+
if ( QgsDirectoryItem::hiddenPath( path ) )
117+
continue;
118+
115119
QgsDirectoryItem *item = new QgsDirectoryItem( NULL, path, path );
116120

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

530534
mFavourites->removeDirectory( item );
531535
}
536+
537+
void QgsBrowserModel::hidePath( QgsDataItem *item )
538+
{
539+
QSettings settings;
540+
QStringList hiddenItems = settings.value( "/browser/hiddenPaths",
541+
QStringList() ).toStringList();
542+
int idx = hiddenItems.indexOf( item->path() );
543+
if ( idx != -1 )
544+
{
545+
hiddenItems.removeAt( idx );
546+
}
547+
else
548+
{
549+
hiddenItems << item->path();
550+
}
551+
settings.setValue( "/browser/hiddenPaths", hiddenItems );
552+
if ( item->parent() )
553+
{
554+
item->parent()->deleteChildItem( item );
555+
}
556+
else
557+
{
558+
int i = mRootItems.indexOf( item );
559+
emit beginRemoveRows( QModelIndex(), i, i );
560+
mRootItems.remove( i );
561+
item->deleteLater();
562+
emit endRemoveRows();
563+
}
564+
}

src/core/qgsbrowsermodel.h

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class CORE_EXPORT QgsBrowserModel : public QAbstractItemModel
138138
void removeFavourite( const QModelIndex &index );
139139
void updateProjectHome();
140140

141+
void hidePath( QgsDataItem *item );
142+
141143
protected:
142144
// populates the model
143145
void addRootItems();

src/core/qgsdataitem.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -787,10 +787,14 @@ QVector<QgsDataItem*> QgsDirectoryItem::createChildren()
787787
deleteLater( children );
788788
return children;
789789
}
790+
790791
QString subdirPath = dir.absoluteFilePath( subdir );
792+
791793
QgsDebugMsgLevel( QString( "creating subdir: %1" ).arg( subdirPath ), 2 );
792794

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

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

887+
bool QgsDirectoryItem::hiddenPath( QString path )
888+
{
889+
QSettings settings;
890+
QStringList hiddenItems = settings.value( "/browser/hiddenPaths",
891+
QStringList() ).toStringList();
892+
int idx = hiddenItems.indexOf( path );
893+
return ( idx > -1 );
894+
}
895+
883896
void QgsDirectoryItem::childrenCreated()
884897
{
885898
QgsDebugMsg( QString( "mRefreshLater = %1" ).arg( mRefreshLater ) );

src/core/qgsdataitem.h

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
409409
//! @note deprecated since 2.10 - use QgsDataItemProviderRegistry
410410
Q_DECL_DEPRECATED static QVector<QLibrary*> mLibraries;
411411

412+
static bool hiddenPath( QString path );
413+
412414
public slots:
413415
virtual void childrenCreated() override;
414416
void directoryChanged();

0 commit comments

Comments
 (0)