aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/divelistview.cpp56
-rw-r--r--qt-ui/divelistview.h8
-rw-r--r--qt-ui/maintab.cpp18
-rw-r--r--qt-ui/mainwindow.cpp2
-rw-r--r--qthelper.cpp12
-rw-r--r--qthelper.h2
6 files changed, 75 insertions, 23 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index e646bab04..d8538a5fd 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -47,8 +47,6 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
searchBox->hide();
connect(showSearchBox, SIGNAL(triggered(bool)), this, SLOT(showSearchEdit()));
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
- selectedTrips.clear();
-
setupUi();
}
@@ -133,24 +131,66 @@ void DiveListView::rememberSelection()
continue;
struct dive *d = (struct dive *) index.data(DiveTripModel::DIVE_ROLE).value<void*>();
if (d)
- selectedDives.push_front(get_divenr(d));
+ selectedDives.insert(d->divetrip, get_divenr(d));
}
}
void DiveListView::restoreSelection()
{
unselectDives();
- selectedTrips.clear(); // I wish we didn't lose those...
- Q_FOREACH(int i, selectedDives) {
- selectDive(i);
+ Q_FOREACH(dive_trip_t *trip, selectedDives.keys()){
+ QList<int> divesOnTrip = getDivesInTrip(trip);
+ QList<int> selectedDivesOnTrip = selectedDives.values(trip);
+
+ // Trip was not selected, let's select single-dives.
+ if (trip == NULL || divesOnTrip.count() != selectedDivesOnTrip.count()){
+ Q_FOREACH(int i, selectedDivesOnTrip){
+ selectDive(i);
+ }
+ }else{
+ selectTrip(trip);
+ Q_FOREACH(int i, selectedDivesOnTrip){
+ selectDive(i);
+ }
+ }
}
}
+void DiveListView::selectTrip ( dive_trip_t* trip )
+{
+ if (!trip)
+ return;
+
+ QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
+ QModelIndexList match = m->match(m->index(0,0), DiveTripModel::TRIP_ROLE, QVariant::fromValue<void*>(trip), 2, Qt::MatchRecursive);
+ QItemSelectionModel::SelectionFlags flags;
+ if (!match.count())
+ return;
+ QModelIndex idx = match.first();
+ flags = QItemSelectionModel::Select;
+ flags |= QItemSelectionModel::Rows;
+ selectionModel()->select(idx, flags);
+ expand(idx);
+}
+
void DiveListView::unselectDives()
{
selectionModel()->clearSelection();
}
+QList< dive_trip_t* > DiveListView::selectedTrips()
+{
+ QModelIndexList indexes = selectionModel()->selectedRows();
+ QList<dive_trip_t*> ret;
+ Q_FOREACH(const QModelIndex& index, indexes){
+ dive_trip_t *trip = static_cast<dive_trip_t*>(index.data(DiveTripModel::TRIP_ROLE).value<void*>());
+ if(!trip)
+ continue;
+ ret.push_back(trip);
+ }
+ return ret;
+}
+
void DiveListView::selectDive(int i, bool scrollto, bool toggle)
{
if( i == -1)
@@ -347,8 +387,6 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
if (!dive) { // it's a trip!
if (model->rowCount(index)) {
struct dive *child = (struct dive*) model->data(index.child(0,0), DiveTripModel::DIVE_ROLE).value<void*>();
- if (child && child->divetrip)
- selectedTrips.remove(child->divetrip);
while (child) {
deselect_dive(get_divenr(child));
child = child->next;
@@ -368,8 +406,6 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
if (model->rowCount(index)) {
QItemSelection selection;
struct dive *child = (struct dive*) model->data(index.child(0,0), DiveTripModel::DIVE_ROLE).value<void*>();
- if (child && child->divetrip)
- selectedTrips.insert(child->divetrip);
while (child) {
select_dive(get_divenr(child));
child = child->next;
diff --git a/qt-ui/divelistview.h b/qt-ui/divelistview.h
index b4a0d3b35..aae89a40f 100644
--- a/qt-ui/divelistview.h
+++ b/qt-ui/divelistview.h
@@ -29,8 +29,7 @@ public:
void rememberSelection();
void restoreSelection();
void contextMenuEvent(QContextMenuEvent *event);
- QSet<dive_trip_t *> selectedTrips;
-
+ QList<dive_trip_t*> selectedTrips();
public slots:
void toggleColumnVisibilityByIndex();
void reloadHeaderActions();
@@ -55,17 +54,20 @@ signals:
private:
bool mouseClickSelection;
QList<int> expandedRows;
- QList<int> selectedDives;
int sortColumn;
Qt::SortOrder currentOrder;
DiveTripModel::Layout currentLayout;
QLineEdit *searchBox;
QModelIndex contextMenuIndex;
+
+ /* if dive_trip_t is null, there's no problem. */
+ QMultiHash<dive_trip_t *, int> selectedDives;
void merge_trip(const QModelIndex &a, const int offset);
void setupUi();
void backupExpandedRows();
void restoreExpandedRows();
int lastVisibleColumn();
+ void selectTrip ( dive_trip_t* trip );
};
#endif // DIVELISTVIEW_H
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index f132d2fec..11d764abe 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -129,7 +129,7 @@ void MainTab::enableEdition(EditMode newEditMode)
ui.notesButtonBox->show();
ui.equipmentButtonBox->show();
- if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ 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 Cancel when done."));
ui.diveNotesMessage->animatedShow();
@@ -292,7 +292,7 @@ void MainTab::updateDiveInfo(int dive)
if (d) {
updateGpsCoordinates(d);
ui.dateTimeEdit->setDateTime(QDateTime::fromTime_t(d->when - gettimezoneoffset()));
- if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
setTabText(0, tr("Trip Notes"));
// only use trip relevant fields
ui.coordinates->setVisible(false);
@@ -313,7 +313,7 @@ void MainTab::updateDiveInfo(int dive)
ui.airtemp->setVisible(false);
ui.watertemp->setVisible(false);
// rename the remaining fields and fill data from selected trip
- dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
+ dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin();
ui.LocationLabel->setText(tr("Trip Location"));
ui.location->setText(currentTrip->location);
ui.NotesLabel->setText(tr("Trip Notes"));
@@ -472,7 +472,7 @@ void MainTab::acceptChanges()
ui.notesButtonBox->hide();
ui.equipmentButtonBox->hide();
/* now figure out if things have changed */
- if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
if (notesBackup[NULL].notes != ui.notes->toPlainText() ||
notesBackup[NULL].location != ui.location->text())
mark_divelist_changed(TRUE);
@@ -585,7 +585,7 @@ void MainTab::rejectChanges()
tabBar()->setTabIcon(1, QIcon()); // Equipment
mainWindow()->dive_list()->setEnabled(true);
- if (mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1){
+ if (mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1){
ui.notes->setText(notesBackup[NULL].notes );
ui.location->setText(notesBackup[NULL].location);
} else {
@@ -749,9 +749,9 @@ void MainTab::on_location_textChanged(const QString& text)
{
if (editMode == NONE)
return;
- if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
// we are editing a trip
- dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
+ dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin();
EDIT_TEXT(currentTrip->location, text);
} else if (editMode == DIVE || editMode == ADD){
if (!ui.coordinates->isModified() ||
@@ -787,9 +787,9 @@ void MainTab::on_notes_textChanged()
{
if (editMode == NONE)
return;
- if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips.count() == 1) {
+ if (editMode == TRIP && mainWindow() && mainWindow()->dive_list()->selectedTrips().count() == 1) {
// we are editing a trip
- dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin();
+ dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips().begin();
EDIT_TEXT(currentTrip->notes, ui.notes->toPlainText());
} else if (editMode == DIVE || editMode == ADD) {
EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui.notes->toPlainText()) );
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 68d23dffe..85047847b 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -149,7 +149,7 @@ void MainWindow::on_actionClose_triggered()
while (dive_table.nr)
delete_single_dive(0);
- dive_list()->selectedTrips.clear();
+ dive_list()->clearSelection();
/* clear the selection and the statistics */
selected_dive = -1;
diff --git a/qthelper.cpp b/qthelper.cpp
index a4e8bd50b..00412b224 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -145,5 +145,17 @@ bool gpsHasChanged(struct dive *dive, struct dive *master, const QString& gps_te
dive->latitude.udeg = latudeg;
dive->longitude.udeg = longudeg;
return true;
+}
+QList< int > getDivesInTrip ( dive_trip_t* trip )
+{
+ QList<int> ret;
+ for(int i = 0; i < dive_table.nr; i++){
+ struct dive *d = get_dive(i);
+ if (d->divetrip == trip){
+ ret.push_back(get_divenr(d));
+ }
+ }
+ return ret;
}
+
diff --git a/qthelper.h b/qthelper.h
index cd0d8affa..4b0939334 100644
--- a/qthelper.h
+++ b/qthelper.h
@@ -5,6 +5,7 @@
#include <QString>
#include <stdint.h>
#include "dive.h"
+#include "divelist.h"
#include <QTranslator>
// global pointers for our translation
@@ -40,4 +41,5 @@ public:
QString weight_string(int weight_in_grams);
bool gpsHasChanged(struct dive* dive, struct dive *master, const QString &gps_text);
+QList<int> getDivesInTrip(dive_trip_t *trip);
#endif // QTHELPER_H