diff options
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/divelistview.cpp | 61 | ||||
-rw-r--r-- | qt-ui/divelistview.h | 5 | ||||
-rw-r--r-- | qt-ui/diveplanner.cpp | 30 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 9 | ||||
-rw-r--r-- | qt-ui/downloadfromdivecomputer.cpp | 4 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 2 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 129 | ||||
-rw-r--r-- | qt-ui/mainwindow.h | 4 |
8 files changed, 173 insertions, 71 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 92a10ca38..b2f33ffa1 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -47,8 +47,62 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec connect(showSearchBox, SIGNAL(triggered(bool)), this, SLOT(showSearchEdit())); connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString))); selectedTrips.clear(); + + setupUi(); } +DiveListView::~DiveListView() +{ + QSettings settings; + settings.beginGroup("ListWidget"); + for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++){ + if (isColumnHidden(i)) + continue; + settings.setValue(QString("colwidth%1").arg(i), columnWidth(i)); + } + settings.endGroup(); +} + +void DiveListView::setupUi(){ + QSettings settings; + static bool firstRun = true; + if(firstRun) + backupExpandedRows(); + settings.beginGroup("ListWidget"); + /* if no width are set, use the calculated width for each column; + * for that to work we need to temporarily expand all rows */ + expandAll(); + for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) { + if(isColumnHidden(i)) + continue; + QVariant width = settings.value(QString("colwidth%1").arg(i)); + if (width.isValid()) + setColumnWidth(i, width.toInt()); + else + setColumnWidth(i, 100); + } + settings.endGroup(); + if(firstRun) + restoreExpandedRows(); + else + collapseAll(); + firstRun = false; +} + +void DiveListView::backupExpandedRows(){ + expandedRows.clear(); + for(int i = 0; i < model()->rowCount(); i++){ + if(isExpanded( model()->index(i, 0) )){ + expandedRows.push_back(i); + } + } +} + +void DiveListView::restoreExpandedRows(){ + Q_FOREACH(const int &i, expandedRows){ + setExpanded( model()->index(i, 0), true ); + } +} void DiveListView::fixMessyQtModelBehaviour() { QAbstractItemModel *m = model(); @@ -132,9 +186,15 @@ void DiveListView::headerClicked(int i) sortByColumn(i, currentOrder); } else { // clear the model, repopulate with new indexes. + if(currentLayout == DiveTripModel::TREE){ + backupExpandedRows(); + } reload(newLayout, false); currentOrder = Qt::DescendingOrder; sortByColumn(i, currentOrder); + if (newLayout == DiveTripModel::TREE){ + restoreExpandedRows(); + } } // repopulate the selections. @@ -178,6 +238,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort) setCurrentIndex(firstDiveOrTrip); } } + setupUi(); } void DiveListView::reloadHeaderActions() diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h index 384ece9a3..f71013177 100644 --- a/qt-ui/divelistview.h +++ b/qt-ui/divelistview.h @@ -19,6 +19,7 @@ class DiveListView : public QTreeView Q_OBJECT public: DiveListView(QWidget *parent = 0); + ~DiveListView(); void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected); void currentChanged(const QModelIndex& current, const QModelIndex& previous); void reload(DiveTripModel::Layout layout, bool forceSort = true); @@ -48,12 +49,16 @@ signals: private: bool mouseClickSelection; + QList<int> expandedRows; int sortColumn; Qt::SortOrder currentOrder; DiveTripModel::Layout currentLayout; QLineEdit *searchBox; QModelIndex contextMenuIndex; void merge_trip(const QModelIndex &a, const int offset); + void setupUi(); + void backupExpandedRows(); + void restoreExpandedRows(); }; #endif // DIVELISTVIEW_H diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index 0701cb6d6..ec7a8a21f 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -559,7 +559,7 @@ void DivePlannerGraphics::mouseMoveEvent(QMouseEvent* event) horizontalLine->setPos(fromPercent(0, Qt::Horizontal), mappedPos.y()); depthString->setText(get_depth_string(depthLine->valueAt(mappedPos), true, false)); - depthString->setPos(fromPercent(5, Qt::Horizontal), mappedPos.y()); + depthString->setPos(fromPercent(1, Qt::Horizontal), mappedPos.y()); timeString->setText(QString::number(rint(timeLine->valueAt(mappedPos))) + "min"); timeString->setPos(mappedPos.x()+1, fromPercent(95, Qt::Vertical)); @@ -944,9 +944,9 @@ void DivePlannerWidget::lastStopChanged(bool checked) plannerModel->setLastStop6m(checked); } -void DivePlannerPointsModel::setPlanMode(bool isPlan) +void DivePlannerPointsModel::setPlanMode(Mode m) { - mode = isPlan ? PLAN : ADD; + mode = m; } bool DivePlannerPointsModel::isPlanner() @@ -1044,7 +1044,7 @@ int DivePlannerPointsModel::rowCount(const QModelIndex& parent) const return divepoints.count(); } -DivePlannerPointsModel::DivePlannerPointsModel(QObject* parent): QAbstractTableModel(parent) +DivePlannerPointsModel::DivePlannerPointsModel(QObject* parent): QAbstractTableModel(parent), mode(NOTHING) { } @@ -1186,13 +1186,24 @@ void DivePlannerPointsModel::cancelPlan() return; } } + clear(); + emit planCanceled(); + setPlanMode(NOTHING); +} +DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const +{ + return mode; +} + +void DivePlannerPointsModel::clear() +{ beginRemoveRows(QModelIndex(), 0, rowCount()-1); divepoints.clear(); endRemoveRows(); - emit planCanceled(); } + void DivePlannerPointsModel::createTemporaryPlan() { // This needs to be done in the following steps: @@ -1228,9 +1239,7 @@ void DivePlannerPointsModel::createTemporaryPlan() void DivePlannerPointsModel::undoEdition() { - beginRemoveRows(QModelIndex(), 0, rowCount()-1); - divepoints.clear(); - endRemoveRows(); + clear(); Q_FOREACH(const sample &s, backupSamples){ int o2, he; get_gas_from_events(¤t_dive->dc, s.time.seconds, &o2, &he); @@ -1270,8 +1279,7 @@ void DivePlannerPointsModel::createPlan() // 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(); + clear(); planCreated(); + setPlanMode(NOTHING); } diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 83bfadc32..9fc9cc641 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -21,6 +21,7 @@ class DivePlannerPointsModel : public QAbstractTableModel{ public: static DivePlannerPointsModel* instance(); enum Sections{REMOVE, DEPTH, DURATION, GAS, CCSETPOINT, COLUMNS}; + enum Mode { NOTHING, PLAN, ADD }; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; @@ -28,11 +29,11 @@ public: virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); virtual Qt::ItemFlags flags(const QModelIndex& index) const; void removeSelectedPoints(const QVector<int>& rows); - enum Modes { PLAN, ADD }; - void setPlanMode(bool); + void setPlanMode(Mode mode); bool isPlanner(); void createSimpleDive(); - + void clear(); + Mode currentMode() const; /** * @return the row number. */ @@ -63,7 +64,7 @@ signals: private: explicit DivePlannerPointsModel(QObject* parent = 0); struct diveplan diveplan; - Modes mode; + Mode mode; QVector<divedatapoint> divepoints; struct dive *tempDive; void deleteTemporaryPlan(struct divedatapoint *dp); diff --git a/qt-ui/downloadfromdivecomputer.cpp b/qt-ui/downloadfromdivecomputer.cpp index 72ba7933d..be9c8e337 100644 --- a/qt-ui/downloadfromdivecomputer.cpp +++ b/qt-ui/downloadfromdivecomputer.cpp @@ -106,6 +106,7 @@ void DownloadFromDCWidget::updateState(states state) && state == CANCELLING) { timer->stop(); reject(); + ui.ok->setText(tr("OK")); } // the cancelation process is finished @@ -122,6 +123,7 @@ void DownloadFromDCWidget::updateState(states state) timer->stop(); ui.progressBar->setValue(100); markChildrenAsEnabled(); + ui.ok->setText(tr("OK")); accept(); } @@ -139,7 +141,7 @@ void DownloadFromDCWidget::updateState(states state) markChildrenAsEnabled(); ui.progressBar->hide(); - ui.ok->setText(tr("retry")); + ui.ok->setText(tr("Retry")); } // properly updating the widget state diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 8230cf663..2708687da 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -497,6 +497,7 @@ void MainTab::acceptChanges() mainWindow()->showProfile(); mainWindow()->refreshDisplay(); mark_divelist_changed(TRUE); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); } editMode = NONE; @@ -609,6 +610,7 @@ void MainTab::rejectChanges() updateDiveInfo(selected_dive); mainWindow()->showProfile(); mainWindow()->refreshDisplay(); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING); } editMode = NONE; } diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 4489569fb..61fa76bfe 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -54,12 +54,14 @@ MainWindow::MainWindow() : helpView(0) connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(reloadHeaderActions())); connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ProfileWidget, SLOT(refresh())); ui.mainErrorMessage->hide(); - ui.ListWidget->reload(DiveTripModel::TREE); initialUiSetup(); readSettings(); + ui.ListWidget->reload(DiveTripModel::TREE); ui.ListWidget->reloadHeaderActions(); ui.ListWidget->setFocus(); ui.globe->reload(); + ui.ListWidget->expand(ui.ListWidget->model()->index(0,0)); + ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0,0), QAbstractItemView::PositionAtCenter); } // this gets called after we download dives from a divecomputer @@ -217,8 +219,13 @@ void MainWindow::enableDcShortcuts() void MainWindow::on_actionDivePlanner_triggered() { + if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){ + QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." ); + return; + } disableDcShortcuts(); - DivePlannerPointsModel::instance()->setPlanMode(true); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); + DivePlannerPointsModel::instance()->clear(); ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); ui.infoPane->setCurrentIndex(PLANNERWIDGET); } @@ -269,6 +276,11 @@ void MainWindow::on_actionEditDeviceNames_triggered() void MainWindow::on_actionAddDive_triggered() { + if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){ + QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." ); + return; + } + // clear the selection for (int i = 0; i < dive_table.nr; i++) { struct dive *d = get_dive(i); @@ -276,7 +288,8 @@ void MainWindow::on_actionAddDive_triggered() deselect_dive(i); } disableDcShortcuts(); - DivePlannerPointsModel::instance()->setPlanMode(false); + DivePlannerPointsModel::instance()->clear(); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); // 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 + gettimezoneoffset(); @@ -349,12 +362,14 @@ void MainWindow::on_infoProfileSplitter_splitterMoved(int pos, int idx) #define BEHAVIOR QList<int>() void MainWindow::on_actionViewList_triggered() { + beginChangeState(LIST_MAXIMIZED); ui.listGlobeSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); ui.mainSplitter->setSizes( BEHAVIOR << COLLAPSED << EXPANDED); } void MainWindow::on_actionViewProfile_triggered() { + beginChangeState(PROFILE_MAXIMIZED); ui.infoProfileSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); ui.mainSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); redrawProfile(); @@ -362,12 +377,14 @@ void MainWindow::on_actionViewProfile_triggered() void MainWindow::on_actionViewInfo_triggered() { + beginChangeState(INFO_MAXIMIZED); ui.infoProfileSplitter->setSizes(BEHAVIOR << EXPANDED << COLLAPSED); ui.mainSplitter->setSizes( BEHAVIOR << EXPANDED << COLLAPSED); } void MainWindow::on_actionViewGlobe_triggered() { + beginChangeState(GLOBE_MAXIMIZED); ui.mainSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); ui.listGlobeSplitter->setSizes(BEHAVIOR << COLLAPSED << EXPANDED); } @@ -375,17 +392,47 @@ void MainWindow::on_actionViewGlobe_triggered() void MainWindow::on_actionViewAll_triggered() { - // big number squash the info profile to it's minimum. - ui.infoProfileSplitter->setSizes(QList<int>() << 1 << 20000); + beginChangeState(VIEWALL); + QSettings settings; + settings.beginGroup("MainWindow"); + if (settings.value("mainSplitter").isValid()){ + ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); + ui.infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray()); + ui.listGlobeSplitter->restoreState(settings.value("listGlobeSplitter").toByteArray()); + } else { + QList<int> mainSizes; + mainSizes.append( qApp->desktop()->size().height() * 0.7 ); + mainSizes.append( qApp->desktop()->size().height() * 0.3 ); + ui.mainSplitter->setSizes( mainSizes ); - // big number squash the globe view. - ui.listGlobeSplitter->setSizes(QList<int>() << 2000 << 1 ); + QList<int> infoProfileSizes; + infoProfileSizes.append( qApp->desktop()->size().width() * 0.3 ); + infoProfileSizes.append( qApp->desktop()->size().width() * 0.7 ); + ui.infoProfileSplitter->setSizes(infoProfileSizes); - // half and half? - ui.mainSplitter->setSizes( QList<int>() << 1 << 1); + QList<int> listGlobeSizes; + listGlobeSizes.append( qApp->desktop()->size().width() * 0.7 ); + listGlobeSizes.append( qApp->desktop()->size().width() * 0.3 ); + ui.listGlobeSplitter->setSizes(listGlobeSizes); + } redrawProfile(); } +void MainWindow::beginChangeState(CurrentState s){ + if (state == VIEWALL){ + saveSplitterSizes(); + } + state = s; +} + +void MainWindow::saveSplitterSizes(){ + QSettings settings; + settings.beginGroup("MainWindow"); + settings.setValue("mainSplitter", ui.mainSplitter->saveState()); + settings.setValue("infoProfileSplitter", ui.infoProfileSplitter->saveState()); + settings.setValue("listGlobeSplitter", ui.listGlobeSplitter->saveState()); +} + void MainWindow::on_actionPreviousDC_triggered() { dc_number--; @@ -523,43 +570,14 @@ void MainWindow::initialUiSetup() QSize sz = settings.value("size", qApp->desktop()->size()).value<QSize>(); resize(sz); - if (settings.value("mainSplitter").isValid()){ - ui.mainSplitter->restoreState(settings.value("mainSplitter").toByteArray()); - ui.infoProfileSplitter->restoreState(settings.value("infoProfileSplitter").toByteArray()); - ui.listGlobeSplitter->restoreState(settings.value("listGlobeSplitter").toByteArray()); - } else { - QList<int> mainSizes; - mainSizes.append( qApp->desktop()->size().height() * 0.7 ); - mainSizes.append( qApp->desktop()->size().height() * 0.3 ); - ui.mainSplitter->setSizes( mainSizes ); - - QList<int> infoProfileSizes; - infoProfileSizes.append( qApp->desktop()->size().width() * 0.3 ); - infoProfileSizes.append( qApp->desktop()->size().width() * 0.7 ); - ui.infoProfileSplitter->setSizes(infoProfileSizes); - - QList<int> listGlobeSizes; - listGlobeSizes.append( qApp->desktop()->size().width() * 0.7 ); - listGlobeSizes.append( qApp->desktop()->size().width() * 0.3 ); - ui.listGlobeSplitter->setSizes(listGlobeSizes); - } - - settings.endGroup(); - - settings.beginGroup("ListWidget"); - /* if no width are set, use the calculated width for each column; - * for that to work we need to temporarily expand all rows */ - ui.ListWidget->expandAll(); - for (i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) { - QVariant width = settings.value(QString("colwidth%1").arg(i)); - if (width.isValid()) - ui.ListWidget->setColumnWidth(i, width.toInt()); - else - ui.ListWidget->resizeColumnToContents(i); + CurrentState state = (CurrentState) settings.value("lastState", 0).toInt(); + switch(state){ + case VIEWALL: on_actionViewAll_triggered(); break; + case GLOBE_MAXIMIZED : on_actionViewGlobe_triggered(); break; + case INFO_MAXIMIZED : on_actionViewInfo_triggered(); break; + case LIST_MAXIMIZED : on_actionViewList_triggered(); break; + case PROFILE_MAXIMIZED : on_actionViewProfile_triggered(); break; } - ui.ListWidget->collapseAll(); - ui.ListWidget->expand(ui.ListWidget->model()->index(0,0)); - ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0,0), QAbstractItemView::PositionAtCenter); settings.endGroup(); } @@ -625,17 +643,13 @@ void MainWindow::writeSettings() QSettings settings; settings.beginGroup("MainWindow"); + settings.setValue("lastState", (int) state); settings.setValue("size",size()); - settings.setValue("mainSplitter", ui.mainSplitter->saveState()); - settings.setValue("infoProfileSplitter", ui.infoProfileSplitter->saveState()); - settings.setValue("listGlobeSplitter", ui.listGlobeSplitter->saveState()); + if (state == VIEWALL){ + saveSplitterSizes(); + } settings.endGroup(); - settings.beginGroup("ListWidget"); - for (i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) - if (!ui.ListWidget->isColumnHidden(i)) - settings.setValue(QString("colwidth%1").arg(i), ui.ListWidget->columnWidth(i)); - settings.endGroup(); settings.beginGroup("Units"); SAVE_VALUE("length", units.length); SAVE_VALUE("pressure", units.pressure); @@ -822,12 +836,17 @@ void MainWindow::on_actionImportCSV_triggered() void MainWindow::editCurrentDive() { + if(DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING){ + QMessageBox::warning(this, tr("Warning"), "First finish the current edition before trying to do another." ); + return; + } + struct dive *d = current_dive; QString defaultDC(d->dc.model); - + DivePlannerPointsModel::instance()->clear(); if (defaultDC == "manually added dive"){ disableDcShortcuts(); - DivePlannerPointsModel::instance()->setPlanMode(false); + DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); ui.stackedWidget->setCurrentIndex(PLANNERPROFILE); // Planner. ui.infoPane->setCurrentIndex(MAINTAB); DivePlannerPointsModel::instance()->loadFromDive(d); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index e35230a3c..9a8deb1a0 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -36,6 +36,7 @@ public: enum {COLLAPSED, EXPANDED}; enum StackWidgetIndexes{ PROFILE, PLANNERPROFILE}; enum InfoWidgetIndexes{ MAINTAB, PLANNERWIDGET}; + enum CurrentState{ VIEWALL, GLOBE_MAXIMIZED, INFO_MAXIMIZED, PROFILE_MAXIMIZED, LIST_MAXIMIZED}; MainWindow(); ProfileGraphicsView *graphics(); @@ -116,12 +117,15 @@ private: QAction *actionNextDive; QAction *actionPreviousDive; QWebView *helpView; + CurrentState state; QString filter(); bool askSaveChanges(); void writeSettings(); void redrawProfile(); void file_save(); void file_save_as(); + void beginChangeState(CurrentState s); + void saveSplitterSizes(); }; MainWindow *mainWindow(); |