Skip to content

Commit 37e3035

Browse files
author
Emilio Loi
committedApr 17, 2013
Now "Save as Default" button ask where to save the style
1 parent 8645094 commit 37e3035

File tree

10 files changed

+518
-146
lines changed

10 files changed

+518
-146
lines changed
 

‎src/app/qgsloadstylefromdbdialog.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ QgsLoadStyleFromDBDialog::QgsLoadStyleFromDBDialog( QWidget *parent )
2424
mRelatedTable->setEditTriggers( QTableWidget::NoEditTriggers );
2525
mRelatedTable->horizontalHeader()->setStretchLastSection( true );
2626
mRelatedTable->setSelectionBehavior( QTableWidget::SelectRows );
27+
mRelatedTable->verticalHeader()->setVisible( false );
2728

2829
mOthersTable->setEditTriggers( QTableWidget::NoEditTriggers );
2930
mOthersTable->horizontalHeader()->setStretchLastSection( true );
3031
mOthersTable->setSelectionBehavior( QTableWidget::SelectRows );
32+
mOthersTable->verticalHeader()->setVisible( false );
3133

3234
connect(mRelatedTable, SIGNAL( cellClicked( int,int ) ), this, SLOT( cellSelectedRelatedTable( int ) ) );
3335
connect(mOthersTable, SIGNAL( cellClicked( int,int ) ), this, SLOT( cellSelectedOthersTable( int ) ) );
@@ -74,8 +76,9 @@ void QgsLoadStyleFromDBDialog::initializeLists( QVector<QString> ids, QVector<QS
7476
}
7577
for( int i=sectionLimit; i<ids.count(); i++ )
7678
{
77-
mOthersTable->setItem(i, 0, new QTableWidgetItem( names.value( i, "" ) ) );
78-
mOthersTable->setItem(i, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
79+
int j = i-sectionLimit;
80+
mOthersTable->setItem(j, 0, new QTableWidgetItem( names.value( i, "" ) ) );
81+
mOthersTable->setItem(j, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
7982
}
8083
}
8184

‎src/app/qgssavestyletodbdialog.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <QSettings>
1414
#include <QDomDocument>
1515
#include <QMessageBox>
16+
#include <QDateTime>
1617

1718
QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent ) :
1819
QDialog( parent )
@@ -42,6 +43,15 @@ QString QgsSaveStyleToDbDialog::getUIFileContent()
4243
return mUIFileContent;
4344
}
4445

46+
void QgsSaveStyleToDbDialog::accept()
47+
{
48+
if( getName().isEmpty() ){
49+
QMessageBox::information( this, tr( "Save style in database" ), tr( "A name is mandatory" ) );
50+
return;
51+
}
52+
QDialog::accept();
53+
}
54+
4555
void QgsSaveStyleToDbDialog::on_mFilePickButton_clicked()
4656
{
4757
QSettings myQSettings; // where we keep last used filter in persistent state

‎src/app/qgssavestyletodbdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public slots:
2929
QString getDescription();
3030
bool isDefault();
3131
void on_mFilePickButton_clicked();
32+
void accept();
3233
};
3334

3435
#endif // QGSSAVESTYLETODBDIALOG_H

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
129129
mSaveAsMenu->addAction( tr( "QGIS Layer Style File" ) );
130130
mSaveAsMenu->addAction( tr( "SLD File" ) );
131131

132-
//Only if the provider support loading & saving style to db add new choices
132+
//Only if the provider support loading & saving styles to db add new choices
133133
if( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
134134
{
135135
//for loading
@@ -557,18 +557,40 @@ void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
557557

558558
void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
559559
{
560-
apply(); // make sure the qml to save is uptodate
560+
apply();
561+
QString errorMsg;
562+
if( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
563+
{
564+
QMessageBox askToUser;
565+
askToUser.setText( tr( "Save default style to: " ) );
566+
askToUser.setIcon( QMessageBox::Question );
567+
askToUser.addButton( tr( "Cancel" ), QMessageBox::RejectRole);
568+
askToUser.addButton( tr( "Local database" ), QMessageBox::NoRole );
569+
askToUser.addButton( tr( "Datasource database" ), QMessageBox::YesRole );
570+
571+
switch ( askToUser.exec() )
572+
{
573+
case (0):
574+
return;
575+
break;
576+
case (2):
577+
layer->saveStyleToDatabase("", "", true, "", errorMsg );
578+
if( errorMsg.isNull() )
579+
{
580+
return;
581+
}
582+
break;
583+
default:
584+
break;
585+
}
586+
}
561587

562-
// a flag passed by reference
563-
bool defaultSavedFlag = false;
564-
// after calling this the above flag will be set true for success
565-
// or false if the save operation failed
566-
QString myMessage = layer->saveDefaultStyle( defaultSavedFlag );
567-
if ( !defaultSavedFlag )
568-
{
569-
//only raise the message if something went wrong
570-
QMessageBox::information( this, tr( "Default Style" ), myMessage );
571-
}
588+
bool defaultSavedFlag = false;
589+
errorMsg = layer->saveDefaultStyle( defaultSavedFlag );
590+
if ( !defaultSavedFlag )
591+
{
592+
QMessageBox::warning( this, tr( "Default Style" ), errorMsg );
593+
}
572594
}
573595

574596

‎src/core/qgsmaplayer.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,7 @@ QString QgsMapLayer::styleURI( )
698698

699699
QString QgsMapLayer::loadDefaultStyle( bool & theResultFlag )
700700
{
701+
QString ciao = styleURI();
701702
return loadNamedStyle( styleURI(), theResultFlag );
702703
}
703704

@@ -881,7 +882,7 @@ void QgsMapLayer::exportNamedStyle(QDomDocument &doc, QString &errorMsg)
881882

882883
QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag )
883884
{
884-
return saveNamedStyle( styleURI(), theResultFlag );
885+
return saveNamedStyle( styleURI(), theResultFlag );
885886
}
886887

887888
QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag )

‎src/core/qgsvectorlayer.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,10 +1711,7 @@ bool QgsVectorLayer::writeXml( QDomNode & layer_node,
17111711
// renderer specific settings
17121712
QString errorMsg;
17131713
return writeSymbology( layer_node, document, errorMsg );
1714-
} // bool QgsVectorLayer::writeXml
1715-
1716-
1717-
1714+
}
17181715

17191716
bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage )
17201717
{
@@ -3774,6 +3771,7 @@ QString QgsVectorLayer::getStyleFromDatabase(QString styleId, QString &msgError)
37743771
return getStyleByIdMethod( mDataSource, styleId, msgError );
37753772
}
37763773

3774+
37773775
void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,
37783776
bool useAsDefault, QString uiFileContent, QString &msgError){
37793777

@@ -3819,7 +3817,6 @@ void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,
38193817
QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
38203818
{
38213819
QgsDataSourceURI dsUri( theURI );
3822-
38233820
if ( !dsUri.database().isEmpty() )
38243821
{
38253822
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
@@ -3831,7 +3828,7 @@ QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFla
38313828
{
38323829
QString qml, errorMsg;
38333830
qml = loadStyleExternalMethod( mDataSource, errorMsg );
3834-
if( qml.compare( tr( "" ) ) )
3831+
if( !qml.isEmpty() )
38353832
{
38363833
theResultFlag = this->applyNamedStyle( qml, errorMsg );
38373834
}

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,7 +3229,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
32293229
const QString& uiFileContent, bool useAsDefault, QString& errCause )
32303230
{
32313231
QgsDataSourceURI dsUri( uri );
3232-
QString f_table_catalog, f_table_schema, f_table_name, f_geometry_column;
3232+
QString f_table_catalog, f_table_schema, f_table_name, f_geometry_column, owner, isdef, name, desc;
32333233
QString styleTableName = QObject::tr( "layer_styles" );
32343234
QgsPostgresResult res;
32353235

@@ -3261,8 +3261,11 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
32613261
f_table_schema = dsUri.schema();
32623262
f_table_name = dsUri.table();
32633263
f_geometry_column = dsUri.geometryColumn();
3264-
QString owner = dsUri.username();
3265-
QString isdef = (useAsDefault) ? QObject::tr( "true" ) : QObject::tr( "false" );
3264+
owner = dsUri.username();
3265+
isdef = (useAsDefault) ? QObject::tr( "true" ) : QObject::tr( "false" );
3266+
name = ( styleName.isEmpty() ) ? dsUri.table() : styleName;
3267+
desc = ( styleDescription.isEmpty() ) ? QDateTime::currentDateTime().toString() : styleDescription;
3268+
32663269
QString uiFileColumn( "" );
32673270
QString uiFileValue( "" );
32683271
if( !uiFileContent.isEmpty() )
@@ -3282,11 +3285,11 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
32823285
.arg( QgsPostgresConn::quotedValue( f_table_schema ) )
32833286
.arg( QgsPostgresConn::quotedValue( f_table_name ) )
32843287
.arg( QgsPostgresConn::quotedValue( f_geometry_column ) )
3285-
.arg( QgsPostgresConn::quotedValue( styleName ) )
3288+
.arg( QgsPostgresConn::quotedValue( name ) )
32863289
.arg( QgsPostgresConn::quotedValue( qmlStyle ) )
32873290
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
32883291
.arg( isdef )
3289-
.arg( QgsPostgresConn::quotedValue( styleDescription ) )
3292+
.arg( QgsPostgresConn::quotedValue( desc ) )
32903293
.arg( QgsPostgresConn::quotedValue( owner ) )
32913294
.arg( uiFileColumn )
32923295
.arg( uiFileValue );
@@ -3386,9 +3389,9 @@ QGISEXTERN int listStyles( const QString& uri, QVector<QString> &ids, QVector<Q
33863389
int numberOfRelatedStyles = PQntuples( result );
33873390
for( int i=0; i<numberOfRelatedStyles; i++ )
33883391
{
3389-
ids.push_front( QObject::tr( PQgetvalue( result, i, 0 ) ) );
3390-
names.push_front( QObject::tr( PQgetvalue( result, i, 1 ) ) );
3391-
descriptions.push_front( QObject::tr( PQgetvalue( result, i, 2 ) ) );
3392+
ids.append( QObject::tr( PQgetvalue( result, i, 0 ) ) );
3393+
names.append( QObject::tr( PQgetvalue( result, i, 1 ) ) );
3394+
descriptions.append( QObject::tr( PQgetvalue( result, i, 2 ) ) );
33923395
}
33933396

33943397
QString selectOthersQuery = QObject::tr( "SELECT id, styleName, description FROM %1 WHERE NOT(f_table_catalog=%2 AND f_table_schema=%3 AND f_table_name=%4 AND f_geometry_column=%5) ORDER BY update_time DESC;")
@@ -3407,9 +3410,9 @@ QGISEXTERN int listStyles( const QString& uri, QVector<QString> &ids, QVector<Q
34073410
}
34083411
for( int i=0; i<PQntuples( result ); i++ )
34093412
{
3410-
ids.push_front( QObject::tr( PQgetvalue( result, i, 0 ) ) );
3411-
names.push_front( QObject::tr( PQgetvalue( result, i, 1 ) ) );
3412-
descriptions.push_front( QObject::tr( PQgetvalue( result, i, 2 ) ) );
3413+
ids.append( QObject::tr( PQgetvalue( result, i, 0 ) ) );
3414+
names.append( QObject::tr( PQgetvalue( result, i, 1 ) ) );
3415+
descriptions.append( QObject::tr( PQgetvalue( result, i, 2 ) ) );
34133416
}
34143417

34153418
return numberOfRelatedStyles;

‎tests/testdata/lines.qml

Lines changed: 100 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
2-
<qgis version="1.9.90-Alpha" minimumScale="1" maximumScale="1e+08" minLabelScale="1" maxLabelScale="1e+08" hasScaleBasedVisibilityFlag="0" scaleBasedLabelVisibilityFlag="0">
2+
<qgis version="1.9.0-Master" minimumScale="1" maximumScale="1e+08" minLabelScale="1" maxLabelScale="1e+08" hasScaleBasedVisibilityFlag="0" scaleBasedLabelVisibilityFlag="0">
33
<transparencyLevelInt>255</transparencyLevelInt>
44
<classificationattribute>Name</classificationattribute>
55
<uniquevalue>
@@ -11,9 +11,9 @@
1111
<pointsymbol>hard:circle</pointsymbol>
1212
<pointsize>11</pointsize>
1313
<pointsizeunits>pixels</pointsizeunits>
14-
<rotationclassificationfieldname></rotationclassificationfieldname>
15-
<scaleclassificationfieldname></scaleclassificationfieldname>
16-
<symbolfieldname></symbolfieldname>
14+
<rotationclassificationfieldname null="1"></rotationclassificationfieldname>
15+
<scaleclassificationfieldname null="1"></scaleclassificationfieldname>
16+
<symbolfieldname null="1"></symbolfieldname>
1717
<outlinecolor red="154" blue="116" green="139"/>
1818
<outlinestyle>DashDotDotLine</outlinestyle>
1919
<outlinewidth>5</outlinewidth>
@@ -28,9 +28,9 @@
2828
<pointsymbol>hard:circle</pointsymbol>
2929
<pointsize>11</pointsize>
3030
<pointsizeunits>pixels</pointsizeunits>
31-
<rotationclassificationfieldname></rotationclassificationfieldname>
32-
<scaleclassificationfieldname></scaleclassificationfieldname>
33-
<symbolfieldname></symbolfieldname>
31+
<rotationclassificationfieldname null="1"></rotationclassificationfieldname>
32+
<scaleclassificationfieldname null="1"></scaleclassificationfieldname>
33+
<symbolfieldname null="1"></symbolfieldname>
3434
<outlinecolor red="94" blue="55" green="89"/>
3535
<outlinestyle>SolidLine</outlinestyle>
3636
<outlinewidth>7</outlinewidth>
@@ -39,7 +39,96 @@
3939
<texturepath></texturepath>
4040
</symbol>
4141
</uniquevalue>
42-
<customproperties/>
42+
<customproperties>
43+
<property key="labeling" value="pal"/>
44+
<property key="labeling/addDirectionSymbol" value="false"/>
45+
<property key="labeling/angleOffset" value="0"/>
46+
<property key="labeling/bufferColorB" value="255"/>
47+
<property key="labeling/bufferColorG" value="255"/>
48+
<property key="labeling/bufferColorR" value="255"/>
49+
<property key="labeling/bufferJoinStyle" value="64"/>
50+
<property key="labeling/bufferNoFill" value="false"/>
51+
<property key="labeling/bufferSize" value="1"/>
52+
<property key="labeling/bufferSizeInMapUnits" value="false"/>
53+
<property key="labeling/bufferTransp" value="0"/>
54+
<property key="labeling/centroidWhole" value="false"/>
55+
<property key="labeling/dataDefined/AlwaysShow" value=""/>
56+
<property key="labeling/dataDefined/Bold" value=""/>
57+
<property key="labeling/dataDefined/BufferColor" value=""/>
58+
<property key="labeling/dataDefined/BufferSize" value=""/>
59+
<property key="labeling/dataDefined/BufferTransp" value=""/>
60+
<property key="labeling/dataDefined/Color" value=""/>
61+
<property key="labeling/dataDefined/Family" value=""/>
62+
<property key="labeling/dataDefined/FontTransp" value=""/>
63+
<property key="labeling/dataDefined/Hali" value=""/>
64+
<property key="labeling/dataDefined/Italic" value=""/>
65+
<property key="labeling/dataDefined/LabelDistance" value=""/>
66+
<property key="labeling/dataDefined/MaxScale" value=""/>
67+
<property key="labeling/dataDefined/MinScale" value=""/>
68+
<property key="labeling/dataDefined/PositionX" value=""/>
69+
<property key="labeling/dataDefined/PositionY" value=""/>
70+
<property key="labeling/dataDefined/Rotation" value=""/>
71+
<property key="labeling/dataDefined/Show" value=""/>
72+
<property key="labeling/dataDefined/Size" value=""/>
73+
<property key="labeling/dataDefined/Strikeout" value=""/>
74+
<property key="labeling/dataDefined/Underline" value=""/>
75+
<property key="labeling/dataDefined/Vali" value=""/>
76+
<property key="labeling/decimals" value="0"/>
77+
<property key="labeling/displayAll" value="false"/>
78+
<property key="labeling/dist" value="0"/>
79+
<property key="labeling/distInMapUnits" value="false"/>
80+
<property key="labeling/enabled" value="false"/>
81+
<property key="labeling/fieldName" value=""/>
82+
<property key="labeling/fontCapitals" value="0"/>
83+
<property key="labeling/fontFamily" value="Ubuntu"/>
84+
<property key="labeling/fontItalic" value="false"/>
85+
<property key="labeling/fontLetterSpacing" value="0"/>
86+
<property key="labeling/fontLimitPixelSize" value="false"/>
87+
<property key="labeling/fontMaxPixelSize" value="10000"/>
88+
<property key="labeling/fontMinPixelSize" value="3"/>
89+
<property key="labeling/fontSize" value="11"/>
90+
<property key="labeling/fontSizeInMapUnits" value="false"/>
91+
<property key="labeling/fontStrikeout" value="false"/>
92+
<property key="labeling/fontUnderline" value="false"/>
93+
<property key="labeling/fontWeight" value="50"/>
94+
<property key="labeling/fontWordSpacing" value="0"/>
95+
<property key="labeling/formatNumbers" value="false"/>
96+
<property key="labeling/isExpression" value="false"/>
97+
<property key="labeling/labelOffsetInMapUnits" value="true"/>
98+
<property key="labeling/labelPerPart" value="false"/>
99+
<property key="labeling/leftDirectionSymbol" value="&lt;"/>
100+
<property key="labeling/limitNumLabels" value="false"/>
101+
<property key="labeling/maxCurvedCharAngleIn" value="20"/>
102+
<property key="labeling/maxCurvedCharAngleOut" value="-20"/>
103+
<property key="labeling/maxNumLabels" value="2000"/>
104+
<property key="labeling/mergeLines" value="false"/>
105+
<property key="labeling/minFeatureSize" value="0"/>
106+
<property key="labeling/multilineAlign" value="0"/>
107+
<property key="labeling/multilineHeight" value="1"/>
108+
<property key="labeling/namedStyle" value="Regular"/>
109+
<property key="labeling/obstacle" value="true"/>
110+
<property key="labeling/placeDirectionSymbol" value="0"/>
111+
<property key="labeling/placement" value="2"/>
112+
<property key="labeling/placementFlags" value="10"/>
113+
<property key="labeling/plussign" value="true"/>
114+
<property key="labeling/preserveRotation" value="true"/>
115+
<property key="labeling/previewBkgrdColor" value="#ffffff"/>
116+
<property key="labeling/priority" value="5"/>
117+
<property key="labeling/reverseDirectionSymbol" value="false"/>
118+
<property key="labeling/rightDirectionSymbol" value=">"/>
119+
<property key="labeling/scaleMax" value="0"/>
120+
<property key="labeling/scaleMin" value="0"/>
121+
<property key="labeling/textColorB" value="0"/>
122+
<property key="labeling/textColorG" value="0"/>
123+
<property key="labeling/textColorR" value="0"/>
124+
<property key="labeling/textTransp" value="0"/>
125+
<property key="labeling/upsidedownLabels" value="0"/>
126+
<property key="labeling/wrapChar" value=""/>
127+
<property key="labeling/xOffset" value="0"/>
128+
<property key="labeling/xQuadOffset" value="0"/>
129+
<property key="labeling/yOffset" value="0"/>
130+
<property key="labeling/yQuadOffset" value="0"/>
131+
</customproperties>
43132
<displayfield>Name</displayfield>
44133
<label>0</label>
45134
<labelattributes>
@@ -69,5 +158,8 @@
69158
<editform></editform>
70159
<editforminit></editforminit>
71160
<annotationform></annotationform>
161+
<editorlayout>generatedlayout</editorlayout>
162+
<excludeAttributesWMS/>
163+
<excludeAttributesWFS/>
72164
<attributeactions/>
73165
</qgis>

0 commit comments

Comments
 (0)
Please sign in to comment.