Skip to content
Permalink
Browse files

[needs-docs][feature] New button for empty the composer table (#5407)

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

0 comments on commit 9388717

Please sign in to comment.
You can’t perform that action at this time.