Skip to content

Commit 88d482e

Browse files
committed
non spatial are not identifiable
also removes checkboxes from items not being checkable
1 parent c6caa29 commit 88d482e

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

src/app/qgslayercapabilitiesmodel.cpp

+28-17
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,14 @@ Qt::ItemFlags QgsLayerCapabilitiesModel::flags( const QModelIndex &idx ) const
128128
{
129129
if ( idx.column() == IdentifiableColumn )
130130
{
131-
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
131+
if ( layer->isSpatial() )
132+
{
133+
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsUserCheckable;
134+
}
135+
else
136+
{
137+
return nullptr;
138+
}
132139
}
133140
else if ( idx.column() == ReadOnlyColumn )
134141
{
@@ -138,7 +145,7 @@ Qt::ItemFlags QgsLayerCapabilitiesModel::flags( const QModelIndex &idx ) const
138145
}
139146
else
140147
{
141-
return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
148+
return nullptr;
142149
}
143150
}
144151
else if ( idx.column() == SearchableColumn )
@@ -224,15 +231,18 @@ QVariant QgsLayerCapabilitiesModel::data( const QModelIndex &idx, int role ) con
224231
QVariant falseValue = role == Qt::CheckStateRole ? Qt::Unchecked : false;
225232
if ( idx.column() == IdentifiableColumn )
226233
{
227-
return !mNonIdentifiableLayers.contains( layer->id() ) ? trueValue : falseValue;
234+
if ( layer->isSpatial() )
235+
return !mNonIdentifiableLayers.contains( layer->id() ) ? trueValue : falseValue;
228236
}
229237
else if ( idx.column() == ReadOnlyColumn )
230238
{
231-
return mReadOnlyLayers.value( layer, true ) ? trueValue : falseValue;
239+
if ( layer->type() == QgsMapLayer::VectorLayer )
240+
return mReadOnlyLayers.value( layer, true ) ? trueValue : falseValue;
232241
}
233242
else if ( idx.column() == SearchableColumn )
234243
{
235-
return mSearchableLayers.value( layer, true ) ? trueValue : falseValue;
244+
if ( layer->type() == QgsMapLayer::VectorLayer )
245+
return mSearchableLayers.value( layer, true ) ? trueValue : falseValue;
236246
}
237247
}
238248
}
@@ -249,19 +259,21 @@ bool QgsLayerCapabilitiesModel::setData( const QModelIndex &index, const QVarian
249259
{
250260
if ( index.column() == IdentifiableColumn )
251261
{
252-
bool nonIdentifiable = value == Qt::Unchecked;
253-
bool containsLayer = mNonIdentifiableLayers.contains( layer->id() );
254-
if ( containsLayer && !nonIdentifiable )
255-
mNonIdentifiableLayers.removeAll( layer->id() );
256-
if ( !containsLayer && nonIdentifiable )
257-
mNonIdentifiableLayers.append( layer->id() );
258-
emit dataChanged( index, index );
259-
return true;
262+
if ( layer->isSpatial() )
263+
{
264+
bool nonIdentifiable = value == Qt::Unchecked;
265+
bool containsLayer = mNonIdentifiableLayers.contains( layer->id() );
266+
if ( containsLayer && !nonIdentifiable )
267+
mNonIdentifiableLayers.removeAll( layer->id() );
268+
if ( !containsLayer && nonIdentifiable )
269+
mNonIdentifiableLayers.append( layer->id() );
270+
emit dataChanged( index, index );
271+
return true;
272+
}
260273
}
261274
else if ( index.column() == ReadOnlyColumn )
262275
{
263-
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
264-
if ( vl )
276+
if ( layer->type() == QgsMapLayer::VectorLayer )
265277
{
266278
mReadOnlyLayers.insert( layer, value == Qt::Checked );
267279
emit dataChanged( index, index );
@@ -270,8 +282,7 @@ bool QgsLayerCapabilitiesModel::setData( const QModelIndex &index, const QVarian
270282
}
271283
else if ( index.column() == SearchableColumn )
272284
{
273-
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( layer );
274-
if ( vl )
285+
if ( layer->type() == QgsMapLayer::VectorLayer )
275286
{
276287
mSearchableLayers.insert( layer, value == Qt::Checked );
277288
emit dataChanged( index, index );

src/core/qgsmaplayer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteCo
247247
QDomNode srsNode = layerElement.namedItem( QStringLiteral( "srs" ) );
248248
mCRS.readXml( srsNode );
249249
mCRS.setValidationHint( tr( "Specify CRS for layer %1" ).arg( mne.text() ) );
250-
mCRS.validate();
250+
if ( isSpatial() )
251+
mCRS.validate();
251252
savedCRS = mCRS;
252253

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

0 commit comments

Comments
 (0)