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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user