summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@gmail.com>2015-05-10 17:19:34 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-11 07:30:52 -0700
commit9523132b6da30231b3c56f3ee203a97b8a69c34f (patch)
tree57936db323caf6130d939a5b222a0443bf3bd565 /qt-ui/divelistview.cpp
parentd6f45ec74dc6c18824045fe364131833124d5d4e (diff)
downloadsubsurface-9523132b6da30231b3c56f3ee203a97b8a69c34f.tar.gz
Only show Collapse all when its needed
This makes Collapse All only visible when its needed, and it also fixes a crash when invocking collapse all when there was nothing to collapse. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index ae502eecc..0b79ef9fc 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -800,22 +800,29 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
// verify if there is a node that`s not expanded.
bool needs_expand = false;
bool needs_collapse = false;
+ uint expanded_nodes = 0;
for(int i = 0, end = model()->rowCount(); i < end; i++) {
QModelIndex idx = model()->index(i, 0);
if (idx.data(DiveTripModel::DIVE_ROLE).value<void *>())
continue;
- if (!isExpanded(idx))
+ if (!isExpanded(idx)) {
needs_expand = true;
- else
+ } else {
needs_collapse = true;
+ expanded_nodes ++;
+ }
}
if (needs_expand)
popup.addAction(tr("Expand all"), this, SLOT(expandAll()));
if (needs_collapse)
popup.addAction(tr("Collapse all"), this, SLOT(collapseAll()));
- collapseAction = popup.addAction(tr("Collapse others"), this, SLOT(collapseAll()));
+ // verify if there`s a need for collapse others
+ if (expanded_nodes > 1)
+ collapseAction = popup.addAction(tr("Collapse others"), this, SLOT(collapseAll()));
+
+
if (d) {
popup.addAction(tr("Remove dive(s) from trip"), this, SLOT(removeFromTrip()));
popup.addAction(tr("Create new trip above"), this, SLOT(newTripAbove()));