on xenial help sign in
Pulling a MockNotification out of the model still fails with a nullptr and I don't know where that actually happens.
commit11eadce63fe73d209a3d408285dd31fd55ba7eac authorMirco Müller <mirco.mueller@ubuntu.com> dateThu 15 Jan 2015, 12:59 (12 years ago) parentd4ebb4d
4 files changed+22−15
tests/mocks/Unity/Notifications/MockNotification.cpp+3−1 tests/mocks/Unity/Notifications/MockNotificationModel.cpp+9−4 tests/mocks/Unity/Notifications/MockNotificationModel.h−1 tests/qmltests/Notifications/tst_Notifications.qml+10−9
tests/mocks/Unity/Notifications/MockNotification.cpp+3−1
@@ -19,6 +19,8 @@
1919
2020#include "MockNotification.h"
2121
22+#include <QDebug>
23+
2224struct MockNotificationPrivate {
2325 unsigned int id;
2426 QString summary;
@@ -45,7 +47,7 @@ QString MockNotification::getSummary() const {
4547
4648void MockNotification::setSummary(const QString &summary) {
4749 if(p->summary != summary) {
48− p->summary= summary;
50+ p->summary = summary;
4951 Q_EMIT summaryChanged(p->summary);
5052 Q_EMIT dataChanged(p->id);
5153 }
tests/mocks/Unity/Notifications/MockNotificationModel.cpp+9−4
@@ -47,7 +47,7 @@ int MockNotificationModel::rowCount(const QModelIndex &parent) const {
4747}
4848
4949QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
50− //printf("Data %d.\n", index.row());
50+ qDebug() << "::data()";
5151 if (!index.isValid())
5252 return QVariant();
5353
@@ -88,8 +88,12 @@ QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
8888}
8989
9090void MockNotificationModel::append(const QSharedPointer<MockNotification> &n) {
91− p->queue.append(n);
92− //qDebug() << "append() called, count:" << p->queue.size() << ", summary: " << QString(p->queue[0]->getSummary());
91+ int location = p->queue.size();
92+ QModelIndex insertionPoint = QModelIndex();
93+ beginInsertRows(insertionPoint, location, location);
94+ p->queue.insert(location, n);
95+ endInsertRows();
96+ qDebug() << "queue-size:" << p->queue.size();
9397}
9498
9599QSharedPointer<MockNotification> MockNotificationModel::getNotification(unsigned int id) const {
@@ -142,10 +146,11 @@ void MockNotificationModel::deleteFromVisible(int loc) {
142146}
143147
144148MockNotification* MockNotificationModel::getRaw(const unsigned int notificationId) const {
149+ qDebug() << "::getRaw()";
145150 for(int i=0; i<p->queue.size(); i++) {
146151 if(p->queue[i]->getID() == notificationId) {
147152 MockNotification* n = p->queue[i].data();
148− QQmlEngine::setObjectOwnership(n, QQmlEngine::CppOwnership);
153+ //QQmlEngine::setObjectOwnership(n, QQmlEngine::CppOwnership);
149154 return n;
150155 }
151156 }
tests/mocks/Unity/Notifications/MockNotificationModel.h−1
@@ -61,7 +61,6 @@ Q_SIGNALS:
6161private:
6262 QScopedPointer<MockNotificationModelPrivate> p;
6363
64− void localAppend(const MockNotification& n);
6564 void deleteFromVisible(int loc);
6665 void deleteFirst();
6766};
tests/qmltests/Notifications/tst_Notifications.qml+10−9
@@ -30,7 +30,7 @@ Item {
3030 width: notificationsRect.width + interactiveControls.width
3131 height: notificationsRect.height
3232
33− property list<Notification> dataList: [
33+ property list<Notification> mockList: [
3434 Notification {
3535 nid: 0
3636 type: Notification.PlaceHolder
@@ -125,36 +125,36 @@ Item {
125125
126126 // add the default/PlaceHolder notification to the model
127127 Component.onCompleted: {
128− append(dataList[0])
128+ append(mockList[0])
129129 }
130130 }
131131
132132 function add2over1SnapDecisionNotification() {
133− mockModel.append(dataList[1])
133+ mockModel.append(mockList[1])
134134 }
135135
136136 function addEphemeralNotification() {
137− mockModel.append(dataList[2])
137+ mockModel.append(mockList[2])
138138 }
139139
140140 function addEphemeralNonShapedIconNotification() {
141− mockModel.append(dataList[3])
141+ mockModel.append(mockList[3])
142142 }
143143
144144 function addEphemeralIconSummaryNotification() {
145− mockModel.append(dataList[4])
145+ mockModel.append(mockList[4])
146146 }
147147
148148 function addInteractiveNotification() {
149− mockModel.append(dataList[5])
149+ mockModel.append(mockList[5])
150150 }
151151
152152 function addConfirmationNotification() {
153− mockModel.append(dataList[6])
153+ mockModel.append(mockList[6])
154154 }
155155
156156 function add2ndConfirmationNotification() {
157− mockModel.append(dataList[7])
157+ mockModel.append(mockList[7])
158158 }
159159
160160 function clearNotifications() {
@@ -187,6 +187,7 @@ Item {
187187
188188 anchors.fill: parent
189189 model: mockModel
190+ //model: mockList
190191 }
191192 }
192193