Skip to content

Commit 0f003e8

Browse files
committed
Sort KitList by HW type
That way the grouping makes more sense.
1 parent e901ee0 commit 0f003e8

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

kitmodel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,15 @@ QDataStream &operator>>(QDataStream &in, KitModel &kits)
5454
unsigned int version;
5555
in >> version;
5656

57+
kits.beginResetModel();
58+
5759
if(version == 1)
5860
in >> kits.kits >> kits.nextID;
5961
else
6062
qWarning() << "Unknown KitModel serialization version " << version;
6163

64+
kits.endResetModel();
65+
6266
return in;
6367
}
6468

kitmodel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class KitModel : public QAbstractListModel
1414
Q_OBJECT
1515
public:
1616
enum Role {
17+
NameRole = Qt::DisplayRole,
1718
IDRole = Qt::UserRole + 1,
18-
NameRole,
1919
TypeRole,
2020
FlashRole,
2121
Boot1Role,
@@ -32,7 +32,7 @@ class KitModel : public QAbstractListModel
3232
Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
3333
Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
3434
Q_INVOKABLE bool copy(const int row);
35-
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &) override;
35+
Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
3636
Q_INVOKABLE void addKit(QString name, QString boot1, QString flash, QString snapshot_path);
3737
Q_INVOKABLE QModelIndex indexForID(const unsigned int id) const;
3838
Q_INVOKABLE bool allKitsEmpty() const;

qml/Firebird/UIComponents/KitList.qml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ Rectangle {
1717
width: 1
1818
}
1919

20-
QSortFilterProxyModel {
21-
id: sortedModel
22-
sortRole: KitModel.TypeRole
23-
}
24-
2520
ScrollView {
2621
anchors.margins: parent.border.width
2722
anchors.fill: parent
@@ -37,6 +32,12 @@ Rectangle {
3732
highlightMoveDuration: 50
3833
highlightResizeDuration: 0
3934

35+
QSortFilterProxyModel {
36+
id: sortedModel
37+
sortRole: KitModel.TypeRole
38+
Component.onCompleted: Emu.sortProxyModel(sortedModel, 0)
39+
}
40+
4041
model: sortedModel
4142

4243
highlight: Rectangle {
@@ -45,11 +46,13 @@ Rectangle {
4546
}
4647

4748
delegate: Item {
48-
property variant myData: model
49+
property var myData: model;
4950

5051
height: item.height + 10
5152
width: listView.width - listView.anchors.margins
5253

54+
property int kitIndex: sortedModel.mapToSource(sortedModel.index(index, 0)).row
55+
5356
MouseArea {
5457
anchors.fill: parent
5558
onClicked: function() {
@@ -73,7 +76,6 @@ Rectangle {
7376
id: item
7477
width: parent.width - 15
7578
anchors.centerIn: parent
76-
7779
kitName: name
7880
flashFile: Emu.basename(flash)
7981
stateFile: Emu.basename(snapshot)
@@ -90,7 +92,7 @@ Rectangle {
9092
text: qsTr("Remove")
9193
visible: parent.ListView.view.currentIndex === index && parent.ListView.view.count > 1
9294
onClicked: {
93-
kitModel.removeRows(index, 1)
95+
kitModel.removeRows(kitIndex, 1)
9496
}
9597
}
9698

@@ -107,7 +109,7 @@ Rectangle {
107109
text: qsTr("Copy")
108110
visible: parent.ListView.view.currentIndex === index
109111
onClicked: {
110-
kitModel.copy(index)
112+
kitModel.copy(kitIndex)
111113
}
112114
}
113115
}

qmlbridge.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,14 @@ bool QMLBridge::saveDialogSupported()
483483
return QVersionNumber::fromString(QString::fromUtf8(qVersion())) < QVersionNumber(5, 13);
484484
#else
485485
return true;
486-
#endif
486+
#endif
487+
}
488+
489+
void QMLBridge::sortProxyModel(QObject *model, int column)
490+
{
491+
auto *sortfilterproxymodel = qobject_cast<QSortFilterProxyModel*>(model);
492+
if(sortfilterproxymodel)
493+
sortfilterproxymodel->sort(column);
487494
}
488495

489496
void QMLBridge::speedChanged(double speed)

qmlbridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ class QMLBridge : public QObject
9696

9797
Q_INVOKABLE bool saveDialogSupported();
9898

99+
Q_INVOKABLE void sortProxyModel(QObject *model, int column);
100+
99101
void setActive(bool b);
100102

101103
void notifyButtonStateChanged(int row, int col, bool state);

0 commit comments

Comments
 (0)