@@ -101,6 +101,7 @@ QList<QgsGrassImport*> QgsGrassMapsetItem::mImports;
101
101
QgsGrassMapsetItem::QgsGrassMapsetItem ( QgsDataItem* parent, QString dirPath, QString path )
102
102
: QgsDirectoryItem( parent, " " , dirPath, path )
103
103
, mMapsetFileSystemWatcher( 0 )
104
+ , mRefreshLater( false )
104
105
{
105
106
QDir dir ( mDirPath );
106
107
mName = dir.dirName ();
@@ -115,17 +116,16 @@ QgsGrassMapsetItem::QgsGrassMapsetItem( QgsDataItem* parent, QString dirPath, QS
115
116
void QgsGrassMapsetItem::setState ( State state )
116
117
{
117
118
QgsDebugMsg ( " Entered" );
118
- QgsDirectoryItem::setState ( state );
119
- // TODO: verify and re-enable, it seems to be causing strange icon switching during import, sometimes
120
- #if 0
119
+
120
+ // TODO: it seems to be causing strange icon switching during import, sometimes
121
121
if ( state == Populated )
122
122
{
123
123
if ( !mMapsetFileSystemWatcher )
124
124
{
125
125
mMapsetFileSystemWatcher = new QFileSystemWatcher ( this );
126
126
mMapsetFileSystemWatcher ->addPath ( mDirPath + " /vector" );
127
127
mMapsetFileSystemWatcher ->addPath ( mDirPath + " /cellhd" );
128
- connect( mMapsetFileSystemWatcher, SIGNAL( directoryChanged( const QString & ) ), SLOT( directoryChanged () ) );
128
+ connect ( mMapsetFileSystemWatcher , SIGNAL ( directoryChanged ( const QString & ) ), SLOT ( onDirectoryChanged () ) );
129
129
}
130
130
}
131
131
else if ( state == NotPopulated )
@@ -136,7 +136,8 @@ void QgsGrassMapsetItem::setState( State state )
136
136
mMapsetFileSystemWatcher = 0 ;
137
137
}
138
138
}
139
- #endif
139
+
140
+ QgsDirectoryItem::setState ( state );
140
141
}
141
142
142
143
bool QgsGrassMapsetItem::objectInImports ( QgsGrassObject grassObject )
@@ -168,8 +169,14 @@ QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
168
169
QVector<QgsDataItem*> items;
169
170
170
171
QStringList vectorNames = QgsGrass::vectors ( mDirPath );
171
- foreach ( QString name, vectorNames )
172
+ Q_FOREACH ( QString name, vectorNames )
172
173
{
174
+ if ( mRefreshLater )
175
+ {
176
+ deleteLater ( items );
177
+ return items;
178
+ }
179
+
173
180
QgsGrassObject vectorObject ( mGisdbase , mLocation , mName , name, QgsGrassObject::Vector );
174
181
175
182
// Skip temporary import maps. If Vect_open_old during refresh fails due to missing topo, hist file remains open
@@ -293,6 +300,11 @@ QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
293
300
294
301
foreach ( QString name, rasterNames )
295
302
{
303
+ if ( mRefreshLater )
304
+ {
305
+ deleteLater ( items );
306
+ return items;
307
+ }
296
308
QString path = mPath + " /" + " raster" + " /" + name;
297
309
QString uri = mDirPath + " /" + " cellhd" + " /" + name;
298
310
QgsDebugMsg ( " uri = " + uri );
@@ -311,6 +323,11 @@ QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
311
323
QStringList groupNames = QgsGrass::groups ( mDirPath );
312
324
foreach ( QString name, groupNames )
313
325
{
326
+ if ( mRefreshLater )
327
+ {
328
+ deleteLater ( items );
329
+ return items;
330
+ }
314
331
QString path = mPath + " /" + " group" + " /" + name;
315
332
QString uri = mDirPath + " /" + " group" + " /" + name;
316
333
QgsDebugMsg ( " uri = " + uri );
@@ -322,6 +339,11 @@ QVector<QgsDataItem*> QgsGrassMapsetItem::createChildren()
322
339
323
340
foreach ( QgsGrassImport* import , mImports )
324
341
{
342
+ if ( mRefreshLater )
343
+ {
344
+ deleteLater ( items );
345
+ return items;
346
+ }
325
347
if ( !import )
326
348
{
327
349
continue ;
@@ -631,6 +653,37 @@ void QgsGrassMapsetItem::openMapset()
631
653
QgsGrass::saveMapset ();
632
654
}
633
655
656
+ void QgsGrassMapsetItem::onDirectoryChanged ()
657
+ {
658
+ QgsDebugMsg ( " entered" );
659
+ if ( state () == Populating )
660
+ {
661
+ // schedule to refresh later, because refres() simply returns if Populating
662
+ mRefreshLater = true ;
663
+ }
664
+ else
665
+ {
666
+ refresh ();
667
+ }
668
+ }
669
+
670
+ void QgsGrassMapsetItem::childrenCreated ()
671
+ {
672
+ QgsDebugMsg ( QString ( " mRefreshLater = %1" ).arg ( mRefreshLater ) );
673
+
674
+ if ( mRefreshLater )
675
+ {
676
+ QgsDebugMsg ( " directory changed during createChidren() -> refresh() again" );
677
+ mRefreshLater = false ;
678
+ setState ( Populated );
679
+ refresh ();
680
+ }
681
+ else
682
+ {
683
+ QgsDirectoryItem::childrenCreated ();
684
+ }
685
+ }
686
+
634
687
// ----------------------- QgsGrassObjectItemBase ------------------------------
635
688
636
689
QgsGrassObjectItemBase::QgsGrassObjectItemBase ( QgsGrassObject grassObject ) :
@@ -702,6 +755,9 @@ void QgsGrassObjectItemBase::deleteGrassObject( QgsDataItem* parent )
702
755
}
703
756
}
704
757
758
+
759
+ // ------------------------ QgsGrassObjectItem ----------------------------------
760
+
705
761
QgsGrassObjectItem::QgsGrassObjectItem ( QgsDataItem* parent, QgsGrassObject grassObject,
706
762
QString name, QString path, QString uri,
707
763
LayerType layerType, QString providerKey,
@@ -732,13 +788,6 @@ QList<QAction*> QgsGrassObjectItem::actions()
732
788
return lst;
733
789
}
734
790
735
- bool QgsGrassObjectItem::equal ( const QgsDataItem *other )
736
- {
737
- const QgsGrassObjectItem * item = qobject_cast<const QgsGrassObjectItem *>( other );
738
- return QgsLayerItem::equal ( other ) && item && mGrassObject == item->mGrassObject
739
- && mShowObjectActions == item->mShowObjectActions ;
740
- }
741
-
742
791
void QgsGrassObjectItem::renameGrassObject ()
743
792
{
744
793
QgsGrassObjectItemBase::renameGrassObject ( parent () );
@@ -749,20 +798,49 @@ void QgsGrassObjectItem::deleteGrassObject()
749
798
QgsGrassObjectItemBase::deleteGrassObject ( parent () );
750
799
}
751
800
801
+ bool QgsGrassObjectItem::equal ( const QgsDataItem *other )
802
+ {
803
+ const QgsGrassObjectItem * item = qobject_cast<const QgsGrassObjectItem *>( other );
804
+ return QgsLayerItem::equal ( other ) && item && mGrassObject == item->mGrassObject
805
+ && mShowObjectActions == item->mShowObjectActions ;
806
+ }
807
+
752
808
// ----------------------- QgsGrassVectorItem ------------------------------
753
809
754
810
QgsGrassVectorItem::QgsGrassVectorItem ( QgsDataItem* parent, QgsGrassObject grassObject, QString path, QString labelName, bool valid ) :
755
811
QgsDataCollectionItem( parent, labelName.isEmpty() ? grassObject.name() : labelName, path )
756
812
, QgsGrassObjectItemBase( grassObject )
757
813
, mValid( valid )
814
+ , mWatcher( 0 )
758
815
{
759
816
QgsDebugMsg ( " name = " + grassObject.name () + " path = " + path );
817
+ mCapabilities = NoCapabilities; // disable Fertile from QgsDataCollectionItem
760
818
setCapabilities ( QgsDataItem::NoCapabilities ); // disable fertility
761
819
if ( !mValid )
762
820
{
763
821
setState ( Populated );
764
822
setIconName ( " /mIconDelete.png" );
765
823
}
824
+ QString watchPath = mGrassObject .mapsetPath () + " /vector/" + mGrassObject .name ();
825
+ QgsDebugMsg ( " add watcher on " + watchPath );
826
+ // The watcher does not seem to work without parent
827
+ mWatcher = new QFileSystemWatcher ( this );
828
+ mWatcher ->addPath ( watchPath );
829
+ connect ( mWatcher , SIGNAL ( directoryChanged ( const QString & ) ), SLOT ( onDirectoryChanged () ) );
830
+ }
831
+
832
+ QgsGrassVectorItem::~QgsGrassVectorItem ()
833
+ {
834
+ delete mWatcher ;
835
+ }
836
+
837
+ void QgsGrassVectorItem::onDirectoryChanged ()
838
+ {
839
+ QgsDebugMsg ( " entered" );
840
+ if ( parent () )
841
+ {
842
+ parent ()->refresh ();
843
+ }
766
844
}
767
845
768
846
QList<QAction*> QgsGrassVectorItem::actions ()
@@ -790,6 +868,32 @@ void QgsGrassVectorItem::deleteGrassObject()
790
868
QgsGrassObjectItemBase::deleteGrassObject ( parent () );
791
869
}
792
870
871
+ bool QgsGrassVectorItem::equal ( const QgsDataItem *other )
872
+ {
873
+ if ( QgsDataCollectionItem::equal ( other ) )
874
+ {
875
+ const QgsGrassVectorItem * item = qobject_cast<const QgsGrassVectorItem *>( other );
876
+ if ( item && mGrassObject == item->mGrassObject && mValid == item->mValid )
877
+ {
878
+ if ( mChildren .size () == item->mChildren .size () )
879
+ {
880
+ // check children
881
+ for ( int i = 0 ; i < mChildren .size (); i++ )
882
+ {
883
+ QgsDataItem *child = mChildren .value ( i );
884
+ QgsDataItem *otherChild = item->mChildren .value ( i );
885
+ if ( !child || !otherChild || !child->equal ( otherChild ) )
886
+ {
887
+ return false ;
888
+ }
889
+ }
890
+ return true ;
891
+ }
892
+ }
893
+ }
894
+ return false ;
895
+ }
896
+
793
897
// ----------------------- QgsGrassVectorLayerItem ------------------------------
794
898
795
899
QgsGrassVectorLayerItem::QgsGrassVectorLayerItem ( QgsDataItem* parent, QgsGrassObject grassObject, QString layerName,
0 commit comments