forked from qt-creator/qt-creator
ProjectExplorer: Paddle back on IDevice aspect exposure
Make the aspects private, but provide accessors to value and defaultValue as needed. This allows setters to be kept protected when wanted. Change-Id: I26f93f62d4ac2e7346f95543c38d8ac9156348c2 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -177,7 +177,7 @@ static IDevice::Ptr createDeviceFromInfo(const CreateAvdInfo &info)
|
||||
const Id deviceId = AndroidDevice::idFromAvdInfo(info);
|
||||
dev->setupId(IDevice::AutoDetected, deviceId);
|
||||
dev->setMachineType(IDevice::Emulator);
|
||||
dev->displayName.setValue(info.name);
|
||||
dev->setDisplayName(info.name);
|
||||
dev->setDeviceState(IDevice::DeviceConnected);
|
||||
dev->setAvdPath(avdFilePath() / (info.name + ".avd"));
|
||||
dev->setExtraData(Constants::AndroidAvdName, info.name);
|
||||
@@ -349,7 +349,7 @@ AndroidDevice::AndroidDevice()
|
||||
{
|
||||
setupId(IDevice::AutoDetected, Constants::ANDROID_DEVICE_ID);
|
||||
setType(Constants::ANDROID_DEVICE_TYPE);
|
||||
displayName.setDefaultValue(Tr::tr("Run on Android"));
|
||||
setDefaultDisplayName(Tr::tr("Run on Android"));
|
||||
setDisplayType(Tr::tr("Android"));
|
||||
setMachineType(IDevice::Hardware);
|
||||
setOsType(OsType::OsTypeOtherUnix);
|
||||
@@ -672,7 +672,7 @@ static void handleDevicesListChange(const QString &serialNumber)
|
||||
} else {
|
||||
AndroidDevice *newDev = new AndroidDevice();
|
||||
newDev->setupId(IDevice::AutoDetected, id);
|
||||
newDev->displayName.setValue(displayName);
|
||||
newDev->setDisplayName(displayName);
|
||||
newDev->setMachineType(IDevice::Hardware);
|
||||
newDev->setDeviceState(state);
|
||||
|
||||
@@ -758,7 +758,7 @@ static void handleAvdListChange(const AndroidDeviceInfoList &avdList)
|
||||
|
||||
AndroidDevice *newDev = new AndroidDevice;
|
||||
newDev->setupId(IDevice::AutoDetected, deviceId);
|
||||
newDev->displayName.setValue(displayName);
|
||||
newDev->setDisplayName(displayName);
|
||||
newDev->setMachineType(item.type);
|
||||
newDev->setDeviceState(item.state);
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ ProjectExplorer::IDevice::Ptr BareMetalDeviceConfigurationWizard::device() const
|
||||
{
|
||||
const auto dev = BareMetalDevice::create();
|
||||
dev->setupId(ProjectExplorer::IDevice::ManuallyAdded, Utils::Id());
|
||||
dev->displayName.setDefaultValue(m_setupPage->configurationName());
|
||||
dev->setDefaultDisplayName(m_setupPage->configurationName());
|
||||
dev->setType(Constants::BareMetalOsType);
|
||||
dev->setMachineType(ProjectExplorer::IDevice::Hardware);
|
||||
dev->setDebugServerProviderId(m_setupPage->debugServerProviderId());
|
||||
|
||||
@@ -84,7 +84,7 @@ void DeviceDetector::handleDeviceEvent(QdbDeviceTracker::DeviceEventType eventTy
|
||||
const QString name = Tr::tr("Boot to Qt device %1").arg(serial);
|
||||
QdbDevice::Ptr device = QdbDevice::create();
|
||||
device->setupId(IDevice::AutoDetected, deviceId);
|
||||
device->displayName.setValue(name);
|
||||
device->setDisplayName(name);
|
||||
device->setType(Qdb::Constants::QdbLinuxOsType);
|
||||
device->setMachineType(IDevice::Hardware);
|
||||
device->setExtraData(ProjectExplorer::Constants::SUPPORTS_RSYNC, true);
|
||||
|
||||
@@ -207,7 +207,7 @@ public:
|
||||
{
|
||||
QdbDevice::Ptr device = QdbDevice::create();
|
||||
|
||||
device->displayName.setValue(settingsPage.deviceName());
|
||||
device->setDisplayName(settingsPage.deviceName());
|
||||
device->setupId(ProjectExplorer::IDevice::ManuallyAdded, Utils::Id());
|
||||
device->setType(Constants::QdbLinuxOsType);
|
||||
device->setMachineType(ProjectExplorer::IDevice::Hardware);
|
||||
|
||||
@@ -1001,8 +1001,8 @@ void DockerDevice::fromMap(const Store &map)
|
||||
// This is the only place where we can correctly set the default name.
|
||||
// Only here do we know the image id and the repo reliably, no matter
|
||||
// where or how we were created.
|
||||
if (displayName.value() == displayName.defaultValue()) {
|
||||
displayName.setDefaultValue(
|
||||
if (displayName() == defaultDisplayName()) {
|
||||
setDefaultDisplayName(
|
||||
Tr::tr("Docker Image \"%1\" (%2)").arg(repoAndTag()).arg(imageId.value()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ IosDevice::IosDevice(CtorHelper)
|
||||
: m_lastPort(Constants::IOS_DEVICE_PORT_START)
|
||||
{
|
||||
setType(Constants::IOS_DEVICE_TYPE);
|
||||
displayName.setDefaultValue(IosDevice::name());
|
||||
setDefaultDisplayName(IosDevice::name());
|
||||
setDisplayType(Tr::tr("iOS"));
|
||||
setMachineType(IDevice::Hardware);
|
||||
setOsType(Utils::OsTypeMac);
|
||||
@@ -248,7 +248,7 @@ void IosDeviceManager::deviceConnected(const QString &uid, const QString &name)
|
||||
if (!dev) {
|
||||
auto newDev = new IosDevice(uid);
|
||||
if (!name.isNull())
|
||||
newDev->displayName.setValue(name);
|
||||
newDev->setDisplayName(name);
|
||||
qCDebug(detectLog) << "adding ios device " << uid;
|
||||
devManager->addDevice(IDevice::ConstPtr(newDev));
|
||||
} else if (dev->deviceState() != IDevice::DeviceConnected &&
|
||||
@@ -364,7 +364,7 @@ void IosDeviceManager::deviceInfo(const QString &uid,
|
||||
}
|
||||
if (!skipUpdate) {
|
||||
if (info.contains(kDeviceName))
|
||||
newDev->displayName.setValue(info.value(kDeviceName));
|
||||
newDev->setDisplayName(info.value(kDeviceName));
|
||||
newDev->m_extraInfo = info;
|
||||
newDev->m_handler = handler;
|
||||
qCDebug(detectLog) << "updated info of ios device " << uid;
|
||||
|
||||
@@ -28,7 +28,7 @@ IosSimulator::IosSimulator(Id id)
|
||||
setType(Constants::IOS_SIMULATOR_TYPE);
|
||||
setMachineType(IDevice::Emulator);
|
||||
setOsType(Utils::OsTypeMac);
|
||||
displayName.setDefaultValue(Tr::tr("iOS Simulator"));
|
||||
setDefaultDisplayName(Tr::tr("iOS Simulator"));
|
||||
setDisplayType(Tr::tr("iOS Simulator"));
|
||||
setDeviceState(DeviceStateUnknown);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ McuSupportDevice::McuSupportDevice()
|
||||
setupId(IDevice::AutoDetected, Constants::DEVICE_ID);
|
||||
setType(Constants::DEVICE_TYPE);
|
||||
const QString displayNameAndType = Tr::tr("MCU Device");
|
||||
displayName.setDefaultValue(displayNameAndType);
|
||||
setDefaultDisplayName(displayNameAndType);
|
||||
setDisplayType(displayNameAndType);
|
||||
setDeviceState(IDevice::DeviceStateUnknown);
|
||||
setMachineType(IDevice::Hardware);
|
||||
|
||||
@@ -42,7 +42,7 @@ DesktopDevice::DesktopDevice()
|
||||
|
||||
setupId(IDevice::AutoDetected, DESKTOP_DEVICE_ID);
|
||||
setType(DESKTOP_DEVICE_TYPE);
|
||||
displayName.setDefaultValue(Tr::tr("Local PC"));
|
||||
setDefaultDisplayName(Tr::tr("Local PC"));
|
||||
setDisplayType(Tr::tr("Desktop"));
|
||||
|
||||
setDeviceState(IDevice::DeviceStateUnknown);
|
||||
|
||||
@@ -261,7 +261,7 @@ void DeviceManager::addDevice(const IDevice::ConstPtr &_device)
|
||||
}
|
||||
|
||||
// TODO: make it thread safe?
|
||||
device->displayName.setValue(Utils::makeUniquelyNumbered(device->displayName(), names));
|
||||
device->setDisplayName(Utils::makeUniquelyNumbered(device->displayName(), names));
|
||||
|
||||
const int pos = d->indexForId(device->id());
|
||||
|
||||
@@ -567,7 +567,7 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
TestDeviceFactory factory;
|
||||
|
||||
TestDevice::Ptr dev = IDevice::Ptr(new TestDevice);
|
||||
dev->displayName.setValue(QLatin1String("blubbdiblubbfurz!"));
|
||||
dev->setDisplayName(QLatin1String("blubbdiblubbfurz!"));
|
||||
QVERIFY(dev->isAutoDetected());
|
||||
QCOMPARE(dev->deviceState(), IDevice::DeviceStateUnknown);
|
||||
QCOMPARE(dev->type(), TestDevice::testTypeId());
|
||||
@@ -628,7 +628,7 @@ void ProjectExplorerTest::testDeviceManager()
|
||||
TestDevice::Ptr dev3 = IDevice::Ptr(new TestDevice);
|
||||
QVERIFY(dev->id() != dev3->id());
|
||||
|
||||
dev3->displayName.setValue(dev->displayName());
|
||||
dev3->setDisplayName(dev->displayName());
|
||||
mgr->addDevice(dev3);
|
||||
QCOMPARE(mgr->deviceAt(mgr->deviceCount() - 1)->displayName(),
|
||||
QString(dev3->displayName() + QLatin1Char('2')));
|
||||
|
||||
@@ -340,7 +340,7 @@ void DeviceSettingsWidget::currentDeviceChanged(int index)
|
||||
}
|
||||
|
||||
Layouting::Column item{Layouting::noMargin};
|
||||
device->displayName.addToLayout(item);
|
||||
device->addDisplayNameToLayout(item);
|
||||
QWidget *newEdit = item.emerge();
|
||||
QLayoutItem *oldItem = m_generalFormLayout->replaceWidget(m_deviceNameEditWidget, newEdit);
|
||||
QTC_CHECK(oldItem);
|
||||
|
||||
@@ -144,6 +144,10 @@ public:
|
||||
QList<IDevice::DeviceAction> deviceActions;
|
||||
Store extraData;
|
||||
IDevice::OpenTerminal openTerminal;
|
||||
|
||||
Utils::StringAspect displayName;
|
||||
Utils::FilePathAspect debugServerPath;
|
||||
Utils::FilePathAspect qmlRunCommand;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
@@ -155,12 +159,9 @@ IDevice::IDevice()
|
||||
{
|
||||
setAutoApply(false);
|
||||
|
||||
displayName.setSettingsKey(DisplayNameKey);
|
||||
displayName.setDisplayStyle(StringAspect::DisplayStyle::LineEditDisplay);
|
||||
|
||||
debugServerPath.setSettingsKey(DebugServerKey);
|
||||
|
||||
qmlRunCommand.setSettingsKey(QmlRuntimeKey);
|
||||
registerAspect(&d->displayName);
|
||||
d->displayName.setSettingsKey(DisplayNameKey);
|
||||
d->displayName.setDisplayStyle(StringAspect::DisplayStyle::LineEditDisplay);
|
||||
|
||||
auto validateDisplayName = [](const QString &old,
|
||||
const QString &newValue) -> expected_str<void> {
|
||||
@@ -176,9 +177,9 @@ IDevice::IDevice()
|
||||
return {};
|
||||
};
|
||||
|
||||
displayName.setValidationFunction(
|
||||
d->displayName.setValidationFunction(
|
||||
[this, validateDisplayName](FancyLineEdit *edit, QString *errorMsg) -> bool {
|
||||
auto result = validateDisplayName(displayName.value(), edit->text());
|
||||
auto result = validateDisplayName(d->displayName.value(), edit->text());
|
||||
if (result)
|
||||
return true;
|
||||
|
||||
@@ -188,7 +189,7 @@ IDevice::IDevice()
|
||||
return false;
|
||||
});
|
||||
|
||||
displayName.setValueAcceptor(
|
||||
d->displayName.setValueAcceptor(
|
||||
[validateDisplayName](const QString &old,
|
||||
const QString &newValue) -> std::optional<QString> {
|
||||
if (!validateDisplayName(old, newValue))
|
||||
@@ -196,6 +197,12 @@ IDevice::IDevice()
|
||||
|
||||
return newValue;
|
||||
});
|
||||
|
||||
registerAspect(&d->debugServerPath);
|
||||
d->debugServerPath.setSettingsKey(DebugServerKey);
|
||||
|
||||
registerAspect(&d->qmlRunCommand);
|
||||
d->qmlRunCommand.setSettingsKey(QmlRuntimeKey);
|
||||
}
|
||||
|
||||
IDevice::~IDevice() = default;
|
||||
@@ -253,6 +260,26 @@ FilePath IDevice::filePath(const QString &pathOnDevice) const
|
||||
return FilePath::fromParts(u"device", id().toString(), pathOnDevice);
|
||||
}
|
||||
|
||||
FilePath IDevice::debugServerPath() const
|
||||
{
|
||||
return d->debugServerPath();
|
||||
}
|
||||
|
||||
void IDevice::setDebugServerPath(const FilePath &path)
|
||||
{
|
||||
d->debugServerPath.setValue(path);
|
||||
}
|
||||
|
||||
FilePath IDevice::qmlRunCommand() const
|
||||
{
|
||||
return d->qmlRunCommand();
|
||||
}
|
||||
|
||||
void IDevice::setQmlRunCommand(const FilePath &path)
|
||||
{
|
||||
d->qmlRunCommand.setValue(path);
|
||||
}
|
||||
|
||||
bool IDevice::handlesFile(const FilePath &filePath) const
|
||||
{
|
||||
if (filePath.scheme() == u"device" && filePath.host() == id().toString())
|
||||
@@ -566,6 +593,31 @@ IDevice::Ptr IDevice::clone() const
|
||||
return device;
|
||||
}
|
||||
|
||||
QString IDevice::displayName() const
|
||||
{
|
||||
return d->displayName();
|
||||
}
|
||||
|
||||
void IDevice::setDisplayName(const QString &name)
|
||||
{
|
||||
d->displayName.setValue(name);
|
||||
}
|
||||
|
||||
QString IDevice::defaultDisplayName() const
|
||||
{
|
||||
return d->displayName.defaultValue();
|
||||
}
|
||||
|
||||
void IDevice::setDefaultDisplayName(const QString &name)
|
||||
{
|
||||
d->displayName.setDefaultValue(name);
|
||||
}
|
||||
|
||||
void IDevice::addDisplayNameToLayout(Layouting::Layout &layout) const
|
||||
{
|
||||
d->displayName.addToLayout(layout);
|
||||
}
|
||||
|
||||
QString IDevice::deviceStateToString() const
|
||||
{
|
||||
switch (d->deviceState) {
|
||||
|
||||
@@ -100,7 +100,13 @@ public:
|
||||
|
||||
virtual Ptr clone() const;
|
||||
|
||||
Utils::StringAspect displayName{this};
|
||||
QString displayName() const;
|
||||
void setDisplayName(const QString &name);
|
||||
|
||||
QString defaultDisplayName() const;
|
||||
void setDefaultDisplayName(const QString &name);
|
||||
|
||||
void addDisplayNameToLayout(Layouting::Layout &layout) const;
|
||||
|
||||
// Provide some information on the device suitable for formated
|
||||
// output, e.g. in tool tips. Get a list of name value pairs.
|
||||
@@ -173,8 +179,11 @@ public:
|
||||
virtual Utils::FilePath rootPath() const;
|
||||
virtual Utils::FilePath filePath(const QString &pathOnDevice) const;
|
||||
|
||||
Utils::FilePathAspect debugServerPath{this};
|
||||
Utils::FilePathAspect qmlRunCommand{this};
|
||||
Utils::FilePath debugServerPath() const;
|
||||
void setDebugServerPath(const Utils::FilePath &path);
|
||||
|
||||
Utils::FilePath qmlRunCommand() const;
|
||||
void setQmlRunCommand(const Utils::FilePath &path);
|
||||
|
||||
void setExtraData(Utils::Id kind, const QVariant &data);
|
||||
QVariant extraData(Utils::Id kind) const;
|
||||
|
||||
@@ -79,7 +79,7 @@ IDevice::Ptr IDeviceFactory::construct() const
|
||||
|
||||
IDevice::Ptr device = m_constructor();
|
||||
QTC_ASSERT(device, return {});
|
||||
device->displayName.setDefaultValue(displayName());
|
||||
device->setDisplayName(displayName());
|
||||
return device;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
QnxDevice()
|
||||
{
|
||||
setDisplayType(Tr::tr("QNX"));
|
||||
displayName.setDefaultValue(Tr::tr("QNX Device"));
|
||||
setDefaultDisplayName(Tr::tr("QNX Device"));
|
||||
setOsType(OsTypeOtherUnix);
|
||||
setupId(IDevice::ManuallyAdded);
|
||||
setType(Constants::QNX_QNX_OS_TYPE);
|
||||
|
||||
@@ -217,12 +217,12 @@ void GenericLinuxDeviceConfigurationWidget::keyFileEditingFinished()
|
||||
|
||||
void GenericLinuxDeviceConfigurationWidget::gdbServerEditingFinished()
|
||||
{
|
||||
device()->debugServerPath.setValue(m_gdbServerLineEdit->filePath());
|
||||
device()->setDebugServerPath(m_gdbServerLineEdit->filePath());
|
||||
}
|
||||
|
||||
void GenericLinuxDeviceConfigurationWidget::qmlRuntimeEditingFinished()
|
||||
{
|
||||
device()->qmlRunCommand.setValue(m_qmlRuntimeLineEdit->filePath());
|
||||
device()->setQmlRunCommand(m_qmlRuntimeLineEdit->filePath());
|
||||
}
|
||||
|
||||
void GenericLinuxDeviceConfigurationWidget::handleFreePortsChanged()
|
||||
|
||||
@@ -1014,7 +1014,7 @@ LinuxDevice::LinuxDevice()
|
||||
setFileAccess(&d->m_fileAccess);
|
||||
setDisplayType(Tr::tr("Remote Linux"));
|
||||
setOsType(OsTypeLinux);
|
||||
displayName.setDefaultValue(Tr::tr("Remote Linux Device"));
|
||||
setDefaultDisplayName(Tr::tr("Remote Linux Device"));
|
||||
|
||||
setupId(IDevice::ManuallyAdded, Utils::Id());
|
||||
setType(Constants::GenericLinuxOsType);
|
||||
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
&& !m_userNameLineEdit->text().trimmed().isEmpty();
|
||||
}
|
||||
bool validatePage() final {
|
||||
m_device->displayName.setValue(m_nameLineEdit->text().trimmed());
|
||||
m_device->setDisplayName(m_nameLineEdit->text().trimmed());
|
||||
SshParameters sshParams = m_device->sshParameters();
|
||||
sshParams.setHost(m_hostNameLineEdit->text().trimmed());
|
||||
sshParams.setUserName(m_userNameLineEdit->text().trimmed());
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
setupId(IDevice::AutoDetected, Constants::WEBASSEMBLY_DEVICE_DEVICE_ID);
|
||||
setType(Constants::WEBASSEMBLY_DEVICE_TYPE);
|
||||
const QString displayNameAndType = Tr::tr("Web Browser");
|
||||
displayName.setDefaultValue(displayNameAndType);
|
||||
setDefaultDisplayName(displayNameAndType);
|
||||
setDisplayType(displayNameAndType);
|
||||
setDeviceState(IDevice::DeviceStateUnknown);
|
||||
setMachineType(IDevice::Hardware);
|
||||
|
||||
Reference in New Issue
Block a user