mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-12 13:06:16 +00:00
Fix wrong handling of Dive Table, and revert some wrong changes.
This patch just reverts some wrong changes that I'v done on a past commit ( sorry ) and correctly handles the selectDive, by using a IDX instead of the dive pointer, as dirk told me it's extremely error-prone since the pointer can change. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
c1a05fd034
commit
4f9526ef81
6 changed files with 32 additions and 74 deletions
|
@ -110,8 +110,10 @@ void DiveListView::backupExpandedRows(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::restoreExpandedRows(){
|
void DiveListView::restoreExpandedRows(){
|
||||||
|
setAnimated(false);
|
||||||
Q_FOREACH(const int &i, expandedRows)
|
Q_FOREACH(const int &i, expandedRows)
|
||||||
setExpanded( model()->index(i, 0), true );
|
setExpanded( model()->index(i, 0), true );
|
||||||
|
setAnimated(true);
|
||||||
}
|
}
|
||||||
void DiveListView::fixMessyQtModelBehaviour()
|
void DiveListView::fixMessyQtModelBehaviour()
|
||||||
{
|
{
|
||||||
|
@ -139,9 +141,7 @@ void DiveListView::restoreSelection()
|
||||||
{
|
{
|
||||||
unselectDives();
|
unselectDives();
|
||||||
Q_FOREACH(int i, selectedDives) {
|
Q_FOREACH(int i, selectedDives) {
|
||||||
struct dive *d = get_dive(i);
|
selectDive(i);
|
||||||
if (d)
|
|
||||||
selectDive(d);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,25 +150,18 @@ void DiveListView::unselectDives()
|
||||||
selectionModel()->clearSelection();
|
selectionModel()->clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::selectDive(struct dive *dive, bool scrollto, bool toggle)
|
void DiveListView::selectDive(int i, bool scrollto, bool toggle)
|
||||||
{
|
{
|
||||||
if (dive == NULL)
|
|
||||||
return;
|
|
||||||
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||||
QModelIndexList match = m->match(m->index(0,0), DiveTripModel::NR, dive->number, 1, Qt::MatchRecursive);
|
QModelIndexList match = m->match(m->index(0,0), DiveTripModel::DIVE_IDX, i, 2, Qt::MatchRecursive);
|
||||||
QItemSelectionModel::SelectionFlags flags;
|
QItemSelectionModel::SelectionFlags flags;
|
||||||
QModelIndex idx = match.first();
|
QModelIndex idx = match.first();
|
||||||
|
|
||||||
QModelIndex parent = idx.parent();
|
|
||||||
if (parent.isValid())
|
|
||||||
expand(parent);
|
|
||||||
flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select;
|
flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select;
|
||||||
flags |= QItemSelectionModel::Rows;
|
flags |= QItemSelectionModel::Rows;
|
||||||
selectionModel()->select(idx, flags);
|
selectionModel()->select(idx, flags);
|
||||||
if (scrollto)
|
if (scrollto)
|
||||||
scrollTo(idx, PositionAtCenter);
|
scrollTo(idx, PositionAtCenter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::showSearchEdit()
|
void DiveListView::showSearchEdit()
|
||||||
{
|
{
|
||||||
searchBox->show();
|
searchBox->show();
|
||||||
|
@ -196,25 +189,9 @@ bool DiveListView::eventFilter(QObject* , QEvent* event)
|
||||||
// index. TRIP_ROLE vs DIVE_ROLE?
|
// index. TRIP_ROLE vs DIVE_ROLE?
|
||||||
void DiveListView::headerClicked(int i)
|
void DiveListView::headerClicked(int i)
|
||||||
{
|
{
|
||||||
sortColumn = i;
|
DiveTripModel::Layout newLayout = i == (int) DiveTripModel::NR ? DiveTripModel::TREE : DiveTripModel::LIST;
|
||||||
QItemSelection oldSelection = selectionModel()->selection();
|
rememberSelection();
|
||||||
QList<struct dive*> currentSelectedDives;
|
|
||||||
DiveTripModel::Layout newLayout;
|
|
||||||
bool first = true;
|
|
||||||
|
|
||||||
newLayout = i == (int) DiveTripModel::NR ? DiveTripModel::TREE : DiveTripModel::LIST;
|
|
||||||
|
|
||||||
Q_FOREACH(const QModelIndex& index , oldSelection.indexes()) {
|
|
||||||
if (index.column() != 0) // We only care about the dives, so, let's stick to rows and discard columns.
|
|
||||||
continue;
|
|
||||||
|
|
||||||
struct dive *d = (struct dive *) index.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
|
||||||
if (d)
|
|
||||||
currentSelectedDives.push_back(d);
|
|
||||||
}
|
|
||||||
|
|
||||||
unselectDives();
|
unselectDives();
|
||||||
|
|
||||||
/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */
|
/* No layout change? Just re-sort, and scroll to first selection, making sure all selections are expanded */
|
||||||
if (currentLayout == newLayout) {
|
if (currentLayout == newLayout) {
|
||||||
currentOrder = (currentOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder;
|
currentOrder = (currentOrder == Qt::DescendingOrder) ? Qt::AscendingOrder : Qt::DescendingOrder;
|
||||||
|
@ -231,12 +208,7 @@ void DiveListView::headerClicked(int i)
|
||||||
restoreExpandedRows();
|
restoreExpandedRows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
restoreSelection();
|
||||||
// repopulate the selections.
|
|
||||||
Q_FOREACH(struct dive *d, currentSelectedDives) {
|
|
||||||
selectDive(d, first);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
||||||
|
@ -263,7 +235,7 @@ void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
||||||
|
|
||||||
sortByColumn(sortColumn, currentOrder);
|
sortByColumn(sortColumn, currentOrder);
|
||||||
if (amount_selected && current_dive != NULL) {
|
if (amount_selected && current_dive != NULL) {
|
||||||
selectDive(current_dive, true);
|
selectDive(selected_dive, true);
|
||||||
} else {
|
} else {
|
||||||
QModelIndex firstDiveOrTrip = m->index(0,0);
|
QModelIndex firstDiveOrTrip = m->index(0,0);
|
||||||
if (firstDiveOrTrip.isValid()) {
|
if (firstDiveOrTrip.isValid()) {
|
||||||
|
@ -495,23 +467,25 @@ void DiveListView::deleteDive()
|
||||||
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
struct dive *d = (struct dive *) contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void*>();
|
||||||
if (!d)
|
if (!d)
|
||||||
return;
|
return;
|
||||||
|
// after a dive is deleted the ones following it move forward in the dive_table
|
||||||
QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(model());
|
// so instead of using the for_each_dive macro I'm using an explicit for loop
|
||||||
DiveTripModel *realModel = qobject_cast<DiveTripModel*>(proxy->sourceModel());
|
// to make this easier to understand
|
||||||
realModel->deleteSelectedDives();
|
for (i = 0; i < dive_table.nr; i++) {
|
||||||
|
d = get_dive(i);
|
||||||
struct dive* next_dive = 0;
|
if (!d->selected)
|
||||||
if (amount_selected == 0) {
|
continue;
|
||||||
if (i > 0){
|
delete_single_dive(i);
|
||||||
next_dive = get_dive(nr -1);
|
i--; // so the next dive isn't skipped... it's now #i
|
||||||
}
|
}
|
||||||
else{
|
if (amount_selected == 0) {
|
||||||
|
if (i > 0)
|
||||||
|
select_dive(nr - 1);
|
||||||
|
else
|
||||||
mainWindow()->cleanUpEmpty();
|
mainWindow()->cleanUpEmpty();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
mark_divelist_changed(TRUE);
|
mark_divelist_changed(TRUE);
|
||||||
if (next_dive)
|
mainWindow()->refreshDisplay();
|
||||||
selectDive(next_dive);
|
reload(currentLayout, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::testSlot()
|
void DiveListView::testSlot()
|
||||||
|
@ -563,7 +537,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
|
||||||
QAction * actionTaken = popup.exec(event->globalPos());
|
QAction * actionTaken = popup.exec(event->globalPos());
|
||||||
if (actionTaken == collapseAction && collapseAction) {
|
if (actionTaken == collapseAction && collapseAction) {
|
||||||
this->setAnimated(false);
|
this->setAnimated(false);
|
||||||
selectDive(current_dive, true);
|
selectDive(selected_dive, true);
|
||||||
scrollTo(selectedIndexes().first());
|
scrollTo(selectedIndexes().first());
|
||||||
this->setAnimated(true);
|
this->setAnimated(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
void reload(DiveTripModel::Layout layout, bool forceSort = true);
|
void reload(DiveTripModel::Layout layout, bool forceSort = true);
|
||||||
bool eventFilter(QObject* , QEvent* );
|
bool eventFilter(QObject* , QEvent* );
|
||||||
void unselectDives();
|
void unselectDives();
|
||||||
void selectDive(struct dive *, bool scrollto = false, bool toggle = false);
|
void selectDive(int dive_table_idx, bool scrollto = false, bool toggle = false);
|
||||||
void rememberSelection();
|
void rememberSelection();
|
||||||
void restoreSelection();
|
void restoreSelection();
|
||||||
void contextMenuEvent(QContextMenuEvent *event);
|
void contextMenuEvent(QContextMenuEvent *event);
|
||||||
|
|
|
@ -115,7 +115,7 @@ void GlobeGPS::mouseClicked(qreal lon, qreal lat, GeoDataCoordinates::Unit unit)
|
||||||
mainWindow()->dive_list()->unselectDives();
|
mainWindow()->dive_list()->unselectDives();
|
||||||
clear = false;
|
clear = false;
|
||||||
}
|
}
|
||||||
mainWindow()->dive_list()->selectDive(dive, first, toggle);
|
mainWindow()->dive_list()->selectDive(idx, first, toggle);
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,7 +511,7 @@ void MainTab::acceptChanges()
|
||||||
// unselectDives() doesn't mess with the dive_table at all
|
// unselectDives() doesn't mess with the dive_table at all
|
||||||
struct dive *addedDive = current_dive;
|
struct dive *addedDive = current_dive;
|
||||||
mainWindow()->dive_list()->unselectDives();
|
mainWindow()->dive_list()->unselectDives();
|
||||||
mainWindow()->dive_list()->selectDive(addedDive, true, true);
|
mainWindow()->dive_list()->selectDive(selected_dive, true, true);
|
||||||
mainWindow()->showProfile();
|
mainWindow()->showProfile();
|
||||||
mark_divelist_changed(TRUE);
|
mark_divelist_changed(TRUE);
|
||||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::NOTHING);
|
||||||
|
|
|
@ -989,6 +989,9 @@ QVariant DiveItem::data(int column, int role) const
|
||||||
if (role == DiveTripModel::DIVE_ROLE)
|
if (role == DiveTripModel::DIVE_ROLE)
|
||||||
retVal = QVariant::fromValue<void*>(dive);
|
retVal = QVariant::fromValue<void*>(dive);
|
||||||
|
|
||||||
|
if(role == DiveTripModel::DIVE_IDX){
|
||||||
|
retVal = get_divenr(dive);
|
||||||
|
}
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1198,23 +1201,6 @@ QVariant DiveComputerModel::data(const QModelIndex& index, int role) const
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveTripModel::deleteSelectedDives()
|
|
||||||
{
|
|
||||||
// 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
|
|
||||||
beginRemoveRows(index(0,0), 0, rowCount()-1);
|
|
||||||
for (int i = 0; i < dive_table.nr; i++) {
|
|
||||||
struct dive *d = get_dive(i);
|
|
||||||
if (!d->selected)
|
|
||||||
continue;
|
|
||||||
delete_single_dive(i);
|
|
||||||
i--; // so the next dive isn't skipped... it's now #i
|
|
||||||
}
|
|
||||||
endRemoveRows();
|
|
||||||
setupModelData();
|
|
||||||
}
|
|
||||||
|
|
||||||
int DiveComputerModel::rowCount(const QModelIndex& parent) const
|
int DiveComputerModel::rowCount(const QModelIndex& parent) const
|
||||||
{
|
{
|
||||||
return numRows;
|
return numRows;
|
||||||
|
|
|
@ -192,7 +192,7 @@ public:
|
||||||
enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT,
|
enum Column {NR, DATE, RATING, DEPTH, DURATION, TEMPERATURE, TOTALWEIGHT,
|
||||||
SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS };
|
SUIT, CYLINDER, NITROX, SAC, OTU, MAXCNS, LOCATION, COLUMNS };
|
||||||
|
|
||||||
enum ExtraRoles{STAR_ROLE = Qt::UserRole + 1, DIVE_ROLE, TRIP_ROLE, SORT_ROLE};
|
enum ExtraRoles{STAR_ROLE = Qt::UserRole + 1, DIVE_ROLE, TRIP_ROLE, SORT_ROLE, DIVE_IDX};
|
||||||
enum Layout{TREE, LIST, CURRENT};
|
enum Layout{TREE, LIST, CURRENT};
|
||||||
|
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||||
|
@ -200,8 +200,6 @@ public:
|
||||||
DiveTripModel(QObject* parent = 0);
|
DiveTripModel(QObject* parent = 0);
|
||||||
Layout layout() const;
|
Layout layout() const;
|
||||||
void setLayout(Layout layout);
|
void setLayout(Layout layout);
|
||||||
void deleteSelectedDives();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setupModelData();
|
void setupModelData();
|
||||||
QMap<dive_trip_t*, TripItem*> trips;
|
QMap<dive_trip_t*, TripItem*> trips;
|
||||||
|
|
Loading…
Add table
Reference in a new issue