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

MerginMaps / input / 6690232974

30 Oct 2023 08:34AM UTC coverage: 62.205% (-0.04%) from 62.243%
6690232974

Pull #2882

github

wonder-sk
code style
Pull Request #2882: Download data in parallel during sync

7686 of 12356 relevant lines covered (62.2%)

105.07 hits per line

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

57.32
/app/relationfeaturesmodel.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 "relationfeaturesmodel.h"
11
#include "qgsvectorlayer.h"
12
#include "inpututils.h"
13

14
#include "qgsproject.h"
15

16
RelationFeaturesModel::RelationFeaturesModel( QObject *parent )
2✔
17
  : FeaturesModel( parent )
2✔
18
{
19
}
2✔
20

21
QVariant RelationFeaturesModel::data( const QModelIndex &index, int role ) const
1✔
22
{
23
  int row = index.row();
1✔
24
  if ( row < 0 || row >= FeaturesModel::rowCount() )
1✔
25
    return QVariant();
×
26

27
  if ( !index.isValid() )
1✔
28
    return QVariant();
×
29

30
  if ( role == PhotoPath )
1✔
31
  {
32
    const FeatureLayerPair pair = FeaturesModel::data( index, FeaturesModel::FeaturePair ).value<FeatureLayerPair>();
×
33
    return relationPhotoPath( pair );
×
34
  }
×
35
  else
36
    return FeaturesModel::data( index, role );
1✔
37
}
38

39
QHash<int, QByteArray> RelationFeaturesModel::roleNames() const
×
40
{
41
  QHash<int, QByteArray> roles = FeaturesModel::roleNames();
×
42
  roles[PhotoPath] = QStringLiteral( "PhotoPath" ).toLatin1();
×
43

44
  return roles;
×
45
}
×
46

47
void RelationFeaturesModel::setup()
3✔
48
{
49
  if ( !mRelation.isValid() || !mParentFeatureLayerPair.isValid() )
3✔
50
    return;
2✔
51

52
  setIsTextType( photoFieldIndex( mRelation.referencingLayer() ) == -1 );
1✔
53

54
  QObject::connect( mRelation.referencingLayer(), &QgsVectorLayer::afterCommitChanges, this, &RelationFeaturesModel::populate );
1✔
55

56
  FeaturesModel::setLayer( mRelation.referencingLayer() );
1✔
57
  populate();
1✔
58
}
59

60
void RelationFeaturesModel::setupFeatureRequest( QgsFeatureRequest &request )
7✔
61
{
62
  FeaturesModel::setupFeatureRequest( request );
7✔
63

64
  QgsFeatureRequest e = mRelation.getRelatedFeaturesRequest( mParentFeatureLayerPair.feature() );
7✔
65
  request.combineFilterExpression( e.filterExpression()->operator QString() );
7✔
66
}
7✔
67

68
void RelationFeaturesModel::setParentFeatureLayerPair( FeatureLayerPair pair )
2✔
69
{
70
  if ( mParentFeatureLayerPair == pair )
2✔
71
    return;
×
72

73
  mParentFeatureLayerPair = pair;
2✔
74
  emit parentFeatureLayerPairChanged( mParentFeatureLayerPair );
2✔
75

76
  if ( !InputUtils::isFeatureIdValid( pair.feature().id() ) )
2✔
77
  {
78
    //
79
    // Clear the model in case parent feature has invalid id (e.g. is new) and do not populate it
80
    //
81

82
    beginResetModel();
1✔
83
    reset();
1✔
84
    endResetModel();
1✔
85
  }
86
  else
87
  {
88
    setup();
1✔
89
  }
90
}
91

92
void RelationFeaturesModel::setRelation( QgsRelation relation )
2✔
93
{
94
  if ( mRelation.id() != relation.id() )
2✔
95
  {
96
    mRelation = relation;
2✔
97
    emit relationChanged( mRelation );
2✔
98

99
    setup();
2✔
100
  }
101
}
2✔
102

103
FeatureLayerPair RelationFeaturesModel::parentFeatureLayerPair() const
×
104
{
105
  return mParentFeatureLayerPair;
×
106
}
107

108
QgsRelation RelationFeaturesModel::relation() const
×
109
{
110
  return mRelation;
×
111
}
112

113
QVariant RelationFeaturesModel::relationPhotoPath( const FeatureLayerPair &featurePair ) const
×
114
{
115
  // Feature title used to get path of the referenced image.
116
  QString path = featureTitle( featurePair ).toString();
×
117

118
  int fieldIndex = photoFieldIndex( featurePair.layer() );
×
119
  QgsEditorWidgetSetup setup = featurePair.layer()->editorWidgetSetup( fieldIndex );
×
120
  QVariantMap config = setup.config();
×
121

122
  QString finalPath = InputUtils::resolvePath( path, homePath(), config, featurePair, QgsProject::instance() );
×
123

124
  return QVariant( finalPath );
×
125
}
×
126

127
int RelationFeaturesModel::photoFieldIndex( QgsVectorLayer *layer ) const
1✔
128
{
129

130
  QgsFields fields = layer->fields();
1✔
131
  for ( int i = 0; i < fields.size(); i++ )
5✔
132
  {
133
    // Lets try by widget type
134
    QgsEditorWidgetSetup setup = layer->editorWidgetSetup( i );
4✔
135
    if ( setup.type() == QStringLiteral( "ExternalResource" ) )
4✔
136
    {
137
      return i;
×
138
    }
139
  }
4✔
140
  return -1;
1✔
141
}
1✔
142

143
bool RelationFeaturesModel::isTextType() const
×
144
{
145
  return mIsTextType;
×
146
}
147

148
void RelationFeaturesModel::setIsTextType( bool isTextType )
1✔
149
{
150
  if ( isTextType != mIsTextType )
1✔
151
  {
152
    mIsTextType = isTextType;
×
153
    emit isTextTypeChanged();
×
154
  }
155
}
1✔
156

157
QString RelationFeaturesModel::homePath() const
×
158
{
159
  return mHomePath;
×
160
}
161

162
void RelationFeaturesModel::setHomePath( const QString &homePath )
×
163
{
164
  if ( homePath != mHomePath )
×
165
  {
166
    mHomePath = homePath;
×
167
    emit homePathChanged();
×
168
  }
169
}
×
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