Skip to content

Commit

Permalink
fix #11261: improved logic for inserting measures
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgarthur committed Apr 13, 2013
1 parent 958449d commit 3ccfc35
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
28 changes: 28 additions & 0 deletions libmscore/element.cpp
Expand Up @@ -1559,6 +1559,34 @@ bool Element::isText() const
|| type() == TEMPO_TEXT;
}

//---------------------------------------------------------
// parentChordRest
//---------------------------------------------------------

Element* Element::parentChordRest()
{
if (isChordRest())
return this;
else if (_parent)
return _parent->parentChordRest();
else
return 0;
}

//---------------------------------------------------------
// parentChordRest
//---------------------------------------------------------

Element* Element::findMeasure()
{
if (type() == MEASURE)
return this;
else if (_parent)
return _parent->findMeasure();
else
return 0;
}

//---------------------------------------------------------
// undoSetColor
//---------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions libmscore/element.h
Expand Up @@ -314,6 +314,8 @@ class Element : public QObject {
virtual void setScore(Score* s) { _score = s; }
Element* parent() const { return _parent; }
void setParent(Element* e) { _parent = e; }
Element* parentChordRest();
Element* findMeasure();

qreal spatium() const;

Expand Down
15 changes: 15 additions & 0 deletions libmscore/select.cpp
Expand Up @@ -182,6 +182,21 @@ ChordRest* Selection::lastChordRest(int track) const
return cr;
}

//---------------------------------------------------------
// findMeasure
//---------------------------------------------------------


Measure* Selection::findMeasure() const
{
Measure *m = 0;
if (_el.size() >= 1) {
Element* el = _el[0];
m = static_cast<Measure*>(el->findMeasure());
}
return m;
}

//---------------------------------------------------------
// deselectAll
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions libmscore/select.h
Expand Up @@ -86,6 +86,7 @@ class Selection {
Element* element() const;
ChordRest* firstChordRest(int track = -1) const;
ChordRest* lastChordRest(int track = -1) const;
Measure* findMeasure() const;
void update();
void updateState();
void dump();
Expand Down
12 changes: 9 additions & 3 deletions mscore/musescore.cpp
Expand Up @@ -143,10 +143,16 @@ extern void qt_mac_set_menubar_icons(bool b);

void MuseScore::cmdInsertMeasures()
{
if (cs) {
insertMeasuresDialog = new InsertMeasuresDialog;
insertMeasuresDialog->show();
if (cs) {
if (cs->selection().state() == SEL_NONE && !cs->selection().findMeasure()) {
QMessageBox::warning(0, "MuseScore",
tr("No measure selected:\n" "Please select a measure and try again"));
}
else {
insertMeasuresDialog = new InsertMeasuresDialog;
insertMeasuresDialog->show();
}
}
}

//---------------------------------------------------------
Expand Down
22 changes: 15 additions & 7 deletions mscore/scoreview.cpp
Expand Up @@ -4858,17 +4858,23 @@ void ScoreView::appendMeasures(int n, Element::ElementType type)

MeasureBase* ScoreView::checkSelectionStateForInsertMeasure()
{
if (_score->selection().state() == SEL_RANGE) {
MeasureBase* mb = _score->selection().startSegment()->measure();
MeasureBase* mb = 0;
if (_score->selection().state() == SEL_RANGE) {
mb = _score->selection().startSegment()->measure();
return mb;
}

mb = _score->selection().findMeasure();
if (mb)
return static_cast<MeasureBase*>(mb);

Element* e = _score->selection().element();
if (e) {
if (e->type() == Element::VBOX || e->type() == Element::TBOX)
return static_cast<MeasureBase*>(e);
}
QMessageBox::warning(0, "MuseScore",
tr("No Measure selected:\n" "please select a measure and try again"));
QMessageBox::warning(0, "MuseScore",
tr("No measure selected:\n" "Please select a measure and try again"));
return 0;
}

Expand All @@ -4882,9 +4888,10 @@ void ScoreView::cmdInsertMeasures(int n, Element::ElementType type)
if (!mb)
return;
_score->startCmd();
for (int i = 0; i < n; ++i)
for (int i = 0; i < n; ++i)
mb = _score->insertMeasure(type, mb);
_score->select(0, SELECT_SINGLE, 0);
if (mb)
_score->select(mb, SELECT_SINGLE, 0);
_score->endCmd();
}

Expand All @@ -4907,7 +4914,8 @@ void ScoreView::cmdInsertMeasure(Element::ElementType type)
startEdit(s);
return;
}
_score->select(0, SELECT_SINGLE, 0);
if (mb)
_score->select(mb, SELECT_SINGLE, 0);
_score->endCmd();
}

Expand Down

0 comments on commit 3ccfc35

Please sign in to comment.