Skip to content

Commit 0692f25

Browse files
committed
[GRASS] refresh module input when location changed
1 parent ac38d89 commit 0692f25

2 files changed

Lines changed: 40 additions & 20 deletions

File tree

src/plugins/grass/qgsgrassmoduleinput.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,15 @@ QgsGrassModuleInputModel::QgsGrassModuleInputModel( QObject *parent )
5959
: QStandardItemModel( parent )
6060
, mWatcher( 0 )
6161
{
62+
QgsDebugMsg( "entered" );
6263
setColumnCount( 1 );
63-
reload();
6464

65-
QString locationPath = QgsGrass::getDefaultLocationPath();
6665
mWatcher = new QFileSystemWatcher( this );
67-
mWatcher->addPath( locationPath );
66+
connect( mWatcher, SIGNAL( directoryChanged( const QString & ) ), SLOT( onDirectoryChanged( const QString & ) ) );
6867

69-
// Watching all dirs in loacation because a dir may become a mapset later, when WIND is created
68+
connect( QgsGrass::instance(), SIGNAL( mapsetChanged() ), SLOT( onMapsetChanged() ) );
7069

71-
//QStringList mapsets = QgsGrass::mapsets( QgsGrass::getDefaultGisdbase(), QgsGrass::getDefaultLocation() );
72-
QStringList dirNames = locationDirNames();
73-
foreach ( QString dirName, dirNames )
74-
{
75-
QString dirPath = locationPath + "/" + dirName;
76-
// Watch the dir in any case, WIND mabe created later
77-
mWatcher->addPath( dirPath );
78-
79-
foreach ( QString watchedDir, watchedDirs() )
80-
{
81-
watch( dirPath + "/" + watchedDir );
82-
}
83-
}
84-
connect( mWatcher, SIGNAL( directoryChanged( const QString & ) ), SLOT( onDirectoryChanged( const QString & ) ) );
70+
reload();
8571
}
8672

8773
void QgsGrassModuleInputModel::onDirectoryChanged( const QString & path )
@@ -242,12 +228,44 @@ void QgsGrassModuleInputModel::refreshMapset( QStandardItem *mapsetItem, const Q
242228

243229
void QgsGrassModuleInputModel::reload()
244230
{
231+
QgsDebugMsg( "entered" );
232+
mWatcher->removePaths( mWatcher->files() );
233+
mWatcher->removePaths( mWatcher->directories() );
234+
245235
clear();
236+
237+
mLocationPath = QgsGrass::getDefaultLocationPath();
238+
246239
QStringList mapsets = QgsGrass::mapsets( QgsGrass::getDefaultGisdbase(), QgsGrass::getDefaultLocation() );
247240
foreach ( QString mapset, mapsets )
248241
{
249242
addMapset( mapset );
250243
}
244+
245+
mWatcher->addPath( mLocationPath );
246+
247+
// Watching all dirs in location because a dir may become a mapset later, when WIND is created
248+
QStringList dirNames = locationDirNames();
249+
foreach ( QString dirName, dirNames )
250+
{
251+
QString dirPath = mLocationPath + "/" + dirName;
252+
// Watch the dir in any case, WIND mabe created later
253+
mWatcher->addPath( dirPath );
254+
255+
foreach ( QString watchedDir, watchedDirs() )
256+
{
257+
watch( dirPath + "/" + watchedDir );
258+
}
259+
}
260+
}
261+
262+
void QgsGrassModuleInputModel::onMapsetChanged()
263+
{
264+
QgsDebugMsg( "entered" );
265+
if ( mLocationPath != QgsGrass::getDefaultLocationPath() )
266+
{
267+
reload();
268+
}
251269
}
252270

253271
QgsGrassModuleInputModel::~QgsGrassModuleInputModel()
@@ -263,7 +281,6 @@ QgsGrassModuleInputModel *QgsGrassModuleInputModel::instance()
263281

264282
QVariant QgsGrassModuleInputModel::data( const QModelIndex & index, int role ) const
265283
{
266-
QgsDebugMsg( "entered" );
267284
QVariant data = QStandardItemModel::data( index, role );
268285
if ( role == Qt::DisplayRole || role == Qt::EditRole ) // EditRole for combo
269286
{
@@ -306,7 +323,6 @@ bool QgsGrassModuleInputProxy::filterAcceptsRow( int sourceRow, const QModelInde
306323

307324
bool QgsGrassModuleInputProxy::lessThan( const QModelIndex & left, const QModelIndex & right ) const
308325
{
309-
Q_UNUSED( right )
310326
if ( mSourceModel )
311327
{
312328
// keep current mapset on top

src/plugins/grass/qgsgrassmoduleinput.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,22 @@ class QgsGrassModuleInputModel : public QStandardItemModel
7474
/** Reload current mapset */
7575
void reload();
7676

77+
void onMapsetChanged();
78+
7779
void onDirectoryChanged( const QString & path );
7880

7981
private:
8082
void addMapset( const QString & mapset );
8183
void refreshMapset( QStandardItem *mapsetItem, const QString & mapset );
8284
// Add to watched paths if exists and if not yet watched
8385
void watch( const QString & path );
86+
QString mLocationPath;
8487
// mapset watched dirs
8588
QStringList watchedDirs() { QStringList l; l << "cellhd" << "vector"; return l; }
8689
// names of
8790
QStringList locationDirNames();
8891
QFileSystemWatcher *mWatcher;
92+
8993
};
9094

9195
// Filter maps by type

0 commit comments

Comments
 (0)