Skip to content

Commit

Permalink
[needs-docs][feature] New button for empty the composer table (#5407)
Browse files Browse the repository at this point in the history
Adds a button to empty a composer table. Useful when you have a table
with a lot of columns and you want only a few.

Also change table  from SingleSelection to MultiSelection and allow to
delete selected rows and move selections up and down.
  • Loading branch information
lbartoletti authored and nyalldawson committed Oct 24, 2017
1 parent 8514fa3 commit 9388717
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
45 changes: 26 additions & 19 deletions src/app/composer/qgsattributeselectiondialog.cpp
Expand Up @@ -280,6 +280,7 @@ QgsAttributeSelectionDialog::QgsAttributeSelectionDialog( QgsComposerAttributeTa
connect( mColumnUpPushButton, &QPushButton::clicked, this, &QgsAttributeSelectionDialog::mColumnUpPushButton_clicked );
connect( mColumnDownPushButton, &QPushButton::clicked, this, &QgsAttributeSelectionDialog::mColumnDownPushButton_clicked );
connect( mResetColumnsPushButton, &QPushButton::clicked, this, &QgsAttributeSelectionDialog::mResetColumnsPushButton_clicked );
connect( mClearColumnsPushButton, &QPushButton::clicked, this, &QgsAttributeSelectionDialog::mClearColumnsPushButton_clicked );
connect( mAddSortColumnPushButton, &QPushButton::clicked, this, &QgsAttributeSelectionDialog::mAddSortColumnPushButton_clicked );
connect( mRemoveSortColumnPushButton, &QPushButton::clicked, this, &QgsAttributeSelectionDialog::mRemoveSortColumnPushButton_clicked );
connect( mSortColumnUpPushButton, &QPushButton::clicked, this, &QgsAttributeSelectionDialog::mSortColumnUpPushButton_clicked );
Expand Down Expand Up @@ -330,13 +331,12 @@ QgsAttributeSelectionDialog::~QgsAttributeSelectionDialog()

void QgsAttributeSelectionDialog::mRemoveColumnPushButton_clicked()
{
//remove selected row from model
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
if ( viewSelection.length() > 0 )
{
int selectedRow = viewSelection.indexes().at( 0 ).row();
mColumnModel->removeRow( selectedRow );
}
//remove selected rows from model
QModelIndexList indexes = mColumnsTableView->selectionModel()->selectedRows();
int count = indexes.count();

for ( int i = count; i > 0; --i )
mColumnModel->removeRow( indexes.at( i - 1 ).row(), QModelIndex() );
}

void QgsAttributeSelectionDialog::mAddColumnPushButton_clicked()
Expand All @@ -348,23 +348,23 @@ void QgsAttributeSelectionDialog::mAddColumnPushButton_clicked()
void QgsAttributeSelectionDialog::mColumnUpPushButton_clicked()
{
//move selected row up
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
if ( !viewSelection.empty() )
{
int selectedRow = viewSelection.indexes().at( 0 ).row();
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftUp );
}

QModelIndexList indexes = mColumnsTableView->selectionModel()->selectedRows();
int count = indexes.count();

std::reverse( indexes.begin(), indexes.end() );
for ( int i = count; i > 0; --i )
mColumnModel->moveRow( indexes.at( i - 1 ).row(), QgsComposerAttributeTableColumnModelV2::ShiftUp );
}

void QgsAttributeSelectionDialog::mColumnDownPushButton_clicked()
{
//move selected row down
QItemSelection viewSelection( mColumnsTableView->selectionModel()->selection() );
if ( !viewSelection.empty() )
{
int selectedRow = viewSelection.indexes().at( 0 ).row();
mColumnModel->moveRow( selectedRow, QgsComposerAttributeTableColumnModelV2::ShiftDown );
}
QModelIndexList indexes = mColumnsTableView->selectionModel()->selectedRows();
int count = indexes.count();

for ( int i = count; i > 0; --i )
mColumnModel->moveRow( indexes.at( i - 1 ).row(), QgsComposerAttributeTableColumnModelV2::ShiftDown );
}

void QgsAttributeSelectionDialog::mResetColumnsPushButton_clicked()
Expand All @@ -374,6 +374,13 @@ void QgsAttributeSelectionDialog::mResetColumnsPushButton_clicked()
mSortColumnComboBox->setCurrentIndex( 0 );
}

void QgsAttributeSelectionDialog::mClearColumnsPushButton_clicked()
{
//remove all columns
mColumnModel->removeRows( 0, mColumnModel->rowCount() );
mSortColumnComboBox->setCurrentIndex( 0 );
}

void QgsAttributeSelectionDialog::mAddSortColumnPushButton_clicked()
{
//add column to sort order widget
Expand Down
1 change: 1 addition & 0 deletions src/app/composer/qgsattributeselectiondialog.h
Expand Up @@ -123,6 +123,7 @@ class QgsAttributeSelectionDialog: public QDialog, private Ui::QgsAttributeSelec
void mColumnUpPushButton_clicked();
void mColumnDownPushButton_clicked();
void mResetColumnsPushButton_clicked();
void mClearColumnsPushButton_clicked();
void mAddSortColumnPushButton_clicked();
void mRemoveSortColumnPushButton_clicked();
void mSortColumnUpPushButton_clicked();
Expand Down
9 changes: 8 additions & 1 deletion src/ui/composer/qgsattributeselectiondialogbase.ui
Expand Up @@ -77,6 +77,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="mClearColumnsPushButton">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
Expand Down Expand Up @@ -113,7 +120,7 @@
<enum>Qt::IgnoreAction</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
Expand Down

0 comments on commit 9388717

Please sign in to comment.