diff options
Diffstat (limited to 'qt-models')
-rw-r--r-- | qt-models/maplocationmodel.cpp | 19 | ||||
-rw-r--r-- | qt-models/maplocationmodel.h | 2 |
2 files changed, 20 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();
+}
diff --git a/qt-models/maplocationmodel.h b/qt-models/maplocationmodel.h index e398a8091..8dff65eac 100644 --- a/qt-models/maplocationmodel.h +++ b/qt-models/maplocationmodel.h @@ -44,6 +44,8 @@ public: QVariant data(const QModelIndex &index, int role) const override; int rowCount(const QModelIndex &parent) const override; int count(); + void add(MapLocation *); + void clear(); protected: QHash<int, QByteArray> roleNames() const; |