• 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

89.7
/source/app/loading/nativeloader.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 "nativeloader.h"
21

22
#include "nativeloader_legacy.h"
23
#include "nativesaver.h"
24

25
#include "app/application.h"
26
#include "app/graph/graphmodel.h"
27
#include "app/graph/mutablegraph.h"
28

29
#include "shared/graph/igraphmodel.h"
30
#include "shared/graph/grapharray_json.h"
31

32
#include "shared/plugins/iplugin.h"
33

34
#include "shared/utils/scope_exit.h"
35
#include "shared/utils/container.h"
36
#include "shared/utils/source_location.h"
37
#include "shared/utils/json.h"
38

39
#include "shared/loading/userelementdata.h"
40
#include "shared/loading/jsongraphparser.h"
41

42
#include <zlib.h>
43

44
#include <QDataStream>
45
#include <QDebug>
46
#include <QFile>
47
#include <QObject>
48
#include <QRegularExpression>
49
#include <QVector3D>
50
#include <QtGlobal>
51

52
#include <algorithm>
53
#include <cmath>
54
#include <cstdint>
55
#include <string>
56
#include <thread>
57

58
static bool isCompressed(const QString& filePath)
59
{
502 ✔
60
    QFile file(filePath);
502 ✔
61

62
    const int GzipHeaderSize = 10;
502 ✔
63
    if(!file.open(QIODevice::ReadOnly) || file.size() < GzipHeaderSize)
502 !
64
        return false;
12 ✔
65

66
    unsigned char header[GzipHeaderSize];
490 ✔
67

68
    if(file.read(reinterpret_cast<char*>(header), GzipHeaderSize) != GzipHeaderSize)
490 !
69
        return false;
×
70

71
    // Gzip magic number
72
    return header[0] == 0x1f && header[1] == 0x8b;
490 !
73
}
490 ✔
74

75
static bool decompress(const QString& filePath, QByteArray& byteArray,
76
                       int maxReadSize = -1, Loader* loader = nullptr)
77
{
92 ✔
78
    QFile file(filePath);
92 ✔
79

80
    if(!file.open(QIODevice::ReadOnly))
92 !
81
        return false;
×
82

83
    auto totalBytes = static_cast<uint64_t>(file.size());
92 ✔
84

85
    if(totalBytes == 0)
92 !
86
        return false;
×
87

88
    uint64_t bytesRead = 0;
92 ✔
89
    uint64_t bytesDecompressed = 0;
92 ✔
90
    QDataStream input(&file);
92 ✔
91

92
    z_stream zstream = {};
92 ✔
93
    auto ret = inflateInit2(&zstream, MAX_WBITS + 32); // 32 means read gzip header/trailer
92 ✔
94
    if(ret != Z_OK)
92 !
95
        return false;
×
96

97
    auto atExit = std::experimental::make_scope_exit([&zstream]
92 ✔
98
    {
92 ✔
99
       inflateEnd(&zstream);
92 ✔
100
    });
92 ✔
101

102
    do
92 ✔
103
    {
98 ✔
104
        const int ChunkSize = 1 << 14;
98 ✔
105
        std::vector<unsigned char> inBuffer(ChunkSize);
98 ✔
106

107
        auto numBytes = input.readRawData(reinterpret_cast<char*>(inBuffer.data()), ChunkSize);
98 ✔
108

109
        bytesRead += static_cast<uint64_t>(numBytes);
98 ✔
110

111
        if(loader != nullptr)
98 ✔
112
            loader->setProgress(static_cast<int>((bytesRead * 100u) / totalBytes));
36 ✔
113

114
        zstream.avail_in = static_cast<uInt>(numBytes);
98 ✔
115
        if(zstream.avail_in == 0)
98 ✔
116
            break;
4 ✔
117

118
        zstream.next_in = static_cast<z_const Bytef*>(inBuffer.data());
94 ✔
119

120
        do
94 ✔
121
        {
104 ✔
122
            std::vector<unsigned char> outBuffer(ChunkSize);
104 ✔
123
            zstream.avail_out = ChunkSize;
104 ✔
124
            zstream.next_out = static_cast<Bytef*>(outBuffer.data());
104 ✔
125

126
            ret = inflate(&zstream, Z_NO_FLUSH);
104 ✔
127
            Q_ASSERT(ret != Z_STREAM_ERROR);
104 !
128

129
            switch(ret)
104 ✔
130
            {
104 ✔
131
            case Z_NEED_DICT:
×
132
            case Z_DATA_ERROR:
4 ✔
133
            case Z_MEM_ERROR:
4 !
134
                return false;
4 ✔
135

136
            default: break;
100 ✔
137
            }
104 ✔
138

139
            numBytes = ChunkSize - static_cast<int>(zstream.avail_out);
100 ✔
140
            bytesDecompressed += static_cast<uint64_t>(numBytes);
100 ✔
141
            byteArray.append(reinterpret_cast<const char*>(outBuffer.data()), static_cast<qsizetype>(numBytes));
100 ✔
142

143
            // Check if we've read more than we've been asked to
144
            if(maxReadSize >= 0 && bytesDecompressed >= static_cast<uint64_t>(maxReadSize))
100 ✔
145
                return true;
8 ✔
146

147
        } while(zstream.avail_out == 0);
100 ✔
148
    } while(ret != Z_STREAM_END);
94 ✔
149

150
    return true;
80 ✔
151
}
92 ✔
152

153
static bool load(const QString& filePath, QByteArray& byteArray,
154
                 int maxReadSize = -1, Loader* loader = nullptr)
155
{
502 ✔
156
    if(isCompressed(filePath))
502 ✔
157
    {
92 ✔
158
        if(loader != nullptr)
92 ✔
159
            loader->setPhase(QObject::tr("Decompressing"));
32 ✔
160

161
        return decompress(filePath, byteArray, maxReadSize, loader);
92 ✔
162
    }
92 ✔
163

164
    QFile file(filePath);
410 ✔
165

166
    if(!file.open(QIODevice::ReadOnly))
410 !
167
        return false;
×
168

169
    auto totalBytes = file.size();
410 ✔
170

171
    if(totalBytes == 0)
410 ✔
172
        return false;
2 ✔
173

174
    decltype(totalBytes) bytesRead = 0;
408 ✔
175
    QDataStream input(&file);
408 ✔
176

177
    do
408 ✔
178
    {
408 ✔
179
        const int ChunkSize = 2 << 16;
408 ✔
180
        std::vector<unsigned char> buffer(ChunkSize);
408 ✔
181

182
        auto numBytes = input.readRawData(reinterpret_cast<char*>(buffer.data()), ChunkSize);
408 ✔
183
        byteArray.append(reinterpret_cast<char*>(buffer.data()), static_cast<qsizetype>(numBytes));
408 ✔
184

185
        bytesRead += numBytes;
408 ✔
186

187
        if(loader != nullptr)
408 ✔
188
            loader->setProgress(static_cast<int>((bytesRead * 100u) / totalBytes));
144 ✔
189

190
        // Check if we've read more than we've been asked to
191
        if(maxReadSize >= 0 && bytesRead >= maxReadSize)
408 !
192
            return true;
×
193

194
    } while(!input.atEnd());
408 !
195

196
    return true;
408 ✔
197
}
408 ✔
198

199
struct Header
200
{
201
    int _version = -1;
202
    QString _pluginName;
203
    int _pluginDataVersion = -1;
204
};
205

206
static bool parseHeader(const QUrl& url, Header* header = nullptr)
207
{
326 ✔
208
    if(!url.isLocalFile())
326 !
209
        return false;
×
210

211
    QByteArray byteArray;
326 ✔
212

213
    if(!load(url.toLocalFile(), byteArray, NativeSaver::MaxHeaderSize))
326 ✔
214
        return false;
6 ✔
215

216
    // byteArray now has a JSON fragment that hopefully includes the header
217
    QString fragment(byteArray);
320 ✔
218

219
    // Strip off the leading [
220
    static const QRegularExpression re(uR"(^\s*\[\s*)"_s);
320 ✔
221
    fragment.replace(re, {});
320 ✔
222

223
    int position = 0;
320 ✔
224
    int braceDepth = 0;
320 ✔
225
    bool inQuotes = false;
320 ✔
226
    bool escaping = false;
320 ✔
227
    for(auto character : fragment)
320 ✔
228
    {
28,846 ✔
229
        if(!escaping)
28,846 !
230
        {
28,846 ✔
231
            switch(character.toLatin1())
28,846 ✔
232
            {
28,846 ✔
233
            case '{': braceDepth++; break;
308 ✔
234
            case '}': braceDepth--; break;
308 ✔
235
            case '"': inQuotes = !inQuotes; break;
3,248 ✔
236
            case '\\': escaping = true; break;
×
237
            default: break;
24,982 ✔
238
            }
28,846 ✔
239
        }
28,846 ✔
240
        else
×
241
            escaping = false;
×
242

243
        position++;
28,846 ✔
244

245
        if(braceDepth == 0)
28,846 ✔
246
            break;
318 ✔
247
    }
28,846 ✔
248

249
    const QString headerString = fragment.left(position);
320 ✔
250
    auto headerByteArray = headerString.toUtf8();
320 ✔
251
    json jsonHeader = json::parse(headerByteArray.begin(), headerByteArray.end(), nullptr, false);
320 ✔
252

253
    if(jsonHeader.is_discarded() || jsonHeader.is_null() || !jsonHeader.is_object())
320 !
254
        return false;
24 ✔
255

256
    if(!u::contains(jsonHeader, "version") || !jsonHeader["version"].is_number_integer())
296 ✔
257
        return false;
8 ✔
258

259
    if(!u::contains(jsonHeader, "pluginName") || !jsonHeader["pluginName"].is_string())
288 !
260
        return false;
2 ✔
261

262
    if(!u::contains(jsonHeader, "pluginDataVersion") || !jsonHeader["pluginDataVersion"].is_number_integer())
286 !
263
        return false;
2 ✔
264

265
    if(header != nullptr)
284 !
266
    {
284 ✔
267
        header->_version            = jsonHeader["version"];
284 ✔
268
        header->_pluginName         = QString::fromStdString(jsonHeader["pluginName"]);
284 ✔
269
        header->_pluginDataVersion  = jsonHeader["pluginDataVersion"];
284 ✔
270
    }
284 ✔
271

272
    return true;
284 ✔
273
}
286 ✔
274

275
bool Loader::parse(const QUrl& url, IGraphModel* igraphModel)
276
{
188 ✔
277
    try
188 ✔
278
    {
188 ✔
279
        return parseNativeFile(url, igraphModel);
188 ✔
280
    }
188 ✔
281
    catch(const json::exception& e)
188 ✔
282
    {
188 ✔
283
        // A value isn't of the expected type
284
        setFailureReason(QObject::tr("Invalid content: %1").arg(QString::fromStdString(e.what())));
14 ✔
285
    }
14 ✔
286

287
    return false;
14 ✔
288
}
188 ✔
289

290
bool Loader::parseNativeFile(const QUrl& url, IGraphModel* igraphModel)
291
{
188 ✔
292
    auto* graphModel = dynamic_cast<GraphModel*>(igraphModel);
188 ✔
293

294
    Q_ASSERT(graphModel != nullptr);
188 !
295
    if(graphModel == nullptr)
188 !
296
        return false;
×
297

298
    Header header;
188 ✔
299
    if(!parseHeader(url, &header))
188 ✔
300
    {
10 ✔
301
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
10 ✔
302
        return false;
10 ✔
303
    }
10 ✔
304

305
    auto version = header._version;
178 ✔
306

307
    if(version > NativeSaver::Version)
178 ✔
308
    {
2 ✔
309
        setFailureReason(QObject::tr("It was saved using a newer version of %1. "
2 ✔
310
            "Please visit the %1 website to upgrade.")
2 ✔
311
            .arg(Application::name()));
2 ✔
312
        return false;
2 ✔
313
    }
2 ✔
314

315
    QByteArray byteArray;
176 ✔
316

317
    if(!load(url.toLocalFile(), byteArray, -1, this))
176 !
318
    {
×
319
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
×
320
        return false;
×
321
    }
×
322

323
    setProgress(-1);
176 ✔
324
    setPhase(QObject::tr("Parsing"));
176 ✔
325

326
    auto jsonArray = parseJsonFrom(byteArray, this);
176 ✔
327

328
    if(cancelled())
176 !
329
        return false;
×
330

331
    if(jsonArray.is_null() || !jsonArray.is_array())
176 !
332
    {
4 ✔
333
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
4 ✔
334
        return false;
4 ✔
335
    }
4 ✔
336

337
    if(jsonArray.size() != 2)
172 ✔
338
    {
2 ✔
339
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
340
        return false;
2 ✔
341
    }
2 ✔
342

343
    auto allObjects = std::ranges::all_of(jsonArray,
170 ✔
344
    [](const auto& i)
170 ✔
345
    {
340 ✔
346
       return i.is_object();
340 ✔
347
    });
340 ✔
348

349
    if(!allObjects)
170 ✔
350
    {
2 ✔
351
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
352
        return false;
2 ✔
353
    }
2 ✔
354

355
    auto jsonBody = jsonArray.at(1);
168 ✔
356
    upgradeLegacyFormat(jsonBody, version, *graphModel);
168 ✔
357

358
    if(u::contains(jsonBody, "infiniteParse"))
168 ✔
359
    {
2 ✔
360
        while(!cancelled())
4 ✔
361
        {
2 ✔
362
            using namespace std::chrono_literals;
2 ✔
363
            std::this_thread::sleep_for(1000ms);
2 ✔
364
        }
2 ✔
365

366
        return false;
2 ✔
367
    }
2 ✔
368

369
    if(!u::contains(jsonBody, "graph") || !jsonBody["graph"].is_object())
166 !
370
    {
2 ✔
371
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
372
        return false;
2 ✔
373
    }
2 ✔
374

375
    const auto& jsonGraph = jsonBody["graph"];
164 ✔
376

377
    if(!JsonGraphParser::parseGraphObject(jsonGraph, graphModel, *this, "useElementIdsLiterally"_yes))
164 ✔
378
        return false;
2 ✔
379

380
    setProgress(-1);
162 ✔
381

382
    if(u::contains(jsonBody, "nodeNames"))
162 !
383
    {
162 ✔
384
        u::forEachJsonGraphArray(jsonBody["nodeNames"], [graphModel](NodeId nodeId, const QString& nodeName)
162 ✔
385
        {
1,448 ✔
386
            if(graphModel->mutableGraph().containsNodeId(nodeId))
1,448 ✔
387
                graphModel->setNodeName(nodeId, nodeName);
1,446 ✔
388
        });
1,448 ✔
389
    }
162 ✔
390

391
    if(u::contains(jsonBody, "userNodeData") && jsonBody["userNodeData"].is_object())
162 !
392
    {
160 ✔
393
        if(!graphModel->userNodeData().load(jsonBody["userNodeData"], *this))
160 ✔
394
        {
2 ✔
395
            setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
396
            return false;
2 ✔
397
        }
2 ✔
398
    }
160 ✔
399

400
    if(u::contains(jsonBody, "userEdgeData") && jsonBody["userEdgeData"].is_object())
160 !
401
    {
158 ✔
402
        if(!graphModel->userEdgeData().load(jsonBody["userEdgeData"], *this))
158 ✔
403
        {
2 ✔
404
            setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
405
            return false;
2 ✔
406
        }
2 ✔
407
    }
158 ✔
408

409
    if(u::contains(jsonBody, "transforms"))
158 ✔
410
    {
156 ✔
411
        for(const auto& transform : jsonBody["transforms"])
156 ✔
412
            _transforms.append(QString::fromStdString(transform));
236 ✔
413
    }
156 ✔
414

415
    if(u::contains(jsonBody, "visualisations"))
158 ✔
416
    {
156 ✔
417
        for(const auto& visualisation : jsonBody["visualisations"])
156 ✔
418
            _visualisations.append(QString::fromStdString(visualisation));
54 ✔
419
    }
156 ✔
420

421
    if(u::contains(jsonBody, "projection"))
158 ✔
422
        _projection = jsonBody["projection"];
146 ✔
423

424
    if(u::contains(jsonBody, "2dshading"))
158 ✔
425
        _shading2D = jsonBody["2dshading"];
146 ✔
426

427
    if(u::contains(jsonBody, "3dshading"))
158 ✔
428
        _shading3D = jsonBody["3dshading"];
146 ✔
429

430
    if(u::contains(jsonBody, "bookmarks"))
158 ✔
431
    {
156 ✔
432
        const auto bookmarks = jsonBody["bookmarks"];
156 ✔
433
        for(auto bookmarkIt = bookmarks.begin(); bookmarkIt != bookmarks.end(); ++bookmarkIt)
206 ✔
434
        {
50 ✔
435
            const QString name = QString::fromStdString(bookmarkIt.key());
50 ✔
436
            const auto& array = bookmarkIt.value();
50 ✔
437

438
            if(array.is_array())
50 !
439
            {
50 ✔
440
                NodeIdSet nodeIds;
50 ✔
441

442
                for(const auto& nodeId : array)
50 ✔
443
                    nodeIds.insert(nodeId.get<int>());
102 ✔
444

445
                _bookmarks.insert({name, nodeIds});
50 ✔
446
            }
50 ✔
447
        }
50 ✔
448
    }
156 ✔
449

450
    if(u::contains(jsonBody, "log"))
158 ✔
451
        _log = QString::fromStdString(jsonBody["log"]);
154 ✔
452

453
    if(u::contains(jsonBody, "enrichmentTables"))
158 ✔
454
    {
50 ✔
455
        for(const auto& tableModel : jsonBody["enrichmentTables"])
50 ✔
456
        {
50 ✔
457
            auto& data = _enrichmentTableData.emplace_back();
50 ✔
458

459
            // If Data is empty then it's just an empty table
460
            if(u::contains(tableModel, "data"))
50 !
461
            {
50 ✔
462
                for(const auto& dataRow : tableModel["data"])
50 ✔
463
                {
108 ✔
464
                    if(dataRow.is_null())
108 !
465
                    {
×
466
                        qDebug() << "null dataRow in enrichment table";
×
467
                        continue;
×
468
                    }
×
469

470
                    if(dataRow.size() != EnrichmentTableModel::Results::NumResultColumns)
108 ✔
471
                    {
4 ✔
472
                        qDebug() << "enrichment table dataRow has the wrong number of values";
4 ✔
473
                        continue;
4 ✔
474
                    }
4 ✔
475

476
                    auto& row = data._table.emplace_back();
104 ✔
477
                    row.reserve(dataRow.size());
104 ✔
478

479
                    for(const auto& value : dataRow)
104 ✔
480
                    {
728 ✔
481
                        if(value.is_number())
728 ✔
482
                            row.emplace_back(value.get<std::double_t>());
504 ✔
483
                        else
224 ✔
484
                            row.emplace_back(QString::fromStdString(value.get<std::string>()));
224 ✔
485
                    }
728 ✔
486
                }
104 ✔
487
            }
50 ✔
488

489
            if(u::contains(tableModel, "selectionA"))
50 !
490
                data._selectionA = QString::fromStdString(tableModel["selectionA"]);
50 ✔
491

492
            if(u::contains(tableModel, "selectionB"))
50 !
493
                data._selectionB = QString::fromStdString(tableModel["selectionB"]);
50 ✔
494
        }
50 ✔
495
    }
50 ✔
496

497
    if(u::contains(jsonBody, "layout"))
158 ✔
498
    {
156 ✔
499
        const auto& jsonLayout = jsonBody["layout"];
156 ✔
500

501
        if(u::contains(jsonLayout, "algorithm"))
156 !
502
            _layoutName = QString::fromStdString(jsonLayout["algorithm"]);
156 ✔
503

504
        if(u::contains(jsonLayout, "settings"))
156 !
505
        {
156 ✔
506
            const auto settings = jsonLayout["settings"];
156 ✔
507
            for(auto settingsIt = settings.begin(); settingsIt != settings.end(); ++settingsIt)
392 ✔
508
            {
236 ✔
509
                const QString name = QString::fromStdString(settingsIt.key());
236 ✔
510
                const auto& value = settingsIt.value();
236 ✔
511

512
                if(value.is_number())
236 !
513
                    _layoutSettings.push_back({name, value});
236 ✔
514
            }
236 ✔
515
        }
156 ✔
516

517
        if(u::contains(jsonLayout, "positions"))
156 !
518
        {
156 ✔
519
            _nodePositions = std::make_unique<ExactNodePositions>(graphModel->mutableGraph());
156 ✔
520

521
            u::forEachJsonGraphArray(jsonLayout["positions"], [this, graphModel](NodeId nodeId, const json& position)
156 ✔
522
            {
1,426 ✔
523
                if(!graphModel->mutableGraph().containsNodeId(nodeId))
1,426 ✔
524
                    return;
2 ✔
525

526
                _nodePositions->set(nodeId, QVector3D(
1,424 ✔
527
                    position.at(0),
1,424 ✔
528
                    position.at(1),
1,424 ✔
529
                    position.at(2)));
1,424 ✔
530
            });
1,424 ✔
531
        }
156 ✔
532

533
        _layoutPaused = jsonLayout["paused"];
156 ✔
534
    }
156 ✔
535

536
    if(u::contains(jsonBody, "nodeSize"))
158 ✔
537
        graphModel->setNodeSize(jsonBody["nodeSize"]);
152 ✔
538

539
    if(u::contains(jsonBody, "edgeSize"))
158 ✔
540
        graphModel->setEdgeSize(jsonBody["edgeSize"]);
152 ✔
541

542
    if(u::contains(jsonBody, "textSize"))
158 ✔
543
        graphModel->setTextSize(jsonBody["textSize"]);
152 ✔
544

545
    if(u::contains(jsonBody, "ui"))
158 ✔
546
    {
46 ✔
547
        const auto& jsonUiDataJsonValue = jsonBody["ui"];
46 ✔
548

549
        if(jsonUiDataJsonValue.is_object() || jsonUiDataJsonValue.is_array())
46 !
550
            _uiData = QByteArray::fromStdString(jsonUiDataJsonValue.dump());
44 ✔
551
        else
2 ✔
552
        {
2 ✔
553
            setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
554
            return false;
2 ✔
555
        }
2 ✔
556
    }
46 ✔
557

558
    if(!u::contains(jsonBody, "pluginData"))
156 ✔
559
    {
2 ✔
560
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
561
        return false;
2 ✔
562
    }
2 ✔
563

564
    const auto& pluginDataJsonValue = jsonBody["pluginData"];
154 ✔
565

566
    QByteArray pluginData;
154 ✔
567

568
    if(pluginDataJsonValue.is_object() || pluginDataJsonValue.is_array())
154 !
569
        pluginData = QByteArray::fromStdString(pluginDataJsonValue.dump());
132 ✔
570
    else if(pluginDataJsonValue.is_string())
22 ✔
571
        pluginData = QByteArray::fromHex(QByteArray::fromStdString(pluginDataJsonValue));
18 ✔
572
    else
4 ✔
573
    {
4 ✔
574
        setGenericFailureReason(CURRENT_SOURCE_LOCATION);
4 ✔
575
        return false;
4 ✔
576
    }
4 ✔
577

578
    if(header._pluginDataVersion > _pluginInstance->plugin()->dataVersion())
150 ✔
579
    {
2 ✔
580
        setFailureReason(QObject::tr("Produced using a newer version of the plugin '%1'. Please upgrade.")
2 ✔
581
            .arg(_pluginInstance->plugin()->displayName()));
2 ✔
582
        return false;
2 ✔
583
    }
2 ✔
584

585
    if(!_pluginInstance->load(pluginData, header._pluginDataVersion, graphModel->mutableGraph(), *this))
148 ✔
586
    {
36 ✔
587
        if(!_pluginInstance->failureReason().isEmpty())
36 !
588
            setFailureReason(_pluginInstance->failureReason());
36 ✔
589
        else if(!failureReason().isEmpty())
×
590
            setFailureReason(failureReason());
×
591

592
        return false;
36 ✔
593
    }
36 ✔
594

595
    if(u::contains(jsonBody, "pluginUiData"))
112 ✔
596
    {
102 ✔
597
        const auto& pluginUiDataJsonValue = jsonBody["pluginUiData"];
102 ✔
598

599
        if(pluginUiDataJsonValue.is_object() || pluginUiDataJsonValue.is_array())
102 !
600
            _pluginUiData = QByteArray::fromStdString(pluginUiDataJsonValue.dump());
40 ✔
601
        else if(pluginUiDataJsonValue.is_string())
62 ✔
602
            _pluginUiData = QByteArray::fromHex(QByteArray::fromStdString(pluginUiDataJsonValue));
60 ✔
603
        else
2 ✔
604
        {
2 ✔
605
            setGenericFailureReason(CURRENT_SOURCE_LOCATION);
2 ✔
606
            return false;
2 ✔
607
        }
2 ✔
608

609
        _pluginUiDataVersion = header._pluginDataVersion;
100 ✔
610
    }
100 ✔
611

612
    return true;
110 ✔
613
}
112 ✔
614

615
void Loader::setPluginInstance(IPluginInstance* pluginInstance)
616
{
188 ✔
617
    _pluginInstance = pluginInstance;
188 ✔
618
}
188 ✔
619

620
const ExactNodePositions* Loader::nodePositions() const
621
{
96 ✔
622
    return _nodePositions.get();
96 ✔
623
}
96 ✔
624

625
QString Loader::pluginNameFor(const QUrl& url)
626
{
104 ✔
627
    Header header;
104 ✔
628
    if(parseHeader(url, &header))
104 ✔
629
        return header._pluginName;
100 ✔
630

631
    return {};
4 ✔
632
}
104 ✔
633

634
bool Loader::canOpen(const QUrl& url)
635
{
34 ✔
636
    if(!url.isLocalFile())
34 !
637
        return false;
×
638

639
    Header header;
34 ✔
640
    auto result = parseHeader(url, &header);
34 ✔
641

642
    return result;
34 ✔
643
}
34 ✔
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