mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-19 14:25:27 +00:00
Merge branch 'editMode' of github.com:tcanabrava/subsurface
This commit is contained in:
commit
9e63539237
9 changed files with 82 additions and 34 deletions
|
@ -425,6 +425,22 @@ void DivePlannerPointsModel::createSimpleDive()
|
|||
plannerModel->addStop(M_OR_FT(5,15), 45 * 60, tr("Air"), 0);
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::loadFromDive(dive* d)
|
||||
{
|
||||
/* We need to make a copy, because
|
||||
* as soon as the model is modified, it will
|
||||
* remove all samples from the current dive.
|
||||
* */
|
||||
backupSamples.clear();
|
||||
for(int i = 1; i < d->dc.samples-1; i++){
|
||||
backupSamples.push_back( d->dc.sample[i]);
|
||||
}
|
||||
|
||||
Q_FOREACH(const sample &s, backupSamples){
|
||||
plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void DivePlannerGraphics::prepareSelectGas()
|
||||
{
|
||||
currentGasChoice = static_cast<Button*>(sender());
|
||||
|
@ -1181,6 +1197,16 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
|||
#endif
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::undoEdition()
|
||||
{
|
||||
beginRemoveRows(QModelIndex(), 0, rowCount()-1);
|
||||
divepoints.clear();
|
||||
endRemoveRows();
|
||||
Q_FOREACH(const sample &s, backupSamples){
|
||||
plannerModel->addStop(s.depth.mm, s.time.seconds, tr("Air"), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::deleteTemporaryPlan()
|
||||
{
|
||||
deleteTemporaryPlan(diveplan.dp);
|
||||
|
|
|
@ -54,7 +54,8 @@ public slots:
|
|||
void cancelPlan();
|
||||
void createTemporaryPlan();
|
||||
void deleteTemporaryPlan();
|
||||
|
||||
void loadFromDive(dive* d);
|
||||
void undoEdition();
|
||||
signals:
|
||||
void planCreated();
|
||||
void planCanceled();
|
||||
|
@ -66,6 +67,7 @@ private:
|
|||
QVector<divedatapoint> divepoints;
|
||||
struct dive *tempDive;
|
||||
void deleteTemporaryPlan(struct divedatapoint *dp);
|
||||
QVector<sample> backupSamples; // For editing added dives.
|
||||
};
|
||||
|
||||
class Button : public QObject, public QGraphicsRectItem {
|
||||
|
|
|
@ -113,7 +113,7 @@ void MainTab::addDiveStarted()
|
|||
editMode = ADD;
|
||||
}
|
||||
|
||||
void MainTab::enableEdition()
|
||||
void MainTab::enableEdition(EditMode newEditMode)
|
||||
{
|
||||
if (selected_dive < 0 || editMode != NONE)
|
||||
return;
|
||||
|
@ -170,7 +170,8 @@ void MainTab::enableEdition()
|
|||
notesBackup[mydive].weightsystem[i] = mydive->weightsystem[i];
|
||||
}
|
||||
}
|
||||
editMode = DIVE;
|
||||
|
||||
editMode = newEditMode != NONE ? newEditMode : DIVE;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -449,7 +450,7 @@ void MainTab::acceptChanges()
|
|||
}
|
||||
|
||||
}
|
||||
if (editMode == ADD) {
|
||||
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
||||
// clean up the dive data (get duration, depth information from samples)
|
||||
fixup_dive(current_dive);
|
||||
if (dive_table.nr == 1)
|
||||
|
@ -506,6 +507,9 @@ void MainTab::rejectChanges()
|
|||
delete_single_dive(selected_dive);
|
||||
DivePlannerPointsModel::instance()->cancelPlan();
|
||||
}
|
||||
else if (editMode == MANUALLY_ADDED_DIVE ){
|
||||
DivePlannerPointsModel::instance()->undoEdition();
|
||||
}
|
||||
struct dive *curr = current_dive;
|
||||
ui.notes->setText(notesBackup[curr].notes );
|
||||
ui.location->setText(notesBackup[curr].location);
|
||||
|
@ -563,7 +567,7 @@ void MainTab::rejectChanges()
|
|||
ui.equipmentButtonBox->hide();
|
||||
notesBackup.clear();
|
||||
resetPallete();
|
||||
if (editMode == ADD) {
|
||||
if (editMode == ADD || editMode == MANUALLY_ADDED_DIVE) {
|
||||
// more clean up
|
||||
updateDiveInfo(selected_dive);
|
||||
mainWindow()->showProfile();
|
||||
|
|
|
@ -46,6 +46,8 @@ class MainTab : public QTabWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum EditMode { NONE, DIVE, TRIP, ADD, MANUALLY_ADDED_DIVE };
|
||||
|
||||
MainTab(QWidget *parent);
|
||||
void clearStats();
|
||||
void clearInfo();
|
||||
|
@ -74,8 +76,10 @@ public slots:
|
|||
void editCylinderWidget(const QModelIndex& index);
|
||||
void editWeightWidget(const QModelIndex& index);
|
||||
void addDiveStarted();
|
||||
void enableEdition(EditMode newEditMode = NONE);
|
||||
|
||||
private:
|
||||
EditMode editMode;
|
||||
Ui::MainTab ui;
|
||||
WeightModel *weightModel;
|
||||
CylindersModel *cylindersModel;
|
||||
|
@ -88,9 +92,7 @@ private:
|
|||
* then applying the changes on the other dives.*/
|
||||
struct dive multiEditEquipmentPlaceholder;
|
||||
|
||||
enum { NONE, DIVE, TRIP, ADD } editMode;
|
||||
Completers completers;
|
||||
void enableEdition();
|
||||
void resetPallete();
|
||||
QString printGPSCoords(int lat, int lon);
|
||||
};
|
||||
|
|
|
@ -280,7 +280,8 @@ void MainWindow::on_actionAddDive_triggered()
|
|||
// now cheat - create one dive that we use to store the info tab data in
|
||||
struct dive *dive = alloc_dive();
|
||||
dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L;
|
||||
dive->dc.model = tr("manually added dive").toLocal8Bit().constData(); // do not use tr here since it expects a char*.
|
||||
const char* model = strdup(tr("manually added dive").toLocal8Bit().constData());
|
||||
dive->dc.model = model; // do not use tr here since it expects a char*.
|
||||
record_dive(dive);
|
||||
select_dive(get_divenr(dive));
|
||||
ui.InfoWidget->updateDiveInfo(selected_dive);
|
||||
|
@ -782,13 +783,7 @@ void MainWindow::importFiles(const QStringList fileNames)
|
|||
}
|
||||
}
|
||||
process_dives(TRUE, FALSE);
|
||||
|
||||
ui.InfoWidget->reload();
|
||||
ui.globe->reload();
|
||||
ui.ListWidget->reload(DiveTripModel::TREE);
|
||||
ui.ListWidget->setFocus();
|
||||
WSInfoModel *wsim = WSInfoModel::instance();
|
||||
wsim->updateInfo();
|
||||
refreshDisplay();
|
||||
}
|
||||
|
||||
void MainWindow::loadFiles(const QStringList fileNames)
|
||||
|
@ -813,25 +808,34 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
|||
|
||||
process_dives(FALSE, FALSE);
|
||||
|
||||
ui.InfoWidget->reload();
|
||||
ui.globe->reload();
|
||||
ui.ListWidget->reload(DiveTripModel::TREE);
|
||||
ui.ListWidget->setFocus();
|
||||
WSInfoModel *wsim = WSInfoModel::instance();
|
||||
wsim->updateInfo();
|
||||
refreshDisplay();
|
||||
ui.actionAutoGroup->setChecked(autogroup);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionImportCSV_triggered()
|
||||
{
|
||||
CSVImportDialog *csvImport = new(CSVImportDialog);
|
||||
CSVImportDialog *csvImport = new CSVImportDialog();
|
||||
csvImport->show();
|
||||
process_dives(TRUE, FALSE);
|
||||
|
||||
ui.InfoWidget->reload();
|
||||
ui.globe->reload();
|
||||
ui.ListWidget->reload(DiveTripModel::TREE);
|
||||
ui.ListWidget->setFocus();
|
||||
WSInfoModel *wsim = WSInfoModel::instance();
|
||||
wsim->updateInfo();
|
||||
refreshDisplay();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::editCurrentDive()
|
||||
{
|
||||
struct dive *d = current_dive;
|
||||
QString defaultDC(d->dc.model);
|
||||
|
||||
if (defaultDC == tr("manually added dive")){
|
||||
disableDcShortcuts();
|
||||
DivePlannerPointsModel::instance()->setPlanMode(false);
|
||||
ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner.
|
||||
ui.infoPane->setCurrentIndex(MAINTAB);
|
||||
DivePlannerPointsModel::instance()->loadFromDive(d);
|
||||
ui.InfoWidget->enableEdition(MainTab::MANUALLY_ADDED_DIVE);
|
||||
}
|
||||
else if (defaultDC == tr("Simulated Dive")){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -109,6 +109,7 @@ public slots:
|
|||
void readSettings();
|
||||
void refreshDisplay();
|
||||
void showProfile();
|
||||
void editCurrentDive();
|
||||
|
||||
private:
|
||||
Ui::MainWindow ui;
|
||||
|
|
|
@ -342,7 +342,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
|
|||
}
|
||||
|
||||
if (!printMode)
|
||||
addControlItems();
|
||||
addControlItems(d);
|
||||
|
||||
if (rulerEnabled && !printMode)
|
||||
add_ruler();
|
||||
|
@ -378,20 +378,28 @@ void ProfileGraphicsView::plot_depth_scale()
|
|||
depthMarkers->setPos(depthMarkers->pos().x() - 10, 0);
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::addControlItems()
|
||||
void ProfileGraphicsView::addControlItems(struct dive *d)
|
||||
{
|
||||
QAction *scaleAction = new QAction(QIcon(":scale"), tr("Scale"), this);
|
||||
QAction *rulerAction = new QAction(QIcon(":ruler"), tr("Ruler"), this);
|
||||
QToolBar *toolBar = new QToolBar("", 0);
|
||||
toolBar->addAction(rulerAction);
|
||||
toolBar->addAction(scaleAction);
|
||||
toolBar->setOrientation(Qt::Vertical);
|
||||
//make toolbar transparent
|
||||
toolBar->setStyleSheet(QString::fromUtf8 ("background-color: rgba(255,255,255,0);"));
|
||||
//toolBar->setStyleSheet(QString::fromUtf8 ("background-color: rgba(255,255,255,0);"));
|
||||
|
||||
connect(scaleAction, SIGNAL(triggered()), this, SLOT(on_scaleAction()));
|
||||
connect(rulerAction, SIGNAL(triggered()), this, SLOT(on_rulerAction()));
|
||||
toolBarProxy = scene()->addWidget(toolBar);
|
||||
//Put it into the lower right corner of the profile
|
||||
|
||||
QString defaultDC(d->dc.model);
|
||||
if (defaultDC == tr("manually added dive") || defaultDC == tr("Simulated Dive")) {
|
||||
QAction *editAction = new QAction(QIcon(":edit"), tr("Edit"), this);
|
||||
toolBar->addAction(editAction);
|
||||
connect(editAction, SIGNAL(triggered()), mainWindow(), SLOT(editCurrentDive()));
|
||||
}
|
||||
toolBarProxy = scene()->addWidget(toolBar);
|
||||
toolBarProxy->setPos(gc.maxx-toolBar->width(), gc.maxy-toolBar->height());
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ private:
|
|||
void plot_depth_scale();
|
||||
|
||||
|
||||
void addControlItems();
|
||||
void addControlItems(struct dive *d);
|
||||
|
||||
void create_ruler();
|
||||
void add_ruler();
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<file alias="trash">icons/trash.png</file>
|
||||
<file alias="units">icons/units.png</file>
|
||||
<file alias="advanced">icons/advanced.png</file>
|
||||
<file alias="edit">icons/advanced.png</file>
|
||||
<file alias="graph">icons/graph.png</file>
|
||||
<file alias="minimum">icons/minimum.svg</file>
|
||||
<file alias="maximum">icons/maximum.svg</file>
|
||||
|
|
Loading…
Add table
Reference in a new issue