mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
52316229cd
commit
f4e6df475e
2 changed files with 20 additions and 1 deletions
|
@ -30,7 +30,7 @@ MapLocationModel::MapLocationModel(QObject *parent) : QAbstractListModel(parent)
|
||||||
|
|
||||||
MapLocationModel::~MapLocationModel()
|
MapLocationModel::~MapLocationModel()
|
||||||
{
|
{
|
||||||
qDeleteAll(m_mapLocations);
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MapLocationModel::data( const QModelIndex & index, int role ) const
|
QVariant MapLocationModel::data( const QModelIndex & index, int role ) const
|
||||||
|
@ -63,3 +63,20 @@ MapLocation *MapLocationModel::get(int row)
|
||||||
return NULL;
|
return NULL;
|
||||||
return m_mapLocations.at(row);
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ public:
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
int rowCount(const QModelIndex &parent) const override;
|
int rowCount(const QModelIndex &parent) const override;
|
||||||
int count();
|
int count();
|
||||||
|
void add(MapLocation *);
|
||||||
|
void clear();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const;
|
QHash<int, QByteArray> roleNames() const;
|
||||||
|
|
Loading…
Add table
Reference in a new issue