Commit dff07614 authored by Christian Kandeler's avatar Christian Kandeler
Browse files

Device support: Ensure UI changes are always propagated to the device.



The original problem was that we cannot assume
QLineEdit::editingFinished() is emitted when clicking a button while a
QLineEdit has the focus (QTCREATORBUG-1675). The original solution to
that introduced two more bugs, namely that changes are not visible in
other tabs until the dialog has been closed and reopened and that
pressing "Apply" also applies changes that are done later and which the
user intends to revert by by pressing "Cancel" (QTCREATORBUG-7288).
This patch intends to fix all of these issues.

Task-number: QTCREATORBUG-1675
Task-number: QTCREATORBUG-7288
Change-Id: I569a89f64843e08ee389e3eba6bdcb473ba22393
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 30b55346
......@@ -102,7 +102,6 @@ DeviceSettingsWidget::DeviceSettingsWidget(QWidget *parent)
m_deviceManager(DeviceManager::cloneInstance()),
m_deviceManagerModel(new DeviceManagerModel(m_deviceManager, this)),
m_nameValidator(new NameValidator(m_deviceManager, this)),
m_saveSettingsRequested(false),
m_additionalActionsMapper(new QSignalMapper(this)),
m_configWidget(0)
{
......@@ -115,11 +114,6 @@ DeviceSettingsWidget::DeviceSettingsWidget(QWidget *parent)
DeviceSettingsWidget::~DeviceSettingsWidget()
{
if (m_saveSettingsRequested) {
Core::ICore::settings()->setValue(QLatin1String(LastDeviceIndexKey),
currentIndex());
DeviceManager::replaceInstance();
}
DeviceManager::removeClonedInstance();
delete m_configWidget;
delete m_ui;
......@@ -237,10 +231,17 @@ void DeviceSettingsWidget::fillInValues()
m_ui->nameLineEdit->setText(current->displayName());
}
void DeviceSettingsWidget::updateDeviceFromUi()
{
deviceNameEditingFinished();
if (m_configWidget)
m_configWidget->updateDeviceFromUi();
}
void DeviceSettingsWidget::saveSettings()
{
// We must defer this step because of a stupid bug on MacOS. See QTCREATORBUG-1675.
m_saveSettingsRequested = true;
Core::ICore::settings()->setValue(QLatin1String(LastDeviceIndexKey), currentIndex());
DeviceManager::replaceInstance();
}
int DeviceSettingsWidget::currentIndex() const
......@@ -329,12 +330,14 @@ void DeviceSettingsWidget::handleAdditionalActionRequest(int actionId)
{
const IDevice::ConstPtr device = m_deviceManager->find(currentDevice()->id());
QTC_ASSERT(device, return);
updateDeviceFromUi();
device->executeAction(Core::Id::fromUniqueIdentifier(actionId), this);
}
void DeviceSettingsWidget::handleProcessListRequested()
{
QTC_ASSERT(currentDevice()->canCreateProcessModel(), return);
updateDeviceFromUi();
DeviceProcessesDialog dlg;
dlg.addCloseButton();
dlg.setDevice(currentDevice());
......
......@@ -81,12 +81,12 @@ private:
void clearDetails();
QString parseTestOutput();
void fillInValues();
void updateDeviceFromUi();
Ui::DeviceSettingsWidget *m_ui;
DeviceManager * const m_deviceManager;
DeviceManagerModel * const m_deviceManagerModel;
NameValidator * const m_nameValidator;
bool m_saveSettingsRequested;
QList<QPushButton *> m_additionalActionButtons;
QSignalMapper * const m_additionalActionsMapper;
IDeviceWidget *m_configWidget;
......
......@@ -50,6 +50,18 @@ namespace ProjectExplorer {
class PROJECTEXPLORER_EXPORT IDeviceWidget : public QWidget
{
Q_OBJECT
public:
/*!
* \brief Ensures that all changes in the UI are propagated to the device object.
*
* If the device is always updated right when the change happens, the implementation of
* this function can be empty. Note, however, that you cannot generally rely on the
* QLineEdit::editingFinished() signal being emitted on time if some button in the dialog is
* clicked (e.g. "Apply"). So if you have any handlers for line edit changes, they should
* probably be called here.
*/
virtual void updateDeviceFromUi() = 0;
protected:
IDeviceWidget(const IDevice::Ptr &device, QWidget *parent = 0)
......
......@@ -93,6 +93,14 @@ void BlackBerryDeviceConfigurationWidget::debugTokenEditingFinished()
deviceConfiguration()->setDebugToken(ui->debugToken->path());
}
void BlackBerryDeviceConfigurationWidget::updateDeviceFromUi()
{
hostNameEditingFinished();
passwordEditingFinished();
keyFileEditingFinished();
debugTokenEditingFinished();
}
void BlackBerryDeviceConfigurationWidget::initGui()
{
ui->debugToken->setExpectedKind(Utils::PathChooser::File);
......
......@@ -62,6 +62,7 @@ private slots:
void debugTokenEditingFinished();
private:
void updateDeviceFromUi();
void initGui();
BlackBerryDeviceConfiguration::Ptr deviceConfiguration() const;
......
......@@ -151,6 +151,17 @@ void GenericLinuxDeviceConfigurationWidget::createNewKey()
setPrivateKey(dialog.privateKeyFilePath());
}
void GenericLinuxDeviceConfigurationWidget::updateDeviceFromUi()
{
hostNameEditingFinished();
sshPortEditingFinished();
timeoutEditingFinished();
userNameEditingFinished();
passwordEditingFinished();
keyFileEditingFinished();
handleFreePortsChanged();
}
void GenericLinuxDeviceConfigurationWidget::updatePortsWarningLabel()
{
m_ui->portsWarningLabel->setVisible(!device()->freePorts().hasMore());
......
......@@ -64,6 +64,7 @@ private slots:
void createNewKey();
private:
void updateDeviceFromUi();
void updatePortsWarningLabel();
void initGui();
......
Supports Markdown
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