summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-01-19 06:17:05 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-01-19 06:17:05 (GMT)
commit8eb1bf3ea506ec1f9636cab684695b91d846a3cd (patch)
tree4fbb04e1a9fa8d9256406d9e10d9044c276bf177
parent73ed1b2e5722a70e9676332184fb6cd144177d5b (diff)
downloadQt-8eb1bf3ea506ec1f9636cab684695b91d846a3cd.zip
Qt-8eb1bf3ea506ec1f9636cab684695b91d846a3cd.tar.gz
Qt-8eb1bf3ea506ec1f9636cab684695b91d846a3cd.tar.bz2
WorkerListModel fixes
-rw-r--r--src/declarative/qml/qmlworkerscript.cpp26
-rw-r--r--src/declarative/qml/qmlworkerscript_p.h4
2 files changed, 26 insertions, 4 deletions
diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp
index 8ebf841..75c5179 100644
--- a/src/declarative/qml/qmlworkerscript.cpp
+++ b/src/declarative/qml/qmlworkerscript.cpp
@@ -177,6 +177,12 @@ public:
VariantRef(QmlWorkerListModelAgent *_a) : a(_a) { if (a) a->addref(); }
~VariantRef() { if (a) a->release(); }
+ VariantRef &operator=(const VariantRef &o) {
+ if (o.a) o.a->addref();
+ if (a) a->release(); a = o.a;
+ return *this;
+ }
+
QmlWorkerListModelAgent *a;
};
protected:
@@ -630,7 +636,7 @@ void QmlWorkerListModelAgent::Data::changedChange(int index, int count)
}
QmlWorkerListModelAgent::QmlWorkerListModelAgent(QmlWorkerListModel *m)
-: m_engine(0), m_model(m)
+: m_engine(0), m_ref(1), m_model(m)
{
data.roles = m_model->m_roles;
data.strings = m_model->m_strings;
@@ -648,7 +654,9 @@ void QmlWorkerListModelAgent::addref()
void QmlWorkerListModelAgent::release()
{
- if (!m_ref.deref())
+ bool del = !m_ref.deref();
+
+ if (del)
delete this;
}
@@ -660,7 +668,7 @@ int QmlWorkerListModelAgent::count() const
void QmlWorkerListModelAgent::clear()
{
data.clearChange();
- data.insertChange(0, data.values.count());
+ data.removeChange(0, data.values.count());
data.values.clear();
}
@@ -780,6 +788,8 @@ bool QmlWorkerListModelAgent::event(QEvent *e)
const QList<Change> &changes = s->data.changes;
if (m_model) {
+ bool cc = m_model->m_values.count() != s->data.values.count();
+
m_model->m_roles = s->data.roles;
m_model->m_strings = s->data.strings;
m_model->m_values = s->data.values;
@@ -801,6 +811,9 @@ bool QmlWorkerListModelAgent::event(QEvent *e)
break;
}
}
+
+ if (cc)
+ emit m_model->countChanged();
}
}
@@ -829,8 +842,10 @@ void QmlWorkerListModel::clear()
int count = m_values.count();
m_values.clear();
- if (count)
+ if (count) {
emit itemsRemoved(0, count);
+ emit countChanged();
+ }
}
void QmlWorkerListModel::remove(int index)
@@ -845,6 +860,7 @@ void QmlWorkerListModel::remove(int index)
m_values.removeAt(index);
emit itemsRemoved(index, 1);
+ emit countChanged();
}
void QmlWorkerListModel::append(const QScriptValue &value)
@@ -874,6 +890,7 @@ void QmlWorkerListModel::append(const QScriptValue &value)
m_values.append(data);
emit itemsInserted(m_values.count() - 1, 1);
+ emit countChanged();
}
void QmlWorkerListModel::insert(int index, const QScriptValue &value)
@@ -905,6 +922,7 @@ void QmlWorkerListModel::insert(int index, const QScriptValue &value)
m_values.insert(index, data);
emit itemsInserted(index, 1);
+ emit countChanged();
}
QScriptValue QmlWorkerListModel::get(int index) const
diff --git a/src/declarative/qml/qmlworkerscript_p.h b/src/declarative/qml/qmlworkerscript_p.h
index fdc726e..1c70f2d 100644
--- a/src/declarative/qml/qmlworkerscript_p.h
+++ b/src/declarative/qml/qmlworkerscript_p.h
@@ -118,6 +118,7 @@ class QmlWorkerListModelAgent;
class QmlWorkerListModel : public QListModelInterface
{
Q_OBJECT
+ Q_PROPERTY(int count READ count NOTIFY countChanged);
public:
QmlWorkerListModel(QObject * = 0);
@@ -138,6 +139,9 @@ public:
virtual QHash<int,QVariant> data(int index, const QList<int> &roles = (QList<int>())) const;
virtual QVariant data(int index, int role) const;
+Q_SIGNALS:
+ void countChanged();
+
private:
friend class QmlWorkerListModelAgent;