| 
									
										
										
										
											2013-04-13 20:44:02 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * divelistview.cpp | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * classes for the divelist of Subsurface | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-04-12 08:24:07 +01:00
										 |  |  | #include "divelistview.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-27 12:27:27 -03:00
										 |  |  | #include "models.h"
 | 
					
						
							|  |  |  | #include "modeldelegates.h"
 | 
					
						
							| 
									
										
										
										
											2013-09-22 22:24:28 -07:00
										 |  |  | #include "mainwindow.h"
 | 
					
						
							| 
									
										
										
										
											2013-12-05 18:28:28 +02:00
										 |  |  | #include "subsurfacewebservices.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-20 19:33:32 +03:00
										 |  |  | #include "divelogexportdialog.h"
 | 
					
						
							| 
									
										
										
										
											2013-06-04 21:56:20 +09:00
										 |  |  | #include "../display.h"
 | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | #include "exif.h"
 | 
					
						
							|  |  |  | #include "../file.h"
 | 
					
						
							| 
									
										
										
										
											2013-05-02 19:27:36 -03:00
										 |  |  | #include <QApplication>
 | 
					
						
							|  |  |  | #include <QHeaderView>
 | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | #include <QSettings>
 | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | #include <QKeyEvent>
 | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | #include <QSortFilterProxyModel>
 | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | #include <QAction>
 | 
					
						
							| 
									
										
										
										
											2013-05-30 01:04:42 -03:00
										 |  |  | #include <QLineEdit>
 | 
					
						
							|  |  |  | #include <QKeyEvent>
 | 
					
						
							| 
									
										
										
										
											2013-06-06 03:29:11 +09:00
										 |  |  | #include <QMenu>
 | 
					
						
							| 
									
										
										
										
											2013-10-17 21:50:08 -03:00
										 |  |  | #include <QFileDialog>
 | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2014-05-12 13:53:26 -03:00
										 |  |  | #include "../qthelper.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-12 08:24:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:49 +02:00
										 |  |  | //                                #  Date  Rtg Dpth  Dur  Tmp Wght Suit  Cyl  Gas  SAC  OTU  CNS  Loc
 | 
					
						
							|  |  |  | static int defaultWidth[] =    {  70, 140, 90,  50,  50,  50,  50,  70,  50,  50,  70,  50,  50, 500}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 10:16:53 -07:00
										 |  |  | DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), sortColumn(0), | 
					
						
							| 
									
										
										
										
											2014-10-31 14:17:01 -02:00
										 |  |  | 	currentOrder(Qt::DescendingOrder), dontEmitDiveChangedSignal(false), selectionSaved(false) | 
					
						
							| 
									
										
										
										
											2013-04-12 08:24:07 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-15 18:52:42 +01:00
										 |  |  | 	setItemDelegate(new DiveListDelegate(this)); | 
					
						
							| 
									
										
										
										
											2013-04-24 16:57:30 +01:00
										 |  |  | 	setUniformRowHeights(true); | 
					
						
							| 
									
										
										
										
											2014-01-15 18:52:42 +01:00
										 |  |  | 	setItemDelegateForColumn(DiveTripModel::RATING, new StarWidgetsDelegate(this)); | 
					
						
							| 
									
										
										
										
											2014-10-31 15:27:33 -02:00
										 |  |  | 	MultiFilterSortModel *model = MultiFilterSortModel::instance(); | 
					
						
							| 
									
										
										
										
											2013-06-17 18:59:50 -03:00
										 |  |  | 	model->setSortRole(DiveTripModel::SORT_ROLE); | 
					
						
							| 
									
										
										
										
											2013-05-30 01:04:42 -03:00
										 |  |  | 	model->setFilterKeyColumn(-1); // filter all columns
 | 
					
						
							| 
									
										
										
										
											2014-01-09 20:50:47 +02:00
										 |  |  | 	model->setFilterCaseSensitivity(Qt::CaseInsensitive); | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | 	setModel(model); | 
					
						
							| 
									
										
										
										
											2013-06-12 14:14:25 -03:00
										 |  |  | 	connect(model, SIGNAL(layoutChanged()), this, SLOT(fixMessyQtModelBehaviour())); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-28 16:56:58 -03:00
										 |  |  | 	setSortingEnabled(false); | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | 	setContextMenuPolicy(Qt::DefaultContextMenu); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 	header()->setContextMenuPolicy(Qt::ActionsContextMenu); | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:49 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-01 15:52:23 +02:00
										 |  |  | 	const QFontMetrics metrics(defaultModelFont()); | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:49 +02:00
										 |  |  | 	int em = metrics.width('m'); | 
					
						
							|  |  |  | 	int zw = metrics.width('0'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// Fixes for the layout needed for mac
 | 
					
						
							|  |  |  | #ifdef Q_OS_MAC
 | 
					
						
							| 
									
										
										
										
											2014-10-25 12:46:42 +03:00
										 |  |  | 	int ht = metrics.height(); | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:49 +02:00
										 |  |  | 	header()->setMinimumHeight(ht + 10); | 
					
						
							| 
									
										
										
										
											2014-04-02 21:30:10 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2014-10-15 15:30:49 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// TODO FIXME we need this to get the header names
 | 
					
						
							|  |  |  | 	// can we find a smarter way?
 | 
					
						
							|  |  |  | 	DiveTripModel *tripModel = new DiveTripModel(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// set the default width as a minimum between the hard-coded defaults,
 | 
					
						
							|  |  |  | 	// the header text width and the (assumed) content width, calculated
 | 
					
						
							|  |  |  | 	// based on type
 | 
					
						
							|  |  |  | 	for (int col = DiveTripModel::NR; col < DiveTripModel::COLUMNS; ++col) { | 
					
						
							|  |  |  | 		QString header_txt = tripModel->headerData(col, Qt::Horizontal, Qt::DisplayRole).toString(); | 
					
						
							|  |  |  | 		int width = metrics.width(header_txt); | 
					
						
							|  |  |  | 		int sw = 0; | 
					
						
							|  |  |  | 		switch (col) { | 
					
						
							|  |  |  | 		case DiveTripModel::NR: | 
					
						
							|  |  |  | 		case DiveTripModel::DURATION: | 
					
						
							|  |  |  | 			sw = 8*zw; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case DiveTripModel::DATE: | 
					
						
							|  |  |  | 			sw = 14*em; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case DiveTripModel::RATING: | 
					
						
							|  |  |  | 			sw = static_cast<StarWidgetsDelegate*>(itemDelegateForColumn(col))->starSize().width(); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case DiveTripModel::SUIT: | 
					
						
							|  |  |  | 		case DiveTripModel::SAC: | 
					
						
							|  |  |  | 			sw = 7*em; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case DiveTripModel::LOCATION: | 
					
						
							|  |  |  | 			sw = 50*em; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			sw = 5*em; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (sw > width) | 
					
						
							|  |  |  | 			width = sw; | 
					
						
							|  |  |  | 		width += zw; // small padding
 | 
					
						
							|  |  |  | 		if (width > defaultWidth[col]) | 
					
						
							|  |  |  | 			defaultWidth[col] = width; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	delete tripModel; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-13 16:59:56 -02:00
										 |  |  | 	header()->setStretchLastSection(true); | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | DiveListView::~DiveListView() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QSettings settings; | 
					
						
							|  |  |  | 	settings.beginGroup("ListWidget"); | 
					
						
							| 
									
										
										
										
											2014-08-26 17:23:41 -07:00
										 |  |  | 	// don't set a width for the last column - location is supposed to be "the rest"
 | 
					
						
							|  |  |  | 	for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS - 1; i++) { | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 		if (isColumnHidden(i)) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2014-08-26 17:23:41 -07:00
										 |  |  | 		// we used to hardcode them all to 100 - so that might still be in the settings
 | 
					
						
							|  |  |  | 		if (columnWidth(i) == 100 || columnWidth(i) == defaultWidth[i]) | 
					
						
							|  |  |  | 			settings.remove(QString("colwidth%1").arg(i)); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			settings.setValue(QString("colwidth%1").arg(i), columnWidth(i)); | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-26 17:23:41 -07:00
										 |  |  | 	settings.remove(QString("colwidth%1").arg(DiveTripModel::COLUMNS - 1)); | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 	settings.endGroup(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | void DiveListView::setupUi() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 	QSettings settings; | 
					
						
							| 
									
										
										
										
											2013-11-08 20:46:25 -02:00
										 |  |  | 	static bool firstRun = true; | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (firstRun) | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | 		backupExpandedRows(); | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 	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++) { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (isColumnHidden(i)) | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		QVariant width = settings.value(QString("colwidth%1").arg(i)); | 
					
						
							|  |  |  | 		if (width.isValid()) | 
					
						
							|  |  |  | 			setColumnWidth(i, width.toInt()); | 
					
						
							|  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2014-08-22 14:45:00 -07:00
										 |  |  | 			setColumnWidth(i, defaultWidth[i]); | 
					
						
							| 
									
										
										
										
											2013-11-08 20:30:17 -02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	settings.endGroup(); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (firstRun) | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | 		restoreExpandedRows(); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		collapseAll(); | 
					
						
							|  |  |  | 	firstRun = false; | 
					
						
							| 
									
										
										
										
											2013-11-13 16:59:56 -02:00
										 |  |  | 	setColumnWidth(lastVisibleColumn(), 10); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int DiveListView::lastVisibleColumn() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int lastColumn = -1; | 
					
						
							|  |  |  | 	for (int i = DiveTripModel::NR; i < DiveTripModel::COLUMNS; i++) { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (isColumnHidden(i)) | 
					
						
							| 
									
										
										
										
											2013-11-13 16:59:56 -02:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		lastColumn = i; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return lastColumn; | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-11-08 20:46:25 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | void DiveListView::backupExpandedRows() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | 	expandedRows.clear(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	for (int i = 0; i < model()->rowCount(); i++) | 
					
						
							|  |  |  | 		if (isExpanded(model()->index(i, 0))) | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | 			expandedRows.push_back(i); | 
					
						
							| 
									
										
										
										
											2013-05-30 01:04:42 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | void DiveListView::restoreExpandedRows() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 	setAnimated(false); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (const int &i, expandedRows) | 
					
						
							| 
									
										
										
										
											2014-03-03 13:25:55 -08:00
										 |  |  | 		setExpanded(model()->index(i, 0), true); | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 	setAnimated(true); | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-12 14:14:25 -03:00
										 |  |  | void DiveListView::fixMessyQtModelBehaviour() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAbstractItemModel *m = model(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	for (int i = 0; i < model()->rowCount(); i++) | 
					
						
							|  |  |  | 		if (m->rowCount(m->index(i, 0)) != 0) | 
					
						
							| 
									
										
										
										
											2013-06-12 14:14:25 -03:00
										 |  |  | 			setFirstColumnSpanned(i, QModelIndex(), true); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-14 17:52:03 +09:00
										 |  |  | // this only remembers dives that were selected, not trips
 | 
					
						
							|  |  |  | void DiveListView::rememberSelection() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	selectedDives.clear(); | 
					
						
							|  |  |  | 	QItemSelection selection = selectionModel()->selection(); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (const QModelIndex &index, selection.indexes()) { | 
					
						
							| 
									
										
										
										
											2013-11-14 17:52:03 +09:00
										 |  |  | 		if (index.column() != 0) // We only care about the dives, so, let's stick to rows and discard columns.
 | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		struct dive *d = (struct dive *)index.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-11-14 17:52:03 +09:00
										 |  |  | 		if (d) | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | 			selectedDives.insert(d->divetrip, get_divenr(d)); | 
					
						
							| 
									
										
										
										
											2013-11-14 17:52:03 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-28 19:03:10 -03:00
										 |  |  | 	selectionSaved = true; | 
					
						
							| 
									
										
										
										
											2013-11-14 17:52:03 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveListView::restoreSelection() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-28 19:03:10 -03:00
										 |  |  | 	if (!selectionSaved) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	selectionSaved = false; | 
					
						
							| 
									
										
										
										
											2014-07-21 20:44:46 -03:00
										 |  |  | 	dontEmitDiveChangedSignal = true; | 
					
						
							| 
									
										
										
										
											2013-11-14 17:52:03 +09:00
										 |  |  | 	unselectDives(); | 
					
						
							| 
									
										
										
										
											2014-07-21 20:44:46 -03:00
										 |  |  | 	dontEmitDiveChangedSignal = false; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (dive_trip_t *trip, selectedDives.keys()) { | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | 		QList<int> divesOnTrip = getDivesInTrip(trip); | 
					
						
							|  |  |  | 		QList<int> selectedDivesOnTrip = selectedDives.values(trip); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-28 13:10:33 -07:00
										 |  |  | 		// Only select trip if all of its dives were selected
 | 
					
						
							|  |  |  | 		if (trip != NULL && divesOnTrip.count() == selectedDivesOnTrip.count()) | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | 			selectTrip(trip); | 
					
						
							| 
									
										
										
										
											2014-05-28 13:10:33 -07:00
										 |  |  | 		selectDives(selectedDivesOnTrip); | 
					
						
							| 
									
										
										
										
											2013-11-14 17:52:03 +09:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveListView::selectTrip(dive_trip_t *trip) | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!trip) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model()); | 
					
						
							|  |  |  | 	QModelIndexList match = m->match(m->index(0, 0), DiveTripModel::TRIP_ROLE, QVariant::fromValue<void *>(trip), 2, Qt::MatchRecursive); | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | 	QItemSelectionModel::SelectionFlags flags; | 
					
						
							|  |  |  | 	if (!match.count()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	QModelIndex idx = match.first(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	flags = QItemSelectionModel::Select; | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | 	flags |= QItemSelectionModel::Rows; | 
					
						
							|  |  |  | 	selectionModel()->select(idx, flags); | 
					
						
							|  |  |  | 	expand(idx); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-03 17:52:04 -08:00
										 |  |  | // this is an odd one - when filtering the dive list the selection status of the trips
 | 
					
						
							|  |  |  | // is kept - but all other selections are lost. That's gets us into rather inconsistent state
 | 
					
						
							|  |  |  | // we call this function which clears the selection state of the trips as well, but does so
 | 
					
						
							|  |  |  | // without updating our internal "->selected" state. So once we called this function we can
 | 
					
						
							|  |  |  | // go back and select those dives that are still visible under the filter and everything
 | 
					
						
							|  |  |  | // works as expected
 | 
					
						
							|  |  |  | void DiveListView::clearTripSelection() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// we want to make sure no trips are selected
 | 
					
						
							|  |  |  | 	disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); | 
					
						
							|  |  |  | 	disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Q_FOREACH (const QModelIndex &index, selectionModel()->selectedRows()) { | 
					
						
							|  |  |  | 		dive_trip_t *trip = static_cast<dive_trip_t *>(index.data(DiveTripModel::TRIP_ROLE).value<void *>()); | 
					
						
							|  |  |  | 		if (!trip) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		selectionModel()->select(index, QItemSelectionModel::Deselect); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); | 
					
						
							|  |  |  | 	connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-05 15:41:52 +09:00
										 |  |  | void DiveListView::unselectDives() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-21 17:58:15 -07:00
										 |  |  | 	// make sure we don't try to redraw the dives during the selection change
 | 
					
						
							|  |  |  | 	selected_dive = -1; | 
					
						
							|  |  |  | 	amount_selected = 0; | 
					
						
							|  |  |  | 	// clear the Qt selection
 | 
					
						
							| 
									
										
										
										
											2013-06-05 15:41:52 +09:00
										 |  |  | 	selectionModel()->clearSelection(); | 
					
						
							| 
									
										
										
										
											2014-05-24 13:55:18 -07:00
										 |  |  | 	// clearSelection should emit selectionChanged() but sometimes that
 | 
					
						
							|  |  |  | 	// appears not to happen
 | 
					
						
							| 
									
										
										
										
											2014-08-21 17:58:15 -07:00
										 |  |  | 	// since we are unselecting all dives there is no need to use deselect_dive() - that
 | 
					
						
							|  |  |  | 	// would only cause pointless churn
 | 
					
						
							| 
									
										
										
										
											2014-05-24 13:55:18 -07:00
										 |  |  | 	int i; | 
					
						
							|  |  |  | 	struct dive *dive; | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	for_each_dive (i, dive) { | 
					
						
							| 
									
										
										
										
											2014-08-21 17:58:15 -07:00
										 |  |  | 		dive->selected = false; | 
					
						
							| 
									
										
										
										
											2014-05-24 13:55:18 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-05 15:41:52 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | QList<dive_trip_t *> DiveListView::selectedTrips() | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QList<dive_trip_t *> ret; | 
					
						
							| 
									
										
										
										
											2014-07-15 14:43:20 -03:00
										 |  |  | 	Q_FOREACH (const QModelIndex &index, selectionModel()->selectedRows()) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		dive_trip_t *trip = static_cast<dive_trip_t *>(index.data(DiveTripModel::TRIP_ROLE).value<void *>()); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (!trip) | 
					
						
							| 
									
										
										
										
											2013-11-26 15:44:18 -02:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		ret.push_back(trip); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | void DiveListView::selectDive(int i, bool scrollto, bool toggle) | 
					
						
							| 
									
										
										
										
											2013-06-05 15:41:52 +09:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (i == -1) | 
					
						
							| 
									
										
										
										
											2013-11-16 22:56:48 -02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model()); | 
					
						
							|  |  |  | 	QModelIndexList match = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, i, 2, Qt::MatchRecursive); | 
					
						
							| 
									
										
										
										
											2013-06-07 22:57:45 -07:00
										 |  |  | 	QItemSelectionModel::SelectionFlags flags; | 
					
						
							| 
									
										
										
										
											2014-05-18 19:08:58 +09:00
										 |  |  | 	if (match.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2013-06-05 15:41:52 +09:00
										 |  |  | 	QModelIndex idx = match.first(); | 
					
						
							| 
									
										
										
										
											2013-06-07 18:25:30 -07:00
										 |  |  | 	flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select; | 
					
						
							|  |  |  | 	flags |= QItemSelectionModel::Rows; | 
					
						
							| 
									
										
										
										
											2014-01-06 20:13:21 -02:00
										 |  |  | 	selectionModel()->setCurrentIndex(idx, flags); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (idx.parent().isValid()) { | 
					
						
							| 
									
										
										
										
											2013-11-16 18:54:14 -02:00
										 |  |  | 		setAnimated(false); | 
					
						
							|  |  |  | 		expand(idx.parent()); | 
					
						
							| 
									
										
											  
											
												When scrolling to dive, scroll to trip first
The behavior at startup is actually very annoying: we select the latest
dive, and expand the trip it is in, but since we use "scrollTo()" on
just the dive, and it's not initially visible, the startup will make the
first dive be at the top of the list view.
Which means that the actual _trip_ detail is not visible at all, since
it will have been scrolled off the list view entirely.
Fix this by first scrolling to the trip, and only then scrolling to the
actual dive (using the default "EnsureVisible" policy).  Obviously, if
it's a trip with lots of dives, scrolling to the dive may end up
scrolling away from the trip header again, but at least that never
happens at startup, and at that point you have to scroll away from the
trip just to show the dive.
Do this same dance when changing the dive selection (mainly noticeable
when picking dives on the globe view).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
											
										 
											2014-04-28 10:39:06 -07:00
										 |  |  | 		if (scrollto) | 
					
						
							|  |  |  | 			scrollTo(idx.parent()); | 
					
						
							| 
									
										
										
										
											2013-11-16 18:54:14 -02:00
										 |  |  | 		setAnimated(true); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-05 15:41:52 +09:00
										 |  |  | 	if (scrollto) | 
					
						
							|  |  |  | 		scrollTo(idx, PositionAtCenter); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-02 17:15:40 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveListView::selectDives(const QList<int> &newDiveSelection) | 
					
						
							| 
									
										
										
										
											2013-12-02 17:15:40 -02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (!newDiveSelection.count()) | 
					
						
							| 
									
										
										
										
											2013-12-02 17:15:40 -02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-24 21:03:18 -07:00
										 |  |  | 	dontEmitDiveChangedSignal = true; | 
					
						
							| 
									
										
										
										
											2014-05-24 20:55:28 -07:00
										 |  |  | 	// select the dives, highest index first - this way the oldest of the dives
 | 
					
						
							|  |  |  | 	// becomes the selected_dive that we scroll to
 | 
					
						
							|  |  |  | 	QList<int> sortedSelection = newDiveSelection; | 
					
						
							|  |  |  | 	qSort(sortedSelection.begin(), sortedSelection.end()); | 
					
						
							|  |  |  | 	while (!sortedSelection.isEmpty()) | 
					
						
							|  |  |  | 		selectDive(sortedSelection.takeLast()); | 
					
						
							| 
									
										
										
										
											2013-12-02 17:15:40 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model()); | 
					
						
							| 
									
										
										
										
											2014-05-07 21:51:55 -07:00
										 |  |  | 	QModelIndex idx = m->match(m->index(0, 0), DiveTripModel::DIVE_IDX, selected_dive, 2, Qt::MatchRecursive).first(); | 
					
						
							| 
									
										
											  
											
												When scrolling to dive, scroll to trip first
The behavior at startup is actually very annoying: we select the latest
dive, and expand the trip it is in, but since we use "scrollTo()" on
just the dive, and it's not initially visible, the startup will make the
first dive be at the top of the list view.
Which means that the actual _trip_ detail is not visible at all, since
it will have been scrolled off the list view entirely.
Fix this by first scrolling to the trip, and only then scrolling to the
actual dive (using the default "EnsureVisible" policy).  Obviously, if
it's a trip with lots of dives, scrolling to the dive may end up
scrolling away from the trip header again, but at least that never
happens at startup, and at that point you have to scroll away from the
trip just to show the dive.
Do this same dance when changing the dive selection (mainly noticeable
when picking dives on the globe view).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
											
										 
											2014-04-28 10:39:06 -07:00
										 |  |  | 	if (idx.parent().isValid()) | 
					
						
							|  |  |  | 		scrollTo(idx.parent()); | 
					
						
							| 
									
										
										
										
											2013-12-02 17:15:40 -02:00
										 |  |  | 	scrollTo(idx); | 
					
						
							| 
									
										
										
										
											2014-05-24 20:55:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-24 21:03:18 -07:00
										 |  |  | 	// now that everything is up to date, update the widgets
 | 
					
						
							|  |  |  | 	Q_EMIT currentDiveChanged(selected_dive); | 
					
						
							|  |  |  | 	dontEmitDiveChangedSignal = false; | 
					
						
							| 
									
										
										
										
											2014-05-24 20:55:28 -07:00
										 |  |  | 	return; | 
					
						
							| 
									
										
										
										
											2013-12-02 17:15:40 -02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | bool DiveListView::eventFilter(QObject *, QEvent *event) | 
					
						
							| 
									
										
										
										
											2013-05-30 01:04:42 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (event->type() != QEvent::KeyPress) | 
					
						
							| 
									
										
										
										
											2013-05-30 01:04:42 -03:00
										 |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QKeyEvent *keyEv = static_cast<QKeyEvent *>(event); | 
					
						
							| 
									
										
										
										
											2013-10-11 10:21:04 -03:00
										 |  |  | 	if (keyEv->key() != Qt::Key_Escape) | 
					
						
							| 
									
										
										
										
											2013-05-30 01:04:42 -03:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-31 13:53:04 +09:00
										 |  |  | // NOTE! This loses trip selection, because while we remember the
 | 
					
						
							|  |  |  | // dives, we don't remember the trips (see the "currentSelectedDives"
 | 
					
						
							|  |  |  | // list). I haven't figured out how to look up the trip from the
 | 
					
						
							|  |  |  | // index. TRIP_ROLE vs DIVE_ROLE?
 | 
					
						
							| 
									
										
										
										
											2013-05-30 05:43:14 +09:00
										 |  |  | void DiveListView::headerClicked(int i) | 
					
						
							| 
									
										
										
										
											2013-05-28 17:07:43 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	DiveTripModel::Layout newLayout = i == (int)DiveTripModel::NR ? DiveTripModel::TREE : DiveTripModel::LIST; | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 	rememberSelection(); | 
					
						
							| 
									
										
										
										
											2013-06-05 17:28:22 +09:00
										 |  |  | 	unselectDives(); | 
					
						
							| 
									
										
										
										
											2013-05-31 13:53:04 +09:00
										 |  |  | 	/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */ | 
					
						
							|  |  |  | 	if (currentLayout == newLayout) { | 
					
						
							| 
									
										
										
										
											2013-11-05 14:09:08 +09:00
										 |  |  | 		currentOrder = (currentOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder; | 
					
						
							|  |  |  | 		sortByColumn(i, currentOrder); | 
					
						
							| 
									
										
										
										
											2013-05-31 13:53:04 +09:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		// clear the model, repopulate with new indexes.
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (currentLayout == DiveTripModel::TREE) { | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | 			backupExpandedRows(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-31 13:53:04 +09:00
										 |  |  | 		reload(newLayout, false); | 
					
						
							| 
									
										
										
										
											2013-11-05 14:09:08 +09:00
										 |  |  | 		currentOrder = Qt::DescendingOrder; | 
					
						
							|  |  |  | 		sortByColumn(i, currentOrder); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (newLayout == DiveTripModel::TREE) { | 
					
						
							| 
									
										
										
										
											2013-11-08 21:08:14 -02:00
										 |  |  | 			restoreExpandedRows(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-31 13:53:04 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 	restoreSelection(); | 
					
						
							| 
									
										
										
										
											2014-05-25 06:19:05 -07:00
										 |  |  | 	// remember the new sort column
 | 
					
						
							|  |  |  | 	sortColumn = i; | 
					
						
							| 
									
										
										
										
											2013-05-28 17:07:43 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-29 14:03:36 -03:00
										 |  |  | void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort) | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-05-25 07:28:22 -07:00
										 |  |  | 	// we want to run setupUi() once we actually are displaying something
 | 
					
						
							|  |  |  | 	// in the widget
 | 
					
						
							|  |  |  | 	static bool first = true; | 
					
						
							|  |  |  | 	if (first && dive_table.nr > 0) { | 
					
						
							|  |  |  | 		setupUi(); | 
					
						
							|  |  |  | 		first = false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-06 11:22:08 +09:00
										 |  |  | 	if (layout == DiveTripModel::CURRENT) | 
					
						
							|  |  |  | 		layout = currentLayout; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		currentLayout = layout; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
 | 
					
						
							| 
									
										
										
										
											2013-05-28 17:46:40 -03:00
										 |  |  | 	header()->setClickable(true); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:39 +01:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	header()->setSectionsClickable(true); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2013-05-28 17:46:40 -03:00
										 |  |  | 	connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel *>(model()); | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | 	QAbstractItemModel *oldModel = m->sourceModel(); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (oldModel) { | 
					
						
							| 
									
										
										
										
											2013-05-16 15:09:45 -06:00
										 |  |  | 		oldModel->deleteLater(); | 
					
						
							| 
									
										
										
										
											2013-11-16 19:21:54 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-28 16:56:58 -03:00
										 |  |  | 	DiveTripModel *tripModel = new DiveTripModel(this); | 
					
						
							| 
									
										
										
										
											2013-05-28 17:07:43 -03:00
										 |  |  | 	tripModel->setLayout(layout); | 
					
						
							| 
									
										
										
										
											2013-05-28 16:56:58 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	m->setSourceModel(tripModel); | 
					
						
							| 
									
										
										
										
											2013-05-29 14:03:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (!forceSort) | 
					
						
							| 
									
										
										
										
											2013-05-29 14:03:36 -03:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-05 14:09:08 +09:00
										 |  |  | 	sortByColumn(sortColumn, currentOrder); | 
					
						
							| 
									
										
										
										
											2013-11-13 13:59:02 +09:00
										 |  |  | 	if (amount_selected && current_dive != NULL) { | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 		selectDive(selected_dive, true); | 
					
						
							| 
									
										
										
										
											2013-06-04 21:56:20 +09:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		QModelIndex firstDiveOrTrip = m->index(0, 0); | 
					
						
							| 
									
										
										
										
											2013-06-04 21:56:20 +09:00
										 |  |  | 		if (firstDiveOrTrip.isValid()) { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 			if (m->index(0, 0, firstDiveOrTrip).isValid()) | 
					
						
							|  |  |  | 				setCurrentIndex(m->index(0, 0, firstDiveOrTrip)); | 
					
						
							| 
									
										
										
										
											2013-06-04 21:56:20 +09:00
										 |  |  | 			else | 
					
						
							|  |  |  | 				setCurrentIndex(firstDiveOrTrip); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-16 16:00:33 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (selectedIndexes().count()) { | 
					
						
							| 
									
										
										
										
											2013-11-15 12:01:56 -02:00
										 |  |  | 		QModelIndex curr = selectedIndexes().first(); | 
					
						
							|  |  |  | 		curr = curr.parent().isValid() ? curr.parent() : curr; | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 		if (!isExpanded(curr)) { | 
					
						
							| 
									
										
										
										
											2013-11-15 12:01:56 -02:00
										 |  |  | 			setAnimated(false); | 
					
						
							|  |  |  | 			expand(curr); | 
					
						
							| 
									
										
											  
											
												When scrolling to dive, scroll to trip first
The behavior at startup is actually very annoying: we select the latest
dive, and expand the trip it is in, but since we use "scrollTo()" on
just the dive, and it's not initially visible, the startup will make the
first dive be at the top of the list view.
Which means that the actual _trip_ detail is not visible at all, since
it will have been scrolled off the list view entirely.
Fix this by first scrolling to the trip, and only then scrolling to the
actual dive (using the default "EnsureVisible" policy).  Obviously, if
it's a trip with lots of dives, scrolling to the dive may end up
scrolling away from the trip header again, but at least that never
happens at startup, and at that point you have to scroll away from the
trip just to show the dive.
Do this same dance when changing the dive selection (mainly noticeable
when picking dives on the globe view).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
											
										 
											2014-04-28 10:39:06 -07:00
										 |  |  | 			scrollTo(curr); | 
					
						
							| 
									
										
										
										
											2013-11-15 12:01:56 -02:00
										 |  |  | 			setAnimated(true); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (currentLayout == DiveTripModel::TREE) { | 
					
						
							| 
									
										
										
										
											2013-11-16 18:47:34 -02:00
										 |  |  | 		fixMessyQtModelBehaviour(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveListView::reloadHeaderActions() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 	// Populate the context menu of the headers that will show
 | 
					
						
							|  |  |  | 	// the menu to show / hide columns.
 | 
					
						
							| 
									
										
										
										
											2013-05-22 21:25:05 -07:00
										 |  |  | 	if (!header()->actions().size()) { | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 		QSettings s; | 
					
						
							|  |  |  | 		s.beginGroup("DiveListColumnState"); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		for (int i = 0; i < model()->columnCount(); i++) { | 
					
						
							| 
									
										
										
										
											2013-05-29 23:18:10 +02:00
										 |  |  | 			QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString()); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | 			QString settingName = QString("showColumn%1").arg(i); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 			QAction *a = new QAction(title, header()); | 
					
						
							| 
									
										
										
										
											2014-08-26 17:25:15 -07:00
										 |  |  | 			bool showHeaderFirstRun = !(i == DiveTripModel::MAXCNS || | 
					
						
							|  |  |  | 						    i == DiveTripModel::GAS || | 
					
						
							|  |  |  | 						    i == DiveTripModel::OTU || | 
					
						
							|  |  |  | 						    i == DiveTripModel::TEMPERATURE || | 
					
						
							|  |  |  | 						    i == DiveTripModel::TOTALWEIGHT || | 
					
						
							|  |  |  | 						    i == DiveTripModel::SUIT || | 
					
						
							|  |  |  | 						    i == DiveTripModel::CYLINDER || | 
					
						
							|  |  |  | 						    i == DiveTripModel::SAC); | 
					
						
							| 
									
										
										
										
											2013-10-04 14:28:49 -03:00
										 |  |  | 			bool shown = s.value(settingName, showHeaderFirstRun).toBool(); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 			a->setCheckable(true); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | 			a->setChecked(shown); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 			a->setProperty("index", i); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | 			a->setProperty("settingName", settingName); | 
					
						
							|  |  |  | 			connect(a, SIGNAL(triggered(bool)), this, SLOT(toggleColumnVisibilityByIndex())); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 			header()->addAction(a); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | 			setColumnHidden(i, !shown); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		s.endGroup(); | 
					
						
							| 
									
										
										
										
											2013-06-09 20:09:39 -03:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		for (int i = 0; i < model()->columnCount(); i++) { | 
					
						
							| 
									
										
										
										
											2013-06-09 20:09:39 -03:00
										 |  |  | 			QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString()); | 
					
						
							| 
									
										
										
										
											2013-12-04 18:20:33 +02:00
										 |  |  | 			header()->actions()[i]->setText(title); | 
					
						
							| 
									
										
										
										
											2013-06-09 20:09:39 -03:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | void DiveListView::toggleColumnVisibilityByIndex() | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QAction *action = qobject_cast<QAction *>(sender()); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 	if (!action) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 	s.beginGroup("DiveListColumnState"); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | 	s.setValue(action->property("settingName").toString(), action->isChecked()); | 
					
						
							| 
									
										
										
										
											2013-05-21 16:51:49 -03:00
										 |  |  | 	s.endGroup(); | 
					
						
							| 
									
										
										
										
											2013-05-21 23:07:19 -03:00
										 |  |  | 	s.sync(); | 
					
						
							| 
									
										
										
										
											2013-05-26 10:12:45 -07:00
										 |  |  | 	setColumnHidden(action->property("index").toInt(), !action->isChecked()); | 
					
						
							| 
									
										
										
										
											2013-11-13 16:59:56 -02:00
										 |  |  | 	setColumnWidth(lastVisibleColumn(), 10); | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveListView::currentChanged(const QModelIndex ¤t, const QModelIndex &previous) | 
					
						
							| 
									
										
										
										
											2013-05-14 08:18:26 -03:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!current.isValid()) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2013-06-05 16:46:23 +09:00
										 |  |  | 	scrollTo(current); | 
					
						
							| 
									
										
										
										
											2013-05-14 08:18:26 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveListView::selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-05-29 14:03:36 -03:00
										 |  |  | 	QItemSelection newSelected = selected.size() ? selected : selectionModel()->selection(); | 
					
						
							|  |  |  | 	QItemSelection newDeselected = deselected; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); | 
					
						
							|  |  |  | 	disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); | 
					
						
							| 
									
										
										
										
											2013-05-29 14:03:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (const QModelIndex &index, newDeselected.indexes()) { | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 		if (index.column() != 0) | 
					
						
							| 
									
										
										
										
											2013-05-29 14:03:36 -03:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | 		const QAbstractItemModel *model = index.model(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2014-05-24 13:19:05 -07:00
										 |  |  | 		if (!dive) // it's a trip!
 | 
					
						
							|  |  |  | 			deselect_dives_in_trip((dive_trip_t *)model->data(index, DiveTripModel::TRIP_ROLE).value<void *>()); | 
					
						
							|  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2013-11-16 19:21:54 -02:00
										 |  |  | 			deselect_dive(get_divenr(dive)); | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	Q_FOREACH (const QModelIndex &index, newSelected.indexes()) { | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 		if (index.column() != 0) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2013-06-14 06:17:38 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 		const QAbstractItemModel *model = index.model(); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 		if (!dive) { // it's a trip!
 | 
					
						
							|  |  |  | 			if (model->rowCount(index)) { | 
					
						
							| 
									
										
										
										
											2013-06-14 06:17:38 -07:00
										 |  |  | 				QItemSelection selection; | 
					
						
							| 
									
										
										
										
											2014-05-24 13:19:05 -07:00
										 |  |  | 				select_dives_in_trip((dive_trip_t *)model->data(index, DiveTripModel::TRIP_ROLE).value<void *>()); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 				selection.select(index.child(0, 0), index.child(model->rowCount(index) - 1, 0)); | 
					
						
							| 
									
										
										
										
											2013-06-14 06:17:38 -07:00
										 |  |  | 				selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows); | 
					
						
							|  |  |  | 				selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate); | 
					
						
							|  |  |  | 				if (!isExpanded(index)) | 
					
						
							|  |  |  | 					expand(index); | 
					
						
							| 
									
										
										
										
											2013-05-31 21:05:33 +09:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2013-11-16 19:21:54 -02:00
										 |  |  | 			select_dive(get_divenr(dive)); | 
					
						
							| 
									
										
										
										
											2013-05-13 22:14:59 -03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-29 14:03:36 -03:00
										 |  |  | 	QTreeView::selectionChanged(selectionModel()->selection(), newDeselected); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(selectionChanged(QItemSelection, QItemSelection))); | 
					
						
							|  |  |  | 	connect(selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(currentChanged(QModelIndex, QModelIndex))); | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	if (!dontEmitDiveChangedSignal) | 
					
						
							| 
									
										
										
										
											2014-05-24 21:03:18 -07:00
										 |  |  | 		Q_EMIT currentDiveChanged(selected_dive); | 
					
						
							| 
									
										
										
										
											2013-04-12 08:24:07 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-06-06 03:29:11 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-16 14:46:08 -08:00
										 |  |  | static bool can_merge(const struct dive *a, const struct dive *b) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!a || !b) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	if (a->when > b->when) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	/* Don't merge dives if there's more than half an hour between them */ | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	if (a->when + a->duration.seconds + 30 * 60 < b->when) | 
					
						
							| 
									
										
										
										
											2013-11-16 14:46:08 -08:00
										 |  |  | 		return false; | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 21:57:28 -07:00
										 |  |  | void DiveListView::mergeDives() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2013-10-15 04:37:31 -07:00
										 |  |  | 	struct dive *dive, *maindive = NULL; | 
					
						
							| 
									
										
										
										
											2013-09-23 21:57:28 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	for_each_dive (i, dive) { | 
					
						
							| 
									
										
										
										
											2013-10-15 04:37:31 -07:00
										 |  |  | 		if (dive->selected) { | 
					
						
							| 
									
										
										
										
											2013-11-16 14:46:08 -08:00
										 |  |  | 			if (!can_merge(maindive, dive)) { | 
					
						
							| 
									
										
										
										
											2013-09-23 21:57:28 -07:00
										 |  |  | 				maindive = dive; | 
					
						
							| 
									
										
										
										
											2013-11-05 15:38:41 +09:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2013-09-23 21:57:28 -07:00
										 |  |  | 				maindive = merge_two_dives(maindive, dive); | 
					
						
							| 
									
										
										
										
											2013-11-05 15:38:41 +09:00
										 |  |  | 				i--; // otherwise we skip a dive in the freshly changed list
 | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-10-15 04:37:31 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 	MainWindow::instance()->refreshDisplay(); | 
					
						
							| 
									
										
										
										
											2013-09-23 21:57:28 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-20 06:11:32 +09:00
										 |  |  | void DiveListView::renumberDives() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	RenumberDialog::instance()->renumberOnlySelected(); | 
					
						
							|  |  |  | 	RenumberDialog::instance()->show(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-26 19:16:40 -10:00
										 |  |  | void DiveListView::merge_trip(const QModelIndex &a, int offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i = a.row() + offset; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QModelIndex b = a.sibling(i, 0); | 
					
						
							| 
									
										
										
										
											2013-06-26 19:16:40 -10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	dive_trip_t *trip_a = (dive_trip_t *)a.data(DiveTripModel::TRIP_ROLE).value<void *>(); | 
					
						
							|  |  |  | 	dive_trip_t *trip_b = (dive_trip_t *)b.data(DiveTripModel::TRIP_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-06-26 19:16:40 -10:00
										 |  |  | 	if (trip_a == trip_b || !trip_a || !trip_b) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-05-24 14:02:08 -07:00
										 |  |  | 	combine_trips(trip_a, trip_b); | 
					
						
							| 
									
										
										
										
											2013-11-17 14:37:10 -08:00
										 |  |  | 	rememberSelection(); | 
					
						
							| 
									
										
										
										
											2013-06-26 19:16:40 -10:00
										 |  |  | 	reload(currentLayout, false); | 
					
						
							| 
									
										
										
										
											2013-11-17 14:37:10 -08:00
										 |  |  | 	fixMessyQtModelBehaviour(); | 
					
						
							|  |  |  | 	restoreSelection(); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-04-16 23:56:42 -03:00
										 |  |  | 	//TODO: emit a signal to signalize that the divelist changed?
 | 
					
						
							| 
									
										
										
										
											2013-06-26 19:16:40 -10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveListView::mergeTripAbove() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	merge_trip(contextMenuIndex, -1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveListView::mergeTripBelow() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	merge_trip(contextMenuIndex, +1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | void DiveListView::removeFromTrip() | 
					
						
							| 
									
										
										
										
											2013-06-06 03:29:11 +09:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-16 23:56:42 -03:00
										 |  |  | 	//TODO: move this to C-code.
 | 
					
						
							| 
									
										
										
										
											2013-11-15 14:11:55 +09:00
										 |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2013-12-08 06:05:54 +01:00
										 |  |  | 	struct dive *d; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	for_each_dive (i, d) { | 
					
						
							| 
									
										
										
										
											2013-11-15 14:11:55 +09:00
										 |  |  | 		if (d->selected) | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 			remove_dive_from_trip(d, false); | 
					
						
							| 
									
										
										
										
											2013-11-15 14:11:55 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 	rememberSelection(); | 
					
						
							| 
									
										
										
										
											2013-06-06 10:37:18 +09:00
										 |  |  | 	reload(currentLayout, false); | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 	fixMessyQtModelBehaviour(); | 
					
						
							|  |  |  | 	restoreSelection(); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2013-06-06 10:37:18 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-15 11:32:19 +09:00
										 |  |  | void DiveListView::newTripAbove() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-11-15 11:32:19 +09:00
										 |  |  | 	if (!d) // shouldn't happen as we only are setting up this action if this is a dive
 | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-04-16 23:56:42 -03:00
										 |  |  | 	//TODO: port to c-code.
 | 
					
						
							|  |  |  | 	dive_trip_t *trip; | 
					
						
							|  |  |  | 	int idx; | 
					
						
							| 
									
										
										
										
											2013-11-15 11:32:19 +09:00
										 |  |  | 	rememberSelection(); | 
					
						
							|  |  |  | 	trip = create_and_hookup_trip_from_dive(d); | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	for_each_dive (idx, d) { | 
					
						
							| 
									
										
										
										
											2013-11-15 14:11:55 +09:00
										 |  |  | 		if (d->selected) | 
					
						
							| 
									
										
										
										
											2013-11-15 11:32:19 +09:00
										 |  |  | 			add_dive_to_trip(d, trip); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	trip->expanded = 1; | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 	reload(currentLayout, false); | 
					
						
							|  |  |  | 	fixMessyQtModelBehaviour(); | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 	restoreSelection(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-20 07:42:20 +01:00
										 |  |  | void DiveListView::addToTripBelow() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 	addToTrip(1); | 
					
						
							| 
									
										
										
										
											2014-03-20 07:42:20 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | void DiveListView::addToTripAbove() | 
					
						
							| 
									
										
										
										
											2014-03-20 07:42:20 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 	addToTrip(-1); | 
					
						
							| 
									
										
										
										
											2014-03-20 07:42:20 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | void DiveListView::addToTrip(int delta) | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 	// if there is a trip above / below, then it's a sibling at the same
 | 
					
						
							|  |  |  | 	// level as this dive. So let's take a look
 | 
					
						
							| 
									
										
										
										
											2014-04-16 23:56:42 -03:00
										 |  |  | 	struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 	QModelIndex t = contextMenuIndex.sibling(contextMenuIndex.row() + delta, 0); | 
					
						
							|  |  |  | 	dive_trip_t *trip = (dive_trip_t *)t.data(DiveTripModel::TRIP_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2014-04-16 23:56:42 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 	if (!trip || !d) | 
					
						
							|  |  |  | 		// no dive, no trip? get me out of here
 | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	rememberSelection(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 	add_dive_to_trip(d, trip); | 
					
						
							|  |  |  | 	if (d->selected) { // there are possibly other selected dives that we should add
 | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 		int idx; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		for_each_dive (idx, d) { | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 			if (d->selected) | 
					
						
							|  |  |  | 				add_dive_to_trip(d, trip); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	trip->expanded = 1; | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-08-21 14:20:03 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-15 11:32:19 +09:00
										 |  |  | 	reload(currentLayout, false); | 
					
						
							|  |  |  | 	restoreSelection(); | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 	fixMessyQtModelBehaviour(); | 
					
						
							| 
									
										
										
										
											2013-11-15 11:32:19 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | void DiveListView::markDiveInvalid() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | 	if (!d) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 	for_each_dive (i, d) { | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | 		if (!d->selected) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2014-04-16 23:56:42 -03:00
										 |  |  | 		//TODO: this should be done in the future
 | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | 		// now mark the dive invalid... how do we do THAT?
 | 
					
						
							|  |  |  | 		// d->invalid = true;
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (amount_selected == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 		MainWindow::instance()->cleanUpEmpty(); | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 	MainWindow::instance()->refreshDisplay(); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (prefs.display_invalid_dives == false) { | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | 		clearSelection(); | 
					
						
							|  |  |  | 		// select top dive that isn't marked invalid
 | 
					
						
							|  |  |  | 		rememberSelection(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fixMessyQtModelBehaviour(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-06 10:37:18 +09:00
										 |  |  | void DiveListView::deleteDive() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-11-15 14:11:55 +09:00
										 |  |  | 	if (!d) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2014-04-16 23:56:42 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	//TODO: port this to C-code.
 | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 	// after a dive is deleted the ones following it move forward in the dive_table
 | 
					
						
							|  |  |  | 	// so instead of using the for_each_dive macro I'm using an explicit for loop
 | 
					
						
							|  |  |  | 	// to make this easier to understand
 | 
					
						
							| 
									
										
										
										
											2013-11-16 18:52:14 -02:00
										 |  |  | 	int lastDiveNr = -1; | 
					
						
							| 
									
										
										
										
											2014-05-20 06:37:19 +09:00
										 |  |  | 	for_each_dive (i, d) { | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 		if (!d->selected) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		delete_single_dive(i); | 
					
						
							|  |  |  | 		i--; // so the next dive isn't skipped... it's now #i
 | 
					
						
							| 
									
										
										
										
											2013-11-16 18:52:14 -02:00
										 |  |  | 		lastDiveNr = i; | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-15 14:11:55 +09:00
										 |  |  | 	if (amount_selected == 0) { | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 		MainWindow::instance()->cleanUpEmpty(); | 
					
						
							| 
									
										
										
										
											2013-11-15 14:11:55 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-15 09:30:42 +01:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-02-12 15:22:54 +01:00
										 |  |  | 	MainWindow::instance()->refreshDisplay(); | 
					
						
							| 
									
										
										
										
											2014-01-16 11:50:56 +07:00
										 |  |  | 	if (lastDiveNr != -1) { | 
					
						
							| 
									
										
										
										
											2013-11-16 18:52:14 -02:00
										 |  |  | 		clearSelection(); | 
					
						
							|  |  |  | 		selectDive(lastDiveNr); | 
					
						
							|  |  |  | 		rememberSelection(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-17 15:36:57 -08:00
										 |  |  | 	fixMessyQtModelBehaviour(); | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveListView::testSlot() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | 	if (d) { | 
					
						
							|  |  |  | 		qDebug("testSlot called on dive #%d", d->number); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		QModelIndex child = contextMenuIndex.child(0, 0); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 		d = (struct dive *)child.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | 		if (d) | 
					
						
							|  |  |  | 			qDebug("testSlot called on trip including dive #%d", d->number); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			qDebug("testSlot called on trip with no dive"); | 
					
						
							| 
									
										
										
										
											2013-06-06 03:29:11 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveListView::contextMenuEvent(QContextMenuEvent *event) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QAction *collapseAction = NULL; | 
					
						
							|  |  |  | 	// let's remember where we are
 | 
					
						
							|  |  |  | 	contextMenuIndex = indexAt(event->pos()); | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); | 
					
						
							|  |  |  | 	dive_trip_t *trip = (dive_trip_t *)contextMenuIndex.data(DiveTripModel::TRIP_ROLE).value<void *>(); | 
					
						
							| 
									
										
										
										
											2013-06-06 03:29:11 +09:00
										 |  |  | 	QMenu popup(this); | 
					
						
							| 
									
										
										
										
											2013-06-06 06:51:15 +09:00
										 |  |  | 	if (currentLayout == DiveTripModel::TREE) { | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 		popup.addAction(tr("Expand all"), this, SLOT(expandAll())); | 
					
						
							|  |  |  | 		popup.addAction(tr("Collapse all"), this, SLOT(collapseAll())); | 
					
						
							|  |  |  | 		collapseAction = popup.addAction(tr("Collapse others"), this, SLOT(collapseAll())); | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | 		if (d) { | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 			popup.addAction(tr("Remove dive(s) from trip"), this, SLOT(removeFromTrip())); | 
					
						
							|  |  |  | 			popup.addAction(tr("Create new trip above"), this, SLOT(newTripAbove())); | 
					
						
							| 
									
										
										
										
											2014-05-24 08:27:42 -07:00
										 |  |  | 			if (!d->divetrip) { | 
					
						
							| 
									
										
										
										
											2014-05-24 10:28:11 -07:00
										 |  |  | 				struct dive *top = d; | 
					
						
							|  |  |  | 				struct dive *bottom = d; | 
					
						
							|  |  |  | 				if (d->selected) { | 
					
						
							|  |  |  | 					if (currentOrder == Qt::AscendingOrder) { | 
					
						
							|  |  |  | 						top = first_selected_dive(); | 
					
						
							|  |  |  | 						bottom = last_selected_dive(); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						top = last_selected_dive(); | 
					
						
							|  |  |  | 						bottom = first_selected_dive(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (is_trip_before_after(top, (currentOrder == Qt::AscendingOrder))) | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 					popup.addAction(tr("Add dive(s) to trip immediately above"), this, SLOT(addToTripAbove())); | 
					
						
							| 
									
										
										
										
											2014-05-24 10:28:11 -07:00
										 |  |  | 				if (is_trip_before_after(bottom, (currentOrder == Qt::DescendingOrder))) | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 					popup.addAction(tr("Add dive(s) to trip immediately below"), this, SLOT(addToTripBelow())); | 
					
						
							| 
									
										
										
										
											2014-05-24 08:27:42 -07:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-26 19:16:40 -10:00
										 |  |  | 		if (trip) { | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 			popup.addAction(tr("Merge trip with trip above"), this, SLOT(mergeTripAbove())); | 
					
						
							|  |  |  | 			popup.addAction(tr("Merge trip with trip below"), this, SLOT(mergeTripBelow())); | 
					
						
							| 
									
										
										
										
											2013-06-26 19:16:40 -10:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-06-06 06:51:15 +09:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | 	if (d) { | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 		popup.addAction(tr("Delete dive(s)"), this, SLOT(deleteDive())); | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 		popup.addAction(tr("Mark dive(s) invalid", this, SLOT(markDiveInvalid()))); | 
					
						
							| 
									
										
										
										
											2013-12-06 17:40:59 -08:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-24 03:42:40 -07:00
										 |  |  | 	if (amount_selected > 1 && consecutive_selected()) | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 		popup.addAction(tr("Merge selected dives"), this, SLOT(mergeDives())); | 
					
						
							| 
									
										
										
										
											2013-10-19 20:35:36 +03:00
										 |  |  | 	if (amount_selected >= 1) { | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 		popup.addAction(tr("Renumber dive(s)"), this, SLOT(renumberDives())); | 
					
						
							|  |  |  | 		popup.addAction(tr("Shift times"), this, SLOT(shiftTimes())); | 
					
						
							|  |  |  | 		popup.addAction(tr("Load images"), this, SLOT(loadImages())); | 
					
						
							| 
									
										
										
										
											2013-10-19 20:35:36 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-06-06 06:39:54 +09:00
										 |  |  | 	// "collapse all" really closes all trips,
 | 
					
						
							| 
									
										
										
										
											2013-06-06 06:51:15 +09:00
										 |  |  | 	// "collapse" keeps the trip with the selected dive open
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | 	QAction *actionTaken = popup.exec(event->globalPos()); | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | 	if (actionTaken == collapseAction && collapseAction) { | 
					
						
							|  |  |  | 		this->setAnimated(false); | 
					
						
							| 
									
										
										
										
											2013-11-16 18:41:47 -02:00
										 |  |  | 		selectDive(selected_dive, true); | 
					
						
							| 
									
										
										
										
											2013-11-15 10:51:39 -02:00
										 |  |  | 		scrollTo(selectedIndexes().first()); | 
					
						
							| 
									
										
										
										
											2013-06-06 09:06:42 +09:00
										 |  |  | 		this->setAnimated(true); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	event->accept(); | 
					
						
							| 
									
										
										
										
											2013-06-06 03:29:11 +09:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-10-17 21:50:08 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-18 14:53:05 +01:00
										 |  |  | void DiveListView::shiftTimes() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShiftTimesDialog::instance()->show(); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-12-05 18:28:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | void DiveListView::loadImages() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-11 09:21:36 +01:00
										 |  |  | 	QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open image files"), lastUsedImageDir(), tr("Image files (*.jpg *.jpeg *.pnm *.tif *.tiff)")); | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 	if (fileNames.isEmpty()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	updateLastUsedImageDir(QFileInfo(fileNames[0]).dir().path()); | 
					
						
							| 
									
										
										
										
											2014-02-08 23:56:47 +01:00
										 |  |  | 	ShiftImageTimesDialog shiftDialog(this); | 
					
						
							| 
									
										
										
										
											2014-02-12 16:46:17 +01:00
										 |  |  | 	shiftDialog.setOffset(lastImageTimeOffset()); | 
					
						
							| 
									
										
										
										
											2014-02-08 23:56:47 +01:00
										 |  |  | 	shiftDialog.exec(); | 
					
						
							| 
									
										
										
										
											2014-02-12 16:46:17 +01:00
										 |  |  | 	updateLastImageTimeOffset(shiftDialog.amount()); | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-17 15:39:49 -07:00
										 |  |  | 	Q_FOREACH (const QString &fileName, fileNames) { | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 		int j = 0; | 
					
						
							|  |  |  | 		struct dive *dive; | 
					
						
							| 
									
										
										
										
											2014-05-22 11:40:22 -07:00
										 |  |  | 		for_each_dive (j, dive) { | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 			if (!dive->selected) | 
					
						
							|  |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2014-06-03 14:51:47 -03:00
										 |  |  | 			dive_create_picture(dive, qstrdup(fileName.toUtf8().data()), shiftDialog.amount()); | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-02 18:28:02 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-30 13:46:26 -03:00
										 |  |  | 	mark_divelist_changed(true); | 
					
						
							| 
									
										
										
										
											2014-08-04 14:06:58 -03:00
										 |  |  | 	copy_dive(current_dive, &displayed_dive); | 
					
						
							|  |  |  | 	DivePictureModel::instance()->updateDivePictures(); | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString DiveListView::lastUsedImageDir() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QSettings settings; | 
					
						
							|  |  |  | 	QString lastImageDir = QDir::homePath(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	settings.beginGroup("FileDialog"); | 
					
						
							|  |  |  | 	if (settings.contains("LastImageDir")) | 
					
						
							|  |  |  | 		if (QDir::setCurrent(settings.value("LastImageDir").toString())) | 
					
						
							|  |  |  | 			lastImageDir = settings.value("LastIamgeDir").toString(); | 
					
						
							|  |  |  | 	return lastImageDir; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-27 20:09:57 -08:00
										 |  |  | void DiveListView::updateLastUsedImageDir(const QString &dir) | 
					
						
							| 
									
										
										
										
											2014-01-27 14:44:26 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 	s.beginGroup("FileDialog"); | 
					
						
							|  |  |  | 	s.setValue("LastImageDir", dir); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-12 16:46:17 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | int DiveListView::lastImageTimeOffset() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QSettings settings; | 
					
						
							|  |  |  | 	int offset = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	settings.beginGroup("MainWindow"); | 
					
						
							|  |  |  | 	if (settings.contains("LastImageTimeOffset")) | 
					
						
							|  |  |  | 		offset = settings.value("LastImageTimeOffset").toInt(); | 
					
						
							|  |  |  | 	return offset; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiveListView::updateLastImageTimeOffset(const int offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QSettings s; | 
					
						
							|  |  |  | 	s.beginGroup("MainWindow"); | 
					
						
							|  |  |  | 	s.setValue("LastImageTimeOffset", offset); | 
					
						
							|  |  |  | } |