Show authors in EntryList
This commit is contained in:
parent
dd27c1d3ab
commit
06df8c0f5d
@ -20,6 +20,7 @@
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QVector>
|
||||
#include <QSqlQuery>
|
||||
|
||||
#include "database.h"
|
||||
#include "entryListModel.h"
|
||||
@ -40,6 +41,18 @@ EntryListModel::EntryListModel(QObject *parent)
|
||||
|
||||
QVariant EntryListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if(role == Authors) {
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT name FROM Authors WHERE id=:id"));
|
||||
query.bindValue(QStringLiteral(":id"), data(index, Id));
|
||||
Database::instance().execute(query);
|
||||
QStringList authors;
|
||||
while(query.next()) {
|
||||
authors += query.value(0).toString();
|
||||
}
|
||||
return authors;
|
||||
}
|
||||
|
||||
if (role == Updated || role == Created) {
|
||||
QDateTime updated;
|
||||
updated.setSecsSinceEpoch(QSqlTableModel::data(createIndex(index.row(), role), 0).toInt());
|
||||
@ -58,6 +71,7 @@ QHash<int, QByteArray> EntryListModel::roleNames() const
|
||||
roleNames[Created] = "created";
|
||||
roleNames[Updated] = "updated";
|
||||
roleNames[Link] = "link";
|
||||
roleNames[Authors] = "authors";
|
||||
return roleNames;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
Created,
|
||||
Updated,
|
||||
Link,
|
||||
Authors,
|
||||
};
|
||||
explicit EntryListModel(QObject *parent = nullptr);
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
@ -89,7 +89,7 @@ Kirigami.ScrollablePage {
|
||||
|
||||
delegate: Kirigami.BasicListItem {
|
||||
text: model.title
|
||||
subtitle: model.updated.toLocaleString(Qt.locale(), Locale.ShortFormat)
|
||||
subtitle: model.updated.toLocaleString(Qt.locale(), Locale.ShortFormat) + (model.authors.length === 0 ? "" : " " + i18nc("by <author(s)>", "by") + " " + model.authors.join(", "))
|
||||
|
||||
onClicked: {
|
||||
model.read = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user