Commit f622859b authored by DonLakeFlyer's avatar DonLakeFlyer

Add support for insert/append of multiple objects at a time

For much better performance
parent fbcb38e0
...@@ -172,11 +172,42 @@ void QmlObjectListModel::insert(int i, QObject* object) ...@@ -172,11 +172,42 @@ void QmlObjectListModel::insert(int i, QObject* object)
setDirty(true); setDirty(true);
} }
void QmlObjectListModel::insert(int i, QList<QObject*> objects)
{
if (i < 0 || i > _objectList.count()) {
qWarning() << "Invalid index index:count" << i << _objectList.count();
}
int j = i;
foreach (QObject* object, objects) {
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
// Look for a dirtyChanged signal on the object
if (object->metaObject()->indexOfSignal(QMetaObject::normalizedSignature("dirtyChanged(bool)")) != -1) {
if (!_skipDirtyFirstItem || j != 0) {
QObject::connect(object, SIGNAL(dirtyChanged(bool)), this, SLOT(_childDirtyChanged(bool)));
}
}
j++;
_objectList.insert(i, object);
}
insertRows(i, objects.count());
setDirty(true);
}
void QmlObjectListModel::append(QObject* object) void QmlObjectListModel::append(QObject* object)
{ {
insert(_objectList.count(), object); insert(_objectList.count(), object);
} }
void QmlObjectListModel::append(QList<QObject*> objects)
{
insert(_objectList.count(), objects);
}
QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist) QObjectList QmlObjectListModel::swapObjectList(const QObjectList& newlist)
{ {
QObjectList oldlist(_objectList); QObjectList oldlist(_objectList);
......
...@@ -37,11 +37,13 @@ public: ...@@ -37,11 +37,13 @@ public:
void setDirty(bool dirty); void setDirty(bool dirty);
void append(QObject* object); void append(QObject* object);
void append(QList<QObject*> objects);
QObjectList swapObjectList(const QObjectList& newlist); QObjectList swapObjectList(const QObjectList& newlist);
void clear(void); void clear(void);
QObject* removeAt(int i); QObject* removeAt(int i);
QObject* removeOne(QObject* object) { return removeAt(indexOf(object)); } QObject* removeOne(QObject* object) { return removeAt(indexOf(object)); }
void insert(int i, QObject* object); void insert(int i, QObject* object);
void insert(int i, QList<QObject*> objects);
QObject* operator[](int i); QObject* operator[](int i);
const QObject* operator[](int i) const; const QObject* operator[](int i) const;
bool contains(QObject* object) { return _objectList.indexOf(object) != -1; } bool contains(QObject* object) { return _objectList.indexOf(object) != -1; }
...@@ -63,12 +65,12 @@ private slots: ...@@ -63,12 +65,12 @@ private slots:
private: private:
// Overrides from QAbstractListModel // Overrides from QAbstractListModel
virtual int rowCount(const QModelIndex & parent = QModelIndex()) const; int rowCount(const QModelIndex & parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;
virtual QHash<int, QByteArray> roleNames(void) const; QHash<int, QByteArray> roleNames(void) const override;
virtual bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()); bool insertRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
virtual bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()); bool removeRows(int position, int rows, const QModelIndex &index = QModelIndex()) override;
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
private: private:
QList<QObject*> _objectList; QList<QObject*> _objectList;
......
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