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

MerginMaps / input / 6655250127

26 Oct 2023 02:02PM UTC coverage: 62.234% (-0.07%) from 62.308%
6655250127

push

github

web-flow
Merge pull request #2867 from MerginMaps/other_elems

HTML, Text, Spacer "other form widgets" + "show label"

7483 of 12024 relevant lines covered (62.23%)

122.83 hits per line

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

28.7
/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 )
20✔
21
  : QAbstractListModel( parent )
22
  , mController( controller )
20✔
23
  , mData( data )
20✔
24
{
25
  Q_ASSERT( mController );
20✔
26
  connect( mController, &AttributeController::formDataChanged, this, &AttributeFormModel::onFormDataChanged );
20✔
27
  connect( mController, &AttributeController::featureLayerPairChanged, this, &AttributeFormModel::onFeatureChanged );
20✔
28
}
20✔
29

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

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

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

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

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

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

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

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

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

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

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

135
  return roles;
×
136
}
×
137

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

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

152
  return ret;
×
153
}
154

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

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

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

183
    default:
×
184
      return false;
×
185
  }
186
}
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