Commit 3ffb3646 authored by Don Gagne's avatar Don Gagne

parent c850bd92
...@@ -20,9 +20,10 @@ const int QmlObjectListModel::ObjectRole = Qt::UserRole; ...@@ -20,9 +20,10 @@ const int QmlObjectListModel::ObjectRole = Qt::UserRole;
const int QmlObjectListModel::TextRole = Qt::UserRole + 1; const int QmlObjectListModel::TextRole = Qt::UserRole + 1;
QmlObjectListModel::QmlObjectListModel(QObject* parent) QmlObjectListModel::QmlObjectListModel(QObject* parent)
: QAbstractListModel(parent) : QAbstractListModel (parent)
, _dirty(false) , _dirty (false)
, _skipDirtyFirstItem(false) , _skipDirtyFirstItem (false)
, _externalBeginResetModel (false)
{ {
} }
...@@ -142,8 +143,13 @@ const QObject* QmlObjectListModel::operator[](int index) const ...@@ -142,8 +143,13 @@ const QObject* QmlObjectListModel::operator[](int index) const
void QmlObjectListModel::clear() void QmlObjectListModel::clear()
{ {
while (rowCount()) { if (!_externalBeginResetModel) {
removeAt(0); beginResetModel();
}
_objectList.clear();
if (!_externalBeginResetModel) {
endResetModel();
emit countChanged(count());
} }
} }
...@@ -221,10 +227,14 @@ void QmlObjectListModel::append(QList<QObject*> objects) ...@@ -221,10 +227,14 @@ void QmlObjectListModel::append(QList<QObject*> objects)
QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist) QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist)
{ {
QObjectList oldlist(_objectList); QObjectList oldlist(_objectList);
beginResetModel(); if (!_externalBeginResetModel) {
beginResetModel();
}
_objectList = newlist; _objectList = newlist;
endResetModel(); if (!_externalBeginResetModel) {
emit countChanged(count()); endResetModel();
emit countChanged(count());
}
return oldlist; return oldlist;
} }
...@@ -274,3 +284,21 @@ void QmlObjectListModel::clearAndDeleteContents() ...@@ -274,3 +284,21 @@ void QmlObjectListModel::clearAndDeleteContents()
clear(); clear();
endResetModel(); endResetModel();
} }
void QmlObjectListModel::beginReset(void)
{
if (_externalBeginResetModel) {
qWarning() << "QmlObjectListModel::beginReset already set";
}
_externalBeginResetModel = true;
beginResetModel();
}
void QmlObjectListModel::endReset(void)
{
if (!_externalBeginResetModel) {
qWarning() << "QmlObjectListModel::endReset begin not set";
}
_externalBeginResetModel = false;
endResetModel();
}
...@@ -33,6 +33,7 @@ public: ...@@ -33,6 +33,7 @@ public:
int count () const; int count () const;
bool dirty () const { return _dirty; } bool dirty () const { return _dirty; }
void setDirty (bool dirty); void setDirty (bool dirty);
void append (QObject* object); void append (QObject* object);
void append (QList<QObject*> objects); void append (QList<QObject*> objects);
...@@ -56,8 +57,8 @@ public: ...@@ -56,8 +57,8 @@ public:
/// Clears the list and calls deleteLater on each entry /// Clears the list and calls deleteLater on each entry
void clearAndDeleteContents (); void clearAndDeleteContents ();
void beginReset () { beginResetModel(); } void beginReset ();
void endReset () { endResetModel(); } void endReset ();
signals: signals:
void countChanged (int count); void countChanged (int count);
...@@ -80,6 +81,7 @@ private: ...@@ -80,6 +81,7 @@ private:
bool _dirty; bool _dirty;
bool _skipDirtyFirstItem; bool _skipDirtyFirstItem;
bool _externalBeginResetModel;
static const int ObjectRole; static const int ObjectRole;
static const int TextRole; static const int TextRole;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment