kasts/src/feedsmodel.cpp

62 lines
1.5 KiB
C++
Raw Normal View History

2020-02-28 23:25:08 +01:00
/**
2020-08-14 20:56:04 +02:00
* SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
2020-02-28 23:25:08 +01:00
*
2020-08-14 20:56:04 +02:00
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
2020-02-28 23:25:08 +01:00
*/
2020-04-18 21:07:49 +02:00
#include <QDebug>
#include <QModelIndex>
2020-05-26 16:32:07 +02:00
#include <QSqlQuery>
2020-04-22 02:17:57 +02:00
#include <QUrl>
2020-05-26 16:32:07 +02:00
#include <QVariant>
2020-02-28 23:25:08 +01:00
2020-04-22 02:17:57 +02:00
#include "database.h"
#include "datamanager.h"
2020-10-09 13:47:35 +02:00
#include "feedsmodel.h"
2020-02-28 23:25:08 +01:00
#include "fetcher.h"
2020-03-16 22:37:04 +01:00
2020-10-09 13:47:35 +02:00
FeedsModel::FeedsModel(QObject *parent)
2020-05-26 16:32:07 +02:00
: QAbstractListModel(parent)
2020-02-28 23:25:08 +01:00
{
connect(&DataManager::instance(), &DataManager::feedAdded, this, [this]() {
2020-05-26 16:32:07 +02:00
beginInsertRows(QModelIndex(), rowCount(QModelIndex()) - 1, rowCount(QModelIndex()) - 1);
endInsertRows();
});
connect(&DataManager::instance(), &DataManager::feedRemoved, this, [this](const int &index) {
beginRemoveRows(QModelIndex(), index, index);
endRemoveRows();
2020-05-26 16:32:07 +02:00
});
2020-02-28 23:25:08 +01:00
}
2020-10-09 13:47:35 +02:00
QHash<int, QByteArray> FeedsModel::roleNames() const
2020-02-28 23:25:08 +01:00
{
QHash<int, QByteArray> roleNames;
2020-05-26 16:32:07 +02:00
roleNames[0] = "feed";
2020-02-28 23:25:08 +01:00
return roleNames;
}
2020-10-09 13:47:35 +02:00
int FeedsModel::rowCount(const QModelIndex &parent) const
2020-02-28 23:25:08 +01:00
{
Q_UNUSED(parent);
return DataManager::instance().feedCount();
2020-02-28 23:25:08 +01:00
}
2020-04-18 21:07:49 +02:00
2020-10-09 13:47:35 +02:00
QVariant FeedsModel::data(const QModelIndex &index, int role) const
2020-02-28 23:25:08 +01:00
{
2020-05-26 16:32:07 +02:00
if (role != 0)
return QVariant();
return QVariant::fromValue(DataManager::instance().getFeed(index.row()));
2020-05-26 16:32:07 +02:00
}
2020-05-18 17:02:46 +02:00
2020-10-09 13:47:35 +02:00
void FeedsModel::removeFeed(int index)
2020-05-26 16:32:07 +02:00
{
DataManager::instance().removeFeed(index);
2020-02-28 23:25:08 +01:00
}
2020-10-09 13:47:35 +02:00
void FeedsModel::refreshAll()
{
// for (auto &feed : m_feeds) {
// feed->refresh();
// }
2020-06-09 23:57:24 +02:00
}