Skip to content

Commit 3a2a9b9

Browse files
author
timlinux
committed
Fix for #980 - remove dialogs after loading and saving styles
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8741 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 441758c commit 3a2a9b9

File tree

3 files changed

+91
-47
lines changed

3 files changed

+91
-47
lines changed

src/app/qgsrasterlayerproperties.cpp

+34-16
Original file line numberDiff line numberDiff line change
@@ -2866,12 +2866,17 @@ void QgsRasterLayerProperties::on_pbnLoadDefaultStyle_clicked()
28662866
//reset if the default style was loaded ok only
28672867
if ( defaultLoadedFlag )
28682868
{
2869+
//it worked so do it quietly
28692870
sync();
28702871
}
2871-
QMessageBox::information( this,
2872-
tr("Default Style"),
2873-
myMessage
2874-
);
2872+
else
2873+
{
2874+
//otherwise let the user know what went wrong
2875+
QMessageBox::information( this,
2876+
tr("Default Style"),
2877+
myMessage
2878+
);
2879+
}
28752880
}
28762881

28772882
void QgsRasterLayerProperties::on_pbnSaveDefaultStyle_clicked()
@@ -2881,10 +2886,14 @@ void QgsRasterLayerProperties::on_pbnSaveDefaultStyle_clicked()
28812886
// after calling this the above flag will be set true for success
28822887
// or false if the save operation failed
28832888
QString myMessage = mRasterLayer->saveDefaultStyle( defaultSavedFlag );
2884-
QMessageBox::information( this,
2885-
tr("Default Style"),
2886-
myMessage
2887-
);
2889+
if ( !defaultSavedFlag )
2890+
{
2891+
//let the user know what went wrong
2892+
QMessageBox::information( this,
2893+
tr("Default Style"),
2894+
myMessage
2895+
);
2896+
}
28882897
}
28892898

28902899

@@ -2933,10 +2942,14 @@ void QgsRasterLayerProperties::on_pbnLoadStyle_clicked()
29332942
{
29342943
sync();
29352944
}
2936-
QMessageBox::information( this,
2937-
tr("Default Style"),
2938-
myMessage
2939-
);
2945+
else
2946+
{
2947+
//let the user know something went wrong...
2948+
QMessageBox::information( this,
2949+
tr("Saved Style"),
2950+
myMessage
2951+
);
2952+
}
29402953
}
29412954
else
29422955
{
@@ -2993,12 +3006,17 @@ void QgsRasterLayerProperties::on_pbnSaveStyleAs_clicked()
29933006
//reset if the default style was loaded ok only
29943007
if ( defaultLoadedFlag )
29953008
{
3009+
//dont show the message if all went well...
29963010
sync();
29973011
}
2998-
QMessageBox::information( this,
2999-
tr("Default Style"),
3000-
myMessage
3001-
);
3012+
else
3013+
{
3014+
//if something went wrong let the user know why
3015+
QMessageBox::information( this,
3016+
tr("Saved Style"),
3017+
myMessage
3018+
);
3019+
}
30023020
}
30033021
else
30043022
{

src/app/qgsvectorlayerproperties.cpp

+33-16
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,17 @@ void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
629629
//reset if the default style was loaded ok only
630630
if ( defaultLoadedFlag )
631631
{
632+
// all worked ok so no need to inform user
632633
reset ();
633634
}
634-
QMessageBox::information( this,
635-
tr("Default Style"),
636-
myMessage
637-
);
635+
else
636+
{
637+
//something went wrong - let them know why
638+
QMessageBox::information( this,
639+
tr("Default Style"),
640+
myMessage
641+
);
642+
}
638643
}
639644

640645
void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
@@ -646,10 +651,14 @@ void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
646651
// after calling this the above flag will be set true for success
647652
// or false if the save operation failed
648653
QString myMessage = layer->saveDefaultStyle( defaultSavedFlag );
649-
QMessageBox::information( this,
650-
tr("Default Style"),
651-
myMessage
652-
);
654+
if ( !defaultSavedFlag )
655+
{
656+
//only raise the message if something went wrong
657+
QMessageBox::information( this,
658+
tr("Default Style"),
659+
myMessage
660+
);
661+
}
653662
}
654663

655664

@@ -698,10 +707,14 @@ void QgsVectorLayerProperties::on_pbnLoadStyle_clicked()
698707
{
699708
reset ();
700709
}
701-
QMessageBox::information( this,
702-
tr("Default Style"),
703-
myMessage
704-
);
710+
else
711+
{
712+
//let the user know what went wrong
713+
QMessageBox::information( this,
714+
tr("Saved Style"),
715+
myMessage
716+
);
717+
}
705718
}
706719
else
707720
{
@@ -762,10 +775,14 @@ void QgsVectorLayerProperties::on_pbnSaveStyleAs_clicked()
762775
{
763776
reset ();
764777
}
765-
QMessageBox::information( this,
766-
tr("Default Style"),
767-
myMessage
768-
);
778+
else
779+
{
780+
//let the user know what went wrong
781+
QMessageBox::information( this,
782+
tr("Saved Style"),
783+
myMessage
784+
);
785+
}
769786
}
770787
else
771788
{

src/core/qgsmaplayer.cpp

+24-15
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
446446
sqlite3_stmt *myPreparedStatement;
447447
const char *myTail;
448448
int myResult;
449-
449+
450450
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase);
451451
if (myResult)
452452
{
@@ -464,8 +464,10 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
464464
{
465465
QString qml = QString::fromUtf8( (char *)sqlite3_column_text(myPreparedStatement, 0) );
466466
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+
}
469471
}
470472
}
471473
else
@@ -479,21 +481,24 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
479481
}
480482

481483
if(!theResultFlag)
484+
{
482485
return myErrorMessage;
483-
486+
}
484487
// now get the layer node out and pass it over to the layer
485488
// to deserialise...
486489
QDomElement myRoot = myDocument.firstChildElement("qgis");
487490
if (myRoot.isNull())
488491
{
489492
myErrorMessage = "Error: qgis element could not be found in " + theURI;
493+
theResultFlag = false;
490494
return myErrorMessage;
491495
}
492496

493497
QDomElement myLayer = myRoot.firstChildElement("maplayer");
494498
if (myLayer.isNull())
495499
{
496500
myErrorMessage = "Error: maplayer element could not be found in " + theURI;
501+
theResultFlag = false;
497502
return myErrorMessage;
498503
}
499504

@@ -505,6 +510,7 @@ QString QgsMapLayer::loadNamedStyle ( const QString theURI , bool & theResultFla
505510
if (myDataSource.isNull())
506511
{
507512
myErrorMessage = "Error: datasource element could not be found in " + theURI;
513+
theResultFlag = false;
508514
return myErrorMessage;
509515
}
510516
QDomElement myNewDataSource = myDocument.createElement( "datasource" );
@@ -562,23 +568,25 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
562568
// save as utf-8 with 2 spaces for indents
563569
myDocument.save( myFileStream, 2 );
564570
myFile.close();
571+
theResultFlag = true;
565572
return QObject::tr( "Created default style file as " ) + myFileName;
566573
}
567574
else
568575
{
576+
theResultFlag = false;
569577
return QObject::tr( "ERROR: Failed to created default style file as %1 Check file permissions and retry." ).arg(myFileName);
570578
}
571579
}
572580
else
573581
{
574582
QString qml = myDocument.toString();
575-
583+
576584
// read from database
577585
sqlite3 *myDatabase;
578586
sqlite3_stmt *myPreparedStatement;
579587
const char *myTail;
580588
int myResult;
581-
589+
582590
myResult = sqlite3_open(QgsApplication::qgisUserDbFilePath().toUtf8().data(), &myDatabase);
583591
if (myResult)
584592
{
@@ -595,7 +603,8 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
595603
if( sqlite3_step(myPreparedStatement)!=SQLITE_DONE )
596604
{
597605
sqlite3_finalize(myPreparedStatement);
598-
sqlite3_close(myDatabase);
606+
sqlite3_close(myDatabase);
607+
theResultFlag = false;
599608
return tr("The style table could not be created.");
600609
}
601610
}
@@ -611,7 +620,7 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
611620
sqlite3_step(myPreparedStatement)==SQLITE_DONE )
612621
{
613622
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);
615624
}
616625
}
617626

@@ -628,13 +637,13 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
628637
sqlite3_step(myPreparedStatement)==SQLITE_DONE )
629638
{
630639
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);
632646
}
633-
else
634-
{
635-
theResultFlag = true;
636-
myErrorMessage = tr("The style %1 could not be updated in the database.").arg(theURI);
637-
}
638647
}
639648
else
640649
{
@@ -645,7 +654,7 @@ QString QgsMapLayer::saveNamedStyle ( const QString theURI, bool & theResultFlag
645654

646655
sqlite3_finalize(myPreparedStatement);
647656
}
648-
657+
649658
sqlite3_close(myDatabase);
650659
}
651660

0 commit comments

Comments
 (0)