Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add option to insert a NULL value in a value map when loaded from layer
  • Loading branch information
m-kuhn committed Oct 10, 2013
1 parent 9b3820e commit df672e8
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 86 deletions.
13 changes: 11 additions & 2 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -251,7 +251,7 @@ void QgsAttributeTypeDialog::loadFromLayerButtonPushed()
if ( !layerDialog.exec() )
return;

updateMap( layerDialog.valueMap() );
updateMap( layerDialog.valueMap(), layerDialog.insertNull() );
}

void QgsAttributeTypeDialog::loadFromCSVButtonPushed()
Expand Down Expand Up @@ -318,14 +318,23 @@ void QgsAttributeTypeDialog::loadFromCSVButtonPushed()
updateMap( map );
}

void QgsAttributeTypeDialog::updateMap( const QMap<QString, QVariant> &map )
void QgsAttributeTypeDialog::updateMap( const QMap<QString, QVariant> &map, bool insertNull )
{
tableWidget->clearContents();
for ( int i = tableWidget->rowCount() - 1; i > 0; i-- )
{
tableWidget->removeRow( i );
}
int row = 0;

if ( insertNull )
{
QSettings settings;
tableWidget->setItem( row, 0, new QTableWidgetItem( settings.value( "qgis/nullValue", "NULL" ).toString() ) );
tableWidget->setItem( row, 1, new QTableWidgetItem( "<NULL>" ) );
++row;
}

for ( QMap<QString, QVariant>::const_iterator mit = map.begin(); mit != map.end(); mit++, row++ )
{
tableWidget->insertRow( row );
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsattributetypedialog.h
Expand Up @@ -217,8 +217,9 @@ class APP_EXPORT QgsAttributeTypeDialog: public QDialog, private Ui::QgsAttribut
/**
* Function to update the value map
* @param map new map
* @param insertNull Add a Null value on top
*/
void updateMap( const QMap<QString, QVariant> &map );
void updateMap( const QMap<QString, QVariant> &map, bool insertNull = false );

bool mFieldEditable;
bool mLabelOnTop;
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsattributetypeloaddialog.cpp
Expand Up @@ -162,6 +162,11 @@ QMap<QString, QVariant> &QgsAttributeTypeLoadDialog::valueMap()
return mValueMap;
}

bool QgsAttributeTypeLoadDialog::insertNull()
{
return nullCheckBox->isChecked();
}

void QgsAttributeTypeLoadDialog::loadDataToValueMap()
{
mValueMap.clear();
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsattributetypeloaddialog.h
Expand Up @@ -54,6 +54,13 @@ class APP_EXPORT QgsAttributeTypeLoadDialog: public QDialog, private Ui::QgsAttr
*/
QMap<QString, QVariant> &valueMap();

/**
* Returns true if the "Add NULL value" checkbox has been checked.
*
* @return true if the "Add NULL value" checkbox has been checked.
*/
bool insertNull();

private slots:
/**
* Slot which reacts to change of selected layer to fill other two comboboxes with correct data
Expand Down
161 changes: 78 additions & 83 deletions src/ui/qgsattributeloadfrommap.ui
Expand Up @@ -6,99 +6,94 @@
<rect>
<x>0</x>
<y>0</y>
<width>362</width>
<height>374</height>
<width>420</width>
<height>578</height>
</rect>
</property>
<property name="windowTitle">
<string>Load values from layer</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>10</x>
<y>340</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>341</width>
<height>331</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="layerLabel">
<property name="text">
<string>Layer</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="keyLabel">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="layerComboBox"/>
</item>
<item row="5" column="0" colspan="3">
<widget class="QTableWidget" name="previewTableWidget">
<column>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="layerLabel">
<property name="text">
<string>Value</string>
<string>Layer</string>
</property>
</column>
<column>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="keyLabel">
<property name="text">
<string>Description</string>
</property>
</column>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="valueTableLabel">
<property name="text">
<string>Select data from attributes in selected layer.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="valueLabel">
<property name="text">
<string>Value</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="valueComboBox"/>
</item>
<item row="2" column="2" rowspan="2">
<widget class="QPushButton" name="previewButton">
<property name="text">
<string>View All</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="keyComboBox"/>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QComboBox" name="layerComboBox"/>
</item>
<item row="5" column="0" colspan="3">
<widget class="QTableWidget" name="previewTableWidget">
<column>
<property name="text">
<string>Value</string>
</property>
</column>
<column>
<property name="text">
<string>Description</string>
</property>
</column>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="valueTableLabel">
<property name="text">
<string>Select data from attributes in selected layer.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="valueLabel">
<property name="text">
<string>Value</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="valueComboBox"/>
</item>
<item row="2" column="2" rowspan="2">
<widget class="QPushButton" name="previewButton">
<property name="text">
<string>View All</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QComboBox" name="keyComboBox"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="QCheckBox" name="nullCheckBox">
<property name="text">
<string>Insert NULL value on top</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>layerComboBox</tabstop>
Expand Down
13 changes: 13 additions & 0 deletions src/ui/qgsattributetypeedit.ui
Expand Up @@ -306,6 +306,19 @@
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit df672e8

Please sign in to comment.