bool operator instead of optional + qobject_cast

This commit is contained in:
allejok96
2022-07-03 17:21:10 +02:00
parent 8cb41f01d8
commit 98c56a96cf
3 changed files with 13 additions and 9 deletions

View File

@@ -253,16 +253,22 @@ private:
typedef QVector<Note *> NoteVector;
/*! \brief Bounding box of notes
*
* Defaults to all zero, and will in that case evaluate to false if converted to bool.
*/
struct NoteBounds
{
TimePos start;
TimePos end;
int lowest;
int highest;
operator bool() { return start.getTicks() || end.getTicks() || lowest || highest; }
};
std::optional<NoteBounds> boundsForNotes(const NoteVector& notes);
NoteBounds boundsForNotes(const NoteVector& notes);
} // namespace lmms

View File

@@ -240,12 +240,10 @@ bool Note::withinRange(int tickStart, int tickEnd) const
/*! \brief Get the start/end/bottom/top positions of notes in a vector
*
* Returns no value if there are no notes
*/
std::optional<NoteBounds> boundsForNotes(const NoteVector& notes)
NoteBounds boundsForNotes(const NoteVector& notes)
{
if (notes.empty()) { return {}; }
if (notes.empty()) { return NoteBounds(); }
TimePos start = notes.front()->pos();
TimePos end = start;

View File

@@ -155,12 +155,12 @@ void MidiClipView::transposeSelection()
int lowest = NumKeys - 1;
for (ClipView* clipview: selection)
{
if (auto mcv = dynamic_cast<MidiClipView*>(clipview))
if (auto mcv = qobject_cast<MidiClipView*>(clipview))
{
if (auto bounds = boundsForNotes(mcv->getMidiClip()->notes()))
{
lowest = std::min(bounds->lowest, lowest);
highest = std::max(bounds->highest, highest);
lowest = std::min(bounds.lowest, lowest);
highest = std::max(bounds.highest, highest);
}
}
}
@@ -176,7 +176,7 @@ void MidiClipView::transposeSelection()
QSet<Track*> m_changedTracks;
for (ClipView* clipview: selection)
{
auto mcv = dynamic_cast<MidiClipView*>(clipview);
auto mcv = qobject_cast<MidiClipView*>(clipview);
if (!mcv) { continue; }
auto clip = mcv->getMidiClip();