[FEATURE] Allow hiding paths from the browser panel

This commit is contained in:
Nathan Woodrow 2015-12-07 18:14:41 +10:00
parent d1c063419b
commit d021100e5e
10 changed files with 172 additions and 28 deletions

View File

@ -96,6 +96,8 @@ class QgsBrowserModel : QAbstractItemModel
void removeFavourite( const QModelIndex &index );
void updateProjectHome();
void hidePath( QgsDataItem *item );
protected:
// populates the model
void addRootItems();

View File

@ -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() );

View File

@ -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 );

View File

@ -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();

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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();

View File

@ -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 ) );

View File

@ -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();

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>780</width>
<height>629</height>
</rect>
</property>
<property name="minimumSize">
@ -310,8 +310,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>610</width>
<height>670</height>
<width>607</width>
<height>582</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
@ -948,8 +948,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>655</width>
<height>1057</height>
<width>601</width>
<height>1014</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
@ -1376,8 +1376,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>626</width>
<height>549</height>
<width>618</width>
<height>702</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_27">
@ -1653,6 +1653,52 @@
</layout>
</widget>
</item>
<item>
<widget class="QgsCollapsibleGroupBox" name="groupBox_28">
<property name="title">
<string>Hideen Browser Path</string>
</property>
<layout class="QGridLayout" name="_15">
<item row="0" column="0">
<widget class="QLabel" name="mSVGLabel_4">
<property name="text">
<string>Paths hidden from browser panel</string>
</property>
</widget>
</item>
<item row="0" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>31</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="3">
<widget class="QListWidget" name="mListHiddenBrowserPaths">
<property name="minimumSize">
<size>
<width>0</width>
<height>120</height>
</size>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="mBtnRemoveHiddenPath">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_8">
<property name="orientation">
@ -1693,8 +1739,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>728</width>
<height>802</height>
<width>548</width>
<height>675</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_29">
@ -2332,8 +2378,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>171</width>
<height>258</height>
<width>129</width>
<height>231</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_46">
@ -2428,8 +2474,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>526</width>
<height>327</height>
<width>453</width>
<height>281</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_25">
@ -2757,8 +2803,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>684</width>
<height>602</height>
<width>538</width>
<height>527</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_30">
@ -3243,8 +3289,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>504</width>
<height>307</height>
<width>381</width>
<height>271</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_39">
@ -3439,8 +3485,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>501</width>
<height>640</height>
<width>374</width>
<height>537</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_31">
@ -3930,8 +3976,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<height>372</height>
<width>345</width>
<height>350</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
@ -4060,8 +4106,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>565</width>
<height>647</height>
<width>416</width>
<height>595</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_15">
@ -4297,8 +4343,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>226</height>
<width>225</width>
<height>201</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_32">
@ -4397,8 +4443,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>531</width>
<height>705</height>
<width>389</width>
<height>634</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_33">