Skip to content
Permalink
Browse files

use toggle selection button instead of check/uncheck2

  • Loading branch information
3nids committed Sep 3, 2018
1 parent 88d482e commit b5aa65c5aff5c01f59e7e47918f743320cf660c4
@@ -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
@@ -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;
@@ -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 );
@@ -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();
} );

@@ -277,7 +277,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<width>563</width>
<height>833</height>
</rect>
</property>
@@ -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">
@@ -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">
@@ -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>
@@ -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>
@@ -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">
@@ -1653,7 +1643,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>676</width>
<width>603</width>
<height>2666</height>
</rect>
</property>

0 comments on commit b5aa65c

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