Esempio n. 1
0
//! [1]
void NoteViewer::updateNote()
{
    // Store previous values
    const QString oldTitle = m_title;
    const QString oldDescription = m_description;
    const QDateTime oldDueDateTime = m_dueDateTime;
    const NotebookEntryStatus::Type oldStatus = m_status;

    // Fetch new values from persistent storage
    const NotebookEntry note = m_notebookService->notebookEntry(m_noteId);

    m_title = note.title();
    m_description = note.description().plainText();
    m_dueDateTime = note.dueDateTime();
    m_status = note.status();

    // Check whether values have changed
    if (oldTitle != m_title)
        emit titleChanged();

    if (oldDescription != m_description)
        emit descriptionChanged();

    if (oldDueDateTime != m_dueDateTime)
        emit dueDateTimeChanged();

    if (oldStatus != m_status)
        emit statusChanged();
}
Esempio n. 2
0
//! [2]
void FormEditor::loadNote(const NotebookEntryId &noteId)
{
    m_noteId = noteId;

    // Load the note from the persistent storage
    const NotebookEntry note = m_notebookService->notebookEntry(m_noteId);

    // Update the properties with the data from the note
    m_title = note.title();
    m_description = note.description();
    m_dueDateTime = note.dueDateTime();
    m_completed = (note.status() == NotebookEntryStatus::Completed);

    // Emit the change notifications
    emit titleChanged();
    emit descriptionChanged();
    emit dueDateTimeChanged();
    emit completedChanged();
}
Esempio n. 3
0
//! [3]
void FormEditor::saveNote()
{
    if (m_mode == CreateMode) {
        NotebookEntry *note = new NotebookEntry;

        note->setTitle(m_title);
        note->setDescription(m_description);
        note->setDueDateTime(m_dueDateTime);
        note->setStatus(m_completed ? NotebookEntryStatus::Completed : NotebookEntryStatus::NotCompleted);

        // Save the note to persistent storage (always store in system default notebook)
        m_notebookService->addNotebookEntry(note, m_notebookService->defaultNotebook().id());

    } else if (m_mode == EditMode) {
        // Load the note from persistent storage
        NotebookEntry note = m_notebookService->notebookEntry(m_noteId);

        if (note.isValid()) {
            // Update the single attributes
            note.setTitle(m_title);
            note.setDescription(m_description);
            note.setDueDateTime(m_dueDateTime);
            note.setStatus(m_completed ? NotebookEntryStatus::Completed : NotebookEntryStatus::NotCompleted);

            // Save the updated note back to persistent storage
            m_notebookService->updateNotebookEntry(note);
        }
    }
}