Skip to content

Commit

Permalink
Merge branch '1.1' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsergio committed Apr 23, 2016
2 parents 656c85e + a106255 commit 9454317
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 22 deletions.
8 changes: 6 additions & 2 deletions src/jsonstorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ Storage::Data JsonStorage::deserializeJsonData(const QByteArray &serializedData,
Tag::Ptr tag = Tag::Ptr(new Tag(kernel, QString()));
tag->fromJson(t.toMap());
if (!tag->name().isEmpty() && !Storage::itemListContains<Tag::Ptr>(result.tags, tag)) {
if (kernel) // Reuse tags from given storage
tag = kernel->storage()->tag(tag->name());
if (kernel) { // Reuse tags from given storage
if (Tag::Ptr tag2 = kernel->storage()->tag(tag->name(), /*create=*/ false)) {
tag = tag2;
}
}

result.tags << tag;
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,26 @@ void Storage::load()
createTag(tr("books"), QStringLiteral("{b2697470-f457-461c-9310-7d4b56aea395}"));
createTag(tr("movies"), QStringLiteral("{387be44a-1eb7-4895-954a-cf5bc82d8f03}"));
}

m_loadingInProgress = false;

verifyLoadedData();

emit taskCountChanged();
}

void Storage::verifyLoadedData()
{
foreach (const Tag::Ptr &tag, m_data.tags) {
if (tag->uuid(/*createIfEmpty=*/false).isEmpty()) {
qWarning() << Q_FUNC_INFO << "No uuid for tag" << tag;
#ifdef UNIT_TEST_RUN
// Q_ASSERT(false);
#endif
}
}
}

void Storage::save()
{
#if defined(UNIT_TEST_RUN)
Expand Down
1 change: 1 addition & 0 deletions src/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private Q_SLOTS:
virtual void save_impl() = 0;

private:
void verifyLoadedData();
void connectTask(const Task::Ptr &);
int proxyRowToSource(int proxyIndex) const;
QTimer m_scheduleTimer;
Expand Down
8 changes: 5 additions & 3 deletions src/syncable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ void Syncable::setRevisionOnWebDAVServer(int revision)
m_revisionOnWebDAVServer = revision;
}

QString Syncable::uuid() const
QString Syncable::uuid(bool createIfEmpty) const
{
if (m_uuid.isEmpty()) // Delayed creation, since it can be expensive and we don't need to create it in CTOR because it's going to be set when loading
if (createIfEmpty && m_uuid.isEmpty()) // Delayed creation, since it can be expensive and we don't need to create it in CTOR because it's going to be set when loading
m_uuid = QUuid::createUuid().toString();

return m_uuid;
Expand All @@ -75,8 +75,10 @@ void Syncable::fromJson(const QVariantMap &map)
parseUnknownFields(map);

QString uuid = map.value(QStringLiteral("uuid")).toString();
if (uuid.isEmpty())
if (uuid.isEmpty()) {
qWarning() << Q_FUNC_INFO << "Tag doesn't have uuid, creating one:" << this;
uuid = QUuid::createUuid().toString();
}
setUuid(uuid);
setRevision(map.value(QStringLiteral("revision"), 0).toInt());
setRevisionOnWebDAVServer(map.value(QStringLiteral("revisionOnWebDAVServer"), -1).toInt());
Expand Down
4 changes: 2 additions & 2 deletions src/syncable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Syncable
int revision() const;
int revisionOnWebDAVServer() const;
void setRevisionOnWebDAVServer(int);
QString uuid() const;
QString uuid(bool createIfEmpty = true) const;
void setUuid(const QString &uuid);

virtual void fromJson(const QVariantMap &);
Expand All @@ -48,7 +48,7 @@ class Syncable
mutable QString m_uuid;

private:
Q_DISABLE_COPY(Syncable);
Q_DISABLE_COPY(Syncable)
void parseUnknownFields(const QVariantMap &);
};

Expand Down
2 changes: 1 addition & 1 deletion src/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ inline QDebug operator<<(QDebug dbg, const Tag::Ptr &tag)
if (!tag)
return dbg;

dbg.nospace() << "Tag: uuid=" << tag->uuid()
dbg.nospace() << "Tag: uuid=" << tag->uuid(false)
<< "; name=" << tag->name()
<< "; rev=" << tag->revision();
return dbg.space();
Expand Down
4 changes: 3 additions & 1 deletion src/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ Task::Task(Kernel *kernel, const QString &summary)
connect(this, &Task::dueDateChanged, &Task::onEdited);
connect(this, &Task::priorityChanged, &Task::onEdited);

connect(this, &Task::dueDateChanged, &Task::dueDateDisplayTextChanged);

connect(kernel, &Kernel::dayChanged, this, &Task::onDayChanged);

#if defined(UNIT_TEST_RUN)
Expand Down Expand Up @@ -537,7 +539,7 @@ void Task::onEdited()
void Task::onDayChanged()
{
if (m_dueDate.isValid()) {
emit dueDateChanged();
emit dueDateDisplayTextChanged();
if (dueToday() || isOverdue())
setStaged(true);
}
Expand Down
21 changes: 11 additions & 10 deletions src/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class Task : public QObject, public Syncable {
Q_PROPERTY(bool isUrl READ isUrl NOTIFY summaryChanged)
Q_PROPERTY(QString priorityStr READ priorityStr NOTIFY priorityChanged)
Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
Q_PROPERTY(bool dueToday READ dueToday NOTIFY dueDateChanged)
Q_PROPERTY(bool isOverdue READ isOverdue NOTIFY dueDateChanged)
Q_PROPERTY(QString prettyDueDateString READ prettyDueDateString NOTIFY dueDateChanged)
Q_PROPERTY(QString prettyDueDateRecurString READ prettyDueDateRecurString NOTIFY dueDateChanged)
Q_PROPERTY(QString dueDateString READ dueDateString NOTIFY dueDateChanged)
Q_PROPERTY(QDate dueDate READ dueDate WRITE setDueDate NOTIFY dueDateChanged)
Q_PROPERTY(bool dueToday READ dueToday NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(bool isOverdue READ isOverdue NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(QString prettyDueDateString READ prettyDueDateString NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(QString prettyDueDateRecurString READ prettyDueDateRecurString NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(QString dueDateString READ dueDateString NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(QDate dueDate READ dueDate WRITE setDueDate NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(int daysSinceLastPomodoro READ daysSinceLastPomodoro NOTIFY daysSinceLastPomodoroChanged)
Q_PROPERTY(int daysSinceCreation READ daysSinceCreation NOTIFY daysSinceCreationChanged)
Q_PROPERTY(bool staged READ staged WRITE setStaged NOTIFY stagedChanged)
Expand All @@ -79,10 +79,10 @@ class Task : public QObject, public Syncable {

Q_PROPERTY(TaskContextMenuModel* contextMenuModel READ contextMenuModel CONSTANT)
Q_PROPERTY(SortedTaskContextMenuModel* sortedContextMenuModel READ sortedContextMenuModel CONSTANT)
Q_PROPERTY(int periodType READ periodType NOTIFY dueDateChanged)
Q_PROPERTY(bool recurs READ recurs NOTIFY dueDateChanged)
Q_PROPERTY(uint frequency READ frequency WRITE setFrequency NOTIFY dueDateChanged)
Q_PROPERTY(QString frequencyWord READ frequencyWord NOTIFY dueDateChanged)
Q_PROPERTY(int periodType READ periodType NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(bool recurs READ recurs NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(uint frequency READ frequency WRITE setFrequency NOTIFY dueDateDisplayTextChanged)
Q_PROPERTY(QString frequencyWord READ frequencyWord NOTIFY dueDateDisplayTextChanged)

public:
typedef QSharedPointer<Task> Ptr;
Expand Down Expand Up @@ -206,6 +206,7 @@ public Q_SLOTS:
void changed();
void tagToggled(const QString &tag);
void dueDateChanged();
void dueDateDisplayTextChanged();

protected:
QVector<QString> supportedFields() const Q_DECL_OVERRIDE;
Expand Down
6 changes: 3 additions & 3 deletions tests/testtagmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void TestTagModel::testFromFile_data()
QStringList expectedSignals;
QStringList expectedSignalsInUnsortedModel;
for (int i = 0; i < expectedNumTags; ++i) {
expectedSignals << "rowsAboutToBeInserted" << "rowsInserted";
expectedSignalsInUnsortedModel << "rowsAboutToBeInserted" << "rowsInserted";
// expectedSignals << "rowsAboutToBeInserted" << "rowsInserted";
// expectedSignalsInUnsortedModel << "rowsAboutToBeInserted" << "rowsInserted";
}

expectedSignals << "modelAboutToBeReset" << "modelReset" // Because of final assignment when loading
Expand Down Expand Up @@ -110,7 +110,7 @@ void TestTagModel::testFromFile()
// qDebug() << "tag " << tag->name() << tag->taskCount();
}

//spy->dumpDebugInfo();
// tagsModelSpy->dumpDebugInfo();
QCOMPARE(tagsModelSpy->count(), expectedSignals.count());

for (int i = 0; i < expectedSignals.count(); ++i) {
Expand Down

0 comments on commit 9454317

Please sign in to comment.