Skip to content

Commit

Permalink
fix #186386: pitches in Edit Drumset not sorted in numeric order
Browse files Browse the repository at this point in the history
  • Loading branch information
lasconic committed Apr 11, 2017
1 parent 4ca351e commit 84cfe04
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions mscore/editdrumset.cpp
Expand Up @@ -52,6 +52,18 @@ const char* noteHeadNames[int(NoteHead::Group::HEAD_GROUPS)] = {
QT_TRANSLATE_NOOP("EditDrumset", "Ti"),
};

//---------------------------------------------------------
// operator<
//---------------------------------------------------------

bool EditDrumsetTreeWidgetItem::operator<(const QTreeWidgetItem & other) const
{
if (treeWidget()->sortColumn() == Column::PITCH)
return data(Column::PITCH, Qt::UserRole) < other.data(Column::PITCH, Qt::UserRole);
else
return text(treeWidget()->sortColumn()) < other.text(treeWidget()->sortColumn());
}

//---------------------------------------------------------
// EditDrumset
//---------------------------------------------------------
Expand Down Expand Up @@ -101,7 +113,7 @@ void EditDrumset::updateList()
{
pitchList->clear();
for (int i = 0; i < 128; ++i) {
QTreeWidgetItem* item = new QTreeWidgetItem(pitchList);
QTreeWidgetItem* item = new EditDrumsetTreeWidgetItem(pitchList);
item->setText(Column::PITCH, QString("%1").arg(i));
item->setText(Column::NOTE, pitch2string(i));
if (nDrumset.shortcut(i) == 0)
Expand All @@ -111,7 +123,7 @@ void EditDrumset::updateList()
item->setText(Column::SHORTCUT, s);
}
item->setText(Column::NAME, qApp->translate("drumset", nDrumset.name(i).toUtf8().constData()));
item->setData(0, Qt::UserRole, i);
item->setData(Column::PITCH, Qt::UserRole, i);
}
pitchList->sortItems(3, Qt::SortOrder::DescendingOrder);
}
Expand Down
7 changes: 7 additions & 0 deletions mscore/editdrumset.h
Expand Up @@ -57,6 +57,13 @@ class EditDrumset : public QDialog, private Ui::EditDrumsetBase {
};


class EditDrumsetTreeWidgetItem : public QTreeWidgetItem {
public:
EditDrumsetTreeWidgetItem(QTreeWidget * parent)
: QTreeWidgetItem(parent) {};
virtual bool operator<(const QTreeWidgetItem & other) const;
};


} // namespace Ms
#endif
Expand Down

0 comments on commit 84cfe04

Please sign in to comment.