Skip to content

Commit

Permalink
Sort KitList by HW type
Browse files Browse the repository at this point in the history
That way the grouping makes more sense.
  • Loading branch information
Vogtinator committed Aug 26, 2020
1 parent 523afe4 commit 1ab4998
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions kitmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ QDataStream &operator>>(QDataStream &in, KitModel &kits)
unsigned int version;
in >> version;

kits.beginResetModel();

if(version == 1)
in >> kits.kits >> kits.nextID;
else
qWarning() << "Unknown KitModel serialization version " << version;

kits.endResetModel();

return in;
}

Expand Down
4 changes: 2 additions & 2 deletions kitmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class KitModel : public QAbstractListModel
Q_OBJECT
public:
enum Role {
NameRole = Qt::DisplayRole,
IDRole = Qt::UserRole + 1,
NameRole,
TypeRole,
FlashRole,
Boot1Role,
Expand All @@ -32,7 +32,7 @@ class KitModel : public QAbstractListModel
Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Q_INVOKABLE bool copy(const int row);
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &) override;
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
Q_INVOKABLE void addKit(QString name, QString boot1, QString flash, QString snapshot_path);
Q_INVOKABLE QModelIndex indexForID(const unsigned int id) const;
Q_INVOKABLE bool allKitsEmpty() const;
Expand Down
2 changes: 1 addition & 1 deletion qml/ConfigPageEmulation.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ColumnLayout {
model: Emu.kits
currentIndex: model.indexForID(Emu.defaultKit).row
onCurrentIndexChanged: {
Emu.defaultKit = model.data(model.index(currentIndex, 0, null), KitModel.IDRole);
Emu.defaultKit = model.data(model.index(currentIndex, 0), KitModel.IDRole);
currentIndex = Qt.binding(function() { return model.indexForID(Emu.defaultKit).row; });
}
}
Expand Down
20 changes: 11 additions & 9 deletions qml/Firebird/UIComponents/KitList.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ Rectangle {
width: 1
}

QSortFilterProxyModel {
id: sortedModel
sortRole: KitModel.TypeRole
}

ScrollView {
anchors.margins: parent.border.width
anchors.fill: parent
Expand All @@ -35,6 +30,12 @@ Rectangle {
highlightMoveDuration: 50
highlightResizeDuration: 0

QSortFilterProxyModel {
id: sortedModel
sortRole: KitModel.TypeRole
Component.onCompleted: Emu.sortProxyModel(sortedModel, 0)
}

model: sortedModel

highlight: Rectangle {
Expand All @@ -43,12 +44,14 @@ Rectangle {
}

delegate: Item {
property variant myData: model
property var myData: model;

height: item.height + 10
width: listView.width - listView.anchors.margins
anchors.horizontalCenter: parent.horizontalCenter

property int kitIndex: sortedModel.mapToSource(sortedModel.index(index, 0)).row

MouseArea {
anchors.fill: parent
onClicked: function() {
Expand All @@ -72,7 +75,6 @@ Rectangle {
id: item
width: parent.width - 15
anchors.centerIn: parent

kitName: name
flashFile: Emu.basename(flash)
stateFile: Emu.basename(snapshot)
Expand All @@ -89,7 +91,7 @@ Rectangle {
text: qsTr("Remove")
visible: parent.ListView.view.currentIndex === index && parent.ListView.view.count > 1
onClicked: {
kitModel.removeRows(index, 1)
kitModel.removeRows(kitIndex, 1)
}
}

Expand All @@ -106,7 +108,7 @@ Rectangle {
text: qsTr("Copy")
visible: parent.ListView.view.currentIndex === index
onClicked: {
kitModel.copy(index)
kitModel.copy(kitIndex)
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion qmlbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,14 @@ bool QMLBridge::saveDialogSupported()
return QVersionNumber::fromString(QString::fromUtf8(qVersion())) < QVersionNumber(5, 13);
#else
return true;
#endif
#endif
}

void QMLBridge::sortProxyModel(QObject *model, int column)
{
auto *sortfilterproxymodel = qobject_cast<QSortFilterProxyModel*>(model);
if(sortfilterproxymodel)
sortfilterproxymodel->sort(column);
}

void QMLBridge::speedChanged(double speed)
Expand Down
2 changes: 2 additions & 0 deletions qmlbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class QMLBridge : public QObject

Q_INVOKABLE bool saveDialogSupported();

Q_INVOKABLE void sortProxyModel(QObject *model, int column);

void setActive(bool b);

void notifyButtonStateChanged(int row, int col, bool state);
Expand Down

0 comments on commit 1ab4998

Please sign in to comment.