diff --git a/kitmodel.cpp b/kitmodel.cpp index 333383e2..fb9da95d 100644 --- a/kitmodel.cpp +++ b/kitmodel.cpp @@ -54,11 +54,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; } @@ -81,12 +85,8 @@ QHash KitModel::roleNames() const QVariant KitModel::data(const QModelIndex &index, int role) const { - return getDataRow(index.row(), role); -} - -QVariant KitModel::getDataRow(const int row, int role) const -{ - if(row < 0 || row >= kits.count()) + int row = index.row(); + if(!index.isValid() || row < 0 || row >= kits.count()) return QVariant(); switch(role) @@ -108,9 +108,10 @@ QVariant KitModel::getDataRow(const int row, int role) const } } -bool KitModel::setDataRow(const int row, const QVariant &value, int role) +bool KitModel::setData(const QModelIndex &index, const QVariant &value, int role) { - if(row < 0 || row >= kits.count()) + int row = index.row(); + if(!index.isValid() || row < 0 || row >= kits.count()) return false; switch(role) @@ -142,10 +143,10 @@ bool KitModel::setDataRow(const int row, const QVariant &value, int role) { // Refresh type as well kits[row].type = typeForFlash(value.toString()); - emit dataChanged(index(row), index(row), QVector({FlashRole, TypeRole})); + emit dataChanged(index, index, QVector({FlashRole, TypeRole})); } else - emit dataChanged(index(row), index(row), QVector({role})); + emit dataChanged(index, index, QVector({role})); emit anythingChanged(); return true; @@ -166,17 +167,18 @@ bool KitModel::copy(const int row) return true; } -bool KitModel::remove(const int row) +bool KitModel::removeRows(int row, int count, const QModelIndex &) { - if(row < 0 || row >= kits.count()) + if(row < 0 || row + count - 1 >= kits.count() || count < 1) return false; // Do not remove the last remaining kit - if(kits.count() == 1) + if(kits.count() == count) return false; - beginRemoveRows({}, row, row); - kits.removeAt(row); + beginRemoveRows({}, row, row + count - 1); + while(count--) + kits.removeAt(row); endRemoveRows(); emit anythingChanged(); @@ -194,11 +196,11 @@ void KitModel::addKit(QString name, QString boot1, QString flash, QString snapsh emit anythingChanged(); } -int KitModel::indexForID(const unsigned int id) +QModelIndex KitModel::indexForID(const unsigned int id) const { auto it = std::find_if(kits.begin(), kits.end(), [&] (const Kit &kit) { return kit.id == id; }); - return it == kits.end() ? -1 : (it - kits.begin()); + return it == kits.end() ? QModelIndex() : index(it - kits.begin()); } bool KitModel::allKitsEmpty() const diff --git a/kitmodel.h b/kitmodel.h index 460fad8f..0da29572 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, @@ -30,12 +30,11 @@ class KitModel : public QAbstractListModel Q_INVOKABLE virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override; Q_INVOKABLE virtual QHash roleNames() const override; Q_INVOKABLE virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; - Q_INVOKABLE QVariant getDataRow(const int row, int role = Qt::DisplayRole) const; - Q_INVOKABLE bool setDataRow(const int row, const QVariant &value, int role = Qt::EditRole); + 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 remove(const int row); + 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 int indexForID(const unsigned int id); + Q_INVOKABLE QModelIndex indexForID(const unsigned int id) const; Q_INVOKABLE bool allKitsEmpty() const; QString typeForFlash(QString flash); diff --git a/main.cpp b/main.cpp index 53a2b312..bee33d33 100644 --- a/main.cpp +++ b/main.cpp @@ -120,6 +120,8 @@ int main(int argc, char **argv) qmlRegisterType("Firebird.Emu", 1, 0, "EmuScreen"); // Register KitModel qmlRegisterType("Firebird.Emu", 1, 0, "KitModel"); + // Register Qt's stuff + qmlRegisterType("Firebird.Emu", 1, 0, "QSortFilterProxyModel"); #ifndef MOBILE_UI MainWindow mw; diff --git a/mainwindow.cpp b/mainwindow.cpp index 376718a4..f3eebb13 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -821,16 +821,16 @@ void MainWindow::refillKitMenus() action = ui->menuBoot_Diags_with_Kit->addAction(kit.name); action->setData(kit.id); connect(action, SIGNAL(triggered()), this, SLOT(startKitDiags())); - } + } } void MainWindow::updateWindowTitle() { // Need to update window title if kit is active - int kitIndex = the_qml_bridge->kitIndexForID(the_qml_bridge->getCurrentKitId()); - if(kitIndex >= 0) + const QModelIndex kitIndex = the_qml_bridge->getKitModel()->indexForID(the_qml_bridge->getCurrentKitId()); + if(kitIndex.isValid()) { - auto name = the_qml_bridge->getKitModel()->getKits()[kitIndex].name; + auto name = the_qml_bridge->getKitModel()->data(kitIndex, KitModel::NameRole).toString(); setWindowTitle(tr("Firebird Emu - %1").arg(name)); } else diff --git a/qml/ConfigPageEmulation.qml b/qml/ConfigPageEmulation.qml index 210bae58..aeb67da5 100644 --- a/qml/ConfigPageEmulation.qml +++ b/qml/ConfigPageEmulation.qml @@ -47,10 +47,10 @@ ColumnLayout { Layout.maximumWidth: parent.parent.width * 0.4 textRole: "name" model: Emu.kits - currentIndex: Emu.kitIndexForID(Emu.defaultKit) + currentIndex: model.indexForID(Emu.defaultKit).row onCurrentIndexChanged: { - Emu.defaultKit = model.getDataRow(currentIndex, KitModel.IDRole); - currentIndex = Qt.binding(function() { return Emu.kitIndexForID(Emu.defaultKit); }); + Emu.defaultKit = model.data(model.index(currentIndex, 0), KitModel.IDRole); + currentIndex = Qt.binding(function() { return model.indexForID(Emu.defaultKit).row; }); } } } diff --git a/qml/ConfigPageKits.qml b/qml/ConfigPageKits.qml index e860b46a..fbeb8279 100644 --- a/qml/ConfigPageKits.qml +++ b/qml/ConfigPageKits.qml @@ -53,7 +53,7 @@ ColumnLayout { text: kitList.currentItem.myData.name onTextChanged: { if(text !== kitList.currentItem.myData.name) - kitModel.setDataRow(kitList.currentIndex, text, KitModel.NameRole); + kitList.currentItem.myData.name = text; text = Qt.binding(function() { return kitList.currentItem.myData.name; }); } } @@ -69,7 +69,7 @@ ColumnLayout { filePath: kitList.currentItem.myData.boot1 onFilePathChanged: { if(filePath !== kitList.currentItem.myData.boot1) - kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.Boot1Role); + kitList.currentItem.myData.boot1 = filePath; filePath = Qt.binding(function() { return kitList.currentItem.myData.boot1; }); } } @@ -85,7 +85,7 @@ ColumnLayout { filePath: kitList.currentItem.myData.flash onFilePathChanged: { if(filePath !== kitList.currentItem.myData.flash) - kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole); + kitList.currentItem.myData.flash = filePath; filePath = Qt.binding(function() { return kitList.currentItem.myData.flash; }); } showCreateButton: true @@ -95,7 +95,7 @@ ColumnLayout { FlashDialog { id: flashDialog onFlashCreated: { - kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.FlashRole); + kitList.currentItem.myData.flash = filePath; } } @@ -111,7 +111,7 @@ ColumnLayout { filePath: kitList.currentItem.myData.snapshot onFilePathChanged: { if(filePath !== kitList.currentItem.myData.snapshot) - kitModel.setDataRow(kitList.currentIndex, filePath, KitModel.SnapshotRole); + kitList.currentItem.myData.snapshot = filePath; filePath = Qt.binding(function() { return kitList.currentItem.myData.snapshot; }); } } diff --git a/qml/Firebird/UIComponents/KitList.qml b/qml/Firebird/UIComponents/KitList.qml index 022ef059..2664bbc4 100644 --- a/qml/Firebird/UIComponents/KitList.qml +++ b/qml/Firebird/UIComponents/KitList.qml @@ -5,7 +5,7 @@ import Firebird.Emu 1.0 Rectangle { property alias currentItem: listView.currentItem property alias currentIndex: listView.currentIndex - property alias kitModel: listView.model + property alias kitModel: sortedModel.sourceModel SystemPalette { id: paletteActive @@ -32,17 +32,27 @@ Rectangle { highlightMoveDuration: 50 highlightResizeDuration: 0 + QSortFilterProxyModel { + id: sortedModel + sortRole: KitModel.TypeRole + Component.onCompleted: Emu.sortProxyModel(sortedModel, 0) + } + + model: sortedModel + highlight: Rectangle { color: paletteActive.highlight anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined } delegate: Item { - property variant myData: model + property var myData: model; height: item.height + 10 width: listView.width - listView.anchors.margins + property int kitIndex: sortedModel.mapToSource(sortedModel.index(index, 0)).row + MouseArea { anchors.fill: parent onClicked: function() { @@ -66,7 +76,6 @@ Rectangle { id: item width: parent.width - 15 anchors.centerIn: parent - kitName: name flashFile: Emu.basename(flash) stateFile: Emu.basename(snapshot) @@ -83,7 +92,7 @@ Rectangle { text: qsTr("Remove") visible: parent.ListView.view.currentIndex === index && parent.ListView.view.count > 1 onClicked: { - kitModel.remove(index) + kitModel.removeRows(kitIndex, 1) } } @@ -100,7 +109,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 98981265..fc03109f 100644 --- a/qmlbridge.cpp +++ b/qmlbridge.cpp @@ -28,7 +28,7 @@ QMLBridge::QMLBridge(QObject *parent) : QObject(parent) //Migrate old settings if(settings.contains(QStringLiteral("usbdir")) && !settings.contains(QStringLiteral("usbdirNew"))) - setUSBDir(QStringLiteral("/") + settings.value(QStringLiteral("usbdir")).toString()); + settings.setValue(QStringLiteral("usbdirNew"), QStringLiteral("/") + settings.value(QStringLiteral("usbdir")).toString()); bool add_default_kit = false; @@ -56,10 +56,75 @@ QMLBridge::QMLBridge(QObject *parent) : QObject(parent) } // Same for debug_on_* - debug_on_start = getDebugOnStart(); - debug_on_warn = getDebugOnWarn(); - - print_on_warn = getPrintOnWarn(); + ::debug_on_start = debug_on_start = settings.value(QStringLiteral("debugOnStart"), false).toBool();; + connect(this, &QMLBridge::debugOnStartChanged, [&] { + ::debug_on_start = debug_on_start; + settings.setValue(QStringLiteral("debugOnStart"), debug_on_start); + }); + + ::debug_on_warn = debug_on_warn = settings.value(QStringLiteral("debugOnWarn"), !isMobile()).toBool(); + connect(this, &QMLBridge::debugOnWarnChanged, [&] { + ::debug_on_warn = debug_on_warn; + settings.setValue(QStringLiteral("debugOnWarn"), debug_on_warn); + }); + + ::print_on_warn = print_on_warn = settings.value(QStringLiteral("printOnWarn"), true).toBool(); + connect(this, &QMLBridge::printOnWarnChanged, [&] { + ::print_on_warn = print_on_warn; + settings.setValue(QStringLiteral("printOnWarn"), print_on_warn); + }); + + gdb_port = settings.value(QStringLiteral("gdbPort"), 3333).toInt();; + connect(this, &QMLBridge::gdbPortChanged, + [&] { settings.setValue(QStringLiteral("gdbPort"), gdb_port); }); + + gdb_enabled = settings.value(QStringLiteral("gdbEnabled"), !isMobile()).toBool(); + connect(this, &QMLBridge::gdbEnabledChanged, + [&] { settings.setValue(QStringLiteral("gdbEnabled"), gdb_enabled); }); + + rdb_enabled = settings.value(QStringLiteral("rdbgEnabled"), !isMobile()).toBool(); + connect(this, &QMLBridge::rdbEnabledChanged, + [&] { settings.setValue(QStringLiteral("rdbgEnabled"), rdb_enabled); }); + + rdb_port = settings.value(QStringLiteral("rdbgPort"), 3334).toInt(); + connect(this, &QMLBridge::rdbPortChanged, + [&] { settings.setValue(QStringLiteral("rdbgPort"), rdb_port); }); + + autostart = settings.value(QStringLiteral("emuAutostart"), true).toBool(); + connect(this, &QMLBridge::autostartChanged, + [&] { settings.setValue(QStringLiteral("emuAutostart"), autostart); }); + + default_kit_id = settings.value(QStringLiteral("defaultKit"), 0).toUInt(); + connect(this, &QMLBridge::defaultKitChanged, + [&] { settings.setValue(QStringLiteral("defaultKit"), default_kit_id); }); + + left_handed = settings.value(QStringLiteral("leftHanded"), false).toBool(); + connect(this, &QMLBridge::leftHandedChanged, + [&] { settings.setValue(QStringLiteral("leftHanded"), left_handed); }); + + suspend_on_close = settings.value(QStringLiteral("suspendOnClose"), true).toBool(); + connect(this, &QMLBridge::suspendOnCloseChanged, + [&] { settings.setValue(QStringLiteral("suspendOnClose"), suspend_on_close); }); + + usb_dir = settings.value(QStringLiteral("usbdirNew"), QStringLiteral("/ndless")).toString(); + connect(this, &QMLBridge::usbDirChanged, + [&] { settings.setValue(QStringLiteral("usbdirNew"), usb_dir); }); + + mobile_x = settings.value(QStringLiteral("mobileX"), -1).toInt(); + connect(this, &QMLBridge::mobileXChanged, + [&] { settings.setValue(QStringLiteral("mobileX"), mobile_x); }); + + mobile_y = settings.value(QStringLiteral("mobileY"), -1).toInt(); + connect(this, &QMLBridge::mobileYChanged, + [&] { settings.setValue(QStringLiteral("mobileY"), mobile_y); }); + + mobile_w = settings.value(QStringLiteral("mobileWidth"), -1).toInt(); + connect(this, &QMLBridge::mobileWChanged, + [&] { settings.setValue(QStringLiteral("mobileWidth"), mobile_w); }); + + mobile_h = settings.value(QStringLiteral("mobileHeight"), -1).toInt(); + connect(this, &QMLBridge::mobileHChanged, + [&] { settings.setValue(QStringLiteral("mobileHeight"), mobile_h); }); connect(&kit_model, SIGNAL(anythingChanged()), this, SLOT(saveKits()), Qt::QueuedConnection); @@ -69,177 +134,6 @@ QMLBridge::QMLBridge(QObject *parent) : QObject(parent) QMLBridge::~QMLBridge() {} -unsigned int QMLBridge::getGDBPort() -{ - return settings.value(QStringLiteral("gdbPort"), 3333).toInt(); -} - -void QMLBridge::setGDBPort(unsigned int port) -{ - if(getGDBPort() == port) - return; - - settings.setValue(QStringLiteral("gdbPort"), port); - emit gdbPortChanged(); -} - -bool QMLBridge::getGDBEnabled() -{ - return settings.value(QStringLiteral("gdbEnabled"), !isMobile()).toBool(); -} - -void QMLBridge::setGDBEnabled(bool e) -{ - if(getGDBEnabled() == e) - return; - - settings.setValue(QStringLiteral("gdbEnabled"), e); - emit gdbEnabledChanged(); -} - -unsigned int QMLBridge::getRDBPort() -{ - return settings.value(QStringLiteral("rdbgPort"), 3334).toInt(); -} - -void QMLBridge::setRDBPort(unsigned int port) -{ - if(getRDBPort() == port) - return; - - settings.setValue(QStringLiteral("rdbgPort"), port); - emit rdbPortChanged(); -} - -bool QMLBridge::getRDBEnabled() -{ - return settings.value(QStringLiteral("rdbgEnabled"), !isMobile()).toBool(); -} - -void QMLBridge::setRDBEnabled(bool e) -{ - if(getRDBEnabled() == e) - return; - - settings.setValue(QStringLiteral("rdbgEnabled"), e); - emit rdbEnabledChanged(); -} - -bool QMLBridge::getDebugOnWarn() -{ - return settings.value(QStringLiteral("debugOnWarn"), !isMobile()).toBool(); -} - -void QMLBridge::setDebugOnWarn(bool e) -{ - if(getDebugOnWarn() == e) - return; - - debug_on_warn = e; - settings.setValue(QStringLiteral("debugOnWarn"), e); - emit debugOnWarnChanged(); -} - -bool QMLBridge::getDebugOnStart() -{ - return settings.value(QStringLiteral("debugOnStart"), false).toBool(); -} - -void QMLBridge::setDebugOnStart(bool e) -{ - if(getDebugOnStart() == e) - return; - - debug_on_start = e; - settings.setValue(QStringLiteral("debugOnStart"), e); - emit debugOnStartChanged(); -} - -void QMLBridge::setPrintOnWarn(bool p) -{ - if (getPrintOnWarn() == p) - return; - - print_on_warn = p; - settings.setValue(QStringLiteral("printOnWarn"), p); - emit printOnWarnChanged(); -} - -bool QMLBridge::getPrintOnWarn() -{ - return settings.value(QStringLiteral("printOnWarn"), true).toBool(); -} - -bool QMLBridge::getAutostart() -{ - return settings.value(QStringLiteral("emuAutostart"), true).toBool(); -} - -void QMLBridge::setAutostart(bool e) -{ - if(getAutostart() == e) - return; - - settings.setValue(QStringLiteral("emuAutostart"), e); - emit autostartChanged(); -} - -unsigned int QMLBridge::getDefaultKit() -{ - return settings.value(QStringLiteral("defaultKit"), 0).toUInt(); -} - -void QMLBridge::setDefaultKit(unsigned int id) -{ - if(getDefaultKit() == id) - return; - - settings.setValue(QStringLiteral("defaultKit"), id); - emit defaultKitChanged(); -} - -bool QMLBridge::getLeftHanded() -{ - return settings.value(QStringLiteral("leftHanded"), false).toBool(); -} - -void QMLBridge::setLeftHanded(bool e) -{ - if(getLeftHanded() == e) - return; - - settings.setValue(QStringLiteral("leftHanded"), e); - emit leftHandedChanged(); -} - -bool QMLBridge::getSuspendOnClose() -{ - return settings.value(QStringLiteral("suspendOnClose"), true).toBool(); -} - -void QMLBridge::setSuspendOnClose(bool e) -{ - if(getSuspendOnClose() == e) - return; - - settings.setValue(QStringLiteral("suspendOnClose"), e); - emit suspendOnCloseChanged(); -} - -QString QMLBridge::getUSBDir() -{ - return settings.value(QStringLiteral("usbdirNew"), QStringLiteral("/ndless")).toString(); -} - -void QMLBridge::setUSBDir(QString dir) -{ - if(getUSBDir() == dir) - return; - - settings.setValue(QStringLiteral("usbdirNew"), dir); - emit usbDirChanged(); -} - bool QMLBridge::getIsRunning() { return emu_thread.isRunning(); @@ -317,11 +211,6 @@ bool QMLBridge::fileExists(QString path) return QFile::exists(path); } -int QMLBridge::kitIndexForID(unsigned int id) -{ - return kit_model.indexForID(id); -} - #ifndef MOBILE_UI void QMLBridge::switchUIMode(bool mobile_ui) { @@ -463,46 +352,6 @@ void QMLBridge::setTurboMode(bool b) emu_thread.setTurboMode(b); } -int QMLBridge::getMobileX() -{ - return settings.value(QStringLiteral("mobileX"), -1).toInt(); -} - -void QMLBridge::setMobileX(int x) -{ - settings.setValue(QStringLiteral("mobileX"), x); -} - -int QMLBridge::getMobileY() -{ - return settings.value(QStringLiteral("mobileY"), -1).toInt(); -} - -void QMLBridge::setMobileY(int y) -{ - settings.setValue(QStringLiteral("mobileY"), y); -} - -int QMLBridge::getMobileWidth() -{ - return settings.value(QStringLiteral("mobileWidth"), -1).toInt(); -} - -void QMLBridge::setMobileWidth(int w) -{ - settings.setValue(QStringLiteral("mobileWidth"), w); -} - -int QMLBridge::getMobileHeight() -{ - return settings.value(QStringLiteral("mobileHeight"), -1).toInt(); -} - -void QMLBridge::setMobileHeight(int h) -{ - settings.setValue(QStringLiteral("mobileHeight"), h); -} - bool QMLBridge::restart() { if(emu_thread.isRunning() && !emu_thread.stop()) @@ -511,7 +360,7 @@ bool QMLBridge::restart() return false; } - emu_thread.port_gdb = getGDBEnabled() ? getGDBPort() : 0; + emu_thread.port_gdb = gdb_enabled ? gdb_port : 0; emu_thread.port_rdbg = getRDBEnabled() ? getRDBPort() : 0; if(!emu_thread.boot1.isEmpty() && !emu_thread.flash.isEmpty()) { @@ -548,8 +397,8 @@ void QMLBridge::resume() { toastMessage(tr("Resuming emulation")); - emu_thread.port_gdb = getGDBEnabled() ? getGDBPort() : 0; - emu_thread.port_rdbg = getRDBEnabled() ? getRDBPort() : 0; + emu_thread.port_gdb = gdb_enabled ? gdb_port : 0; + emu_thread.port_rdbg = rdb_enabled ? rdb_port : 0; auto snapshot_path = getSnapshotPath(); if(!snapshot_path.isEmpty()) @@ -560,7 +409,7 @@ void QMLBridge::resume() bool QMLBridge::useDefaultKit() { - if(setCurrentKit(getDefaultKit())) + if(setCurrentKit(default_kit_id)) return true; setCurrentKit(kit_model.getKits()[0].id); // Use first kit as fallback @@ -586,11 +435,11 @@ int QMLBridge::getCurrentKitId() const Kit *QMLBridge::useKit(unsigned int id) { - int kitIndex = kitIndexForID(id); - if(kitIndex < 0) + const QModelIndex kitIndex = kit_model.indexForID(id); + if(!kitIndex.isValid()) return nullptr; - auto &&kit = kit_model.getKits()[kitIndex]; + auto &&kit = kit_model.getKits()[kitIndex.row()]; emu_thread.boot1 = kit.boot1; emu_thread.flash = kit.flash; fallback_snapshot_path = kit.snapshot; @@ -620,9 +469,9 @@ QString QMLBridge::getFlashPath() QString QMLBridge::getSnapshotPath() { - int kitIndex = kitIndexForID(current_kit_id); - if(kitIndex >= 0) - return kit_model.getKits()[kitIndex].snapshot; + const QModelIndex kitIndex = kit_model.indexForID(current_kit_id); + if(kitIndex.isValid()) + return kit_model.getKits()[kitIndex.row()].snapshot; else return fallback_snapshot_path; } @@ -634,7 +483,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 bac8576d..a778da7b 100644 --- a/qmlbridge.h +++ b/qmlbridge.h @@ -13,54 +13,37 @@ class QMLBridge : public QObject explicit QMLBridge(QObject *parent = 0); ~QMLBridge(); - Q_PROPERTY(unsigned int gdbPort READ getGDBPort WRITE setGDBPort NOTIFY gdbPortChanged) - Q_PROPERTY(bool gdbEnabled READ getGDBEnabled WRITE setGDBEnabled NOTIFY gdbEnabledChanged) - Q_PROPERTY(unsigned int rdbPort READ getRDBPort WRITE setRDBPort NOTIFY rdbPortChanged) - Q_PROPERTY(bool rdbEnabled READ getRDBEnabled WRITE setRDBEnabled NOTIFY rdbEnabledChanged) - Q_PROPERTY(bool debugOnStart READ getDebugOnStart WRITE setDebugOnStart NOTIFY debugOnStartChanged) - Q_PROPERTY(bool debugOnWarn READ getDebugOnWarn WRITE setDebugOnWarn NOTIFY debugOnWarnChanged) - Q_PROPERTY(bool printOnWarn READ getPrintOnWarn WRITE setPrintOnWarn NOTIFY printOnWarnChanged) - Q_PROPERTY(bool autostart READ getAutostart WRITE setAutostart NOTIFY autostartChanged) - Q_PROPERTY(unsigned int defaultKit READ getDefaultKit WRITE setDefaultKit NOTIFY defaultKitChanged) - Q_PROPERTY(bool leftHanded READ getLeftHanded WRITE setLeftHanded NOTIFY leftHandedChanged) - Q_PROPERTY(bool suspendOnClose READ getSuspendOnClose WRITE setSuspendOnClose NOTIFY suspendOnCloseChanged) - Q_PROPERTY(QString usbdir READ getUSBDir WRITE setUSBDir NOTIFY usbDirChanged) - Q_PROPERTY(QString version READ getVersion CONSTANT) + // Settings + Q_PROPERTY(unsigned int gdbPort MEMBER gdb_port NOTIFY gdbPortChanged) + Q_PROPERTY(bool gdbEnabled MEMBER gdb_enabled NOTIFY gdbEnabledChanged) + Q_PROPERTY(unsigned int rdbPort MEMBER rdb_port NOTIFY rdbPortChanged) + Q_PROPERTY(bool rdbEnabled MEMBER rdb_enabled NOTIFY rdbEnabledChanged) + Q_PROPERTY(bool debugOnStart MEMBER debug_on_start NOTIFY debugOnStartChanged) + Q_PROPERTY(bool debugOnWarn MEMBER debug_on_warn NOTIFY debugOnWarnChanged) + Q_PROPERTY(bool printOnWarn MEMBER print_on_warn NOTIFY printOnWarnChanged) + Q_PROPERTY(bool autostart MEMBER autostart NOTIFY autostartChanged) + Q_PROPERTY(unsigned int defaultKit MEMBER default_kit_id NOTIFY defaultKitChanged) + Q_PROPERTY(bool leftHanded MEMBER left_handed NOTIFY leftHandedChanged) + Q_PROPERTY(bool suspendOnClose MEMBER suspend_on_close NOTIFY suspendOnCloseChanged) + Q_PROPERTY(QString usbdir MEMBER usb_dir NOTIFY usbDirChanged) + Q_PROPERTY(int mobileX MEMBER mobile_x NOTIFY mobileXChanged) + Q_PROPERTY(int mobileY MEMBER mobile_y NOTIFY mobileYChanged) + Q_PROPERTY(int mobileWidth MEMBER mobile_w NOTIFY mobileWChanged) + Q_PROPERTY(int mobileHeight MEMBER mobile_h NOTIFY mobileHChanged) + Q_PROPERTY(bool isRunning READ getIsRunning NOTIFY isRunningChanged) + Q_PROPERTY(QString version READ getVersion CONSTANT) Q_PROPERTY(KitModel* kits READ getKitModel CONSTANT) - Q_PROPERTY(double speed READ getSpeed NOTIFY speedChanged) Q_PROPERTY(bool turboMode READ getTurboMode WRITE setTurboMode NOTIFY turboModeChanged) - Q_PROPERTY(int mobileX READ getMobileX WRITE setMobileX NOTIFY neverEmitted) - Q_PROPERTY(int mobileY READ getMobileY WRITE setMobileY NOTIFY neverEmitted) - Q_PROPERTY(int mobileWidth READ getMobileWidth WRITE setMobileWidth NOTIFY neverEmitted) - Q_PROPERTY(int mobileHeight READ getMobileHeight WRITE setMobileHeight NOTIFY neverEmitted) - - unsigned int getGDBPort(); - void setGDBPort(unsigned int port); - void setGDBEnabled(bool e); - bool getGDBEnabled(); - unsigned int getRDBPort(); - void setRDBPort(unsigned int port); - void setRDBEnabled(bool e); - bool getRDBEnabled(); - void setDebugOnWarn(bool e); - bool getDebugOnWarn(); - void setDebugOnStart(bool e); - bool getDebugOnStart(); - void setPrintOnWarn(bool p); - bool getPrintOnWarn(); - void setAutostart(bool e); - bool getAutostart(); - unsigned int getDefaultKit(); - void setDefaultKit(unsigned int id); - bool getLeftHanded(); - void setLeftHanded(bool e); - bool getSuspendOnClose(); - void setSuspendOnClose(bool e); - QString getUSBDir(); - void setUSBDir(QString dir); + unsigned int getGDBPort() { return gdb_port; } + bool getGDBEnabled() { return gdb_enabled; } + unsigned int getRDBPort() { return rdb_port; } + bool getRDBEnabled() { return rdb_enabled; } + bool getAutostart() { return autostart; } + QString getUSBDir() { return usb_dir; } + bool getIsRunning(); QString getVersion(); @@ -68,15 +51,6 @@ class QMLBridge : public QObject bool getTurboMode(); void setTurboMode(bool e); - int getMobileX(); - void setMobileX(int x); - int getMobileY(); - void setMobileY(int y); - int getMobileWidth(); - void setMobileWidth(int w); - int getMobileHeight(); - void setMobileHeight(int h); - KitModel *getKitModel() { return &kit_model; } Q_INVOKABLE void setButtonState(int id, bool state); @@ -92,7 +66,6 @@ class QMLBridge : public QObject Q_INVOKABLE QUrl dir(QString path); Q_INVOKABLE QString toLocalFile(QUrl url); Q_INVOKABLE bool fileExists(QString path); - Q_INVOKABLE int kitIndexForID(unsigned int id); Q_INVOKABLE bool setCurrentKit(unsigned int id); Q_INVOKABLE int getCurrentKitId(); @@ -123,6 +96,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); @@ -136,6 +111,7 @@ public slots: void suspended(bool success); signals: + // Settings void gdbPortChanged(); void gdbEnabledChanged(); void rdbPortChanged(); @@ -148,6 +124,11 @@ public slots: void leftHandedChanged(); void suspendOnCloseChanged(); void usbDirChanged(); + void mobileXChanged(); + void mobileYChanged(); + void mobileWChanged(); + void mobileHChanged(); + void isRunningChanged(); void speedChanged(); void turboModeChanged(); @@ -162,10 +143,6 @@ public slots: void touchpadStateChanged(qreal x, qreal y, bool contact, bool down); void buttonStateChanged(int id, bool state); - /* Never called. Used as NOTIFY value for writable properties - * that aren't used outside of QML. */ - void neverEmitted(); - private: static void usblink_progress_changed(int percent, void *qml_bridge_p); @@ -176,7 +153,13 @@ public slots: KitModel kit_model; QSettings settings; bool is_active = false; -}; + + // Settings + int mobile_x, mobile_y, mobile_w, mobile_h; + unsigned int gdb_port, rdb_port, default_kit_id; + bool gdb_enabled, rdb_enabled, debug_on_warn, debug_on_start, + print_on_warn, autostart, suspend_on_close, left_handed; + QString usb_dir;}; extern QMLBridge *the_qml_bridge;