fix #11261: improved logic for inserting measures

This commit is contained in:
Daniel 2013-04-13 16:53:44 -05:00
parent 958449d646
commit 3ccfc359f4
6 changed files with 70 additions and 10 deletions

View file

@ -1559,6 +1559,34 @@ bool Element::isText() const
|| type() == TEMPO_TEXT; || 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 // undoSetColor
//--------------------------------------------------------- //---------------------------------------------------------

View file

@ -314,6 +314,8 @@ class Element : public QObject {
virtual void setScore(Score* s) { _score = s; } virtual void setScore(Score* s) { _score = s; }
Element* parent() const { return _parent; } Element* parent() const { return _parent; }
void setParent(Element* e) { _parent = e; } void setParent(Element* e) { _parent = e; }
Element* parentChordRest();
Element* findMeasure();
qreal spatium() const; qreal spatium() const;

View file

@ -182,6 +182,21 @@ ChordRest* Selection::lastChordRest(int track) const
return cr; 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 // deselectAll
//--------------------------------------------------------- //---------------------------------------------------------

View file

@ -86,6 +86,7 @@ class Selection {
Element* element() const; Element* element() const;
ChordRest* firstChordRest(int track = -1) const; ChordRest* firstChordRest(int track = -1) const;
ChordRest* lastChordRest(int track = -1) const; ChordRest* lastChordRest(int track = -1) const;
Measure* findMeasure() const;
void update(); void update();
void updateState(); void updateState();
void dump(); void dump();

View file

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

View file

@ -4858,17 +4858,23 @@ void ScoreView::appendMeasures(int n, Element::ElementType type)
MeasureBase* ScoreView::checkSelectionStateForInsertMeasure() MeasureBase* ScoreView::checkSelectionStateForInsertMeasure()
{ {
if (_score->selection().state() == SEL_RANGE) { MeasureBase* mb = 0;
MeasureBase* mb = _score->selection().startSegment()->measure(); if (_score->selection().state() == SEL_RANGE) {
mb = _score->selection().startSegment()->measure();
return mb; return mb;
} }
mb = _score->selection().findMeasure();
if (mb)
return static_cast<MeasureBase*>(mb);
Element* e = _score->selection().element(); Element* e = _score->selection().element();
if (e) { if (e) {
if (e->type() == Element::VBOX || e->type() == Element::TBOX) if (e->type() == Element::VBOX || e->type() == Element::TBOX)
return static_cast<MeasureBase*>(e); return static_cast<MeasureBase*>(e);
} }
QMessageBox::warning(0, "MuseScore", QMessageBox::warning(0, "MuseScore",
tr("No Measure selected:\n" "please select a measure and try again")); tr("No measure selected:\n" "Please select a measure and try again"));
return 0; return 0;
} }
@ -4882,9 +4888,10 @@ void ScoreView::cmdInsertMeasures(int n, Element::ElementType type)
if (!mb) if (!mb)
return; return;
_score->startCmd(); _score->startCmd();
for (int i = 0; i < n; ++i) for (int i = 0; i < n; ++i)
mb = _score->insertMeasure(type, mb); mb = _score->insertMeasure(type, mb);
_score->select(0, SELECT_SINGLE, 0); if (mb)
_score->select(mb, SELECT_SINGLE, 0);
_score->endCmd(); _score->endCmd();
} }
@ -4907,7 +4914,8 @@ void ScoreView::cmdInsertMeasure(Element::ElementType type)
startEdit(s); startEdit(s);
return; return;
} }
_score->select(0, SELECT_SINGLE, 0); if (mb)
_score->select(mb, SELECT_SINGLE, 0);
_score->endCmd(); _score->endCmd();
} }