mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
Reimplement the Sort method to change from Tree / List, and remember selection.
Things are working as they should, but I hit on -probably- a Qt bug that makes painting on the table view a bit weird ( it only updates the painting by moving the mouse around ). I'll try to fake the mouse movements in a couple of commits after this one. There's also a few columns that are not being correctly sorted, probably something to do with the SortRole. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
bb77f5a44e
commit
f46a2d56bc
1 changed files with 10 additions and 18 deletions
|
@ -29,32 +29,24 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
|
|||
|
||||
void DiveListView::headerClicked(int i )
|
||||
{
|
||||
QModelIndexList oldSelection = selectionModel()->selectedRows();
|
||||
QItemSelection oldSelection = selectionModel()->selection();
|
||||
QList<struct dive*> currentSelectedDives;
|
||||
Q_FOREACH(const QModelIndex& index , oldSelection){
|
||||
Q_FOREACH(const QModelIndex& index , oldSelection.indexes()){
|
||||
struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>();
|
||||
if (d){
|
||||
if (d){ // can also be a trip, so test.
|
||||
currentSelectedDives.push_back(d);
|
||||
}
|
||||
}
|
||||
|
||||
if (i == (int) TreeItemDT::NR){
|
||||
reload(DiveTripModel::TREE);
|
||||
}else{
|
||||
reload(DiveTripModel::LIST);
|
||||
}
|
||||
|
||||
QModelIndexList newSelection;
|
||||
QItemSelection newSelection2;
|
||||
reload( i == (int) TreeItemDT::NR ? DiveTripModel::TREE : DiveTripModel::LIST);
|
||||
|
||||
selectionModel()->clearSelection();
|
||||
Q_FOREACH(struct dive *d, currentSelectedDives){
|
||||
QModelIndexList match = model()->match(model()->index(0,0), TreeItemDT::DIVE_ROLE, QVariant::fromValue<void*>(d), 1, Qt::MatchRecursive);
|
||||
if (match.count() == 0){
|
||||
qDebug() << "Well, this shouldn't happen.";
|
||||
}else{
|
||||
newSelection << match.first();
|
||||
}
|
||||
selectionModel()->select(match.first(), QItemSelectionModel::Select | QItemSelectionModel::Rows);
|
||||
}
|
||||
|
||||
sortByColumn(i);
|
||||
}
|
||||
|
||||
void DiveListView::reload(DiveTripModel::Layout layout)
|
||||
|
@ -122,8 +114,8 @@ void DiveListView::toggleColumnVisibilityByIndex()
|
|||
|
||||
void DiveListView::setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command)
|
||||
{
|
||||
if (mouseClickSelection)
|
||||
QTreeView::setSelection(rect, command);
|
||||
//if (mouseClickSelection)
|
||||
QTreeView::setSelection(rect, command);
|
||||
}
|
||||
|
||||
void DiveListView::mousePressEvent(QMouseEvent* event)
|
||||
|
|
Loading…
Reference in a new issue