@@ -83,10 +83,10 @@ QgsMapLayer::QgsMapLayer( QgsMapLayer::LayerType type,
8383QgsMapLayer::~QgsMapLayer ()
8484{
8585 delete mCRS ;
86- if ( mpCacheImage )
87- {
88- delete mpCacheImage;
89- }
86+ if ( mpCacheImage )
87+ {
88+ delete mpCacheImage;
89+ }
9090}
9191
9292QgsMapLayer::LayerType QgsMapLayer::type () const
@@ -171,6 +171,12 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
171171 uri.setDatabase ( QgsProject::instance ()->readPath ( uri.database () ) );
172172 mDataSource = uri.uri ();
173173 }
174+ else if ( provider == " ogr" )
175+ {
176+ QStringList theURIParts = mDataSource .split ( " |" );
177+ theURIParts[0 ] = QgsProject::instance ()->readPath ( theURIParts[0 ] );
178+ mDataSource = theURIParts.join ( " |" );
179+ }
174180 else
175181 {
176182 mDataSource = QgsProject::instance ()->readPath ( mDataSource );
@@ -221,15 +227,7 @@ bool QgsMapLayer::readXML( QDomNode & layer_node )
221227 }
222228
223229 // 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 );
233231 setMinimumScale ( element.attribute ( " minimumScale" ).toFloat () );
234232 setMaximumScale ( element.attribute ( " maximumScale" ).toFloat () );
235233
@@ -267,14 +265,7 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
267265 QDomElement maplayer = document.createElement ( " maplayer" );
268266
269267 // 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 );
278269 maplayer.setAttribute ( " minimumScale" , minimumScale () );
279270 maplayer.setAttribute ( " maximumScale" , maximumScale () );
280271
@@ -298,6 +289,12 @@ bool QgsMapLayer::writeXML( QDomNode & layer_node, QDomDocument & document )
298289 uri.setConnection ( uri.host (), uri.port (), database, uri.username (), uri.password () );
299290 src = uri.uri ();
300291 }
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+ }
301298 else
302299 {
303300 src = QgsProject::instance ()->writePath ( src );
@@ -584,6 +581,11 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
584581 return myErrorMessage;
585582 }
586583
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+
587589 QString errorMsg;
588590 theResultFlag = readSymbology ( myRoot, errorMsg );
589591 if ( !theResultFlag )
@@ -613,6 +615,11 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
613615 myRootNode.setAttribute ( " version" , QString ( " %1" ).arg ( QGis::QGIS_VERSION ) );
614616 myDocument.appendChild ( myRootNode );
615617
618+ // use scale dependent visibility flag
619+ myRootNode.setAttribute ( " hasScaleBasedVisibilityFlag" , hasScaleBasedVisibility () ? 1 : 0 );
620+ myRootNode.setAttribute ( " minimumScale" , minimumScale () );
621+ myRootNode.setAttribute ( " maximumScale" , maximumScale () );
622+
616623 QString errorMsg;
617624 if ( !writeSymbology ( myRootNode, myDocument, errorMsg ) )
618625 {
@@ -621,9 +628,22 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
621628
622629 // check if the uri is a file or ends with .qml,
623630 // 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 ) )
627647 {
628648 QFileInfo myDirInfo ( myFileInfo.path () ); // excludes file name
629649 if ( !myDirInfo.isWritable () )
@@ -742,12 +762,12 @@ QUndoStack* QgsMapLayer::undoStack()
742762 return &mUndoStack ;
743763}
744764
745- void QgsMapLayer::setCacheImage ( QImage * thepImage )
746- {
765+ void QgsMapLayer::setCacheImage ( QImage * thepImage )
766+ {
747767 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;
753773}
0 commit comments