From 1e1ad82f3b7ffd1913c53c7842f93f36549a82f5 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Mon, 5 Jul 2021 20:40:47 +0300 Subject: [PATCH] Remove unused geometry setters in Item Originally, only x, y, width, and height property setters were used. A bit later "position" and "size" helper setters were added to simplify code in SurfaceItem sub-classes. It seems like setX(), setY(), setWidth(), and setHeight() are unused now, so remove them. --- src/item.cpp | 107 +++-------------------------------- src/item.h | 40 ++----------- src/surfaceitem_internal.cpp | 2 +- src/surfaceitem_wayland.cpp | 2 +- src/toplevel.cpp | 3 +- 5 files changed, 17 insertions(+), 137 deletions(-) diff --git a/src/item.cpp b/src/item.cpp index 9d9542d93d..eb7b59883d 100644 --- a/src/item.cpp +++ b/src/item.cpp @@ -39,76 +39,6 @@ Item::~Item() } } -int Item::x() const -{ - return m_x; -} - -void Item::setX(int x) -{ - if (m_x == x) { - return; - } - scheduleRepaint(boundingRect()); - m_x = x; - updateBoundingRect(); - scheduleRepaint(boundingRect()); - Q_EMIT xChanged(); -} - -int Item::y() const -{ - return m_y; -} - -void Item::setY(int y) -{ - if (m_y == y) { - return; - } - scheduleRepaint(boundingRect()); - m_y = y; - updateBoundingRect(); - scheduleRepaint(boundingRect()); - Q_EMIT yChanged(); -} - -int Item::width() const -{ - return m_width; -} - -void Item::setWidth(int width) -{ - if (m_width == width) { - return; - } - scheduleRepaint(rect()); - m_width = width; - updateBoundingRect(); - scheduleRepaint(rect()); - discardQuads(); - Q_EMIT widthChanged(); -} - -int Item::height() const -{ - return m_height; -} - -void Item::setHeight(int height) -{ - if (m_height == height) { - return; - } - scheduleRepaint(rect()); - m_height = height; - updateBoundingRect(); - scheduleRepaint(rect()); - discardQuads(); - Q_EMIT heightChanged(); -} - Item *Item::parentItem() const { return m_parentItem; @@ -160,55 +90,34 @@ Scene::Window *Item::window() const QPoint Item::position() const { - return QPoint(x(), y()); + return m_position; } void Item::setPosition(const QPoint &point) { - const bool xDirty = (x() != point.x()); - const bool yDirty = (y() != point.y()); - - if (xDirty || yDirty) { + if (m_position != point) { scheduleRepaint(boundingRect()); - m_x = point.x(); - m_y = point.y(); + m_position = point; updateBoundingRect(); scheduleRepaint(boundingRect()); - - if (xDirty) { - Q_EMIT xChanged(); - } - if (yDirty) { - Q_EMIT yChanged(); - } + Q_EMIT positionChanged(); } } QSize Item::size() const { - return QSize(width(), height()); + return m_size; } void Item::setSize(const QSize &size) { - const bool widthDirty = (width() != size.width()); - const bool heightDirty = (height() != size.height()); - - if (widthDirty || heightDirty) { + if (m_size != size) { scheduleRepaint(rect()); - m_width = size.width(); - m_height = size.height(); + m_size = size; updateBoundingRect(); scheduleRepaint(rect()); - discardQuads(); - - if (widthDirty) { - Q_EMIT widthChanged(); - } - if (heightDirty) { - Q_EMIT heightChanged(); - } + Q_EMIT sizeChanged(); } } diff --git a/src/item.h b/src/item.h index f457e21a54..1c7908553a 100644 --- a/src/item.h +++ b/src/item.h @@ -24,24 +24,6 @@ public: explicit Item(Scene::Window *window, Item *parent = nullptr); ~Item() override; - /** - * Returns the x coordinate relative to the top left corner of the parent item. - */ - int x() const; - void setX(int x); - - /** - * Returns the y coordinate relative to the top left corner of the parent item. - */ - int y() const; - void setY(int y); - - int width() const; - void setWidth(int width); - - int height() const; - void setHeight(int height); - QPoint position() const; void setPosition(const QPoint &point); @@ -106,21 +88,13 @@ public: Q_SIGNALS: /** - * This signal is emitted when the x coordinate of this item has changed. + * This signal is emitted when the position of this item has changed. */ - void xChanged(); + void positionChanged(); /** - * This signal is emitted when the y coordinate of this item has changed. + * This signal is emitted when the size of this item has changed. */ - void yChanged(); - /** - * This signal is emitted when the width of this item has changed. - */ - void widthChanged(); - /** - * This signal is emitted when the height of this item has changed. - */ - void heightChanged(); + void sizeChanged(); /** * This signal is emitted when the rectangle that encloses this item and all of its children @@ -146,10 +120,8 @@ private: QPointer m_parentItem; QList m_childItems; QRect m_boundingRect; - int m_x = 0; - int m_y = 0; - int m_width = 0; - int m_height = 0; + QPoint m_position; + QSize m_size = QSize(0, 0); bool m_visible = true; bool m_effectiveVisible = true; QVector m_repaints; diff --git a/src/surfaceitem_internal.cpp b/src/surfaceitem_internal.cpp index 686a105264..74422a69ed 100644 --- a/src/surfaceitem_internal.cpp +++ b/src/surfaceitem_internal.cpp @@ -29,7 +29,7 @@ QPointF SurfaceItemInternal::mapToBuffer(const QPointF &point) const QRegion SurfaceItemInternal::shape() const { - return QRegion(0, 0, width(), height()); + return QRegion(rect()); } SurfacePixmap *SurfaceItemInternal::createPixmap() diff --git a/src/surfaceitem_wayland.cpp b/src/surfaceitem_wayland.cpp index d5ea9346a9..428f7b1581 100644 --- a/src/surfaceitem_wayland.cpp +++ b/src/surfaceitem_wayland.cpp @@ -66,7 +66,7 @@ QPointF SurfaceItemWayland::mapToBuffer(const QPointF &point) const QRegion SurfaceItemWayland::shape() const { - return QRegion(0, 0, width(), height()); + return QRegion(rect()); } QRegion SurfaceItemWayland::opaque() const diff --git a/src/toplevel.cpp b/src/toplevel.cpp index bc8b09dc90..edf9ef9333 100644 --- a/src/toplevel.cpp +++ b/src/toplevel.cpp @@ -270,8 +270,7 @@ bool Toplevel::setupCompositing() effect_window = new EffectWindowImpl(this); Compositor::self()->scene()->addToplevel(this); - connect(windowItem(), &WindowItem::xChanged, this, &Toplevel::visibleGeometryChanged); - connect(windowItem(), &WindowItem::yChanged, this, &Toplevel::visibleGeometryChanged); + connect(windowItem(), &WindowItem::positionChanged, this, &Toplevel::visibleGeometryChanged); connect(windowItem(), &WindowItem::boundingRectChanged, this, &Toplevel::visibleGeometryChanged); return true;