NoteBook.cpp Example File
notebook/src/NoteBook.cpp
#include "NoteBook.hpp"
#include "NoteEditor.hpp"
#include "NoteViewer.hpp"
#include <bb/pim/notebook/NotebookEntry>
using namespace bb::cascades;
using namespace bb::pim::notebook;
NoteBook::NoteBook(QObject *parent)
: QObject(parent)
, m_notebookService(new NotebookService(this))
, m_model(new GroupDataModel(this))
, m_noteViewer(new NoteViewer(m_notebookService, this))
, m_noteEditor(new NoteEditor(m_notebookService, this))
{
m_model->setGrouping(ItemGrouping::None);
bool ok = connect(m_notebookService, SIGNAL(notebookEntriesAdded(QList<bb::pim::notebook::NotebookEntryId>)), SLOT(filterNotes()));
Q_ASSERT(ok);
ok = connect(m_notebookService, SIGNAL(notebookEntriesUpdated(QList<bb::pim::notebook::NotebookEntryId>)), SLOT(filterNotes()));
Q_ASSERT(ok);
ok = connect(m_notebookService, SIGNAL(notebookEntriesDeleted(QList<bb::pim::notebook::NotebookEntryId>)), SLOT(filterNotes()));
Q_ASSERT(ok);
filterNotes();
}
void NoteBook::setCurrentNote(const QVariantList &indexPath)
{
if (indexPath.isEmpty()) {
m_currentNoteId = NotebookEntryId();
} else {
const QVariantMap entry = m_model->data(indexPath).toMap();
m_currentNoteId = entry.value("noteId").value<NotebookEntryId>();
}
}
void NoteBook::createNote()
{
m_noteEditor->reset();
m_noteEditor->setMode(NoteEditor::CreateMode);
}
void NoteBook::editNote()
{
m_noteEditor->loadNote(m_currentNoteId);
m_noteEditor->setMode(NoteEditor::EditMode);
}
void NoteBook::viewNote()
{
m_noteViewer->setNoteId(m_currentNoteId);
}
void NoteBook::deleteNote()
{
m_notebookService->deleteNotebookEntry(m_currentNoteId);
}
bb::cascades::GroupDataModel* NoteBook::model() const
{
return m_model;
}
QString NoteBook::filter() const
{
return m_filter;
}
void NoteBook::setFilter(const QString &filter)
{
if (m_filter == filter)
return;
m_filter = filter;
emit filterChanged();
filterNotes();
}
NoteViewer* NoteBook::noteViewer() const
{
return m_noteViewer;
}
NoteEditor* NoteBook::noteEditor() const
{
return m_noteEditor;
}
void NoteBook::filterNotes()
{
NotebookEntryFilter filter;
filter.setSearchString(m_filter);
const QList<NotebookEntry> notes = m_notebookService->notebookEntries(filter);
m_model->clear();
foreach (const NotebookEntry ¬e, notes) {
QVariantMap entry;
entry["noteId"] = QVariant::fromValue(note.id());
entry["title"] = note.title();
entry["status"] = NoteViewer::statusToString(note.status());
m_model->insert(entry);
}
}