@@ -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
8773void QgsGrassModuleInputModel::onDirectoryChanged ( const QString & path )
@@ -242,12 +228,44 @@ void QgsGrassModuleInputModel::refreshMapset( QStandardItem *mapsetItem, const Q
242228
243229void 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
253271QgsGrassModuleInputModel::~QgsGrassModuleInputModel ()
@@ -263,7 +281,6 @@ QgsGrassModuleInputModel *QgsGrassModuleInputModel::instance()
263281
264282QVariant 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
307324bool QgsGrassModuleInputProxy::lessThan ( const QModelIndex & left, const QModelIndex & right ) const
308325{
309- Q_UNUSED ( right )
310326 if ( mSourceModel )
311327 {
312328 // keep current mapset on top
0 commit comments