From 9523132b6da30231b3c56f3ee203a97b8a69c34f Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 10 May 2015 17:19:34 -0300 Subject: [PATCH] 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 Signed-off-by: Dirk Hohndel --- qt-ui/divelistview.cpp | 13 ++++++++++--- 1 file 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()) 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()));