Find entry by title.

This commit is contained in:
Louis-Bertrand Varin 2017-05-21 13:51:16 -04:00
parent 54ad927044
commit eeafe77614
2 changed files with 20 additions and 1 deletions

View File

@ -497,7 +497,18 @@ Entry* Group::findEntry(QString entryId)
}
}
return findEntryByPath(entryId);
Entry* entry = findEntryByPath(entryId);
if (entry) {
return entry;
}
for (Entry* entry : entriesRecursive(false)) {
if (entry->title() == entryId) {
return entry;
}
}
return nullptr;
}
Entry* Group::findEntryByUuid(const Uuid& uuid)

View File

@ -606,9 +606,17 @@ void TestGroup::testFindEntry()
QVERIFY(entry != nullptr);
QCOMPARE(entry->title(), QString("entry2"));
// Should also find the entry only by title.
entry = db->rootGroup()->findEntry(QString("entry2"));
QVERIFY(entry != nullptr);
QCOMPARE(entry->title(), QString("entry2"));
entry = db->rootGroup()->findEntry(QString("invalid/path/to/entry2"));
QVERIFY(entry == nullptr);
entry = db->rootGroup()->findEntry(QString("entry27"));
QVERIFY(entry == nullptr);
// A valid UUID that does not exist in this database.
entry = db->rootGroup()->findEntry(QString("febfb01ebcdf9dbd90a3f1579dc75281"));
QVERIFY(entry == nullptr);