Skip to content
Permalink
Browse files

Restore attribute table column sizes in the Merge Attributes dialog

Otherwise the columns all get set to a minimal default width,
which quickly gets very frustrating if you're merging a lot of
features and have to keep manually resizing columns to see cell content...
  • Loading branch information
nyalldawson committed Mar 16, 2021
1 parent 60f788c commit f8107b479c452f0bddb105ae61d82257374897da
Showing with 30 additions and 0 deletions.
  1. +26 −0 src/app/qgsmergeattributesdialog.cpp
  2. +4 −0 src/app/qgsmergeattributesdialog.h
@@ -110,6 +110,8 @@ QgsMergeAttributesDialog::QgsMergeAttributesDialog( const QgsFeatureList &featur

connect( mSkipAllButton, &QAbstractButton::clicked, this, &QgsMergeAttributesDialog::setAllToSkip );
connect( mTableWidget, &QTableWidget::cellChanged, this, &QgsMergeAttributesDialog::tableWidgetCellChanged );

setAttributeTableConfig( mVectorLayer->attributeTableConfig() );
}

QgsMergeAttributesDialog::QgsMergeAttributesDialog()
@@ -126,6 +128,29 @@ QgsMergeAttributesDialog::~QgsMergeAttributesDialog()
delete mSelectionRubberBand;
}

void QgsMergeAttributesDialog::setAttributeTableConfig( const QgsAttributeTableConfig &config )
{
const QVector< QgsAttributeTableConfig::ColumnConfig > columns = config.columns();
for ( const QgsAttributeTableConfig::ColumnConfig &columnConfig : columns )
{
if ( columnConfig.hidden )
continue;

const int col = mFieldToColumnMap.value( columnConfig.name, -1 );
if ( col < 0 )
continue;

if ( columnConfig.width >= 0 )
{
mTableWidget->setColumnWidth( col, columnConfig.width );
}
else
{
mTableWidget->setColumnWidth( col, mTableWidget->horizontalHeader()->defaultSectionSize() );
}
}
}

void QgsMergeAttributesDialog::createTableWidgetContents()
{
//get information about attributes from vector layer
@@ -152,6 +177,7 @@ void QgsMergeAttributesDialog::createTableWidgetContents()
}

mTableWidget->setColumnCount( col + 1 );
mFieldToColumnMap[ mFields.at( idx ).name() ] = col;

QComboBox *cb = createMergeComboBox( mFields.at( idx ).type() );
if ( mFields.at( idx ).constraints().constraints() & QgsFieldConstraints::ConstraintUnique )
@@ -29,6 +29,7 @@ class QgsMapCanvas;
class QgsRubberBand;
class QgsVectorLayer;
class QComboBox;
class QgsAttributeTableConfig;


//! A dialog to insert the merge behavior for attributes (e.g. for the union features editing tool)
@@ -72,6 +73,8 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA
private:
QgsMergeAttributesDialog(); //default constructor forbidden
void createTableWidgetContents();
void setAttributeTableConfig( const QgsAttributeTableConfig &config );

//! Create new combo box with the options for featureXX / mean / min / max
QComboBox *createMergeComboBox( QVariant::Type columnType ) const;

@@ -106,6 +109,7 @@ class APP_EXPORT QgsMergeAttributesDialog: public QDialog, private Ui::QgsMergeA

QgsFields mFields;
QSet<int> mHiddenAttributes;
QMap< QString, int > mFieldToColumnMap;
bool mUpdating = false;

static const QList< QgsStatisticalSummary::Statistic > DISPLAY_STATS;

0 comments on commit f8107b4

Please sign in to comment.