Skip to content

Commit 9611ec3

Browse files
jef-nalexbruy
authored andcommittedDec 28, 2011
query builder: support null values in values lists
1 parent a13385e commit 9611ec3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed
 

‎src/app/qgsquerybuilder.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <QMessageBox>
2020
#include <QRegExp>
2121
#include <QPushButton>
22+
#include <QSettings>
2223
#include "qgsvectorlayer.h"
2324
#include "qgsvectordataprovider.h"
2425

@@ -100,12 +101,18 @@ void QgsQueryBuilder::fillValues( int idx, int limit )
100101
QList<QVariant> values;
101102
mLayer->uniqueValues( idx, values, limit );
102103

104+
QSettings settings;
105+
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
106+
107+
QgsDebugMsg( QString( "nullValue: %1" ).arg( nullValue ) );
108+
103109
for ( int i = 0; i < values.size(); i++ )
104110
{
105-
QStandardItem *myItem = new QStandardItem( values[i].toString() );
111+
QStandardItem *myItem = new QStandardItem( values[i].isNull() ? nullValue : values[i].toString() );
106112
myItem->setEditable( false );
107-
myItem->setData( values[i] );
113+
myItem->setData( values[i], Qt::UserRole + 1 );
108114
mModelValues->insertRow( mModelValues->rowCount(), myItem );
115+
QgsDebugMsg( QString( "Value is null: %1\nvalue: %2" ).arg( values[i].isNull() ).arg( values[i].isNull() ? nullValue : values[i].toString() ) );
109116
}
110117
}
111118

@@ -269,9 +276,9 @@ void QgsQueryBuilder::on_lstFields_doubleClicked( const QModelIndex &index )
269276
void QgsQueryBuilder::on_lstValues_doubleClicked( const QModelIndex &index )
270277
{
271278
QVariant value = mModelValues->data( index, Qt::UserRole + 1 );
272-
if( value.isNull() )
279+
if ( value.isNull() )
273280
txtSQL->insertPlainText( "NULL" );
274-
else if( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
281+
else if ( value.type() == QVariant::Int || value.type() == QVariant::Double || value.type() == QVariant::LongLong )
275282
txtSQL->insertPlainText( value.toString() );
276283
else
277284
txtSQL->insertPlainText( "'" + value.toString() + "'" );

0 commit comments

Comments
 (0)