diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-29 19:55:24 +0900 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-29 19:55:24 +0900 |
commit | 8df20f414966db685e4709eb101e071b4783c09f (patch) | |
tree | e92d0772b2a393ae3ca73ebb47ac74e37adeb9d1 /qt-ui/models.cpp | |
parent | 4371a4a29859c9419a646cb7ed1182c19f54d7ab (diff) | |
parent | 5a994b08f6323680fe8362f129f097c9c2aaef2e (diff) | |
download | subsurface-8df20f414966db685e4709eb101e071b4783c09f.tar.gz |
Merge branch 'bug111' of https://github.com/tcanabrava/subsurface
Diffstat (limited to 'qt-ui/models.cpp')
-rw-r--r-- | qt-ui/models.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
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(); } |