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
This commit is contained in:
Even Rouault 2016-05-17 12:08:18 +02:00
parent a5ef216fbc
commit 8ee697bf2d
4 changed files with 23 additions and 14 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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>

View File

@ -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" );