From 11c3b97495766208e0357f49dcf1668577d4e9f7 Mon Sep 17 00:00:00 2001 From: Pier Luigi Fiorini Date: Tue, 25 Mar 2014 08:16:36 +0000 Subject: [PATCH] libhawaiishell: Move element handling to Containment and ContainmentItem Elements are added to containments, the Containment attached object creates elements graphical representation. Issue: #151 --- src/libhawaiishell/containment.cpp | 20 ++++++++++++++++++++ src/libhawaiishell/containment.h | 26 ++++++++++++++++++++++++++ src/libhawaiishell/containmentitem.cpp | 16 ++++++++++++++++ src/libhawaiishell/containmentitem.h | 15 +++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/src/libhawaiishell/containment.cpp b/src/libhawaiishell/containment.cpp index 37fc3d2e..7a291f19 100644 --- a/src/libhawaiishell/containment.cpp +++ b/src/libhawaiishell/containment.cpp @@ -32,6 +32,7 @@ #include #include "containment.h" +#include "element.h" #include "package.h" #include "pluginloader.h" @@ -56,6 +57,7 @@ class ContainmentPrivate bool immutable; bool configuring; Package package; + QList elements; }; ContainmentPrivate::ContainmentPrivate() @@ -213,6 +215,24 @@ void Containment::setPackage(const Package &package) Q_EMIT packageChanged(package); } +void Containment::addElement(const QString &name) +{ + Q_D(Containment); + + Element *element = new Element(name, this, this); + d->elements.append(element); + Q_EMIT elementAdded(element); +} + +void Containment::removeElement(Element *element) +{ + Q_D(Containment); + + d->elements.removeOne(element); + Q_EMIT elementRemoved(element); + element->deleteLater(); +} + } // namespace Shell } // namespace Hawaii diff --git a/src/libhawaiishell/containment.h b/src/libhawaiishell/containment.h index 3ef0b6e0..e04b0bac 100644 --- a/src/libhawaiishell/containment.h +++ b/src/libhawaiishell/containment.h @@ -37,6 +37,7 @@ namespace Hawaii { namespace Shell { class ContainmentPrivate; +class Element; class HAWAIISHELL_EXPORT Containment : public QObject { @@ -116,6 +117,19 @@ class HAWAIISHELL_EXPORT Containment : public QObject */ void setPackage(const Package &package); + /*! + * Adds the element called \a name. + * \param name internal name of the element to add + * (something along the line of org.hawaii.elements.anelement). + */ + void addElement(const QString &name); + + /*! + * Removes the \a element. + * \param element the element to remove. + */ + void removeElement(Element *element); + Q_SIGNALS: /*! * Emitted when the containment type is changed. @@ -158,6 +172,18 @@ class HAWAIISHELL_EXPORT Containment : public QObject */ void packageChanged(const Package &package); + /*! + * Emitted when an element is added. + * \param element the elmement. + */ + void elementAdded(Hawaii::Shell::Element *element); + + /*! + * Emitted when an element is removed. + * \param element the elmement. + */ + void elementRemoved(Hawaii::Shell::Element *element); + private: Q_DECLARE_PRIVATE(Containment) ContainmentPrivate *const d_ptr; diff --git a/src/libhawaiishell/containmentitem.cpp b/src/libhawaiishell/containmentitem.cpp index cbf1234f..9488fcc4 100644 --- a/src/libhawaiishell/containmentitem.cpp +++ b/src/libhawaiishell/containmentitem.cpp @@ -33,6 +33,7 @@ #include "containment.h" #include "containmentitem.h" +#include "elementitem.h" #include "package.h" #include "qmlobject.h" @@ -52,6 +53,7 @@ class ContainmentItemPrivate Containment *containment; QmlObject *qmlObject; + void _q_elementAdded(Element *element); void _q_packageChanged(); static QHash s_rootObjects; @@ -70,6 +72,16 @@ ContainmentItemPrivate::ContainmentItemPrivate(ContainmentItem *self) { } +void ContainmentItemPrivate::_q_elementAdded(Element *element) +{ + Q_Q(ContainmentItem); + + ElementItem *elementItem = new ElementItem(element, q); + //elementItem->setContextProperty("Shell", QVariant::fromValue(ShellManager::instance()->controller())); + elementItem->initialize(); + Q_EMIT q->elementAdded(elementItem); +} + void ContainmentItemPrivate::_q_packageChanged() { Q_Q(ContainmentItem); @@ -113,6 +125,10 @@ ContainmentItem::ContainmentItem(Containment *containment, QQuickItem *parent) connect(containment, &Containment::configuringChanged, this, &ContainmentItem::configuringChanged); + // Handle elements + connect(containment, SIGNAL(elementAdded(Hawaii::Shell::Element*)), + this, SLOT(_q_elementAdded(Hawaii::Shell::Element*))); + // Reinizialize this item when the package is changed connect(containment, SIGNAL(packageChanged(Package)), this, SLOT(_q_packageChanged())); diff --git a/src/libhawaiishell/containmentitem.h b/src/libhawaiishell/containmentitem.h index f4b45349..2fa85b1f 100644 --- a/src/libhawaiishell/containmentitem.h +++ b/src/libhawaiishell/containmentitem.h @@ -37,6 +37,8 @@ namespace Shell { class Containment; class ContainmentItemPrivate; +class Element; +class ElementItem; class HAWAIISHELL_EXPORT ContainmentItem : public QQuickItem { @@ -149,10 +151,23 @@ class HAWAIISHELL_EXPORT ContainmentItem : public QQuickItem */ void configuringChanged(bool newValue); + /*! + * Emitted when an element is added. + * \param element graphical representation of the elmement. + */ + void elementAdded(Hawaii::Shell::ElementItem *element); + + /*! + * Emitted when an element is removed. + * \param element graphical representation of the elmement. + */ + void elementRemoved(Hawaii::Shell::ElementItem *element); + private: Q_DECLARE_PRIVATE(ContainmentItem) ContainmentItemPrivate *const d_ptr; + Q_PRIVATE_SLOT(d_func(), void _q_elementAdded(Hawaii::Shell::Element *element)) Q_PRIVATE_SLOT(d_func(), void _q_packageChanged()) };