Skip to content

Commit

Permalink
use toggle selection button instead of check/uncheck2
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Sep 3, 2018
1 parent 88d482e commit b5aa65c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 50 deletions.
9 changes: 4 additions & 5 deletions src/app/qgslayercapabilitiesmodel.cpp
Expand Up @@ -55,16 +55,15 @@ void QgsLayerCapabilitiesModel::setFilterText( const QString &filterText )
invalidateFilter();
}

void QgsLayerCapabilitiesModel::checkSelectedItems( const QModelIndexList &checkedIndexes, bool check )
void QgsLayerCapabilitiesModel::toggleSelectedItems( const QModelIndexList &checkedIndexes )
{
QVector<int> roles = QVector<int>() << Qt::CheckStateRole;
// beginResetModel();
for ( const QModelIndex &index : checkedIndexes )
{
if ( setData( index, check ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole ) )
emit dataChanged( index, index ); //), roles);
bool isChecked = data( index, Qt::CheckStateRole ) == Qt::Checked;
if ( setData( index, isChecked ? Qt::Unchecked : Qt::Checked, Qt::CheckStateRole ) )
emit dataChanged( index, index );
}
//endResetModel();
}

QStringList QgsLayerCapabilitiesModel::nonIdentifiableLayers() const
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgslayercapabilitiesmodel.h
Expand Up @@ -59,7 +59,7 @@ class APP_EXPORT QgsLayerCapabilitiesModel : public QSortFilterProxyModel

public slots:
void setFilterText( const QString &filterText = QString() );
void checkSelectedItems( const QModelIndexList &checkedIndexes, bool check );
void toggleSelectedItems( const QModelIndexList &checkedIndexes );

protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;
Expand Down
14 changes: 3 additions & 11 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -369,8 +369,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
Q_UNUSED( selected );
Q_UNUSED( deselected );
bool hasSelection = !mLayerCapabilitiesTree->selectionModel()->selectedIndexes().isEmpty();
mLayerCapabilitiesCheckButton->setEnabled( hasSelection );
mLayerCapabilitiesUncheckButton->setEnabled( hasSelection );
mLayerCapabilitiesToggleSelectionButton->setEnabled( hasSelection );
} );

mLayerCapabilitiesTreeFilterLineEdit->setShowClearButton( true );
Expand All @@ -382,18 +381,11 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mLayerCapabilitiesTree->expandAll();
} );

connect( mLayerCapabilitiesCheckButton, &QToolButton::clicked, this, [ = ]( bool clicked )
connect( mLayerCapabilitiesToggleSelectionButton, &QToolButton::clicked, this, [ = ]( bool clicked )
{
Q_UNUSED( clicked );
const QModelIndexList indexes = mLayerCapabilitiesTree->selectionModel()->selectedIndexes();
mLayerCapabilitiesModel->checkSelectedItems( indexes, true );
mLayerCapabilitiesTree->repaint();
} );
connect( mLayerCapabilitiesUncheckButton, &QToolButton::clicked, this, [ = ]( bool clicked )
{
Q_UNUSED( clicked );
const QModelIndexList indexes = mLayerCapabilitiesTree->selectionModel()->selectedIndexes();
mLayerCapabilitiesModel->checkSelectedItems( indexes, false );
mLayerCapabilitiesModel->toggleSelectedItems( indexes );
mLayerCapabilitiesTree->repaint();
} );

Expand Down
56 changes: 23 additions & 33 deletions src/ui/qgsprojectpropertiesbase.ui
Expand Up @@ -277,7 +277,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<width>563</width>
<height>833</height>
</rect>
</property>
Expand Down Expand Up @@ -875,8 +875,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<height>764</height>
<width>547</width>
<height>152</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
Expand Down Expand Up @@ -950,8 +950,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<height>764</height>
<width>271</width>
<height>597</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_12">
Expand Down Expand Up @@ -1414,30 +1414,10 @@
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="1" column="0" colspan="4">
<widget class="QTreeView" name="mLayerCapabilitiesTree"/>
<item row="3" column="3">
<widget class="QgsFilterLineEdit" name="mLayerCapabilitiesTreeFilterLineEdit"/>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="mLayerCapabilitiesCheckButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Check Selected</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="mLayerCapabilitiesUncheckButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Uncheck Selected</string>
</property>
</widget>
</item>
<item row="3" column="2">
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -1450,10 +1430,20 @@
</property>
</spacer>
</item>
<item row="3" column="3">
<widget class="QgsFilterLineEdit" name="mLayerCapabilitiesTreeFilterLineEdit"/>
<item row="3" column="0">
<widget class="QPushButton" name="mLayerCapabilitiesToggleSelectionButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Toggle Selection</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<widget class="QTreeView" name="mLayerCapabilitiesTree"/>
</item>
<item row="4" column="3">
<item row="3" column="2">
<widget class="QCheckBox" name="mShowSpatialLayersCheckBox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
Expand Down Expand Up @@ -1591,8 +1581,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<height>764</height>
<width>157</width>
<height>59</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_17">
Expand Down Expand Up @@ -1653,7 +1643,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<width>603</width>
<height>2666</height>
</rect>
</property>
Expand Down

0 comments on commit b5aa65c

Please sign in to comment.