Skip to content

Commit

Permalink
Vector layer save as: usability tunings related to attribute selection
Browse files Browse the repository at this point in the history
- The group is renamed as 'Select fields to export and their export options'
- It has no longer a checkbox. It is just collapsible. So
  QgsVectorLayerSaveAsDialog::attributeSelection() is deprecated and always
  return true.
- For most formats, all attributes are selected by default
- For CSV/XLSX/ODS, if they have edit widgets, the corresponding checkbox in
  "Replace with displayed values" column is also checked by default.
- For DXF, keep existing behaviour: attributes are unchecked and not checkable
- For KML, keep existing behaviour: attributes are unselected by default
  • Loading branch information
rouault committed May 17, 2016
1 parent a5ef216 commit 8ee697b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
28 changes: 18 additions & 10 deletions src/app/ogr/qgsvectorlayersaveasdialog.cpp
Expand Up @@ -223,22 +223,26 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx

browseFilename->setEnabled( true );
leFilename->setEnabled( true );
bool selectAllFields = true;
bool fieldsAsDisplayedValues = false;

if ( format() == "KML" )
{
mEncodingComboBox->setCurrentIndex( mEncodingComboBox->findText( "UTF-8" ) );
mEncodingComboBox->setDisabled( true );
mAttributesSelection->setChecked( true );
mAttributesSelection->setEnabled( true );
selectAllFields = false;
}
else if ( format() == "DXF" )
{
mAttributesSelection->setChecked( true );
mAttributesSelection->setDisabled( true );
mAttributesSelection->setEnabled( false );
selectAllFields = false;
}
else
{
mEncodingComboBox->setEnabled( true );
mAttributesSelection->setEnabled( true );
fieldsAsDisplayedValues = ( format() == "CSV" || format() == "XLS" || format() == "XLSX" || format() == "ODS" );
}

if ( mLayer )
Expand All @@ -264,7 +268,6 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
{
mAttributeTable->setColumnCount( 2 );
mAttributeTable->setHorizontalHeaderLabels( QStringList() << tr( "Name" ) << tr( "Type" ) );
mReplaceRawFieldValues->setVisible( false );
}

mAttributeTableItemChangedSlotEnabled = false;
Expand All @@ -276,7 +279,7 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
QTableWidgetItem *item;
item = new QTableWidgetItem( fld.name() );
item->setFlags( flags | Qt::ItemIsUserCheckable );
item->setCheckState( Qt::Unchecked );
item->setCheckState(( selectAllFields ) ? Qt::Checked : Qt::Unchecked );
mAttributeTable->setItem( i, COLUMN_IDX_NAME, item );

item = new QTableWidgetItem( fld.typeName() );
Expand All @@ -286,12 +289,13 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx
if ( foundFieldThatCanBeExportedAsDisplayedValue )
{
QgsEditorWidgetFactory *factory;
if ( mLayer->editFormConfig()->widgetType( i ) != "TextEdit" &&
if ( flags == Qt::ItemIsEnabled &&
mLayer->editFormConfig()->widgetType( i ) != "TextEdit" &&
( factory = QgsEditorWidgetRegistry::instance()->factory( mLayer->editFormConfig()->widgetType( i ) ) ) )
{
item = new QTableWidgetItem( tr( "Use %1" ).arg( factory->name() ) );
item->setFlags( Qt::ItemIsUserCheckable );
item->setCheckState( Qt::Unchecked );
item->setFlags(( selectAllFields ) ? ( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ) : Qt::ItemIsUserCheckable );
item->setCheckState(( selectAllFields && fieldsAsDisplayedValues ) ? Qt::Checked : Qt::Unchecked );
mAttributeTable->setItem( i, COLUMN_IDX_EXPORT_AS_DISPLAYED_VALUE, item );
}
else
Expand All @@ -305,7 +309,11 @@ void QgsVectorLayerSaveAsDialog::on_mFormatComboBox_currentIndexChanged( int idx

mAttributeTableItemChangedSlotEnabled = true;

mReplaceRawFieldValues->setEnabled( false );
mReplaceRawFieldValuesStateChangedSlotEnabled = false;
mReplaceRawFieldValues->setChecked( selectAllFields && fieldsAsDisplayedValues );
mReplaceRawFieldValuesStateChangedSlotEnabled = true;
mReplaceRawFieldValues->setEnabled( selectAllFields );
mReplaceRawFieldValues->setVisible( foundFieldThatCanBeExportedAsDisplayedValue );

mAttributeTable->resizeColumnsToContents();
}
Expand Down Expand Up @@ -602,7 +610,7 @@ QStringList QgsVectorLayerSaveAsDialog::layerOptions() const

bool QgsVectorLayerSaveAsDialog::attributeSelection() const
{
return mAttributesSelection->isChecked();
return true;
}

QgsAttributeList QgsVectorLayerSaveAsDialog::selectedAttributes() const
Expand Down
1 change: 1 addition & 0 deletions src/app/ogr/qgsvectorlayersaveasdialog.h
Expand Up @@ -48,6 +48,7 @@ class APP_EXPORT QgsVectorLayerSaveAsDialog : public QDialog, private Ui::QgsVec
QStringList datasourceOptions() const;
QStringList layerOptions() const;
long crs() const;
/** @deprecated since 2.16. Now always return true since there is no longer any checkbox */
bool attributeSelection() const;
QgsAttributeList selectedAttributes() const;
/** Return selected attributes that must be exported with their displayed values instead of their raw values. Added in QGIS 2.16 */
Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgsvectorlayersaveasdialogbase.ui
Expand Up @@ -122,10 +122,10 @@
<item>
<widget class="QgsCollapsibleGroupBox" name="mAttributesSelection">
<property name="title">
<string>Limit attributes to export</string>
<string>Select fields to export and their export options</string>
</property>
<property name="checkable">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
Expand Down
4 changes: 2 additions & 2 deletions tests/src/app/testqgsvectorlayersaveasdialog.cpp
Expand Up @@ -79,8 +79,8 @@ void TestQgsVectorLayerSaveAsDialog::testAttributesAsDisplayedValues()

QgsVectorLayerSaveAsDialog d( tempLayer.data() );

QgsCollapsibleGroupBoxBasic* mAttributesSelection = d.findChild<QgsCollapsibleGroupBoxBasic*>( "mAttributesSelection" );
mAttributesSelection->setChecked( true );
QPushButton* mDeselectAllAttributes = d.findChild<QPushButton*>( "mDeselectAllAttributes" );
QTest::mouseClick( mDeselectAllAttributes, Qt::LeftButton );

QTableWidget* mAttributeTable = d.findChild<QTableWidget*>( "mAttributeTable" );
QCheckBox* mReplaceRawFieldValues = d.findChild<QCheckBox*>( "mReplaceRawFieldValues" );
Expand Down

1 comment on commit 8ee697b

@DelazJ
Copy link
Contributor

@DelazJ DelazJ commented on 8ee697b Jan 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rouault are you aware of any reason that would request KML files to have attributes deselected by default? Should we still keep that behavior? http://www.forumsig.org/showthread.php/43198-Export-shape-vers-KML-mais-pas-de-donn%C3%A9es-!!?p=346459#post346459
Thanks

Please sign in to comment.