diff options
author | Joseph W. Joshua <joejoshw@gmail.com> | 2014-06-11 11:47:25 +0300 |
---|---|---|
committer | Thiago Macieira <thiago@macieira.org> | 2014-08-13 10:48:14 -0700 |
commit | 8ccf2e8f1d05fb34854ce5f5de935d523484e163 (patch) | |
tree | 875be8317c39ef3e4aae1c1cebe99e2bbed8401b /qt-ui/configuredivecomputerdialog.cpp | |
parent | 09ec8a44e5c48b6b6a2e4ebb1253fd3cd94154ae (diff) | |
download | subsurface-8ccf2e8f1d05fb34854ce5f5de935d523484e163.tar.gz |
Change ConfigureDiveComputerDialog to use tabbed interface
Changes the dive computer configuration dialog to use a
tabbed interface. This will make it easier to add new
dive computer models to the interface.
Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com>
Signed-off-by: Thiago Macieira <thiago@macieira.org>
Diffstat (limited to 'qt-ui/configuredivecomputerdialog.cpp')
-rw-r--r-- | qt-ui/configuredivecomputerdialog.cpp | 108 |
1 files changed, 41 insertions, 67 deletions
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index c50306f1a..d9cee9229 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -32,8 +32,6 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigureDiveComputerDialog), config(0), - vendorModel(0), - productModel(0), deviceDetails(0) { ui->setupUi(this); @@ -45,24 +43,14 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : connect (config, SIGNAL(readFinished()), this, SLOT(deviceReadFinished())); connect (config, SIGNAL(deviceDetailsChanged(DeviceDetails*)), this, SLOT(deviceDetailsReceived(DeviceDetails*))); + connect (ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings())); + memset(&device_data, 0, sizeof(device_data)); fill_computer_list(); - - vendorModel = new QStringListModel(vendorList); - ui->vendor->setModel(vendorModel); - if (default_dive_computer_vendor) { - ui->vendor->setCurrentIndex(ui->vendor->findText(default_dive_computer_vendor)); - productModel = new QStringListModel(productList[default_dive_computer_vendor]); - ui->product->setModel(productModel); - if (default_dive_computer_product) - ui->product->setCurrentIndex(ui->product->findText(default_dive_computer_product)); - } if (default_dive_computer_device) ui->device->setEditText(default_dive_computer_device); - memset(&device_data, 0, sizeof(device_data)); - - connect (ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings())); + on_tabWidget_currentChanged(0); } ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog() @@ -70,6 +58,22 @@ ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog() delete ui; } + +static void fillDeviceList(const char *name, void *data) +{ + QComboBox *comboBox = (QComboBox *)data; + comboBox->addItem(name); +} + +void ConfigureDiveComputerDialog::fill_device_list(int dc_type) +{ + int deviceIndex; + ui->device->clear(); + deviceIndex = enumerate_devices(fillDeviceList, ui->device, dc_type); + if (deviceIndex >= 0) + ui->device->setCurrentIndex(deviceIndex); +} + void ConfigureDiveComputerDialog::fill_computer_list() { dc_iterator_t *iterator = NULL; @@ -77,7 +81,6 @@ void ConfigureDiveComputerDialog::fill_computer_list() struct mydescriptor *mydescriptor; - QStringList computer; dc_descriptor_iterator(&iterator); while (dc_iterator_next(iterator, &descriptor) == DC_STATUS_SUCCESS) { const char *vendor = dc_descriptor_get_vendor(descriptor); @@ -110,21 +113,6 @@ void ConfigureDiveComputerDialog::fill_computer_list() qSort(vendorList); } -static void fillDeviceList(const char *name, void *data) -{ - QComboBox *comboBox = (QComboBox *)data; - comboBox->addItem(name); -} - -void ConfigureDiveComputerDialog::fill_device_list(int dc_type) -{ - int deviceIndex; - ui->device->clear(); - deviceIndex = enumerate_devices(fillDeviceList, ui->device, dc_type); - if (deviceIndex >= 0) - ui->device->setCurrentIndex(deviceIndex); -} - void ConfigureDiveComputerDialog::populateDeviceDetails() { deviceDetails->setCustomText(ui->customTextLlineEdit->text()); @@ -140,36 +128,6 @@ void ConfigureDiveComputerDialog::populateDeviceDetails() deviceDetails->setSyncTime(ui->dateTimeSyncCheckBox->isChecked()); } -void ConfigureDiveComputerDialog::on_vendor_currentIndexChanged(const QString &vendor) -{ - int dcType = DC_TYPE_SERIAL; - QAbstractItemModel *currentModel = ui->product->model(); - if (!currentModel) - return; - - productModel = new QStringListModel(productList[vendor]); - ui->product->setModel(productModel); - - if (vendor == QString("Uemis")) - dcType = DC_TYPE_UEMIS; - fill_device_list(dcType); -} - -void ConfigureDiveComputerDialog::on_product_currentIndexChanged(const QString &product) -{ - dc_descriptor_t *descriptor = NULL; - descriptor = descriptorLookup[ui->vendor->currentText() + product]; - - // call dc_descriptor_get_transport to see if the dc_transport_t is DC_TRANSPORT_SERIAL - if (dc_descriptor_get_transport(descriptor) == DC_TRANSPORT_SERIAL) { - // if the dc_transport_t is DC_TRANSPORT_SERIAL, then enable the device node box. - ui->device->setEnabled(true); - } else { - // otherwise disable the device node box - ui->device->setEnabled(false); - } -} - void ConfigureDiveComputerDialog::readSettings() { ui->statusLabel->clear(); @@ -192,13 +150,12 @@ void ConfigureDiveComputerDialog::configError(QString err) void ConfigureDiveComputerDialog::getDeviceData() { device_data.devname = strdup(ui->device->currentText().toUtf8().data()); - device_data.vendor = strdup(ui->vendor->currentText().toUtf8().data()); - device_data.product = strdup(ui->product->currentText().toUtf8().data()); + device_data.vendor = strdup(selected_vendor.toUtf8().data()); + device_data.product = strdup(selected_product.toUtf8().data()); - device_data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()]; + device_data.descriptor = descriptorLookup[selected_vendor + selected_product]; device_data.deviceid = device_data.diveid = 0; - set_default_dive_computer(device_data.vendor, device_data.product); set_default_dive_computer_device(device_data.devname); } @@ -248,8 +205,8 @@ void ConfigureDiveComputerDialog::on_backupButton_clicked() QFileInfo fi(filename); filename = fi.absolutePath().append(QDir::separator()).append("Backup.xml"); QString backupPath = QFileDialog::getSaveFileName(this, tr("Backup Dive Computer Settings"), - filename, tr("Backup files (*.xml)") - ); + filename, tr("Backup files (*.xml)") + ); if (!backupPath.isEmpty()) { populateDeviceDetails(); getDeviceData(); @@ -293,3 +250,20 @@ void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked() } } } + +void ConfigureDiveComputerDialog::on_tabWidget_currentChanged(int index) +{ + switch (index) { + case 0: + selected_vendor = "Heinrichs Weikamp"; + selected_product = "OSTC 3"; + break; + } + + int dcType = DC_TYPE_SERIAL; + + + if (selected_vendor == QString("Uemis")) + dcType = DC_TYPE_UEMIS; + fill_device_list(dcType); +} |