Skip to content

Commit 9a2feca

Browse files
committed
Accept null sprite and stage in models
1 parent 6339aa3 commit 9a2feca

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

src/spritemodel.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,34 @@ SpriteModel::SpriteModel(QObject *parent) :
2020

2121
void SpriteModel::init(libscratchcpp::Sprite *sprite)
2222
{
23-
if (!sprite)
24-
return;
25-
2623
m_sprite = sprite;
2724

28-
m_sprite->bubble()->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
29-
if (type == libscratchcpp::TextBubble::Type::Say) {
30-
if (m_bubbleType == TextBubbleShape::Type::Say)
31-
return;
25+
if (m_sprite) {
26+
m_sprite->bubble()->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
27+
if (type == libscratchcpp::TextBubble::Type::Say) {
28+
if (m_bubbleType == TextBubbleShape::Type::Say)
29+
return;
3230

33-
m_bubbleType = TextBubbleShape::Type::Say;
34-
} else {
35-
if (m_bubbleType == TextBubbleShape::Type::Think)
36-
return;
31+
m_bubbleType = TextBubbleShape::Type::Say;
32+
} else {
33+
if (m_bubbleType == TextBubbleShape::Type::Think)
34+
return;
3735

38-
m_bubbleType = TextBubbleShape::Type::Think;
39-
}
36+
m_bubbleType = TextBubbleShape::Type::Think;
37+
}
4038

41-
emit bubbleTypeChanged();
42-
});
39+
emit bubbleTypeChanged();
40+
});
4341

44-
m_sprite->bubble()->textChanged().connect([this](const std::string &text) {
45-
QString newText = QString::fromStdString(text);
42+
m_sprite->bubble()->textChanged().connect([this](const std::string &text) {
43+
QString newText = QString::fromStdString(text);
4644

47-
if (m_bubbleText != newText) {
48-
m_bubbleText = newText;
49-
emit bubbleTextChanged();
50-
}
51-
});
45+
if (m_bubbleText != newText) {
46+
m_bubbleText = newText;
47+
emit bubbleTextChanged();
48+
}
49+
});
50+
}
5251
}
5352

5453
void SpriteModel::deinitClone()

src/stagemodel.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,34 @@ StageModel::StageModel(QObject *parent) :
1616

1717
void StageModel::init(libscratchcpp::Stage *stage)
1818
{
19-
if (!stage)
20-
return;
21-
2219
m_stage = stage;
2320

24-
m_stage->bubble()->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
25-
if (type == libscratchcpp::TextBubble::Type::Say) {
26-
if (m_bubbleType == TextBubbleShape::Type::Say)
27-
return;
21+
if (m_stage) {
22+
m_stage->bubble()->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
23+
if (type == libscratchcpp::TextBubble::Type::Say) {
24+
if (m_bubbleType == TextBubbleShape::Type::Say)
25+
return;
2826

29-
m_bubbleType = TextBubbleShape::Type::Say;
30-
} else {
31-
if (m_bubbleType == TextBubbleShape::Type::Think)
32-
return;
27+
m_bubbleType = TextBubbleShape::Type::Say;
28+
} else {
29+
if (m_bubbleType == TextBubbleShape::Type::Think)
30+
return;
3331

34-
m_bubbleType = TextBubbleShape::Type::Think;
35-
}
32+
m_bubbleType = TextBubbleShape::Type::Think;
33+
}
3634

37-
emit bubbleTypeChanged();
38-
});
35+
emit bubbleTypeChanged();
36+
});
3937

40-
m_stage->bubble()->textChanged().connect([this](const std::string &text) {
41-
QString newText = QString::fromStdString(text);
38+
m_stage->bubble()->textChanged().connect([this](const std::string &text) {
39+
QString newText = QString::fromStdString(text);
4240

43-
if (m_bubbleText != newText) {
44-
m_bubbleText = newText;
45-
emit bubbleTextChanged();
46-
}
47-
});
41+
if (m_bubbleText != newText) {
42+
m_bubbleText = newText;
43+
emit bubbleTextChanged();
44+
}
45+
});
46+
}
4847
}
4948

5049
void StageModel::onCostumeChanged(libscratchcpp::Costume *costume)

0 commit comments

Comments
 (0)