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.
11eadceMirco Müller
tests/mocks/Unity/Notifications/MockNotification.cpp+3−1
@@ -19,6 +19,8 @@
19
19
20#include "MockNotification.h"
20#include "MockNotification.h"
21
21
22+#include <QDebug>
23+
22struct MockNotificationPrivate {
24struct MockNotificationPrivate {
23 unsigned int id;
25 unsigned int id;
24 QString summary;
26 QString summary;
@@ -45,7 +47,7 @@ QString MockNotification::getSummary() const {
45
47
46void MockNotification::setSummary(const QString &summary) {
48void MockNotification::setSummary(const QString &summary) {
47 if(p->summary != summary) {
49 if(p->summary != summary) {
48− p->summary= summary;
50+ p->summary = summary;
49 Q_EMIT summaryChanged(p->summary);
51 Q_EMIT summaryChanged(p->summary);
50 Q_EMIT dataChanged(p->id);
52 Q_EMIT dataChanged(p->id);
51 }
53 }
tests/mocks/Unity/Notifications/MockNotificationModel.cpp+9−4
@@ -47,7 +47,7 @@ int MockNotificationModel::rowCount(const QModelIndex &parent) const {
47}
47}
48
48
49QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
49QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
50− //printf("Data %d.\n", index.row());
50+ qDebug() << "::data()";
51 if (!index.isValid())
51 if (!index.isValid())
52 return QVariant();
52 return QVariant();
53
53
@@ -88,8 +88,12 @@ QVariant MockNotificationModel::data(const QModelIndex &index, int role) const {
88}
88}
89
89
90void MockNotificationModel::append(const QSharedPointer<MockNotification> &n) {
90void MockNotificationModel::append(const QSharedPointer<MockNotification> &n) {
91+ int location = p->queue.size();
92+ QModelIndex insertionPoint = QModelIndex();
93+ beginInsertRows(insertionPoint, location, location);
91− p->queue.append(n);
94+ p->queue.insert(location, n);
95+ endInsertRows();
92− //qDebug() << "append() called, count:" << p->queue.size() << ", summary: " << QString(p->queue[0]->getSummary());
96+ qDebug() << "queue-size:" << p->queue.size();
93}
97}
94
98
95QSharedPointer<MockNotification> MockNotificationModel::getNotification(unsigned int id) const {
99QSharedPointer<MockNotification> MockNotificationModel::getNotification(unsigned int id) const {
@@ -142,10 +146,11 @@ void MockNotificationModel::deleteFromVisible(int loc) {
142}
146}
143
147
144MockNotification* MockNotificationModel::getRaw(const unsigned int notificationId) const {
148MockNotification* MockNotificationModel::getRaw(const unsigned int notificationId) const {
149+ qDebug() << "::getRaw()";
145 for(int i=0; i<p->queue.size(); i++) {
150 for(int i=0; i<p->queue.size(); i++) {
146 if(p->queue[i]->getID() == notificationId) {
151 if(p->queue[i]->getID() == notificationId) {
147 MockNotification* n = p->queue[i].data();
152 MockNotification* n = p->queue[i].data();
148− QQmlEngine::setObjectOwnership(n, QQmlEngine::CppOwnership);
153+ //QQmlEngine::setObjectOwnership(n, QQmlEngine::CppOwnership);
149 return n;
154 return n;
150 }
155 }
151 }
156 }
tests/mocks/Unity/Notifications/MockNotificationModel.h−1
@@ -61,7 +61,6 @@ Q_SIGNALS:
61private:
61private:
62 QScopedPointer<MockNotificationModelPrivate> p;
62 QScopedPointer<MockNotificationModelPrivate> p;
63
63
64− void localAppend(const MockNotification& n);
65 void deleteFromVisible(int loc);
64 void deleteFromVisible(int loc);
66 void deleteFirst();
65 void deleteFirst();
67};
66};
tests/qmltests/Notifications/tst_Notifications.qml+10−9
@@ -30,7 +30,7 @@ Item {
30 width: notificationsRect.width + interactiveControls.width
30 width: notificationsRect.width + interactiveControls.width
31 height: notificationsRect.height
31 height: notificationsRect.height
32
32
33− property list<Notification> dataList: [
33+ property list<Notification> mockList: [
34 Notification {
34 Notification {
35 nid: 0
35 nid: 0
36 type: Notification.PlaceHolder
36 type: Notification.PlaceHolder
@@ -125,36 +125,36 @@ Item {
125
125
126 // add the default/PlaceHolder notification to the model
126 // add the default/PlaceHolder notification to the model
127 Component.onCompleted: {
127 Component.onCompleted: {
128− append(dataList[0])
128+ append(mockList[0])
129 }
129 }
130 }
130 }
131
131
132 function add2over1SnapDecisionNotification() {
132 function add2over1SnapDecisionNotification() {
133− mockModel.append(dataList[1])
133+ mockModel.append(mockList[1])
134 }
134 }
135
135
136 function addEphemeralNotification() {
136 function addEphemeralNotification() {
137− mockModel.append(dataList[2])
137+ mockModel.append(mockList[2])
138 }
138 }
139
139
140 function addEphemeralNonShapedIconNotification() {
140 function addEphemeralNonShapedIconNotification() {
141− mockModel.append(dataList[3])
141+ mockModel.append(mockList[3])
142 }
142 }
143
143
144 function addEphemeralIconSummaryNotification() {
144 function addEphemeralIconSummaryNotification() {
145− mockModel.append(dataList[4])
145+ mockModel.append(mockList[4])
146 }
146 }
147
147
148 function addInteractiveNotification() {
148 function addInteractiveNotification() {
149− mockModel.append(dataList[5])
149+ mockModel.append(mockList[5])
150 }
150 }
151
151
152 function addConfirmationNotification() {
152 function addConfirmationNotification() {
153− mockModel.append(dataList[6])
153+ mockModel.append(mockList[6])
154 }
154 }
155
155
156 function add2ndConfirmationNotification() {
156 function add2ndConfirmationNotification() {
157− mockModel.append(dataList[7])
157+ mockModel.append(mockList[7])
158 }
158 }
159
159
160 function clearNotifications() {
160 function clearNotifications() {
@@ -187,6 +187,7 @@ Item {
187
187
188 anchors.fill: parent
188 anchors.fill: parent
189 model: mockModel
189 model: mockModel
190+ //model: mockList
190 }
191 }
191 }
192 }
192
193