Skip to content

Commit

Permalink
libhawaiishell: Move element handling to Containment and ContainmentItem
Browse files Browse the repository at this point in the history
Elements are added to containments, the Containment attached object
creates elements graphical representation.

Issue: #151
  • Loading branch information
plfiorini committed Mar 25, 2014
1 parent 9e431b8 commit 11c3b97
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/libhawaiishell/containment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QtConfiguration/QConfiguration>

#include "containment.h"
#include "element.h"
#include "package.h"
#include "pluginloader.h"

Expand All @@ -56,6 +57,7 @@ class ContainmentPrivate
bool immutable;
bool configuring;
Package package;
QList<Element *> elements;
};

ContainmentPrivate::ContainmentPrivate()
Expand Down Expand Up @@ -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
Expand Down
26 changes: 26 additions & 0 deletions src/libhawaiishell/containment.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace Hawaii {
namespace Shell {

class ContainmentPrivate;
class Element;

class HAWAIISHELL_EXPORT Containment : public QObject
{
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions src/libhawaiishell/containmentitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "containment.h"
#include "containmentitem.h"
#include "elementitem.h"
#include "package.h"
#include "qmlobject.h"

Expand All @@ -52,6 +53,7 @@ class ContainmentItemPrivate
Containment *containment;
QmlObject *qmlObject;

void _q_elementAdded(Element *element);
void _q_packageChanged();

static QHash<QObject *, ContainmentItem *> s_rootObjects;
Expand All @@ -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);
Expand Down Expand Up @@ -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()));
Expand Down
15 changes: 15 additions & 0 deletions src/libhawaiishell/containmentitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace Shell {

class Containment;
class ContainmentItemPrivate;
class Element;
class ElementItem;

class HAWAIISHELL_EXPORT ContainmentItem : public QQuickItem
{
Expand Down Expand Up @@ -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())
};

Expand Down

0 comments on commit 11c3b97

Please sign in to comment.