summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp60
1 files changed, 43 insertions, 17 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index cbd62408b..752e12242 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -28,6 +28,8 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
model->setSortRole(TreeItemDT::SORT_ROLE);
model->setFilterKeyColumn(-1); // filter all columns
setModel(model);
+ connect(model, SIGNAL(layoutChanged()), this, SLOT(fixMessyQtModelBehaviour()));
+
setSortingEnabled(false);
setContextMenuPolicy(Qt::DefaultContextMenu);
header()->setContextMenuPolicy(Qt::ActionsContextMenu);
@@ -40,6 +42,17 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelec
searchBox->hide();
connect(showSearchBox, SIGNAL(triggered(bool)), this, SLOT(showSearchEdit()));
connect(searchBox, SIGNAL(textChanged(QString)), model, SLOT(setFilterFixedString(QString)));
+ selectedTrips.clear();
+}
+
+void DiveListView::fixMessyQtModelBehaviour()
+{
+ QAbstractItemModel *m = model();
+ for(int i = 0; i < model()->rowCount(); i++){
+ if (m->rowCount( m->index(i, 0) ) != 0){
+ setFirstColumnSpanned(i, QModelIndex(), true);
+ }
+ }
}
void DiveListView::unselectDives()
@@ -47,16 +60,19 @@ void DiveListView::unselectDives()
selectionModel()->clearSelection();
}
-void DiveListView::selectDive(struct dive *dive, bool scrollto)
+void DiveListView::selectDive(struct dive *dive, bool scrollto, bool toggle)
{
QSortFilterProxyModel *m = qobject_cast<QSortFilterProxyModel*>(model());
QModelIndexList match = m->match(m->index(0,0), TreeItemDT::NR, dive->number, 1, Qt::MatchRecursive);
+ QItemSelectionModel::SelectionFlags flags;
QModelIndex idx = match.first();
QModelIndex parent = idx.parent();
if (parent.isValid())
expand(parent);
- selectionModel()->select( idx, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ flags = toggle ? QItemSelectionModel::Toggle : QItemSelectionModel::Select;
+ flags |= QItemSelectionModel::Rows;
+ selectionModel()->select( idx, flags);
if (scrollto)
scrollTo(idx, PositionAtCenter);
}
@@ -183,6 +199,12 @@ void DiveListView::reloadHeaderActions()
setColumnHidden(i, !shown);
}
s.endGroup();
+ } else {
+ // Skip first QAction item ( static text Visible )
+ for(int i = 0; i < model()->columnCount(); i++) {
+ QString title = QString("%1").arg(model()->headerData(i, Qt::Horizontal).toString());
+ header()->actions()[i+1]->setText( title );
+ }
}
}
@@ -224,48 +246,51 @@ void DiveListView::selectionChanged(const QItemSelection& selected, const QItemS
disconnect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
disconnect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
- Q_FOREACH(const QModelIndex& index, newSelected.indexes()) {
+ Q_FOREACH(const QModelIndex& index, newDeselected.indexes()) {
if (index.column() != 0)
continue;
-
const QAbstractItemModel *model = index.model();
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
if (!dive) { // it's a trip!
if (model->rowCount(index)) {
- QItemSelection selection;
struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>();
+ if (child && child->divetrip)
+ selectedTrips.remove(child->divetrip);
while (child) {
- select_dive(get_index_for_dive(child));
+ deselect_dive(get_index_for_dive(child));
child = child->next;
}
- selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0));
- selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
- selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
- if (!isExpanded(index))
- expand(index);
}
} else {
- select_dive(get_index_for_dive(dive));
+ deselect_dive(get_index_for_dive(dive));
}
}
- Q_FOREACH(const QModelIndex& index, newDeselected.indexes()) {
+ Q_FOREACH(const QModelIndex& index, newSelected.indexes()) {
if (index.column() != 0)
continue;
+
const QAbstractItemModel *model = index.model();
struct dive *dive = (struct dive*) model->data(index, TreeItemDT::DIVE_ROLE).value<void*>();
if (!dive) { // it's a trip!
if (model->rowCount(index)) {
+ QItemSelection selection;
struct dive *child = (struct dive*) model->data(index.child(0,0), TreeItemDT::DIVE_ROLE).value<void*>();
+ if (child && child->divetrip)
+ selectedTrips.insert(child->divetrip);
while (child) {
- deselect_dive(get_index_for_dive(child));
+ select_dive(get_index_for_dive(child));
child = child->next;
}
+ selection.select(index.child(0,0), index.child(model->rowCount(index) -1 , 0));
+ selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
+ selectionModel()->setCurrentIndex(index, QItemSelectionModel::Select | QItemSelectionModel::NoUpdate);
+ if (!isExpanded(index))
+ expand(index);
}
} else {
- deselect_dive(get_index_for_dive(dive));
+ select_dive(get_index_for_dive(dive));
}
}
-
QTreeView::selectionChanged(selectionModel()->selection(), newDeselected);
connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(selectionChanged(QItemSelection,QItemSelection)));
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(currentChanged(QModelIndex,QModelIndex)));
@@ -320,7 +345,8 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
popup.addAction(tr("remove dive from trip"), this, SLOT(removeFromTrip()));
}
}
- popup.addAction(tr("delete dive"), this, SLOT(deleteDive()));
+ if (d)
+ popup.addAction(tr("delete dive"), this, SLOT(deleteDive()));
// "collapse all" really closes all trips,
// "collapse" keeps the trip with the selected dive open
QAction * actionTaken = popup.exec(event->globalPos());