uonedb-qt team mailing list archive
-
uonedb-qt team
-
Mailing list archive
-
Message #00305
[Merge] lp:~kalikiana/u1db-qt/indexRoles into lp:u1db-qt
Christian Dywan has proposed merging lp:~kalikiana/u1db-qt/indexRoles into lp:u1db-qt.
Commit message:
Expose index fields as role names
Requested reviews:
U1DB Qt developers (uonedb-qt)
For more details, see:
https://code.launchpad.net/~kalikiana/u1db-qt/indexRoles/+merge/211771
--
https://code.launchpad.net/~kalikiana/u1db-qt/indexRoles/+merge/211771
Your team U1DB Qt developers is requested to review the proposed merge of lp:~kalikiana/u1db-qt/indexRoles into lp:u1db-qt.
=== modified file 'examples/bookmarks/bookmarks.qml'
--- examples/bookmarks/bookmarks.qml 2014-02-17 17:40:42 +0000
+++ examples/bookmarks/bookmarks.qml 2014-03-19 16:23:32 +0000
@@ -123,8 +123,8 @@
property string detailsDocId: ""
property string detailsContents: ""
delegate: ListItem.Subtitled {
- text: contents.title || '[title:%1]'.arg(docId)
- subText: contents.uri || '[uri:%1]'.arg(docId)
+ text: title
+ subText: uri
// iconSource: contents.uri + "/favicon.ico"
fallbackIconName: "favorite-unselected,text-html"
iconFrame: false
@@ -147,7 +147,7 @@
ListElement { label: 'Ubuntu'; expression: "[ 'uri' ]"; query: "[ 'http://www.ubuntu*' ]" }
ListElement { label: 'Search'; expression: "[ 'meta.title' ]"; query: "[ 'Search*' ]" }
ListElement { label: 'Engine'; expression: "[ 'meta.tags' ]"; query: "[ 'engine' ]" }
- ListElement { label: 'All'; expression: "[ 'meta.visits', 'meta.title' ]"; query: "[ '*', '*' ]" }
+ ListElement { label: 'All'; expression: "[ 'meta.visits', 'meta.title', 'uri' ]"; query: "[ '*', '*', '*' ]" }
}
delegate: OptionSelectorDelegate {
text: i18n.tr(label)
@@ -156,8 +156,11 @@
onSelectedIndexChanged: {
var d = model.get(selectedIndex)
text = '%1 - %2'.arg(d.expression).arg(d.query)
+ bookmarksList.model = null
allBookmarks.index.expression = eval(d.expression)
allBookmarks.query = eval(d.query)
+ // Force update of delegates and role names
+ bookmarksList.model = allBookmarks
}
}
}
=== modified file 'src/query.cpp'
--- src/query.cpp 2014-03-13 19:31:58 +0000
+++ src/query.cpp 2014-03-19 16:23:32 +0000
@@ -64,7 +64,11 @@
return m_results.at(index.row());
if (role == 1) // docId
return m_documents.at(index.row());
- return QVariant();
+
+ int indexForRole = role - 2;
+ QVariantMap result(m_results.at(index.row()).toMap());
+ QString field(m_index->getExpression().at(indexForRole).split(".").last());
+ return result.value(field);
}
/*!
@@ -79,6 +83,14 @@
QHash<int, QByteArray> roles;
roles.insert(0, "contents");
roles.insert(1, "docId");
+ if (!m_index)
+ return roles;
+
+ // A role name for each field in the index
+ uint fieldRole = 2;
+ Q_FOREACH(QString field, m_index->getExpression())
+ roles.insert(fieldRole++, field.split(".").last().toUtf8());
+ qDebug() << roles;
return roles;
}
Follow ups