From 8ccf2e8f1d05fb34854ce5f5de935d523484e163 Mon Sep 17 00:00:00 2001 From: "Joseph W. Joshua" Date: Wed, 11 Jun 2014 11:47:25 +0300 Subject: 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 Signed-off-by: Thiago Macieira --- qt-ui/configuredivecomputerdialog.cpp | 108 +++--- qt-ui/configuredivecomputerdialog.h | 19 +- qt-ui/configuredivecomputerdialog.ui | 612 +++++++++++++++++----------------- 3 files changed, 349 insertions(+), 390 deletions(-) (limited to 'qt-ui') 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); +} diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h index ee1eb4c99..de068c609 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/qt-ui/configuredivecomputerdialog.h @@ -19,10 +19,6 @@ public: ~ConfigureDiveComputerDialog(); private slots: - void on_vendor_currentIndexChanged(const QString &vendor); - - void on_product_currentIndexChanged(const QString &product); - void readSettings(); void configMessage(QString msg); void configError(QString err); @@ -35,24 +31,27 @@ private slots: void on_restoreBackupButton_clicked(); + void on_tabWidget_currentChanged(int index); + private: Ui::ConfigureDiveComputerDialog *ui; + QStringList vendorList; + QHash productList; + ConfigureDiveComputer *config; device_data_t device_data; void getDeviceData(); - QStringList vendorList; - QHash productList; QHash descriptorLookup; - - QStringListModel *vendorModel; - QStringListModel *productModel; - void fill_computer_list(); void fill_device_list(int dc_type); + void fill_computer_list(); DeviceDetails *deviceDetails; void populateDeviceDetails(); + + QString selected_vendor; + QString selected_product; }; #endif // CONFIGUREDIVECOMPUTERDIALOG_H diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui index e117db644..22bd9b563 100644 --- a/qt-ui/configuredivecomputerdialog.ui +++ b/qt-ui/configuredivecomputerdialog.ui @@ -6,38 +6,14 @@ 0 0 - 629 - 496 + 594 + 509 Configure Dive Computer - - - - - - Vendor - - - - - - - Dive Computer - - - - - - - - - - - @@ -113,317 +89,327 @@ - - - - - Custom Text: - - - - - - - Sampling Rate: - - - - - - - Brightness: - - - - - - - Salinity (0-5%): - - - - - - - Sync dive computer time with PC - - - - - - - % - - - 5 - - - - - - - m - - - - - - - true - - - - - - - Last Deco: - - - - - - - Serial No. - - - - - - - Language: - - - - - - - - m/°C - + + + 0 + + + + HW OSTC 3 + + + + + + m + + - - - ft/°F - + + + + Sync dive computer time with PC + + - - - - - - - Eco - + + + + Units: + + - - - Medium - + + + + Salinity (0-5%): + + - - - High - + + + + Language: + + - - - - - - - MMDDYY - + + + + Custom Text: + + - - - DDMMYY - + + + + + 1 + 0 + + + - - - YYMMDD - + + + + Date Format: + + - - - - - - - English - + + + + Compass Gain: + + - - - German - + + + + true + + - - - French - + + + + Last Deco: + + - - - Italian - + + + + Qt::Vertical + + + + 20 + 40 + + + - - - - - - true - - - - - - - Date Format: - - - - - - - Firmware Version: - - - - - - - - 1 - 0 - - - - - - - - Units: - - - - - - - - 2s - + + + + true + + - - - 10s - + + + + + Standard + + + + + Red + + + + + Green + + + + + Blue + + + - - - - - - Dive Mode Colour: - - - - - - - - Standard - + + + + + MMDDYY + + + + + DDMMYY + + + + + YYMMDD + + + - - - Red - + + + + + m/°C + + + + + ft/°F + + + - - - Green - + + + + + English + + + + + German + + + + + French + + + + + Italian + + + - - - Blue - + + + + Brightness: + + - - - - - - Compass Gain: - - - - - - - - 1 - 0 - - - - - 230LSB/Gauss - + + + + Serial No. + + - - - 330LSB/Gauss - + + + + Dive Mode Colour: + + - - - 390LSB/Gauss - + + + + Sampling Rate: + + - - - 440LSB/Gauss - + + + + + Eco + + + + + Medium + + + + + High + + + - - - 660LSB/Gauss - + + + + + 2s + + + + + 10s + + + - - - 820LSB/Gauss - + + + + Firmware Version: + + - - - 1090LSB/Gauss - + + + + % + + + 5 + + - - - 1370LSB/Gauss - + + + + + 1 + 0 + + + + + 230LSB/Gauss + + + + + 330LSB/Gauss + + + + + 390LSB/Gauss + + + + + 440LSB/Gauss + + + + + 660LSB/Gauss + + + + + 820LSB/Gauss + + + + + 1090LSB/Gauss + + + + + 1370LSB/Gauss + + + - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - + + + @@ -469,13 +455,13 @@ - vendor - product device search retrieveDetails + saveSettingsPushButton backupButton restoreBackupButton + tabWidget serialNoLineEdit firmwareVersionLineEdit customTextLlineEdit -- cgit v1.2.3-70-g09d2