summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2016-03-15 11:11:44 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2016-03-17 14:41:24 +0000
commit98c8af10b75feafaff5b36fe70e0e041a3e79151 (patch)
treec8849508d5f7b149f9ac4f34c5e5b91600ed4b6e
parentde4cfc6b53b426799a035fefe81db9d49d3d03ab (diff)
Populate declarative Item id with the new id after it be created.
We need to update declararive organizer item id with the new id value after creation to make possible to edit or delete it in the future, without need to fetch a new item. Change-Id: I5da7e6fb6a52416b97312a3179f8db3b6d65e3d7 Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com> Reviewed-by: Christopher Adams <chris.adams@jollamobile.com>
-rw-r--r--src/imports/organizer/qdeclarativeorganizermodel.cpp22
-rw-r--r--tests/auto/organizer/qmlorganizer/testcases/tst_organizercollectionfilter.qml10
-rw-r--r--tests/auto/organizer/qmlorganizer/testcases/tst_organizerintersectionfilter.qml11
-rw-r--r--tests/auto/organizer/qmlorganizer/testcases/tst_organizerrecurrence.qml51
-rw-r--r--tests/auto/organizer/qmlorganizer/testcases/tst_organizerunionfilter.qml11
5 files changed, 95 insertions, 10 deletions
diff --git a/src/imports/organizer/qdeclarativeorganizermodel.cpp b/src/imports/organizer/qdeclarativeorganizermodel.cpp
index 0d85d4fa1..d77b786d4 100644
--- a/src/imports/organizer/qdeclarativeorganizermodel.cpp
+++ b/src/imports/organizer/qdeclarativeorganizermodel.cpp
@@ -36,6 +36,7 @@
#include <QtCore/qfile.h>
#include <QtCore/qmath.h>
#include <QtCore/qurl.h>
+#include <QtCore/qpointer.h>
#include <QtQml/qqmlinfo.h>
@@ -77,6 +78,7 @@ static QString urlToLocalFileName(const QUrl& url)
}
+static const char ITEM_TO_SAVE_PROPERTY[] = {"ITEM_TO_SAVE_PROPERTY"};
class QDeclarativeOrganizerModelPrivate
{
@@ -1247,6 +1249,14 @@ void QDeclarativeOrganizerModel::saveItem(QDeclarativeOrganizerItem* di)
req->setManager(d->m_manager);
req->setItem(item);
+ if (di->itemId().isEmpty()) {
+ // if the item id is empty this means that this item is a new event
+ // we need to keep trace of this declarative item to update with the
+ // new Id as soon as this request finish
+ QPointer<QDeclarativeOrganizerItem> pItem = di;
+ req->setProperty(ITEM_TO_SAVE_PROPERTY, QVariant::fromValue(pItem));
+ }
+
connect(req, SIGNAL(stateChanged(QOrganizerAbstractRequest::State)), this, SLOT(onRequestStateChanged(QOrganizerAbstractRequest::State)));
req->start();
@@ -1341,6 +1351,18 @@ void QDeclarativeOrganizerModel::onRequestStateChanged(QOrganizerAbstractRequest
QOrganizerAbstractRequest *request = qobject_cast<QOrganizerAbstractRequest *>(sender());
Q_ASSERT(request);
+ if (request->error() == QOrganizerManager::NoError &&
+ request->type() == QOrganizerAbstractRequest::ItemSaveRequest) {
+ QVariant vItem = request->property(ITEM_TO_SAVE_PROPERTY);
+ if (vItem.isValid()) {
+ QPointer<QDeclarativeOrganizerItem> pItem = vItem.value<QPointer<QDeclarativeOrganizerItem> >();
+ // Fill declarative item id
+ QOrganizerItemSaveRequest *sr = static_cast<QOrganizerItemSaveRequest *>(request);
+ if (pItem && sr->items().length() == 1)
+ pItem->setItem(sr->items()[0]);
+ }
+ }
+
checkError(request);
request->deleteLater();
}
diff --git a/tests/auto/organizer/qmlorganizer/testcases/tst_organizercollectionfilter.qml b/tests/auto/organizer/qmlorganizer/testcases/tst_organizercollectionfilter.qml
index 6fa4523b8..c010e549b 100644
--- a/tests/auto/organizer/qmlorganizer/testcases/tst_organizercollectionfilter.qml
+++ b/tests/auto/organizer/qmlorganizer/testcases/tst_organizercollectionfilter.qml
@@ -128,7 +128,15 @@ Rectangle {
utility.waitModelChange(0);
compare(model.itemCount, 0)
- //save event to default collection
+ //save a new event to default collection
+ event = Qt.createQmlObject(
+ "import QtOrganizer 5.0;"
+ + "Event { "
+ + " displayLabel: \"organizer collection filter test event\"; "
+ + " description: \"organizer collection filter test event\"; "
+ + " startDateTime: '2010-12-12'; "
+ + " endDateTime: '2010-12-13'; }"
+ , test);
event.collectionId = model.defaultCollectionId();
model.saveItem(event);
utility.waitModelChange(1);
diff --git a/tests/auto/organizer/qmlorganizer/testcases/tst_organizerintersectionfilter.qml b/tests/auto/organizer/qmlorganizer/testcases/tst_organizerintersectionfilter.qml
index 11f3cbb20..99681ec35 100644
--- a/tests/auto/organizer/qmlorganizer/testcases/tst_organizerintersectionfilter.qml
+++ b/tests/auto/organizer/qmlorganizer/testcases/tst_organizerintersectionfilter.qml
@@ -116,7 +116,16 @@ Rectangle {
utility.waitModelChange(1);
compare(model.itemCount, 1)
- //event with new collection id
+ //new event with new collection id
+ event = Qt.createQmlObject(
+ "import QtOrganizer 5.0;"
+ + "Event { "
+ + " id:event;"
+ + " displayLabel: \"organizer intersection filter test event\"; "
+ + " description: \"organizer intersection filter test event\"; "
+ + " startDateTime: '2010-12-12'; "
+ + " endDateTime: '2010-12-13'; }"
+ , test);
event.collectionId = savedCollection.collectionId;
model.saveItem(event);
utility.waitModelChange(2);
diff --git a/tests/auto/organizer/qmlorganizer/testcases/tst_organizerrecurrence.qml b/tests/auto/organizer/qmlorganizer/testcases/tst_organizerrecurrence.qml
index 021c7f603..95fa0796e 100644
--- a/tests/auto/organizer/qmlorganizer/testcases/tst_organizerrecurrence.qml
+++ b/tests/auto/organizer/qmlorganizer/testcases/tst_organizerrecurrence.qml
@@ -39,6 +39,19 @@ TestCase {
id: test
name: "OrganizerRecurrenceTests"
+ property var testEvent: null
+ property var testTodo: null
+
+ Component {
+ id: eventComponent
+ Event {}
+ }
+
+ Component {
+ id: todoComponent
+ Todo {}
+ }
+
QOrganizerTestUtility {
id: utility
}
@@ -50,14 +63,6 @@ TestCase {
endPeriod:'2014-12-31'
}
- Event {
- id: testEvent
- }
-
- Todo {
- id: testTodo
- }
-
RecurrenceRule {
id: testRule
}
@@ -79,9 +84,25 @@ TestCase {
}
function cleanup() {
+ if (testEvent) {
+ testEvent.destroy()
+ testEvent = null
+ }
+
+ if (testTodo) {
+ testTodo.destroy()
+ testTodo = null
+ }
+
model.manager = ""
}
+ function init()
+ {
+ testEvent = eventComponent.createObject(test)
+ testTodo = todoComponent.createObject(test)
+ }
+
function localDateTime(tsSpec) {
// Parse a ISO8601 time spec and return it as local time; if passed to the Date
// ctor, it will be interpreted as UTC
@@ -711,6 +732,7 @@ TestCase {
model.manager = managers[i];
spyManagerChanged.wait()
cleanDatabase();
+ testEvent = eventComponent.createObject(test)
testRule.frequency = RecurrenceRule.Daily;
testRule.interval = 1;
@@ -737,6 +759,7 @@ TestCase {
model.manager = managers[i];
spyManagerChanged.wait()
cleanDatabase();
+ testEvent = eventComponent.createObject(test)
testRule.frequency = RecurrenceRule.Daily;
testRule.interval = 3;
@@ -832,6 +855,16 @@ TestCase {
spyModelChanged.wait()
}
compare(model.itemIds().length, 0)
+
+ if (testEvent) {
+ testEvent.destroy()
+ testEvent = null
+ }
+
+ if (testTodo) {
+ testTodo.destroy()
+ testTodo = null
+ }
}
function populateTestItemsFromData(data) {
@@ -859,6 +892,8 @@ TestCase {
testXRule.positions = data.xrule.positions;
testXRule.firstDayOfWeek = data.xrule.firstDayOfWeek;
}
+ testEvent = eventComponent.createObject(test)
+ testTodo = todoComponent.createObject(test)
testEvent.startDateTime = new Date(data.definitions.start);
testTodo.startDateTime = new Date(data.definitions.start);
diff --git a/tests/auto/organizer/qmlorganizer/testcases/tst_organizerunionfilter.qml b/tests/auto/organizer/qmlorganizer/testcases/tst_organizerunionfilter.qml
index 96a8e2852..727d2f6ad 100644
--- a/tests/auto/organizer/qmlorganizer/testcases/tst_organizerunionfilter.qml
+++ b/tests/auto/organizer/qmlorganizer/testcases/tst_organizerunionfilter.qml
@@ -114,12 +114,23 @@ Rectangle {
model.saveItem(event);
utility.waitModelChange(1);
compare(model.itemCount, 1)
+ event.destroy()
//event with new collection id
+ event = Qt.createQmlObject(
+ "import QtOrganizer 5.0;"
+ + "Event { "
+ + " id:event;"
+ + " displayLabel: \"organizer union filter test event\"; "
+ + " description: \"organizer union filter test event\"; "
+ + " startDateTime: '2010-12-12'; "
+ + " endDateTime: '2010-12-13'; }"
+ , test);
event.collectionId = savedCollection.collectionId;
model.saveItem(event);
utility.waitModelChange(2);
compare(model.itemCount, 2)
+ event.destroy()
var fetchlist = model.items;
var idEventId;