Fix 'Rect::isEmpty()' and small performance fixes

Specifically, don't emit the 'valueChanged' signal
if nothing actually changed.
This commit is contained in:
Jonas Kulla 2013-09-28 21:45:33 +02:00
parent 4c06b676ad
commit 1737ec9af4
2 changed files with 29 additions and 5 deletions

View File

@ -271,6 +271,14 @@ void Rect::operator=(const IntRect &rect)
void Rect::set(int x, int y, int w, int h) 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->x = x;
this->y = y; this->y = y;
width = w; width = w;
@ -280,30 +288,50 @@ void Rect::set(int x, int y, int w, int h)
void Rect::empty() void Rect::empty()
{ {
if (!(x || y || width || height))
return;
x = y = width = height = 0; x = y = width = height = 0;
valueChanged(); valueChanged();
} }
bool Rect::isEmpty() const
{
return !(width && height);
}
void Rect::setX(int value) void Rect::setX(int value)
{ {
if (x == value)
return;
x = value; x = value;
valueChanged(); valueChanged();
} }
void Rect::setY(int value) void Rect::setY(int value)
{ {
if (y == value)
return;
y = value; y = value;
valueChanged(); valueChanged();
} }
void Rect::setWidth(int value) void Rect::setWidth(int value)
{ {
if (width == value)
return;
width = value; width = value;
valueChanged(); valueChanged();
} }
void Rect::setHeight(int value) void Rect::setHeight(int value)
{ {
if (height == value)
return;
height = value; height = value;
valueChanged(); valueChanged();
} }

View File

@ -165,11 +165,7 @@ struct Rect : public Serializable
} }
void empty(); void empty();
bool isEmpty() const;
bool isEmpty() const
{
return !(x || y || width || height);
}
void setX(int value); void setX(int value);
void setY(int value); void setY(int value);