diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-07-25 21:23:19 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-09-01 07:48:43 -0700 |
commit | 89e0c3f46498ba3e0844514b6709a07c200a68df (patch) | |
tree | 8609c84130cb04180d9db4bb43f2dfc11cf563c3 /qt-models/treemodel.cpp | |
parent | 236f0512bec2946b35052abf637c7c8df97f34bf (diff) | |
download | subsurface-89e0c3f46498ba3e0844514b6709a07c200a68df.tar.gz |
Cleanup: make DiveTripModel a global object
DiveTripModel (the model describing the dive-list) was destroyed
and recreated on every reset of the list. This seems excessive.
Instead - in analogy to most other models - make it a single
global object.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/treemodel.cpp')
-rw-r--r-- | qt-models/treemodel.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/qt-models/treemodel.cpp b/qt-models/treemodel.cpp index 5ddd2d3a2..3c76cc939 100644 --- a/qt-models/treemodel.cpp +++ b/qt-models/treemodel.cpp @@ -32,12 +32,12 @@ QVariant TreeItem::data(int, int) const TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent) { columns = 0; // I'm not sure about this one - I can't see where it gets initialized - rootItem = new TreeItem(); + rootItem.reset(new TreeItem); } -TreeModel::~TreeModel() +void TreeModel::clear() { - delete rootItem; + rootItem.reset(new TreeItem); } QVariant TreeModel::data(const QModelIndex &index, int role) const @@ -64,7 +64,7 @@ QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) con if (!hasIndex(row, column, parent)) return QModelIndex(); - TreeItem *parentItem = (!parent.isValid()) ? rootItem : static_cast<TreeItem *>(parent.internalPointer()); + TreeItem *parentItem = (!parent.isValid()) ? rootItem.get() : static_cast<TreeItem *>(parent.internalPointer()); TreeItem *childItem = parentItem->children[row]; @@ -79,7 +79,7 @@ QModelIndex TreeModel::parent(const QModelIndex &index) const TreeItem *childItem = static_cast<TreeItem *>(index.internalPointer()); TreeItem *parentItem = childItem->parent; - if (parentItem == rootItem || !parentItem) + if (parentItem == rootItem.get() || !parentItem) return QModelIndex(); return createIndex(parentItem->row(), 0, parentItem); @@ -90,7 +90,7 @@ int TreeModel::rowCount(const QModelIndex &parent) const TreeItem *parentItem; if (!parent.isValid()) - parentItem = rootItem; + parentItem = rootItem.get(); else parentItem = static_cast<TreeItem *>(parent.internalPointer()); |