• 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

29.46
/app/attributes/attributeformmodel.cpp
1
/***************************************************************************
2
 attributeformmodel.cpp
3
  --------------------------------------
4
  Date                 : 20.4.2021
5
  Copyright            : (C) 2021 by Peter Petrik
6
  Email                : zilolv@gmail.com
7
 ***************************************************************************
8
 *                                                                         *
9
 *   This program is free software; you can redistribute it and/or modify  *
10
 *   it under the terms of the GNU General Public License as published by  *
11
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 *   (at your option) any later version.                                   *
13
 *                                                                         *
14
 ***************************************************************************/
15

16
#include "attributeformmodel.h"
17
#include "attributecontroller.h"
18
#include "attributedata.h"
19

20
AttributeFormModel::AttributeFormModel( QObject *parent, AttributeController *controller, const QVector<QUuid> &data )
19✔
21
  : QAbstractListModel( parent )
22
  , mController( controller )
19✔
23
  , mData( data )
19✔
24
{
25
  Q_ASSERT( mController );
19✔
26
  connect( mController, &AttributeController::formDataChanged, this, &AttributeFormModel::onFormDataChanged );
19✔
27
  connect( mController, &AttributeController::featureLayerPairChanged, this, &AttributeFormModel::onFeatureChanged );
19✔
28
}
19✔
29

30
AttributeFormModel::~AttributeFormModel() = default;
38✔
31

32
int AttributeFormModel::rowCount( const QModelIndex &parent ) const
696✔
33
{
34
  Q_UNUSED( parent )
35
  return mData.size();
696✔
36
}
37

38
QVariant AttributeFormModel::data( const QModelIndex &index, int role ) const
354✔
39
{
40
  Q_ASSERT( mController );
354✔
41
  if ( !index.isValid() )
354✔
42
    return QVariant();
×
43

44
  const int row = index.row();
354✔
45
  if ( !rowIsValid( row ) )
354✔
46
    return QVariant();
×
47

48
  const QUuid uuid = mData[row];
354✔
49
  const FormItem *item = mController->formItem( uuid );
354✔
50
  if ( !item )
354✔
51
    return QVariant();
×
52

53
  switch ( role )
354✔
54
  {
55
    case Name:
×
56
      return item->name();
×
57
    case Type:
×
58
      return item->type();
×
59
    case AttributeValue:
×
60
      return mController->formValue( item->fieldIndex() );
×
61
    case RawValueIsNull:
×
62
      return item->rawValue().isNull();
×
63
    case AttributeEditable:
×
64
      return item->isEditable();
×
65
    case AttributeFormModel::EditorWidget:
×
66
      return item->editorWidgetType();
×
67
    case AttributeFormModel::EditorWidgetConfig:
×
68
      return item->editorWidgetConfig();
×
69
    case AttributeFormModel::RememberValue:
×
70
      return mController->formShouldRememberValue( item->fieldIndex() );
×
71
    case AttributeFormModel::Field:
×
72
      return item->field();
×
73
    case FieldIndex:
×
74
      return item->fieldIndex();
×
75
    case AttributeFormModel::Group:
×
76
      return item->groupName();
×
77
    case Visible:
354✔
78
      return item->isVisible();
354✔
79
    case ValidationMessage:
×
80
      return item->validationMessage();
×
81
    case ValidationStatus:
×
82
      return item->validationStatus();
×
83
    case Relation:
×
84
      return QVariant::fromValue( item->relation() );
×
85
    case RawValue:
×
86
      return item->rawValue();
×
87
    default:
×
88
      return QVariant();
×
89
  }
90
}
91

92
void AttributeFormModel::onFormDataChanged( const QUuid id, const QVector<int> roles )
223✔
93
{
94
  const int row = mData.indexOf( id );
223✔
95
  if ( rowIsValid( row ) )
223✔
96
  {
97
    const QModelIndex modelIndex = index( row, 0 );
223✔
98
    emit dataChanged( modelIndex, modelIndex, roles );
223✔
99
  }
100
}
223✔
101

102
void AttributeFormModel::onFeatureChanged()
26✔
103
{
104
  if ( rowCount() > 0 )
26✔
105
    emit dataChanged( index( 0, 0 ), index( rowCount() - 1, 0 ) );
25✔
106
}
26✔
107

108
bool AttributeFormModel::rowIsValid( int row ) const
577✔
109
{
110
  return ( row >= 0 ) && ( row < mData.size() );
577✔
111
}
112

113
QHash<int, QByteArray> AttributeFormModel::roleNames() const
×
114
{
115
  QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
×
116

117
  roles[Type] = QByteArray( "Type" );
×
118
  roles[Name] = QByteArray( "Name" );
×
119
  roles[AttributeValue] = QByteArray( "AttributeValue" );
×
120
  roles[RawValueIsNull] = QByteArray( "RawValueIsNull" );
×
121
  roles[AttributeEditable] = QByteArray( "AttributeEditable" );
×
122
  roles[EditorWidget] = QByteArray( "EditorWidget" );
×
123
  roles[EditorWidgetConfig] = QByteArray( "EditorWidgetConfig" );
×
124
  roles[RememberValue] = QByteArray( "RememberValue" );
×
125
  roles[AttributeFormModel::Field] = QByteArray( "Field" );
×
126
  roles[AttributeFormModel::Group] = QByteArray( "Group" );
×
127
  roles[ValidationMessage] = QByteArray( "ValidationMessage" );
×
128
  roles[ValidationStatus] = QByteArray( "ValidationStatus" );
×
129
  roles[Relation] = QByteArray( "Relation" );
×
130
  roles[RawValue] = QByteArray( "RawValue" );
×
131

132
  return roles;
×
133
}
×
134

135
Qt::ItemFlags AttributeFormModel::flags( const QModelIndex &index ) const
×
136
{
137
  const int row = index.row();
×
138
  if ( !rowIsValid( row ) )
×
139
  {
140
    return Qt::ItemFlags();
×
141
  }
142

143
  Qt::ItemFlags ret = Qt::ItemIsEnabled;
×
144
  const QUuid uuid = mData[row];
×
145
  const FormItem *item = mController->formItem( uuid );
×
146
  if ( item && item->isEditable() )
×
147
    ret |= Qt::ItemIsEditable;
×
148

149
  return ret;
×
150
}
151

152
bool AttributeFormModel::setData( const QModelIndex &index, const QVariant &value, int role )
×
153
{
154
  const int row = index.row();
×
155
  if ( !rowIsValid( row ) )
×
156
  {
157
    return false;
×
158
  }
159
  const QUuid uuid = mData[row];
×
160

161
  switch ( role )
×
162
  {
163
    case RememberValue:
×
164
    {
165
      bool shouldRememberValue = value.toBool();
×
166
      return mController->setFormShouldRememberValue( uuid, shouldRememberValue );
×
167
    }
168

169
    case AttributeValue:
×
170
    {
171
      const FormItem *item = mController->formItem( uuid );
×
172
      //if ( mController->formValue( item->fieldIndex() ) == value )
173
      if ( item->rawValue() == value )
×
174
      {
175
        return false;
×
176
      }
177
      return mController->setFormValue( uuid, value );
×
178
    }
179

180
    default:
×
181
      return false;
×
182
  }
183
}
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