[Interest] Prevent unnecessary update to widgets from outside objects

iman ahmadvand iman72411 at gmail.com
Sun Nov 19 10:56:28 CET 2017


Hi everyone.

We've some QObject class which is actually an animator class(responsible
for animating associated target widget):

class Animator : public QVariantAnimation {
Q_OBJECT

Q_PROPERTY(QObject* targetObject READ targetObject WRITE setTargetObject)

public:
explicit Animator(QObject* target, QObject* parent = nullptr) {
setTargetObject(target);
}
~Animator() {
stop();
}

QObject* targetObject() const {
return d_func()->target;
}
void setTargetObject(QObject* target) {
Q_D(Animator);

if (d->target == target)
return;

if (d->state == QVariantAnimation::Running) {
qWarning("Animation::setTargetObject: you can't change the target of a
running animation");
return;
}
d->target = target;
}

protected:
void updateCurrentValue(const QVariant& value) override {
Q_UNUSED(value);
Q_D(Animator);

if (!d->target.isNull()) {
QEvent update(QEvent::StyleAnimationUpdate);
update.setAccepted(false);
QCoreApplication::sendEvent(d->target, &update);
if (!update.isAccepted())
stop();
}
}

private:
Q_DECLARE_PRIVATE(Animator)
Q_DISABLE_COPY(Animator)
};

Now, the problem is how we can prevent this update mechanism if there're
multiple Animators trying to send update to target?
How we can prevent some of the unnecessary updates ?

Regards.
Iman.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20171119/65b7c86b/attachment.html>


More information about the Interest mailing list