Skip to content
Permalink
Browse files

Vector layer save as: usability tunings related to attribute selection

- 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 8ee697bf2dcb7cb6329d2d6aefc009350878375d
@@ -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 )
@@ -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;
@@ -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() );
@@ -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
@@ -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();
}
@@ -602,7 +610,7 @@ QStringList QgsVectorLayerSaveAsDialog::layerOptions() const

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

QgsAttributeList QgsVectorLayerSaveAsDialog::selectedAttributes() const
@@ -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 */
@@ -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>
@@ -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" );

1 comment on commit 8ee697b

@DelazJ

This comment has been minimized.

Copy link
Contributor

@DelazJ DelazJ commented on 8ee697b Jan 3, 2017

@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.
You can’t perform that action at this time.