Commit a00ee753 authored by Alessandro Portale's avatar Alessandro Portale

ProjectExplorer: Introduce IDeviceFactory::iconForId()

This adds the possibility to have an icon for a device type. Now,
a Kit can have a proper icon if just the device type but not device
is selected.

Change-Id: I2a382ffd5b46cbbf74cdd0b934b3d450d300bfff
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
Reviewed-by: Vikas Pachdha's avatarVikas Pachdha <vikas.pachdha@qt.io>
Reviewed-by: Alessandro Portale's avatarAlessandro Portale <alessandro.portale@qt.io>
parent 2584366f
......@@ -45,10 +45,6 @@ AndroidDevice::AndroidDevice()
{
setDisplayName(QCoreApplication::translate("Android::Internal::AndroidDevice", "Run on Android"));
setDeviceState(DeviceReadyToUse);
setDeviceIcon({Utils::Icon({{":/android/images/androiddevicesmall.png",
Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint),
Utils::Icon({{":/android/images/androiddevice.png",
Utils::Theme::IconsBaseColor}})});
}
AndroidDevice::AndroidDevice(const AndroidDevice &other)
......
......@@ -28,6 +28,10 @@
#include "androidconstants.h"
#include <utils/icon.h>
#include <QIcon>
namespace Android {
namespace Internal {
......@@ -48,6 +52,18 @@ QList<Core::Id> AndroidDeviceFactory::availableCreationIds() const
return QList<Core::Id>() << Core::Id(Constants::ANDROID_DEVICE_TYPE);
}
QIcon AndroidDeviceFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
using namespace Utils;
static const QIcon icon =
Icon::combinedIcon({Icon({{":/android/images/androiddevicesmall.png",
Theme::PanelTextColorDark}}, Icon::Tint),
Icon({{":/android/images/androiddevice.png",
Theme::IconsBaseColor}})});
return icon;
}
bool AndroidDeviceFactory::canCreate() const
{
return false;
......
......@@ -38,6 +38,7 @@ public:
QString displayNameForId(Core::Id type) const;
QList<Core::Id> availableCreationIds() const;
QIcon iconForId(Core::Id type) const;
bool canCreate() const;
ProjectExplorer::IDevice::Ptr create(Core::Id id) const;
......
......@@ -33,7 +33,6 @@
#include <coreplugin/id.h>
#include <ssh/sshconnection.h>
#include <utils/icon.h>
#include <utils/qtcassert.h>
#include <QCoreApplication>
......@@ -153,28 +152,16 @@ DeviceProcess *BareMetalDevice::createProcess(QObject *parent) const
return new GdbServerProviderProcess(sharedFromThis(), parent);
}
static const QList<Utils::Icon> &bareMetalDeviceIcon()
{
static const QList<Utils::Icon> icon = {
Utils::Icon({{":/baremetal/images/baremetaldevicesmall.png",
Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint),
Utils::Icon({{":/baremetal/images/baremetaldevice.png",
Utils::Theme::IconsBaseColor}})};
return icon;
}
BareMetalDevice::BareMetalDevice(const QString &name, Core::Id type, MachineType machineType, Origin origin, Core::Id id)
: IDevice(type, origin, machineType, id)
{
setDisplayName(name);
setDeviceIcon(bareMetalDeviceIcon());
}
BareMetalDevice::BareMetalDevice(const BareMetalDevice &other)
: IDevice(other)
{
setGdbServerProviderId(other.gdbServerProviderId());
setDeviceIcon(bareMetalDeviceIcon());
}
} //namespace Internal
......
......@@ -29,8 +29,11 @@
#include "baremetalconstants.h"
#include "baremetaldevice.h"
#include <utils/icon.h>
#include <utils/qtcassert.h>
#include <QIcon>
using namespace ProjectExplorer;
namespace BareMetal {
......@@ -51,6 +54,18 @@ QList<Core::Id> BareMetalDeviceConfigurationFactory::availableCreationIds() cons
return QList<Core::Id>() << Core::Id(Constants::BareMetalOsType);
}
QIcon BareMetalDeviceConfigurationFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
using namespace Utils;
static const QIcon icon =
Icon::combinedIcon({Icon({{":/baremetal/images/baremetaldevicesmall.png",
Theme::PanelTextColorDark}}, Icon::Tint),
Icon({{":/baremetal/images/baremetaldevice.png",
Theme::IconsBaseColor}})});
return icon;
}
IDevice::Ptr BareMetalDeviceConfigurationFactory::create(Core::Id id) const
{
QTC_ASSERT(id == Constants::BareMetalOsType, return IDevice::Ptr());
......
......@@ -40,6 +40,7 @@ public:
QString displayNameForId(Core::Id type) const;
QList<Core::Id> availableCreationIds() const;
QIcon iconForId(Core::Id type) const;
ProjectExplorer::IDevice::Ptr create(Core::Id id) const;
bool canRestore(const QVariantMap &map) const;
......
......@@ -31,7 +31,6 @@
#include <projectexplorer/devicesupport/devicemanager.h>
#include <projectexplorer/kitinformation.h>
#include <coreplugin/helpmanager.h>
#include <utils/icon.h>
#include <utils/portlist.h>
#include <QCoreApplication>
......@@ -92,10 +91,6 @@ IosDevice::IosDevice()
ports.addRange(Utils::Port(Constants::IOS_DEVICE_PORT_START),
Utils::Port(Constants::IOS_DEVICE_PORT_END));
setFreePorts(ports);
setDeviceIcon({Utils::Icon({{":/ios/images/iosdevicesmall.png",
Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint),
Utils::Icon({{":/ios/images/iosdevice.png",
Utils::Theme::IconsBaseColor}})});
}
IosDevice::IosDevice(const IosDevice &other)
......
......@@ -28,6 +28,10 @@
#include "iosconstants.h"
#include <utils/icon.h>
#include <QIcon>
namespace Ios {
namespace Internal {
......@@ -46,6 +50,18 @@ QList<Core::Id> IosDeviceFactory::availableCreationIds() const
return QList<Core::Id>() << Core::Id(Constants::IOS_DEVICE_TYPE);
}
QIcon IosDeviceFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
using namespace Utils;
static const QIcon icon =
Icon::combinedIcon({Icon({{":/ios/images/iosdevicesmall.png",
Theme::PanelTextColorDark}}, Icon::Tint),
Icon({{":/ios/images/iosdevice.png",
Theme::IconsBaseColor}})});
return icon;
}
bool IosDeviceFactory::canCreate() const
{
return false;
......
......@@ -42,6 +42,7 @@ public:
QString displayNameForId(Core::Id type) const override;
QList<Core::Id> availableCreationIds() const override;
QIcon iconForId(Core::Id type) const override;
bool canCreate() const override;
ProjectExplorer::IDevice::Ptr create(Core::Id id) const override;
......
......@@ -28,7 +28,6 @@
#include "iostoolhandler.h"
#include <projectexplorer/kitinformation.h>
#include <utils/icon.h>
#include <utils/port.h>
#include <QCoreApplication>
......@@ -54,10 +53,6 @@ IosSimulator::IosSimulator(Core::Id id)
{
setDisplayName(QCoreApplication::translate("Ios::Internal::IosSimulator", "iOS Simulator"));
setDeviceState(DeviceReadyToUse);
setDeviceIcon({Utils::Icon({{":/ios/images/iosdevicesmall.png",
Utils::Theme::PanelTextColorDark}}, Utils::Icon::Tint),
Utils::Icon({{":/ios/images/iosdevice.png",
Utils::Theme::IconsBaseColor}})});
}
IosSimulator::IosSimulator()
......
......@@ -27,8 +27,11 @@
#include <QLatin1String>
#include "iosconstants.h"
#include "iossimulator.h"
#include "utils/icon.h"
#include "utils/qtcassert.h"
#include <QIcon>
namespace Ios {
namespace Internal {
......@@ -49,6 +52,18 @@ QList<Core::Id> IosSimulatorFactory::availableCreationIds() const
return QList<Core::Id>() << Core::Id(Constants::IOS_SIMULATOR_TYPE);
}
QIcon IosSimulatorFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
using namespace Utils;
static const QIcon icon =
Icon::combinedIcon({Icon({{":/ios/images/iosdevicesmall.png",
Theme::PanelTextColorDark}}, Icon::Tint),
Icon({{":/ios/images/iosdevice.png",
Theme::IconsBaseColor}})});
return icon;
}
bool IosSimulatorFactory::canCreate() const
{
return false;
......
......@@ -38,6 +38,7 @@ public:
QString displayNameForId(Core::Id type) const override;
QList<Core::Id> availableCreationIds() const override;
QIcon iconForId(Core::Id type) const override;
bool canCreate() const override;
ProjectExplorer::IDevice::Ptr create(Core::Id id) const override;
......
......@@ -26,9 +26,15 @@
#include "desktopdevicefactory.h"
#include "desktopdevice.h"
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorericons.h>
#include <utils/icon.h>
#include <utils/qtcassert.h>
#include <QApplication>
#include <QIcon>
#include <QStyle>
namespace ProjectExplorer {
namespace Internal {
......@@ -47,6 +53,17 @@ QList<Core::Id> DesktopDeviceFactory::availableCreationIds() const
return QList<Core::Id>() << Core::Id(Constants::DESKTOP_DEVICE_TYPE);
}
QIcon DesktopDeviceFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
static const QIcon icon =
Utils::creatorTheme()->flag(Utils::Theme::FlatSideBarIcons)
? Utils::Icon::combinedIcon({Icons::DESKTOP_DEVICE.icon(),
Icons::DESKTOP_DEVICE_SMALL.icon()})
: QApplication::style()->standardIcon(QStyle::SP_ComputerIcon);
return icon;
}
bool DesktopDeviceFactory::canCreate() const
{
return false;
......
......@@ -39,6 +39,7 @@ public:
QString displayNameForId(Core::Id type) const override;
QList<Core::Id> availableCreationIds() const override;
QIcon iconForId(Core::Id type) const override;
bool canCreate() const override;
IDevice::Ptr create(Core::Id id) const override;
......
......@@ -49,6 +49,8 @@ public:
virtual QList<Core::Id> availableCreationIds() const = 0;
virtual QIcon iconForId(Core::Id type) const = 0;
virtual bool canCreate() const;
virtual IDevice::Ptr create(Core::Id id) const = 0;
......
......@@ -25,12 +25,14 @@
#include "kit.h"
#include "devicesupport/idevicefactory.h"
#include "kitinformation.h"
#include "kitmanager.h"
#include "ioutputparser.h"
#include "osparser.h"
#include "projectexplorerconstants.h"
#include "projectexplorericons.h"
#include <extensionsystem/pluginmanager.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
......@@ -356,6 +358,15 @@ Id Kit::id() const
return d->m_id;
}
static QIcon iconForDeviceType(Core::Id deviceType)
{
const IDeviceFactory *factory = ExtensionSystem::PluginManager::getObject<IDeviceFactory>(
[&deviceType](const IDeviceFactory *factory) {
return factory->availableCreationIds().contains(deviceType);
});
return factory ? factory->iconForId(deviceType) : QIcon();
}
QIcon Kit::icon() const
{
if (!d->m_cachedIcon.isNull())
......@@ -375,10 +386,14 @@ QIcon Kit::icon() const
}
}
d->m_cachedIcon = creatorTheme()->flag(Theme::FlatSideBarIcons)
? Icon::combinedIcon({Icons::DESKTOP_DEVICE.icon(),
Icons::DESKTOP_DEVICE_SMALL.icon()})
: QApplication::style()->standardIcon(QStyle::SP_ComputerIcon);
const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(this);
const QIcon deviceTypeIcon = iconForDeviceType(deviceType);
if (!deviceTypeIcon.isNull()) {
d->m_cachedIcon = deviceTypeIcon;
return d->m_cachedIcon;
}
d->m_cachedIcon = iconForDeviceType(Constants::DESKTOP_DEVICE_TYPE);
return d->m_cachedIcon;
}
......
......@@ -31,6 +31,8 @@
#include <utils/qtcassert.h>
#include <QIcon>
namespace Qnx {
namespace Internal {
......@@ -50,6 +52,12 @@ QList<Core::Id> QnxDeviceFactory::availableCreationIds() const
return { Constants::QNX_QNX_OS_TYPE };
}
QIcon QnxDeviceFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
return QIcon();
}
bool QnxDeviceFactory::canCreate() const
{
return true;
......
......@@ -39,6 +39,7 @@ public:
QString displayNameForId(Core::Id type) const;
QList<Core::Id> availableCreationIds() const;
QIcon iconForId(Core::Id type) const;
bool canCreate() const;
ProjectExplorer::IDevice::Ptr create(Core::Id id) const;
......
......@@ -33,6 +33,8 @@
#include <utils/qtcassert.h>
#include <QIcon>
using namespace ProjectExplorer;
namespace RemoteLinux {
......@@ -53,6 +55,12 @@ QList<Core::Id> GenericLinuxDeviceConfigurationFactory::availableCreationIds() c
return QList<Core::Id>() << Core::Id(Constants::GenericLinuxOsType);
}
QIcon GenericLinuxDeviceConfigurationFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
return QIcon();
}
IDevice::Ptr GenericLinuxDeviceConfigurationFactory::create(Core::Id id) const
{
QTC_ASSERT(id == Constants::GenericLinuxOsType, return IDevice::Ptr());
......
......@@ -41,6 +41,7 @@ public:
QString displayNameForId(Core::Id type) const;
QList<Core::Id> availableCreationIds() const;
QIcon iconForId(Core::Id type) const;
ProjectExplorer::IDevice::Ptr create(Core::Id id) const;
bool canRestore(const QVariantMap &map) const;
......
......@@ -34,6 +34,7 @@
#include <qtsupport/qtversionmanager.h>
#include <utils/qtcassert.h>
#include <QIcon>
#include <QFileInfo>
using Core::MessageManager;
......@@ -72,6 +73,12 @@ QList<Core::Id> WinRtDeviceFactory::availableCreationIds() const
<< Constants::WINRT_DEVICE_TYPE_EMULATOR;
}
QIcon WinRtDeviceFactory::iconForId(Core::Id type) const
{
Q_UNUSED(type)
return QIcon();
}
IDevice::Ptr WinRtDeviceFactory::create(Core::Id id) const
{
Q_UNUSED(id);
......
......@@ -38,6 +38,7 @@ public:
WinRtDeviceFactory();
QString displayNameForId(Core::Id type) const;
QList<Core::Id> availableCreationIds() const;
QIcon iconForId(Core::Id type) const;
bool canCreate() const { return false; }
ProjectExplorer::IDevice::Ptr create(Core::Id id) const;
bool canRestore(const QVariantMap &map) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment