88 ***************************************************************************/
99
1010#include " qgsvectorlayer.h"
11- #include " layersproxymodel .h"
11+ #include " recordinglayersproxymodel .h"
1212
1313#include " qgsproject.h"
1414#include " qgslayertree.h"
1515
16- LayersProxyModel::LayersProxyModel ( QObject *parent ) :
16+ RecordingLayersProxyModel::RecordingLayersProxyModel ( QObject *parent ) :
1717 QgsMapLayerProxyModel{ parent }
1818{
19- QObject::connect ( this , &LayersProxyModel::rowsInserted, this , &LayersProxyModel::countChanged );
20- QObject::connect ( this , &LayersProxyModel::rowsRemoved, this , &LayersProxyModel::countChanged );
21-
22- updateFilterFunction ();
19+ QObject::connect ( this , &RecordingLayersProxyModel::rowsInserted, this , &RecordingLayersProxyModel::countChanged );
20+ QObject::connect ( this , &RecordingLayersProxyModel::rowsRemoved, this , &RecordingLayersProxyModel::countChanged );
2321}
2422
25- bool LayersProxyModel ::filterAcceptsRow ( int source_row, const QModelIndex &source_parent ) const
23+ bool RecordingLayersProxyModel ::filterAcceptsRow ( int source_row, const QModelIndex &source_parent ) const
2624{
2725 if ( !QgsMapLayerProxyModel::filterAcceptsRow ( source_row, source_parent ) )
2826 return false ;
@@ -31,10 +29,10 @@ bool LayersProxyModel::filterAcceptsRow( int source_row, const QModelIndex &sour
3129 QModelIndex index = mModel ->index ( source_row, 0 , source_parent );
3230 QgsMapLayer *layer = mModel ->layerFromIndex ( index );
3331
34- return filterFunction ( layer );
32+ return mModel -> data ( index, LayersModel::LayerVisible ). toBool ( );
3533}
3634
37- QList<QgsMapLayer *> LayersProxyModel ::layers () const
35+ QList<QgsMapLayer *> RecordingLayersProxyModel ::layers () const
3836{
3937 QList<QgsMapLayer *> filteredLayers;
4038
@@ -52,12 +50,12 @@ QList<QgsMapLayer *> LayersProxyModel::layers() const
5250 return filteredLayers;
5351}
5452
55- void LayersProxyModel ::refreshData ()
53+ void RecordingLayersProxyModel ::refreshData ()
5654{
5755 invalidate ();
5856}
5957
60- QgsMapLayer *LayersProxyModel ::firstUsableLayer () const
58+ QgsMapLayer *RecordingLayersProxyModel ::firstUsableLayer () const
6159{
6260 QList<QgsMapLayer *> filteredLayers = layers ();
6361
@@ -69,7 +67,7 @@ QgsMapLayer *LayersProxyModel::firstUsableLayer() const
6967 return nullptr ;
7068}
7169
72- QModelIndex LayersProxyModel ::indexFromLayerId ( QString layerId ) const
70+ QModelIndex RecordingLayersProxyModel ::indexFromLayerId ( QString layerId ) const
7371{
7472 if ( layerId.isEmpty () )
7573 return QModelIndex ();
@@ -79,7 +77,7 @@ QModelIndex LayersProxyModel::indexFromLayerId( QString layerId ) const
7977 return mModel ->indexFromLayer ( layer ); // return source model index to skip converting indexes in proxy model
8078}
8179
82- QgsVectorLayer *LayersProxyModel ::layerFromLayerId ( QString layerId ) const
80+ QgsVectorLayer *RecordingLayersProxyModel ::layerFromLayerId ( QString layerId ) const
8381{
8482 QList<QgsMapLayer *> filteredLayers = layers ();
8583
@@ -95,7 +93,7 @@ QgsVectorLayer *LayersProxyModel::layerFromLayerId( QString layerId ) const
9593 return nullptr ;
9694}
9795
98- QgsVectorLayer *LayersProxyModel ::layerFromLayerName ( const QString &layerName ) const
96+ QgsVectorLayer *RecordingLayersProxyModel ::layerFromLayerName ( const QString &layerName ) const
9997{
10098 QList<QgsMapLayer *> filteredLayers = layers ();
10199
@@ -111,76 +109,23 @@ QgsVectorLayer *LayersProxyModel::layerFromLayerName( const QString &layerName )
111109 return nullptr ;
112110}
113111
114- QVariant LayersProxyModel ::getData ( QModelIndex index, int role ) const
112+ QVariant RecordingLayersProxyModel ::getData ( QModelIndex index, int role ) const
115113{
116114 return sourceModel ()->data ( index, role );
117115}
118116
119- QgsProject *LayersProxyModel::qgsProject () const
120- {
121- return mProject ;
122- }
123-
124- void LayersProxyModel::setQgsProject ( QgsProject *project )
125- {
126- if ( mProject != project )
127- {
128- mProject = project;
129- emit qgsProjectChanged ();
130- }
131- }
132-
133- LayersProxyModel::LayerModelTypes LayersProxyModel::modelType () const
134- {
135- return mModelType ;
136- }
137-
138- void LayersProxyModel::setModelType ( LayerModelTypes type )
139- {
140- if ( mModelType != type )
141- {
142- mModelType = type;
143-
144- updateFilterFunction ();
145-
146- emit modelTypeChanged ();
147- }
148- }
149-
150- LayersModel *LayersProxyModel::model () const
117+ LayersModel *RecordingLayersProxyModel::model () const
151118{
152119 return mModel ;
153120}
154121
155- void LayersProxyModel ::setModel ( LayersModel *model )
122+ void RecordingLayersProxyModel ::setModel ( LayersModel *model )
156123{
157124 if ( mModel != model )
158125 {
159126 mModel = model;
160127 setSourceModel ( mModel );
128+ setFilters ( Qgis::LayerFilter::HasGeometry | Qgis::LayerFilter::WritableLayer );
161129 emit modelChanged ();
162130 }
163131}
164-
165- void LayersProxyModel::updateFilterFunction ()
166- {
167- beginResetModel ();
168-
169- switch ( mModelType )
170- {
171- case ActiveLayerSelection:
172- filterFunction = [this ]( QgsMapLayer * layer )
173- {
174- return InputUtils::recordingAllowed ( layer, mProject );
175- };
176- break ;
177- default :
178- filterFunction = []( QgsMapLayer * )
179- {
180- return true ;
181- };
182- break ;
183- }
184-
185- endResetModel ();
186- }
0 commit comments