Skip to content
Permalink
Browse files

Now you can add ui files

  • Loading branch information
Emilio Loi
Emilio Loi committed Apr 13, 2013
1 parent 4e52a8a commit 8694c19f23df70e92c5eeca64ff5c4a0a9d631cc
@@ -9,6 +9,11 @@

#include "qgssavestyletodbdialog.h"

#include <QFileDialog>
#include <QSettings>
#include <QDomDocument>
#include <QMessageBox>

QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent ) :
QDialog( parent )
{
@@ -18,6 +23,7 @@ QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent ) :
setTabOrder( mNameEdit, mDescriptionEdit );
setTabOrder( mDescriptionEdit, mUseAsDefault );
setTabOrder( mUseAsDefault, buttonBox );

}
QString QgsSaveStyleToDbDialog::getName()
{
@@ -31,3 +37,44 @@ bool QgsSaveStyleToDbDialog::isDefault()
{
return mUseAsDefault->isChecked();
}
QString QgsSaveStyleToDbDialog::getUIFileContent()
{
return mUIFileContent;
}

void QgsSaveStyleToDbDialog::on_mFilePickButton_clicked()
{
QSettings myQSettings; // where we keep last used filter in persistent state
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();

QString myFileName = QFileDialog::getOpenFileName( this, tr( "Attach Qt Creator UI file" ), myLastUsedDir, tr( "Qt Creator UI file .ui" ) + " (*.ui)" );
if ( myFileName.isNull() )
{
return;
}


QFileInfo myFI( myFileName );

QFile uiFile( myFI.filePath() );

QString myPath = myFI.path();
myQSettings.setValue( "style/lastStyleDir", myPath );

if(uiFile.open( QIODevice::ReadOnly ) )
{
QString content( uiFile.readAll() );
QDomDocument doc;

if( !doc.setContent(content) || doc.documentElement().tagName().compare( "ui" ) )
{
QMessageBox::warning(this, tr( "Wrong file" ),
tr( "The selected file does not appear to be a valid Qt Creator UI file."));
return;
}
mUIFileContent = content;
mFileNameLabel->setText( myFI.fileName() );
}

}

@@ -16,15 +16,19 @@

class QgsSaveStyleToDbDialog : public QDialog, private Ui::QgsSaveToDBDialog
{
QString mUIFileContent;
Q_OBJECT
public:
explicit QgsSaveStyleToDbDialog(QWidget *parent = 0);

signals:

public slots:
QString getUIFileContent();
QString getName();
QString getDescription();
bool isDefault();
void on_mFilePickButton_clicked();
};

#endif // QGSSAVESTYLETODBDIALOG_H
@@ -645,11 +645,12 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
{
QString styleName = askToUser.getName();
QString styleDesc = askToUser.getDescription();
QString uiFileContent = askToUser.getUIFileContent();
bool isDefault = askToUser.isDefault();

apply();

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

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

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

}

void QgsVectorLayerProperties::showListOfStylesFromDatabase()
{
//TODO el1073 ui&logic
}

QList<QgsVectorOverlayPlugin*> QgsVectorLayerProperties::overlayPlugins() const
{
QList<QgsVectorOverlayPlugin*> pluginList;
@@ -136,6 +136,8 @@ class QgsVectorLayerProperties : public QDialog, private Ui::QgsVectorLayerPrope

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

protected:

@@ -82,6 +82,7 @@ typedef bool saveStyle_t(
const QString& sldStyle,
const QString& styleName,
const QString& styleDescription,
const QString& uiFileContent,
bool useAsDefault,
QString& errCause
);
@@ -3717,7 +3718,8 @@ QDomElement QgsAttributeEditorField::toDomElement( QDomDocument& doc ) const
return elem;
}

void QgsVectorLayer::saveStyleToDatabase(QString name, QString description, bool useAsDefault, QString &msgError){
void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,
bool useAsDefault, QString uiFileContent, QString &msgError){

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

saveStyleExternalMethod(mDataSource, qmlStyle, sldStyle, name, description, useAsDefault, msgError);
saveStyleExternalMethod(mDataSource, qmlStyle, sldStyle, name,
description, uiFileContent, useAsDefault, msgError);
}

QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
@@ -382,7 +382,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
virtual bool writeXml( QDomNode & layer_node, QDomDocument & doc );

virtual void saveStyleToDatabase( QString name, QString description,
bool useAsDefault, QString &msgError );
bool useAsDefault, QString uiFileContent,
QString &msgError );

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

@@ -3226,7 +3226,7 @@ QGISEXTERN bool deleteLayer( const QString& uri, QString& errCause )

QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QString& sldStyle,
const QString& styleName, const QString& styleDescription,
bool useAsDefault, QString& errCause )
const QString& uiFileContent, bool useAsDefault, QString& errCause )
{
QgsDataSourceURI dsUri( uri );
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
res = conn->PQexec( createTabeQuery );
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{
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 " );
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() );
conn->disconnect();
return false;
}
@@ -3263,13 +3263,20 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
f_geometry_column = dsUri.geometryColumn();
QString owner = dsUri.username();
QString isdef = (useAsDefault) ? QObject::tr( "true" ) : QObject::tr( "false" );
QString uiFileColumn( "" );
QString uiFileValue( "" );
if( !uiFileContent.isEmpty() )
{
uiFileColumn.append( QObject::tr( ", ui" ) );
uiFileValue.append( QObject::tr( ",XMLPARSE(DOCUMENT %1)" ).arg( QgsPostgresConn::quotedValue( uiFileContent ) ) );
}

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) "
"description, owner %12) "
"VALUES(%2,%3,%4,%5,%6,XMLPARSE(DOCUMENT %7),"
"XMLPARSE(DOCUMENT %8),%9,%10,%11);" )
"XMLPARSE(DOCUMENT %8),%9,%10,%11 %13);" )
.arg( styleTableName )
.arg( QgsPostgresConn::quotedValue( f_table_catalog ) )
.arg( QgsPostgresConn::quotedValue( f_table_schema ) )
@@ -3280,7 +3287,10 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
.arg( isdef )
.arg( QgsPostgresConn::quotedValue( styleDescription ) )
.arg( QgsPostgresConn::quotedValue( owner ) );
.arg( QgsPostgresConn::quotedValue( owner ) )
.arg( uiFileColumn )
.arg( uiFileValue );


if( useAsDefault )
{
@@ -3298,7 +3308,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
conn->disconnect();
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{
errCause = QObject::tr( "Unable to save layer style. It's not possible to insert a new record in style table. " );
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" );
return false;
}
return true;
@@ -17,8 +17,12 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QPlainTextEdit" name="mDescriptionEdit"/>
<item row="5" column="1">
<widget class="QCheckBox" name="mUseAsDefault">
<property name="text">
<string>Use as default style for this layer</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="descriptionLabel">
@@ -27,6 +31,19 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPlainTextEdit" name="mDescriptionEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mUILabel">
<property name="text">
<string>UI</string>
</property>
<property name="buddy">
<cstring>mNameEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
@@ -37,7 +54,10 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="0" column="1">
<widget class="QLineEdit" name="mNameEdit"/>
</item>
<item row="6" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
@@ -47,15 +67,29 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="mUseAsDefault">
<property name="text">
<string>Use as default style for this layer</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mNameEdit"/>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="mFileNameLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mFilePickButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Open...</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>

0 comments on commit 8694c19

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