mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
another indention update
This commit is contained in:
parent
9ca7223e4a
commit
d4542feedf
@ -170,7 +170,7 @@ class Editor(QsciScintilla):
|
||||
self.uncommentScut.setContext(Qt.WidgetShortcut)
|
||||
self.uncommentScut.activated.connect(self.parent.pc.uncommentCode)
|
||||
self.modificationChanged.connect(self.parent.modified)
|
||||
|
||||
|
||||
def settingsEditor(self):
|
||||
# Set Python lexer
|
||||
self.setLexers()
|
||||
@ -559,12 +559,12 @@ class Editor(QsciScintilla):
|
||||
QApplication.restoreOverrideCursor()
|
||||
self.setModified(True)
|
||||
self.endUndoAction()
|
||||
|
||||
|
||||
self.parent.tw.listObject(self.parent.tw.currentWidget())
|
||||
self.mtime = os.stat(pathfile).st_mtime
|
||||
msgText = QCoreApplication.translate('PythonConsole', 'The file <b>"%1"</b> has been changed and reloaded').arg(pathfile)
|
||||
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)
|
||||
|
||||
|
||||
QsciScintilla.focusInEvent(self, e)
|
||||
|
||||
class EditorTab(QWidget):
|
||||
@ -582,7 +582,7 @@ class EditorTab(QWidget):
|
||||
self.path = filename
|
||||
if os.path.exists(filename):
|
||||
self.loadFile(filename, False)
|
||||
|
||||
|
||||
# Creates layout for message bar
|
||||
self.layout = QGridLayout(self.newEditor)
|
||||
self.layout.setContentsMargins(0, 0, 0, 0)
|
||||
@ -600,7 +600,7 @@ class EditorTab(QWidget):
|
||||
|
||||
self.keyFilter = KeyFilter(parent, self)
|
||||
self.setEventFilter(self.keyFilter)
|
||||
|
||||
|
||||
def loadFile(self, filename, modified):
|
||||
try:
|
||||
fn = open(unicode(filename), "rb")
|
||||
|
@ -31,14 +31,14 @@ QgsLoadStyleFromDBDialog::QgsLoadStyleFromDBDialog( QWidget *parent )
|
||||
mOthersTable->setSelectionBehavior( QTableWidget::SelectRows );
|
||||
mOthersTable->verticalHeader()->setVisible( false );
|
||||
|
||||
connect(mRelatedTable, SIGNAL( cellClicked( int,int ) ), this, SLOT( cellSelectedRelatedTable( int ) ) );
|
||||
connect(mOthersTable, SIGNAL( cellClicked( int,int ) ), this, SLOT( cellSelectedOthersTable( int ) ) );
|
||||
connect(mRelatedTable, SIGNAL( doubleClicked( QModelIndex ) ),
|
||||
this, SLOT( accept() ) );
|
||||
connect(mOthersTable, SIGNAL( doubleClicked( QModelIndex ) ),
|
||||
this, SLOT( accept() ) );
|
||||
connect(mCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
|
||||
connect(mLoadButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
|
||||
connect( mRelatedTable, SIGNAL( cellClicked( int, int ) ), this, SLOT( cellSelectedRelatedTable( int ) ) );
|
||||
connect( mOthersTable, SIGNAL( cellClicked( int, int ) ), this, SLOT( cellSelectedOthersTable( int ) ) );
|
||||
connect( mRelatedTable, SIGNAL( doubleClicked( QModelIndex ) ),
|
||||
this, SLOT( accept() ) );
|
||||
connect( mOthersTable, SIGNAL( doubleClicked( QModelIndex ) ),
|
||||
this, SLOT( accept() ) );
|
||||
connect( mCancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
|
||||
connect( mLoadButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
|
||||
|
||||
setTabOrder( mRelatedTable, mOthersTable );
|
||||
setTabOrder( mOthersTable, mCancelButton );
|
||||
@ -47,54 +47,54 @@ QgsLoadStyleFromDBDialog::QgsLoadStyleFromDBDialog( QWidget *parent )
|
||||
}
|
||||
|
||||
void QgsLoadStyleFromDBDialog::initializeLists( QVector<QString> ids, QVector<QString> names,
|
||||
QVector<QString> descriptions, int sectionLimit )
|
||||
QVector<QString> descriptions, int sectionLimit )
|
||||
{
|
||||
mIds = ids;
|
||||
mNames = names;
|
||||
mDescriptions = descriptions;
|
||||
mSectionLimit = sectionLimit;
|
||||
int relatedTableNOfCols = ( sectionLimit > 0 ) ? 2 : 1;
|
||||
int othersTableNOfCols = ( ids.count() - sectionLimit > 0 ) ? 2 : 1;
|
||||
QString twoColsHeader( "Name;Description" );
|
||||
QString oneColsHeader( "No styles found in the database" );
|
||||
QString relatedTableHeader = ( relatedTableNOfCols == 1 ) ? oneColsHeader : twoColsHeader;
|
||||
QString othersTableHeader = ( othersTableNOfCols == 1 ) ? oneColsHeader : twoColsHeader;
|
||||
mIds = ids;
|
||||
mNames = names;
|
||||
mDescriptions = descriptions;
|
||||
mSectionLimit = sectionLimit;
|
||||
int relatedTableNOfCols = ( sectionLimit > 0 ) ? 2 : 1;
|
||||
int othersTableNOfCols = ( ids.count() - sectionLimit > 0 ) ? 2 : 1;
|
||||
QString twoColsHeader( "Name;Description" );
|
||||
QString oneColsHeader( "No styles found in the database" );
|
||||
QString relatedTableHeader = ( relatedTableNOfCols == 1 ) ? oneColsHeader : twoColsHeader;
|
||||
QString othersTableHeader = ( othersTableNOfCols == 1 ) ? oneColsHeader : twoColsHeader;
|
||||
|
||||
mRelatedTable->setColumnCount( relatedTableNOfCols );
|
||||
mOthersTable->setColumnCount( othersTableNOfCols );
|
||||
mRelatedTable->setHorizontalHeaderLabels( relatedTableHeader.split( ";" ) );
|
||||
mOthersTable->setHorizontalHeaderLabels( othersTableHeader.split( ";" ) );
|
||||
mRelatedTable->setRowCount( sectionLimit );
|
||||
mOthersTable->setRowCount( ids.count() - sectionLimit );
|
||||
mRelatedTable->setDisabled( ( relatedTableNOfCols == 1 ) );
|
||||
mOthersTable->setDisabled( ( othersTableNOfCols == 1 ) );
|
||||
mRelatedTable->setColumnCount( relatedTableNOfCols );
|
||||
mOthersTable->setColumnCount( othersTableNOfCols );
|
||||
mRelatedTable->setHorizontalHeaderLabels( relatedTableHeader.split( ";" ) );
|
||||
mOthersTable->setHorizontalHeaderLabels( othersTableHeader.split( ";" ) );
|
||||
mRelatedTable->setRowCount( sectionLimit );
|
||||
mOthersTable->setRowCount( ids.count() - sectionLimit );
|
||||
mRelatedTable->setDisabled(( relatedTableNOfCols == 1 ) );
|
||||
mOthersTable->setDisabled(( othersTableNOfCols == 1 ) );
|
||||
|
||||
for( int i=0; i<sectionLimit; i++ )
|
||||
{
|
||||
mRelatedTable->setItem(i, 0, new QTableWidgetItem( names.value( i, "" ) ) );
|
||||
mRelatedTable->setItem(i, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
|
||||
}
|
||||
for( int i=sectionLimit; i<ids.count(); i++ )
|
||||
{
|
||||
int j = i-sectionLimit;
|
||||
mOthersTable->setItem(j, 0, new QTableWidgetItem( names.value( i, "" ) ) );
|
||||
mOthersTable->setItem(j, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
|
||||
}
|
||||
for ( int i = 0; i < sectionLimit; i++ )
|
||||
{
|
||||
mRelatedTable->setItem( i, 0, new QTableWidgetItem( names.value( i, "" ) ) );
|
||||
mRelatedTable->setItem( i, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
|
||||
}
|
||||
for ( int i = sectionLimit; i < ids.count(); i++ )
|
||||
{
|
||||
int j = i - sectionLimit;
|
||||
mOthersTable->setItem( j, 0, new QTableWidgetItem( names.value( i, "" ) ) );
|
||||
mOthersTable->setItem( j, 1, new QTableWidgetItem( descriptions.value( i, "" ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
QString QgsLoadStyleFromDBDialog::getSelectedStyleId()
|
||||
{
|
||||
return mSelectedStyleId;
|
||||
return mSelectedStyleId;
|
||||
}
|
||||
|
||||
void QgsLoadStyleFromDBDialog::cellSelectedRelatedTable( int r )
|
||||
{
|
||||
mLoadButton->setEnabled( true );
|
||||
mSelectedStyleId = mIds.value( r );
|
||||
mLoadButton->setEnabled( true );
|
||||
mSelectedStyleId = mIds.value( r );
|
||||
}
|
||||
|
||||
void QgsLoadStyleFromDBDialog::cellSelectedOthersTable( int r )
|
||||
{
|
||||
mLoadButton->setEnabled( true );
|
||||
mSelectedStyleId = mIds.value( r + mSectionLimit );
|
||||
mLoadButton->setEnabled( true );
|
||||
mSelectedStyleId = mIds.value( r + mSectionLimit );
|
||||
}
|
||||
|
@ -26,14 +26,14 @@ class QgsLoadStyleFromDBDialog: public QDialog, private Ui::QgsLoadStyleFromDBDi
|
||||
public:
|
||||
explicit QgsLoadStyleFromDBDialog( QWidget *parent = 0 );
|
||||
|
||||
void initializeLists( QVector<QString> ids, QVector<QString> names, QVector<QString> descriptions, int sectionLimit);
|
||||
void initializeLists( QVector<QString> ids, QVector<QString> names, QVector<QString> descriptions, int sectionLimit );
|
||||
QString getSelectedStyleId();
|
||||
|
||||
public slots:
|
||||
public slots:
|
||||
void cellSelectedRelatedTable( int r );
|
||||
void cellSelectedOthersTable( int r );
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
@ -18,73 +18,74 @@
|
||||
QgsSaveStyleToDbDialog::QgsSaveStyleToDbDialog( QWidget *parent ) :
|
||||
QDialog( parent )
|
||||
{
|
||||
setupUi( this );
|
||||
setWindowTitle( "Save style in database" );
|
||||
mDescriptionEdit->setTabChangesFocus( true );
|
||||
setTabOrder( mNameEdit, mDescriptionEdit );
|
||||
setTabOrder( mDescriptionEdit, mUseAsDefault );
|
||||
setTabOrder( mUseAsDefault, buttonBox );
|
||||
setupUi( this );
|
||||
setWindowTitle( "Save style in database" );
|
||||
mDescriptionEdit->setTabChangesFocus( true );
|
||||
setTabOrder( mNameEdit, mDescriptionEdit );
|
||||
setTabOrder( mDescriptionEdit, mUseAsDefault );
|
||||
setTabOrder( mUseAsDefault, buttonBox );
|
||||
|
||||
}
|
||||
QString QgsSaveStyleToDbDialog::getName()
|
||||
{
|
||||
return mNameEdit->text();
|
||||
return mNameEdit->text();
|
||||
}
|
||||
QString QgsSaveStyleToDbDialog::getDescription()
|
||||
{
|
||||
return mDescriptionEdit->toPlainText();
|
||||
return mDescriptionEdit->toPlainText();
|
||||
}
|
||||
bool QgsSaveStyleToDbDialog::isDefault()
|
||||
{
|
||||
return mUseAsDefault->isChecked();
|
||||
return mUseAsDefault->isChecked();
|
||||
}
|
||||
QString QgsSaveStyleToDbDialog::getUIFileContent()
|
||||
{
|
||||
return mUIFileContent;
|
||||
return mUIFileContent;
|
||||
}
|
||||
|
||||
void QgsSaveStyleToDbDialog::accept()
|
||||
{
|
||||
if( getName().isEmpty() ){
|
||||
QMessageBox::information( this, tr( "Save style in database" ), tr( "A name is mandatory" ) );
|
||||
return;
|
||||
}
|
||||
QDialog::accept();
|
||||
if ( getName().isEmpty() )
|
||||
{
|
||||
QMessageBox::information( this, tr( "Save style in database" ), tr( "A name is mandatory" ) );
|
||||
return;
|
||||
}
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void QgsSaveStyleToDbDialog::on_mFilePickButton_clicked()
|
||||
{
|
||||
QSettings myQSettings; // where we keep last used filter in persistent state
|
||||
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();
|
||||
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() )
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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() );
|
||||
}
|
||||
mUIFileContent = content;
|
||||
mFileNameLabel->setText( myFI.fileName() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,12 @@ class QgsSaveStyleToDbDialog : public QDialog, private Ui::QgsSaveToDBDialog
|
||||
{
|
||||
QString mUIFileContent;
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QgsSaveStyleToDbDialog(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
public:
|
||||
explicit QgsSaveStyleToDbDialog( QWidget *parent = 0 );
|
||||
|
||||
public slots:
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
QString getUIFileContent();
|
||||
QString getName();
|
||||
QString getDescription();
|
||||
|
@ -143,20 +143,20 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
|
||||
mSaveAsMenu->addAction( tr( "SLD File" ) );
|
||||
|
||||
//Only if the provider support loading & saving styles to db add new choices
|
||||
if( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
|
||||
if ( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
|
||||
{
|
||||
//for loading
|
||||
mLoadStyleMenu = new QMenu();
|
||||
mLoadStyleMenu->addAction( tr( "Load from file" ) );
|
||||
mLoadStyleMenu->addAction( tr( "Load from database" ) );
|
||||
pbnLoadStyle->setContextMenuPolicy( Qt::PreventContextMenu );
|
||||
pbnLoadStyle->setMenu( mLoadStyleMenu );
|
||||
//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 * ) ) ) ;
|
||||
QObject::connect( mLoadStyleMenu, SIGNAL( triggered( QAction * ) ),
|
||||
this, SLOT( loadStyleMenuTriggered( QAction * ) ) ) ;
|
||||
|
||||
//for saving
|
||||
mSaveAsMenu->addAction( tr( "Save on database (%1)" ).arg( layer->providerType() ) );
|
||||
//for saving
|
||||
mSaveAsMenu->addAction( tr( "Save on database (%1)" ).arg( layer->providerType() ) );
|
||||
}
|
||||
|
||||
QObject::connect( mSaveAsMenu, SIGNAL( triggered( QAction * ) ),
|
||||
@ -555,44 +555,45 @@ void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
|
||||
QString msg;
|
||||
bool defaultLoadedFlag = false;
|
||||
|
||||
if( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
|
||||
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 );
|
||||
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();
|
||||
}
|
||||
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;
|
||||
}
|
||||
return;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString myMessage = layer->loadNamedStyle(layer->styleURI(), defaultLoadedFlag, true);
|
||||
QString myMessage = layer->loadNamedStyle( layer->styleURI(), defaultLoadedFlag, true );
|
||||
// QString myMessage = layer->loadDefaultStyle( defaultLoadedFlag );
|
||||
//reset if the default style was loaded ok only
|
||||
if ( defaultLoadedFlag )
|
||||
@ -609,40 +610,40 @@ void QgsVectorLayerProperties::on_pbnLoadDefaultStyle_clicked()
|
||||
|
||||
void QgsVectorLayerProperties::on_pbnSaveDefaultStyle_clicked()
|
||||
{
|
||||
apply();
|
||||
QString errorMsg;
|
||||
if( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
|
||||
{
|
||||
QMessageBox askToUser;
|
||||
askToUser.setText( tr( "Save default style to: " ) );
|
||||
askToUser.setIcon( QMessageBox::Question );
|
||||
askToUser.addButton( tr( "Cancel" ), QMessageBox::RejectRole);
|
||||
askToUser.addButton( tr( "Local database" ), QMessageBox::NoRole );
|
||||
askToUser.addButton( tr( "Datasource database" ), QMessageBox::YesRole );
|
||||
apply();
|
||||
QString errorMsg;
|
||||
if ( layer->dataProvider()->isSaveAndLoadStyleToDBSupported() )
|
||||
{
|
||||
QMessageBox askToUser;
|
||||
askToUser.setText( tr( "Save default style to: " ) );
|
||||
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() )
|
||||
switch ( askToUser.exec() )
|
||||
{
|
||||
case( 0 ):
|
||||
return;
|
||||
break;
|
||||
case( 2 ):
|
||||
layer->saveStyleToDatabase( "", "", true, "", errorMsg );
|
||||
if ( errorMsg.isNull() )
|
||||
{
|
||||
case (0):
|
||||
return;
|
||||
break;
|
||||
case (2):
|
||||
layer->saveStyleToDatabase("", "", true, "", errorMsg );
|
||||
if( errorMsg.isNull() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool defaultSavedFlag = false;
|
||||
errorMsg = layer->saveDefaultStyle( defaultSavedFlag );
|
||||
if ( !defaultSavedFlag )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Default Style" ), errorMsg );
|
||||
}
|
||||
bool defaultSavedFlag = false;
|
||||
errorMsg = layer->saveDefaultStyle( defaultSavedFlag );
|
||||
if ( !defaultSavedFlag )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Default Style" ), errorMsg );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -711,95 +712,95 @@ void QgsVectorLayerProperties::saveStyleAs( StyleType styleType )
|
||||
QString myLastUsedDir = myQSettings.value( "style/lastStyleDir", "." ).toString();
|
||||
|
||||
QString format, extension;
|
||||
if( styleType == DB )
|
||||
if ( styleType == DB )
|
||||
{
|
||||
QString infoWindowTitle = QObject::tr( "Save style to DB (%1)" ).arg( layer->providerType() );
|
||||
QString msgError;
|
||||
QString infoWindowTitle = QObject::tr( "Save style to DB (%1)" ).arg( layer->providerType() );
|
||||
QString msgError;
|
||||
|
||||
QgsSaveStyleToDbDialog askToUser;
|
||||
//Ask the user for a name and a description about the style
|
||||
if( askToUser.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString styleName = askToUser.getName();
|
||||
QString styleDesc = askToUser.getDescription();
|
||||
QString uiFileContent = askToUser.getUIFileContent();
|
||||
bool isDefault = askToUser.isDefault();
|
||||
QgsSaveStyleToDbDialog askToUser;
|
||||
//Ask the user for a name and a description about the style
|
||||
if ( askToUser.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString styleName = askToUser.getName();
|
||||
QString styleDesc = askToUser.getDescription();
|
||||
QString uiFileContent = askToUser.getUIFileContent();
|
||||
bool isDefault = askToUser.isDefault();
|
||||
|
||||
apply();
|
||||
apply();
|
||||
|
||||
layer->saveStyleToDatabase( styleName, styleDesc, isDefault, uiFileContent, msgError );
|
||||
if( !msgError.isNull() )
|
||||
{
|
||||
QMessageBox::warning( this, infoWindowTitle, msgError );
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::information( this, infoWindowTitle, tr( "Style saved" ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
layer->saveStyleToDatabase( styleName, styleDesc, isDefault, uiFileContent, msgError );
|
||||
if ( !msgError.isNull() )
|
||||
{
|
||||
QMessageBox::warning( this, infoWindowTitle, msgError );
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::information( this, infoWindowTitle, tr( "Style saved" ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
QString format, extension;
|
||||
if ( styleType == SLD )
|
||||
{
|
||||
format = tr( "SLD File" ) + " (*.sld)";
|
||||
extension = ".sld";
|
||||
}
|
||||
else
|
||||
{
|
||||
format = tr( "QGIS Layer Style File" ) + " (*.qml)";
|
||||
extension = ".qml";
|
||||
}
|
||||
QString format, extension;
|
||||
if ( styleType == SLD )
|
||||
{
|
||||
format = tr( "SLD File" ) + " (*.sld)";
|
||||
extension = ".sld";
|
||||
}
|
||||
else
|
||||
{
|
||||
format = tr( "QGIS Layer Style File" ) + " (*.qml)";
|
||||
extension = ".qml";
|
||||
}
|
||||
|
||||
QString myOutputFileName = QFileDialog::getSaveFileName( this, tr( "Save layer properties as style file" ),
|
||||
myLastUsedDir, format );
|
||||
if ( myOutputFileName.isNull() ) //dialog canceled
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString myOutputFileName = QFileDialog::getSaveFileName( this, tr( "Save layer properties as style file" ),
|
||||
myLastUsedDir, format );
|
||||
if ( myOutputFileName.isNull() ) //dialog canceled
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
apply(); // make sure the style to save is uptodate
|
||||
apply(); // make sure the style to save is uptodate
|
||||
|
||||
QString myMessage;
|
||||
bool defaultLoadedFlag = false;
|
||||
QString myMessage;
|
||||
bool defaultLoadedFlag = false;
|
||||
|
||||
//ensure the user never omitted the extension from the file name
|
||||
if ( !myOutputFileName.endsWith( extension, Qt::CaseInsensitive ) )
|
||||
{
|
||||
myOutputFileName += extension;
|
||||
}
|
||||
//ensure the user never omitted the extension from the file name
|
||||
if ( !myOutputFileName.endsWith( extension, Qt::CaseInsensitive ) )
|
||||
{
|
||||
myOutputFileName += extension;
|
||||
}
|
||||
|
||||
if ( styleType == SLD )
|
||||
{
|
||||
// convert to SLD
|
||||
myMessage = layer->saveSldStyle( myOutputFileName, defaultLoadedFlag );
|
||||
}
|
||||
else
|
||||
{
|
||||
myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag );
|
||||
}
|
||||
if ( styleType == SLD )
|
||||
{
|
||||
// convert to SLD
|
||||
myMessage = layer->saveSldStyle( myOutputFileName, defaultLoadedFlag );
|
||||
}
|
||||
else
|
||||
{
|
||||
myMessage = layer->saveNamedStyle( myOutputFileName, defaultLoadedFlag );
|
||||
}
|
||||
|
||||
//reset if the default style was loaded ok only
|
||||
if ( defaultLoadedFlag )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
//let the user know what went wrong
|
||||
QMessageBox::information( this, tr( "Saved Style" ), myMessage );
|
||||
}
|
||||
//reset if the default style was loaded ok only
|
||||
if ( defaultLoadedFlag )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
//let the user know what went wrong
|
||||
QMessageBox::information( this, tr( "Saved Style" ), myMessage );
|
||||
}
|
||||
|
||||
QFileInfo myFI( myOutputFileName );
|
||||
QString myPath = myFI.path();
|
||||
// Persist last used dir
|
||||
myQSettings.setValue( "style/lastStyleDir", myPath );
|
||||
QFileInfo myFI( myOutputFileName );
|
||||
QString myPath = myFI.path();
|
||||
// Persist last used dir
|
||||
myQSettings.setValue( "style/lastStyleDir", myPath );
|
||||
}
|
||||
}
|
||||
|
||||
@ -813,53 +814,53 @@ void QgsVectorLayerProperties::loadStyleMenuTriggered( QAction *action )
|
||||
|
||||
if ( index == 0 ) //Load from filesystem
|
||||
{
|
||||
this->on_pbnLoadStyle_clicked();
|
||||
this->on_pbnLoadStyle_clicked();
|
||||
}
|
||||
else if( index == 1 ) //Load from database
|
||||
else if ( index == 1 ) //Load from database
|
||||
{
|
||||
this->showListOfStylesFromDatabase();
|
||||
this->showListOfStylesFromDatabase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void QgsVectorLayerProperties::showListOfStylesFromDatabase()
|
||||
{
|
||||
QString errorMsg;
|
||||
QVector<QString> ids, names, descriptions;
|
||||
QString errorMsg;
|
||||
QVector<QString> ids, names, descriptions;
|
||||
|
||||
//get the list of styles in the db
|
||||
int sectionLimit = layer->listStylesInDatabase(ids, names, descriptions, errorMsg);
|
||||
if( !errorMsg.isNull() )
|
||||
//get the list of styles in the db
|
||||
int sectionLimit = layer->listStylesInDatabase( ids, names, descriptions, errorMsg );
|
||||
if ( !errorMsg.isNull() )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error occured retrievning styles from database " ), errorMsg );
|
||||
return;
|
||||
}
|
||||
|
||||
QgsLoadStyleFromDBDialog dialog;
|
||||
dialog.initializeLists( ids, names, descriptions, sectionLimit );
|
||||
|
||||
if ( dialog.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString selectedStyleId = dialog.getSelectedStyleId();
|
||||
|
||||
QString qmlStyle = layer->getStyleFromDatabase( selectedStyleId, errorMsg );
|
||||
if ( !errorMsg.isNull() )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error occured retrievning styles from database "), errorMsg );
|
||||
return;
|
||||
QMessageBox::warning( this, tr( "Error occured retrievning styles from database " ), errorMsg );
|
||||
return;
|
||||
}
|
||||
if ( layer->applyNamedStyle( qmlStyle, errorMsg ) )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error occured retrievning styles from database " ),
|
||||
tr( "The style retriev is not a valid named style. Error message: %1" )
|
||||
.arg( errorMsg ) );
|
||||
}
|
||||
|
||||
QgsLoadStyleFromDBDialog dialog;
|
||||
dialog.initializeLists(ids, names, descriptions, sectionLimit);
|
||||
|
||||
if( dialog.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString selectedStyleId = dialog.getSelectedStyleId();
|
||||
|
||||
QString qmlStyle = layer->getStyleFromDatabase( selectedStyleId, errorMsg );
|
||||
if( !errorMsg.isNull() )
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error occured retrievning styles from database "), errorMsg );
|
||||
return;
|
||||
}
|
||||
if( layer->applyNamedStyle( qmlStyle, errorMsg) )
|
||||
{
|
||||
reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning( this, tr( "Error occured retrievning styles from database "),
|
||||
tr( "The style retriev is not a valid named style. Error message: %1" )
|
||||
.arg( errorMsg ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -840,34 +840,34 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
|
||||
return "";
|
||||
}
|
||||
|
||||
void QgsMapLayer::exportNamedStyle(QDomDocument &doc, QString &errorMsg)
|
||||
void QgsMapLayer::exportNamedStyle( QDomDocument &doc, QString &errorMsg )
|
||||
{
|
||||
QDomImplementation DomImplementation;
|
||||
QDomDocumentType documentType = DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" );
|
||||
QDomDocument myDocument( documentType );
|
||||
QDomImplementation DomImplementation;
|
||||
QDomDocumentType documentType = DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd", "SYSTEM" );
|
||||
QDomDocument myDocument( documentType );
|
||||
|
||||
QDomElement myRootNode = myDocument.createElement( "qgis" );
|
||||
myRootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );
|
||||
myDocument.appendChild( myRootNode );
|
||||
QDomElement myRootNode = myDocument.createElement( "qgis" );
|
||||
myRootNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );
|
||||
myDocument.appendChild( myRootNode );
|
||||
|
||||
myRootNode.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 );
|
||||
myRootNode.setAttribute( "minimumScale", QString::number( minimumScale() ) );
|
||||
myRootNode.setAttribute( "maximumScale", QString::number( maximumScale() ) );
|
||||
myRootNode.setAttribute( "hasScaleBasedVisibilityFlag", hasScaleBasedVisibility() ? 1 : 0 );
|
||||
myRootNode.setAttribute( "minimumScale", QString::number( minimumScale() ) );
|
||||
myRootNode.setAttribute( "maximumScale", QString::number( maximumScale() ) );
|
||||
|
||||
#if 0
|
||||
// <transparencyLevelInt>
|
||||
QDomElement transparencyLevelIntElement = myDocument.createElement( "transparencyLevelInt" );
|
||||
QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) );
|
||||
transparencyLevelIntElement.appendChild( transparencyLevelIntText );
|
||||
myRootNode.appendChild( transparencyLevelIntElement );
|
||||
#endif
|
||||
#if 0
|
||||
// <transparencyLevelInt>
|
||||
QDomElement transparencyLevelIntElement = myDocument.createElement( "transparencyLevelInt" );
|
||||
QDomText transparencyLevelIntText = myDocument.createTextNode( QString::number( getTransparency() ) );
|
||||
transparencyLevelIntElement.appendChild( transparencyLevelIntText );
|
||||
myRootNode.appendChild( transparencyLevelIntElement );
|
||||
#endif
|
||||
|
||||
if ( !writeSymbology( myRootNode, myDocument, errorMsg ) )
|
||||
{
|
||||
errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
|
||||
return;
|
||||
}
|
||||
doc = myDocument;
|
||||
if ( !writeSymbology( myRootNode, myDocument, errorMsg ) )
|
||||
{
|
||||
errorMsg = QObject::tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
|
||||
return;
|
||||
}
|
||||
doc = myDocument;
|
||||
}
|
||||
|
||||
QString QgsMapLayer::saveDefaultStyle( bool & theResultFlag )
|
||||
@ -1012,41 +1012,42 @@ QString QgsMapLayer::saveNamedStyle( const QString theURI, bool & theResultFlag
|
||||
return myErrorMessage;
|
||||
}
|
||||
|
||||
void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg ){
|
||||
QDomDocument myDocument = QDomDocument();
|
||||
void QgsMapLayer::exportSldStyle( QDomDocument &doc, QString &errorMsg )
|
||||
{
|
||||
QDomDocument myDocument = QDomDocument();
|
||||
|
||||
QDomNode header = myDocument.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" );
|
||||
myDocument.appendChild( header );
|
||||
QDomNode header = myDocument.createProcessingInstruction( "xml", "version=\"1.0\" encoding=\"UTF-8\"" );
|
||||
myDocument.appendChild( header );
|
||||
|
||||
// Create the root element
|
||||
QDomElement root = myDocument.createElementNS( "http://www.opengis.net/sld", "StyledLayerDescriptor" );
|
||||
root.setAttribute( "version", "1.1.0" );
|
||||
root.setAttribute( "xsi:schemaLocation", "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" );
|
||||
root.setAttribute( "xmlns:ogc", "http://www.opengis.net/ogc" );
|
||||
root.setAttribute( "xmlns:se", "http://www.opengis.net/se" );
|
||||
root.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
|
||||
root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
|
||||
myDocument.appendChild( root );
|
||||
// Create the root element
|
||||
QDomElement root = myDocument.createElementNS( "http://www.opengis.net/sld", "StyledLayerDescriptor" );
|
||||
root.setAttribute( "version", "1.1.0" );
|
||||
root.setAttribute( "xsi:schemaLocation", "http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" );
|
||||
root.setAttribute( "xmlns:ogc", "http://www.opengis.net/ogc" );
|
||||
root.setAttribute( "xmlns:se", "http://www.opengis.net/se" );
|
||||
root.setAttribute( "xmlns:xlink", "http://www.w3.org/1999/xlink" );
|
||||
root.setAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
|
||||
myDocument.appendChild( root );
|
||||
|
||||
// Create the NamedLayer element
|
||||
QDomElement namedLayerNode = myDocument.createElement( "NamedLayer" );
|
||||
root.appendChild( namedLayerNode );
|
||||
// Create the NamedLayer element
|
||||
QDomElement namedLayerNode = myDocument.createElement( "NamedLayer" );
|
||||
root.appendChild( namedLayerNode );
|
||||
|
||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
|
||||
if ( !vlayer )
|
||||
{
|
||||
errorMsg = tr( "Could not save symbology because:\n%1" )
|
||||
.arg( "Non-vector layers not supported yet" );
|
||||
return;
|
||||
}
|
||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( this );
|
||||
if ( !vlayer )
|
||||
{
|
||||
errorMsg = tr( "Could not save symbology because:\n%1" )
|
||||
.arg( "Non-vector layers not supported yet" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !vlayer->writeSld( namedLayerNode, myDocument, errorMsg ) )
|
||||
{
|
||||
errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
|
||||
return;
|
||||
}
|
||||
if ( !vlayer->writeSld( namedLayerNode, myDocument, errorMsg ) )
|
||||
{
|
||||
errorMsg = tr( "Could not save symbology because:\n%1" ).arg( errorMsg );
|
||||
return;
|
||||
}
|
||||
|
||||
doc = myDocument;
|
||||
doc = myDocument;
|
||||
}
|
||||
|
||||
QString QgsMapLayer::saveSldStyle( const QString theURI, bool & theResultFlag )
|
||||
@ -1054,7 +1055,7 @@ QString QgsMapLayer::saveSldStyle( const QString theURI, bool & theResultFlag )
|
||||
QString errorMsg;
|
||||
QDomDocument myDocument;
|
||||
exportSldStyle( myDocument, errorMsg );
|
||||
if( !errorMsg.isNull() )
|
||||
if ( !errorMsg.isNull() )
|
||||
{
|
||||
theResultFlag = false;
|
||||
return errorMsg;
|
||||
|
@ -79,33 +79,33 @@
|
||||
#endif
|
||||
|
||||
typedef bool saveStyle_t(
|
||||
const QString& uri,
|
||||
const QString& qmlStyle,
|
||||
const QString& sldStyle,
|
||||
const QString& styleName,
|
||||
const QString& styleDescription,
|
||||
const QString& uiFileContent,
|
||||
bool useAsDefault,
|
||||
QString& errCause
|
||||
const QString& uri,
|
||||
const QString& qmlStyle,
|
||||
const QString& sldStyle,
|
||||
const QString& styleName,
|
||||
const QString& styleDescription,
|
||||
const QString& uiFileContent,
|
||||
bool useAsDefault,
|
||||
QString& errCause
|
||||
);
|
||||
|
||||
typedef QString loadStyle_t(
|
||||
const QString& uri,
|
||||
QString& errCause
|
||||
const QString& uri,
|
||||
QString& errCause
|
||||
);
|
||||
|
||||
typedef int listStyles_t(
|
||||
const QString& uri,
|
||||
QVector<QString> &ids,
|
||||
QVector<QString> &names,
|
||||
QVector<QString> &descriptions,
|
||||
QString& errCause
|
||||
const QString& uri,
|
||||
QVector<QString> &ids,
|
||||
QVector<QString> &names,
|
||||
QVector<QString> &descriptions,
|
||||
QString& errCause
|
||||
);
|
||||
|
||||
typedef QString getStyleById_t(
|
||||
const QString& uri,
|
||||
QString styleID,
|
||||
QString& errCause
|
||||
const QString& uri,
|
||||
QString styleID,
|
||||
QString& errCause
|
||||
);
|
||||
|
||||
|
||||
@ -3732,84 +3732,85 @@ QDomElement QgsAttributeEditorField::toDomElement( QDomDocument& doc ) const
|
||||
|
||||
int QgsVectorLayer::listStylesInDatabase( QVector<QString> &ids, QVector<QString> &names, QVector<QString> &descriptions, QString &msgError )
|
||||
{
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( !myLib )
|
||||
{
|
||||
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
|
||||
return -1;
|
||||
}
|
||||
listStyles_t* listStylesExternalMethod = ( listStyles_t * ) cast_to_fptr(myLib->resolve("listStyles"));
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( !myLib )
|
||||
{
|
||||
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
|
||||
return -1;
|
||||
}
|
||||
listStyles_t* listStylesExternalMethod = ( listStyles_t * ) cast_to_fptr( myLib->resolve( "listStyles" ) );
|
||||
|
||||
if ( !listStylesExternalMethod )
|
||||
{
|
||||
delete myLib;
|
||||
msgError = QObject::tr( "Provider %1 has no listStyles method" ).arg( mProviderKey );
|
||||
return -1;
|
||||
}
|
||||
if ( !listStylesExternalMethod )
|
||||
{
|
||||
delete myLib;
|
||||
msgError = QObject::tr( "Provider %1 has no listStyles method" ).arg( mProviderKey );
|
||||
return -1;
|
||||
}
|
||||
|
||||
return listStylesExternalMethod(mDataSource, ids, names, descriptions, msgError);
|
||||
return listStylesExternalMethod( mDataSource, ids, names, descriptions, msgError );
|
||||
}
|
||||
|
||||
QString QgsVectorLayer::getStyleFromDatabase(QString styleId, QString &msgError)
|
||||
QString QgsVectorLayer::getStyleFromDatabase( QString styleId, QString &msgError )
|
||||
{
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( !myLib )
|
||||
{
|
||||
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
getStyleById_t* getStyleByIdMethod = ( getStyleById_t * ) cast_to_fptr(myLib->resolve("getStyleById"));
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( !myLib )
|
||||
{
|
||||
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
getStyleById_t* getStyleByIdMethod = ( getStyleById_t * ) cast_to_fptr( myLib->resolve( "getStyleById" ) );
|
||||
|
||||
if ( !getStyleByIdMethod )
|
||||
{
|
||||
delete myLib;
|
||||
msgError = QObject::tr( "Provider %1 has no getStyleById method" ).arg( mProviderKey );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
if ( !getStyleByIdMethod )
|
||||
{
|
||||
delete myLib;
|
||||
msgError = QObject::tr( "Provider %1 has no getStyleById method" ).arg( mProviderKey );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
|
||||
return getStyleByIdMethod( mDataSource, styleId, msgError );
|
||||
return getStyleByIdMethod( mDataSource, styleId, msgError );
|
||||
}
|
||||
|
||||
|
||||
void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,
|
||||
bool useAsDefault, QString uiFileContent, QString &msgError){
|
||||
void QgsVectorLayer::saveStyleToDatabase( QString name, QString description,
|
||||
bool useAsDefault, QString uiFileContent, QString &msgError )
|
||||
{
|
||||
|
||||
QString sldStyle, qmlStyle;
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( !myLib )
|
||||
{
|
||||
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
|
||||
return;
|
||||
}
|
||||
saveStyle_t* saveStyleExternalMethod = ( saveStyle_t * ) cast_to_fptr(myLib->resolve("saveStyle"));
|
||||
QString sldStyle, qmlStyle;
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( !myLib )
|
||||
{
|
||||
msgError = QObject::tr( "Unable to load %1 provider" ).arg( mProviderKey );
|
||||
return;
|
||||
}
|
||||
saveStyle_t* saveStyleExternalMethod = ( saveStyle_t * ) cast_to_fptr( myLib->resolve( "saveStyle" ) );
|
||||
|
||||
if ( !saveStyleExternalMethod )
|
||||
{
|
||||
delete myLib;
|
||||
msgError = QObject::tr( "Provider %1 has no saveStyle method" ).arg( mProviderKey );
|
||||
return;
|
||||
}
|
||||
if ( !saveStyleExternalMethod )
|
||||
{
|
||||
delete myLib;
|
||||
msgError = QObject::tr( "Provider %1 has no saveStyle method" ).arg( mProviderKey );
|
||||
return;
|
||||
}
|
||||
|
||||
QDomDocument qmlDocument, sldDocument;
|
||||
this->exportNamedStyle(qmlDocument, msgError);
|
||||
if( !msgError.isNull() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
qmlStyle = qmlDocument.toString();
|
||||
QDomDocument qmlDocument, sldDocument;
|
||||
this->exportNamedStyle( qmlDocument, msgError );
|
||||
if ( !msgError.isNull() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
qmlStyle = qmlDocument.toString();
|
||||
|
||||
this->exportSldStyle(sldDocument, msgError);
|
||||
if( !msgError.isNull() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
sldStyle = sldDocument.toString();
|
||||
this->exportSldStyle( sldDocument, msgError );
|
||||
if ( !msgError.isNull() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
sldStyle = sldDocument.toString();
|
||||
|
||||
saveStyleExternalMethod(mDataSource, qmlStyle, sldStyle, name,
|
||||
description, uiFileContent, useAsDefault, msgError);
|
||||
saveStyleExternalMethod( mDataSource, qmlStyle, sldStyle, name,
|
||||
description, uiFileContent, useAsDefault, msgError );
|
||||
}
|
||||
|
||||
|
||||
@ -3817,60 +3818,60 @@ void QgsVectorLayer::saveStyleToDatabase(QString name, QString description,
|
||||
|
||||
QString QgsVectorLayer::loadNamedStyle( const QString theURI, bool &theResultFlag , bool loadFromLocalDB )
|
||||
{
|
||||
QgsDataSourceURI dsUri( theURI );
|
||||
if ( !loadFromLocalDB && !dsUri.database().isEmpty() )
|
||||
QgsDataSourceURI dsUri( theURI );
|
||||
if ( !loadFromLocalDB && !dsUri.database().isEmpty() )
|
||||
{
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( myLib )
|
||||
{
|
||||
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();
|
||||
QLibrary *myLib = pReg->providerLibrary( mProviderKey );
|
||||
if ( myLib )
|
||||
{
|
||||
loadStyle_t* loadStyleExternalMethod = ( loadStyle_t * ) cast_to_fptr( myLib->resolve( "loadStyle" ) );
|
||||
if ( loadStyleExternalMethod )
|
||||
{
|
||||
QString qml, errorMsg;
|
||||
qml = loadStyleExternalMethod( mDataSource, errorMsg );
|
||||
if( !qml.isEmpty() )
|
||||
{
|
||||
theResultFlag = this->applyNamedStyle( qml, errorMsg );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if( !theResultFlag )
|
||||
{
|
||||
return QgsMapLayer::loadNamedStyle( theURI, theResultFlag );
|
||||
}
|
||||
return QObject::tr( "Loaded from Provider" );
|
||||
}
|
||||
|
||||
bool QgsVectorLayer::applyNamedStyle(QString namedStyle, QString errorMsg )
|
||||
{
|
||||
QDomDocument myDocument( "qgis" );
|
||||
myDocument.setContent( namedStyle );
|
||||
|
||||
QDomElement myRoot = myDocument.firstChildElement( "qgis" );
|
||||
|
||||
if( myRoot.isNull() )
|
||||
{
|
||||
errorMsg = tr( "Error: qgis element could not be found" );
|
||||
return false;
|
||||
}
|
||||
toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
|
||||
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
|
||||
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );
|
||||
|
||||
#if 0
|
||||
//read transparency level
|
||||
QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" );
|
||||
if ( ! transparencyNode.isNull() )
|
||||
loadStyle_t* loadStyleExternalMethod = ( loadStyle_t * ) cast_to_fptr( myLib->resolve( "loadStyle" ) );
|
||||
if ( loadStyleExternalMethod )
|
||||
{
|
||||
// set transparency level only if it's in project
|
||||
// (otherwise it sets the layer transparent)
|
||||
QDomElement myElement = transparencyNode.toElement();
|
||||
setTransparency( myElement.text().toInt() );
|
||||
QString qml, errorMsg;
|
||||
qml = loadStyleExternalMethod( mDataSource, errorMsg );
|
||||
if ( !qml.isEmpty() )
|
||||
{
|
||||
theResultFlag = this->applyNamedStyle( qml, errorMsg );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return readSymbology( myRoot, errorMsg );
|
||||
}
|
||||
if ( !theResultFlag )
|
||||
{
|
||||
return QgsMapLayer::loadNamedStyle( theURI, theResultFlag );
|
||||
}
|
||||
return QObject::tr( "Loaded from Provider" );
|
||||
}
|
||||
|
||||
bool QgsVectorLayer::applyNamedStyle( QString namedStyle, QString errorMsg )
|
||||
{
|
||||
QDomDocument myDocument( "qgis" );
|
||||
myDocument.setContent( namedStyle );
|
||||
|
||||
QDomElement myRoot = myDocument.firstChildElement( "qgis" );
|
||||
|
||||
if ( myRoot.isNull() )
|
||||
{
|
||||
errorMsg = tr( "Error: qgis element could not be found" );
|
||||
return false;
|
||||
}
|
||||
toggleScaleBasedVisibility( myRoot.attribute( "hasScaleBasedVisibilityFlag" ).toInt() == 1 );
|
||||
setMinimumScale( myRoot.attribute( "minimumScale" ).toFloat() );
|
||||
setMaximumScale( myRoot.attribute( "maximumScale" ).toFloat() );
|
||||
|
||||
#if 0
|
||||
//read transparency level
|
||||
QDomNode transparencyNode = myRoot.namedItem( "transparencyLevelInt" );
|
||||
if ( ! transparencyNode.isNull() )
|
||||
{
|
||||
// set transparency level only if it's in project
|
||||
// (otherwise it sets the layer transparent)
|
||||
QDomElement myElement = transparencyNode.toElement();
|
||||
setTransparency( myElement.text().toInt() );
|
||||
}
|
||||
#endif
|
||||
|
||||
return readSymbology( myRoot, errorMsg );
|
||||
}
|
||||
|
@ -714,15 +714,15 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
|
||||
* @return the number of styles related to current layer
|
||||
*/
|
||||
virtual int listStylesInDatabase( QVector<QString> &ids, QVector<QString> &names,
|
||||
QVector<QString> &descriptions, QString &msgError );
|
||||
QVector<QString> &descriptions, QString &msgError );
|
||||
|
||||
/**
|
||||
* Will return the named style corresponding to style id provided
|
||||
*/
|
||||
virtual QString getStyleFromDatabase( QString styleId, QString &msgError );
|
||||
|
||||
virtual QString loadNamedStyle( const QString theURI, bool &theResultFlag, bool loadFromLocalDb=false );
|
||||
virtual bool applyNamedStyle(QString namedStyle , QString errorMsg);
|
||||
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.
|
||||
* @param elem the DOM element
|
||||
|
@ -3242,38 +3242,38 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
|
||||
return false;
|
||||
}
|
||||
|
||||
QString checkExitingTableQuery = QObject::tr( "SELECT COUNT(*) FROM information_schema.tables WHERE table_name='%1'" ).arg( styleTableName );
|
||||
QString checkExitingTableQuery = QObject::tr( "SELECT COUNT(*) FROM information_schema.tables WHERE table_name='%1'" ).arg( styleTableName );
|
||||
|
||||
PGresult* result = conn->PQexec( checkExitingTableQuery );
|
||||
char* c = PQgetvalue( result, 0, 0 );
|
||||
if( *c == '0' )
|
||||
PGresult* result = conn->PQexec( checkExitingTableQuery );
|
||||
char* c = PQgetvalue( result, 0, 0 );
|
||||
if ( *c == '0' )
|
||||
{
|
||||
QString createTabeQuery = QObject::tr( "CREATE TABLE public.%1 (id SERIAL PRIMARY KEY, f_table_catalog varchar(256), f_table_schema varchar(256), f_table_name varchar(256), f_geometry_column varchar(256), styleName varchar(30), styleQML xml, styleSLD xml, useAsDefault boolean, description text, owner varchar(30), ui xml, update_time timestamp DEFAULT CURRENT_TIMESTAMP );" ).arg( styleTableName );
|
||||
|
||||
res = conn->PQexec( createTabeQuery );
|
||||
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
|
||||
{
|
||||
QString createTabeQuery = QObject::tr( "CREATE TABLE public.%1 (id SERIAL PRIMARY KEY, f_table_catalog varchar(256), f_table_schema varchar(256), f_table_name varchar(256), f_geometry_column varchar(256), styleName varchar(30), styleQML xml, styleSLD xml, useAsDefault boolean, description text, owner varchar(30), ui xml, update_time timestamp DEFAULT CURRENT_TIMESTAMP );" ).arg( styleTableName );
|
||||
|
||||
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 this is due to table permissions (user=%1). Please contact your database admin" ).arg( dsUri.username() );
|
||||
conn->disconnect();
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
f_table_catalog = dsUri.database();
|
||||
f_table_schema = dsUri.schema();
|
||||
f_table_name = dsUri.table();
|
||||
f_geometry_column = dsUri.geometryColumn();
|
||||
owner = dsUri.username();
|
||||
isdef = (useAsDefault) ? QObject::tr( "true" ) : QObject::tr( "false" );
|
||||
isdef = ( useAsDefault ) ? QObject::tr( "true" ) : QObject::tr( "false" );
|
||||
name = ( styleName.isEmpty() ) ? dsUri.table() : styleName;
|
||||
desc = ( styleDescription.isEmpty() ) ? QDateTime::currentDateTime().toString() : styleDescription;
|
||||
|
||||
QString uiFileColumn( "" );
|
||||
QString uiFileValue( "" );
|
||||
if( !uiFileContent.isEmpty() )
|
||||
if ( !uiFileContent.isEmpty() )
|
||||
{
|
||||
uiFileColumn.append( QObject::tr( ", ui" ) );
|
||||
uiFileValue.append( QObject::tr( ",XMLPARSE(DOCUMENT %1)" ).arg( QgsPostgresConn::quotedValue( uiFileContent ) ) );
|
||||
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, "
|
||||
@ -3282,56 +3282,56 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
|
||||
"description, owner %12) "
|
||||
"VALUES(%2,%3,%4,%5,%6,XMLPARSE(DOCUMENT %7),"
|
||||
"XMLPARSE(DOCUMENT %8),%9,%10,%11 %13);" )
|
||||
.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( name ) )
|
||||
.arg( QgsPostgresConn::quotedValue( qmlStyle ) )
|
||||
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
|
||||
.arg( isdef )
|
||||
.arg( QgsPostgresConn::quotedValue( desc ) )
|
||||
.arg( QgsPostgresConn::quotedValue( owner ) )
|
||||
.arg( uiFileColumn )
|
||||
.arg( uiFileValue );
|
||||
.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( name ) )
|
||||
.arg( QgsPostgresConn::quotedValue( qmlStyle ) )
|
||||
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
|
||||
.arg( isdef )
|
||||
.arg( QgsPostgresConn::quotedValue( desc ) )
|
||||
.arg( QgsPostgresConn::quotedValue( owner ) )
|
||||
.arg( uiFileColumn )
|
||||
.arg( uiFileValue );
|
||||
|
||||
QString checkQuery = QObject::tr( "SELECT styleName FROM %1 WHERE f_table_catalog=%2 AND f_table_schema=%3 AND f_table_name=%4 AND f_geometry_column=%5 AND styleName=%6" )
|
||||
.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( name ) );
|
||||
.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( name ) );
|
||||
|
||||
result = conn->PQexec( checkQuery );
|
||||
if( PQntuples( result ) > 0 )
|
||||
if ( PQntuples( result ) > 0 )
|
||||
{
|
||||
sql = QObject::tr( "UPDATE %1 SET useAsDefault=%2, styleQML=XMLPARSE(DOCUMENT %3), styleSLD=XMLPARSE(DOCUMENT %4), description=%5, owner=%6 WHERE f_table_catalog=%7 AND f_table_schema=%8 AND f_table_name=%9 AND f_geometry_column=%10 AND styleName=%11;")
|
||||
.arg( styleTableName )
|
||||
.arg( isdef )
|
||||
.arg( QgsPostgresConn::quotedValue( qmlStyle
|
||||
) )
|
||||
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
|
||||
.arg( QgsPostgresConn::quotedValue( desc ) )
|
||||
.arg( QgsPostgresConn::quotedValue( owner ) )
|
||||
.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( name ) );
|
||||
sql = QObject::tr( "UPDATE %1 SET useAsDefault=%2, styleQML=XMLPARSE(DOCUMENT %3), styleSLD=XMLPARSE(DOCUMENT %4), description=%5, owner=%6 WHERE f_table_catalog=%7 AND f_table_schema=%8 AND f_table_name=%9 AND f_geometry_column=%10 AND styleName=%11;" )
|
||||
.arg( styleTableName )
|
||||
.arg( isdef )
|
||||
.arg( QgsPostgresConn::quotedValue( qmlStyle
|
||||
) )
|
||||
.arg( QgsPostgresConn::quotedValue( sldStyle ) )
|
||||
.arg( QgsPostgresConn::quotedValue( desc ) )
|
||||
.arg( QgsPostgresConn::quotedValue( owner ) )
|
||||
.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( name ) );
|
||||
}
|
||||
|
||||
if( useAsDefault )
|
||||
if ( useAsDefault )
|
||||
{
|
||||
QString removeDefaultSql = QObject::tr( "UPDATE %1 SET useAsDefault=false WHERE f_table_catalog=%2 AND f_table_schema=%3 AND f_table_name=%4 AND f_geometry_column=%5;")
|
||||
.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 ) );
|
||||
sql = QObject::tr("BEGIN; %1 %2 COMMIT;")
|
||||
.arg( removeDefaultSql ).arg( sql );
|
||||
QString removeDefaultSql = QObject::tr( "UPDATE %1 SET useAsDefault=false WHERE f_table_catalog=%2 AND f_table_schema=%3 AND f_table_name=%4 AND f_geometry_column=%5;" )
|
||||
.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 ) );
|
||||
sql = QObject::tr( "BEGIN; %1 %2 COMMIT;" )
|
||||
.arg( removeDefaultSql ).arg( sql );
|
||||
}
|
||||
|
||||
res = conn->PQexec( sql );
|
||||
@ -3347,135 +3347,135 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
|
||||
|
||||
QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )
|
||||
{
|
||||
QgsDataSourceURI dsUri( uri );
|
||||
QString styleTableName = QObject::tr( "layer_styles" );
|
||||
QString f_table_catalog, f_table_schema, f_table_name, f_geometry_column;
|
||||
|
||||
QgsPostgresConn* conn = QgsPostgresConn::connectDb( dsUri.connectionInfo(), false );
|
||||
if ( !conn )
|
||||
{
|
||||
errCause = QObject::tr( "Connection to database failed" );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
|
||||
f_table_catalog = dsUri.database();
|
||||
f_table_schema = dsUri.schema();
|
||||
f_table_name = dsUri.table();
|
||||
f_geometry_column = dsUri.geometryColumn();
|
||||
|
||||
QString selectQmlQuery = QObject::tr( "SELECT styleQML 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 LIMIT 1;")
|
||||
.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 ) );
|
||||
|
||||
PGresult* result = conn->PQexec( selectQmlQuery );
|
||||
if( PQntuples(result) == 1 )
|
||||
{
|
||||
char* c = PQgetvalue( result, 0, 0 );
|
||||
return QObject::tr( c );;
|
||||
}
|
||||
QgsDataSourceURI dsUri( uri );
|
||||
QString styleTableName = QObject::tr( "layer_styles" );
|
||||
QString f_table_catalog, f_table_schema, f_table_name, f_geometry_column;
|
||||
|
||||
QgsPostgresConn* conn = QgsPostgresConn::connectDb( dsUri.connectionInfo(), false );
|
||||
if ( !conn )
|
||||
{
|
||||
errCause = QObject::tr( "Connection to database failed" );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
|
||||
f_table_catalog = dsUri.database();
|
||||
f_table_schema = dsUri.schema();
|
||||
f_table_name = dsUri.table();
|
||||
f_geometry_column = dsUri.geometryColumn();
|
||||
|
||||
QString selectQmlQuery = QObject::tr( "SELECT styleQML 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 LIMIT 1;" )
|
||||
.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 ) );
|
||||
|
||||
PGresult* result = conn->PQexec( selectQmlQuery );
|
||||
if ( PQntuples( result ) == 1 )
|
||||
{
|
||||
char* c = PQgetvalue( result, 0, 0 );
|
||||
return QObject::tr( c );;
|
||||
}
|
||||
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
|
||||
QGISEXTERN int listStyles( const QString& uri, QVector<QString> &ids, QVector<QString> &names,
|
||||
QVector<QString> &descriptions, QString& errCause )
|
||||
QVector<QString> &descriptions, QString& errCause )
|
||||
{
|
||||
QgsDataSourceURI dsUri( uri );
|
||||
QString styleTableName = QObject::tr( "layer_styles" );
|
||||
QString f_table_catalog, f_table_schema, f_table_name, f_geometry_column;
|
||||
QgsDataSourceURI dsUri( uri );
|
||||
QString styleTableName = QObject::tr( "layer_styles" );
|
||||
QString f_table_catalog, f_table_schema, f_table_name, f_geometry_column;
|
||||
|
||||
QgsPostgresConn* conn = QgsPostgresConn::connectDb( dsUri.connectionInfo(), false );
|
||||
if ( !conn )
|
||||
{
|
||||
errCause = QObject::tr( "Connection to database failed using username: %1" ).arg( dsUri.username() );
|
||||
return -1;
|
||||
}
|
||||
QgsPostgresConn* conn = QgsPostgresConn::connectDb( dsUri.connectionInfo(), false );
|
||||
if ( !conn )
|
||||
{
|
||||
errCause = QObject::tr( "Connection to database failed using username: %1" ).arg( dsUri.username() );
|
||||
return -1;
|
||||
}
|
||||
|
||||
f_table_catalog = dsUri.database();
|
||||
f_table_schema = dsUri.schema();
|
||||
f_table_name = dsUri.table();
|
||||
f_geometry_column = dsUri.geometryColumn();
|
||||
f_table_catalog = dsUri.database();
|
||||
f_table_schema = dsUri.schema();
|
||||
f_table_name = dsUri.table();
|
||||
f_geometry_column = dsUri.geometryColumn();
|
||||
|
||||
// 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;" )
|
||||
.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 ) );
|
||||
// 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;" )
|
||||
.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 ) );
|
||||
|
||||
PGresult* result = conn->PQexec( selectRelatedQuery );
|
||||
if ( PQresultStatus( result ) != PGRES_TUPLES_OK )
|
||||
{
|
||||
QgsMessageLog::logMessage( QObject::tr( "Error executing query: %1" ).arg( selectRelatedQuery ) );
|
||||
errCause = QObject::tr( "Error executing the select query for related styles. The query was logged" );
|
||||
return -1;
|
||||
}
|
||||
int numberOfRelatedStyles = PQntuples( result );
|
||||
for( int i=0; i<numberOfRelatedStyles; i++ )
|
||||
{
|
||||
ids.append( QObject::tr( PQgetvalue( result, i, 0 ) ) );
|
||||
names.append( QObject::tr( PQgetvalue( result, i, 1 ) ) );
|
||||
descriptions.append( QObject::tr( PQgetvalue( result, i, 2 ) ) );
|
||||
}
|
||||
PGresult* result = conn->PQexec( selectRelatedQuery );
|
||||
if ( PQresultStatus( result ) != PGRES_TUPLES_OK )
|
||||
{
|
||||
QgsMessageLog::logMessage( QObject::tr( "Error executing query: %1" ).arg( selectRelatedQuery ) );
|
||||
errCause = QObject::tr( "Error executing the select query for related styles. The query was logged" );
|
||||
return -1;
|
||||
}
|
||||
int numberOfRelatedStyles = PQntuples( result );
|
||||
for ( int i = 0; i < numberOfRelatedStyles; i++ )
|
||||
{
|
||||
ids.append( QObject::tr( PQgetvalue( result, i, 0 ) ) );
|
||||
names.append( QObject::tr( PQgetvalue( result, i, 1 ) ) );
|
||||
descriptions.append( QObject::tr( PQgetvalue( result, i, 2 ) ) );
|
||||
}
|
||||
|
||||
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;")
|
||||
.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 ) );
|
||||
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;" )
|
||||
.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 ) );
|
||||
|
||||
result = conn->PQexec( selectOthersQuery );
|
||||
if ( PQresultStatus( result ) != PGRES_TUPLES_OK )
|
||||
{
|
||||
QgsMessageLog::logMessage( QObject::tr( "Error executing query: %1" ).arg( selectOthersQuery ) );
|
||||
errCause = QObject::tr( "Error executing the select query for unrelated styles. The query was logged" );
|
||||
return -1;
|
||||
}
|
||||
for( int i=0; i<PQntuples( result ); i++ )
|
||||
{
|
||||
ids.append( QObject::tr( PQgetvalue( result, i, 0 ) ) );
|
||||
names.append( QObject::tr( PQgetvalue( result, i, 1 ) ) );
|
||||
descriptions.append( QObject::tr( PQgetvalue( result, i, 2 ) ) );
|
||||
}
|
||||
result = conn->PQexec( selectOthersQuery );
|
||||
if ( PQresultStatus( result ) != PGRES_TUPLES_OK )
|
||||
{
|
||||
QgsMessageLog::logMessage( QObject::tr( "Error executing query: %1" ).arg( selectOthersQuery ) );
|
||||
errCause = QObject::tr( "Error executing the select query for unrelated styles. The query was logged" );
|
||||
return -1;
|
||||
}
|
||||
for ( int i = 0; i < PQntuples( result ); i++ )
|
||||
{
|
||||
ids.append( QObject::tr( PQgetvalue( result, i, 0 ) ) );
|
||||
names.append( QObject::tr( PQgetvalue( result, i, 1 ) ) );
|
||||
descriptions.append( QObject::tr( PQgetvalue( result, i, 2 ) ) );
|
||||
}
|
||||
|
||||
return numberOfRelatedStyles;
|
||||
return numberOfRelatedStyles;
|
||||
}
|
||||
|
||||
QGISEXTERN QString getStyleById(const QString& uri, QString styleId, QString& errCause )
|
||||
QGISEXTERN QString getStyleById( const QString& uri, QString styleId, QString& errCause )
|
||||
{
|
||||
QgsDataSourceURI dsUri( uri );
|
||||
QString styleTableName = QObject::tr( "layer_styles" );
|
||||
QgsDataSourceURI dsUri( uri );
|
||||
QString styleTableName = QObject::tr( "layer_styles" );
|
||||
|
||||
QgsPostgresConn* conn = QgsPostgresConn::connectDb( dsUri.connectionInfo(), false );
|
||||
if ( !conn )
|
||||
{
|
||||
errCause = QObject::tr( "Connection to database failed using username: %1" ).arg( dsUri.username() );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
QgsPostgresConn* conn = QgsPostgresConn::connectDb( dsUri.connectionInfo(), false );
|
||||
if ( !conn )
|
||||
{
|
||||
errCause = QObject::tr( "Connection to database failed using username: %1" ).arg( dsUri.username() );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
|
||||
QString selectQmlQuery = QObject::tr( "SELECT styleQml FROM %1 WHERE id=%2")
|
||||
.arg( styleTableName )
|
||||
.arg( styleId );
|
||||
PGresult* result = conn->PQexec( selectQmlQuery );
|
||||
if ( PQresultStatus( result ) != PGRES_TUPLES_OK )
|
||||
{
|
||||
QgsMessageLog::logMessage( QObject::tr( "Error executing query: %1" ).arg( selectQmlQuery ) );
|
||||
errCause = QObject::tr( "Error executing the select query. The query was logged" );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
if( PQntuples( result ) == 1)
|
||||
{
|
||||
return PQgetvalue( result, 0, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
errCause = QObject::tr( "Consistence error in table '%1'. Style id should be unique" ).arg( styleTableName );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
QString selectQmlQuery = QObject::tr( "SELECT styleQml FROM %1 WHERE id=%2" )
|
||||
.arg( styleTableName )
|
||||
.arg( styleId );
|
||||
PGresult* result = conn->PQexec( selectQmlQuery );
|
||||
if ( PQresultStatus( result ) != PGRES_TUPLES_OK )
|
||||
{
|
||||
QgsMessageLog::logMessage( QObject::tr( "Error executing query: %1" ).arg( selectQmlQuery ) );
|
||||
errCause = QObject::tr( "Error executing the select query. The query was logged" );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
if ( PQntuples( result ) == 1 )
|
||||
{
|
||||
return PQgetvalue( result, 0, 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
errCause = QObject::tr( "Consistence error in table '%1'. Style id should be unique" ).arg( styleTableName );
|
||||
return QObject::tr( "" );
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
|
||||
/**
|
||||
* It returns true. Saving style to db is supported by this provider
|
||||
*/
|
||||
virtual bool isSaveAndLoadStyleToDBSupported(){ return true; }
|
||||
virtual bool isSaveAndLoadStyleToDBSupported() { return true; }
|
||||
|
||||
QgsAttributeList attributeIndexes();
|
||||
|
||||
|
@ -37,7 +37,7 @@ from qgis.core import (QgsVectorLayer,
|
||||
QgsRasterDataProvider,
|
||||
QgsMultiBandColorRenderer,
|
||||
QGis)
|
||||
|
||||
|
||||
from utilities import (unitTestDataPath,
|
||||
getQgisTestApp,
|
||||
TestCase,
|
||||
@ -53,31 +53,31 @@ class TestQgsBlendModes(TestCase):
|
||||
def __init__(self, methodName):
|
||||
"""Run once on class initialisation."""
|
||||
unittest.TestCase.__init__(self, methodName)
|
||||
|
||||
|
||||
# initialize class MapRegistry, Canvas, MapRenderer, Map and PAL
|
||||
self.mMapRegistry = QgsMapLayerRegistry.instance()
|
||||
|
||||
|
||||
# create point layer
|
||||
myShpFile = os.path.join(TEST_DATA_DIR, 'points.shp')
|
||||
self.mPointLayer = QgsVectorLayer(myShpFile, 'Points', 'ogr')
|
||||
self.mMapRegistry.addMapLayer(self.mPointLayer)
|
||||
|
||||
|
||||
# create polygon layer
|
||||
myShpFile = os.path.join(TEST_DATA_DIR, 'polys.shp')
|
||||
self.mPolygonLayer = QgsVectorLayer(myShpFile, 'Polygons', 'ogr')
|
||||
self.mPolygonLayer = QgsVectorLayer(myShpFile, 'Polygons', 'ogr')
|
||||
self.mMapRegistry.addMapLayer(self.mPolygonLayer)
|
||||
|
||||
|
||||
# create two raster layers
|
||||
myRasterFile = os.path.join(TEST_DATA_DIR, 'landsat.tif')
|
||||
myRasterFile = os.path.join(TEST_DATA_DIR, 'landsat.tif')
|
||||
self.mRasterLayer1 = QgsRasterLayer(myRasterFile, "raster1")
|
||||
self.mRasterLayer2 = QgsRasterLayer(myRasterFile, "raster2")
|
||||
myMultiBandRenderer1 = QgsMultiBandColorRenderer(self.mRasterLayer1.dataProvider(), 2, 3, 4)
|
||||
self.mRasterLayer1.setRenderer(myMultiBandRenderer1)
|
||||
self.mMapRegistry.addMapLayer(self.mRasterLayer1)
|
||||
myMultiBandRenderer2 = QgsMultiBandColorRenderer(self.mRasterLayer2.dataProvider(), 2, 3, 4)
|
||||
myMultiBandRenderer2 = QgsMultiBandColorRenderer(self.mRasterLayer2.dataProvider(), 2, 3, 4)
|
||||
self.mRasterLayer2.setRenderer(myMultiBandRenderer2)
|
||||
self.mMapRegistry.addMapLayer(self.mRasterLayer2)
|
||||
|
||||
self.mMapRegistry.addMapLayer(self.mRasterLayer2)
|
||||
|
||||
# to match blend modes test comparisons background
|
||||
self.mCanvas = CANVAS
|
||||
self.mCanvas.setCanvasColor(QColor(152, 219, 249))
|
||||
@ -85,47 +85,47 @@ class TestQgsBlendModes(TestCase):
|
||||
self.mMap.resize(QSize(400, 400))
|
||||
self.mMapRenderer = self.mCanvas.mapRenderer()
|
||||
self.mMapRenderer.setOutputSize(QSize(400, 400), 72)
|
||||
|
||||
|
||||
def testVectorBlending(self):
|
||||
"""Test that blend modes work for vector layers."""
|
||||
|
||||
|
||||
#Add vector layers to map
|
||||
myLayers = QStringList()
|
||||
myLayers.append(self.mPointLayer.id())
|
||||
myLayers.append(self.mPolygonLayer.id())
|
||||
myLayers.append(self.mPolygonLayer.id())
|
||||
self.mMapRenderer.setLayerSet(myLayers)
|
||||
self.mMapRenderer.setExtent(self.mPointLayer.extent())
|
||||
|
||||
self.mMapRenderer.setExtent(self.mPointLayer.extent())
|
||||
|
||||
#Set blending modes for both layers
|
||||
self.mPointLayer.setBlendMode(QPainter.CompositionMode_Overlay)
|
||||
self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_Multiply)
|
||||
self.mPolygonLayer.setBlendMode(QPainter.CompositionMode_Multiply)
|
||||
|
||||
checker = QgsRenderChecker()
|
||||
checker.setControlName("expected_vector_blendmodes")
|
||||
checker.setMapRenderer(self.mMapRenderer)
|
||||
checker.setMapRenderer(self.mMapRenderer)
|
||||
|
||||
myResult = checker.runTest("vector_blendmodes");
|
||||
myMessage = ('vector blending failed')
|
||||
assert myResult, myMessage
|
||||
|
||||
|
||||
def testRasterBlending(self):
|
||||
"""Test that blend modes work for raster layers."""
|
||||
#Add raster layers to map
|
||||
myLayers = QStringList()
|
||||
myLayers.append(self.mRasterLayer1.id())
|
||||
myLayers.append(self.mRasterLayer2.id())
|
||||
myLayers.append(self.mRasterLayer2.id())
|
||||
self.mMapRenderer.setLayerSet(myLayers)
|
||||
self.mMapRenderer.setExtent(self.mRasterLayer1.extent())
|
||||
|
||||
self.mMapRenderer.setExtent(self.mRasterLayer1.extent())
|
||||
|
||||
#Set blending mode for top layer
|
||||
self.mRasterLayer1.setBlendMode(QPainter.CompositionMode_Plus)
|
||||
checker = QgsRenderChecker()
|
||||
checker.setControlName("expected_raster_blendmodes")
|
||||
checker.setMapRenderer(self.mMapRenderer)
|
||||
checker.setMapRenderer(self.mMapRenderer)
|
||||
|
||||
myResult = checker.runTest("raster_blendmodes");
|
||||
myMessage = ('raster blending failed')
|
||||
assert myResult, myMessage
|
||||
assert myResult, myMessage
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user