aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/divelistview.cpp9
-rw-r--r--qt-ui/diveplanner.cpp229
-rw-r--r--qt-ui/diveplanner.h14
-rw-r--r--qt-ui/graphicsview-common.cpp5
-rw-r--r--qt-ui/graphicsview-common.h1
-rw-r--r--qt-ui/maintab.cpp188
-rw-r--r--qt-ui/maintab.h6
-rw-r--r--qt-ui/mainwindow.cpp2
8 files changed, 312 insertions, 142 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 4b856f601..2e40678ad 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -226,16 +226,7 @@ void DiveListView::currentChanged(const QModelIndex& current, const QModelIndex&
{
if (!current.isValid())
return;
- const QAbstractItemModel *model = current.model();
- int selectedDive = 0;
- struct dive *dive = (struct dive*) model->data(current, DiveTripModel::DIVE_ROLE).value<void*>();
- if (!dive) // it's a trip! select first child.
- dive = (struct dive*) model->data(current.child(0,0), DiveTripModel::DIVE_ROLE).value<void*>();
- selectedDive = get_divenr(dive);
scrollTo(current);
- if (selectedDive == selected_dive)
- return;
- Q_EMIT currentDiveChanged(selectedDive);
}
void DiveListView::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp
index ab7bda17d..ceb5ebdba 100644
--- a/qt-ui/diveplanner.cpp
+++ b/qt-ui/diveplanner.cpp
@@ -5,6 +5,7 @@
#include "ui_diveplanner.h"
#include "mainwindow.h"
#include "tableview.h"
+#include "graphicsview-common.h"
#include "../dive.h"
#include "../divelist.h"
@@ -19,6 +20,7 @@
#include <QModelIndex>
#include <QSettings>
#include <QTableView>
+#include <QColor>
#define TIME_INITIAL_MAX 30
@@ -40,6 +42,11 @@ QString strForAir(const divedatapoint& p){
: QObject::tr("Choose Gas");
}
+QColor getColor(const color_indice_t i)
+{
+ return profile_color[i].at(0);
+}
+
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0)
@@ -66,6 +73,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
fromPercent(100, Qt::Horizontal),
fromPercent(0, Qt::Vertical)
);
+
horizontalLine->setPen(QPen(Qt::DotLine));
scene()->addItem(horizontalLine);
@@ -73,6 +81,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
timeLine->setMinimum(0);
timeLine->setMaximum(TIME_INITIAL_MAX);
timeLine->setTickInterval(10);
+ timeLine->setColor(getColor(TIME_GRID));
timeLine->setLine(
fromPercent(10, Qt::Horizontal),
fromPercent(90, Qt::Vertical),
@@ -81,7 +90,7 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
);
timeLine->setOrientation(Qt::Horizontal);
timeLine->setTickSize(fromPercent(1, Qt::Vertical));
- timeLine->setColor(profile_color[TIME_GRID].at(0));
+ timeLine->setTextColor(getColor(TIME_TEXT));
timeLine->updateTicks();
scene()->addItem(timeLine);
@@ -97,7 +106,8 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
);
depthLine->setOrientation(Qt::Vertical);
depthLine->setTickSize(fromPercent(1, Qt::Horizontal));
- depthLine->setColor(profile_color[DEPTH_GRID].at(0));
+ depthLine->setColor(getColor(DEPTH_GRID));
+ depthLine->setTextColor(getColor(SAMPLE_DEEP));
depthLine->updateTicks();
scene()->addItem(depthLine);
@@ -317,7 +327,7 @@ void DivePlannerGraphics::keyEscAction()
scene()->clearSelection();
return;
}
- cancelPlan();
+ plannerModel->cancelPlan();
}
qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientation)
@@ -327,18 +337,6 @@ qreal DivePlannerGraphics::fromPercent(qreal percent, Qt::Orientation orientatio
return result;
}
-void DivePlannerGraphics::cancelPlan()
-{
- if (handles.size()){
- if (QMessageBox::warning(mainWindow(), tr("Save the Plan?"),
- tr("You have a working plan, \n are you sure that you wanna cancel it?"),
- QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok){
- return;
- }
- }
- mainWindow()->showProfile();
-}
-
void DivePlannerGraphics::increaseDepth()
{
if (depthLine->maximum() + 10 > MAX_DEEPNESS)
@@ -422,42 +420,14 @@ void DivePlannerGraphics::createDecoStops()
qDeleteAll(lines);
lines.clear();
- // This needs to be done in the following steps:
- // Get the user-input and calculate the dive info
- // Not sure if this is the place to create the diveplan...
- // We just start with a surface node at time = 0
+ plannerModel->createTemporaryPlan();
struct diveplan diveplan = plannerModel->getDiveplan();
- struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0);
- dp->entered = TRUE;
- diveplan.dp = dp;
-
- int rowCount = plannerModel->rowCount();
- int lastIndex = -1;
- for(int i = 0; i < rowCount; i++){
- divedatapoint p = plannerModel->at(i);
- int deltaT = lastIndex != -1 ? p.time - plannerModel->at(lastIndex).time : p.time;
- lastIndex = i;
- dp = plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2);
- }
-
-#if DEBUG_PLAN
- dump_plan(&diveplan);
-#endif
- char *cache = NULL;
- struct dive *dive = NULL;
- char *errorString = NULL;
- plan(&diveplan, &cache, &dive, &errorString);
-#if DEBUG_PLAN
- dump_plan(&diveplan);
-#endif
-
- while(dp->next)
+ struct divedatapoint *dp = diveplan.dp;
+ while(dp->next){
dp = dp->next;
+ }
- dpMaxTime = dp->time / 60.0 + 5;
-
- if (timeLine->maximum() < dp->time / 60.0 + 5 ||
- dp->time / 60.0 + 15 < timeLine->maximum()) {
+ if (timeLine->maximum() < dp->time / 60.0 + 5 || dp->time / 60.0 + 15 < timeLine->maximum()) {
double newMax = fmax(dp->time / 60.0 + 5, minMinutes);
timeLine->setMaximum(newMax);
timeLine->updateTicks();
@@ -483,6 +453,7 @@ void DivePlannerGraphics::createDecoStops()
QPolygonF poly;
poly.append(QPointF(lastx, lasty));
+
for (dp = diveplan.dp; dp != NULL; dp = dp->next) {
double xpos = timeLine->posAtValue(dp->time / 60.0);
double ypos = depthLine->posAtValue(dp->depth / 1000.0);
@@ -510,16 +481,7 @@ void DivePlannerGraphics::createDecoStops()
pat.setColorAt(0, profile_color[DEPTH_TOP].first());
diveBg->setBrush(pat);
- deleteTemporaryDivePlan(diveplan.dp);
- delete_single_dive(get_divenr(dive));
-}
-
-void DivePlannerGraphics::deleteTemporaryDivePlan(divedatapoint* dp)
-{
- if (!dp)
- return;
- deleteTemporaryDivePlan(dp->next);
- free(dp);
+ plannerModel->deleteTemporaryPlan();
}
void DivePlannerGraphics::resizeEvent(QResizeEvent* event)
@@ -681,6 +643,11 @@ void Ruler::setMinimum(double minimum)
min = minimum;
}
+void Ruler::setTextColor(const QColor& color)
+{
+ textColor = color;
+}
+
Ruler::Ruler() : orientation(Qt::Horizontal)
{
}
@@ -688,39 +655,70 @@ Ruler::Ruler() : orientation(Qt::Horizontal)
void Ruler::setOrientation(Qt::Orientation o)
{
orientation = o;
+ // position the elements on the screen.
+ setMinimum(minimum());
+ setMaximum(maximum());
}
void Ruler::updateTicks()
{
qDeleteAll(ticks);
ticks.clear();
+ qDeleteAll(labels);
+ labels.clear();
+
QLineF m = line();
QGraphicsLineItem *item = NULL;
+ QGraphicsSimpleTextItem *label = NULL;
+
+ double steps = (max - min) / interval;
+ qreal pos;
+ double currValue = min;
if (orientation == Qt::Horizontal) {
- double steps = (max - min) / interval;
double stepSize = (m.x2() - m.x1()) / steps;
- qreal pos;
- for (pos = m.x1(); pos < m.x2(); pos += stepSize) {
+ for (pos = m.x1(); pos < m.x2(); pos += stepSize, currValue += interval) {
item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
item->setPen(pen());
ticks.push_back(item);
+
+ label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
+ label->setBrush(QBrush(textColor));
+ label->setFlag(ItemIgnoresTransformations);
+ label->setPos(pos - label->boundingRect().width()/2, m.y1() + tickSize + 5);
+ labels.push_back(label);
}
item = new QGraphicsLineItem(pos, m.y1(), pos, m.y1() + tickSize, this);
item->setPen(pen());
ticks.push_back(item);
+
+ label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
+ label->setBrush(QBrush(textColor));
+ label->setFlag(ItemIgnoresTransformations);
+ label->setPos(pos - label->boundingRect().width()/2, m.y1() + tickSize + 5);
+ labels.push_back(label);
} else {
- double steps = (max - min) / interval;
double stepSize = (m.y2() - m.y1()) / steps;
- qreal pos;
- for (pos = m.y1(); pos < m.y2(); pos += stepSize) {
+ for (pos = m.y1(); pos < m.y2(); pos += stepSize, currValue += interval) {
item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
item->setPen(pen());
ticks.push_back(item);
+
+ label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
+ label->setBrush(QBrush(textColor));
+ label->setFlag(ItemIgnoresTransformations);
+ label->setPos(m.x2() - 80, pos);
+ labels.push_back(label);
}
item = new QGraphicsLineItem(m.x1(), pos, m.x1() - tickSize, pos, this);
item->setPen(pen());
ticks.push_back(item);
+
+ label = new QGraphicsSimpleTextItem(QString::number(currValue), this);
+ label->setBrush(QBrush(textColor));
+ label->setFlag(ItemIgnoresTransformations);
+ label->setPos(m.x2() - 80, pos);
+ labels.push_back(label);
}
}
@@ -780,7 +778,12 @@ double Ruler::minimum() const
void Ruler::setColor(const QColor& color)
{
- setPen(QPen(color));
+ QPen defaultPen(color);
+ defaultPen.setJoinStyle(Qt::RoundJoin);
+ defaultPen.setCapStyle(Qt::RoundCap);
+ defaultPen.setWidth(2);
+ defaultPen.setCosmetic(true);
+ setPen(defaultPen);
}
Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem()
@@ -840,6 +843,13 @@ DivePlannerWidget::DivePlannerWidget(QWidget* parent, Qt::WindowFlags f): QWidge
connect(ui->highGF, SIGNAL(textChanged(QString)), this, SLOT(gfhighChanged(QString)));
connect(ui->lastStop, SIGNAL(toggled(bool)), this, SLOT(lastStopChanged(bool)));
+ // Creating the plan
+ connect(ui->buttonBox, SIGNAL(accepted()), plannerModel, SLOT(createPlan()));
+ connect(ui->buttonBox, SIGNAL(rejected()), plannerModel, SLOT(cancelPlan()));
+ connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(showProfile()));
+ connect(plannerModel, SIGNAL(planCreated()), mainWindow(), SLOT(refreshDisplay()));
+ connect(plannerModel, SIGNAL(planCanceled()), mainWindow(), SLOT(showProfile()));
+
/* set defaults. */
ui->startTime->setTime( QTime(1, 0) );
ui->ATMPressure->setText( "1013" );
@@ -975,11 +985,6 @@ DivePlannerPointsModel* DivePlannerPointsModel::instance()
return self;
}
-void DivePlannerPointsModel::createPlan()
-{
-
-}
-
void DivePlannerPointsModel::setBottomSac(int sac)
{
diveplan.bottomsac = sac;
@@ -1094,3 +1099,87 @@ struct diveplan DivePlannerPointsModel::getDiveplan()
{
return diveplan;
}
+
+void DivePlannerPointsModel::cancelPlan()
+{
+ if(rowCount()){
+ if (QMessageBox::warning(mainWindow(), tr("Save the Plan?"),
+ tr("You have a working plan, \n are you sure that you wanna cancel it?"),
+ QMessageBox::Ok | QMessageBox::Cancel) != QMessageBox::Ok){
+ return;
+ }
+ }
+
+ beginRemoveRows(QModelIndex(), 0, rowCount()-1);
+ divepoints.clear();
+ endRemoveRows();
+ emit planCanceled();
+}
+
+void DivePlannerPointsModel::createTemporaryPlan()
+{
+ // This needs to be done in the following steps:
+ // Get the user-input and calculate the dive info
+ // Not sure if this is the place to create the diveplan...
+ // We just start with a surface node at time = 0
+ struct divedatapoint *dp = create_dp(0, 0, 209, 0, 0);
+ dp->entered = TRUE;
+ diveplan.dp = dp;
+ int lastIndex = -1;
+ for(int i = 0; i < rowCount(); i++){
+ divedatapoint p = at(i);
+ int deltaT = lastIndex != -1 ? p.time - at(lastIndex).time : p.time;
+ lastIndex = i;
+ dp = plan_add_segment(&diveplan, deltaT, p.depth, p.o2, p.he, p.po2);
+ }
+#if DEBUG_PLAN
+ dump_plan(&diveplan);
+#endif
+ char *cache = NULL;
+ tempDive = NULL;
+ char *errorString = NULL;
+ plan(&diveplan, &cache, &tempDive, &errorString);
+#if DEBUG_PLAN
+ dump_plan(&diveplan);
+#endif
+}
+
+void DivePlannerPointsModel::deleteTemporaryPlan()
+{
+ deleteTemporaryPlan(diveplan.dp);
+ delete_single_dive(get_divenr(tempDive));
+ tempDive = NULL;
+}
+
+void DivePlannerPointsModel::deleteTemporaryPlan(struct divedatapoint *dp)
+{
+ if (!dp){
+ return;
+ }
+
+ deleteTemporaryPlan(dp->next);
+ free(dp);
+}
+
+void DivePlannerPointsModel::createPlan()
+{
+ // Ok, so, here the diveplan creates a dive,
+ // puts it on the dive list, and we need to remember
+ // to not delete it later. mumble. ;p
+ char *cache = NULL;
+ tempDive = NULL;
+ char *errorString = NULL;
+
+ createTemporaryPlan();
+ plan(&diveplan, &cache, &tempDive, &errorString);
+ mark_divelist_changed(TRUE);
+
+ // Remove and clean the diveplan, so we don't delete
+ // the dive by mistake.
+ diveplan.dp = NULL;
+ beginRemoveRows(QModelIndex(), 0, rowCount() -1 );
+ divepoints.clear();
+ endRemoveRows();
+
+ planCreated();
+}
diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h
index 091b9f80c..8dd8db3e3 100644
--- a/qt-ui/diveplanner.h
+++ b/qt-ui/diveplanner.h
@@ -50,11 +50,20 @@ public slots:
void setLastStop6m(bool value);
void createPlan();
void remove(const QModelIndex& index);
+ void cancelPlan();
+ void createTemporaryPlan();
+ void deleteTemporaryPlan();
+
+signals:
+ void planCreated();
+ void planCanceled();
private:
explicit DivePlannerPointsModel(QObject* parent = 0);
struct diveplan diveplan;
QVector<divedatapoint> divepoints;
+ struct dive *tempDive;
+ void deleteTemporaryPlan(struct divedatapoint *dp);
};
class Button : public QObject, public QGraphicsRectItem {
@@ -95,16 +104,19 @@ public:
qreal percentAt(const QPointF& p);
qreal posAtValue(qreal value);
void setColor(const QColor& color);
+ void setTextColor(const QColor& color);
private:
Qt::Orientation orientation;
QList<QGraphicsLineItem*> ticks;
+ QList<QGraphicsSimpleTextItem*> labels;
double min;
double max;
double interval;
double posBegin;
double posEnd;
double tickSize;
+ QColor textColor;
};
class DivePlannerGraphics : public QGraphicsView {
@@ -119,7 +131,6 @@ protected:
virtual void mousePressEvent(QMouseEvent* event);
virtual void mouseReleaseEvent(QMouseEvent* event);
bool isPointOutOfBoundaries(const QPointF& point);
- void deleteTemporaryDivePlan(struct divedatapoint* dp);
qreal fromPercent(qreal percent, Qt::Orientation orientation);
private slots:
void keyEscAction();
@@ -133,7 +144,6 @@ private slots:
void decreaseTime();
void decreaseDepth();;
void createDecoStops();
- void cancelPlan();
void prepareSelectGas();
void selectGas(const QModelIndex& index);
void pointInserted(const QModelIndex&, int start, int end);
diff --git a/qt-ui/graphicsview-common.cpp b/qt-ui/graphicsview-common.cpp
index fbe196e98..30b9ccb08 100644
--- a/qt-ui/graphicsview-common.cpp
+++ b/qt-ui/graphicsview-common.cpp
@@ -55,3 +55,8 @@ void fill_profile_color()
profile_color[CALC_CEILING_DEEP] = COLOR(APPLE1_HIGH_TRANS, BLACK1_HIGH_TRANS, APPLE1_HIGH_TRANS);
#undef COLOR
}
+
+QColor getColor(const color_indice_t i, bool isGrayscale = false)
+{
+ return profile_color[i].at((isGrayscale) ? 1 : 0);
+}
diff --git a/qt-ui/graphicsview-common.h b/qt-ui/graphicsview-common.h
index 96cecc8e6..d2499c823 100644
--- a/qt-ui/graphicsview-common.h
+++ b/qt-ui/graphicsview-common.h
@@ -33,7 +33,6 @@ typedef enum {
/* profile_color[color indice] = COLOR(screen color, b/w printer color, color printer}} printer & screen colours could be different */
extern QMap<color_indice_t, QVector<QColor> > profile_color;
-
void fill_profile_color();
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 30c071d55..42250b42c 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -20,12 +20,12 @@
#include <QSet>
#include <QTableView>
#include <QSettings>
+#include <QPalette>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui(new Ui::MainTab()),
weightModel(new WeightModel()),
cylindersModel(new CylindersModel()),
- currentDive(0),
editMode(NONE)
{
ui->setupUi(this);
@@ -91,7 +91,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
void MainTab::enableEdition()
{
- if (ui->editAccept->isVisible() || !currentDive)
+ if (ui->editAccept->isVisible() || !selected_dive)
return;
ui->editAccept->setChecked(true);
@@ -150,6 +150,7 @@ void MainTab::clearStats()
void MainTab::updateDiveInfo(int dive)
{
+ editMode = NONE;
// This method updates ALL tabs whenever a new dive or trip is
// selected.
// If exactly one trip has been selected, we show the location / notes
@@ -162,7 +163,7 @@ void MainTab::updateDiveInfo(int dive)
process_selected_dives();
process_all_dives(d, &prevd);
- currentDive = d;
+
UPDATE_TEXT(d, notes);
UPDATE_TEXT(d, location);
UPDATE_TEXT(d, suit);
@@ -325,24 +326,39 @@ void MainTab::on_editAccept_clicked(bool edit)
mainWindow()->dive_list()->setEnabled(!edit);
if (edit) {
+
+ // We may be editing one or more dives here. backup everything.
+ notesBackup.clear();
+
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
// we are editing trip location and notes
ui->diveNotesMessage->setText(tr("This trip is being edited. Select Save or Undo when ready."));
ui->diveNotesMessage->animatedShow();
- notesBackup.notes = ui->notes->toPlainText();
- notesBackup.location = ui->location->text();
+ notesBackup[NULL].notes = ui->notes->toPlainText();
+ notesBackup[NULL].location = ui->location->text();
editMode = TRIP;
} else {
ui->diveNotesMessage->setText(tr("This dive is being edited. Select Save or Undo when ready."));
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();
- notesBackup.visibility = ui->visibility->currentStars();
- editMode = DIVE;
+
+ // We may be editing one or more dives here. backup everything.
+ struct dive *mydive;
+ for (int i = 0; i < dive_table.nr; i++) {
+ mydive = get_dive(i);
+ if (!mydive)
+ continue;
+ if (!mydive->selected)
+ continue;
+
+ notesBackup[mydive].buddy = QString(mydive->buddy);
+ notesBackup[mydive].suit = QString(mydive->suit);
+ notesBackup[mydive].notes = QString(mydive->notes);
+ notesBackup[mydive].divemaster = QString(mydive->divemaster);
+ notesBackup[mydive].location = QString(mydive->location);
+ notesBackup[mydive].rating = mydive->rating;
+ notesBackup[mydive].visibility = mydive->visibility;
+ }
+ editMode = DIVE;
}
} else {
ui->diveNotesMessage->animatedHide();
@@ -350,38 +366,78 @@ void MainTab::on_editAccept_clicked(bool edit)
ui->editReset->hide();
/* now figure out if things have changed */
if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
- if (notesBackup.notes != ui->notes->toPlainText() ||
- notesBackup.location != ui->location->text())
+ if (notesBackup[NULL].notes != ui->notes->toPlainText() ||
+ notesBackup[NULL].location != ui->location->text())
mark_divelist_changed(TRUE);
} else {
- 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.visibility != ui->visibility->currentStars() ||
- notesBackup.rating != ui->rating->currentStars())
+ struct dive *curr = current_dive;
+ if (notesBackup[curr].buddy != ui->buddy->text() ||
+ notesBackup[curr].suit != ui->suit->text() ||
+ notesBackup[curr].notes != ui->notes->toPlainText() ||
+ notesBackup[curr].divemaster != ui->divemaster->text() ||
+ notesBackup[curr].location != ui->location->text() ||
+ notesBackup[curr].rating != ui->visibility->currentStars() ||
+ notesBackup[curr].visibility != ui->rating->currentStars())
+
mark_divelist_changed(TRUE);
- if (notesBackup.location != ui->location->text())
+ if (notesBackup[curr].location != ui->location->text())
mainWindow()->globe()->reload();
}
editMode = NONE;
}
+ QPalette p;
+ ui->buddy->setPalette(p);
+ ui->notes->setPalette(p);
+ ui->location->setPalette(p);
+ ui->divemaster->setPalette(p);
+ ui->suit->setPalette(p);
}
+#define EDIT_TEXT2(what, text) \
+ textByteArray = text.toLocal8Bit(); \
+ free(what);\
+ what = strdup(textByteArray.data());
+
+#define EDIT_TEXT(what, text) \
+ QByteArray textByteArray = text.toLocal8Bit(); \
+ free(what);\
+ what = strdup(textByteArray.data());
+
void MainTab::on_editReset_clicked()
{
if (!ui->editAccept->isChecked())
return;
- ui->notes->setText(notesBackup.notes);
- ui->location->setText(notesBackup.location);
- if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() != 1) {
- ui->buddy->setText(notesBackup.buddy);
- ui->suit->setText(notesBackup.suit);
- ui->divemaster->setText(notesBackup.divemaster);
- ui->rating->setCurrentStars(notesBackup.rating);
- ui->visibility->setCurrentStars(notesBackup.visibility);
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1){
+ ui->notes->setText(notesBackup[NULL].notes );
+ ui->location->setText(notesBackup[NULL].location);
+ }else{
+ struct dive *curr = current_dive;
+ ui->notes->setText(notesBackup[curr].notes );
+ ui->location->setText(notesBackup[curr].location);
+ ui->buddy->setText(notesBackup[curr].buddy);
+ ui->suit->setText(notesBackup[curr].suit);
+ ui->divemaster->setText(notesBackup[curr].divemaster);
+ ui->rating->setCurrentStars(notesBackup[curr].rating);
+ ui->visibility->setCurrentStars(notesBackup[curr].visibility);
+
+ struct dive *mydive;
+ for (int i = 0; i < dive_table.nr; i++) {
+ mydive = get_dive(i);
+ if (!mydive)
+ continue;
+ if (!mydive->selected)
+ continue;
+
+ QByteArray textByteArray;
+ EDIT_TEXT2(mydive->buddy, notesBackup[mydive].buddy);
+ EDIT_TEXT2(mydive->suit, notesBackup[mydive].suit);
+ EDIT_TEXT2(mydive->notes, notesBackup[mydive].notes);
+ EDIT_TEXT2(mydive->divemaster, notesBackup[mydive].divemaster);
+ EDIT_TEXT2(mydive->location, notesBackup[mydive].location);
+ mydive->rating = notesBackup[mydive].rating;
+ mydive->visibility = notesBackup[mydive].visibility;
+ }
}
ui->editAccept->setChecked(false);
ui->diveNotesMessage->animatedHide();
@@ -397,75 +453,95 @@ void MainTab::on_editReset_clicked()
ui->editAccept->hide();
ui->editReset->hide();
+ notesBackup.clear();
+ QPalette p;
+ ui->buddy->setPalette(p);
+ ui->notes->setPalette(p);
+ ui->location->setPalette(p);
+ ui->divemaster->setPalette(p);
+ ui->suit->setPalette(p);
editMode = NONE;
}
+#undef EDIT_TEXT2
+
+#define EDIT_SELECTED_DIVES( WHAT ) \
+ if (editMode == NONE) \
+ return; \
+ struct dive *mydive; \
+\
+ for (int i = 0; i < dive_table.nr; i++) { \
+ mydive = get_dive(i); \
+ if (!mydive) \
+ continue; \
+ if (!mydive->selected) \
+ continue; \
+\
+ WHAT; \
+ }
-#define EDIT_TEXT(what, text) \
- QByteArray textByteArray = text.toLocal8Bit(); \
- free(what);\
- what = strdup(textByteArray.data());
+void markChangedWidget(QWidget *w){
+ QPalette p;
+ p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter());
+ w->setPalette(p);
+}
void MainTab::on_buddy_textChanged(const QString& text)
{
- if (!currentDive)
- return;
- EDIT_TEXT(currentDive->buddy, text);
+ EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->buddy, text) );
+ markChangedWidget(ui->buddy);
}
void MainTab::on_divemaster_textChanged(const QString& text)
{
- if (!currentDive)
- return;
- EDIT_TEXT(currentDive->divemaster, text);
+ EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->divemaster, text) );
+ markChangedWidget(ui->divemaster);
}
void MainTab::on_location_textChanged(const QString& text)
{
+ if (editMode == NONE)
+ return;
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
// we are editing a trip
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE){
- if (!currentDive)
- return;
- EDIT_TEXT(currentDive->location, text);
+ EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) )
}
+
+ markChangedWidget(ui->location);
}
void MainTab::on_suit_textChanged(const QString& text)
{
- if (!currentDive)
- return;
- EDIT_TEXT(currentDive->suit, text);
+ EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->suit, text) );
+ markChangedWidget(ui->suit);
}
void MainTab::on_notes_textChanged()
{
+ if (editMode == NONE)
+ return;
if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
// we are editing a trip
dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText());
} else if (editMode == DIVE) {
- if (!currentDive)
- return;
- EDIT_TEXT(currentDive->notes, ui->notes->toPlainText());
+ EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui->notes->toPlainText()) );
}
+ markChangedWidget(ui->notes);
}
#undef EDIT_TEXT
void MainTab::on_rating_valueChanged(int value)
{
- if (!currentDive)
- return;
- currentDive->rating = value;
+ EDIT_SELECTED_DIVES(mydive->rating = value );
}
void MainTab::on_visibility_valueChanged(int value)
{
- if (!currentDive)
- return;
- currentDive->visibility = value;
+ EDIT_SELECTED_DIVES( mydive->visibility = value );
}
void MainTab::editCylinderWidget(const QModelIndex& index)
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index c423bc619..f9f65a3ff 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -9,11 +9,12 @@
#include <QTabWidget>
#include <QDialog>
+#include <QMap>
#include "models.h"
class QCompleter;
-
+struct dive;
namespace Ui
{
class MainTab;
@@ -68,8 +69,7 @@ private:
Ui::MainTab *ui;
WeightModel *weightModel;
CylindersModel *cylindersModel;
- NotesBackup notesBackup;
- struct dive* currentDive;
+ QMap<dive*, NotesBackup> notesBackup;
enum { NONE, DIVE, TRIP } editMode;
Completers completers;
void enableEdition();
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index f2f95897a..740849033 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -45,6 +45,7 @@ MainWindow* mainWindow()
MainWindow::MainWindow() : ui(new Ui::MainWindow()), helpView(0)
{
+ instance = this;
ui->setupUi(this);
setWindowIcon(QIcon(":subsurface-icon"));
connect(ui->ListWidget, SIGNAL(currentDiveChanged(int)), this, SLOT(current_dive_changed(int)));
@@ -59,7 +60,6 @@ MainWindow::MainWindow() : ui(new Ui::MainWindow()), helpView(0)
ui->ListWidget->reloadHeaderActions();
ui->ListWidget->setFocus();
ui->globe->reload();
- instance = this;
}
// this gets called after we download dives from a divecomputer