forked from qt-creator/qt-creator
IDevice: Replace QSharedPointer with std::shared_ptr
According to https://wiki.qt.io/Things_To_Look_Out_For_In_Reviews QSharedPointer impl is poor and it's going to be removed from Qt 7. Replace QWeakPointer with std::weak_ptr. Replace QEnableSharedFromThis with std::enable_shared_from_this. Use std::static_pointer_cast and std::dynamic_pointer_cast for casts used with QSharedPointer before. Change-Id: If255a100c790860934f36d52906b93f33c31cfe8 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -403,7 +403,7 @@ void IosConfigurations::updateSimulators()
|
||||
DeviceManager *devManager = DeviceManager::instance();
|
||||
Id devId = Constants::IOS_SIMULATOR_DEVICE_ID;
|
||||
IDevice::ConstPtr dev = devManager->find(devId);
|
||||
if (dev.isNull()) {
|
||||
if (!dev) {
|
||||
dev = IDevice::ConstPtr(new IosSimulator(devId));
|
||||
devManager->addDevice(dev);
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ IosDeployStep::IosDeployStep(BuildStepList *parent, Utils::Id id)
|
||||
void IosDeployStep::updateDisplayNames()
|
||||
{
|
||||
IDevice::ConstPtr dev = DeviceKitAspect::device(kit());
|
||||
const QString devName = dev.isNull() ? IosDevice::name() : dev->displayName();
|
||||
const QString devName = dev ? dev->displayName() : IosDevice::name();
|
||||
setDisplayName(Tr::tr("Deploy to %1").arg(devName));
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ GroupItem IosDeployStep::runRecipe()
|
||||
}
|
||||
// otherwise use iostool:
|
||||
const auto onSetup = [this](IosTransfer &transfer) {
|
||||
if (m_device.isNull()) {
|
||||
if (!m_device) {
|
||||
TaskHub::addTask(
|
||||
DeploymentTask(Task::Error, Tr::tr("Deployment failed. No iOS device found.")));
|
||||
return SetupResult::StopWithError;
|
||||
@@ -273,15 +273,15 @@ QWidget *IosDeployStep::createConfigWidget()
|
||||
|
||||
QString IosDeployStep::deviceId() const
|
||||
{
|
||||
if (iosdevice().isNull())
|
||||
return QString();
|
||||
if (!iosdevice())
|
||||
return {};
|
||||
return iosdevice()->uniqueDeviceID();
|
||||
}
|
||||
|
||||
bool IosDeployStep::checkProvisioningProfile()
|
||||
{
|
||||
IosDevice::ConstPtr device = iosdevice();
|
||||
if (device.isNull())
|
||||
if (!device)
|
||||
return true;
|
||||
|
||||
const FilePath provisioningFilePath = m_bundlePath.pathAppended("embedded.mobileprovision");
|
||||
@@ -330,12 +330,12 @@ bool IosDeployStep::checkProvisioningProfile()
|
||||
|
||||
IosDevice::ConstPtr IosDeployStep::iosdevice() const
|
||||
{
|
||||
return m_device.dynamicCast<const IosDevice>();
|
||||
return std::dynamic_pointer_cast<const IosDevice>(m_device);
|
||||
}
|
||||
|
||||
IosSimulator::ConstPtr IosDeployStep::iossimulator() const
|
||||
{
|
||||
return m_device.dynamicCast<const IosSimulator>();
|
||||
return std::dynamic_pointer_cast<const IosSimulator>(m_device);
|
||||
}
|
||||
|
||||
// IosDeployStepFactory
|
||||
|
||||
@@ -127,7 +127,7 @@ IDevice::DeviceInfo IosDevice::deviceInformation() const
|
||||
|
||||
IDeviceWidget *IosDevice::createWidget()
|
||||
{
|
||||
return new IosDeviceInfoWidget(sharedFromThis());
|
||||
return new IosDeviceInfoWidget(shared_from_this());
|
||||
}
|
||||
|
||||
void IosDevice::fromMap(const Store &map)
|
||||
@@ -222,7 +222,7 @@ void IosDeviceManager::deviceConnected(const QString &uid, const QString &name)
|
||||
Utils::Id devType(Constants::IOS_DEVICE_TYPE);
|
||||
Utils::Id devId = baseDevId.withSuffix(uid);
|
||||
IDevice::ConstPtr dev = devManager->find(devId);
|
||||
if (dev.isNull()) {
|
||||
if (!dev) {
|
||||
auto newDev = new IosDevice(uid);
|
||||
if (!name.isNull())
|
||||
newDev->settings()->displayName.setValue(name);
|
||||
@@ -250,10 +250,10 @@ void IosDeviceManager::deviceDisconnected(const QString &uid)
|
||||
Utils::Id devType(Constants::IOS_DEVICE_TYPE);
|
||||
Utils::Id devId = baseDevId.withSuffix(uid);
|
||||
IDevice::ConstPtr dev = devManager->find(devId);
|
||||
if (dev.isNull() || dev->type() != devType) {
|
||||
if (!dev || dev->type() != devType) {
|
||||
qCWarning(detectLog) << "ignoring disconnection of ios device " << uid; // should neve happen
|
||||
} else {
|
||||
auto iosDev = static_cast<const IosDevice *>(dev.data());
|
||||
auto iosDev = static_cast<const IosDevice *>(dev.get());
|
||||
if (iosDev->m_extraInfo.isEmpty()
|
||||
|| iosDev->m_extraInfo.value(kDeviceName) == QLatin1String("*unknown*")) {
|
||||
devManager->removeDevice(iosDev->id());
|
||||
@@ -325,8 +325,8 @@ void IosDeviceManager::deviceInfo(const QString &uid,
|
||||
IDevice::ConstPtr dev = devManager->find(devId);
|
||||
bool skipUpdate = false;
|
||||
IosDevice *newDev = nullptr;
|
||||
if (!dev.isNull() && dev->type() == devType) {
|
||||
auto iosDev = static_cast<const IosDevice *>(dev.data());
|
||||
if (dev && dev->type() == devType) {
|
||||
auto iosDev = static_cast<const IosDevice *>(dev.get());
|
||||
if (iosDev->m_handler == handler && iosDev->m_extraInfo == info) {
|
||||
skipUpdate = true;
|
||||
newDev = const_cast<IosDevice *>(iosDev);
|
||||
@@ -570,9 +570,9 @@ void IosDeviceManager::updateAvailableDevices(const QStringList &devices)
|
||||
for (int iDevice = 0; iDevice < devManager->deviceCount(); ++iDevice) {
|
||||
IDevice::ConstPtr dev = devManager->deviceAt(iDevice);
|
||||
Utils::Id devType(Constants::IOS_DEVICE_TYPE);
|
||||
if (dev.isNull() || dev->type() != devType)
|
||||
if (!dev || dev->type() != devType)
|
||||
continue;
|
||||
auto iosDev = static_cast<const IosDevice *>(dev.data());
|
||||
auto iosDev = static_cast<const IosDevice *>(dev.get());
|
||||
if (devices.contains(iosDev->uniqueDeviceID()))
|
||||
continue;
|
||||
if (iosDev->deviceState() != IDevice::DeviceDisconnected) {
|
||||
@@ -604,7 +604,7 @@ bool IosDeviceFactory::canRestore(const Store &map) const
|
||||
IosDeviceInfoWidget::IosDeviceInfoWidget(const IDevice::Ptr &device)
|
||||
: IDeviceWidget(device)
|
||||
{
|
||||
const auto iosDevice = qSharedPointerCast<IosDevice>(device);
|
||||
const auto iosDevice = std::static_pointer_cast<IosDevice>(device);
|
||||
using namespace Layouting;
|
||||
// clang-format off
|
||||
Form {
|
||||
|
||||
@@ -24,8 +24,8 @@ class IosDevice final : public ProjectExplorer::IDevice
|
||||
{
|
||||
public:
|
||||
using Dict = QMap<QString, QString>;
|
||||
using ConstPtr = QSharedPointer<const IosDevice>;
|
||||
using Ptr = QSharedPointer<IosDevice>;
|
||||
using ConstPtr = std::shared_ptr<const IosDevice>;
|
||||
using Ptr = std::shared_ptr<IosDevice>;
|
||||
|
||||
enum class Handler { IosTool, DeviceCtl };
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ IosRunConfiguration::IosRunConfiguration(Target *target, Id id)
|
||||
|
||||
setUpdater([this, target] {
|
||||
IDevice::ConstPtr dev = DeviceKitAspect::device(target->kit());
|
||||
const QString devName = dev.isNull() ? IosDevice::name() : dev->displayName();
|
||||
const QString devName = dev ? dev->displayName() : IosDevice::name();
|
||||
setDefaultDisplayName(Tr::tr("Run on %1").arg(devName));
|
||||
setDisplayName(Tr::tr("Run %1 on %2").arg(applicationName()).arg(devName));
|
||||
|
||||
@@ -97,10 +97,10 @@ bool IosRunConfiguration::isEnabled(Id runMode) const
|
||||
return true;
|
||||
|
||||
IDevice::ConstPtr dev = DeviceKitAspect::device(kit());
|
||||
if (dev.isNull() || dev->deviceState() != IDevice::DeviceReadyToUse)
|
||||
if (!dev || dev->deviceState() != IDevice::DeviceReadyToUse)
|
||||
return false;
|
||||
|
||||
IosDevice::ConstPtr iosdevice = dev.dynamicCast<const IosDevice>();
|
||||
IosDevice::ConstPtr iosdevice = std::dynamic_pointer_cast<const IosDevice>(dev);
|
||||
if (iosdevice && iosdevice->handler() == IosDevice::Handler::DeviceCtl
|
||||
&& runMode != ProjectExplorer::Constants::NORMAL_RUN_MODE) {
|
||||
return false;
|
||||
@@ -242,7 +242,7 @@ QString IosRunConfiguration::disabledReason(Id runMode) const
|
||||
DeviceManager *dm = DeviceManager::instance();
|
||||
for (int idev = 0; idev < dm->deviceCount(); ++idev) {
|
||||
IDevice::ConstPtr availDev = dm->deviceAt(idev);
|
||||
if (!availDev.isNull() && availDev->type() == Constants::IOS_DEVICE_TYPE) {
|
||||
if (availDev && availDev->type() == Constants::IOS_DEVICE_TYPE) {
|
||||
if (availDev->deviceState() == IDevice::DeviceReadyToUse) {
|
||||
validDevName += QLatin1Char(' ');
|
||||
validDevName += availDev->displayName();
|
||||
@@ -253,7 +253,7 @@ QString IosRunConfiguration::disabledReason(Id runMode) const
|
||||
}
|
||||
}
|
||||
|
||||
if (dev.isNull()) {
|
||||
if (!dev) {
|
||||
if (!validDevName.isEmpty())
|
||||
return Tr::tr("No device chosen. Select %1.").arg(validDevName); // should not happen
|
||||
else if (hasConncetedDev)
|
||||
@@ -277,7 +277,7 @@ QString IosRunConfiguration::disabledReason(Id runMode) const
|
||||
else
|
||||
return Tr::tr("%1 is not connected.").arg(dev->displayName());
|
||||
}
|
||||
IosDevice::ConstPtr iosdevice = dev.dynamicCast<const IosDevice>();
|
||||
IosDevice::ConstPtr iosdevice = std::dynamic_pointer_cast<const IosDevice>(dev);
|
||||
if (iosdevice && iosdevice->handler() == IosDevice::Handler::DeviceCtl
|
||||
&& runMode != ProjectExplorer::Constants::NORMAL_RUN_MODE) {
|
||||
return Tr::tr("Debugging and profiling is currently not supported for devices with iOS "
|
||||
|
||||
@@ -118,7 +118,7 @@ DeviceCtlRunner::DeviceCtlRunner(RunControl *runControl)
|
||||
QTC_ASSERT(data, return);
|
||||
m_bundlePath = data->bundleDirectory;
|
||||
m_arguments = ProcessArgs::splitArgs(runControl->commandLine().arguments(), OsTypeMac);
|
||||
m_device = DeviceKitAspect::device(runControl->kit()).dynamicCast<const IosDevice>();
|
||||
m_device = std::dynamic_pointer_cast<const IosDevice>(DeviceKitAspect::device(runControl->kit()));
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
m_pollTimer.setInterval(500ms); // not too often since running devicectl takes time
|
||||
@@ -465,9 +465,9 @@ FilePath IosRunner::bundlePath() const
|
||||
|
||||
QString IosRunner::deviceId() const
|
||||
{
|
||||
IosDevice::ConstPtr dev = m_device.dynamicCast<const IosDevice>();
|
||||
IosDevice::ConstPtr dev = std::dynamic_pointer_cast<const IosDevice>(m_device);
|
||||
if (!dev)
|
||||
return QString();
|
||||
return {};
|
||||
return dev->uniqueDeviceID();
|
||||
}
|
||||
|
||||
@@ -502,16 +502,16 @@ void IosRunner::start()
|
||||
return;
|
||||
}
|
||||
if (m_device->type() == Ios::Constants::IOS_DEVICE_TYPE) {
|
||||
IosDevice::ConstPtr iosDevice = m_device.dynamicCast<const IosDevice>();
|
||||
if (m_device.isNull()) {
|
||||
IosDevice::ConstPtr iosDevice = std::dynamic_pointer_cast<const IosDevice>(m_device);
|
||||
if (!m_device) {
|
||||
reportFailure();
|
||||
return;
|
||||
}
|
||||
if (m_qmlDebugServices != QmlDebug::NoQmlDebugServices)
|
||||
m_qmlServerPort = iosDevice->nextPort();
|
||||
} else {
|
||||
IosSimulator::ConstPtr sim = m_device.dynamicCast<const IosSimulator>();
|
||||
if (sim.isNull()) {
|
||||
IosSimulator::ConstPtr sim = std::dynamic_pointer_cast<const IosSimulator>(m_device);
|
||||
if (!sim) {
|
||||
reportFailure();
|
||||
return;
|
||||
}
|
||||
@@ -700,7 +700,7 @@ IosRunSupport::IosRunSupport(RunControl *runControl)
|
||||
setId("IosRunSupport");
|
||||
runControl->setIcon(Icons::RUN_SMALL_TOOLBAR);
|
||||
runControl->setDisplayName(QString("Run on %1")
|
||||
.arg(device().isNull() ? QString() : device()->displayName()));
|
||||
.arg(device() ? device()->displayName() : QString()));
|
||||
}
|
||||
|
||||
IosRunSupport::~IosRunSupport()
|
||||
@@ -798,7 +798,7 @@ void IosDebugSupport::start()
|
||||
}
|
||||
|
||||
if (device()->type() == Ios::Constants::IOS_DEVICE_TYPE) {
|
||||
IosDevice::ConstPtr dev = device().dynamicCast<const IosDevice>();
|
||||
IosDevice::ConstPtr dev = std::dynamic_pointer_cast<const IosDevice>(device());
|
||||
setStartMode(AttachToRemoteProcess);
|
||||
setIosPlatform("remote-ios");
|
||||
const QString osVersion = dev->osVersion();
|
||||
@@ -877,7 +877,7 @@ void IosDebugSupport::start()
|
||||
IosRunWorkerFactory::IosRunWorkerFactory()
|
||||
{
|
||||
setProducer([](RunControl *control) -> RunWorker * {
|
||||
IosDevice::ConstPtr iosdevice = control->device().dynamicCast<const IosDevice>();
|
||||
IosDevice::ConstPtr iosdevice = std::dynamic_pointer_cast<const IosDevice>(control->device());
|
||||
if (iosdevice && iosdevice->handler() == IosDevice::Handler::DeviceCtl) {
|
||||
return new DeviceCtlRunner(control);
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ QDebug operator <<(QDebug debug, const IosDeviceType &deviceType);
|
||||
class IosSimulator final : public ProjectExplorer::IDevice
|
||||
{
|
||||
public:
|
||||
using ConstPtr = QSharedPointer<const IosSimulator>;
|
||||
using Ptr = QSharedPointer<IosSimulator>;
|
||||
using ConstPtr = std::shared_ptr<const IosSimulator>;
|
||||
using Ptr = std::shared_ptr<IosSimulator>;
|
||||
ProjectExplorer::IDevice::DeviceInfo deviceInformation() const override;
|
||||
|
||||
ProjectExplorer::IDeviceWidget *createWidget() override;
|
||||
|
||||
Reference in New Issue
Block a user