Skip to content

Commit 8694c19

Browse files
author
Emilio Loi
committedApr 13, 2013
Now you can add ui files
1 parent 4e52a8a commit 8694c19

File tree

8 files changed

+135
-25
lines changed

8 files changed

+135
-25
lines changed
 

‎src/app/qgssavestyletodbdialog.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99

1010
#include "qgssavestyletodbdialog.h"
1111

12+
#include <QFileDialog>
13+
#include <QSettings>
14+
#include <QDomDocument>
15+
#include <QMessageBox>
16+
1217
QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent ) :
1318
QDialog( parent )
1419
{
@@ -18,6 +23,7 @@ QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent ) :
1823
setTabOrder( mNameEdit, mDescriptionEdit );
1924
setTabOrder( mDescriptionEdit, mUseAsDefault );
2025
setTabOrder( mUseAsDefault, buttonBox );
26+
2127
}
2228
QString QgsSaveStyleToDbDialog::getName()
2329
{
@@ -31,3 +37,44 @@ bool QgsSaveStyleToDbDialog::isDefault()
3137
{
3238
return mUseAsDefault->isChecked();
3339
}
40+
QString QgsSaveStyleToDbDialog::getUIFileContent()
41+
{
42+
return mUIFileContent;
43+
}
44+
45+
void QgsSaveStyleToDbDialog::on_mFilePickButton_clicked()
46+
{
47+
QSettings myQSettings; // where we keep last used filter in persistent state
48+
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();
49+
50+
QString myFileName = QFileDialog::getOpenFileName( this, tr( "Attach Qt Creator UI file" ), myLastUsedDir, tr( "Qt Creator UI file .ui" ) + " (*.ui)" );
51+
if ( myFileName.isNull() )
52+
{
53+
return;
54+
}
55+
56+
57+
QFileInfo myFI( myFileName );
58+
59+
QFile uiFile( myFI.filePath() );
60+
61+
QString myPath = myFI.path();
62+
myQSettings.setValue( "style/lastStyleDir", myPath );
63+
64+
if(uiFile.open( QIODevice::ReadOnly ) )
65+
{
66+
QString content( uiFile.readAll() );
67+
QDomDocument doc;
68+
69+
if( !doc.setContent(content) || doc.documentElement().tagName().compare( "ui" ) )
70+
{
71+
QMessageBox::warning(this, tr( "Wrong file" ),
72+
tr( "The selected file does not appear to be a valid Qt Creator UI file."));
73+
return;
74+
}
75+
mUIFileContent = content;
76+
mFileNameLabel->setText( myFI.fileName() );
77+
}
78+
79+
}
80+

‎src/app/qgssavestyletodbdialog.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,19 @@
1616

1717
class QgsSaveStyleToDbDialog : public QDialog, private Ui::QgsSaveToDBDialog
1818
{
19+
QString mUIFileContent;
1920
Q_OBJECT
2021
public:
2122
explicit QgsSaveStyleToDbDialog(QWidget *parent = 0);
2223

2324
signals:
25+
2426
public slots:
27+
QString getUIFileContent();
2528
QString getName();
2629
QString getDescription();
2730
bool isDefault();
31+
void on_mFilePickButton_clicked();
2832
};
2933

3034
#endif // QGSSAVESTYLETODBDIALOG_H

‎src/app/qgsvectorlayerproperties.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,12 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
645645
{
646646
QString styleName = askToUser.getName();
647647
QString styleDesc = askToUser.getDescription();
648+
QString uiFileContent = askToUser.getUIFileContent();
648649
bool isDefault = askToUser.isDefault();
649650

650651
apply();
651652

652-
layer->saveStyleToDatabase( styleName, styleDesc, isDefault, msgError );
653+
layer->saveStyleToDatabase( styleName, styleDesc, isDefault, uiFileContent, msgError );
653654
if( !msgError.isNull() )
654655
{
655656
QMessageBox::warning( this, infoWindowTitle, msgError );
@@ -733,14 +734,22 @@ void QgsVectorLayerProperties::loadStyleMenuTriggered( QAction *action )
733734

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

736-
//Load from filesystem
737-
if ( index == 0 )
737+
if ( index == 0 ) //Load from filesystem
738738
{
739-
this->on_pbnLoadStyle_clicked();
739+
this->on_pbnLoadStyle_clicked();
740+
}
741+
else if( index == 1 ) //Load from database
742+
{
743+
this->showListOfStylesFromDatabase();
740744
}
741745

742746
}
743747

748+
void QgsVectorLayerProperties::showListOfStylesFromDatabase()
749+
{
750+
//TODO el1073 ui&logic
751+
}
752+
744753
QList<QgsVectorOverlayPlugin*> QgsVectorLayerProperties::overlayPlugins() const
745754
{
746755
QList<QgsVectorOverlayPlugin*> pluginList;

‎src/app/qgsvectorlayerproperties.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope
136136

137137
/** called when is possible to choice if load the style from filesystem or from db */
138138
void loadStyleMenuTriggered( QAction * );
139+
/** when provider supports, it will list all the styles relative the layer */
140+
void showListOfStylesFromDatabase();
139141

140142
protected:
141143

‎src/core/qgsvectorlayer.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ typedef bool saveStyle_t(
8282
const QString& sldStyle,
8383
const QString& styleName,
8484
const QString& styleDescription,
85+
const QString& uiFileContent,
8586
bool useAsDefault,
8687
QString& errCause
8788
);
@@ -3717,7 +3718,8 @@ QDomElement QgsAttributeEditorField::toDomElement( QDomDocument& doc ) const
37173718
return elem;
37183719
}
37193720

3720-
void QgsVectorLayer::saveStyleToDatabase(QString name, QString description, bool useAsDefault, QString &msgError){
3721+
void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,
3722+
bool useAsDefault, QString uiFileContent, QString &msgError){
37213723

37223724
QString sldStyle, qmlStyle;
37233725
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
@@ -3751,7 +3753,8 @@ void QgsVectorLayer::saveStyleToDatabase(QString name, QString description, bool
37513753
}
37523754
sldStyle = sldDocument.toString();
37533755

3754-
saveStyleExternalMethod(mDataSource, qmlStyle, sldStyle, name, description, useAsDefault, msgError);
3756+
saveStyleExternalMethod(mDataSource, qmlStyle, sldStyle, name,
3757+
description, uiFileContent, useAsDefault, msgError);
37553758
}
37563759

37573760
QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )

‎src/core/qgsvectorlayer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
382382
virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );
383383

384384
virtual void saveStyleToDatabase( QString name, QString description,
385-
bool useAsDefault, QString &msgError );
385+
bool useAsDefault, QString uiFileContent,
386+
QString &msgError );
386387

387388
virtual QString loadNamedStyle( const QString theURI, bool &theResultFlag );
388389

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,7 @@ QGISEXTERN bool deleteLayer( const QString& uri, QString& errCause )
32263226

32273227
QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QString& sldStyle,
32283228
const QString& styleName, const QString& styleDescription,
3229-
bool useAsDefault, QString& errCause )
3229+
const QString& uiFileContent, bool useAsDefault, QString& errCause )
32303230
{
32313231
QgsDataSourceURI dsUri( uri );
32323232
QString f_table_catalog, f_table_schema, f_table_name, f_geometry_column;
@@ -3251,7 +3251,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
32513251
res = conn->PQexec( createTabeQuery );
32523252
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
32533253
{
3254-
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 " );
3254+
errCause = QObject::tr( "Unable to save layer style. It's not possible to create the destination table on the database. Maybe this is due to table permissions (user=%1). Please contact your database admin" ).arg( dsUri.username() );
32553255
conn->disconnect();
32563256
return false;
32573257
}
@@ -3263,13 +3263,20 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
32633263
f_geometry_column = dsUri.geometryColumn();
32643264
QString owner = dsUri.username();
32653265
QString isdef = (useAsDefault) ? QObject::tr( "true" ) : QObject::tr( "false" );
3266+
QString uiFileColumn( "" );
3267+
QString uiFileValue( "" );
3268+
if( !uiFileContent.isEmpty() )
3269+
{
3270+
uiFileColumn.append( QObject::tr( ", ui" ) );
3271+
uiFileValue.append( QObject::tr( ",XMLPARSE(DOCUMENT %1)" ).arg( QgsPostgresConn::quotedValue( uiFileContent ) ) );
3272+
}
32663273

32673274
QString sql = QObject::tr( "INSERT INTO %1 ( f_table_catalog, "
32683275
"f_table_schema, f_table_name, f_geometry_column, "
32693276
"styleName, styleQML, styleSLD, useAsDefault, "
3270-
"description, owner) "
3277+
"description, owner %12) "
32713278
"VALUES(%2,%3,%4,%5,%6,XMLPARSE(DOCUMENT %7),"
3272-
"XMLPARSE(DOCUMENT %8),%9,%10,%11);" )
3279+
"XMLPARSE(DOCUMENT %8),%9,%10,%11 %13);" )
32733280
.arg( styleTableName )
32743281
.arg( QgsPostgresConn::quotedValue( f_table_catalog ) )
32753282
.arg( QgsPostgresConn::quotedValue( f_table_schema ) )
@@ -3280,7 +3287,10 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
32803287
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
32813288
.arg( isdef )
32823289
.arg( QgsPostgresConn::quotedValue( styleDescription ) )
3283-
.arg( QgsPostgresConn::quotedValue( owner ) );
3290+
.arg( QgsPostgresConn::quotedValue( owner ) )
3291+
.arg( uiFileColumn )
3292+
.arg( uiFileValue );
3293+
32843294

32853295
if( useAsDefault )
32863296
{
@@ -3298,7 +3308,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
32983308
conn->disconnect();
32993309
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
33003310
{
3301-
errCause = QObject::tr( "Unable to save layer style. It's not possible to insert a new record in style table. " );
3311+
errCause = QObject::tr( "Unable to save layer style. It's not possible to insert a new record in style table. Maybe this is due to table permissions (user=%1). Please contact your database admin" );
33023312
return false;
33033313
}
33043314
return true;

‎src/ui/qgssavetodbdialog.ui

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
<bool>true</bool>
1818
</property>
1919
<layout class="QGridLayout" name="gridLayout">
20-
<item row="1" column="1">
21-
<widget class="QPlainTextEdit" name="mDescriptionEdit"/>
20+
<item row="5" column="1">
21+
<widget class="QCheckBox" name="mUseAsDefault">
22+
<property name="text">
23+
<string>Use as default style for this layer</string>
24+
</property>
25+
</widget>
2226
</item>
2327
<item row="1" column="0">
2428
<widget class="QLabel" name="descriptionLabel">
@@ -27,6 +31,19 @@
2731
</property>
2832
</widget>
2933
</item>
34+
<item row="1" column="1">
35+
<widget class="QPlainTextEdit" name="mDescriptionEdit"/>
36+
</item>
37+
<item row="4" column="0">
38+
<widget class="QLabel" name="mUILabel">
39+
<property name="text">
40+
<string>UI</string>
41+
</property>
42+
<property name="buddy">
43+
<cstring>mNameEdit</cstring>
44+
</property>
45+
</widget>
46+
</item>
3047
<item row="0" column="0">
3148
<widget class="QLabel" name="nameLabel">
3249
<property name="text">
@@ -37,7 +54,10 @@
3754
</property>
3855
</widget>
3956
</item>
40-
<item row="3" column="1">
57+
<item row="0" column="1">
58+
<widget class="QLineEdit" name="mNameEdit"/>
59+
</item>
60+
<item row="6" column="1">
4161
<widget class="QDialogButtonBox" name="buttonBox">
4262
<property name="standardButtons">
4363
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
@@ -47,15 +67,29 @@
4767
</property>
4868
</widget>
4969
</item>
50-
<item row="2" column="1">
51-
<widget class="QCheckBox" name="mUseAsDefault">
52-
<property name="text">
53-
<string>Use as default style for this layer</string>
54-
</property>
55-
</widget>
56-
</item>
57-
<item row="0" column="1">
58-
<widget class="QLineEdit" name="mNameEdit"/>
70+
<item row="4" column="1">
71+
<layout class="QHBoxLayout" name="horizontalLayout_2">
72+
<item>
73+
<widget class="QLabel" name="mFileNameLabel">
74+
<property name="text">
75+
<string/>
76+
</property>
77+
</widget>
78+
</item>
79+
<item>
80+
<widget class="QToolButton" name="mFilePickButton">
81+
<property name="sizePolicy">
82+
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
83+
<horstretch>0</horstretch>
84+
<verstretch>0</verstretch>
85+
</sizepolicy>
86+
</property>
87+
<property name="text">
88+
<string>Open...</string>
89+
</property>
90+
</widget>
91+
</item>
92+
</layout>
5993
</item>
6094
</layout>
6195
</widget>

0 commit comments

Comments
 (0)