• 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

75.82
/source/app/commands/applyvisualisationscommand.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 "applyvisualisationscommand.h"
21

22
#include "app/graph/graphmodel.h"
23
#include "app/ui/document.h"
24

25
#include "app/ui/visualisations/visualisationconfigparser.h"
26

27
#include "shared/utils/container.h"
28

29
#include <QObject>
30
#include <QSet>
31
#include <QtGlobal>
32

33
#include <utility>
34

35
using namespace Qt::Literals::StringLiterals;
36

37
ApplyVisualisationsCommand::ApplyVisualisationsCommand(GraphModel* graphModel,
38
                                                       Document* document,
39
                                                       QStringList previousVisualisations,
40
                                                       QStringList visualisations, int transformIndex) :
41
    _graphModel(graphModel),
24 ✔
42
    _document(document),
24 ✔
43
    _previousVisualisations(std::move(previousVisualisations)),
24 ✔
44
    _visualisations(std::move(visualisations)),
24 ✔
45
    _transformIndex(transformIndex)
24 ✔
46
{}
24 ✔
47

48
QString ApplyVisualisationsCommand::description() const
49
{
80 ✔
50
    return QObject::tr("Apply Visualisations");
80 ✔
51
}
80 ✔
52

53
QString ApplyVisualisationsCommand::verb() const
54
{
16 ✔
55
    return QObject::tr("Applying Visualisations");
16 ✔
56
}
16 ✔
57

58
QString ApplyVisualisationsCommand::debugDescription() const
59
{
×
60
    auto prev = QSet<QString>(_previousVisualisations.begin(), _previousVisualisations.end());
×
61
    auto diff = QSet<QString>(_visualisations.begin(), _visualisations.end());
×
62
    diff.subtract(prev);
×
63

64
    auto text = description();
×
65

66
    for(const auto& visualisation : std::as_const(diff))
×
67
        text.append(u"\n  %1"_s.arg(visualisation));
×
68

69
    return text;
×
70
}
×
71

72
void ApplyVisualisationsCommand::apply(const QStringList& visualisations,
73
                                       const QStringList& previousVisualisations)
74
{
32 ✔
75
    _graphModel->buildVisualisations(visualisations);
32 ✔
76

77
    _document->executeOnMainThreadAndWait(
32 ✔
78
    [this, newVisualisations = cancelled() ? previousVisualisations : visualisations]
32 ✔
79
    {
32 ✔
80
        _document->setVisualisations(newVisualisations);
32 ✔
81
    }, u"setVisualisations"_s);
32 ✔
82
}
32 ✔
83

84
QStringList ApplyVisualisationsCommand::patchedVisualisations(const QStringList& previousVisualisations,
85
    const QStringList& visualisations, const std::map<QString, QString>& assignedAttributeNames)
86
{
30 ✔
87
    if(assignedAttributeNames.empty())
30 ✔
88
        return visualisations;
6 ✔
89

90
    QStringList patched;
24 ✔
91
    patched.reserve(visualisations.size());
24 ✔
92

93
    for(int i = 0; i < visualisations.size(); i++)
64 ✔
94
    {
40 ✔
95
        const auto& visualisation = visualisations.at(i);
40 ✔
96

97
        if(i < previousVisualisations.size())
40 ✔
98
        {
12 ✔
99
            // Just pass through the visualisations that aren't new
100
            patched.append(visualisation);
12 ✔
101
            continue;
12 ✔
102
        }
12 ✔
103

104
        VisualisationConfigParser p;
28 ✔
105

106
        if(!p.parse(visualisation))
28 !
107
            continue;
×
108

109
        auto visualisationConfig = p.result();
28 ✔
110

111
        if(u::contains(assignedAttributeNames, visualisationConfig._attributeName))
28 ✔
112
            visualisationConfig._attributeName = assignedAttributeNames.at(visualisationConfig._attributeName);
26 ✔
113

114
        patched.append(visualisationConfig.asString());
28 ✔
115
    }
28 ✔
116

117
    return patched;
24 ✔
118
}
30 ✔
119

120
QStringList ApplyVisualisationsCommand::patchedVisualisations() const
121
{
32 ✔
122
    // When a transform creates an attribute whose name is already in use, it is given a unique
123
    // name (c.f. u::findUniqueName), so the visualisations added for it are patched to match
124
    if(_transformIndex >= 0 && _visualisations.size() > _previousVisualisations.size())
32 !
125
    {
12 ✔
126
        return patchedVisualisations(_previousVisualisations, _visualisations,
12 ✔
127
            _graphModel->assignedAttributeNamesAtTransformIndex(_transformIndex));
12 ✔
128
    }
12 ✔
129

130
    return _visualisations;
20 ✔
131
}
32 ✔
132

133
bool ApplyVisualisationsCommand::execute()
134
{
26 ✔
135
    apply(patchedVisualisations(), _previousVisualisations);
26 ✔
136
    return true;
26 ✔
137
}
26 ✔
138

139
void ApplyVisualisationsCommand::undo()
140
{
6 ✔
141
    apply(_previousVisualisations, patchedVisualisations());
6 ✔
142
}
6 ✔
143

144
void ApplyVisualisationsCommand::replaces(const ICommand* replacee)
145
{
×
146
    const auto* avcReplacee =
×
147
        dynamic_cast<const ApplyVisualisationsCommand*>(replacee);
×
148
    Q_ASSERT(avcReplacee != nullptr);
×
149

150
    _previousVisualisations = avcReplacee->_previousVisualisations;
×
151
}
×
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