From 3ccfc359f41dcd70d9fcf6e2dccaa20397decf92 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 13 Apr 2013 16:53:44 -0500 Subject: [PATCH] fix #11261: improved logic for inserting measures --- libmscore/element.cpp | 28 ++++++++++++++++++++++++++++ libmscore/element.h | 2 ++ libmscore/select.cpp | 15 +++++++++++++++ libmscore/select.h | 1 + mscore/musescore.cpp | 12 +++++++++--- mscore/scoreview.cpp | 22 +++++++++++++++------- 6 files changed, 70 insertions(+), 10 deletions(-) diff --git a/libmscore/element.cpp b/libmscore/element.cpp index 869eaf600d..aa2e22c0bf 100644 --- a/libmscore/element.cpp +++ b/libmscore/element.cpp @@ -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 //--------------------------------------------------------- diff --git a/libmscore/element.h b/libmscore/element.h index 780320c2c0..b151a10c77 100644 --- a/libmscore/element.h +++ b/libmscore/element.h @@ -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; diff --git a/libmscore/select.cpp b/libmscore/select.cpp index 57b6bd563f..9c6e3a7376 100644 --- a/libmscore/select.cpp +++ b/libmscore/select.cpp @@ -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(el->findMeasure()); + } + return m; + } + //--------------------------------------------------------- // deselectAll //--------------------------------------------------------- diff --git a/libmscore/select.h b/libmscore/select.h index bd650f786c..723aa65133 100644 --- a/libmscore/select.h +++ b/libmscore/select.h @@ -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(); diff --git a/mscore/musescore.cpp b/mscore/musescore.cpp index e0a818ac43..891c853dd8 100644 --- a/mscore/musescore.cpp +++ b/mscore/musescore.cpp @@ -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(); + } + } } //--------------------------------------------------------- diff --git a/mscore/scoreview.cpp b/mscore/scoreview.cpp index fc4aa99257..4343fa1199 100644 --- a/mscore/scoreview.cpp +++ b/mscore/scoreview.cpp @@ -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(mb); + Element* e = _score->selection().element(); if (e) { if (e->type() == Element::VBOX || e->type() == Element::TBOX) return static_cast(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; } @@ -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(); } @@ -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(); }