Fix removing feeds

This commit is contained in:
Tobias Fella 2020-09-02 22:54:09 +02:00
parent c3b3a9505e
commit c393955c10
2 changed files with 6 additions and 7 deletions

View File

@ -58,24 +58,23 @@ QVariant FeedListModel::data(const QModelIndex &index, int role) const
{ {
if (role != 0) if (role != 0)
return QVariant(); return QVariant();
if (m_feeds[index.row()] == nullptr) if (m_feeds.length() <= index.row())
loadFeed(index.row()); loadFeed(index.row());
return QVariant::fromValue(m_feeds[index.row()]); return QVariant::fromValue(m_feeds[index.row()]);
} }
void FeedListModel::loadFeed(int index) const void FeedListModel::loadFeed(int index) const
{ {
m_feeds[index] = new Feed(index); m_feeds += new Feed(index);
} }
void FeedListModel::removeFeed(int index) void FeedListModel::removeFeed(int index)
{ {
Feed *feed = m_feeds[index]; m_feeds[index]->remove();
delete m_feeds[index];
beginRemoveRows(QModelIndex(), index, index); beginRemoveRows(QModelIndex(), index, index);
m_feeds[index] = nullptr; m_feeds.removeAt(index);
endRemoveRows(); endRemoveRows();
feed->remove();
delete feed;
} }
void FeedListModel::refreshAll() void FeedListModel::refreshAll()

View File

@ -28,5 +28,5 @@ public:
private: private:
void loadFeed(int index) const; void loadFeed(int index) const;
mutable QHash<int, Feed *> m_feeds; mutable QVector<Feed *> m_feeds;
}; };