/**************************** QgsGrassModuleInputModel ****************************/ QgsGrassModuleInputModel::QgsGrassModuleInputModel( QObject *parent ) : QStandardItemModel( parent ) , mWatcher( 0 ) { setColumnCount( 1 ); reload(); QString locationPath = QgsGrass::getDefaultLocationPath(); mWatcher = new QFileSystemWatcher( this ); mWatcher->addPath( locationPath ); // Watching all dirs in loacation because a dir may become a mapset later, when WIND is created //QStringList mapsets = QgsGrass::mapsets( QgsGrass::getDefaultGisdbase(), QgsGrass::getDefaultLocation() ); QStringList dirNames = locationDirNames(); foreach ( QString dirName, dirNames ) { QString dirPath = locationPath + "/" + dirName; // Watch the dir in any case, WIND mabe created later mWatcher->addPath( dirPath ); foreach ( QString watchedDir, watchedDirs() ) { watch( dirPath + "/" + watchedDir ); }
void QgsGrassModuleInputModel::onDirectoryChanged( const QString &path ) { QgsDebugMsg( "path = " + path ); QString locationPath = QgsGrass::getDefaultLocationPath(); QDir parentDir( path ); parentDir.cdUp(); QString mapset; QList<QgsGrassObject::Type> types; if ( path == locationPath ) { QgsDebugMsg( "location = " + path ); QStringList dirNames = locationDirNames(); //QStringList mapsets = QgsGrass::mapsets( QgsGrass::getDefaultGisdbase(), QgsGrass::getDefaultLocation() ); for ( int i = rowCount() - 1; i >= 0; i-- ) { QString mapset = item( i )->text(); if ( !QgsGrass::isMapset( locationPath + "/" + mapset ) ) { QgsDebugMsg( "removed mapset " + mapset ); removeRows( i, 1 ); } } Q_FOREACH ( const QString &dirName, dirNames ) { // Add to watcher in any case, either for WIND, cellhd or vector QString dirPath = locationPath + "/" + dirName; watch( dirPath ); if ( QgsGrass::isMapset( dirPath ) && findItems( dirName ).isEmpty() ) { addMapset( dirName ); } }