Skip to content

Commit df672e8

Browse files
committedOct 10, 2013
Add option to insert a NULL value in a value map when loaded from layer
1 parent 9b3820e commit df672e8

6 files changed

+116
-86
lines changed
 

‎src/app/qgsattributetypedialog.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ void QgsAttributeTypeDialog::loadFromLayerButtonPushed()
251251
if ( !layerDialog.exec() )
252252
return;
253253

254-
updateMap( layerDialog.valueMap() );
254+
updateMap( layerDialog.valueMap(), layerDialog.insertNull() );
255255
}
256256

257257
void QgsAttributeTypeDialog::loadFromCSVButtonPushed()
@@ -318,14 +318,23 @@ void QgsAttributeTypeDialog::loadFromCSVButtonPushed()
318318
updateMap( map );
319319
}
320320

321-
void QgsAttributeTypeDialog::updateMap( const QMap<QString, QVariant> &map )
321+
void QgsAttributeTypeDialog::updateMap( const QMap<QString, QVariant> &map, bool insertNull )
322322
{
323323
tableWidget->clearContents();
324324
for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
325325
{
326326
tableWidget->removeRow( i );
327327
}
328328
int row = 0;
329+
330+
if ( insertNull )
331+
{
332+
QSettings settings;
333+
tableWidget->setItem( row, 0, new QTableWidgetItem( settings.value( "qgis/nullValue", "NULL" ).toString() ) );
334+
tableWidget->setItem( row, 1, new QTableWidgetItem( "<NULL>" ) );
335+
++row;
336+
}
337+
329338
for ( QMap<QString, QVariant>::const_iterator mit = map.begin(); mit != map.end(); mit++, row++ )
330339
{
331340
tableWidget->insertRow( row );

‎src/app/qgsattributetypedialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ class APP_EXPORT QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttribut
217217
/**
218218
* Function to update the value map
219219
* @param map new map
220+
* @param insertNull Add a Null value on top
220221
*/
221-
void updateMap( const QMap<QString, QVariant> &map );
222+
void updateMap( const QMap<QString, QVariant> &map, bool insertNull = false );
222223

223224
bool mFieldEditable;
224225
bool mLabelOnTop;

‎src/app/qgsattributetypeloaddialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ QMap<QString, QVariant> &QgsAttributeTypeLoadDialog::valueMap()
162162
return mValueMap;
163163
}
164164

165+
bool QgsAttributeTypeLoadDialog::insertNull()
166+
{
167+
return nullCheckBox->isChecked();
168+
}
169+
165170
void QgsAttributeTypeLoadDialog::loadDataToValueMap()
166171
{
167172
mValueMap.clear();

‎src/app/qgsattributetypeloaddialog.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ class APP_EXPORT QgsAttributeTypeLoadDialog: public QDialog, private Ui::QgsAttr
5454
*/
5555
QMap<QString, QVariant> &valueMap();
5656

57+
/**
58+
* Returns true if the "Add NULL value" checkbox has been checked.
59+
*
60+
* @return true if the "Add NULL value" checkbox has been checked.
61+
*/
62+
bool insertNull();
63+
5764
private slots:
5865
/**
5966
* Slot which reacts to change of selected layer to fill other two comboboxes with correct data

‎src/ui/qgsattributeloadfrommap.ui

Lines changed: 78 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -6,99 +6,94 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>362</width>
10-
<height>374</height>
9+
<width>420</width>
10+
<height>578</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Load values from layer</string>
1515
</property>
16-
<widget class="QDialogButtonBox" name="buttonBox">
17-
<property name="geometry">
18-
<rect>
19-
<x>10</x>
20-
<y>340</y>
21-
<width>341</width>
22-
<height>32</height>
23-
</rect>
24-
</property>
25-
<property name="orientation">
26-
<enum>Qt::Horizontal</enum>
27-
</property>
28-
<property name="standardButtons">
29-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
30-
</property>
31-
</widget>
32-
<widget class="QWidget" name="gridLayoutWidget">
33-
<property name="geometry">
34-
<rect>
35-
<x>10</x>
36-
<y>10</y>
37-
<width>341</width>
38-
<height>331</height>
39-
</rect>
40-
</property>
41-
<layout class="QGridLayout" name="gridLayout">
42-
<item row="1" column="0">
43-
<widget class="QLabel" name="layerLabel">
44-
<property name="text">
45-
<string>Layer</string>
46-
</property>
47-
</widget>
48-
</item>
49-
<item row="3" column="0">
50-
<widget class="QLabel" name="keyLabel">
51-
<property name="text">
52-
<string>Description</string>
53-
</property>
54-
</widget>
55-
</item>
56-
<item row="1" column="1" colspan="2">
57-
<widget class="QComboBox" name="layerComboBox"/>
58-
</item>
59-
<item row="5" column="0" colspan="3">
60-
<widget class="QTableWidget" name="previewTableWidget">
61-
<column>
16+
<layout class="QVBoxLayout" name="verticalLayout">
17+
<item>
18+
<layout class="QGridLayout" name="gridLayout">
19+
<item row="1" column="0">
20+
<widget class="QLabel" name="layerLabel">
6221
<property name="text">
63-
<string>Value</string>
22+
<string>Layer</string>
6423
</property>
65-
</column>
66-
<column>
24+
</widget>
25+
</item>
26+
<item row="3" column="0">
27+
<widget class="QLabel" name="keyLabel">
6728
<property name="text">
6829
<string>Description</string>
6930
</property>
70-
</column>
71-
</widget>
72-
</item>
73-
<item row="0" column="0" colspan="3">
74-
<widget class="QLabel" name="valueTableLabel">
75-
<property name="text">
76-
<string>Select data from attributes in selected layer.</string>
77-
</property>
78-
</widget>
79-
</item>
80-
<item row="2" column="0">
81-
<widget class="QLabel" name="valueLabel">
82-
<property name="text">
83-
<string>Value</string>
84-
</property>
85-
</widget>
86-
</item>
87-
<item row="2" column="1">
88-
<widget class="QComboBox" name="valueComboBox"/>
89-
</item>
90-
<item row="2" column="2" rowspan="2">
91-
<widget class="QPushButton" name="previewButton">
92-
<property name="text">
93-
<string>View All</string>
94-
</property>
95-
</widget>
96-
</item>
97-
<item row="3" column="1">
98-
<widget class="QComboBox" name="keyComboBox"/>
99-
</item>
100-
</layout>
101-
</widget>
31+
</widget>
32+
</item>
33+
<item row="1" column="1" colspan="2">
34+
<widget class="QComboBox" name="layerComboBox"/>
35+
</item>
36+
<item row="5" column="0" colspan="3">
37+
<widget class="QTableWidget" name="previewTableWidget">
38+
<column>
39+
<property name="text">
40+
<string>Value</string>
41+
</property>
42+
</column>
43+
<column>
44+
<property name="text">
45+
<string>Description</string>
46+
</property>
47+
</column>
48+
</widget>
49+
</item>
50+
<item row="0" column="0" colspan="3">
51+
<widget class="QLabel" name="valueTableLabel">
52+
<property name="text">
53+
<string>Select data from attributes in selected layer.</string>
54+
</property>
55+
</widget>
56+
</item>
57+
<item row="2" column="0">
58+
<widget class="QLabel" name="valueLabel">
59+
<property name="text">
60+
<string>Value</string>
61+
</property>
62+
</widget>
63+
</item>
64+
<item row="2" column="1">
65+
<widget class="QComboBox" name="valueComboBox"/>
66+
</item>
67+
<item row="2" column="2" rowspan="2">
68+
<widget class="QPushButton" name="previewButton">
69+
<property name="text">
70+
<string>View All</string>
71+
</property>
72+
</widget>
73+
</item>
74+
<item row="3" column="1">
75+
<widget class="QComboBox" name="keyComboBox"/>
76+
</item>
77+
<item row="4" column="0" colspan="2">
78+
<widget class="QCheckBox" name="nullCheckBox">
79+
<property name="text">
80+
<string>Insert NULL value on top</string>
81+
</property>
82+
</widget>
83+
</item>
84+
</layout>
85+
</item>
86+
<item>
87+
<widget class="QDialogButtonBox" name="buttonBox">
88+
<property name="orientation">
89+
<enum>Qt::Horizontal</enum>
90+
</property>
91+
<property name="standardButtons">
92+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
93+
</property>
94+
</widget>
95+
</item>
96+
</layout>
10297
</widget>
10398
<tabstops>
10499
<tabstop>layerComboBox</tabstop>

‎src/ui/qgsattributetypeedit.ui

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,19 @@
306306
</property>
307307
</widget>
308308
</item>
309+
<item>
310+
<spacer name="verticalSpacer_13">
311+
<property name="orientation">
312+
<enum>Qt::Vertical</enum>
313+
</property>
314+
<property name="sizeHint" stdset="0">
315+
<size>
316+
<width>20</width>
317+
<height>40</height>
318+
</size>
319+
</property>
320+
</spacer>
321+
</item>
309322
</layout>
310323
</item>
311324
</layout>

0 commit comments

Comments
 (0)
Please sign in to comment.