Skip to content

Commit

Permalink
fix #293707: undo doesn't restore deleted frame immediately
Browse files Browse the repository at this point in the history
Why do these changes fix this particular issue?

After adding any other element, we `setLayout` at the element's
location. However, for boxes, there is an early return, and this step is
missed, meaning the box won't appear until a relevant measure is layed out.
This fix adds the missing `setLayout`.
  • Loading branch information
jthistle committed Sep 4, 2019
1 parent ca3eb20 commit 3f40a56
Show file tree
Hide file tree
Showing 8 changed files with 513 additions and 5 deletions.
11 changes: 6 additions & 5 deletions libmscore/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ void Score::addElement(Element* element)
|| et == ElementType::FBOX
) {
measures()->add(toMeasureBase(element));
setLayout(element->tick());
return;
}

Expand Down Expand Up @@ -2096,7 +2097,7 @@ bool Score::appendScore(Score* score, bool addPageBreak, bool addSectionBreak)
else if (!last()->lineBreak() && !last()->pageBreak()) {
last()->undoSetBreak(true, LayoutBreak::Type::LINE);
}

if (addSectionBreak && !last()->sectionBreak())
last()->undoSetBreak(true, LayoutBreak::Type::SECTION);

Expand Down Expand Up @@ -2144,7 +2145,7 @@ bool Score::appendMeasuresFromScore(Score* score, const Fraction& startTick, con
pmb->setNext(nmb);
pmb = nmb;
}

Measure* firstAppendedMeasure = tick2measure(tickOfAppend);

// if the appended score has less staves,
Expand All @@ -2170,7 +2171,7 @@ bool Score::appendMeasuresFromScore(Score* score, const Fraction& startTick, con
int trackIdx = staff2track(staffIdx); // idx of irst track on the staff
Staff* staff = this->staff(staffIdx);
Staff* ostaff = score->staff(staffIdx);

// check if key signature needs to be changed
if (ostaff->key(otick) != staff->key(ctick)) {
Segment* ns = firstAppendedMeasure->undoGetSegment(SegmentType::KeySig, ctick);
Expand All @@ -2190,7 +2191,7 @@ bool Score::appendMeasuresFromScore(Score* score, const Fraction& startTick, con
if (ns)
ns->remove(ns->element(trackIdx));
}

// check if time signature needs to be changed
TimeSig* ots = ostaff->timeSig(otick), * cts = staff->timeSig(ctick);
TimeSig* pts = staff->timeSig(ctick - Fraction::fromTicks(1));
Expand Down Expand Up @@ -2235,7 +2236,7 @@ bool Score::appendMeasuresFromScore(Score* score, const Fraction& startTick, con
auto lb = ospans.lower_bound(startTick.ticks()), ub = ospans.upper_bound(endTick.ticks());
for (auto sp = lb; sp != ub; sp++) {
Spanner* spanner = sp->second;

if (spanner->tick2() > endTick) continue; // map is by tick() so this can still happen in theory...

Spanner* ns = toSpanner(spanner->clone());
Expand Down
1 change: 1 addition & 0 deletions mtest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ subdirs (
libmscore/barline
libmscore/beam
libmscore/breath
libmscore/box
libmscore/chordsymbol
libmscore/clef
libmscore/clef_courtesy
Expand Down
16 changes: 16 additions & 0 deletions mtest/libmscore/box/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
#
# Copyright (C) 2019 Werner Schweer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation and appearing in
# the file LICENSE.GPL
#=============================================================================

set(TARGET tst_box)

include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc)

79 changes: 79 additions & 0 deletions mtest/libmscore/box/tst_box.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2019 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#include <QtTest/QtTest>
#include "mtest/testutils.h"
#include "libmscore/score.h"
#include "libmscore/system.h"
#include "libmscore/undo.h"
#include "libmscore/box.h"

#define DIR QString("libmscore/box/")

using namespace Ms;

//---------------------------------------------------------
// TestBox
//---------------------------------------------------------

class TestBox : public QObject, public MTest
{
Q_OBJECT

private slots:
void initTestCase();
void undoRemoveVBox();
};

//---------------------------------------------------------
// initTestCase
//---------------------------------------------------------

void TestBox::initTestCase()
{
initMTest();
}

//---------------------------------------------------------
// undoRemoveVBox
/// read a file with a vbox. Delete it, and undo. Check that the VBox still exists.
//---------------------------------------------------------

void TestBox::undoRemoveVBox()
{
QString readFile(DIR + "undoRemoveVBox.mscx");
QString writeFile1("undoRemoveVBox1-test.mscx");
QString reference1(DIR + "undoRemoveVBox1-ref.mscx");
QString writeFile2("undoRemoveVBox2-test.mscx");
QString reference2(DIR + "undoRemoveVBox2-ref.mscx");

MasterScore* score = readScore(readFile);
score->doLayout();

System* s = score->systems()[0];
VBox* box = toVBox(s->measure(0));

score->startCmd();
score->select(box);
score->cmdDeleteSelection();
score->endCmd();
QVERIFY(saveCompareScore(score, writeFile1, reference1));

// undo
score->undoStack()->undo(nullptr);
QVERIFY(saveCompareScore(score, writeFile2, reference2));

delete score;
}

QTEST_MAIN(TestBox)
#include "tst_box.moc"
136 changes: 136 additions & 0 deletions mtest/libmscore/box/undoRemoveVBox.mscx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="3.01">
<Score>
<LayerTag id="0" tag="default"></LayerTag>
<currentLayer>0</currentLayer>
<Division>480</Division>
<Style>
<Spatium>1.76389</Spatium>
</Style>
<showInvisible>1</showInvisible>
<showUnprintable>1</showUnprintable>
<showFrames>1</showFrames>
<showMargins>0</showMargins>
<metaTag name="arranger"></metaTag>
<metaTag name="composer">Composer</metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="poet"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle">Title</metaTag>
<Part>
<Staff id="1">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
</Staff>
<trackName>Piano</trackName>
<Instrument>
<longName>Piano</longName>
<shortName>Pno.</shortName>
<trackName>Piano</trackName>
<minPitchP>21</minPitchP>
<maxPitchP>108</maxPitchP>
<minPitchA>21</minPitchA>
<maxPitchA>108</maxPitchA>
<clef staff="2">F</clef>
<Articulation>
<velocity>100</velocity>
<gateTime>95</gateTime>
</Articulation>
<Articulation name="staccatissimo">
<velocity>100</velocity>
<gateTime>33</gateTime>
</Articulation>
<Articulation name="staccato">
<velocity>100</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="portato">
<velocity>100</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="tenuto">
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="marcato">
<velocity>120</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="sforzato">
<velocity>150</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="sforzatoStaccato">
<velocity>150</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="marcatoStaccato">
<velocity>120</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="marcatoTenuto">
<velocity>120</velocity>
<gateTime>100</gateTime>
</Articulation>
<Channel>
<program value="0"/>
</Channel>
</Instrument>
</Part>
<Staff id="1">
<VBox>
<height>10</height>
<Text>
<style>Title</style>
<text>VBox</text>
</Text>
</VBox>
<!-- Measure 1 -->
<Measure>
<voice>
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
</TimeSig>
<Rest>
<durationType>measure</durationType>
<duration>4/4</duration>
</Rest>
</voice>
</Measure>
<!-- Measure 2 -->
<Measure>
<voice>
<Rest>
<durationType>measure</durationType>
<duration>4/4</duration>
</Rest>
</voice>
</Measure>
<!-- Measure 3 -->
<Measure>
<voice>
<Rest>
<durationType>measure</durationType>
<duration>4/4</duration>
</Rest>
</voice>
</Measure>
<!-- Measure 4 -->
<Measure>
<voice>
<Rest>
<durationType>measure</durationType>
<duration>4/4</duration>
</Rest>
</voice>
</Measure>
</Staff>
</Score>
</museScore>
Loading

0 comments on commit 3f40a56

Please sign in to comment.