@@ -64,6 +64,7 @@ QgsGrassModuleInputModel::QgsGrassModuleInputModel( QObject *parent )
6464
6565 mWatcher = new QFileSystemWatcher ( this );
6666 connect ( mWatcher , SIGNAL ( directoryChanged ( const QString & ) ), SLOT ( onDirectoryChanged ( const QString & ) ) );
67+ connect ( mWatcher , SIGNAL ( fileChanged ( const QString & ) ), SLOT ( onFileChanged ( const QString & ) ) );
6768
6869 connect ( QgsGrass::instance (), SIGNAL ( mapsetChanged () ), SLOT ( onMapsetChanged () ) );
6970
@@ -80,7 +81,7 @@ void QgsGrassModuleInputModel::onDirectoryChanged( const QString & path )
8081 QDir parentDir ( path );
8182 parentDir.cdUp ();
8283 QString mapset;
83-
84+ QList<QgsGrassObject::Type> types;
8485 if ( path == locationPath )
8586 {
8687 QgsDebugMsg ( " location = " + path );
@@ -117,25 +118,58 @@ void QgsGrassModuleInputModel::onDirectoryChanged( const QString & path )
117118 {
118119 watch ( path + " /" + watchedDir );
119120 }
121+ // TODO: use db path defined in mapset VAR
122+ watch ( path + " /tgis/sqlite.db" );
120123 }
121124 else // cellhd or vector dir
122125 {
123126 QgsDebugMsg ( " cellhd/vector = " + path );
124127 mapset = parentDir.dirName ();
128+ if ( path.endsWith ( " cellhd" ) )
129+ {
130+ types << QgsGrassObject::Raster;
131+ }
132+ else if ( path.endsWith ( " vector" ) )
133+ {
134+ types << QgsGrassObject::Vector;
135+ }
125136 }
126137 if ( !mapset.isEmpty () )
127138 {
128139 QList<QStandardItem *> items = findItems ( mapset );
129140 if ( items.size () == 1 )
130141 {
131- refreshMapset ( items[0 ], mapset );
142+ refreshMapset ( items[0 ], mapset, types );
143+ }
144+ }
145+ }
146+
147+ void QgsGrassModuleInputModel::onFileChanged ( const QString & path )
148+ {
149+ QgsDebugMsg ( " path = " + path );
150+ // when tgis/sqlite.db is changed, this gets called twice, probably the file changes more times when it is modified
151+ if ( path.endsWith ( " /tgis/sqlite.db" ) )
152+ {
153+ QDir dir = QFileInfo ( path ).dir ();
154+ dir.cdUp ();
155+ QString mapset = dir.dirName ();
156+ QList<QStandardItem *> items = findItems ( mapset );
157+ if ( items.size () == 1 )
158+ {
159+ QList<QgsGrassObject::Type> types;
160+ types << QgsGrassObject::Strds << QgsGrassObject::Stvds << QgsGrassObject::Str3ds;
161+ refreshMapset ( items[0 ], mapset, types );
132162 }
133163 }
134164}
135165
136166void QgsGrassModuleInputModel::watch ( const QString & path )
137167{
138- if ( !mWatcher ->directories ().contains ( path ) && QFileInfo ( path ).exists () )
168+ if ( QFileInfo ( path ).isDir () && !mWatcher ->directories ().contains ( path ) )
169+ {
170+ mWatcher ->addPath ( path );
171+ }
172+ else if ( QFileInfo ( path ).isFile () && !mWatcher ->files ().contains ( path ) )
139173 {
140174 mWatcher ->addPath ( path );
141175 }
@@ -163,19 +197,24 @@ void QgsGrassModuleInputModel::addMapset( const QString & mapset )
163197 appendRow ( mapsetItem );
164198}
165199
166- void QgsGrassModuleInputModel::refreshMapset ( QStandardItem *mapsetItem, const QString & mapset )
200+ void QgsGrassModuleInputModel::refreshMapset ( QStandardItem *mapsetItem, const QString & mapset, const QList<QgsGrassObject::Type> & theTypes )
167201{
168202 QgsDebugMsg ( " mapset = " + mapset );
169203 if ( !mapsetItem )
170204 {
171205 return ;
172206 }
173207
174- QList<QgsGrassObject::Type> types;
175- types << QgsGrassObject::Raster << QgsGrassObject::Vector;
208+ QList<QgsGrassObject::Type> types = theTypes;
209+ if ( types.isEmpty () )
210+ {
211+ types << QgsGrassObject::Raster << QgsGrassObject::Vector;
212+ types << QgsGrassObject::Strds << QgsGrassObject::Stvds << QgsGrassObject::Str3ds;
213+ }
176214 foreach ( QgsGrassObject::Type type, types )
177215 {
178- QStringList maps = QgsGrass::grassObjects ( QgsGrass::getDefaultGisdbase () + " /" + QgsGrass::getDefaultLocation () + " /" + mapset, type );
216+ QgsGrassObject mapsetObject ( QgsGrass::getDefaultGisdbase (), QgsGrass::getDefaultLocation (), mapset, " " , QgsGrassObject::Mapset );
217+ QStringList maps = QgsGrass::grassObjects ( mapsetObject, type );
179218 QStringList mapNames;
180219 foreach ( const QString& map, maps )
181220 {
@@ -230,9 +269,16 @@ void QgsGrassModuleInputModel::refreshMapset( QStandardItem *mapsetItem, const Q
230269
231270void QgsGrassModuleInputModel::reload ()
232271{
272+
233273 QgsDebugMsg ( " entered" );
234- mWatcher ->removePaths ( mWatcher ->files () );
235- mWatcher ->removePaths ( mWatcher ->directories () );
274+ if ( !mWatcher ->files ().isEmpty () )
275+ {
276+ mWatcher ->removePaths ( mWatcher ->files () );
277+ }
278+ if ( !mWatcher ->directories ().isEmpty () )
279+ {
280+ mWatcher ->removePaths ( mWatcher ->directories () );
281+ }
236282
237283 clear ();
238284
@@ -258,6 +304,7 @@ void QgsGrassModuleInputModel::reload()
258304 {
259305 watch ( dirPath + " /" + watchedDir );
260306 }
307+ watch ( dirPath + " /tgis/sqlite.db" );
261308 }
262309}
263310
@@ -825,6 +872,18 @@ QgsGrassModuleInput::QgsGrassModuleInput( QgsGrassModule *module,
825872 {
826873 mType = QgsGrassObject::Raster;
827874 }
875+ else if ( element == " strds" )
876+ {
877+ mType = QgsGrassObject::Strds;
878+ }
879+ else if ( element == " stvds" )
880+ {
881+ mType = QgsGrassObject::Stvds;
882+ }
883+ else if ( element == " str3ds" )
884+ {
885+ mType = QgsGrassObject::Str3ds;
886+ }
828887 else
829888 {
830889 mErrors << tr ( " GRASS element %1 not supported" ).arg ( element );
0 commit comments