• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MerginMaps / input / 6422038473

05 Oct 2023 04:51PM UTC coverage: 62.265% (+0.4%) from 61.9%
6422038473

push

github

web-flow
Remove subscription pages for iOS and call-to-actions (#2835)

* remove subscription pages for ios and call-to-actions

* bring back button to account page to get to the dashboard

* merge url params

7681 of 12336 relevant lines covered (62.26%)

105.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/app/layersproxymodel.cpp
1
/***************************************************************************
2
 *                                                                         *
3
 *   This program is free software; you can redistribute it and/or modify  *
4
 *   it under the terms of the GNU General Public License as published by  *
5
 *   the Free Software Foundation; either version 2 of the License, or     *
6
 *   (at your option) any later version.                                   *
7
 *                                                                         *
8
 ***************************************************************************/
9

10
#include "qgsvectorlayer.h"
11
#include "layersproxymodel.h"
12

13
#include "qgsproject.h"
14
#include "qgslayertree.h"
15

16
LayersProxyModel::LayersProxyModel( LayersModel *model, LayerModelTypes modelType ) :
22✔
17
  mModelType( modelType ),
22✔
18
  mModel( model )
22✔
19
{
20
  setSourceModel( mModel );
22✔
21

22
  switch ( mModelType )
22✔
23
  {
24
    case ActiveLayerSelection:
22✔
25
      filterFunction = [this]( QgsMapLayer * layer ) { return recordingAllowed( layer ); };
177✔
26
      break;
22✔
27
    default:
×
28
      filterFunction = []( QgsMapLayer * ) { return true; };
×
29
      break;
×
30
  }
31
}
22✔
32

33
bool LayersProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
113✔
34
{
35
  if ( !QgsMapLayerProxyModel::filterAcceptsRow( source_row, source_parent ) )
113✔
36
    return false;
×
37

38
  // get layer from row and parent index
39
  QModelIndex index = mModel->index( source_row, 0, source_parent );
113✔
40
  QgsMapLayer *layer = mModel->layerFromIndex( index );
113✔
41

42
  return filterFunction( layer );
113✔
43
}
44

45
bool layerHasGeometry( const QgsVectorLayer *layer )
146✔
46
{
47
  if ( !layer || !layer->isValid() )
146✔
48
    return false;
×
49
  return layer->wkbType() != Qgis::WkbType::NoGeometry && layer->wkbType() != Qgis::WkbType::Unknown;
146✔
50
}
51

52
bool LayersProxyModel::recordingAllowed( QgsMapLayer *layer ) const
155✔
53
{
54
  if ( !layer || !layer->isValid() )
155✔
55
    return false;
4✔
56

57
  QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layer );
151✔
58
  return ( vectorLayer && !vectorLayer->readOnly() && layerHasGeometry( vectorLayer ) && layerVisible( layer ) );
151✔
59
}
60

61
bool LayersProxyModel::layerVisible( QgsMapLayer *layer ) const
121✔
62
{
63
  QgsLayerTree *root = QgsProject::instance()->layerTreeRoot();
121✔
64
  QgsLayerTreeLayer *layerTree = root->findLayer( layer );
121✔
65

66
  if ( layerTree )
121✔
67
    return layerTree->isVisible();
117✔
68

69
  return false;
4✔
70
}
71

72
QList<QgsMapLayer *> LayersProxyModel::layers() const
8✔
73
{
74
  QList<QgsMapLayer *> filteredLayers;
8✔
75

76
  if ( !mModel )
8✔
77
    return filteredLayers;
×
78

79
  QList<QgsMapLayer *> allLayers = mModel->layers();
8✔
80
  int layersCount = allLayers.size();
8✔
81

82
  for ( int i = 0; i < layersCount; i++ )
50✔
83
  {
84
    if ( filterFunction( allLayers.at( i ) ) )
42✔
85
      filteredLayers << allLayers.at( i );
32✔
86
  }
87
  return filteredLayers;
8✔
88
}
8✔
89

90
void LayersProxyModel::refreshData()
4✔
91
{
92
  invalidate();
4✔
93
}
4✔
94

95
QgsMapLayer *LayersProxyModel::firstUsableLayer() const
4✔
96
{
97
  QList<QgsMapLayer *> filteredLayers = layers();
4✔
98

99
  if ( filteredLayers.size() > 0 )
4✔
100
  {
101
    return filteredLayers.at( 0 );
4✔
102
  }
103

104
  return nullptr;
×
105
}
4✔
106

107
QModelIndex LayersProxyModel::indexFromLayerId( QString layerId ) const
×
108
{
109
  if ( layerId.isEmpty() )
×
110
    return QModelIndex();
×
111

112
  QgsVectorLayer *layer = layerFromLayerId( layerId );
×
113

114
  return mModel->indexFromLayer( layer ); // return source model index to skip converting indexes in proxy model
×
115
}
116

117
QgsVectorLayer *LayersProxyModel::layerFromLayerId( QString layerId ) const
×
118
{
119
  QList<QgsMapLayer *> filteredLayers = layers();
×
120

121
  for ( int i = 0; i < filteredLayers.count(); i++ )
×
122
  {
123
    if ( filteredLayers.at( i )->id() == layerId )
×
124
    {
125
      QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( filteredLayers.at( i ) );
×
126
      if ( layer )
×
127
        return layer;
×
128
    }
129
  }
130
  return nullptr;
×
131
}
×
132

133
QgsVectorLayer *LayersProxyModel::layerFromLayerName( const QString &layerName ) const
4✔
134
{
135
  QList<QgsMapLayer *> filteredLayers = layers();
4✔
136

137
  for ( int i = 0; i < filteredLayers.count(); i++ )
20✔
138
  {
139
    if ( filteredLayers.at( i )->name() == layerName )
16✔
140
    {
141
      QgsVectorLayer *layer = qobject_cast<QgsVectorLayer *>( filteredLayers.at( i ) );
×
142
      if ( layer )
×
143
        return layer;
×
144
    }
145
  }
146
  return nullptr;
4✔
147
}
4✔
148

149
QVariant LayersProxyModel::getData( QModelIndex index, int role ) const
×
150
{
151
  return sourceModel()->data( index, role );
×
152
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc