~rpadovani/reminders-app/1382730

« back to all changes in this revision

Viewing changes to src/plugin/Evernote/tag.cpp

  • Committer: Tarmac
  • Author(s): Michael Zanetti
  • Date: 2014-10-11 16:31:17 UTC
  • mfrom: (266.2.6 reminders-app-tags)
  • Revision ID: tarmac-20141011163117-k34jgx6jk5zizxpw
Add support for tags. Fixes: https://bugs.launchpad.net/bugs/1379747.

Approved by Riccardo Padovani, Ubuntu Phone Apps Jenkins Bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright: 2014 Canonical, Ltd
 
3
 *
 
4
 * This file is part of reminders
 
5
 *
 
6
 * reminders is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; version 3.
 
9
 *
 
10
 * reminders is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
 *
 
18
 * Authors: Michael Zanetti <michael.zanetti@canonical.com>
 
19
 */
 
20
 
 
21
#include "tag.h"
 
22
#include "note.h"
 
23
 
 
24
#include "notesstore.h"
 
25
 
 
26
Tag::Tag(const QString &guid, QObject *parent) :
 
27
    QObject(parent),
 
28
    m_guid(guid),
 
29
    m_noteCount(0)
 
30
{
 
31
    updateNoteCount();
 
32
}
 
33
 
 
34
Tag::~Tag()
 
35
{
 
36
}
 
37
 
 
38
QString Tag::guid() const
 
39
{
 
40
    return m_guid;
 
41
}
 
42
 
 
43
QString Tag::name() const
 
44
{
 
45
    return m_name;
 
46
}
 
47
 
 
48
void Tag::setName(const QString &name)
 
49
{
 
50
    if (m_name != name) {
 
51
        m_name = name;
 
52
        emit nameChanged();
 
53
    }
 
54
}
 
55
 
 
56
int Tag::noteCount() const
 
57
{
 
58
    return m_noteCount;
 
59
}
 
60
 
 
61
Tag *Tag::clone()
 
62
{
 
63
    Tag *tag = new Tag(m_guid);
 
64
    tag->setName(m_name);
 
65
    return tag;
 
66
}
 
67
 
 
68
void Tag::updateNoteCount()
 
69
{
 
70
    int noteCount = 0;
 
71
    foreach (Note *note, NotesStore::instance()->notes()) {
 
72
        if (note->tagGuids().contains(m_guid)) {
 
73
            noteCount++;
 
74
        }
 
75
    }
 
76
    if (m_noteCount != noteCount) {
 
77
        m_noteCount = noteCount;
 
78
        emit noteCountChanged();
 
79
    }
 
80
}