Device: Simplify updating 'connected' indicator in target selector.

By listening to the signal updated() instead of deviceListChanged() we
can't simplify the update. updated() is also emitted when devices are
added or removed.

Change-Id: Ife985f420e2a2904d65185148d0db38b7367b3fd
Reviewed-by: Christian Kandeler <christian.kandeler@nokia.com>
This commit is contained in:
Nikolai Kosjar
2012-04-27 15:58:59 +02:00
committed by Tobias Hunger
parent b3148e7dc2
commit 3d9150075b
2 changed files with 24 additions and 31 deletions

View File

@@ -116,11 +116,7 @@ Target::Target(Project *project, const Core::Id id) :
ProjectConfiguration(project, id),
d(new TargetPrivate)
{
connect(DeviceManager::instance(), SIGNAL(deviceUpdated(Core::Id)),
this, SLOT(updateDeviceState(Core::Id)));
// everything changed...
connect(DeviceManager::instance(), SIGNAL(deviceListChanged()),
this, SLOT(updateDeviceState()));
connect(DeviceManager::instance(), SIGNAL(updated()), this, SLOT(updateDeviceState()));
}
Target::~Target()
@@ -510,34 +506,30 @@ static QString formatToolTip(const IDevice::DeviceInfo &input)
void Target::updateDeviceState()
{
IDevice::ConstPtr dev = currentDevice();
if (dev.isNull())
return;
updateDeviceState(dev->id());
}
void Target::updateDeviceState(Core::Id devId)
{
IDevice::ConstPtr dev = DeviceManager::instance()->find(devId);
QTC_ASSERT(!dev.isNull(), return);
IDevice::ConstPtr current = currentDevice();
if (current.isNull()
|| devId != current->id()
|| dev->availability() == IDevice::DeviceAvailabilityUnknown) {
setOverlayIcon(QIcon());
setToolTip(QString());
return;
QPixmap overlay;
if (current.isNull()) {
overlay = d->m_disconnectedPixmap;
} else {
switch (current->availability()) {
case IDevice::DeviceAvailabilityUnknown:
setOverlayIcon(QIcon());
setToolTip(QString());
return;
case IDevice::DeviceAvailable:
overlay = d->m_connectedPixmap;
break;
case IDevice::DeviceUnavailable:
overlay = d->m_disconnectedPixmap;
break;
default:
break;
}
}
static const int TARGET_OVERLAY_ORIGINAL_SIZE = 32;
QPixmap overlay;
if (dev->availability() == IDevice::DeviceAvailable)
overlay = d->m_connectedPixmap;
else
overlay = d->m_disconnectedPixmap;
double factor = Core::Constants::TARGET_ICON_SIZE / (double)TARGET_OVERLAY_ORIGINAL_SIZE;
QSize overlaySize(overlay.size().width()*factor, overlay.size().height()*factor);
QPixmap pixmap(Core::Constants::TARGET_ICON_SIZE, Core::Constants::TARGET_ICON_SIZE);
@@ -548,7 +540,7 @@ void Target::updateDeviceState(Core::Id devId)
overlay.scaled(overlaySize));
setOverlayIcon(QIcon(pixmap));
setToolTip(formatToolTip(dev->deviceInformation()));
setToolTip(current.isNull() ? QString() : formatToolTip(current->deviceInformation()));
}
ProjectExplorer::IDevice::ConstPtr Target::currentDevice() const