6 changes: 3 additions & 3 deletions src/app/composer/qgscomposer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
QList<double>::iterator zoom_it;
for ( zoom_it = mStatusZoomLevelsList.begin(); zoom_it != mStatusZoomLevelsList.end(); ++zoom_it )
{
mStatusZoomCombo->insertItem( 0, QString( tr( "%1\%" ) ).arg(( *zoom_it ) * 100 ) );
mStatusZoomCombo->insertItem( 0, tr( "%1%" ).arg( *zoom_it * 100.0, 0, 'f', 1 ) );
}
connect( mStatusZoomCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( statusZoomCombo_currentIndexChanged( int ) ) );
connect( mStatusZoomCombo->lineEdit(), SIGNAL( returnPressed() ), this, SLOT( statusZoomCombo_zoomEntered() ) );
Expand Down Expand Up @@ -735,7 +735,7 @@ void QgsComposer::updateStatusZoom()
double zoomLevel = mView->transform().m11() * 100 / scale100;

mStatusZoomCombo->blockSignals( true );
mStatusZoomCombo->lineEdit()->setText( QString( tr( "%1\%" ) ).arg( QString::number( zoomLevel, 'f', 1 ) ) );
mStatusZoomCombo->lineEdit()->setText( tr( "%1%" ).arg( zoomLevel, 0, 'f', 1 ) );
mStatusZoomCombo->blockSignals( false );
}

Expand All @@ -747,7 +747,7 @@ void QgsComposer::statusZoomCombo_currentIndexChanged( int index )
mView->setZoomLevel( selectedZoom );
//update zoom combobox text for correct format (one decimal place, trailing % sign)
mStatusZoomCombo->blockSignals( true );
mStatusZoomCombo->lineEdit()->setText( QString( tr( "%1\%" ) ).arg( QString::number( selectedZoom * 100, 'f', 1 ) ) );
mStatusZoomCombo->lineEdit()->setText( tr( "%1%" ).arg( selectedZoom * 100.0, 0, 'f', 1 ) );
mStatusZoomCombo->blockSignals( false );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/composer/qgscomposermousehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event
QList<QgsComposerItem*>::iterator itemIter = selectedItems.begin();
for ( ; itemIter != selectedItems.end(); ++itemIter )
{
if (( *itemIter )->positionLock() || ( !( *itemIter )->flags() & QGraphicsItem::ItemIsSelectable ) )
if (( *itemIter )->positionLock() || (( *itemIter )->flags() & QGraphicsItem::ItemIsSelectable ) == 0 )
{
//don't move locked items
continue;
Expand All @@ -615,7 +615,7 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event
QList<QgsComposerItem*>::iterator itemIter = selectedItems.begin();
for ( ; itemIter != selectedItems.end(); ++itemIter )
{
if (( *itemIter )->positionLock() || ( !( *itemIter )->flags() & QGraphicsItem::ItemIsSelectable ) )
if (( *itemIter )->positionLock() || (( *itemIter )->flags() & QGraphicsItem::ItemIsSelectable ) == 0 )
{
//don't resize locked items or unselectable items (eg, items which make up an item group)
continue;
Expand Down
7 changes: 6 additions & 1 deletion src/core/qgscoordinatereferencesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ bool QgsCoordinateReferenceSystem::syncDatumTransform( const QString& dbPath )

int n = CSLCount( fieldnames );

int idxid, idxrx, idxry, idxrz;
int idxid = -1, idxrx = -1, idxry = -1, idxrz = -1;
for ( unsigned int i = 0; i < sizeof( map ) / sizeof( *map ); i++ )
{
bool last = i == sizeof( map ) / sizeof( *map ) - 1;
Expand Down Expand Up @@ -2046,6 +2046,11 @@ bool QgsCoordinateReferenceSystem::syncDatumTransform( const QString& dbPath )

CSLDestroy( fieldnames );

Q_ASSERT( idxid >= 0 );
Q_ASSERT( idxrx >= 0 );
Q_ASSERT( idxry >= 0 );
Q_ASSERT( idxrz >= 0 );

sqlite3 *db;
int openResult = sqlite3_open( dbPath.toUtf8().constData(), &db );
if ( openResult != SQLITE_OK )
Expand Down
8 changes: 7 additions & 1 deletion src/providers/postgres/qgspostgresconn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
#include "qgsfield.h"
#include "qgspgtablemodel.h"

#include <QApplication>
#include <QSettings>
#include <QThread>

#include <climits>

// for htonl
Expand Down Expand Up @@ -267,7 +270,10 @@ void QgsPostgresConn::disconnect()
Q_ASSERT( !key.isNull() );
connections.remove( key );

deleteLater();
if ( QThread::currentThread() == QApplication::instance()->thread() )
deleteLater();
else
delete this;
}

/* private */
Expand Down
47 changes: 28 additions & 19 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3360,6 +3360,7 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
QMessageBox::Yes | QMessageBox::No ) == QMessageBox::No )
{
errCause = QObject::tr( "Operation aborted. No changes were made in the database" );
conn->disconnect();
return false;
}

Expand Down Expand Up @@ -3402,14 +3403,14 @@ QGISEXTERN bool saveStyle( const QString& uri, const QString& qmlStyle, const QS
}

res = conn->PQexec( sql );
conn->disconnect();
if ( res.PQresultStatus() != PGRES_COMMAND_OK )
{

bool saved = res.PQresultStatus() == PGRES_COMMAND_OK;
if ( !saved )
errCause = QObject::tr( "Unable to save layer style. It's not possible to insert a new record into the style table. Maybe this is due to table permissions (user=%1). Please contact your database administrator." ).arg( dsUri.username() );
return false;
}

return true;
conn->disconnect();

return saved;
}


Expand Down Expand Up @@ -3439,7 +3440,9 @@ QGISEXTERN QString loadStyle( const QString& uri, QString& errCause )

QgsPostgresResult result = conn->PQexec( selectQmlQuery, false );

return result.PQntuples() == 1 ? result.PQgetvalue( 0, 0 ) : "";
QString style = result.PQntuples() == 1 ? result.PQgetvalue( 0, 0 ) : "";
conn->disconnect();
return style;
}

QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &names,
Expand Down Expand Up @@ -3470,6 +3473,7 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
{
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" );
conn->disconnect();
return -1;
}

Expand All @@ -3495,15 +3499,19 @@ QGISEXTERN int listStyles( const QString &uri, QStringList &ids, QStringList &na
{
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" );
conn->disconnect();
return -1;
}

for ( int i = 0; i < result.PQntuples(); i++ )
{
ids.append( result.PQgetvalue( i, 0 ) );
names.append( result.PQgetvalue( i, 1 ) );
descriptions.append( result.PQgetvalue( i, 2 ) );
}

conn->disconnect();

return numberOfRelatedStyles;
}

Expand All @@ -3515,25 +3523,26 @@ QGISEXTERN QString getStyleById( const QString& uri, QString styleId, QString& e
if ( !conn )
{
errCause = QObject::tr( "Connection to database failed using username: %1" ).arg( dsUri.username() );
return QObject::tr( "" );
return "";
}

QString style;
QString selectQmlQuery = QString( "SELECT styleQml FROM layer_styles WHERE id=%1" ).arg( QgsPostgresConn::quotedValue( styleId ) );
QgsPostgresResult result = conn->PQexec( selectQmlQuery );
if ( result.PQresultStatus() != PGRES_TUPLES_OK )
if ( result.PQresultStatus() == 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 "";
}

if ( result.PQntuples() == 1 )
{
return result.PQgetvalue( 0, 0 );
if ( result.PQntuples() == 1 )
style = result.PQgetvalue( 0, 0 );
else
errCause = QObject::tr( "Consistency error in table '%1'. Style id should be unique" ).arg( "layer_styles" );
}
else
{
errCause = QObject::tr( "Consistency error in table '%1'. Style id should be unique" ).arg( "layer_styles" );
return "";
QgsMessageLog::logMessage( QObject::tr( "Error executing query: %1" ).arg( selectQmlQuery ) );
errCause = QObject::tr( "Error executing the select query. The query was logged" );
}

conn->disconnect();

return style;
}