Skip to content

Commit d2bb206

Browse files
committed
Notify about bubble layer changes
Resolves: #148
1 parent 7bda325 commit d2bb206

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

src/spritemodel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ void SpriteModel::init(libscratchcpp::Sprite *sprite)
2323
m_sprite = sprite;
2424

2525
if (m_sprite) {
26-
m_sprite->bubble()->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
26+
libscratchcpp::TextBubble *bubble = m_sprite->bubble();
27+
28+
bubble->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
2729
if (type == libscratchcpp::TextBubble::Type::Say) {
2830
if (m_bubbleType == TextBubbleShape::Type::Say)
2931
return;
@@ -39,14 +41,16 @@ void SpriteModel::init(libscratchcpp::Sprite *sprite)
3941
emit bubbleTypeChanged();
4042
});
4143

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

4547
if (m_bubbleText != newText) {
4648
m_bubbleText = newText;
4749
emit bubbleTextChanged();
4850
}
4951
});
52+
53+
bubble->layerOrderChanged().connect([this](int) { emit bubbleLayerChanged(); });
5054
}
5155
}
5256

src/stagemodel.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ void StageModel::init(libscratchcpp::Stage *stage)
1919
m_stage = stage;
2020

2121
if (m_stage) {
22-
m_stage->bubble()->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
22+
libscratchcpp::TextBubble *bubble = m_stage->bubble();
23+
24+
bubble->typeChanged().connect([this](libscratchcpp::TextBubble::Type type) {
2325
if (type == libscratchcpp::TextBubble::Type::Say) {
2426
if (m_bubbleType == TextBubbleShape::Type::Say)
2527
return;
@@ -35,14 +37,16 @@ void StageModel::init(libscratchcpp::Stage *stage)
3537
emit bubbleTypeChanged();
3638
});
3739

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

4143
if (m_bubbleText != newText) {
4244
m_bubbleText = newText;
4345
emit bubbleTextChanged();
4446
}
4547
});
48+
49+
bubble->layerOrderChanged().connect([this](int) { emit bubbleLayerChanged(); });
4650
}
4751
}
4852

test/target_models/spritemodel_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,5 +476,5 @@ TEST(SpriteModelTest, BubbleLayer)
476476

477477
sprite.bubble()->setLayerOrder(5);
478478
ASSERT_EQ(model.bubbleLayer(), 5);
479-
// TODO: Use spy here
479+
ASSERT_EQ(spy.count(), 1);
480480
}

test/target_models/stagemodel_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,5 @@ TEST(StageModelTest, BubbleLayer)
235235

236236
stage.bubble()->setLayerOrder(5);
237237
ASSERT_EQ(model.bubbleLayer(), 5);
238-
// TODO: Use spy here
238+
ASSERT_EQ(spy.count(), 1);
239239
}

0 commit comments

Comments
 (0)