@@ -83,10 +83,10 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
83
83
QgsMapLayer::~QgsMapLayer ()
84
84
{
85
85
delete mCRS ;
86
- if ( mpCacheImage )
87
- {
88
- delete mpCacheImage;
89
- }
86
+ if ( mpCacheImage )
87
+ {
88
+ delete mpCacheImage;
89
+ }
90
90
}
91
91
92
92
QgsMapLayer::LayerType QgsMapLayer::type () const
@@ -171,6 +171,12 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
171
171
uri.setDatabase ( QgsProject::instance ()->readPath ( uri.database () ) );
172
172
mDataSource = uri.uri ();
173
173
}
174
+ else if ( provider == " ogr" )
175
+ {
176
+ QStringList theURIParts = mDataSource .split ( " |" );
177
+ theURIParts[0 ] = QgsProject::instance ()->readPath ( theURIParts[0 ] );
178
+ mDataSource = theURIParts.join ( " |" );
179
+ }
174
180
else
175
181
{
176
182
mDataSource = QgsProject::instance ()->readPath ( mDataSource );
@@ -221,15 +227,7 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
221
227
}
222
228
223
229
// use scale dependent visibility flag
224
- QString hasScaleBasedVisibility = element.attribute ( " hasScaleBasedVisibilityFlag" );
225
- if ( " 1" == hasScaleBasedVisibility )
226
- {
227
- toggleScaleBasedVisibility ( true );
228
- }
229
- else
230
- {
231
- toggleScaleBasedVisibility ( false );
232
- }
230
+ toggleScaleBasedVisibility ( element.attribute ( " hasScaleBasedVisibilityFlag" ).toInt () == 1 );
233
231
setMinimumScale ( element.attribute ( " minimumScale" ).toFloat () );
234
232
setMaximumScale ( element.attribute ( " maximumScale" ).toFloat () );
235
233
@@ -267,14 +265,7 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
267
265
QDomElement maplayer = document.createElement ( " maplayer" );
268
266
269
267
// use scale dependent visibility flag
270
- if ( hasScaleBasedVisibility () )
271
- {
272
- maplayer.setAttribute ( " hasScaleBasedVisibilityFlag" , 1 );
273
- }
274
- else
275
- {
276
- maplayer.setAttribute ( " hasScaleBasedVisibilityFlag" , 0 );
277
- }
268
+ maplayer.setAttribute ( " hasScaleBasedVisibilityFlag" , hasScaleBasedVisibility () ? 1 : 0 );
278
269
maplayer.setAttribute ( " minimumScale" , minimumScale () );
279
270
maplayer.setAttribute ( " maximumScale" , maximumScale () );
280
271
@@ -298,6 +289,12 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
298
289
uri.setConnection ( uri.host (), uri.port (), database, uri.username (), uri.password () );
299
290
src = uri.uri ();
300
291
}
292
+ else if ( vlayer && vlayer->providerType () == " ogr" )
293
+ {
294
+ QStringList theURIParts = src.split ( " |" );
295
+ theURIParts[0 ] = QgsProject::instance ()->readPath ( theURIParts[0 ] );
296
+ src = theURIParts.join ( " |" );
297
+ }
301
298
else
302
299
{
303
300
src = QgsProject::instance ()->writePath ( src );
@@ -584,6 +581,11 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
584
581
return myErrorMessage;
585
582
}
586
583
584
+ // use scale dependent visibility flag
585
+ toggleScaleBasedVisibility ( myRoot.attribute ( " hasScaleBasedVisibilityFlag" ).toInt () == 1 );
586
+ setMinimumScale ( myRoot.attribute ( " minimumScale" ).toFloat () );
587
+ setMaximumScale ( myRoot.attribute ( " maximumScale" ).toFloat () );
588
+
587
589
QString errorMsg;
588
590
theResultFlag = readSymbology ( myRoot, errorMsg );
589
591
if ( !theResultFlag )
@@ -613,6 +615,11 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
613
615
myRootNode.setAttribute ( " version" , QString ( " %1" ).arg ( QGis::QGIS_VERSION ) );
614
616
myDocument.appendChild ( myRootNode );
615
617
618
+ // use scale dependent visibility flag
619
+ myRootNode.setAttribute ( " hasScaleBasedVisibilityFlag" , hasScaleBasedVisibility () ? 1 : 0 );
620
+ myRootNode.setAttribute ( " minimumScale" , minimumScale () );
621
+ myRootNode.setAttribute ( " maximumScale" , maximumScale () );
622
+
616
623
QString errorMsg;
617
624
if ( !writeSymbology ( myRootNode, myDocument, errorMsg ) )
618
625
{
@@ -621,9 +628,22 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
621
628
622
629
// check if the uri is a file or ends with .qml,
623
630
// which indicates that it should become one
624
- // everything else goes to the database.
625
- QFileInfo myFileInfo ( theURI );
626
- if ( myFileInfo.exists () || theURI.endsWith ( " .qml" , Qt::CaseInsensitive ) )
631
+ // everything else goes to the database
632
+ QString filename;
633
+
634
+ QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
635
+ if ( vlayer && vlayer->providerType () == " ogr" )
636
+ {
637
+ QStringList theURIParts = theURI.split ( " |" );
638
+ filename = theURIParts[0 ];
639
+ }
640
+ else
641
+ {
642
+ filename = theURI;
643
+ }
644
+
645
+ QFileInfo myFileInfo ( filename );
646
+ if ( myFileInfo.exists () || filename.endsWith ( " .qml" , Qt::CaseInsensitive ) )
627
647
{
628
648
QFileInfo myDirInfo ( myFileInfo.path () ); // excludes file name
629
649
if ( !myDirInfo.isWritable () )
@@ -742,12 +762,12 @@ QUndoStack* QgsMapLayer::undoStack()
742
762
return &mUndoStack ;
743
763
}
744
764
745
- void QgsMapLayer::setCacheImage ( QImage * thepImage )
746
- {
765
+ void QgsMapLayer::setCacheImage ( QImage * thepImage )
766
+ {
747
767
QgsDebugMsg ( " cache Image set!" );
748
- if ( mpCacheImage )
749
- {
750
- delete mpCacheImage;
751
- }
752
- mpCacheImage = thepImage;
768
+ if ( mpCacheImage )
769
+ {
770
+ delete mpCacheImage;
771
+ }
772
+ mpCacheImage = thepImage;
753
773
}
0 commit comments