2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-14 03:44:02 +00:00
|
|
|
/*
|
|
|
|
* divelistview.h
|
|
|
|
*
|
|
|
|
* header file for the dive list of Subsurface
|
|
|
|
*
|
|
|
|
*/
|
2013-04-12 07:24:07 +00:00
|
|
|
#ifndef DIVELISTVIEW_H
|
|
|
|
#define DIVELISTVIEW_H
|
|
|
|
|
|
|
|
/*! A view subclass for use with dives
|
|
|
|
Note: calling this a list view might be misleading?
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QTreeView>
|
2014-02-09 17:18:54 +00:00
|
|
|
#include <QLineEdit>
|
2015-04-24 15:10:55 +00:00
|
|
|
#include <QNetworkAccessManager>
|
2016-04-05 05:02:03 +00:00
|
|
|
#include "qt-models/divetripmodel.h"
|
2013-04-12 07:24:07 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class DiveListView : public QTreeView {
|
2013-05-14 11:18:26 +00:00
|
|
|
Q_OBJECT
|
2013-04-12 07:24:07 +00:00
|
|
|
public:
|
|
|
|
DiveListView(QWidget *parent = 0);
|
2013-11-08 22:30:17 +00:00
|
|
|
~DiveListView();
|
2017-01-28 11:16:45 +00:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent * event);
|
2014-02-28 04:09:57 +00:00
|
|
|
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
|
|
|
void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
2018-11-04 16:54:38 +00:00
|
|
|
void setSortOrder(int i, Qt::SortOrder order); // Call to set sort order
|
|
|
|
void reload(); // Call to reload model data
|
2014-02-28 04:09:57 +00:00
|
|
|
bool eventFilter(QObject *, QEvent *);
|
2013-06-05 06:41:52 +00:00
|
|
|
void unselectDives();
|
2014-11-04 01:52:04 +00:00
|
|
|
void clearTripSelection();
|
2018-10-20 09:56:06 +00:00
|
|
|
void selectDive(QModelIndex index, bool scrollto = false, bool toggle = false);
|
2013-11-16 20:41:47 +00:00
|
|
|
void selectDive(int dive_table_idx, bool scrollto = false, bool toggle = false);
|
2014-02-28 04:09:57 +00:00
|
|
|
void selectDives(const QList<int> &newDiveSelection);
|
2018-10-20 09:56:06 +00:00
|
|
|
void selectFirstDive();
|
|
|
|
QModelIndex indexOfFirstDive();
|
2013-11-14 08:52:03 +00:00
|
|
|
void rememberSelection();
|
|
|
|
void restoreSelection();
|
2013-06-06 00:06:42 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent *event);
|
2014-02-28 04:09:57 +00:00
|
|
|
QList<dive_trip_t *> selectedTrips();
|
2018-06-09 14:24:39 +00:00
|
|
|
static QString lastUsedImageDir();
|
2018-06-10 14:40:23 +00:00
|
|
|
static void updateLastUsedImageDir(const QString &s);
|
2014-02-28 04:09:57 +00:00
|
|
|
public
|
|
|
|
slots:
|
2013-05-26 17:12:45 +00:00
|
|
|
void toggleColumnVisibilityByIndex();
|
|
|
|
void reloadHeaderActions();
|
2018-11-04 16:54:38 +00:00
|
|
|
void sortIndicatorChanged(int index, Qt::SortOrder order);
|
2013-06-06 00:06:42 +00:00
|
|
|
void removeFromTrip();
|
2013-06-06 01:37:18 +00:00
|
|
|
void deleteDive();
|
2013-12-07 01:40:59 +00:00
|
|
|
void markDiveInvalid();
|
2018-09-29 20:13:44 +00:00
|
|
|
void rowsInserted(const QModelIndex &parent, int start, int end) override;
|
|
|
|
void reset() override;
|
2013-06-27 05:16:40 +00:00
|
|
|
void mergeTripAbove();
|
|
|
|
void mergeTripBelow();
|
2013-11-15 02:32:19 +00:00
|
|
|
void newTripAbove();
|
2013-11-17 23:36:57 +00:00
|
|
|
void addToTripAbove();
|
2014-03-20 06:42:20 +00:00
|
|
|
void addToTripBelow();
|
2013-09-24 04:57:28 +00:00
|
|
|
void mergeDives();
|
2015-10-02 01:17:37 +00:00
|
|
|
void splitDives();
|
2014-05-19 21:11:32 +00:00
|
|
|
void renumberDives();
|
2013-11-18 13:53:05 +00:00
|
|
|
void shiftTimes();
|
2014-01-27 13:44:26 +00:00
|
|
|
void loadImages();
|
2015-04-24 15:10:55 +00:00
|
|
|
void loadWebImages();
|
Undo: select dives after add, remove, merge, split dive commands
Select the proper dives after the add, remove, split and merge
dives commands on undo *and* redo. Generally, select the added
dives. For undo of add, remember the pre-addition selection.
For redo of remove, select the closest dive to the first removed
dive.
The biggest part of the commit is the signal-interface between
the dive commands and the dive-list model and dive-list view.
This is done in two steps:
1) To the DiveTripModel in batches of trips. The dive trip model
transforms the dives into indices.
2) To the DiveListView. The DiveListView has to translate the
DiveTripModel indexes to actual indexes via its QSortFilterProxy-
model.
For code-reuse, derive all divelist-changing commands from a new base-class,
which has a flag that describes whether the divelist changed. The helper
functions which add and remove dives are made members of the base class and
set the flag is a selected dive is added or removed.
To properly detect when the current dive was deleted it
became necessary to turn the current dive from an index
to a pointer, because indices are not stable.
Unfortunately, in some cases an index was expected and these
places now have to transform the dive into an index. These
should be converted in due course.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-03 09:35:43 +00:00
|
|
|
void diveSelectionChanged(const QVector<QModelIndex> &indexes, bool select);
|
2018-08-14 13:12:21 +00:00
|
|
|
void currentDiveChanged(QModelIndex index);
|
2018-10-20 09:56:06 +00:00
|
|
|
void filterFinished();
|
2013-05-14 01:14:59 +00:00
|
|
|
private:
|
|
|
|
bool mouseClickSelection;
|
2013-11-08 23:08:14 +00:00
|
|
|
QList<int> expandedRows;
|
2018-12-27 09:06:11 +00:00
|
|
|
DiveTripModelBase::Layout currentLayout;
|
2013-06-06 00:06:42 +00:00
|
|
|
QModelIndex contextMenuIndex;
|
2014-05-25 04:03:18 +00:00
|
|
|
bool dontEmitDiveChangedSignal;
|
2014-05-28 22:03:10 +00:00
|
|
|
bool selectionSaved;
|
2018-07-25 18:40:47 +00:00
|
|
|
// Remember the initial column widths, to avoid writing unchanged widths to the settings
|
|
|
|
QVector<int> initialColumnWidths;
|
2013-11-26 17:44:18 +00:00
|
|
|
|
|
|
|
/* if dive_trip_t is null, there's no problem. */
|
|
|
|
QMultiHash<dive_trip_t *, int> selectedDives;
|
2018-12-27 09:06:11 +00:00
|
|
|
void resetModel(); // Call after model changed
|
2013-06-27 05:16:40 +00:00
|
|
|
void merge_trip(const QModelIndex &a, const int offset);
|
2018-07-26 16:03:07 +00:00
|
|
|
void setColumnWidths();
|
2018-07-25 19:23:19 +00:00
|
|
|
void calculateInitialColumnWidth(int col);
|
2013-11-08 23:08:14 +00:00
|
|
|
void backupExpandedRows();
|
|
|
|
void restoreExpandedRows();
|
2013-11-13 18:59:56 +00:00
|
|
|
int lastVisibleColumn();
|
2014-02-28 04:09:57 +00:00
|
|
|
void selectTrip(dive_trip_t *trip);
|
2014-02-12 15:46:17 +00:00
|
|
|
void updateLastImageTimeOffset(int offset);
|
|
|
|
int lastImageTimeOffset();
|
2014-08-21 19:20:03 +00:00
|
|
|
void addToTrip(int delta);
|
2015-04-24 15:10:55 +00:00
|
|
|
void matchImagesToDives(QStringList fileNames);
|
|
|
|
void loadImageFromURL(QUrl url);
|
|
|
|
QNetworkAccessManager manager;
|
2013-04-12 07:24:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DIVELISTVIEW_H
|