Skip to content

Commit

Permalink
non spatial are not identifiable
Browse files Browse the repository at this point in the history
also removes checkboxes from items not being checkable
  • Loading branch information
3nids committed Sep 3, 2018
1 parent c6caa29 commit 88d482e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
45 changes: 28 additions & 17 deletions src/app/qgslayercapabilitiesmodel.cpp
Expand Up @@ -128,7 +128,14 @@ Qt::ItemFlags QgsLayerCapabilitiesModel::flags( const QModelIndex &idx ) const
{
if ( idx.column() == IdentifiableColumn )
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
if ( layer->isSpatial() )
{
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
}
else
{
return nullptr;
}
}
else if ( idx.column() == ReadOnlyColumn )
{
Expand All @@ -138,7 +145,7 @@ Qt::ItemFlags QgsLayerCapabilitiesModel::flags( const QModelIndex &idx ) const
}
else
{
return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
return nullptr;
}
}
else if ( idx.column() == SearchableColumn )
Expand Down Expand Up @@ -224,15 +231,18 @@ QVariant QgsLayerCapabilitiesModel::data( const QModelIndex &idx, int role ) con
QVariant falseValue = role == Qt::CheckStateRole ? Qt::Unchecked : false;
if ( idx.column() == IdentifiableColumn )
{
return !mNonIdentifiableLayers.contains( layer->id() ) ? trueValue : falseValue;
if ( layer->isSpatial() )
return !mNonIdentifiableLayers.contains( layer->id() ) ? trueValue : falseValue;
}
else if ( idx.column() == ReadOnlyColumn )
{
return mReadOnlyLayers.value( layer, true ) ? trueValue : falseValue;
if ( layer->type() == QgsMapLayer::VectorLayer )
return mReadOnlyLayers.value( layer, true ) ? trueValue : falseValue;
}
else if ( idx.column() == SearchableColumn )
{
return mSearchableLayers.value( layer, true ) ? trueValue : falseValue;
if ( layer->type() == QgsMapLayer::VectorLayer )
return mSearchableLayers.value( layer, true ) ? trueValue : falseValue;
}
}
}
Expand All @@ -249,19 +259,21 @@ bool QgsLayerCapabilitiesModel::setData( const QModelIndex &index, const QVarian
{
if ( index.column() == IdentifiableColumn )
{
bool nonIdentifiable = value == Qt::Unchecked;
bool containsLayer = mNonIdentifiableLayers.contains( layer->id() );
if ( containsLayer && !nonIdentifiable )
mNonIdentifiableLayers.removeAll( layer->id() );
if ( !containsLayer && nonIdentifiable )
mNonIdentifiableLayers.append( layer->id() );
emit dataChanged( index, index );
return true;
if ( layer->isSpatial() )
{
bool nonIdentifiable = value == Qt::Unchecked;
bool containsLayer = mNonIdentifiableLayers.contains( layer->id() );
if ( containsLayer && !nonIdentifiable )
mNonIdentifiableLayers.removeAll( layer->id() );
if ( !containsLayer && nonIdentifiable )
mNonIdentifiableLayers.append( layer->id() );
emit dataChanged( index, index );
return true;
}
}
else if ( index.column() == ReadOnlyColumn )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( vl )
if ( layer->type() == QgsMapLayer::VectorLayer )
{
mReadOnlyLayers.insert( layer, value == Qt::Checked );
emit dataChanged( index, index );
Expand All @@ -270,8 +282,7 @@ bool QgsLayerCapabilitiesModel::setData( const QModelIndex &index, const QVarian
}
else if ( index.column() == SearchableColumn )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
if ( vl )
if ( layer->type() == QgsMapLayer::VectorLayer )
{
mSearchableLayers.insert( layer, value == Qt::Checked );
emit dataChanged( index, index );
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -247,7 +247,8 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteCo
QDomNode srsNode = layerElement.namedItem( QStringLiteral( "srs" ) );
mCRS.readXml( srsNode );
mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
mCRS.validate();
if ( isSpatial() )
mCRS.validate();
savedCRS = mCRS;

// Do not validate any projections in children, they will be overwritten anyway.
Expand Down

0 comments on commit 88d482e

Please sign in to comment.