Skip to content

Commit 48b5f33

Browse files
committed
Update dspx processing
1 parent 59b3075 commit 48b5f33

11 files changed

Lines changed: 242 additions & 20 deletions

‎src/plugins/coreplugin/core/CoreInterface.cpp‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <SVSCraftCore/SVSCraftNamespace.h>
3939
#include <SVSCraftQuick/Theme.h>
4040

41+
#include <coreplugin/DspxCheckerRegistry.h>
4142
#include <coreplugin/HomeWindowInterface.h>
4243
#include <coreplugin/internal/BehaviorPreference.h>
4344
#include <coreplugin/internal/CoreAchievementsModel.h>
@@ -58,11 +59,13 @@ namespace Core {
5859

5960
QQmlEngine *qmlEngine;
6061
QAK::ActionRegistry *actionRegistry;
62+
DspxCheckerRegistry *dspxCheckerRegistry;
6163

6264
void init() {
6365
Q_Q(CoreInterface);
6466
qmlEngine = new QQmlEngine(q);
6567
actionRegistry = new QAK::ActionRegistry(q);
68+
dspxCheckerRegistry = new DspxCheckerRegistry(q);
6669
}
6770
};
6871

@@ -82,6 +85,11 @@ namespace Core {
8285
return instance()->d_func()->actionRegistry;
8386
}
8487

88+
DspxCheckerRegistry * CoreInterface::dspxCheckerRegistry() {
89+
Q_ASSERT(instance());
90+
return instance()->d_func()->dspxCheckerRegistry;
91+
}
92+
8593
int CoreInterface::execSettingsDialog(const QString &id, QWindow *parent) {
8694
static std::unique_ptr<QWindow> dlg;
8795

‎src/plugins/coreplugin/core/CoreInterface.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Core {
2323
}
2424

2525
class ProjectWindowInterface;
26+
class DspxCheckerRegistry;
2627

2728
class CoreInterfacePrivate;
2829

@@ -38,6 +39,12 @@ namespace Core {
3839

3940
static QAK::ActionRegistry *actionRegistry();
4041

42+
static DspxCheckerRegistry *dspxCheckerRegistry();
43+
44+
static constexpr const char *dspxEditorId() {
45+
return "org.diffscope.diffscope";
46+
}
47+
4148
Q_INVOKABLE static int execSettingsDialog(const QString &id, QWindow *parent);
4249
Q_INVOKABLE static void execPluginsDialog(QWindow *parent);
4350
Q_INVOKABLE static void execAboutAppDialog(QWindow *parent);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include "DspxCheckerRegistry.h"
2+
#include "DspxCheckerRegistry_p.h"
3+
4+
5+
namespace Core {
6+
7+
DspxCheckerRegistry::DspxCheckerRegistry(QObject *parent) : IDspxChecker(parent), d_ptr(new DspxCheckerRegistryPrivate) {
8+
Q_D(DspxCheckerRegistry);
9+
d->q_ptr = this;
10+
}
11+
12+
DspxCheckerRegistry::~DspxCheckerRegistry() = default;
13+
14+
void DspxCheckerRegistry::registerChecker(IDspxChecker *checker) {
15+
Q_D(DspxCheckerRegistry);
16+
d->checkers.append(checker);
17+
}
18+
19+
QList<IDspxChecker *> DspxCheckerRegistry::checkers() const {
20+
Q_D(const DspxCheckerRegistry);
21+
return d->checkers;
22+
}
23+
24+
QList<DspxCheckWarning> DspxCheckerRegistry::runCheck(const QDspx::Model &model, Level level, bool failFast) {
25+
Q_D(DspxCheckerRegistry);
26+
for (auto checker : d->checkers) {
27+
auto warnings = checker->runCheck(model, level, failFast);
28+
if (failFast && !warnings.isEmpty())
29+
return warnings;
30+
}
31+
return {};
32+
}
33+
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef DIFFSCOPE_COREPLUGIN_DSPXCHECKERREGISTRY_H
2+
#define DIFFSCOPE_COREPLUGIN_DSPXCHECKERREGISTRY_H
3+
4+
#include <QObject>
5+
6+
#include <coreplugin/IDspxChecker.h>
7+
8+
namespace QDspx {
9+
struct Model;
10+
}
11+
12+
namespace Core {
13+
14+
class DspxCheckerRegistryPrivate;
15+
16+
class DspxCheckerRegistry : public IDspxChecker {
17+
Q_OBJECT
18+
Q_DECLARE_PRIVATE(DspxCheckerRegistry)
19+
public:
20+
explicit DspxCheckerRegistry(QObject *parent = nullptr);
21+
~DspxCheckerRegistry() override;
22+
23+
void registerChecker(IDspxChecker *checker);
24+
QList<IDspxChecker *> checkers() const;
25+
26+
QList<DspxCheckWarning> runCheck(const QDspx::Model &model, Level level, bool failFast) override;
27+
28+
private:
29+
QScopedPointer<DspxCheckerRegistryPrivate> d_ptr;
30+
};
31+
32+
}
33+
34+
#endif //DIFFSCOPE_COREPLUGIN_DSPXCHECKERREGISTRY_H
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef DIFFSCOPE_COREPLUGIN_DSPXCHECKERREGISTRY_P_H
2+
#define DIFFSCOPE_COREPLUGIN_DSPXCHECKERREGISTRY_P_H
3+
4+
#include <coreplugin/DspxCheckerRegistry.h>
5+
6+
namespace Core {
7+
class DspxCheckerRegistryPrivate {
8+
Q_DECLARE_PUBLIC(DspxCheckerRegistry)
9+
public:
10+
DspxCheckerRegistry *q_ptr;
11+
QList<IDspxChecker *> checkers;
12+
};
13+
}
14+
15+
#endif //DIFFSCOPE_COREPLUGIN_DSPXCHECKERREGISTRY_P_H

‎src/plugins/coreplugin/project/DspxInspectorDialog.cpp‎

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "DspxInspectorDialog.h"
22
#include "DspxInspectorDialog_p.h"
33

4+
#include <application_config.h>
5+
46
#include <QApplication>
57
#include <QDir>
68
#include <QVBoxLayout>
@@ -14,10 +16,29 @@
1416
#include <opendspx/model.h>
1517
#include <opendspxserializer/serializer.h>
1618

19+
#include <SVSCraftCore/Semver.h>
20+
21+
#include <coreplugin/CoreInterface.h>
22+
#include <coreplugin/DspxCheckerRegistry.h>
1723
#include <coreplugin/OpenSaveProjectFileScenario.h>
1824

1925
namespace Core {
2026

27+
static bool checkIsVersionCompatible(const QString &version) {
28+
if (version.isEmpty())
29+
return true;
30+
SVS::Semver currentSemver(QStringLiteral(APPLICATION_SEMVER));
31+
SVS::Semver fileSemver(version);
32+
if (fileSemver == currentSemver)
33+
return true;
34+
if (fileSemver > currentSemver)
35+
return false;
36+
if (!fileSemver.preRelease().isEmpty() || !fileSemver.build().isEmpty()) {
37+
return false;
38+
}
39+
return true;
40+
}
41+
2142
DspxInspectorDialog::DspxInspectorDialog(QWidget *parent) : QDialog(parent), d_ptr(new DspxInspectorDialogPrivate) {
2243
Q_D(DspxInspectorDialog);
2344
d->q_ptr = this;
@@ -126,7 +147,7 @@ namespace Core {
126147
if (!f.open(QIODevice::ReadOnly)) {
127148
addErrorItem(
128149
problemModel,
129-
tr("Failed to open file"),
150+
tr("Fatal: Failed to open file"),
130151
{},
131152
style()->standardIcon(QStyle::SP_MessageBoxCritical),
132153
{
@@ -190,7 +211,7 @@ namespace Core {
190211
}
191212
addErrorItem(
192213
problemModel,
193-
tr("Error: Invalid data type") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
214+
tr("Invalid data type") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
194215
e->path(),
195216
style()->standardIcon(QStyle::SP_MessageBoxCritical),
196217
{
@@ -205,7 +226,7 @@ namespace Core {
205226
auto e = error.staticCast<QDspx::InvalidObjectTypeError>();
206227
addErrorItem(
207228
problemModel,
208-
tr("Error: Invalid object type") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
229+
tr("Invalid object type") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
209230
e->path(),
210231
style()->standardIcon(QStyle::SP_MessageBoxCritical),
211232
{
@@ -220,7 +241,7 @@ namespace Core {
220241
auto e = error.staticCast<QDspx::RangeConstraintViolationError>();
221242
addErrorItem(
222243
problemModel,
223-
tr("Error: Range constraint violation") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
244+
tr("Range constraint violation") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
224245
e->path(),
225246
style()->standardIcon(QStyle::SP_MessageBoxCritical),
226247
{
@@ -241,7 +262,7 @@ namespace Core {
241262
info.emplace_back(tr("Actual enum value"), e->actualEnumValue().toString());
242263
addErrorItem(
243264
problemModel,
244-
tr("Error: Enum constraint violation") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
265+
tr("Enum constraint violation") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
245266
e->path(),
246267
style()->standardIcon(QStyle::SP_MessageBoxCritical),
247268
info,
@@ -257,7 +278,7 @@ namespace Core {
257278
}
258279
addErrorItem(
259280
problemModel,
260-
tr("Error: Missing properties") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
281+
tr("Missing properties") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
261282
e->path(),
262283
style()->standardIcon(QStyle::SP_MessageBoxCritical),
263284
info,
@@ -273,7 +294,7 @@ namespace Core {
273294
}
274295
addErrorItem(
275296
problemModel,
276-
tr("Error: Redundant properties") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
297+
tr("Redundant properties") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
277298
e->path(),
278299
style()->standardIcon(QStyle::SP_MessageBoxCritical),
279300
info,
@@ -289,9 +310,9 @@ namespace Core {
289310
}
290311
addErrorItem(
291312
problemModel,
292-
tr("Warning: Overlapping items") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
313+
tr("Overlapping items") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
293314
e->path(),
294-
style()->standardIcon(QStyle::SP_MessageBoxWarning),
315+
{},
295316
info,
296317
tr("Items at specific indexes in the array at the specific path overlap.")
297318
);
@@ -301,9 +322,9 @@ namespace Core {
301322
auto e = error.staticCast<QDspx::ZeroLengthRangeError>();
302323
addErrorItem(
303324
problemModel,
304-
tr("Warning: Zero-length range") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
325+
tr("Zero-length range") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
305326
e->path(),
306-
style()->standardIcon(QStyle::SP_MessageBoxWarning),
327+
{},
307328
{},
308329
tr("The range length of the entity object at the specific path is zero.")
309330
);
@@ -313,9 +334,9 @@ namespace Core {
313334
auto e = error.staticCast<QDspx::ErroneousClipRangeError>();
314335
addErrorItem(
315336
problemModel,
316-
tr("Warning: Erroneous clip range") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
337+
tr("Erroneous clip range") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
317338
e->path(),
318-
style()->standardIcon(QStyle::SP_MessageBoxWarning),
339+
{},
319340
{},
320341
tr("The clipping range of the clip entity object at the specific path exceeds its range limit.")
321342
);
@@ -325,9 +346,9 @@ namespace Core {
325346
auto e = error.staticCast<QDspx::ErroneousClipPositionError>();
326347
addErrorItem(
327348
problemModel,
328-
tr("Warning: Erroneous clip position") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
349+
tr("Erroneous clip position") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
329350
e->path(),
330-
style()->standardIcon(QStyle::SP_MessageBoxWarning),
351+
{},
331352
{},
332353
tr("The position of the clip entity object at the specific path exceeds the view range limit. It might be not visible in the viewport.")
333354
);
@@ -337,7 +358,7 @@ namespace Core {
337358
auto e = error.staticCast<QDspx::SafeRangeLimitExceededError>();
338359
addErrorItem(
339360
problemModel,
340-
tr("Warning: Safe range limit exceeded") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
361+
tr("Safe range limit exceeded") + QStringLiteral(" (0x%1)").arg(QString::number(error->type(), 16), 4, '0'),
341362
e->path(),
342363
style()->standardIcon(QStyle::SP_MessageBoxWarning),
343364
{},
@@ -348,6 +369,43 @@ namespace Core {
348369
}
349370
}
350371

372+
if (dspxModel.content.global.editorId != CoreInterface::dspxEditorId()) {
373+
addErrorItem(
374+
problemModel,
375+
tr("File Created With Another Application"),
376+
QStringLiteral("$.content.global.editorId"),
377+
style()->standardIcon(QStyle::SP_MessageBoxWarning),
378+
{
379+
{tr("Editor ID"), dspxModel.content.global.editorId},
380+
{tr("Editor name"), dspxModel.content.global.editorName},
381+
},
382+
tr("This project file was created with another application. Some features may not be fully compatible or may behave differently.")
383+
);
384+
} else if (auto version = dspxModel.content.workspace.value("diffscope").value("editorVersion").toString(); !checkIsVersionCompatible(version)) {
385+
addErrorItem(
386+
problemModel,
387+
tr("File Created With Incompatible Version"),
388+
QStringLiteral("$.content.workspace.diffscope.editorVersion"),
389+
style()->standardIcon(QStyle::SP_MessageBoxWarning),
390+
{
391+
{tr("Version"), version},
392+
},
393+
tr("This project file was created with an newer version or test version of %1. Some features may not be fully compatible or may behave differently.").arg(QApplication::applicationDisplayName())
394+
);
395+
}
396+
397+
auto customCheckResult = CoreInterface::dspxCheckerRegistry()->runCheck(dspxModel, IDspxChecker::Weak, false);
398+
for (const auto &warning : customCheckResult) {
399+
addErrorItem(
400+
problemModel,
401+
warning.message,
402+
warning.jsonPath,
403+
warning.level == IDspxChecker::Strong ? style()->standardIcon(QStyle::SP_MessageBoxWarning) : QIcon(),
404+
warning.info,
405+
warning.description
406+
);
407+
}
408+
351409
// TODO show file structure
352410
}
353411

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "IDspxChecker.h"
2+
3+
namespace Core {
4+
5+
IDspxChecker::IDspxChecker(QObject *parent) : QObject(parent) {}
6+
7+
IDspxChecker::~IDspxChecker() = default;
8+
9+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef DIFFSCOPE_COREPLUGIN_IDSPXCHECKER_H
2+
#define DIFFSCOPE_COREPLUGIN_IDSPXCHECKER_H
3+
4+
#include <QObject>
5+
#include <QVariant>
6+
7+
namespace QDspx {
8+
struct Model;
9+
}
10+
11+
namespace Core {
12+
13+
struct DspxCheckWarning;
14+
15+
class IDspxChecker : public QObject {
16+
Q_OBJECT
17+
public:
18+
explicit IDspxChecker(QObject *parent = nullptr);
19+
~IDspxChecker() override;
20+
21+
enum Level {
22+
Weak,
23+
Strong,
24+
};
25+
26+
virtual QList<DspxCheckWarning> runCheck(const QDspx::Model &model, Level level, bool failFast) = 0;
27+
};
28+
29+
struct DspxCheckWarning {
30+
IDspxChecker::Level level;
31+
QString message;
32+
QString jsonPath;
33+
QString description;
34+
QList<QPair<QString, QVariant>> info;
35+
};
36+
37+
}
38+
39+
#endif //DIFFSCOPE_COREPLUGIN_IDSPXCHECKER_H

0 commit comments

Comments
 (0)