Skip to content

Commit

Permalink
Now also "Restore Default Style" works
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilio Loi committed Apr 17, 2013
1 parent 37e3035 commit 6e9de00
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
43 changes: 42 additions & 1 deletion src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -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 )
{
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -698,7 +698,6 @@ QString QgsMapLayer::styleURI( )

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

Expand Down
7 changes: 4 additions & 3 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -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 ) )
Expand Down

0 comments on commit 6e9de00

Please sign in to comment.