From c6f84de37c33ef66f479d1adcffea6eab903c674 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Tue, 28 May 2013 16:56:58 -0300 Subject: Adds the code to make the dive list behave like tree or list This code adds the possibility to make the DiveList behave like a Tree or a List, depending on what layout is set. Signed-off-by: Tomaz Canabrava --- qt-ui/models.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'qt-ui/models.cpp') diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 38ef8938c..98a84d7f9 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -1003,7 +1003,6 @@ DiveTripModel::DiveTripModel(QObject* parent) : QAbstractItemModel(parent) { rootItem = new TreeItemDT(); - setupModelData(); } DiveTripModel::~DiveTripModel() @@ -1096,6 +1095,11 @@ void DiveTripModel::setupModelData() { int i = dive_table.nr; + if (rowCount()){ + beginRemoveRows(QModelIndex(), 0, rowCount()-1); + endRemoveRows(); + } + while (--i >= 0) { struct dive* dive = get_dive(i); update_cylinder_related_info(dive); @@ -1104,11 +1108,14 @@ void DiveTripModel::setupModelData() DiveItem* diveItem = new DiveItem(); diveItem->dive = dive; - if (!trip) { + if (!trip || currentLayout == LIST) { diveItem->parent = rootItem; rootItem->children.push_back(diveItem); continue; } + if (currentLayout == LIST) + continue; + if (!trips.keys().contains(trip)) { TripItem* tripItem = new TripItem(); tripItem->trip = trip; @@ -1121,4 +1128,20 @@ void DiveTripModel::setupModelData() TripItem* tripItem = trips[trip]; tripItem->children.push_back(diveItem); } + + if (rowCount()){ + beginInsertRows(QModelIndex(), 0, rowCount()-1); + endInsertRows(); + } +} + +DiveTripModel::Layout DiveTripModel::layout() const +{ + return currentLayout; +} + +void DiveTripModel::setLayout(DiveTripModel::Layout layout) +{ + currentLayout = layout; + setupModelData(); } -- cgit v1.2.3-70-g09d2