Expose Enclosures to QML
This commit is contained in:
parent
1129d4c0f2
commit
649c6a1e10
@ -39,6 +39,9 @@ EntryListModel::EntryListModel(QObject *parent)
|
||||
|
||||
QVariant EntryListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Enclosure) {
|
||||
return enclosure(data(index, Id).toString());
|
||||
}
|
||||
if (role == Authors) {
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT name FROM Authors WHERE id=:id"));
|
||||
@ -59,6 +62,15 @@ QVariant EntryListModel::data(const QModelIndex &index, int role) const
|
||||
return QSqlTableModel::data(createIndex(index.row(), role), 0);
|
||||
}
|
||||
|
||||
QString EntryListModel::enclosure(QString id) const
|
||||
{
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("SELECT url from Enclosures WHERE id=:id;"));
|
||||
query.bindValue(QStringLiteral(":id"), id);
|
||||
Database::instance().execute(query);
|
||||
return query.next() ? query.value(0).toString() : QLatin1String("");
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> EntryListModel::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roleNames;
|
||||
@ -70,6 +82,7 @@ QHash<int, QByteArray> EntryListModel::roleNames() const
|
||||
roleNames[Updated] = "updated";
|
||||
roleNames[Link] = "link";
|
||||
roleNames[Authors] = "authors";
|
||||
roleNames[Enclosure] = "enclosure";
|
||||
return roleNames;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
Updated,
|
||||
Link,
|
||||
Authors,
|
||||
Enclosure,
|
||||
};
|
||||
explicit EntryListModel(QObject *parent = nullptr);
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
@ -55,4 +56,6 @@ Q_SIGNALS:
|
||||
|
||||
private:
|
||||
QString m_feed;
|
||||
|
||||
QString enclosure(QString id) const;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user