2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* maintab.cpp
|
|
|
|
*
|
|
|
|
* classes for the "notebook" area of the main window of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-07 22:20:43 +00:00
|
|
|
#include "maintab.h"
|
|
|
|
#include "ui_maintab.h"
|
2013-05-19 03:09:36 +00:00
|
|
|
#include "mainwindow.h"
|
2013-05-07 03:36:37 +00:00
|
|
|
#include "../helpers.h"
|
|
|
|
#include "../statistics.h"
|
2013-05-19 03:09:36 +00:00
|
|
|
#include "divelistview.h"
|
2013-05-22 17:11:49 +00:00
|
|
|
#include "modeldelegates.h"
|
2013-04-13 13:17:59 +00:00
|
|
|
|
|
|
|
#include <QLabel>
|
2013-05-18 23:42:59 +00:00
|
|
|
#include <QDebug>
|
2013-04-07 22:20:43 +00:00
|
|
|
|
|
|
|
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
2013-04-13 13:17:59 +00:00
|
|
|
ui(new Ui::MainTab()),
|
|
|
|
weightModel(new WeightModel()),
|
2013-05-18 23:42:59 +00:00
|
|
|
cylindersModel(new CylindersModel()),
|
|
|
|
currentDive(0)
|
2013-04-07 22:20:43 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2013-04-13 13:17:59 +00:00
|
|
|
ui->cylinders->setModel(cylindersModel);
|
|
|
|
ui->weights->setModel(weightModel);
|
2013-05-18 23:42:59 +00:00
|
|
|
ui->diveNotesMessage->hide();
|
|
|
|
ui->diveNotesMessage->setCloseButtonVisible(false);
|
2013-05-19 14:19:57 +00:00
|
|
|
|
2013-05-20 00:38:20 +00:00
|
|
|
// we start out with the fields read-only; once things are
|
|
|
|
// filled from a dive, they are made writeable
|
|
|
|
ui->location->setReadOnly(true);
|
|
|
|
ui->divemaster->setReadOnly(true);
|
|
|
|
ui->buddy->setReadOnly(true);
|
|
|
|
ui->suit->setReadOnly(true);
|
|
|
|
ui->notes->setReadOnly(true);
|
|
|
|
ui->rating->setReadOnly(true);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->setReadOnly(true);
|
2013-05-23 03:00:26 +00:00
|
|
|
|
2013-05-19 19:56:27 +00:00
|
|
|
ui->editAccept->hide();
|
|
|
|
ui->editReset->hide();
|
2013-05-19 14:45:01 +00:00
|
|
|
|
|
|
|
ui->location->installEventFilter(this);
|
|
|
|
ui->divemaster->installEventFilter(this);
|
|
|
|
ui->buddy->installEventFilter(this);
|
|
|
|
ui->suit->installEventFilter(this);
|
|
|
|
ui->notes->installEventFilter(this);
|
|
|
|
ui->rating->installEventFilter(this);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->installEventFilter(this);
|
2013-05-09 07:32:27 +00:00
|
|
|
|
|
|
|
/* example of where code is more concise than Qt designer */
|
|
|
|
QList<QObject *> infoTabWidgets = ui->infoTab->children();
|
2013-05-19 16:00:57 +00:00
|
|
|
Q_FOREACH(QObject* obj, infoTabWidgets) {
|
2013-05-09 07:32:27 +00:00
|
|
|
QLabel* label = qobject_cast<QLabel *>(obj);
|
|
|
|
if (label)
|
|
|
|
label->setAlignment(Qt::AlignHCenter);
|
|
|
|
}
|
2013-05-10 22:56:05 +00:00
|
|
|
QList<QObject *> statisticsTabWidgets = ui->statisticsTab->children();
|
2013-05-19 16:00:57 +00:00
|
|
|
Q_FOREACH(QObject* obj, statisticsTabWidgets) {
|
2013-05-10 22:56:05 +00:00
|
|
|
QLabel* label = qobject_cast<QLabel *>(obj);
|
|
|
|
if (label)
|
|
|
|
label->setAlignment(Qt::AlignHCenter);
|
|
|
|
}
|
2013-05-22 12:17:18 +00:00
|
|
|
|
|
|
|
/*Thid couldn't be done on the ui file because element
|
|
|
|
is floating, instead of being fixed on the layout. */
|
|
|
|
QIcon plusIcon(":plus");
|
|
|
|
addCylinder = new QPushButton(plusIcon, QString(), ui->cylindersGroup);
|
|
|
|
addCylinder->setFlat(true);
|
|
|
|
addCylinder->setToolTip(tr("Add Cylinder"));
|
2013-05-22 12:40:26 +00:00
|
|
|
connect(addCylinder, SIGNAL(clicked(bool)), this, SLOT(addCylinder_clicked()));
|
2013-05-22 12:42:35 +00:00
|
|
|
addCylinder->setEnabled(false);
|
2013-05-22 12:17:18 +00:00
|
|
|
addWeight = new QPushButton(plusIcon, QString(), ui->weightGroup);
|
|
|
|
addWeight->setFlat(true);
|
|
|
|
addWeight->setToolTip(tr("Add Weight System"));
|
2013-05-22 12:40:26 +00:00
|
|
|
connect(addWeight, SIGNAL(clicked(bool)), this, SLOT(addWeight_clicked()));
|
2013-05-22 12:42:35 +00:00
|
|
|
addWeight->setEnabled(false);
|
2013-05-22 14:00:20 +00:00
|
|
|
|
|
|
|
connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders->model(), SLOT(remove(QModelIndex)));
|
|
|
|
connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex)));
|
|
|
|
|
|
|
|
ui->cylinders->setColumnWidth( CylindersModel::REMOVE, 24);
|
|
|
|
ui->cylinders->horizontalHeader()->setResizeMode (CylindersModel::REMOVE , QHeaderView::Fixed);
|
2013-05-22 17:11:49 +00:00
|
|
|
ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
|
2013-05-22 14:00:20 +00:00
|
|
|
ui->weights->setColumnWidth( WeightModel::REMOVE, 24);
|
|
|
|
ui->cylinders->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
|
2013-05-22 12:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need to manually position the 'plus' on cylinder and weight.
|
|
|
|
void MainTab::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
if (ui->cylindersGroup->isVisible())
|
|
|
|
addCylinder->setGeometry( ui->cylindersGroup->contentsRect().width() - 30, 2, 24,24);
|
|
|
|
|
|
|
|
if (ui->weightGroup->isVisible())
|
|
|
|
addWeight->setGeometry( ui->weightGroup->contentsRect().width() - 30, 2, 24,24);
|
|
|
|
|
|
|
|
QTabWidget::resizeEvent(event);
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:17:18 +00:00
|
|
|
void MainTab::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
QTabWidget::showEvent(event);
|
|
|
|
addCylinder->setGeometry( ui->cylindersGroup->contentsRect().width() - 30, 2, 24,24);
|
|
|
|
addWeight->setGeometry( ui->weightGroup->contentsRect().width() - 30, 2, 24,24);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-19 14:45:01 +00:00
|
|
|
bool MainTab::eventFilter(QObject* object, QEvent* event)
|
|
|
|
{
|
2013-05-23 03:00:26 +00:00
|
|
|
if (event->type() == QEvent::FocusIn || event->type() == QEvent::MouseButtonPress) {
|
2013-05-20 00:38:20 +00:00
|
|
|
if (ui->editAccept->isVisible() || !currentDive)
|
2013-05-19 14:45:01 +00:00
|
|
|
return false;
|
2013-05-20 00:38:20 +00:00
|
|
|
|
2013-05-19 19:56:27 +00:00
|
|
|
ui->editAccept->setChecked(true);
|
|
|
|
ui->editAccept->show();
|
|
|
|
ui->editReset->show();
|
|
|
|
on_editAccept_clicked(true);
|
2013-05-19 14:45:01 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
void MainTab::clearEquipment()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::clearInfo()
|
|
|
|
{
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->sacText->clear();
|
|
|
|
ui->otuText->clear();
|
|
|
|
ui->oxygenHeliumText->clear();
|
|
|
|
ui->gasUsedText->clear();
|
|
|
|
ui->dateText->clear();
|
|
|
|
ui->diveTimeText->clear();
|
|
|
|
ui->surfaceIntervalText->clear();
|
|
|
|
ui->maximumDepthText->clear();
|
|
|
|
ui->averageDepthText->clear();
|
|
|
|
ui->waterTemperatureText->clear();
|
|
|
|
ui->airTemperatureText->clear();
|
|
|
|
ui->airPressureText->clear();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::clearStats()
|
|
|
|
{
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->maximumDepthAllText->clear();
|
|
|
|
ui->minimumDepthAllText->clear();
|
|
|
|
ui->averageDepthAllText->clear();
|
|
|
|
ui->maximumSacAllText->clear();
|
|
|
|
ui->minimumSacAllText->clear();
|
|
|
|
ui->averageSacAllText->clear();
|
|
|
|
ui->divesAllText->clear();
|
|
|
|
ui->maximumTemperatureAllText->clear();
|
|
|
|
ui->minimumTemperatureAllText->clear();
|
|
|
|
ui->averageTemperatureAllText->clear();
|
|
|
|
ui->totalTimeAllText->clear();
|
|
|
|
ui->averageTimeAllText->clear();
|
|
|
|
ui->longestAllText->clear();
|
|
|
|
ui->shortestAllText->clear();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 17:16:16 +00:00
|
|
|
#define UPDATE_TEXT(d, field) \
|
|
|
|
if (!d || !d->field) \
|
|
|
|
ui->field->setText(""); \
|
|
|
|
else \
|
|
|
|
ui->field->setText(d->field)
|
|
|
|
|
2013-05-07 03:36:37 +00:00
|
|
|
|
2013-05-06 16:23:14 +00:00
|
|
|
void MainTab::updateDiveInfo(int dive)
|
|
|
|
{
|
|
|
|
// So, this is what happens now:
|
|
|
|
// Every tab should be populated from this method,
|
|
|
|
// it will be called whenever a new dive is selected
|
|
|
|
// I'm already populating the 'notes' box
|
|
|
|
// to show how it can be done.
|
2013-05-14 07:28:30 +00:00
|
|
|
// If you are unsure about the name of something,
|
2013-05-06 16:23:14 +00:00
|
|
|
// open the file maintab.ui on the designer
|
|
|
|
// click on the item and check its objectName,
|
|
|
|
// the access is ui->objectName from here on.
|
2013-05-07 03:36:37 +00:00
|
|
|
volume_t sacVal;
|
2013-05-20 05:42:24 +00:00
|
|
|
temperature_t temp;
|
2013-05-19 15:08:29 +00:00
|
|
|
struct dive *prevd;
|
2013-05-06 16:23:14 +00:00
|
|
|
struct dive *d = get_dive(dive);
|
2013-05-19 15:08:29 +00:00
|
|
|
|
2013-05-20 05:42:24 +00:00
|
|
|
process_selected_dives();
|
2013-05-19 15:08:29 +00:00
|
|
|
process_all_dives(d, &prevd);
|
2013-05-18 23:42:59 +00:00
|
|
|
currentDive = d;
|
2013-05-06 17:16:16 +00:00
|
|
|
UPDATE_TEXT(d, notes);
|
|
|
|
UPDATE_TEXT(d, location);
|
|
|
|
UPDATE_TEXT(d, suit);
|
|
|
|
UPDATE_TEXT(d, divemaster);
|
|
|
|
UPDATE_TEXT(d, buddy);
|
2013-05-10 22:56:05 +00:00
|
|
|
/* infoTab */
|
2013-05-08 19:08:00 +00:00
|
|
|
if (d) {
|
2013-05-20 00:38:20 +00:00
|
|
|
/* make the fields writeable */
|
|
|
|
ui->location->setReadOnly(false);
|
|
|
|
ui->divemaster->setReadOnly(false);
|
|
|
|
ui->buddy->setReadOnly(false);
|
|
|
|
ui->suit->setReadOnly(false);
|
|
|
|
ui->notes->setReadOnly(false);
|
|
|
|
ui->rating->setReadOnly(false);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->setReadOnly(false);
|
2013-05-20 00:38:20 +00:00
|
|
|
/* and fill them from the dive */
|
2013-05-06 17:16:16 +00:00
|
|
|
ui->rating->setCurrentStars(d->rating);
|
2013-05-08 19:08:00 +00:00
|
|
|
ui->maximumDepthText->setText(get_depth_string(d->maxdepth, TRUE));
|
|
|
|
ui->averageDepthText->setText(get_depth_string(d->meandepth, TRUE));
|
|
|
|
ui->otuText->setText(QString("%1").arg(d->otu));
|
|
|
|
ui->waterTemperatureText->setText(get_temperature_string(d->watertemp, TRUE));
|
|
|
|
ui->airTemperatureText->setText(get_temperature_string(d->airtemp, TRUE));
|
2013-05-07 03:36:37 +00:00
|
|
|
ui->gasUsedText->setText(get_volume_string(get_gas_used(d), TRUE));
|
2013-05-19 15:08:29 +00:00
|
|
|
ui->oxygenHeliumText->setText(get_gaslist(d));
|
|
|
|
ui->dateText->setText(get_dive_date_string(d->when));
|
|
|
|
ui->diveTimeText->setText(QString::number((int)((d->duration.seconds + 30) / 60)));
|
|
|
|
if (prevd)
|
|
|
|
ui->surfaceIntervalText->setText(get_time_string(d->when - (prevd->when + prevd->duration.seconds), 4));
|
2013-05-08 19:08:00 +00:00
|
|
|
if ((sacVal.mliter = d->sac) > 0)
|
2013-05-20 05:42:24 +00:00
|
|
|
ui->sacText->setText(get_volume_string(sacVal, TRUE).append(tr("/min")));
|
2013-05-08 19:08:00 +00:00
|
|
|
else
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->sacText->clear();
|
2013-05-08 19:08:00 +00:00
|
|
|
if (d->surface_pressure.mbar)
|
|
|
|
/* this is ALWAYS displayed in mbar */
|
|
|
|
ui->airPressureText->setText(QString("%1mbar").arg(d->surface_pressure.mbar));
|
|
|
|
else
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->airPressureText->clear();
|
2013-05-20 04:44:21 +00:00
|
|
|
ui->visibility->setCurrentStars(d->visibility);
|
2013-05-20 05:42:24 +00:00
|
|
|
ui->maximumDepthAllText->setText(get_depth_string(stats_selection.max_depth, TRUE));
|
|
|
|
ui->minimumDepthAllText->setText(get_depth_string(stats_selection.min_depth, TRUE));
|
|
|
|
ui->averageDepthAllText->setText(get_depth_string(stats_selection.avg_depth, TRUE));
|
|
|
|
ui->maximumSacAllText->setText(get_volume_string(stats_selection.max_sac, TRUE).append(tr("/min")));
|
|
|
|
ui->minimumSacAllText->setText(get_volume_string(stats_selection.min_sac, TRUE).append(tr("/min")));
|
|
|
|
ui->averageSacAllText->setText(get_volume_string(stats_selection.avg_sac, TRUE).append(tr("/min")));
|
|
|
|
ui->divesAllText->setText(QString::number(stats_selection.selection_size));
|
|
|
|
temp.mkelvin = stats_selection.max_temp;
|
|
|
|
ui->maximumTemperatureAllText->setText(get_temperature_string(temp, TRUE));
|
|
|
|
temp.mkelvin = stats_selection.min_temp;
|
|
|
|
ui->minimumTemperatureAllText->setText(get_temperature_string(temp, TRUE));
|
|
|
|
if (stats_selection.combined_temp && stats_selection.combined_count) {
|
|
|
|
const char *unit;
|
|
|
|
get_temp_units(0, &unit);
|
|
|
|
ui->averageTemperatureAllText->setText(QString("%1%2").arg(stats_selection.combined_temp / stats_selection.combined_count, 0, 'f', 1).arg(unit));
|
|
|
|
}
|
|
|
|
ui->totalTimeAllText->setText(get_time_string(stats_selection.total_time.seconds, 0));
|
|
|
|
int seconds = stats_selection.total_time.seconds;
|
|
|
|
if (stats_selection.selection_size)
|
|
|
|
seconds /= stats_selection.selection_size;
|
|
|
|
ui->averageTimeAllText->setText(get_time_string(seconds, 0));
|
|
|
|
ui->longestAllText->setText(get_time_string(stats_selection.longest_time.seconds, 0));
|
|
|
|
ui->shortestAllText->setText(get_time_string(stats_selection.shortest_time.seconds, 0));
|
2013-05-21 12:33:55 +00:00
|
|
|
cylindersModel->setDive(d);
|
2013-05-21 12:59:41 +00:00
|
|
|
weightModel->setDive(d);
|
2013-05-22 12:42:35 +00:00
|
|
|
addCylinder->setEnabled(true);
|
|
|
|
addWeight->setEnabled(true);
|
2013-05-08 19:08:00 +00:00
|
|
|
} else {
|
2013-05-20 00:38:20 +00:00
|
|
|
/* make the fields read-only */
|
|
|
|
ui->location->setReadOnly(true);
|
|
|
|
ui->divemaster->setReadOnly(true);
|
|
|
|
ui->buddy->setReadOnly(true);
|
|
|
|
ui->suit->setReadOnly(true);
|
|
|
|
ui->notes->setReadOnly(true);
|
|
|
|
ui->rating->setReadOnly(true);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->setReadOnly(true);
|
2013-05-20 00:38:20 +00:00
|
|
|
/* clear the fields */
|
2013-05-08 19:08:00 +00:00
|
|
|
ui->rating->setCurrentStars(0);
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->sacText->clear();
|
|
|
|
ui->otuText->clear();
|
|
|
|
ui->oxygenHeliumText->clear();
|
|
|
|
ui->dateText->clear();
|
|
|
|
ui->diveTimeText->clear();
|
|
|
|
ui->surfaceIntervalText->clear();
|
|
|
|
ui->maximumDepthText->clear();
|
|
|
|
ui->averageDepthText->clear();
|
2013-05-20 04:44:21 +00:00
|
|
|
ui->visibility->setCurrentStars(0);
|
2013-05-13 18:28:55 +00:00
|
|
|
ui->waterTemperatureText->clear();
|
|
|
|
ui->airTemperatureText->clear();
|
|
|
|
ui->gasUsedText->clear();
|
|
|
|
ui->airPressureText->clear();
|
2013-05-21 12:33:55 +00:00
|
|
|
cylindersModel->clear();
|
2013-05-21 12:59:41 +00:00
|
|
|
weightModel->clear();
|
2013-05-22 12:42:35 +00:00
|
|
|
addCylinder->setEnabled(false);
|
|
|
|
addWeight->setEnabled(false);
|
2013-05-08 19:08:00 +00:00
|
|
|
}
|
2013-05-10 22:56:05 +00:00
|
|
|
/* statisticsTab*/
|
2013-05-14 07:28:30 +00:00
|
|
|
/* we can access the stats_selection struct, but how do we ensure the relevant dives are selected
|
2013-05-10 22:56:05 +00:00
|
|
|
* if we don't use the gtk widget to drive this?
|
|
|
|
* Maybe call process_selected_dives? Or re-write to query our Qt list view.
|
|
|
|
*/
|
2013-05-13 18:28:17 +00:00
|
|
|
// qDebug("max temp %u",stats_selection.max_temp);
|
|
|
|
// qDebug("min temp %u",stats_selection.min_temp);
|
2013-05-06 16:23:14 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:40:26 +00:00
|
|
|
void MainTab::addCylinder_clicked()
|
2013-04-13 13:17:59 +00:00
|
|
|
{
|
2013-05-22 17:52:38 +00:00
|
|
|
cylindersModel->add();
|
2013-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_editCylinder_clicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_delCylinder_clicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-22 12:40:26 +00:00
|
|
|
void MainTab::addWeight_clicked()
|
2013-05-01 21:30:34 +00:00
|
|
|
{
|
2013-05-22 17:52:38 +00:00
|
|
|
weightModel->add();
|
2013-05-01 21:30:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_editWeight_clicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_delWeight_clicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
void MainTab::reload()
|
|
|
|
{
|
2013-04-07 22:20:43 +00:00
|
|
|
}
|
2013-05-18 23:42:59 +00:00
|
|
|
|
2013-05-19 19:56:27 +00:00
|
|
|
void MainTab::on_editAccept_clicked(bool edit)
|
2013-05-18 23:42:59 +00:00
|
|
|
{
|
|
|
|
ui->location->setReadOnly(!edit);
|
|
|
|
ui->divemaster->setReadOnly(!edit);
|
|
|
|
ui->buddy->setReadOnly(!edit);
|
|
|
|
ui->suit->setReadOnly(!edit);
|
|
|
|
ui->notes->setReadOnly(!edit);
|
|
|
|
ui->rating->setReadOnly(!edit);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->setReadOnly(!edit);
|
2013-05-18 23:42:59 +00:00
|
|
|
|
2013-05-19 03:09:36 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(!edit);
|
|
|
|
|
2013-05-19 16:00:57 +00:00
|
|
|
if (edit) {
|
2013-05-19 19:56:27 +00:00
|
|
|
ui->diveNotesMessage->setText(tr("This dive is being edited. click on finish / reset when ready."));
|
2013-05-18 23:42:59 +00:00
|
|
|
ui->diveNotesMessage->animatedShow();
|
|
|
|
notesBackup.buddy = ui->buddy->text();
|
|
|
|
notesBackup.suit = ui->suit->text();
|
|
|
|
notesBackup.notes = ui->notes->toPlainText();
|
|
|
|
notesBackup.divemaster = ui->divemaster->text();
|
|
|
|
notesBackup.location = ui->location->text();
|
|
|
|
notesBackup.rating = ui->rating->currentStars();
|
2013-05-20 13:25:16 +00:00
|
|
|
notesBackup.visibility = ui->visibility->currentStars();
|
2013-05-19 16:00:57 +00:00
|
|
|
} else {
|
2013-05-18 23:42:59 +00:00
|
|
|
ui->diveNotesMessage->animatedHide();
|
2013-05-19 19:56:27 +00:00
|
|
|
ui->editAccept->hide();
|
|
|
|
ui->editReset->hide();
|
2013-05-19 21:13:04 +00:00
|
|
|
/* now figure out if things have changed */
|
|
|
|
if (notesBackup.buddy != ui->buddy->text() ||
|
|
|
|
notesBackup.suit != ui->suit->text() ||
|
|
|
|
notesBackup.notes != ui->notes->toPlainText() ||
|
|
|
|
notesBackup.divemaster != ui->divemaster->text() ||
|
|
|
|
notesBackup.location != ui->location->text() ||
|
2013-05-20 13:25:16 +00:00
|
|
|
notesBackup.visibility != ui->visibility->currentStars() ||
|
2013-05-19 21:13:04 +00:00
|
|
|
notesBackup.rating != ui->rating->currentStars())
|
|
|
|
mark_divelist_changed(TRUE);
|
2013-05-19 14:45:01 +00:00
|
|
|
}
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-19 19:56:27 +00:00
|
|
|
void MainTab::on_editReset_clicked()
|
2013-05-18 23:42:59 +00:00
|
|
|
{
|
2013-05-19 19:56:27 +00:00
|
|
|
if (!ui->editAccept->isChecked())
|
2013-05-18 23:42:59 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
ui->buddy->setText(notesBackup.buddy);
|
|
|
|
ui->suit->setText(notesBackup.suit);
|
|
|
|
ui->notes->setText(notesBackup.notes);
|
|
|
|
ui->divemaster->setText(notesBackup.divemaster);
|
|
|
|
ui->location->setText(notesBackup.location);
|
|
|
|
ui->rating->setCurrentStars(notesBackup.rating);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->setCurrentStars(notesBackup.visibility);
|
2013-05-19 19:56:27 +00:00
|
|
|
ui->editAccept->setChecked(false);
|
2013-05-18 23:42:59 +00:00
|
|
|
ui->diveNotesMessage->animatedHide();
|
|
|
|
|
2013-05-19 03:09:36 +00:00
|
|
|
ui->location->setReadOnly(true);
|
|
|
|
ui->divemaster->setReadOnly(true);
|
|
|
|
ui->buddy->setReadOnly(true);
|
|
|
|
ui->suit->setReadOnly(true);
|
|
|
|
ui->notes->setReadOnly(true);
|
|
|
|
ui->rating->setReadOnly(true);
|
2013-05-20 13:25:16 +00:00
|
|
|
ui->visibility->setReadOnly(true);
|
2013-05-19 03:09:36 +00:00
|
|
|
mainWindow()->dive_list()->setEnabled(true);
|
2013-05-19 14:45:01 +00:00
|
|
|
|
2013-05-19 19:56:27 +00:00
|
|
|
ui->editAccept->hide();
|
|
|
|
ui->editReset->hide();
|
2013-05-18 23:42:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define EDIT_NOTES(what, text) \
|
|
|
|
QByteArray textByteArray = text.toLocal8Bit(); \
|
|
|
|
free(currentDive->what);\
|
|
|
|
currentDive->what = strdup(textByteArray.data());
|
|
|
|
|
|
|
|
void MainTab::on_buddy_textChanged(const QString& text)
|
|
|
|
{
|
|
|
|
if (!currentDive)
|
|
|
|
return;
|
|
|
|
EDIT_NOTES(buddy, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_divemaster_textChanged(const QString& text)
|
|
|
|
{
|
|
|
|
if (!currentDive)
|
|
|
|
return;
|
|
|
|
EDIT_NOTES(divemaster, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_location_textChanged(const QString& text)
|
|
|
|
{
|
|
|
|
if (!currentDive)
|
|
|
|
return;
|
|
|
|
EDIT_NOTES(location, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_suit_textChanged(const QString& text)
|
|
|
|
{
|
|
|
|
if (!currentDive)
|
|
|
|
return;
|
|
|
|
EDIT_NOTES(suit, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_notes_textChanged()
|
|
|
|
{
|
|
|
|
if (!currentDive)
|
|
|
|
return;
|
|
|
|
EDIT_NOTES(notes, ui->notes->toPlainText());
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef EDIT_NOTES
|
|
|
|
|
|
|
|
void MainTab::on_rating_valueChanged(int value)
|
|
|
|
{
|
|
|
|
if (!currentDive)
|
|
|
|
return;
|
|
|
|
currentDive->rating = value;
|
|
|
|
}
|
2013-05-20 13:25:16 +00:00
|
|
|
|
|
|
|
void MainTab::on_visibility_valueChanged(int value)
|
|
|
|
{
|
|
|
|
if (!currentDive)
|
|
|
|
return;
|
|
|
|
currentDive->visibility = value;
|
|
|
|
}
|