Skip to content

Commit

Permalink
Restore attribute table column sizes in the Merge Attributes dialog
Browse files Browse the repository at this point in the history
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 f8107b4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/app/qgsmergeattributesdialog.cpp
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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 )
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsmergeattributesdialog.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit f8107b4

Please sign in to comment.