Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e90b39bebb
Fetching contributors…

Cannot retrieve contributors at this time

51 lines (42 sloc) 1.072 kb
#include "DeclarativeView.h"
#include <QFileSystemWatcher>
#include <QDeclarativeEngine>
DeclarativeView::DeclarativeView(const QUrl& url, const bool& autoReload, QWidget *parent)
: QDeclarativeView(url, parent), m_autoReload(false), m_watcher(0)
{
setAutoReload(autoReload);
}
DeclarativeView::~DeclarativeView()
{
destroyWatcher();
}
void DeclarativeView::setAutoReload(const bool& autoReload)
{
m_autoReload = autoReload;
if(m_autoReload) createWatcher();
else destroyWatcher();
}
const bool& DeclarativeView::autoReload() const
{
return m_autoReload;
}
void DeclarativeView::reload()
{
engine()->clearComponentCache();
QUrl url = source();
setSource(QUrl());
setSource(url); // Force reload
}
void DeclarativeView::createWatcher()
{
if(source().toLocalFile().isEmpty()) return;
m_watcher = new QFileSystemWatcher();
m_watcher->addPath(source().toLocalFile());
connect(m_watcher, SIGNAL(fileChanged(QString)), SLOT(reload()));
}
void DeclarativeView::destroyWatcher()
{
if(!m_watcher) return;
m_watcher->disconnect(this);
delete m_watcher;
}
Jump to Line
Something went wrong with that request. Please try again.