10#include <KLocalizedString>
11#include <knewstuffcore_debug.h>
13#include "enginebase.h"
14#include "imageloader_p.h"
18class ItemsModelPrivate
21 ItemsModelPrivate(EngineBase *e)
25 EngineBase *
const engine;
28 bool hasPreviewImages =
false;
30ItemsModel::ItemsModel(EngineBase *engine,
QObject *parent)
32 , d(new ItemsModelPrivate(engine))
36ItemsModel::~ItemsModel() =
default;
40 return d->entries.count();
48 Entry entry = d->entries[
index.
row()];
52int ItemsModel::row(
const Entry &entry)
const
54 return d->entries.indexOf(entry);
64void ItemsModel::addEntry(
const Entry &entry)
67 if (!d->entries.contains(entry)) {
68 QString preview = entry.previewUrl(Entry::PreviewSmall1);
69 if (!d->hasPreviewImages && !preview.
isEmpty()) {
70 d->hasPreviewImages =
true;
76 qCDebug(KNEWSTUFFCORE) <<
"adding entry " << entry.name() <<
" to the model";
78 d->entries.append(entry);
81 if (!preview.
isEmpty() && entry.previewImage(Entry::PreviewSmall1).isNull()) {
82 Q_EMIT loadPreview(entry, Entry::PreviewSmall1);
87void ItemsModel::removeEntry(
const Entry &entry)
89 qCDebug(KNEWSTUFFCORE) <<
"removing entry " << entry.name() <<
" from the model";
90 int index = d->entries.indexOf(entry);
93 d->entries.removeAt(
index);
98void ItemsModel::slotEntryChanged(
const Entry &entry)
100 int i = d->entries.indexOf(entry);
108void ItemsModel::clearEntries()
115void ItemsModel::slotEntryPreviewLoaded(
const Entry &entry, Entry::PreviewType type)
118 if (type == Entry::PreviewSmall1) {
119 slotEntryChanged(entry);
123bool ItemsModel::hasPreviewImages()
const
125 return d->hasPreviewImages;
130#include "moc_itemsmodel.cpp"
KNewStuff data entry container.
void beginInsertRows(const QModelIndex &parent, int first, int last)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QList< int > &roles)
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
bool isEmpty() const const
QVariant fromValue(T &&value)