From 39c0f81b1064d8f2ec7f2bc7d9beae84808a4963 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 23 Feb 2018 16:14:08 +0100 Subject: [PATCH] Implement missing constructors Fixes a crash when no deref/ref on = operator. Makes it possible to leverage move semantics on components. --- qt/component.cpp | 15 +++++++++++++++ qt/component.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/qt/component.cpp b/qt/component.cpp index 8e515645..2dc1ed9b 100644 --- a/qt/component.cpp +++ b/qt/component.cpp @@ -154,6 +154,21 @@ Component::~Component() g_object_unref(m_cpt); } +Component& Component::operator=(const Component& other) +{ + if (&other != this) { + g_object_unref(m_cpt); + m_cpt = other.m_cpt; + g_object_ref(m_cpt); + } + return *this; +} + +Component::Component(Component&& other) + : m_cpt(other.m_cpt) +{ +} + _AsComponent * AppStream::Component::asComponent() const { return m_cpt; diff --git a/qt/component.h b/qt/component.h index 3509f7ff..0cf51051 100644 --- a/qt/component.h +++ b/qt/component.h @@ -100,8 +100,11 @@ Q_GADGET Component(_AsComponent *cpt); Component(); Component(const Component& other); + Component(Component&& other); ~Component(); + Component& operator=(const Component& c); + _AsComponent *asComponent() const; uint valueFlags() const;