Skip to content

Commit

Permalink
Added QMenu on loadStyle button with 2 options (load from filesystem,…
Browse files Browse the repository at this point in the history
… load from db)
  • Loading branch information
Emilio Loi committed Apr 13, 2013
1 parent 7aa831d commit 4e52a8a
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 21 deletions.
32 changes: 30 additions & 2 deletions src/app/qgsvectorlayerproperties.cpp
Expand Up @@ -127,13 +127,25 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
mSaveAsMenu->addAction( tr( "QGIS Layer Style File" ) );
mSaveAsMenu->addAction( tr( "SLD File" ) );

//Only if the provider support saving style to db add new choice
//Only if the provider support loading & saving style to db add new choices
if( layer->dataProvider()->isSavingStyleToDBSupported() )
{
//for loading
mLoadStyleMenu = new QMenu();
mLoadStyleMenu->addAction( tr( "Load from file" ) );
mLoadStyleMenu->addAction( tr( "Load from database" ) );
pbnLoadStyle->setContextMenuPolicy( Qt::PreventContextMenu );
pbnLoadStyle->setMenu( mLoadStyleMenu );

QObject::connect( mLoadStyleMenu, SIGNAL( triggered( QAction * ) ),
this, SLOT( loadStyleMenuTriggered( QAction * ) ) ) ;

//for saving
mSaveAsMenu->addAction( tr( "Save on database (%1)" ).arg( layer->providerType() ) );
}

QObject::connect( mSaveAsMenu, SIGNAL( triggered( QAction * ) ), this, SLOT( saveStyleAsMenuTriggered( QAction * ) ) );
QObject::connect( mSaveAsMenu, SIGNAL( triggered( QAction * ) ),
this, SLOT( saveStyleAsMenuTriggered( QAction * ) ) );

mFieldsPropertiesDialog = new QgsFieldsProperties( layer, mFieldsFrame );
mFieldsFrame->setLayout( new QVBoxLayout( mFieldsFrame ) );
Expand Down Expand Up @@ -713,6 +725,22 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
}
}

void QgsVectorLayerProperties::loadStyleMenuTriggered( QAction *action )
{
QMenu *menu = qobject_cast<QMenu *>( sender() );
if ( !menu )
return;

int index = mLoadStyleMenu->actions().indexOf( action );

//Load from filesystem
if ( index == 0 )
{
this->on_pbnLoadStyle_clicked();
}

}

QList<QgsVectorOverlayPlugin*> QgsVectorLayerProperties::overlayPlugins() const
{
QList<QgsVectorOverlayPlugin*> pluginList;
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsvectorlayerproperties.h
Expand Up @@ -134,6 +134,9 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
/** save the style based on selected format from the menu */
void saveStyleAsMenuTriggered( QAction * );

/** called when is possible to choice if load the style from filesystem or from db */
void loadStyleMenuTriggered( QAction * );

protected:

void saveStyleAs( StyleType styleType );
Expand All @@ -145,6 +148,7 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
bool mMetadataFilled;

QMenu *mSaveAsMenu;
QMenu *mLoadStyleMenu;

/**Renderer dialog which is shown*/
QDialog* mRendererDialog;
Expand Down
20 changes: 11 additions & 9 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -3251,7 +3251,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
res = conn->PQexec( createTabeQuery );
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{
errCause = QObject::tr( "Unable to save layer style. Unable to create style table" );
errCause = QObject::tr( "Unable to save layer style. It's not possible to create the destination table on the database. Maybe you need to contact " );
conn->disconnect();
return false;
}
Expand All @@ -3262,23 +3262,25 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
f_table_name = dsUri.table();
f_geometry_column = dsUri.geometryColumn();
QString owner = dsUri.username();
QString isdef = (useAsDefault) ? QObject::tr( "true" ) : QObject::tr( "false" );

QString sql = QObject::tr( "INSERT INTO %10( f_table_catalog, "
QString sql = QObject::tr( "INSERT INTO %1 ( f_table_catalog, "
"f_table_schema, f_table_name, f_geometry_column, "
"styleName, styleQML, styleSLD, useAsDefault, "
"description, owner) "
"VALUES(%1,%2,%3,%4,%5,XMLPARSE(DOCUMENT %6),"
"XMLPARSE(DOCUMENT %7),true,%8,%9);" )
"VALUES(%2,%3,%4,%5,%6,XMLPARSE(DOCUMENT %7),"
"XMLPARSE(DOCUMENT %8),%9,%10,%11);" )
.arg( styleTableName )
.arg( QgsPostgresConn::quotedValue( f_table_catalog ) )
.arg( QgsPostgresConn::quotedValue( f_table_schema ) )
.arg( QgsPostgresConn::quotedValue( f_table_name ) )
.arg( QgsPostgresConn::quotedValue( f_geometry_column ) )
.arg( QgsPostgresConn::quotedValue( styleName ) )
.arg( QgsPostgresConn::quotedValue( qmlStyle ) )
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
.arg( isdef )
.arg( QgsPostgresConn::quotedValue( styleDescription ) )
.arg( QgsPostgresConn::quotedValue( owner ) )
.arg( styleTableName );
.arg( QgsPostgresConn::quotedValue( owner ) );

if( useAsDefault )
{
Expand All @@ -3288,15 +3290,15 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
.arg( QgsPostgresConn::quotedValue( f_table_schema ) )
.arg( QgsPostgresConn::quotedValue(f_table_name ) )
.arg( QgsPostgresConn::quotedValue(f_geometry_column ) );
sql = QObject::tr("BEGIN; %2 %1 COMMIT;")
.arg( sql ).arg( removeDefaultSql );
sql = QObject::tr("BEGIN; %1 %2 COMMIT;")
.arg( removeDefaultSql ).arg( sql );
}

res = conn->PQexec( sql );
conn->disconnect();
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{
errCause = QObject::tr( "Unable to save layer style" );
errCause = QObject::tr( "Unable to save layer style. It's not possible to insert a new record in style table. " );
return false;
}
return true;
Expand Down
59 changes: 49 additions & 10 deletions src/ui/qgsvectorlayerpropertiesbase.ui
Expand Up @@ -46,6 +46,9 @@
</item>
<item>
<widget class="QPushButton" name="pbnSaveStyleAs">
<property name="contextMenuPolicy">
<enum>Qt::PreventContextMenu</enum>
</property>
<property name="text">
<string>Save Style ...</string>
</property>
Expand Down Expand Up @@ -177,7 +180,16 @@
<string>Fields</string>
</attribute>
<layout class="QGridLayout" name="mFieldsGridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
Expand All @@ -201,7 +213,16 @@
<string>General</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_7">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
Expand All @@ -220,8 +241,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>680</width>
<height>393</height>
<width>910</width>
<height>732</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_3">
Expand Down Expand Up @@ -297,7 +318,16 @@
<bool>true</bool>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>11</number>
</property>
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
<item row="0" column="4">
Expand Down Expand Up @@ -459,7 +489,16 @@ p, li { white-space: pre-wrap; }
<string>Subset</string>
</property>
<layout class="QGridLayout">
<property name="margin">
<property name="leftMargin">
<number>11</number>
</property>
<property name="topMargin">
<number>11</number>
</property>
<property name="rightMargin">
<number>11</number>
</property>
<property name="bottomMargin">
<number>11</number>
</property>
<item row="0" column="0" colspan="2">
Expand Down Expand Up @@ -719,8 +758,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>94</width>
<height>211</height>
<width>892</width>
<height>714</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
Expand Down Expand Up @@ -831,8 +870,8 @@ p, li { white-space: pre-wrap; }
<rect>
<x>0</x>
<y>0</y>
<width>96</width>
<height>112</height>
<width>892</width>
<height>714</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_17">
Expand Down

0 comments on commit 4e52a8a

Please sign in to comment.