Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add invert selection tool on refactor fields processing fix #52816
  • Loading branch information
ismailsunni authored and nyalldawson committed Apr 24, 2023
1 parent 49b3a9d commit 4373ac6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/gui/auto_generated/qgsfieldmappingwidget.sip.in
Expand Up @@ -144,6 +144,11 @@ Moves up currently selected field
bool moveSelectedFieldsDown( );
%Docstring
Moves down the currently selected field
%End

bool invertSelection( );
%Docstring
Invert the field selection state
%End

};
Expand Down
2 changes: 2 additions & 0 deletions src/gui/processing/qgsprocessingfieldmapwidgetwrapper.cpp
Expand Up @@ -53,8 +53,10 @@ QgsProcessingFieldMapPanelWidget::QgsProcessingFieldMapPanelWidget( QWidget *par
connect( mDeleteButton, &QPushButton::clicked, mFieldsView, &QgsFieldMappingWidget::removeSelectedFields );
connect( mUpButton, &QPushButton::clicked, mFieldsView, &QgsFieldMappingWidget::moveSelectedFieldsUp );
connect( mDownButton, &QPushButton::clicked, mFieldsView, &QgsFieldMappingWidget::moveSelectedFieldsDown );
connect( mInvertSelectionButton, &QPushButton::clicked, mFieldsView, &QgsFieldMappingWidget::invertSelection );
connect( mLoadLayerFieldsButton, &QPushButton::clicked, this, &QgsProcessingFieldMapPanelWidget::loadLayerFields );


connect( mFieldsView, &QgsFieldMappingWidget::changed, this, [ = ]
{
if ( !mBlockChangedSignal )
Expand Down
16 changes: 16 additions & 0 deletions src/gui/qgsfieldmappingwidget.cpp
Expand Up @@ -20,6 +20,7 @@
#include "qgsprocessingaggregatewidgets.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
#include "QItemSelectionModel"

#include <QTableView>
#include <QVBoxLayout>
Expand Down Expand Up @@ -147,6 +148,21 @@ bool QgsFieldMappingWidget::removeSelectedFields()
return true;
}

bool QgsFieldMappingWidget::invertSelection()
{

for ( int i = 0; i < mTableView->model()->rowCount(); ++i )
{
for ( int j = 0; j < mTableView->model()->columnCount(); j++ )
{
QModelIndex index = mTableView->model()->index( i, j );
mTableView->selectionModel()->select( index, QItemSelectionModel::Toggle );
}

}
return true;
}

bool QgsFieldMappingWidget::moveSelectedFieldsUp()
{
if ( ! mTableView->selectionModel()->hasSelection() )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsfieldmappingwidget.h
Expand Up @@ -144,6 +144,9 @@ class GUI_EXPORT QgsFieldMappingWidget : public QgsPanelWidget
//! Moves down the currently selected field
bool moveSelectedFieldsDown( );

//! Invert the field selection state
bool invertSelection( );

private:

QTableView *mTableView = nullptr;
Expand Down
12 changes: 12 additions & 0 deletions src/ui/processing/qgsprocessingfieldsmappingpanelbase.ui
Expand Up @@ -116,6 +116,17 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mInvertSelectionButton">
<property name="text">
<string>invert selection</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mActionInvertSelection.svg</normaloff>:/images/themes/default/mActionInvertSelection.svg</iconset>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -188,6 +199,7 @@
</customwidgets>
<resources>
<include location="../../../images/images.qrc"/>
<include location="../../../images/images.qrc"/>
</resources>
<connections/>
</ui>

0 comments on commit 4373ac6

Please sign in to comment.