Skip to content
Permalink
Browse files

Now also "Restore Default Style" works

  • Loading branch information
Emilio Loi
Emilio Loi committed Apr 17, 2013
1 parent 37e3035 commit 6e9de001894aedaee167aaeb915d6dc7c58ea653
@@ -540,8 +540,48 @@ void QgsVectorLayerProperties::on_pbnChangeSpatialRefSys_clicked()

void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
{
QString msg;
bool defaultLoadedFlag = false;
QString myMessage = layer->loadDefaultStyle( defaultLoadedFlag );

if( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
{
QMessageBox askToUser;
askToUser.setText( tr( "Load default style from: " ) );
askToUser.setIcon( QMessageBox::Question );
askToUser.addButton( tr( "Cancel" ), QMessageBox::RejectRole);
askToUser.addButton( tr( "Local database" ), QMessageBox::NoRole );
askToUser.addButton( tr( "Datasource database" ), QMessageBox::YesRole );

switch ( askToUser.exec() )
{
case (0):
return;
break;
case (2):
msg = layer->loadNamedStyle( layer->styleURI(), defaultLoadedFlag );
if( !defaultLoadedFlag )
{
//something went wrong - let them know why
QMessageBox::information( this, tr( "Default Style" ), msg );
}
if( msg.compare( tr( "Loaded from Provider" ) ) )
{
QMessageBox::information( this, tr( "Default Style" ),
tr( "No default style was found for this layer" ) );
}
else{
reset();
}

return;
break;
default:
break;
}
}

QString myMessage = layer->loadNamedStyle(layer->styleURI(), defaultLoadedFlag, true);
// QString myMessage = layer->loadDefaultStyle( defaultLoadedFlag );
//reset if the default style was loaded ok only
if ( defaultLoadedFlag )
{
@@ -553,6 +593,7 @@ void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
//something went wrong - let them know why
QMessageBox::information( this, tr( "Default Style" ), myMessage );
}

}

void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
@@ -698,7 +698,6 @@ QString QgsMapLayer::styleURI( )

QString QgsMapLayer::loadDefaultStyle( bool & theResultFlag )
{
QString ciao = styleURI();
return loadNamedStyle( styleURI(), theResultFlag );
}

@@ -3814,10 +3814,10 @@ void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,



QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag , bool loadFromLocalDB )
{
QgsDataSourceURI dsUri( theURI );
if ( !dsUri.database().isEmpty() )
if ( !loadFromLocalDB && !dsUri.database().isEmpty() )
{
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
@@ -3834,12 +3834,13 @@ QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFla
}
}
}

}
if( !theResultFlag )
{
return QgsMapLayer::loadNamedStyle( theURI, theResultFlag );
}
return tr( "" );
return QObject::tr( "Loaded from Provider" );
}

bool QgsVectorLayer::applyNamedStyle(QString namedStyle, QString errorMsg )
@@ -410,7 +410,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
virtual QString getStyleFromDatabase( QString styleId, QString &msgError );

virtual QString loadNamedStyle( const QString theURI, bool &theResultFlag );
virtual QString loadNamedStyle( const QString theURI, bool &theResultFlag, bool loadFromLocalDb=false );
virtual bool applyNamedStyle(QString namedStyle , QString errorMsg);

/** convert a saved attribute editor element into a AttributeEditor structure as it's used internally.
@@ -3372,7 +3372,8 @@ QGISEXTERN int listStyles( const QString& uri, QVector<QString> &ids, QVector<Q
f_table_name = dsUri.table();
f_geometry_column = dsUri.geometryColumn();

QString selectRelatedQuery = QObject::tr( "SELECT id, styleName, description FROM %1 WHERE f_table_catalog=%2 AND f_table_schema=%3 AND f_table_name=%4 AND f_geometry_column=%5 ORDER BY (CASE WHEN useAsDefault THEN 1 ELSE 2 END), update_time DESC;")
// ORDER BY (CASE WHEN useAsDefault THEN 1 ELSE 2 END), update_time DESC;")
QString selectRelatedQuery = QObject::tr( "SELECT id, styleName, description FROM %1 WHERE f_table_catalog=%2 AND f_table_schema=%3 AND f_table_name=%4 AND f_geometry_column=%5 AND useAsDefault=true;" )
.arg( styleTableName )
.arg( QgsPostgresConn::quotedValue( f_table_catalog ) )
.arg( QgsPostgresConn::quotedValue( f_table_schema ) )

0 comments on commit 6e9de00

Please sign in to comment.
You can’t perform that action at this time.