Skip to content

Commit

Permalink
try to fix #39 and #37
Browse files Browse the repository at this point in the history
  • Loading branch information
derselbst committed Feb 19, 2023
1 parent f9eb8d8 commit 8c3a058
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/models/SortedImageModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct SortedImageModel::Impl
int cachedIconHeight = 1;
std::atomic<ViewFlags_t> cachedViewFlags{ static_cast<ViewFlags_t>(ViewFlag::None) };

QTimer layoutChangedTimer;
QPointer<QTimer> layoutChangedTimer;

Impl(SortedImageModel* parent) : q(parent)
{}
Expand Down Expand Up @@ -82,7 +82,7 @@ struct SortedImageModel::Impl
Q_ASSERT(!future.isNull());
future->waitForFinished();
}
layoutChangedTimer.stop();
layoutChangedTimer->stop();
backgroundTasks.clear();
QMetaObject::invokeMethod(ANPV::globalInstance()->spinningIconHelper(), &ProgressIndicatorHelper::stopRendering);
}
Expand All @@ -98,9 +98,9 @@ struct SortedImageModel::Impl
void updateLayout()
{
xThreadGuard g(q);
if (!layoutChangedTimer.isActive())
if (!layoutChangedTimer->isActive())
{
layoutChangedTimer.start();
layoutChangedTimer->start();
}
}

Expand All @@ -122,15 +122,13 @@ struct SortedImageModel::Impl
void onThumbnailChanged(Image* img)
{
xThreadGuard g(q);
int i = this->entries->getLinearIndexOfItem(img);
QPersistentModelIndex pm = q->index(i, 0);
if (pm.isValid())
QModelIndex m = q->index(img);
if (m.isValid())
{
emit q->layoutAboutToBeChanged({ pm });
// precompute and transform the thumbnail for the UI thread, before we are announcing that a thumbnail is available
img->thumbnailTransformed(this->cachedIconHeight);
emit q->dataChanged(pm, pm, { Qt::DecorationRole });
emit q->layoutChanged();
emit q->dataChanged(m, m, { Qt::DecorationRole });
this->updateLayout();
}
}

Expand Down Expand Up @@ -199,9 +197,10 @@ struct SortedImageModel::Impl

SortedImageModel::SortedImageModel(QObject* parent) : QAbstractTableModel(parent), d(std::make_unique<Impl>(this))
{
d->layoutChangedTimer.setInterval(1000);
d->layoutChangedTimer.setSingleShot(true);
connect(&d->layoutChangedTimer, &QTimer::timeout, this, [&](){ d->forceUpdateLayout();});
d->layoutChangedTimer = new QTimer(this);
d->layoutChangedTimer->setInterval(1000);
d->layoutChangedTimer->setSingleShot(true);
connect(d->layoutChangedTimer, &QTimer::timeout, this, [&](){ d->forceUpdateLayout();});

d->entries.reset(new ImageSectionDataContainer(this));
d->directoryWatcher.reset(new DirectoryWorker(d->entries.get(), this));
Expand Down

0 comments on commit 8c3a058

Please sign in to comment.