Skip to content
Permalink
Browse files

add layer filter in snapping configuration

  • Loading branch information
3nids committed Aug 28, 2018
1 parent 2855ccb commit 0475ff9e6547fa039dba130e3dd9a7c5fa4eb43d
@@ -53,7 +53,7 @@ QWidget *QgsSnappingLayerDelegate::createEditor( QWidget *parent, const QStyleOp
QVariant val = index.model()->data( index.model()->sibling( index.row(), QgsSnappingLayerTreeModel::UnitsColumn, index ), Qt::UserRole );
if ( val.isValid() )
{
QgsTolerance::UnitType units = ( QgsTolerance::UnitType )val.toInt();
QgsTolerance::UnitType units = static_cast<QgsTolerance::UnitType>( val.toInt() );
if ( units == QgsTolerance::Pixels )
{
w->setDecimals( 0 );
@@ -90,7 +90,7 @@ void QgsSnappingLayerDelegate::setEditorData( QWidget *editor, const QModelIndex

if ( index.column() == QgsSnappingLayerTreeModel::TypeColumn )
{
QgsSnappingConfig::SnappingType type = ( QgsSnappingConfig::SnappingType )val.toInt();
QgsSnappingConfig::SnappingType type = static_cast<QgsSnappingConfig::SnappingType>( val.toInt() );
QComboBox *cb = qobject_cast<QComboBox *>( editor );
if ( cb )
{
@@ -107,7 +107,7 @@ void QgsSnappingLayerDelegate::setEditorData( QWidget *editor, const QModelIndex
}
else if ( index.column() == QgsSnappingLayerTreeModel::UnitsColumn )
{
QgsTolerance::UnitType units = ( QgsTolerance::UnitType )val.toInt();
QgsTolerance::UnitType units = static_cast<QgsTolerance::UnitType>( val.toInt() );
QComboBox *w = qobject_cast<QComboBox *>( editor );
if ( w )
{
@@ -229,6 +229,15 @@ QgsVectorLayer *QgsSnappingLayerTreeModel::vectorLayer( const QModelIndex &idx )
return qobject_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() );
}

void QgsSnappingLayerTreeModel::setFilterText( const QString &filterText )
{
if ( filterText == mFilterText )
return;

mFilterText = filterText;
invalidateFilter();
}

void QgsSnappingLayerTreeModel::onSnappingSettingsChanged()
{
const QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> oldSettings = mIndividualLayerSettings;
@@ -317,7 +326,7 @@ bool QgsSnappingLayerTreeModel::nodeShown( QgsLayerTreeNode *node ) const
else
{
QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() );
return layer && layer->isSpatial();
return layer && layer->isSpatial() && ( mFilterText.isEmpty() || layer->name().contains( mFilterText, Qt::CaseInsensitive ) );
}
}

@@ -441,8 +450,6 @@ QVariant QgsSnappingLayerTreeModel::data( const QModelIndex &idx, int role ) con
return tr( "vertex and segment" );
case QgsSnappingConfig::Segment:
return tr( "segment" );
default:
return tr( "N/A" );
}
}

@@ -537,7 +544,7 @@ bool QgsSnappingLayerTreeModel::setData( const QModelIndex &index, const QVarian
else if ( value.toInt() == Qt::Unchecked )
ls.setEnabled( false );
else
Q_ASSERT( "expected checked or unchecked" );
Q_ASSERT( false ); // expected checked or unchecked

QgsSnappingConfig config = mProject->snappingConfig();
config.setIndividualLayerSettings( vl, ls );
@@ -561,7 +568,7 @@ bool QgsSnappingLayerTreeModel::setData( const QModelIndex &index, const QVarian
if ( !ls.valid() )
return false;

ls.setType( ( QgsSnappingConfig::SnappingType )value.toInt() );
ls.setType( static_cast<QgsSnappingConfig::SnappingType>( value.toInt() ) );
QgsSnappingConfig config = mProject->snappingConfig();
config.setIndividualLayerSettings( vl, ls );
mProject->setSnappingConfig( config );
@@ -601,7 +608,7 @@ bool QgsSnappingLayerTreeModel::setData( const QModelIndex &index, const QVarian
if ( !ls.valid() )
return false;

ls.setUnits( ( QgsTolerance::UnitType )value.toInt() );
ls.setUnits( static_cast<QgsTolerance::UnitType>( value.toInt() ) );
QgsSnappingConfig config = mProject->snappingConfig();
config.setIndividualLayerSettings( vl, ls );
mProject->setSnappingConfig( config );
@@ -76,6 +76,9 @@ class APP_EXPORT QgsSnappingLayerTreeModel : public QSortFilterProxyModel

QgsVectorLayer *vectorLayer( const QModelIndex &idx ) const;

public slots:
void setFilterText( const QString &filterText = QString() );

protected:
bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const override;

@@ -86,6 +89,7 @@ class APP_EXPORT QgsSnappingLayerTreeModel : public QSortFilterProxyModel
bool nodeShown( QgsLayerTreeNode *node ) const;

QgsProject *mProject = nullptr;
QString mFilterText;
QHash<QgsVectorLayer *, QgsSnappingConfig::IndividualLayerSettings> mIndividualLayerSettings;
QgsLayerTreeModel *mLayerTreeModel = nullptr;

@@ -62,6 +62,11 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
}

// Advanced config layer tree view
mAdvancedConfigWidget = new QWidget( this );
QVBoxLayout *advancedLayout = new QVBoxLayout();
if ( mDisplayMode == Widget )
advancedLayout->setContentsMargins( 0, 0, 0, 0 );
// tree view
mLayerTreeView = new QTreeView();
QgsSnappingLayerTreeModel *model = new QgsSnappingLayerTreeModel( mProject, this );
model->setLayerTreeModel( new QgsLayerTreeModel( mProject->layerTreeRoot(), model ) );
@@ -82,6 +87,19 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
mLayerTreeView->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding );
mLayerTreeView->setMinimumWidth( 500 );
mLayerTreeView->resizeColumnToContents( 0 );
// filter line edit
QHBoxLayout *filterLayout = new QHBoxLayout();
filterLayout->setContentsMargins( 0, 0, 0, 0 );
filterLayout->addStretch();
QgsFilterLineEdit *filterLineEdit = new QgsFilterLineEdit();
filterLineEdit->setShowClearButton( true );
filterLineEdit->setShowSearchIcon( true );
connect( filterLineEdit, &QgsFilterLineEdit::textChanged, model, &QgsSnappingLayerTreeModel::setFilterText );
filterLayout->addStretch();
filterLayout->addWidget( filterLineEdit );
advancedLayout->addLayout( filterLayout );
advancedLayout->addWidget( mLayerTreeView );
mAdvancedConfigWidget->setLayout( advancedLayout );

// enable button
mEnabledAction = new QAction( tr( "Toggle Snapping" ), this );
@@ -206,7 +224,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,
advConfigButton->setPopupMode( QToolButton::InstantPopup );
QMenu *advConfigMenu = new QMenu( this );
QWidgetAction *advConfigWidgetAction = new QWidgetAction( advConfigMenu );
advConfigWidgetAction->setDefaultWidget( mLayerTreeView );
advConfigWidgetAction->setDefaultWidget( mAdvancedConfigWidget );
advConfigMenu->addAction( advConfigWidgetAction );
advConfigButton->setIcon( QIcon( QgsApplication::getThemeIcon( "/mActionShowAllLayers.svg" ) ) );
advConfigButton->setToolTip( tr( "Edit advanced configuration" ) );
@@ -255,7 +273,7 @@ QgsSnappingWidget::QgsSnappingWidget( QgsProject *project, QgsMapCanvas *canvas,

QGridLayout *topLayout = new QGridLayout();
topLayout->addLayout( layout, 0, 0, Qt::AlignLeft | Qt::AlignTop );
topLayout->addWidget( mLayerTreeView, 1, 0 );
topLayout->addWidget( mAdvancedConfigWidget, 1, 0 );
setLayout( topLayout );
}

@@ -333,7 +351,7 @@ void QgsSnappingWidget::projectSnapSettingsChanged()
mToleranceSpinBox->setValue( config.tolerance() );
}

if ( ( QgsTolerance::UnitType )mUnitsComboBox->currentData().toInt() != config.units() )
if ( static_cast<QgsTolerance::UnitType>( mUnitsComboBox->currentData().toInt() ) != config.units() )
{
mUnitsComboBox->setCurrentIndex( mUnitsComboBox->findData( config.units() ) );
}
@@ -367,9 +385,9 @@ void QgsSnappingWidget::toggleSnappingWidgets( bool enabled )
mTypeButton->setEnabled( enabled );
mToleranceSpinBox->setEnabled( enabled );
mUnitsComboBox->setEnabled( enabled );
if ( mLayerTreeView )
if ( mAdvancedConfigWidget )
{
mLayerTreeView->setEnabled( enabled );
mAdvancedConfigWidget->setEnabled( enabled );
}
mIntersectionSnappingAction->setEnabled( enabled );
mEnableTracingAction->setEnabled( enabled );
@@ -383,7 +401,7 @@ void QgsSnappingWidget::changeTolerance( double tolerance )

void QgsSnappingWidget::changeUnit( int idx )
{
QgsTolerance::UnitType unit = ( QgsTolerance::UnitType )mUnitsComboBox->itemData( idx ).toInt();
QgsTolerance::UnitType unit = static_cast<QgsTolerance::UnitType>( mUnitsComboBox->itemData( idx ).toInt() );
mConfig.setUnits( unit );
mProject->setSnappingConfig( mConfig );

@@ -495,9 +513,9 @@ void QgsSnappingWidget::modeChanged()
mTypeButton->setVisible( !advanced );
mToleranceSpinBox->setVisible( !advanced );
mUnitsComboBox->setVisible( !advanced );
if ( mDisplayMode == Widget && mLayerTreeView )
if ( mDisplayMode == Widget && mAdvancedConfigWidget )
{
mLayerTreeView->setVisible( advanced );
mAdvancedConfigWidget->setVisible( advanced );
}
}
}
@@ -150,6 +150,7 @@ class APP_EXPORT QgsSnappingWidget : public QWidget
QAction *mEnableTracingAction = nullptr;
QgsDoubleSpinBox *mTracingOffsetSpinBox = nullptr;
QTreeView *mLayerTreeView = nullptr;
QWidget *mAdvancedConfigWidget = nullptr;
QgsFloatingWidget *mAdvancedConfigContainer = nullptr;

void cleanGroup( QgsLayerTreeNode *node );

0 comments on commit 0475ff9

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