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

graphia-app / graphia / 42082325281

05 Nov 2026 06:13PM UTC coverage: 71.439% (+0.08%) from 71.364%
42082325281

push

github

timangus
Use QCustomPlot's split sources from its repository

11786 of 18050 branches covered (65.3%)

Branch coverage included in aggregate %.

30011 of 40457 relevant lines covered (74.18%)

300661.03 hits per line

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

87.44
/source/app/transform/graphtransform.cpp
1
/* Copyright © 2013-2025 Tim Angus
2
 * Copyright © 2013-2025 Tom Freeman
3
 *
4
 * This file is part of Graphia.
5
 *
6
 * Graphia is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Graphia is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with Graphia.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19

20
#include "graphtransform.h"
21

22
#include "transformedgraph.h"
23

24
#include "app/graph/graphmodel.h"
25

26
#include <QMetaType>
27
#include <QObject>
28
#include <QStringList>
29

30
#include <algorithm>
31

32
using namespace Qt::Literals::StringLiterals;
33

34
static bool hasUnknownAttributes(const std::vector<QString>& attributeNames,
35
    const GraphModel& graphModel, const GraphTransform& transform)
36
{
1,164 ✔
37
    bool unknownAttributes = false;
1,164 ✔
38

39
    for(const auto& attributeName : attributeNames)
1,164 ✔
40
    {
1,052 ✔
41
        if(!graphModel.attributeExists(attributeName))
1,052 ✔
42
        {
4 ✔
43
            transform.addAlert(AlertType::Error, QObject::tr(R"(Unknown Attribute: "%1")").arg(attributeName));
4 ✔
44
            unknownAttributes = true;
4 ✔
45
        }
4 ✔
46
    }
1,052 ✔
47

48
    return unknownAttributes;
1,164 ✔
49
}
1,164 ✔
50

51
static bool hasInvalidAttributes(const std::vector<QString>& attributeNames,
52
    const GraphModel& graphModel, const GraphTransform& transform)
53
{
1,160 ✔
54
    const bool invalidAttributes = std::ranges::any_of(attributeNames,
1,160 ✔
55
    [&graphModel](const auto& attributeName)
1,160 ✔
56
    {
1,160 ✔
57
        return !graphModel.attributeIsValid(attributeName);
1,048 ✔
58
    });
1,048 ✔
59

60
    if(invalidAttributes)
1,160 !
61
    {
×
62
        transform.addAlert(AlertType::Error, QObject::tr("One or more invalid attributes"));
×
63
        return true;
×
64
    }
×
65

66
    return false;
1,160 ✔
67
}
1,160 ✔
68

69
bool GraphTransform::applyAndUpdate(TransformedGraph& target, const GraphModel& graphModel)
70
{
1,164 ✔
71
    bool anyChange = false;
1,164 ✔
72
    bool change = false;
1,164 ✔
73

74
    do
1,164 ✔
75
    {
1,164 ✔
76
        target.resetChangeOccurred({});
1,164 ✔
77
        clearPhase();
1,164 ✔
78

79
        auto attributeNames = config().referencedAttributeNames();
1,164 ✔
80

81
        if(hasUnknownAttributes(attributeNames, graphModel, *this))
1,164 ✔
82
            continue;
4 ✔
83

84
        if(hasInvalidAttributes(attributeNames, graphModel, *this))
1,160 !
85
            continue;
×
86

87
        apply(target);
1,160 ✔
88
        target.update();
1,160 ✔
89
        change = target.changeOccurred({});
1,160 ✔
90
        anyChange = anyChange || change;
1,160 !
91
    } while(repeating() && change && !cancelled());
1,164 !
92

93
    return anyChange;
×
94
}
1,164 ✔
95

96
void GraphTransform::setProgressable(Progressable* progressable)
97
{
2,334 ✔
98
    _progressable = progressable;
2,334 ✔
99
}
2,334 ✔
100

101
void GraphTransform::setProgress(int percent)
102
{
18,897 ✔
103
    if(_progressable != nullptr)
18,897 ✔
104
        _progressable->setProgress(percent);
2,433 ✔
105
}
18,897 ✔
106

107
void GraphTransform::setPhase(const QString& phase)
108
{
5,344 ✔
109
    if(_progressable != nullptr)
5,344 ✔
110
        _progressable->setPhase(phase);
2,956 ✔
111
}
5,344 ✔
112

113
QString GraphTransformFactory::image() const
114
{
62 ✔
115
    switch(category())
62 ✔
116
    {
62 ✔
117
    case Category::Attributes:      return u"qrc:///transforms/images/attributes.svg"_s;
14 ✔
118
    case Category::Clustering:      return u"qrc:///transforms/images/clustering.svg"_s;
6 ✔
119
    case Category::EdgeReduction:   return u"qrc:///transforms/images/edgereduction.svg"_s;
8 ✔
120
    case Category::Filters:         return u"qrc:///transforms/images/filters.svg"_s;
14 ✔
121
    case Category::Metrics:         return u"qrc:///transforms/images/metrics.svg"_s;
8 ✔
122
    case Category::Structural:      return u"qrc:///transforms/images/structural.svg"_s;
12 ✔
123
    default: break;
×
124
    }
62 ✔
125

126
    return u"qrc:///transforms/images/default.svg"_s;
×
127
}
62 ✔
128

129
QString GraphTransformFactory::categoryDisplayName() const
130
{
60 ✔
131
    switch(category())
60 ✔
132
    {
60 ✔
133
    case Category::Attributes:      return QObject::tr("Attributes");
14 ✔
134
    case Category::Clustering:      return QObject::tr("Clustering");
6 ✔
135
    case Category::EdgeReduction:   return QObject::tr("Edge Reduction");
6 ✔
136
    case Category::Filters:         return QObject::tr("Filters");
12 ✔
137
    case Category::Metrics:         return QObject::tr("Metrics");
10 ✔
138
    case Category::Structural:      return QObject::tr("Structural");
12 ✔
139
    default: break;
×
140
    }
60 ✔
141

142
    return {};
×
143
}
60 ✔
144

145
GraphTransformAttributeParameter GraphTransformFactory::attributeParameter(const QString& parameterName) const
146
{
2 ✔
147
    const auto& p = attributeParameters();
2 ✔
148
    auto it = std::ranges::find_if(p,
2 ✔
149
    [&parameterName](const auto& attributeParameter)
2 ✔
150
    {
2 ✔
151
        return attributeParameter.name() == parameterName;
2 ✔
152
    });
2 ✔
153

154
    if(it != p.end())
2 !
155
        return *it;
2 ✔
156

157
    return {};
×
158
}
2 ✔
159

160
GraphTransformParameter GraphTransformFactory::parameter(const QString& parameterName) const
161
{
80 ✔
162
    const auto& p = parameters();
80 ✔
163
    auto it = std::ranges::find_if(p,
80 ✔
164
    [&parameterName](const auto& parameter)
80 ✔
165
    {
86 ✔
166
        return parameter.name() == parameterName;
86 ✔
167
    });
86 ✔
168

169
    if(it != p.end())
80 ✔
170
        return *it;
60 ✔
171

172
    return {};
20 ✔
173
}
80 ✔
174

175
void GraphTransformFactory::setMissingParametersToDefault(GraphTransformConfig& graphTransformConfig) const
176
{
1,140 ✔
177
    for(const auto& parameter : parameters())
1,140 ✔
178
    {
286 ✔
179
        if(!graphTransformConfig.hasParameter(parameter.name()))
286 ✔
180
        {
108 ✔
181
            const auto& v = parameter.initialValue();
108 ✔
182
            switch(v.typeId())
108 ✔
183
            {
108 ✔
184
            case QMetaType::Int:
16 ✔
185
                graphTransformConfig.setParameterValue(parameter.name(), v.toInt());
16 ✔
186
                break;
16 ✔
187

188
            case QMetaType::Double:
42 ✔
189
                graphTransformConfig.setParameterValue(parameter.name(), v.toDouble());
42 ✔
190
                break;
42 ✔
191

192
            case QMetaType::QString:
24 ✔
193
                graphTransformConfig.setParameterValue(parameter.name(), v.toString());
24 ✔
194
                break;
24 ✔
195

196
            case QMetaType::QStringList:
26 ✔
197
                graphTransformConfig.setParameterValue(parameter.name(), v.toStringList().constFirst());
26 ✔
198
                break;
26 ✔
199

200
            default:
×
201
                break;
×
202
            }
108 ✔
203
        }
108 ✔
204
    }
286 ✔
205
}
1,140 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc