Skip to content

Commit a7d880b

Browse files
committed
Merge remote-tracking branch 'origin/dspx-model'
2 parents 057a578 + f70349c commit a7d880b

116 files changed

Lines changed: 9413 additions & 3 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/libs/3rdparty/opendspx‎

Submodule opendspx updated 63 files
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
add_subdirectory(loadapi)
22

3-
add_subdirectory(uishell)
3+
add_subdirectory(uishell)
4+
5+
add_subdirectory(dspxmodel)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_subdirectory(src)
2+
3+
if(APPLICATION_BUILD_TESTS)
4+
add_subdirectory(tests)
5+
endif()
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#include "AnchorNode.h"
2+
3+
#include <QVariant>
4+
#include <QJSEngine>
5+
6+
#include <opendspx/anchornode.h>
7+
8+
#include <dspxmodel/Model.h>
9+
#include <dspxmodel/ModelStrategy.h>
10+
11+
namespace dspx {
12+
13+
class AnchorNodePrivate {
14+
Q_DECLARE_PUBLIC(AnchorNode)
15+
public:
16+
AnchorNode *q_ptr;
17+
AnchorNode::InterpolationMode interp;
18+
int x;
19+
int y;
20+
21+
void setInterpUnchecked(AnchorNode::InterpolationMode interp_);
22+
void setInterp(AnchorNode::InterpolationMode interp_);
23+
void setXUnchecked(int x_);
24+
void setX(int x_);
25+
};
26+
27+
void AnchorNodePrivate::setInterpUnchecked(AnchorNode::InterpolationMode interp_) {
28+
Q_Q(AnchorNode);
29+
q->model()->strategy()->setEntityProperty(q->handle(), ModelStrategy::P_Type, QVariant::fromValue(interp_));
30+
}
31+
32+
void AnchorNodePrivate::setInterp(AnchorNode::InterpolationMode interp_) {
33+
Q_Q(AnchorNode);
34+
if (auto engine = qjsEngine(q); engine && (interp_ != AnchorNode::None && interp_ != AnchorNode::Linear && interp_ != AnchorNode::Hermite)) {
35+
engine->throwError(QJSValue::RangeError, QStringLiteral("Interpolation mode must be one of None, Linear, or Hermite"));
36+
return;
37+
}
38+
setInterpUnchecked(interp_);
39+
}
40+
41+
void AnchorNodePrivate::setXUnchecked(int x_) {
42+
Q_Q(AnchorNode);
43+
q->model()->strategy()->setEntityProperty(q->handle(), ModelStrategy::P_Position, x_);
44+
}
45+
46+
void AnchorNodePrivate::setX(int x_) {
47+
Q_Q(AnchorNode);
48+
if (auto engine = qjsEngine(q); engine && x_ < 0) {
49+
engine->throwError(QJSValue::RangeError, QStringLiteral("Position must be greater or equal to 0"));
50+
return;
51+
}
52+
setXUnchecked(x_);
53+
}
54+
55+
AnchorNode::AnchorNode(Handle handle, Model *model)
56+
: EntityObject(handle, model), d_ptr(new AnchorNodePrivate) {
57+
Q_D(AnchorNode);
58+
Q_ASSERT(model->strategy()->getEntityType(handle) == ModelStrategy::EI_ParamCurveAnchorNode);
59+
d->q_ptr = this;
60+
d->interp = model->strategy()->getEntityProperty(handle, ModelStrategy::P_Type).value<InterpolationMode>();
61+
d->x = model->strategy()->getEntityProperty(handle, ModelStrategy::P_Position).toInt();
62+
d->y = model->strategy()->getEntityProperty(handle, ModelStrategy::P_Value).toInt();
63+
}
64+
65+
AnchorNode::~AnchorNode() = default;
66+
67+
AnchorNode::InterpolationMode AnchorNode::interp() const {
68+
Q_D(const AnchorNode);
69+
return d->interp;
70+
}
71+
72+
void AnchorNode::setInterp(InterpolationMode interp) {
73+
Q_D(AnchorNode);
74+
Q_ASSERT(interp == None || interp == Linear || interp == Hermite);
75+
d->setInterpUnchecked(interp);
76+
}
77+
78+
int AnchorNode::x() const {
79+
Q_D(const AnchorNode);
80+
return d->x;
81+
}
82+
83+
void AnchorNode::setX(int x) {
84+
Q_D(AnchorNode);
85+
Q_ASSERT(x >= 0);
86+
d->setXUnchecked(x);
87+
}
88+
89+
int AnchorNode::y() const {
90+
Q_D(const AnchorNode);
91+
return d->y;
92+
}
93+
94+
void AnchorNode::setY(int y) {
95+
Q_D(AnchorNode);
96+
model()->strategy()->setEntityProperty(handle(), ModelStrategy::P_Value, y);
97+
}
98+
99+
QDspx::AnchorNode AnchorNode::toQDspx() const {
100+
Q_D(const AnchorNode);
101+
return QDspx::AnchorNode {
102+
.interp = static_cast<QDspx::AnchorNode::Interpolation>(d->interp),
103+
.x = d->x,
104+
.y = d->y,
105+
};
106+
}
107+
108+
void AnchorNode::fromQDspx(const QDspx::AnchorNode &node) {
109+
Q_D(AnchorNode);
110+
setInterp(static_cast<InterpolationMode>(node.interp));
111+
setX(node.x);
112+
setY(node.y);
113+
}
114+
115+
void AnchorNode::handleSetEntityProperty(int property, const QVariant &value) {
116+
Q_D(AnchorNode);
117+
switch (property) {
118+
case ModelStrategy::P_Type: {
119+
d->interp = value.value<InterpolationMode>();
120+
Q_EMIT interpChanged(d->interp);
121+
break;
122+
}
123+
case ModelStrategy::P_Position: {
124+
d->x = value.toInt();
125+
Q_EMIT xChanged(d->x);
126+
break;
127+
}
128+
case ModelStrategy::P_Value: {
129+
d->y = value.toInt();
130+
Q_EMIT yChanged(d->y);
131+
break;
132+
}
133+
default:
134+
Q_UNREACHABLE();
135+
}
136+
}
137+
138+
}
139+
140+
#include "moc_AnchorNode.cpp"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#ifndef DIFFSCOPE_DSPX_MODEL_ANCHORNODE_H
2+
#define DIFFSCOPE_DSPX_MODEL_ANCHORNODE_H
3+
4+
#include <dspxmodel/EntityObject.h>
5+
#include <qqmlintegration.h>
6+
7+
namespace QDspx {
8+
struct AnchorNode;
9+
}
10+
11+
namespace dspx {
12+
13+
class AnchorNodePrivate;
14+
15+
class DSPX_MODEL_EXPORT AnchorNode : public EntityObject {
16+
Q_OBJECT
17+
QML_ELEMENT
18+
QML_UNCREATABLE("")
19+
Q_DECLARE_PRIVATE(AnchorNode)
20+
Q_PRIVATE_PROPERTY(d_func(), InterpolationMode interp MEMBER interp WRITE setInterp NOTIFY interpChanged)
21+
Q_PRIVATE_PROPERTY(d_func(), int x MEMBER x WRITE setX NOTIFY xChanged)
22+
Q_PROPERTY(int y READ y WRITE setY NOTIFY yChanged)
23+
24+
public:
25+
enum InterpolationMode {
26+
None = 0,
27+
Linear,
28+
Hermite
29+
};
30+
Q_ENUM(InterpolationMode)
31+
32+
~AnchorNode() override;
33+
34+
InterpolationMode interp() const;
35+
void setInterp(InterpolationMode interp);
36+
37+
int x() const;
38+
void setX(int x);
39+
40+
int y() const;
41+
void setY(int y);
42+
43+
QDspx::AnchorNode toQDspx() const;
44+
void fromQDspx(const QDspx::AnchorNode &node);
45+
46+
Q_SIGNALS:
47+
void interpChanged(InterpolationMode interp);
48+
void xChanged(int x);
49+
void yChanged(int y);
50+
51+
protected:
52+
void handleSetEntityProperty(int property, const QVariant &value) override;
53+
54+
private:
55+
friend class ModelPrivate;
56+
explicit AnchorNode(Handle handle, Model *model);
57+
QScopedPointer<AnchorNodePrivate> d_ptr;
58+
};
59+
60+
}
61+
62+
#endif //DIFFSCOPE_DSPX_MODEL_ANCHORNODE_H
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include "AnchorNodeSequence.h"
2+
3+
#include <QJSValue>
4+
#include <QJSEngine>
5+
6+
#include <opendspx/anchornode.h>
7+
8+
#include <dspxmodel/private/PointSequenceContainer_p.h>
9+
#include <dspxmodel/private/Model_p.h>
10+
#include <dspxmodel/AnchorNode.h>
11+
#include <dspxmodel/ModelStrategy.h>
12+
#include <dspxmodel/private/PointSequenceData_p.h>
13+
14+
namespace dspx {
15+
16+
class AnchorNodeSequencePrivate : public PointSequenceData<AnchorNodeSequence, AnchorNode, &AnchorNode::x, &AnchorNode::xChanged> {
17+
Q_DECLARE_PUBLIC(AnchorNodeSequence)
18+
};
19+
20+
AnchorNodeSequence::AnchorNodeSequence(Handle handle, Model *model) : EntityObject(handle, model), d_ptr(new AnchorNodeSequencePrivate) {
21+
Q_D(AnchorNodeSequence);
22+
Q_ASSERT(model->strategy()->getEntityType(handle) == ModelStrategy::ES_ParamCurveAnchorNodes);
23+
d->q_ptr = this;
24+
d->pModel = ModelPrivate::get(model);
25+
}
26+
27+
AnchorNodeSequence::~AnchorNodeSequence() = default;
28+
29+
int AnchorNodeSequence::size() const {
30+
Q_D(const AnchorNodeSequence);
31+
return d->container.size();
32+
}
33+
34+
AnchorNode *AnchorNodeSequence::firstItem() const {
35+
Q_D(const AnchorNodeSequence);
36+
return d->firstItem;
37+
}
38+
39+
AnchorNode *AnchorNodeSequence::lastItem() const {
40+
Q_D(const AnchorNodeSequence);
41+
return d->lastItem;
42+
}
43+
44+
AnchorNode *AnchorNodeSequence::previousItem(AnchorNode *item) const {
45+
Q_D(const AnchorNodeSequence);
46+
return d->container.previousItem(item);
47+
}
48+
49+
AnchorNode *AnchorNodeSequence::nextItem(AnchorNode *item) const {
50+
Q_D(const AnchorNodeSequence);
51+
return d->container.nextItem(item);
52+
}
53+
54+
QList<AnchorNode *> AnchorNodeSequence::slice(int position, int length) const {
55+
Q_D(const AnchorNodeSequence);
56+
return d->container.slice(position, length);
57+
}
58+
59+
bool AnchorNodeSequence::contains(AnchorNode *item) const {
60+
Q_D(const AnchorNodeSequence);
61+
return d->container.contains(item);
62+
}
63+
64+
bool AnchorNodeSequence::insertItem(AnchorNode *item) {
65+
Q_D(AnchorNodeSequence);
66+
return d->pModel->strategy->insertIntoSequenceContainer(handle(), item->handle());
67+
}
68+
69+
bool AnchorNodeSequence::removeItem(AnchorNode *item) {
70+
Q_D(AnchorNodeSequence);
71+
return d->pModel->strategy->takeFromSequenceContainer(handle(), item->handle());
72+
}
73+
74+
QList<QDspx::AnchorNode> AnchorNodeSequence::toQDspx() const {
75+
Q_D(const AnchorNodeSequence);
76+
QList<QDspx::AnchorNode> ret;
77+
ret.reserve(d->container.size());
78+
for (const auto &[_, item] : d->container.m_items) {
79+
ret.append(item->toQDspx());
80+
}
81+
return ret;
82+
}
83+
84+
void AnchorNodeSequence::fromQDspx(const QList<QDspx::AnchorNode> &nodes) {
85+
while (size()) {
86+
removeItem(firstItem());
87+
}
88+
for (const auto &node : nodes) {
89+
auto item = model()->createAnchorNode();
90+
item->fromQDspx(node);
91+
insertItem(item);
92+
}
93+
}
94+
95+
void AnchorNodeSequence::handleInsertIntoSequenceContainer(Handle entity) {
96+
Q_D(AnchorNodeSequence);
97+
d->handleInsertIntoSequenceContainer(entity);
98+
}
99+
100+
void AnchorNodeSequence::handleTakeFromSequenceContainer(Handle takenEntity, Handle entity) {
101+
Q_D(AnchorNodeSequence);
102+
d->handleTakeFromSequenceContainer(takenEntity, entity);
103+
}
104+
105+
}
106+
107+
#include "moc_AnchorNodeSequence.cpp"

0 commit comments

Comments
 (0)