Skip to content

Commit 661bb97

Browse files
author
jef
committedJan 17, 2011
[FEATURE] feature form updates:
- make NULL value string representation configurable - fix feature updates in feature form from attribute table - add support for NULL values in value maps (comboboxes) - use layer names instead of ids in drop down list when loading value maps from layers. - support feature form expression fields: line edits on the form which name prefix "expr_" are evaluated. Their value is interpreted as field calculator string and replaced with the calculated value. - support search for NULL in attribute table git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15054 c8812cc2-4d05-0410-92ff-de0c093fc19c

9 files changed

+144
-33
lines changed
 

‎src/app/attributetable/qgsattributetabledialog.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -647,11 +647,25 @@ void QgsAttributeTableDialog::search()
647647
sensString = "LIKE";
648648
}
649649

650-
QString str = QString( "%1 %2 '%3'" )
651-
.arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
652-
.arg( numeric ? "=" : sensString )
653-
.arg( numeric ? mQuery->displayText().replace( "'", "''" ) :
654-
"%" + mQuery->displayText().replace( "'", "''" ) + "%" ); // escape quotes
650+
QSettings settings;
651+
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
652+
653+
QString str;
654+
if ( mQuery->displayText() == nullValue )
655+
{
656+
str = QString( "%1 IS NULL" ).arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) );
657+
}
658+
else
659+
{
660+
str = QString( "%1 %2 '%3'" )
661+
.arg( QgsSearchTreeNode::quotedColumnRef( fieldName ) )
662+
.arg( numeric ? "=" : sensString )
663+
.arg( numeric
664+
? mQuery->displayText().replace( "'", "''" )
665+
:
666+
"%" + mQuery->displayText().replace( "'", "''" ) + "%" ); // escape quotes
667+
}
668+
655669
doSearch( str );
656670
}
657671

‎src/app/attributetable/qgsattributetablemodel.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
414414
}
415415
else
416416
{
417-
return QVariant( "NULL" );
417+
QSettings settings;
418+
return settings.value( "qgis/nullValue", "NULL" );
418419
}
419420
}
420421

@@ -497,6 +498,7 @@ void QgsAttributeTableModel::featureForm( QModelIndex &idx )
497498
QgsFeature f;
498499
QgsAttributeMap attributes;
499500

501+
f.setFeatureId( rowToId( idx.row() ) );
500502
for ( int i = 0; i < mAttributes.size(); i++ )
501503
{
502504
f.changeAttribute( i, data( index( idx.row(), i ), Qt::EditRole ) );

‎src/app/qgsattributedialog.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "qgssymbol.h"
2626
#include "qgsattributeeditor.h"
2727
#include "qgsrubberband.h"
28+
#include "qgssearchstring.h"
29+
#include "qgssearchtreenode.h"
2830

2931
#include "qgisapp.h"
3032

@@ -193,6 +195,48 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
193195
mpIndizes << it.key();
194196
mpWidgets << myWidget;
195197
}
198+
199+
foreach( QLineEdit *le, mDialog->findChildren<QLineEdit*>() )
200+
{
201+
if ( !le->objectName().startsWith( "expr_" ) )
202+
continue;
203+
204+
le->setReadOnly( true );
205+
QString expr = le->text();
206+
le->setText( tr( "Error" ) );
207+
208+
QgsSearchString ss;
209+
if ( !ss.setString( expr ) )
210+
continue;
211+
212+
QgsSearchTreeNode *st = ss.tree();
213+
if ( !st )
214+
continue;
215+
216+
if ( !mFeature->geometry() && st->needsGeometry() )
217+
{
218+
QgsFeature f;
219+
if ( vl->featureAtId( mFeature->id(), f, true, false ) && f.geometry() )
220+
{
221+
mFeature->setGeometry( *f.geometry() );
222+
}
223+
}
224+
225+
QgsSearchTreeValue value;
226+
st->getValue( value, st, vl->pendingFields(), *mFeature );
227+
228+
if ( !value.isError() )
229+
{
230+
if ( value.isNumeric() )
231+
le->setText( QString::number( value.number() ) );
232+
else
233+
le->setText( value.string() );
234+
}
235+
else
236+
{
237+
le->setText( tr( "Error: %1" ).arg( st->errorMsg() ) );
238+
}
239+
}
196240
}
197241

198242
if ( mDialog )

‎src/app/qgsattributetypeloaddialog.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void QgsAttributeTypeLoadDialog::fillLayerList()
7474
QMap<QString, QgsMapLayer*>::iterator layer_it = QgsMapLayerRegistry::instance()->mapLayers().begin();
7575
for ( ; layer_it != QgsMapLayerRegistry::instance()->mapLayers().end(); layer_it++ )
7676
{
77-
layerComboBox->addItem( layer_it.key() );
77+
layerComboBox->addItem( layer_it.value()->name(), layer_it.key() );
7878
}
7979
}
8080

@@ -89,7 +89,7 @@ void QgsAttributeTypeLoadDialog::fillComboBoxes( int layerIndex )
8989
return;
9090
}
9191

92-
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
92+
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
9393
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
9494
if ( vLayer == NULL )
9595
{
@@ -120,7 +120,7 @@ void QgsAttributeTypeLoadDialog::createPreview( int fieldIndex, bool full )
120120
}
121121
int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
122122
int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
123-
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
123+
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
124124
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
125125
if ( vLayer == NULL )
126126
{
@@ -170,7 +170,7 @@ void QgsAttributeTypeLoadDialog::loadDataToValueMap()
170170
mValueMap.clear();
171171
int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
172172
int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
173-
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->currentText() );
173+
QgsMapLayer* dataLayer = QgsMapLayerRegistry::instance()->mapLayer( layerComboBox->itemData( layerComboBox->currentIndex() ).toString() );
174174
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
175175
if ( vLayer == NULL )
176176
{

‎src/app/qgsclipboard.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QString>
2424
#include <QStringList>
2525
#include <QClipboard>
26+
#include <QSettings>
2627

2728
#include "qgsclipboard.h"
2829
#include "qgsfeature.h"
@@ -75,7 +76,10 @@ void QgsClipboard::replaceWithCopyOf( const QgsFieldMap& fields, QgsFeatureList&
7576
if ( it->geometry() )
7677
textFields += it->geometry()->exportToWkt();
7778
else
78-
textFields += "NULL";
79+
{
80+
QSettings settings;
81+
textFields += settings.value( "qgis/nullValue", "NULL" ).toString();
82+
}
7983

8084
// QgsDebugMsg("about to traverse fields.");
8185
//

‎src/app/qgsoptions.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
253253
cbxAddPostgisDC->setChecked( settings.value( "/qgis/addPostgisDC", false ).toBool() );
254254
cbxAddNewLayersToCurrentGroup->setChecked( settings.value( "/qgis/addNewLayersToCurrentGroup", false ).toBool() );
255255
cbxCreateRasterLegendIcons->setChecked( settings.value( "/qgis/createRasterLegendIcons", true ).toBool() );
256+
leNullValue->setText( settings.value( "qgis/nullValue", "NULL" ).toString() );
256257

257258
//set the color for selections
258259
int myRed = settings.value( "/qgis/default_selection_color_red", 255 ).toInt();
@@ -524,6 +525,7 @@ void QgsOptions::saveOptions()
524525
settings.setValue( "qgis/capitaliseLayerName", capitaliseCheckBox->isChecked() );
525526
settings.setValue( "qgis/askToSaveProjectChanges", chbAskToSaveProjectChanges->isChecked() );
526527
settings.setValue( "qgis/warnOldProjectVersion", chbWarnOldProjectVersion->isChecked() );
528+
settings.setValue( "qgis/nullValue", leNullValue->text() );
527529

528530
//overlay placement method
529531
int overlayIndex = mOverlayAlgorithmComboBox->currentIndex();

‎src/gui/qgsattributeeditor.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <QDial>
3838
#include <QCalendarWidget>
3939
#include <QDialogButtonBox>
40+
#include <QSettings>
4041

4142
void QgsAttributeEditor::selectFileName( void )
4243
{
@@ -451,12 +452,15 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
451452
bool modified = false;
452453
QString text;
453454

455+
QSettings settings;
456+
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
457+
454458
QLineEdit *le = qobject_cast<QLineEdit *>( widget );
455459
if ( le )
456460
{
457461
text = le->text();
458462
modified = le->isModified();
459-
if ( text == "NULL" )
463+
if ( text == nullValue )
460464
{
461465
text = QString::null;
462466
}
@@ -467,7 +471,7 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
467471
{
468472
text = te->toHtml();
469473
modified = te->document()->isModified();
470-
if ( text == "NULL" )
474+
if ( text == nullValue )
471475
{
472476
text = QString::null;
473477
}
@@ -478,7 +482,7 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
478482
{
479483
text = pte->toPlainText();
480484
modified = pte->document()->isModified();
481-
if ( text == "NULL" )
485+
if ( text == nullValue )
482486
{
483487
text = QString::null;
484488
}
@@ -492,11 +496,16 @@ bool QgsAttributeEditor::retrieveValue( QWidget *widget, QgsVectorLayer *vl, int
492496
editType == QgsVectorLayer::Classification )
493497
{
494498
text = cb->itemData( cb->currentIndex() ).toString();
499+
if ( text == nullValue )
500+
{
501+
text = QString::null;
502+
}
495503
}
496504
else
497505
{
498506
text = cb->currentText();
499507
}
508+
modified = true;
500509
}
501510

502511
QSpinBox *sb = qobject_cast<QSpinBox *>( widget );
@@ -614,18 +623,27 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
614623
const QgsField &field = vl->pendingFields()[idx];
615624
QVariant::Type myFieldType = field.type();
616625

626+
QSettings settings;
627+
QString nullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
628+
617629
switch ( editType )
618630
{
619631
case QgsVectorLayer::Classification:
620632
case QgsVectorLayer::UniqueValues:
621633
case QgsVectorLayer::Enumeration:
622634
case QgsVectorLayer::ValueMap:
623635
{
636+
QVariant v = value;
624637
QComboBox *cb = qobject_cast<QComboBox *>( editor );
625638
if ( cb == NULL )
626639
return false;
627640

628-
int idx = cb->findData( value );
641+
if ( v.isNull() )
642+
{
643+
v = nullValue;
644+
}
645+
646+
int idx = cb->findData( v );
629647
if ( idx < 0 )
630648
return false;
631649

@@ -693,7 +711,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
693711
if ( myFieldType == QVariant::Int || myFieldType == QVariant::Double || myFieldType == QVariant::LongLong )
694712
text = "";
695713
else
696-
text = "NULL";
714+
text = nullValue;
697715
else
698716
text = value.toString();
699717

‎src/gui/qgsattributeeditor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
3131
Q_OBJECT
3232

3333
public:
34-
QgsAttributeEditor( QObject *parent ) : QObject( parent ) {}
34+
QgsAttributeEditor( QObject *parent ) : QObject( parent ) {};
3535
static QWidget *createAttributeEditor( QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value );
3636
static bool retrieveValue( QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value );
3737
static bool setValue( QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value );

‎src/ui/qgsoptionsbase.ui

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
<property name="geometry">
6060
<rect>
6161
<x>0</x>
62-
<y>0</y>
63-
<width>746</width>
64-
<height>545</height>
62+
<y>-126</y>
63+
<width>744</width>
64+
<height>586</height>
6565
</rect>
6666
</property>
6767
<layout class="QGridLayout" name="gridLayout_12">
@@ -168,7 +168,7 @@
168168
<property name="title">
169169
<string>Application</string>
170170
</property>
171-
<layout class="QVBoxLayout" name="verticalLayout_9">
171+
<layout class="QVBoxLayout" name="verticalLayout_2">
172172
<item>
173173
<layout class="QHBoxLayout" name="horizontalLayout_3">
174174
<item>
@@ -316,6 +316,33 @@
316316
</item>
317317
</layout>
318318
</item>
319+
<item>
320+
<layout class="QHBoxLayout" name="horizontalLayout_6">
321+
<item>
322+
<widget class="QLabel" name="label_14">
323+
<property name="text">
324+
<string>Representation for NULL values</string>
325+
</property>
326+
</widget>
327+
</item>
328+
<item>
329+
<spacer name="horizontalSpacer_3">
330+
<property name="orientation">
331+
<enum>Qt::Horizontal</enum>
332+
</property>
333+
<property name="sizeHint" stdset="0">
334+
<size>
335+
<width>40</width>
336+
<height>20</height>
337+
</size>
338+
</property>
339+
</spacer>
340+
</item>
341+
<item>
342+
<widget class="QLineEdit" name="leNullValue"/>
343+
</item>
344+
</layout>
345+
</item>
319346
</layout>
320347
</widget>
321348
</item>
@@ -344,7 +371,7 @@
344371
<rect>
345372
<x>0</x>
346373
<y>0</y>
347-
<width>596</width>
374+
<width>744</width>
348375
<height>466</height>
349376
</rect>
350377
</property>
@@ -515,8 +542,8 @@
515542
<rect>
516543
<x>0</x>
517544
<y>0</y>
518-
<width>507</width>
519-
<height>480</height>
545+
<width>744</width>
546+
<height>469</height>
520547
</rect>
521548
</property>
522549
<layout class="QGridLayout" name="gridLayout_4">
@@ -795,8 +822,8 @@
795822
<rect>
796823
<x>0</x>
797824
<y>0</y>
798-
<width>264</width>
799-
<height>86</height>
825+
<width>760</width>
826+
<height>460</height>
800827
</rect>
801828
</property>
802829
<layout class="QGridLayout" name="gridLayout_10">
@@ -870,8 +897,8 @@
870897
<rect>
871898
<x>0</x>
872899
<y>0</y>
873-
<width>724</width>
874-
<height>438</height>
900+
<width>838</width>
901+
<height>444</height>
875902
</rect>
876903
</property>
877904
<layout class="QGridLayout" name="gridLayout_13">
@@ -1200,8 +1227,8 @@
12001227
<rect>
12011228
<x>0</x>
12021229
<y>0</y>
1203-
<width>371</width>
1204-
<height>557</height>
1230+
<width>416</width>
1231+
<height>568</height>
12051232
</rect>
12061233
</property>
12071234
<layout class="QGridLayout" name="gridLayout_15">
@@ -1297,7 +1324,7 @@
12971324
<x>0</x>
12981325
<y>0</y>
12991326
<width>519</width>
1300-
<height>545</height>
1327+
<height>567</height>
13011328
</rect>
13021329
</property>
13031330
<layout class="QGridLayout" name="gridLayout_17">
@@ -1387,8 +1414,8 @@
13871414
<rect>
13881415
<x>0</x>
13891416
<y>0</y>
1390-
<width>329</width>
1391-
<height>531</height>
1417+
<width>407</width>
1418+
<height>508</height>
13921419
</rect>
13931420
</property>
13941421
<layout class="QGridLayout" name="gridLayout_20">

0 commit comments

Comments
 (0)
Please sign in to comment.