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-04-13 13:17:59 +00:00
|
|
|
#include "addcylinderdialog.h"
|
2013-05-01 22:37:41 +00:00
|
|
|
#include "addweightsystemdialog.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-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-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-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-04-13 13:17:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-19 14:45:01 +00:00
|
|
|
bool MainTab::eventFilter(QObject* object, QEvent* event)
|
|
|
|
{
|
2013-05-19 16:00:57 +00:00
|
|
|
if (event->type() == QEvent::FocusIn) {
|
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->visibilityText->clear();
|
|
|
|
ui->waterTemperatureText->clear();
|
|
|
|
ui->airTemperatureText->clear();
|
|
|
|
ui->airPressureText->clear();
|
2013-05-20 00:38:20 +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-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-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
|
|
|
|
|
|
|
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);
|
|
|
|
/* 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)
|
|
|
|
ui->sacText->setText(get_volume_string(sacVal, TRUE).append("/min"));
|
|
|
|
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-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);
|
|
|
|
/* 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();
|
|
|
|
ui->visibilityText->clear();
|
|
|
|
ui->waterTemperatureText->clear();
|
|
|
|
ui->airTemperatureText->clear();
|
|
|
|
ui->gasUsedText->clear();
|
|
|
|
ui->airPressureText->clear();
|
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-04-13 13:17:59 +00:00
|
|
|
void MainTab::on_addCylinder_clicked()
|
|
|
|
{
|
2013-05-01 21:49:17 +00:00
|
|
|
if (cylindersModel->rowCount() >= MAX_CYLINDERS)
|
|
|
|
return;
|
|
|
|
|
2013-04-13 13:17:59 +00:00
|
|
|
AddCylinderDialog dialog(this);
|
|
|
|
cylinder_t *newCylinder = (cylinder_t*) malloc(sizeof(cylinder_t));
|
|
|
|
newCylinder->type.description = "";
|
|
|
|
|
|
|
|
dialog.setCylinder(newCylinder);
|
|
|
|
int result = dialog.exec();
|
2013-05-19 16:00:57 +00:00
|
|
|
if (result == QDialog::Rejected) {
|
2013-04-13 13:17:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.updateCylinder();
|
|
|
|
cylindersModel->add(newCylinder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_editCylinder_clicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainTab::on_delCylinder_clicked()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-01 21:30:34 +00:00
|
|
|
void MainTab::on_addWeight_clicked()
|
|
|
|
{
|
2013-05-01 21:49:17 +00:00
|
|
|
if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS)
|
|
|
|
return;
|
|
|
|
|
2013-05-01 22:37:41 +00:00
|
|
|
AddWeightsystemDialog dialog(this);
|
2013-05-01 23:23:20 +00:00
|
|
|
weightsystem_t newWeightsystem;
|
|
|
|
newWeightsystem.description = "";
|
|
|
|
newWeightsystem.weight.grams = 0;
|
2013-05-01 22:37:41 +00:00
|
|
|
|
2013-05-01 23:23:20 +00:00
|
|
|
dialog.setWeightsystem(&newWeightsystem);
|
2013-05-01 22:37:41 +00:00
|
|
|
int result = dialog.exec();
|
|
|
|
if (result == QDialog::Rejected)
|
|
|
|
return;
|
|
|
|
|
|
|
|
dialog.updateWeightsystem();
|
2013-05-01 23:23:20 +00:00
|
|
|
weightModel->add(&newWeightsystem);
|
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()
|
|
|
|
{
|
|
|
|
cylindersModel->update();
|
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-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-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() ||
|
|
|
|
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-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);
|
|
|
|
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;
|
|
|
|
}
|