Commit de945256 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Make StackContainer inherit AbstractContainerBase and reuse API

parent 0809021b
Pipeline #1003 passed with stage
in 11 seconds
#include "QQuickStackContainer.h"
#include "QQuickContainerAttachedObject.h"
#include <QtMath>
QQuickStackContainer::QQuickStackContainer (QQuickItem * parent)
: QQuickItem { parent }
: QQuickAbstractContainerBase { parent }
{ }
void QQuickStackContainer::classBegin (void) {
QQuickItem::classBegin ();
}
void QQuickStackContainer::componentComplete (void) {
QQuickItem::componentComplete ();
connect (this, &QQuickStackContainer::visibleChanged, this, &QQuickStackContainer::polish);
connect (this, &QQuickStackContainer::widthChanged, this, &QQuickStackContainer::polish);
connect (this, &QQuickStackContainer::heightChanged, this, &QQuickStackContainer::polish);
polish ();
}
void QQuickStackContainer::setupHandlers (void) { }
void QQuickStackContainer::updatePolish (void) {
QQuickItem::updatePolish ();
int maxChildWidth { 0 }, maxChildHeight { 0 };
const QList<QQuickItem *> childrenList { childItems () };
void QQuickStackContainer::relayout (void) {
int maxChildWidth { 0 };
int maxChildHeight { 0 };
int layoutItemsCount { 0 };
const QList<QQuickItem *> & childrenList { childItems () };
for (QQuickItem * childItem : childrenList) {
if (!childItem->inherits ("QQuickRepeater")) {
if (qCeil (childItem->implicitWidth ()) > maxChildWidth) {
maxChildWidth = qCeil (childItem->implicitWidth ());
}
if (qCeil (childItem->implicitHeight ()) > maxChildHeight) {
maxChildHeight = qCeil (childItem->implicitHeight ());
}
}
}
setImplicitWidth (maxChildWidth);
setImplicitHeight (maxChildHeight);
}
void QQuickStackContainer::itemChange (QQuickItem::ItemChange change, const QQuickItem::ItemChangeData & value) {
QQuickItem::itemChange (change, value);
switch (int (change)) {
case ItemChildAddedChange: {
if (QQuickItem * child { value.item }) {
connect (child, &QQuickItem::visibleChanged, this, &QQuickStackContainer::polish, Qt::UniqueConnection);
connect (child, &QQuickItem::implicitWidthChanged, this, &QQuickStackContainer::polish, Qt::UniqueConnection);
connect (child, &QQuickItem::implicitHeightChanged, this, &QQuickStackContainer::polish, Qt::UniqueConnection);
polish ();
}
break;
}
case ItemChildRemovedChange: {
if (QQuickItem * child { value.item }) {
disconnect (child, Q_NULLPTR, this, Q_NULLPTR);
polish ();
if (!childItem->inherits (REPEATER_CLASSNAME)) {
if (childItem->isVisible ()) {
const QQuickContainerAttachedObject * attached { getContainerAttachedObject (childItem) };
const bool ignored { (attached && attached->get_ignored ()) };
if (!ignored) {
if (childItem->implicitWidth () > maxChildWidth) {
maxChildWidth = qCeil (childItem->implicitWidth ());
}
if (childItem->implicitHeight () > maxChildHeight) {
maxChildHeight = qCeil (childItem->implicitHeight ());
}
++layoutItemsCount;
}
}
break;
}
}
setImplicitWidth (maxChildWidth);
setImplicitHeight (maxChildHeight);
set_layoutItemsCount (layoutItemsCount);
}
#ifndef QQUICKSTACKCONTAINER_H
#define QQUICKSTACKCONTAINER_H
#include <QQuickItem>
#include "QQuickAbstractContainerBase.h"
#include "QmlPropertyHelpers.h"
class QQuickStackContainer : public QQuickItem {
class QQuickStackContainer : public QQuickAbstractContainerBase {
Q_OBJECT
public:
explicit QQuickStackContainer (QQuickItem * parent = Q_NULLPTR);
protected:
void classBegin (void) Q_DECL_FINAL;
void componentComplete (void) Q_DECL_FINAL;
void updatePolish (void) Q_DECL_FINAL;
void itemChange (ItemChange change, const ItemChangeData & value) Q_DECL_FINAL;
void setupHandlers (void) Q_DECL_FINAL;
void relayout (void) Q_DECL_FINAL;
};
#endif // QQUICKSTACKCONTAINER_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment