@@ -446,7 +446,7 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
446
446
sqlite3_stmt *myPreparedStatement;
447
447
const char *myTail;
448
448
int myResult;
449
-
449
+
450
450
myResult = sqlite3_open (QgsApplication::qgisUserDbFilePath ().toUtf8 ().data (), &myDatabase);
451
451
if (myResult)
452
452
{
@@ -464,8 +464,10 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
464
464
{
465
465
QString qml = QString::fromUtf8 ( (char *)sqlite3_column_text (myPreparedStatement, 0 ) );
466
466
theResultFlag = myDocument.setContent ( qml, &myErrorMessage, &line, &column );
467
- if (!theResultFlag)
468
- myErrorMessage = tr (" %1 at line %2 column %3" ).arg ( myErrorMessage ).arg ( line ).arg (column);
467
+ if (!theResultFlag)
468
+ {
469
+ myErrorMessage = tr (" %1 at line %2 column %3" ).arg ( myErrorMessage ).arg ( line ).arg (column);
470
+ }
469
471
}
470
472
}
471
473
else
@@ -479,21 +481,24 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
479
481
}
480
482
481
483
if (!theResultFlag)
484
+ {
482
485
return myErrorMessage;
483
-
486
+ }
484
487
// now get the layer node out and pass it over to the layer
485
488
// to deserialise...
486
489
QDomElement myRoot = myDocument.firstChildElement (" qgis" );
487
490
if (myRoot.isNull ())
488
491
{
489
492
myErrorMessage = " Error: qgis element could not be found in " + theURI;
493
+ theResultFlag = false ;
490
494
return myErrorMessage;
491
495
}
492
496
493
497
QDomElement myLayer = myRoot.firstChildElement (" maplayer" );
494
498
if (myLayer.isNull ())
495
499
{
496
500
myErrorMessage = " Error: maplayer element could not be found in " + theURI;
501
+ theResultFlag = false ;
497
502
return myErrorMessage;
498
503
}
499
504
@@ -505,6 +510,7 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
505
510
if (myDataSource.isNull ())
506
511
{
507
512
myErrorMessage = " Error: datasource element could not be found in " + theURI;
513
+ theResultFlag = false ;
508
514
return myErrorMessage;
509
515
}
510
516
QDomElement myNewDataSource = myDocument.createElement ( " datasource" );
@@ -562,23 +568,25 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
562
568
// save as utf-8 with 2 spaces for indents
563
569
myDocument.save ( myFileStream, 2 );
564
570
myFile.close ();
571
+ theResultFlag = true ;
565
572
return QObject::tr ( " Created default style file as " ) + myFileName;
566
573
}
567
574
else
568
575
{
576
+ theResultFlag = false ;
569
577
return QObject::tr ( " ERROR: Failed to created default style file as %1 Check file permissions and retry." ).arg (myFileName);
570
578
}
571
579
}
572
580
else
573
581
{
574
582
QString qml = myDocument.toString ();
575
-
583
+
576
584
// read from database
577
585
sqlite3 *myDatabase;
578
586
sqlite3_stmt *myPreparedStatement;
579
587
const char *myTail;
580
588
int myResult;
581
-
589
+
582
590
myResult = sqlite3_open (QgsApplication::qgisUserDbFilePath ().toUtf8 ().data (), &myDatabase);
583
591
if (myResult)
584
592
{
@@ -595,7 +603,8 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
595
603
if ( sqlite3_step (myPreparedStatement)!=SQLITE_DONE )
596
604
{
597
605
sqlite3_finalize (myPreparedStatement);
598
- sqlite3_close (myDatabase);
606
+ sqlite3_close (myDatabase);
607
+ theResultFlag = false ;
599
608
return tr (" The style table could not be created." );
600
609
}
601
610
}
@@ -611,7 +620,7 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
611
620
sqlite3_step (myPreparedStatement)==SQLITE_DONE )
612
621
{
613
622
theResultFlag = true ;
614
- myErrorMessage = tr (" The style %1 was saved to database" ).arg (theURI);
623
+ myErrorMessage = tr (" The style %1 was saved to database" ).arg (theURI);
615
624
}
616
625
}
617
626
@@ -628,13 +637,13 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
628
637
sqlite3_step (myPreparedStatement)==SQLITE_DONE )
629
638
{
630
639
theResultFlag = true ;
631
- myErrorMessage = tr (" The style %1 was updated in the database." ).arg (theURI);
640
+ myErrorMessage = tr (" The style %1 was updated in the database." ).arg (theURI);
641
+ }
642
+ else
643
+ {
644
+ theResultFlag = false ;
645
+ myErrorMessage = tr (" The style %1 could not be updated in the database." ).arg (theURI);
632
646
}
633
- else
634
- {
635
- theResultFlag = true ;
636
- myErrorMessage = tr (" The style %1 could not be updated in the database." ).arg (theURI);
637
- }
638
647
}
639
648
else
640
649
{
@@ -645,7 +654,7 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
645
654
646
655
sqlite3_finalize (myPreparedStatement);
647
656
}
648
-
657
+
649
658
sqlite3_close (myDatabase);
650
659
}
651
660
0 commit comments