Removed some assertions that could not be true if using the model filter
Also fixed ugly hack where the KCM updated the model
This commit is contained in:
parent
c8e0c474ef
commit
9fa8538bf1
3 changed files with 15 additions and 27 deletions
|
@ -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<QString, int>::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<QString, int>::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<DeviceDbusInterface*>(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()
|
||||
|
|
|
@ -69,12 +69,10 @@ public:
|
|||
Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const;
|
||||
virtual QHash<int, QByteArray> 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue