mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Fixed the regression of selection not being stored from table to tree
This fixes the regression that I caused in the last commit, where the selection was being correctly reestored from tree-to-table, but it was incorrectly being restored from table-to-tree. I also added a bit of speedup on the view while changing columns. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
9cc04c1ca6
commit
16d0a47853
2 changed files with 24 additions and 5 deletions
|
@ -16,7 +16,7 @@
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
|
|
||||||
|
|
||||||
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false)
|
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false), currentHeaderClicked(-1)
|
||||||
{
|
{
|
||||||
setUniformRowHeights(true);
|
setUniformRowHeights(true);
|
||||||
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
|
setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate());
|
||||||
|
@ -29,6 +29,16 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
||||||
|
|
||||||
void DiveListView::headerClicked(int i )
|
void DiveListView::headerClicked(int i )
|
||||||
{
|
{
|
||||||
|
if (currentHeaderClicked == i){
|
||||||
|
sortByColumn(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentLayout == (i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST)){
|
||||||
|
sortByColumn(i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QItemSelection oldSelection = selectionModel()->selection();
|
QItemSelection oldSelection = selectionModel()->selection();
|
||||||
QList<struct dive*> currentSelectedDives;
|
QList<struct dive*> currentSelectedDives;
|
||||||
Q_FOREACH(const QModelIndex& index , oldSelection.indexes()){
|
Q_FOREACH(const QModelIndex& index , oldSelection.indexes()){
|
||||||
|
@ -44,20 +54,27 @@ void DiveListView::headerClicked(int i )
|
||||||
// clear the model, repopulate with new indexes.
|
// clear the model, repopulate with new indexes.
|
||||||
reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST, false);
|
reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST, false);
|
||||||
selectionModel()->clearSelection();
|
selectionModel()->clearSelection();
|
||||||
|
sortByColumn(i, Qt::DescendingOrder);
|
||||||
|
|
||||||
|
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
|
||||||
|
|
||||||
// repopulat the selections.
|
// repopulat the selections.
|
||||||
Q_FOREACH(struct dive *d, currentSelectedDives){
|
Q_FOREACH(struct dive *d, currentSelectedDives){
|
||||||
QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::NR, d->number, 1, Qt::MatchRecursive);
|
QModelIndexList match = m->match(m->index(0,0), TreeItemDT::NR, d->number, 1, Qt::MatchRecursive);
|
||||||
QModelIndex idx = match.first();
|
QModelIndex idx = match.first();
|
||||||
|
if (i == (int) TreeItemDT::NR && idx.parent().isValid() ){ // Tree Mode Activated.
|
||||||
|
QModelIndex parent = idx.parent();
|
||||||
|
expand(parent);
|
||||||
|
}
|
||||||
selectionModel()->select( idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
selectionModel()->select( idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||||
}
|
}
|
||||||
|
|
||||||
// sort.
|
|
||||||
sortByColumn(i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
void DiveListView::reload(DiveTripModel::Layout layout, bool forceSort)
|
||||||
{
|
{
|
||||||
|
DiveTripModel::Layout oldLayout = currentLayout;
|
||||||
|
currentLayout = layout;
|
||||||
|
|
||||||
header()->setClickable(true);
|
header()->setClickable(true);
|
||||||
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
|
connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,8 @@ Q_SIGNALS:
|
||||||
void currentDiveChanged(int divenr);
|
void currentDiveChanged(int divenr);
|
||||||
private:
|
private:
|
||||||
bool mouseClickSelection;
|
bool mouseClickSelection;
|
||||||
|
int currentHeaderClicked;
|
||||||
|
DiveTripModel::Layout currentLayout;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DIVELISTVIEW_H
|
#endif // DIVELISTVIEW_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue