2019-01-12 19:25:43 +00:00
|
|
|
|
|
|
|
#include "RefreshDeferrer.h"
|
|
|
|
#include "widgets/CutterDockWidget.h"
|
|
|
|
|
|
|
|
RefreshDeferrer::RefreshDeferrer(RefreshDeferrerAccumulator *acc, QObject *parent) : QObject(parent),
|
|
|
|
acc(acc)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
RefreshDeferrer::~RefreshDeferrer()
|
|
|
|
{
|
|
|
|
delete acc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RefreshDeferrer::attemptRefresh(RefreshDeferrerParams params)
|
|
|
|
{
|
|
|
|
if (dockWidget->isVisibleToUser()) {
|
2019-01-13 15:00:07 +00:00
|
|
|
if (acc) {
|
|
|
|
acc->ignoreParams(params);
|
|
|
|
}
|
2019-01-12 19:25:43 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
dirty = true;
|
2019-01-13 14:26:55 +00:00
|
|
|
if (acc) {
|
|
|
|
acc->accumulate(params);
|
|
|
|
}
|
2019-01-12 19:25:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RefreshDeferrer::registerFor(CutterDockWidget *dockWidget)
|
|
|
|
{
|
|
|
|
this->dockWidget = dockWidget;
|
|
|
|
connect(dockWidget, &CutterDockWidget::becameVisibleToUser, this, [this]() {
|
2019-01-13 15:41:08 +00:00
|
|
|
if (dirty) {
|
2019-01-13 14:26:55 +00:00
|
|
|
emit refreshNow(acc ? acc->result() : nullptr);
|
|
|
|
if (acc) {
|
|
|
|
acc->clear();
|
|
|
|
}
|
2019-01-12 19:25:43 +00:00
|
|
|
dirty = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|