diff options
author | Lubomir I. Ivanov <neolit123@gmail.com> | 2017-07-17 22:12:04 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2017-07-28 07:31:11 -0700 |
commit | f4e6df475e1cfd93dc0d73287ec6a5113b5eb176 (patch) | |
tree | acea1a7ddba7810b4c7cf2b718832c7bacce907a /qt-models/maplocationmodel.cpp | |
parent | 52316229cdd57a7c11092bc0522f0b67192aead7 (diff) | |
download | subsurface-f4e6df475e1cfd93dc0d73287ec6a5113b5eb176.tar.gz |
maplocationmodel: implement the clear() and add() methods
- add() will be used to add a MapLocation to the model with
beginInsertRows()...endInsertRows()
- clear() will be used to clear the model with beginRemoveRows()...
endRemoveRows()
NOTE: emiting dataChanged() does not seem to update the QML view for
this model so calling being<..>Rows() seems to be the "correct Qt
approach" to do this.
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Diffstat (limited to 'qt-models/maplocationmodel.cpp')
-rw-r--r-- | qt-models/maplocationmodel.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/qt-models/maplocationmodel.cpp b/qt-models/maplocationmodel.cpp index 5da0733e1..43f28c981 100644 --- a/qt-models/maplocationmodel.cpp +++ b/qt-models/maplocationmodel.cpp @@ -30,7 +30,7 @@ MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent) MapLocationModel::~MapLocationModel()
{
- qDeleteAll(m_mapLocations);
+ clear();
}
QVariant MapLocationModel::data( const QModelIndex & index, int role ) const
@@ -63,3 +63,20 @@ MapLocation *MapLocationModel::get(int row) return NULL;
return m_mapLocations.at(row);
}
+
+void MapLocationModel::add(MapLocation *location)
+{
+ beginInsertRows(QModelIndex(), m_mapLocations.size(), m_mapLocations.size());
+ m_mapLocations.append(location);
+ endInsertRows();
+}
+
+void MapLocationModel::clear()
+{
+ if (!m_mapLocations.size())
+ return;
+ beginRemoveRows(QModelIndex(), 0, m_mapLocations.size() - 1);
+ qDeleteAll(m_mapLocations);
+ m_mapLocations.clear();
+ endRemoveRows();
+}
|