Skip to content

Commit

Permalink
instantiating recording layers model from qml
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ committed Jan 14, 2025
1 parent 9acd0c4 commit 9370820
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
37 changes: 25 additions & 12 deletions app/layersproxymodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@
#include "qgslayertree.h"

LayersProxyModel::LayersProxyModel( QObject *parent ) :
QgsMapLayerProxyModel{ parent }
QgsMapLayerProxyModel{ parent },
filterFunction( []( QgsMapLayer * layer ) { return ( layer && layer->isValid() ); } ) // default filter
{
switch ( mModelType )
{
case ActiveLayerSelection:
filterFunction = [this]( QgsMapLayer * layer ) { return recordingAllowed( layer ); };
break;
default:
filterFunction = []( QgsMapLayer * ) { return true; };
break;
} //inherit 2 ocurrences from layer proxy model - layersProxyModel and recordingLayersProxyModel

QObject::connect( this, &LayersProxyModel::rowsInserted, this, &LayersProxyModel::countChanged );
QObject::connect( this, &LayersProxyModel::rowsRemoved, this, &LayersProxyModel::countChanged );
}
Expand Down Expand Up @@ -174,7 +165,7 @@ void LayersProxyModel::setQgsProject( QgsProject *project )
}
}

LayerModelTypes LayersProxyModel::modelType() const
LayersProxyModel::LayerModelTypes LayersProxyModel::modelType() const
{
return mModelType;
}
Expand All @@ -184,6 +175,9 @@ void LayersProxyModel::setModelType( LayerModelTypes type )
if ( mModelType != type )
{
mModelType = type;

applyFilterFunction();

emit modelTypeChanged();
}
}
Expand All @@ -202,3 +196,22 @@ void LayersProxyModel::setModel( LayersModel *model )
emit modelChanged();
}
}

void LayersProxyModel::applyFilterFunction()
{
switch ( mModelType )
{
case ActiveLayerSelection:
filterFunction = [this]( QgsMapLayer * layer )
{
return recordingAllowed( layer );
};
break;
default:
filterFunction = []( QgsMapLayer * )
{
return true;
};
break;
}
}
20 changes: 11 additions & 9 deletions app/layersproxymodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,23 @@

#include "layersmodel.h"

enum LayerModelTypes
{
AllLayers,
ActiveLayerSelection
};

class LayersProxyModel : public QgsMapLayerProxyModel
{
Q_OBJECT

Q_PROPERTY( int count READ rowCount NOTIFY countChanged )
Q_PROPERTY( QgsProject* qgsProject READ qgsProject WRITE setQgsProject NOTIFY qgsProjectChanged )
Q_PROPERTY( QgsProject *qgsProject READ qgsProject WRITE setQgsProject NOTIFY qgsProjectChanged )
Q_PROPERTY( LayerModelTypes modelType READ modelType WRITE setModelType NOTIFY modelTypeChanged )
Q_PROPERTY( LayersModel* model READ model WRITE setModel NOTIFY modelChanged )
Q_PROPERTY( LayersModel *model READ model WRITE setModel NOTIFY modelChanged )

public:
Q_INVOKABLE explicit LayersProxyModel( QObject *parent = nullptr );
Q_INVOKABLE explicit LayersProxyModel( QObject *parent = nullptr );

enum LayerModelTypes
{
AllLayers,
ActiveLayerSelection
};
Q_ENUM( LayerModelTypes );

bool filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const override;
Expand All @@ -63,6 +62,9 @@ class LayersProxyModel : public QgsMapLayerProxyModel
*/
QList<QgsMapLayer *> layers() const;

//! Filter current model according to its type
void applyFilterFunction();

//! Getters and setters

QgsProject *qgsProject() const;
Expand Down
2 changes: 1 addition & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void initDeclarative()
qmlRegisterType< SplittingMapTool >( "mm", 1, 0, "SplittingMapTool" );
qmlRegisterType< MeasurementMapTool >( "mm", 1, 0, "MeasurementMapTool" );

//qmlRegisterType<LayerModelTypes>( "mm", 1, 0, "LayerModelTypes" );
// layers model
qmlRegisterType<LayersProxyModel>( "mm", 1, 0, "LayersProxyModel" );
qmlRegisterType<LayersModel>( "mm", 1, 0, "LayersModel" );
}
Expand Down

1 comment on commit 9370820

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 25.1.698411 just submitted!

Please sign in to comment.