summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@gmail.com>2015-05-10 17:08:24 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-05-11 07:27:55 -0700
commitd6f45ec74dc6c18824045fe364131833124d5d4e (patch)
tree2b692c261be6e607a472eb35d2156de8dc38314c
parent627de38c01f6bcba56221ed3703bd08d1d215168 (diff)
downloadsubsurface-d6f45ec74dc6c18824045fe364131833124d5d4e.tar.gz
Only show expand all and collapse all options if there`s a need
This patch unclutter the menu by hidding collapse all when all dives are collapsed, and expand all when all dives are expanded. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/divelistview.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 93454dda0..ae502eecc 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -797,8 +797,24 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
dive_trip_t *trip = (dive_trip_t *)contextMenuIndex.data(DiveTripModel::TRIP_ROLE).value<void *>();
QMenu popup(this);
if (currentLayout == DiveTripModel::TREE) {
- popup.addAction(tr("Expand all"), this, SLOT(expandAll()));
- popup.addAction(tr("Collapse all"), this, SLOT(collapseAll()));
+ // verify if there is a node that`s not expanded.
+ bool needs_expand = false;
+ bool needs_collapse = false;
+ 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))
+ needs_expand = true;
+ else
+ needs_collapse = true;
+ }
+ 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()));
if (d) {
popup.addAction(tr("Remove dive(s) from trip"), this, SLOT(removeFromTrip()));