From 1737ec9af464f57b3ba54468be0e717caa3dc670 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sat, 28 Sep 2013 21:45:33 +0200 Subject: [PATCH] Fix 'Rect::isEmpty()' and small performance fixes Specifically, don't emit the 'valueChanged' signal if nothing actually changed. --- src/etc.cpp | 28 ++++++++++++++++++++++++++++ src/etc.h | 6 +----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/etc.cpp b/src/etc.cpp index 9db5449..7a74872 100644 --- a/src/etc.cpp +++ b/src/etc.cpp @@ -271,6 +271,14 @@ void Rect::operator=(const IntRect &rect) void Rect::set(int x, int y, int w, int h) { + if (this->x == x && + this->y == y && + width == w && + height == h) + { + return; + } + this->x = x; this->y = y; width = w; @@ -280,30 +288,50 @@ void Rect::set(int x, int y, int w, int h) void Rect::empty() { + if (!(x || y || width || height)) + return; + x = y = width = height = 0; valueChanged(); } +bool Rect::isEmpty() const +{ + return !(width && height); +} + void Rect::setX(int value) { + if (x == value) + return; + x = value; valueChanged(); } void Rect::setY(int value) { + if (y == value) + return; + y = value; valueChanged(); } void Rect::setWidth(int value) { + if (width == value) + return; + width = value; valueChanged(); } void Rect::setHeight(int value) { + if (height == value) + return; + height = value; valueChanged(); } diff --git a/src/etc.h b/src/etc.h index 9f76059..c060a1c 100644 --- a/src/etc.h +++ b/src/etc.h @@ -165,11 +165,7 @@ struct Rect : public Serializable } void empty(); - - bool isEmpty() const - { - return !(x || y || width || height); - } + bool isEmpty() const; void setX(int value); void setY(int value);