forked from qt-creator/qt-creator
iOS: inline createsimulatordialog.ui
Change-Id: I40c6269a3d0ba61dfbdcc2ac55f4608b9c893e8c Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -24,38 +24,60 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "createsimulatordialog.h"
|
||||
#include "ui_createsimulatordialog.h"
|
||||
|
||||
#include "simulatorcontrol.h"
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
#include <utils/runextensions.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QComboBox>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QPushButton>
|
||||
#include <QVariant>
|
||||
|
||||
namespace Ios {
|
||||
namespace Internal {
|
||||
|
||||
using namespace std::placeholders;
|
||||
namespace Ios::Internal {
|
||||
|
||||
CreateSimulatorDialog::CreateSimulatorDialog(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, m_ui(new Ui::CreateSimulatorDialog)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
resize(320, 160);
|
||||
setWindowTitle(tr("Create Simulator"));
|
||||
|
||||
const auto enableOk = [this] {
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
|
||||
!m_ui->nameEdit->text().isEmpty() &&
|
||||
m_ui->deviceTypeCombo->currentIndex() > 0 &&
|
||||
m_ui->runtimeCombo->currentIndex() > 0);
|
||||
m_nameEdit = new QLineEdit(this);
|
||||
m_deviceTypeCombo = new QComboBox(this);
|
||||
m_runtimeCombo = new QComboBox(this);
|
||||
|
||||
auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
|
||||
using namespace Utils::Layouting;
|
||||
|
||||
Column {
|
||||
Form {
|
||||
tr("Simulator name:"), m_nameEdit, br,
|
||||
tr("Device type:"), m_deviceTypeCombo, br,
|
||||
tr("OS version:"), m_runtimeCombo, br,
|
||||
},
|
||||
buttonBox
|
||||
}.attachTo(this);
|
||||
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
const auto enableOk = [this, buttonBox] {
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
|
||||
!m_nameEdit->text().isEmpty() &&
|
||||
m_deviceTypeCombo->currentIndex() > 0 &&
|
||||
m_runtimeCombo->currentIndex() > 0);
|
||||
};
|
||||
|
||||
connect(m_ui->nameEdit, &QLineEdit::textChanged, this, enableOk);
|
||||
connect(m_ui->runtimeCombo, &QComboBox::currentIndexChanged, this, enableOk);
|
||||
connect(m_ui->deviceTypeCombo, &QComboBox::currentIndexChanged, this, [this, enableOk] {
|
||||
populateRuntimes(m_ui->deviceTypeCombo->currentData().value<DeviceTypeInfo>());
|
||||
connect(m_nameEdit, &QLineEdit::textChanged, this, enableOk);
|
||||
connect(m_runtimeCombo, &QComboBox::currentIndexChanged, this, enableOk);
|
||||
connect(m_deviceTypeCombo, &QComboBox::currentIndexChanged, this, [this, enableOk] {
|
||||
populateRuntimes(m_deviceTypeCombo->currentData().value<DeviceTypeInfo>());
|
||||
enableOk();
|
||||
});
|
||||
|
||||
@@ -74,7 +96,6 @@ CreateSimulatorDialog::CreateSimulatorDialog(QWidget *parent)
|
||||
CreateSimulatorDialog::~CreateSimulatorDialog()
|
||||
{
|
||||
m_futureSync.waitForFinished();
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -82,7 +103,7 @@ CreateSimulatorDialog::~CreateSimulatorDialog()
|
||||
*/
|
||||
QString CreateSimulatorDialog::name() const
|
||||
{
|
||||
return m_ui->nameEdit->text();
|
||||
return m_nameEdit->text();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -94,7 +115,7 @@ QString CreateSimulatorDialog::name() const
|
||||
*/
|
||||
RuntimeInfo CreateSimulatorDialog::runtime() const
|
||||
{
|
||||
return m_ui->runtimeCombo->currentData().value<RuntimeInfo>();
|
||||
return m_runtimeCombo->currentData().value<RuntimeInfo>();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -102,7 +123,7 @@ RuntimeInfo CreateSimulatorDialog::runtime() const
|
||||
*/
|
||||
DeviceTypeInfo CreateSimulatorDialog::deviceType() const
|
||||
{
|
||||
return m_ui->deviceTypeCombo->currentData().value<DeviceTypeInfo>();
|
||||
return m_deviceTypeCombo->currentData().value<DeviceTypeInfo>();
|
||||
}
|
||||
|
||||
/*!
|
||||
@@ -110,30 +131,30 @@ DeviceTypeInfo CreateSimulatorDialog::deviceType() const
|
||||
*/
|
||||
void CreateSimulatorDialog::populateDeviceTypes(const QList<DeviceTypeInfo> &deviceTypes)
|
||||
{
|
||||
m_ui->deviceTypeCombo->clear();
|
||||
m_ui->deviceTypeCombo->addItem(tr("None"));
|
||||
m_deviceTypeCombo->clear();
|
||||
m_deviceTypeCombo->addItem(tr("None"));
|
||||
|
||||
if (deviceTypes.isEmpty())
|
||||
return;
|
||||
|
||||
m_ui->deviceTypeCombo->insertSeparator(1);
|
||||
m_deviceTypeCombo->insertSeparator(1);
|
||||
|
||||
auto addItems = [this, deviceTypes](const QString &filter) {
|
||||
const auto filteredTypes = Utils::filtered(deviceTypes, [filter](const DeviceTypeInfo &type){
|
||||
return type.name.contains(filter, Qt::CaseInsensitive);
|
||||
});
|
||||
for (auto type : filteredTypes) {
|
||||
m_ui->deviceTypeCombo->addItem(type.name, QVariant::fromValue<DeviceTypeInfo>(type));
|
||||
m_deviceTypeCombo->addItem(type.name, QVariant::fromValue<DeviceTypeInfo>(type));
|
||||
}
|
||||
return filteredTypes.count();
|
||||
};
|
||||
|
||||
if (addItems(QStringLiteral("iPhone")) > 0)
|
||||
m_ui->deviceTypeCombo->insertSeparator(m_ui->deviceTypeCombo->count());
|
||||
m_deviceTypeCombo->insertSeparator(m_deviceTypeCombo->count());
|
||||
if (addItems(QStringLiteral("iPad")) > 0)
|
||||
m_ui->deviceTypeCombo->insertSeparator(m_ui->deviceTypeCombo->count());
|
||||
m_deviceTypeCombo->insertSeparator(m_deviceTypeCombo->count());
|
||||
if (addItems(QStringLiteral("TV")) > 0)
|
||||
m_ui->deviceTypeCombo->insertSeparator(m_ui->deviceTypeCombo->count());
|
||||
m_deviceTypeCombo->insertSeparator(m_deviceTypeCombo->count());
|
||||
addItems(QStringLiteral("Watch"));
|
||||
}
|
||||
|
||||
@@ -146,20 +167,20 @@ void CreateSimulatorDialog::populateDeviceTypes(const QList<DeviceTypeInfo> &dev
|
||||
*/
|
||||
void CreateSimulatorDialog::populateRuntimes(const DeviceTypeInfo &deviceType)
|
||||
{
|
||||
m_ui->runtimeCombo->clear();
|
||||
m_ui->runtimeCombo->addItem(tr("None"));
|
||||
m_runtimeCombo->clear();
|
||||
m_runtimeCombo->addItem(tr("None"));
|
||||
|
||||
if (deviceType.name.isEmpty())
|
||||
return;
|
||||
|
||||
m_ui->runtimeCombo->insertSeparator(1);
|
||||
m_runtimeCombo->insertSeparator(1);
|
||||
|
||||
auto addItems = [this](const QString &filter) {
|
||||
const auto filteredTypes = Utils::filtered(m_runtimes, [filter](const RuntimeInfo &runtime){
|
||||
return runtime.name.contains(filter, Qt::CaseInsensitive);
|
||||
});
|
||||
for (auto runtime : filteredTypes) {
|
||||
m_ui->runtimeCombo->addItem(runtime.name, QVariant::fromValue<RuntimeInfo>(runtime));
|
||||
m_runtimeCombo->addItem(runtime.name, QVariant::fromValue<RuntimeInfo>(runtime));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,5 +194,4 @@ void CreateSimulatorDialog::populateRuntimes(const DeviceTypeInfo &deviceType)
|
||||
addItems(QStringLiteral("watchOS"));
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Ios
|
||||
} // Ios::Internal
|
||||
|
||||
Reference in New Issue
Block a user