Showing with 28 additions and 14 deletions.
  1. +0 −5 src/gui/attributetable/qgsattributetablemodel.cpp
  2. +11 −4 src/gui/qgsquerybuilder.cpp
  3. +17 −5 src/providers/ogr/qgsogrprovider.cpp
5 changes: 0 additions & 5 deletions src/gui/attributetable/qgsattributetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ void QgsAttributeTableModel::layerDeleted()

void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
{
if ( mFeatureMap.contains( fid ) )
{
mFeatureMap[ fid ].changeAttribute( idx, value );
}

setData( index( idToRow( fid ), fieldCol( idx ) ), value, Qt::EditRole );
}

Expand Down
15 changes: 11 additions & 4 deletions src/gui/qgsquerybuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QMessageBox>
#include <QRegExp>
#include <QPushButton>
#include <QSettings>
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

Expand Down Expand Up @@ -99,12 +100,18 @@ void QgsQueryBuilder::fillValues( int idx, int limit )
QList<QVariant> values;
mLayer->uniqueValues( idx, values, limit );

QSettings settings;
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();

QgsDebugMsg( QString( "nullValue: %1" ).arg( nullValue ) );

for ( int i = 0; i < values.size(); i++ )
{
QStandardItem *myItem = new QStandardItem( values[i].toString() );
QStandardItem *myItem = new QStandardItem( values[i].isNull() ? nullValue : values[i].toString() );
myItem->setEditable( false );
myItem->setData( values[i] );
myItem->setData( values[i], Qt::UserRole + 1 );
mModelValues->insertRow( mModelValues->rowCount(), myItem );
QgsDebugMsg( QString( "Value is null: %1\nvalue: %2" ).arg( values[i].isNull() ).arg( values[i].isNull() ? nullValue : values[i].toString() ) );
}
}

Expand Down Expand Up @@ -268,9 +275,9 @@ void QgsQueryBuilder::on_lstFields_doubleClicked( const QModelIndex &index )
void QgsQueryBuilder::on_lstValues_doubleClicked( const QModelIndex &index )
{
QVariant value = mModelValues->data( index, Qt::UserRole + 1 );
if( value.isNull() )
if ( value.isNull() )
txtSQL->insertPlainText( "NULL" );
else if( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
else if ( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
txtSQL->insertPlainText( value.toString() );
else
txtSQL->insertPlainText( "'" + value.toString() + "'" );
Expand Down
22 changes: 17 additions & 5 deletions src/providers/ogr/qgsogrprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,19 @@ QStringList QgsOgrProvider::subLayers() const

void QgsOgrProvider::setEncoding( const QString& e )
{
QgsVectorDataProvider::setEncoding( e );
#if defined(OLCStringsAsUTF8)
if ( !OGR_L_TestCapability( ogrLayer, OLCStringsAsUTF8 ) )
{
QgsVectorDataProvider::setEncoding( e );
}
else
{
QgsVectorDataProvider::setEncoding( "UTF-8" );
}
#else
QgsVectorDataProvider::setEncoding( e );
#endif

loadFields();
}

Expand Down Expand Up @@ -2110,7 +2122,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
sql += QString( " WHERE %1" ).arg( mSubsetString );
}

sql += QString( " ORDER BY %1" ).arg( quotedIdentifier( fld.name() ) );
sql += QString( " ORDER BY %1 ASC" ).arg( fld.name() ); // quoting of fieldname produces a syntax error

QgsDebugMsg( QString( "SQL: %1" ).arg( sql ) );
OGRLayerH l = OGR_DS_ExecuteSQL( ogrDataSource, TO8( sql ), NULL, "SQL" );
Expand All @@ -2120,7 +2132,7 @@ void QgsOgrProvider::uniqueValues( int index, QList<QVariant> &uniqueValues, int
OGRFeatureH f;
while ( 0 != ( f = OGR_L_GetNextFeature( l ) ) )
{
uniqueValues << convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
uniqueValues << ( OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() ) );
OGR_F_Destroy( f );

if ( limit >= 0 && uniqueValues.size() >= limit )
Expand Down Expand Up @@ -2162,7 +2174,7 @@ QVariant QgsOgrProvider::minimumValue( int index )
return QVariant();
}

QVariant value = convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
OGR_F_Destroy( f );

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down Expand Up @@ -2201,7 +2213,7 @@ QVariant QgsOgrProvider::maximumValue( int index )
return QVariant();
}

QVariant value = convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) );
QVariant value = OGR_F_IsFieldSet( f, 0 ) ? convertValue( fld.type(), mEncoding->toUnicode( OGR_F_GetFieldAsString( f, 0 ) ) ) : QVariant( fld.type() );
OGR_F_Destroy( f );

OGR_DS_ReleaseResultSet( ogrDataSource, l );
Expand Down