mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
BookmarkItem: Revert to caching icon for 20 seconds
This commit is contained in:
parent
b7c5b6758d
commit
13a6573ecb
|
@ -70,12 +70,16 @@ QList<BookmarkItem*> BookmarkItem::children() const
|
|||
return m_children;
|
||||
}
|
||||
|
||||
QIcon BookmarkItem::icon(bool load)
|
||||
QIcon BookmarkItem::icon()
|
||||
{
|
||||
// Cache icon for 20 seconds
|
||||
const int iconCacheTime = 20 * 1000;
|
||||
|
||||
switch (m_type) {
|
||||
case Url:
|
||||
if (load && m_icon.isNull()) {
|
||||
setIcon(IconProvider::iconForUrl(m_url));
|
||||
if (m_iconTime.isNull() || m_iconTime.elapsed() > iconCacheTime) {
|
||||
m_icon = IconProvider::iconForUrl(m_url);
|
||||
m_iconTime.restart();
|
||||
}
|
||||
return m_icon;
|
||||
case Folder:
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
BookmarkItem* parent() const;
|
||||
QList<BookmarkItem*> children() const;
|
||||
|
||||
QIcon icon(bool load = true);
|
||||
QIcon icon();
|
||||
void setIcon(const QIcon &icon);
|
||||
|
||||
QString urlString() const;
|
||||
|
|
|
@ -131,7 +131,7 @@ QVariant BookmarksModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() == 0) {
|
||||
return itm->icon(false);
|
||||
return itm->icon();
|
||||
}
|
||||
return QVariant();
|
||||
default:
|
||||
|
@ -139,23 +139,6 @@ QVariant BookmarksModel::data(const QModelIndex &index, int role) const
|
|||
}
|
||||
}
|
||||
|
||||
bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
BookmarkItem *itm = item(index);
|
||||
|
||||
if (!itm) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (role == IconRole) {
|
||||
itm->setIcon(value.value<QIcon>());
|
||||
emit dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant BookmarksModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
||||
|
|
|
@ -54,7 +54,6 @@ public:
|
|||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QVariant data(const QModelIndex &index, int role) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role);
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
int rowCount(const QModelIndex &parent) const;
|
||||
int columnCount(const QModelIndex &parent) const;
|
||||
|
|
|
@ -289,16 +289,3 @@ void BookmarksTreeView::keyPressEvent(QKeyEvent* event)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksTreeView::drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const
|
||||
{
|
||||
bool itemIsUrl = BookmarkItem::Type(index.data(BookmarksModel::TypeRole).toInt()) == BookmarkItem::Url;
|
||||
bool iconLoaded = !index.data(BookmarksModel::IconRole).value<QIcon>().isNull();
|
||||
|
||||
if (itemIsUrl && !iconLoaded) {
|
||||
const QPersistentModelIndex idx = index;
|
||||
model()->setData(idx, IconProvider::iconForUrl(index.data(BookmarksModel::UrlRole).toUrl()), BookmarksModel::IconRole);
|
||||
}
|
||||
|
||||
QTreeView::drawRow(painter, options, index);
|
||||
}
|
||||
|
|
|
@ -82,8 +82,6 @@ private:
|
|||
void mouseDoubleClickEvent(QMouseEvent* event);
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
|
||||
void drawRow(QPainter* painter, const QStyleOptionViewItem &options, const QModelIndex &index) const;
|
||||
|
||||
Bookmarks* m_bookmarks;
|
||||
BookmarksModel* m_model;
|
||||
BookmarksFilterModel* m_filter;
|
||||
|
|
Loading…
Reference in New Issue
Block a user