diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-29 19:55:24 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-29 19:55:24 +0900 |
commit | 8df20f414966db685e4709eb101e071b4783c09f (patch) | |
tree | e92d0772b2a393ae3ca73ebb47ac74e37adeb9d1 /qt-ui/divelistview.cpp | |
parent | 4371a4a29859c9419a646cb7ed1182c19f54d7ab (diff) | |
parent | 5a994b08f6323680fe8362f129f097c9c2aaef2e (diff) | |
download | subsurface-8df20f414966db685e4709eb101e071b4783c09f.tar.gz |
Merge branch 'bug111' of https://github.com/tcanabrava/subsurface
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r-- | qt-ui/divelistview.cpp | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp index 4957e3374..948bfa57a 100644 --- a/qt-ui/divelistview.cpp +++ b/qt-ui/divelistview.cpp @@ -22,16 +22,53 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec setItemDelegateForColumn(TreeItemDT::RATING, new StarWidgetsDelegate()); QSortFilterProxyModel *model = new QSortFilterProxyModel(this); setModel(model); + setSortingEnabled(false); header()->setContextMenuPolicy(Qt::ActionsContextMenu); } -void DiveListView::reload() +void DiveListView::headerClicked(int i ) { + QModelIndexList oldSelection = selectionModel()->selectedRows(); + QList<struct dive*> currentSelectedDives; + Q_FOREACH(const QModelIndex& index , oldSelection){ + struct dive *d = (struct dive *) index.data(TreeItemDT::DIVE_ROLE).value<void*>(); + if (d){ + currentSelectedDives.push_back(d); + } + } + + if (i == (int) TreeItemDT::NR){ + reload(DiveTripModel::TREE); + }else{ + reload(DiveTripModel::LIST); + } + + QModelIndexList newSelection; + QItemSelection newSelection2; + + 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(); + } + } +} + +void DiveListView::reload(DiveTripModel::Layout layout) +{ + header()->setClickable(true); + connect(header(), SIGNAL(sectionPressed(int)), this, SLOT(headerClicked(int)), Qt::UniqueConnection); + QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model()); QAbstractItemModel *oldModel = m->sourceModel(); if (oldModel) oldModel->deleteLater(); - m->setSourceModel(new DiveTripModel(this)); + DiveTripModel *tripModel = new DiveTripModel(this); + tripModel->setLayout(layout); + + m->setSourceModel(tripModel); sortByColumn(0, Qt::DescendingOrder); QModelIndex firstDiveOrTrip = m->index(0,0); if (firstDiveOrTrip.isValid()) { |