Device: Fix off-by-one error in settings widget.

There was one place left where we still used the current index with
the device manager, which did the wrong thing due to the desktop device
not being in the model.

Change-Id: I3047597d4805f4b3ca8995313575765e785e0f00
Reviewed-by: Tobias Hunger <tobias.hunger@nokia.com>
This commit is contained in:
Christian Kandeler
2012-05-04 16:39:57 +02:00
parent 8ea32105fa
commit e2cec6bd81
3 changed files with 9 additions and 11 deletions

View File

@@ -266,14 +266,13 @@ void DeviceManager::addDevice(const IDevice::Ptr &device)
void DeviceManager::removeDevice(Core::Id id)
{
const int idx = indexForId(id);
const IDevice::Ptr device = mutableDeviceAt(idx);
const IDevice::Ptr device = mutableDevice(id);
QTC_ASSERT(device, return);
QTC_ASSERT(this != instance() || device->isAutoDetected(), return);
const bool wasDefault = d->defaultDevices.value(device->type()) == device->id();
const QString deviceType = device->type();
d->devices.removeAt(idx);
d->devices.removeAt(indexForId(id));
emit deviceRemoved(device->id());
if (wasDefault) {
@@ -339,10 +338,10 @@ IDevice::ConstPtr DeviceManager::deviceAt(int idx) const
return d->devices.at(idx);
}
IDevice::Ptr DeviceManager::mutableDeviceAt(int idx) const
IDevice::Ptr DeviceManager::mutableDevice(Core::Id id) const
{
QTC_ASSERT(idx >= 0 && idx < deviceCount(), return IDevice::Ptr());
return d->devices.at(idx);
const int index = indexForId(id);
return index == -1 ? IDevice::Ptr() : d->devices.at(index);
}
bool DeviceManager::hasDevice(const QString &name) const

View File

@@ -92,7 +92,7 @@ private:
void ensureOneDefaultDevicePerType();
// For SettingsWidget.
IDevice::Ptr mutableDeviceAt(int index) const;
IDevice::Ptr mutableDevice(Core::Id id) const;
void setDefaultDevice(int index);
static DeviceManager *cloneInstance();
static void replaceInstance();

View File

@@ -226,7 +226,7 @@ void DeviceSettingsWidget::deviceNameEditingFinished()
return;
const QString &newName = m_ui->nameLineEdit->text();
m_deviceManager->mutableDeviceAt(currentIndex())->setDisplayName(newName);
m_deviceManager->mutableDevice(currentDevice()->id())->setDisplayName(newName);
m_nameValidator->setDisplayName(newName);
m_deviceManagerModel->updateDevice(currentDevice()->id());
}
@@ -266,8 +266,7 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
}
if (!m_ui->osSpecificGroupBox->layout())
new QVBoxLayout(m_ui->osSpecificGroupBox);
int managerIndex = m_deviceManager->indexOf(device);
m_configWidget = m_deviceManager->mutableDeviceAt(managerIndex)->createWidget();
m_configWidget = m_deviceManager->mutableDevice(device->id())->createWidget();
if (m_configWidget)
m_ui->osSpecificGroupBox->layout()->addWidget(m_configWidget);
displayCurrent();
@@ -283,7 +282,7 @@ void DeviceSettingsWidget::clearDetails()
void DeviceSettingsWidget::handleAdditionalActionRequest(int actionId)
{
const IDevice::Ptr &device = m_deviceManager->mutableDeviceAt(currentIndex());
IDevice::Ptr device = m_deviceManager->mutableDevice(currentDevice()->id());
QTC_ASSERT(device, return);
device->executeAction(Core::Id::fromUniqueIdentifier(actionId), this);
}