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

parent c850bd92
......@@ -20,9 +20,10 @@ const int QmlObjectListModel::ObjectRole = Qt::UserRole;
const int QmlObjectListModel::TextRole = Qt::UserRole + 1;
QmlObjectListModel::QmlObjectListModel(QObject* parent)
: QAbstractListModel(parent)
, _dirty(false)
, _skipDirtyFirstItem(false)
: QAbstractListModel (parent)
, _dirty (false)
, _skipDirtyFirstItem (false)
, _externalBeginResetModel (false)
{
}
......@@ -142,8 +143,13 @@ const QObject* QmlObjectListModel::operator[](int index) const
void QmlObjectListModel::clear()
{
while (rowCount()) {
removeAt(0);
if (!_externalBeginResetModel) {
beginResetModel();
}
_objectList.clear();
if (!_externalBeginResetModel) {
endResetModel();
emit countChanged(count());
}
}
......@@ -221,10 +227,14 @@ void QmlObjectListModel::append(QList<QObject*> objects)
QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist)
{
QObjectList oldlist(_objectList);
beginResetModel();
if (!_externalBeginResetModel) {
beginResetModel();
}
_objectList = newlist;
endResetModel();
emit countChanged(count());
if (!_externalBeginResetModel) {
endResetModel();
emit countChanged(count());
}
return oldlist;
}
......@@ -274,3 +284,21 @@ void QmlObjectListModel::clearAndDeleteContents()
clear();
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:
int count () const;
bool dirty () const { return _dirty; }
void setDirty (bool dirty);
void append (QObject* object);
void append (QList<QObject*> objects);
......@@ -56,8 +57,8 @@ public:
/// Clears the list and calls deleteLater on each entry
void clearAndDeleteContents ();
void beginReset () { beginResetModel(); }
void endReset () { endResetModel(); }
void beginReset ();
void endReset ();
signals:
void countChanged (int count);
......@@ -80,6 +81,7 @@ private:
bool _dirty;
bool _skipDirtyFirstItem;
bool _externalBeginResetModel;
static const int ObjectRole;
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