From 9fa8538bf13ab6b98a01bba723a4e7f4c22c92bb Mon Sep 17 00:00:00 2001 From: Albert Vaca Date: Sun, 21 Jun 2015 20:20:40 -0700 Subject: [PATCH] Removed some assertions that could not be true if using the model filter Also fixed ugly hack where the KCM updated the model --- interfaces/devicesmodel.cpp | 36 ++++++++++++++---------------------- interfaces/devicesmodel.h | 4 +--- kcm/kcm.cpp | 2 -- 3 files changed, 15 insertions(+), 27 deletions(-) diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp index f3a2909a9..ca854f302 100644 --- a/interfaces/devicesmodel.cpp +++ b/interfaces/devicesmodel.cpp @@ -49,7 +49,7 @@ DevicesModel::DevicesModel(QObject *parent) connect(m_dbusInterface, SIGNAL(deviceAdded(QString)), this, SLOT(deviceAdded(QString))); connect(m_dbusInterface, SIGNAL(deviceVisibilityChanged(QString,bool)), - this, SLOT(deviceStatusChanged(QString))); + this, SLOT(deviceUpdated(QString))); connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceRemoved(QString))); @@ -93,26 +93,23 @@ void DevicesModel::deviceAdded(const QString& id) void DevicesModel::deviceRemoved(const QString& id) { - if (!m_deviceIndexById.contains(id)) { - Q_ASSERT(false); //This should only be emited for existing devices - return; + QMap::iterator it = m_deviceIndexById.find(id); + if (it != m_deviceIndexById.end()) { + int row = *it; + m_deviceIndexById.erase(it); + beginRemoveRows(QModelIndex(), row, row); + delete m_deviceList.takeAt(row); + endRemoveRows(); } - const int row = m_deviceIndexById.take(id); - beginRemoveRows(QModelIndex(), row, row); - delete m_deviceList.takeAt(row); - endRemoveRows(); } -void DevicesModel::deviceStatusChanged(const QString& id) +void DevicesModel::deviceUpdated(const QString& id) { - if (!m_deviceIndexById.contains(id)) { - Q_ASSERT(false); //This should only be emited for existing devices - return; + QMap::iterator it = m_deviceIndexById.find(id); + if (it != m_deviceIndexById.end()) { + const QModelIndex idx = index(it.value()); + Q_EMIT dataChanged(idx, idx); } - - int row = m_deviceIndexById[id]; - const QModelIndex idx = index(row); - Q_EMIT dataChanged(idx, idx); } int DevicesModel::displayFilter() const @@ -178,13 +175,8 @@ void DevicesModel::appendDevice(DeviceDbusInterface* dev) void DevicesModel::nameChanged(const QString& newName) { Q_UNUSED(newName); - DeviceDbusInterface* device = static_cast(sender()); - - int row = m_deviceIndexById[device->id()]; - Q_ASSERT(row >= 0); - const QModelIndex idx = index(row); - Q_EMIT dataChanged(idx, idx); + deviceUpdated(device->id()); } void DevicesModel::clearDevices() diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h index a5d0bff1a..92410ffcb 100644 --- a/interfaces/devicesmodel.h +++ b/interfaces/devicesmodel.h @@ -69,12 +69,10 @@ public: Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const; virtual QHash roleNames() const; -public Q_SLOTS: - void deviceStatusChanged(const QString& id); - private Q_SLOTS: void deviceAdded(const QString& id); void deviceRemoved(const QString& id); + void deviceUpdated(const QString& id); void refreshDeviceList(); void receivedDeviceList(QDBusPendingCallWatcher* watcher); void nameChanged(const QString& newName); diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 09d56e082..ac66dc02b 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -259,8 +259,6 @@ void KdeConnectKcm::pairingFailed(const QString& error) void KdeConnectKcm::pairingChanged(bool paired) { DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender(); - devicesModel->deviceStatusChanged(senderDevice->id()); - if (senderDevice != currentDevice) return; kcmUi->pair_button->setVisible(!paired);