diff --git a/kitmodel.cpp b/kitmodel.cpp index a5c9cfec..fb97e0f2 100644 --- a/kitmodel.cpp +++ b/kitmodel.cpp @@ -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; } diff --git a/kitmodel.h b/kitmodel.h index 935de021..4e1e776f 100644 --- a/kitmodel.h +++ b/kitmodel.h @@ -14,8 +14,8 @@ class KitModel : public QAbstractListModel Q_OBJECT public: enum Role { + NameRole = Qt::DisplayRole, IDRole = Qt::UserRole + 1, - NameRole, TypeRole, FlashRole, Boot1Role, @@ -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; diff --git a/qml/ConfigPageEmulation.qml b/qml/ConfigPageEmulation.qml index cb918284..aeb67da5 100644 --- a/qml/ConfigPageEmulation.qml +++ b/qml/ConfigPageEmulation.qml @@ -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; }); } } diff --git a/qml/Firebird/UIComponents/KitList.qml b/qml/Firebird/UIComponents/KitList.qml index e204c137..7acff984 100644 --- a/qml/Firebird/UIComponents/KitList.qml +++ b/qml/Firebird/UIComponents/KitList.qml @@ -17,11 +17,6 @@ Rectangle { width: 1 } - QSortFilterProxyModel { - id: sortedModel - sortRole: KitModel.TypeRole - } - ScrollView { anchors.margins: parent.border.width anchors.fill: parent @@ -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 { @@ -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() { @@ -72,7 +75,6 @@ Rectangle { id: item width: parent.width - 15 anchors.centerIn: parent - kitName: name flashFile: Emu.basename(flash) stateFile: Emu.basename(snapshot) @@ -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) } } @@ -106,7 +108,7 @@ Rectangle { text: qsTr("Copy") visible: parent.ListView.view.currentIndex === index onClicked: { - kitModel.copy(index) + kitModel.copy(kitIndex) } } } diff --git a/qmlbridge.cpp b/qmlbridge.cpp index 85da2005..0fbb8ead 100644 --- a/qmlbridge.cpp +++ b/qmlbridge.cpp @@ -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(model); + if(sortfilterproxymodel) + sortfilterproxymodel->sort(column); } void QMLBridge::speedChanged(double speed) diff --git a/qmlbridge.h b/qmlbridge.h index c3a95fe0..65b1c327 100644 --- a/qmlbridge.h +++ b/qmlbridge.h @@ -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);