Skip to content

Commit d021100

Browse files
committedDec 11, 2015
[FEATURE] Allow hiding paths from the browser panel
1 parent d1c0634 commit d021100

File tree

10 files changed

+172
-28
lines changed

10 files changed

+172
-28
lines changed
 

‎python/core/qgsbrowsermodel.sip

Lines changed: 2 additions & 0 deletions
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

Lines changed: 14 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 26 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 33 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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();

‎src/ui/qgsoptionsbase.ui

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>800</width>
10-
<height>600</height>
9+
<width>780</width>
10+
<height>629</height>
1111
</rect>
1212
</property>
1313
<property name="minimumSize">
@@ -310,8 +310,8 @@
310310
<rect>
311311
<x>0</x>
312312
<y>0</y>
313-
<width>610</width>
314-
<height>670</height>
313+
<width>607</width>
314+
<height>582</height>
315315
</rect>
316316
</property>
317317
<layout class="QVBoxLayout" name="verticalLayout_28">
@@ -948,8 +948,8 @@
948948
<rect>
949949
<x>0</x>
950950
<y>0</y>
951-
<width>655</width>
952-
<height>1057</height>
951+
<width>601</width>
952+
<height>1014</height>
953953
</rect>
954954
</property>
955955
<layout class="QVBoxLayout" name="verticalLayout_22">
@@ -1376,8 +1376,8 @@
13761376
<rect>
13771377
<x>0</x>
13781378
<y>0</y>
1379-
<width>626</width>
1380-
<height>549</height>
1379+
<width>618</width>
1380+
<height>702</height>
13811381
</rect>
13821382
</property>
13831383
<layout class="QVBoxLayout" name="verticalLayout_27">
@@ -1653,6 +1653,52 @@
16531653
</layout>
16541654
</widget>
16551655
</item>
1656+
<item>
1657+
<widget class="QgsCollapsibleGroupBox" name="groupBox_28">
1658+
<property name="title">
1659+
<string>Hideen Browser Path</string>
1660+
</property>
1661+
<layout class="QGridLayout" name="_15">
1662+
<item row="0" column="0">
1663+
<widget class="QLabel" name="mSVGLabel_4">
1664+
<property name="text">
1665+
<string>Paths hidden from browser panel</string>
1666+
</property>
1667+
</widget>
1668+
</item>
1669+
<item row="0" column="1">
1670+
<spacer>
1671+
<property name="orientation">
1672+
<enum>Qt::Horizontal</enum>
1673+
</property>
1674+
<property name="sizeHint" stdset="0">
1675+
<size>
1676+
<width>31</width>
1677+
<height>20</height>
1678+
</size>
1679+
</property>
1680+
</spacer>
1681+
</item>
1682+
<item row="1" column="0" colspan="3">
1683+
<widget class="QListWidget" name="mListHiddenBrowserPaths">
1684+
<property name="minimumSize">
1685+
<size>
1686+
<width>0</width>
1687+
<height>120</height>
1688+
</size>
1689+
</property>
1690+
</widget>
1691+
</item>
1692+
<item row="0" column="2">
1693+
<widget class="QPushButton" name="mBtnRemoveHiddenPath">
1694+
<property name="text">
1695+
<string>Remove</string>
1696+
</property>
1697+
</widget>
1698+
</item>
1699+
</layout>
1700+
</widget>
1701+
</item>
16561702
<item>
16571703
<spacer name="verticalSpacer_8">
16581704
<property name="orientation">
@@ -1693,8 +1739,8 @@
16931739
<rect>
16941740
<x>0</x>
16951741
<y>0</y>
1696-
<width>728</width>
1697-
<height>802</height>
1742+
<width>548</width>
1743+
<height>675</height>
16981744
</rect>
16991745
</property>
17001746
<layout class="QVBoxLayout" name="verticalLayout_29">
@@ -2332,8 +2378,8 @@
23322378
<rect>
23332379
<x>0</x>
23342380
<y>0</y>
2335-
<width>171</width>
2336-
<height>258</height>
2381+
<width>129</width>
2382+
<height>231</height>
23372383
</rect>
23382384
</property>
23392385
<layout class="QHBoxLayout" name="horizontalLayout_46">
@@ -2428,8 +2474,8 @@
24282474
<rect>
24292475
<x>0</x>
24302476
<y>0</y>
2431-
<width>526</width>
2432-
<height>327</height>
2477+
<width>453</width>
2478+
<height>281</height>
24332479
</rect>
24342480
</property>
24352481
<layout class="QVBoxLayout" name="verticalLayout_25">
@@ -2757,8 +2803,8 @@
27572803
<rect>
27582804
<x>0</x>
27592805
<y>0</y>
2760-
<width>684</width>
2761-
<height>602</height>
2806+
<width>538</width>
2807+
<height>527</height>
27622808
</rect>
27632809
</property>
27642810
<layout class="QVBoxLayout" name="verticalLayout_30">
@@ -3243,8 +3289,8 @@
32433289
<rect>
32443290
<x>0</x>
32453291
<y>0</y>
3246-
<width>504</width>
3247-
<height>307</height>
3292+
<width>381</width>
3293+
<height>271</height>
32483294
</rect>
32493295
</property>
32503296
<layout class="QVBoxLayout" name="verticalLayout_39">
@@ -3439,8 +3485,8 @@
34393485
<rect>
34403486
<x>0</x>
34413487
<y>0</y>
3442-
<width>501</width>
3443-
<height>640</height>
3488+
<width>374</width>
3489+
<height>537</height>
34443490
</rect>
34453491
</property>
34463492
<layout class="QVBoxLayout" name="verticalLayout_31">
@@ -3930,8 +3976,8 @@
39303976
<rect>
39313977
<x>0</x>
39323978
<y>0</y>
3933-
<width>462</width>
3934-
<height>372</height>
3979+
<width>345</width>
3980+
<height>350</height>
39353981
</rect>
39363982
</property>
39373983
<layout class="QVBoxLayout" name="verticalLayout_6">
@@ -4060,8 +4106,8 @@
40604106
<rect>
40614107
<x>0</x>
40624108
<y>0</y>
4063-
<width>565</width>
4064-
<height>647</height>
4109+
<width>416</width>
4110+
<height>595</height>
40654111
</rect>
40664112
</property>
40674113
<layout class="QGridLayout" name="gridLayout_15">
@@ -4297,8 +4343,8 @@
42974343
<rect>
42984344
<x>0</x>
42994345
<y>0</y>
4300-
<width>300</width>
4301-
<height>226</height>
4346+
<width>225</width>
4347+
<height>201</height>
43024348
</rect>
43034349
</property>
43044350
<layout class="QVBoxLayout" name="verticalLayout_32">
@@ -4397,8 +4443,8 @@
43974443
<rect>
43984444
<x>0</x>
43994445
<y>0</y>
4400-
<width>531</width>
4401-
<height>705</height>
4446+
<width>389</width>
4447+
<height>634</height>
44024448
</rect>
44034449
</property>
44044450
<layout class="QVBoxLayout" name="verticalLayout_33">

0 commit comments

Comments
 (0)
Please sign in to comment.