Example #1
0
void TestTags::test_tag_item() {
	Tags tags;
	tags.append("Work");
	tags.append("Home");

	Person *person = new Person;
	person->setName("Moe stein");
	person->save();

	tags.tag(RelationalObjectRef(person), tags.getObjectRef(0));

	QMap<int, QString> item_tags = tags.itemTags(RelationalObjectRef(person));

	QCOMPARE(item_tags.size(), 1);
	QVERIFY(item_tags.contains(1));
	QCOMPARE(item_tags.value(1), QString("Work"));

	tags.tag(RelationalObjectRef(person), tags.getObjectRef(1));

	item_tags = tags.itemTags(RelationalObjectRef(person));
	QCOMPARE(item_tags.size(), 2);
	QVERIFY(item_tags.contains(2));
	QCOMPARE(item_tags.value(2), QString("Home"));

	tags.tag(RelationalObjectRef(person), tags.getObjectRef(1));
	item_tags = tags.itemTags(RelationalObjectRef(person));
	QCOMPARE(item_tags.size(), 2);

	tags.untag(RelationalObjectRef(person), tags.getObjectRef(0));
	item_tags = tags.itemTags(RelationalObjectRef(person));
	QCOMPARE(item_tags.size(), 1);
	QVERIFY(not item_tags.contains(1));

	delete person;
}
Example #2
0
ItemTagsLoader::Tags ItemTagsLoader::toTags(const QStringList &tagList)
{
    Tags tags;

    for (const auto &tagText : tagList) {
        QString tagName = tagText.trimmed();
        Tag tag = findMatchingTag(tagName, m_tags);

        if (isTagValid(tag)) {
            if (tag.match.isEmpty()) {
                tag.name = tagName;
            } else {
                const QRegExp re(tag.match);
                tag.name = QString(tagName).replace(re, tag.name);
            }
        } else {
            tag.name = tagName;

            // Get default tag style from theme.
            const QSettings settings;
            tag.color = settings.value("Theme/num_fg").toString();
        }

        tags.append(tag);
    }

    return tags;
}
Example #3
0
void TestTags::test_item_tags_model() {
	Tags tags;
	tags.append("Work");
	tags.append("Home");

	Person *person = new Person;
	person->setName("Moe stein");
	person->save();

	RelationalObjectRef person_ref(person);
	RelationalObjectRef tag1 = tags.getObjectRef(0);
	RelationalObjectRef tag2 = tags.getObjectRef(1);

	ItemTags *item_tags = tags.itemTagsModelFactory(person_ref);

	item_tags->tag(tag1);
	QCOMPARE(item_tags->rowCount(), 1);

	item_tags->untag(tag2);
	QCOMPARE(item_tags->rowCount(), 1);

	item_tags->tag(tag2);
	QCOMPARE(item_tags->rowCount(), 2);

	item_tags->untag(tag1);
	QCOMPARE(item_tags->rowCount(), 1);

	item_tags->untag(tag2);
	QCOMPARE(item_tags->rowCount(), 0);

	delete item_tags;
	delete person;
}