Regularly check if graphics is modified when visible on screen (#10596)

In case one cannot rely on QFileSystemWatcher.

see https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg199112.html
This commit is contained in:
Guillaume Munch 2017-03-19 14:41:54 +01:00
parent c779e9806e
commit ad16347b08
5 changed files with 24 additions and 2 deletions

View File

@ -99,7 +99,7 @@ public:
/// The document filename this graphic item belongs to
FileName const & doc_file_;
///
FileMonitorPtr monitor_;
ActiveFileMonitorPtr monitor_;
/// Is the file compressed?
bool zipped_;
@ -179,6 +179,14 @@ bool CacheItem::monitoring() const
}
void CacheItem::checkModifiedAsync() const
{
if (!pimpl_->monitor_)
return;
pimpl_->monitor_->checkModifiedAsync();
}
Image const * CacheItem::image() const
{
return pimpl_->image_.get();
@ -214,7 +222,7 @@ void CacheItem::Impl::startMonitor()
{
if (monitor_)
return;
monitor_ = FileSystemWatcher::monitor(filename_);
monitor_ = FileSystemWatcher::activeMonitor(filename_);
monitor_->connect([=](){ startLoading(); });
}

View File

@ -66,6 +66,8 @@ public:
void startMonitoring() const;
///
bool monitoring() const;
/// perform a modification check asynchronously
void checkModifiedAsync() const;
/** Get the image associated with filename().
* If the image is not yet loaded, returns 0.

View File

@ -328,6 +328,15 @@ bool Loader::monitoring() const
}
void Loader::checkModifiedAsync() const
{
if (!pimpl_->cached_item_)
return;
pimpl_->cached_item_->checkModifiedAsync();
}
FileName const & Loader::filename() const
{
static FileName const empty;

View File

@ -81,6 +81,8 @@ public:
void startMonitoring() const;
///
bool monitoring() const;
///
void checkModifiedAsync() const;
/// How far have we got in loading the image?
ImageStatus status() const;

View File

@ -142,6 +142,7 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
loader_.startLoading();
if (!loader_.monitoring())
loader_.startMonitoring();
loader_.checkModifiedAsync();
}
bool const image_ready = displayGraphic(params_) && readyToDisplay(loader_);