Revision control

Copy as Markdown

// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef WITHLENGTH_H
#define WITHLENGTH_H
#include <QtCore/qobject.h>
#include <QtCore/qpoint.h>
#include <QtCore/qrect.h>
#include <QtQml/qqml.h>
class ObjectType : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
ObjectType(QObject *parent = nullptr) : QObject(parent) {}
};
struct ValueTypeWithLength
{
Q_GADGET
QML_VALUE_TYPE(withLength)
QML_CONSTRUCTIBLE_VALUE
Q_PROPERTY(int length READ length CONSTANT)
public:
ValueTypeWithLength() = default;
Q_INVOKABLE ValueTypeWithLength(int length) : m_length(length) {}
Q_INVOKABLE ValueTypeWithLength(QPointF point) : m_length(point.manhattanLength()) {}
Q_INVOKABLE ValueTypeWithLength(QRectF rect) : m_length(rect.width()) {}
Q_INVOKABLE ValueTypeWithLength(ObjectType *o) : m_length(o->objectName().length()) {}
Q_INVOKABLE QString toString() const { return QStringLiteral("no"); }
int length() const { return m_length; }
private:
int m_length = 19;
};
struct InnerWithLength {
int m_length;
};
struct UnconstructibleWithLength
{
Q_GADGET
QML_VALUE_TYPE(unconstructibleWithLength)
QML_FOREIGN(InnerWithLength)
QML_EXTENDED(UnconstructibleWithLength)
public:
UnconstructibleWithLength() = default;
Q_INVOKABLE UnconstructibleWithLength(int length) : v{length} {}
private:
InnerWithLength v;
};
struct LocalWithLength
{
Q_GADGET
Q_PROPERTY(int length READ length CONSTANT)
public:
LocalWithLength() = default;
LocalWithLength(int length) : m_length(length) {}
int length() const { return m_length; }
private:
int m_length = 20;
};
struct ForeignWithLength: private LocalWithLength
{
Q_GADGET
QML_VALUE_TYPE(foreignWithLength)
QML_FOREIGN(LocalWithLength)
QML_EXTENDED(ForeignWithLength)
QML_CONSTRUCTIBLE_VALUE
public:
Q_INVOKABLE ForeignWithLength() = default;
Q_INVOKABLE ForeignWithLength(int length) : LocalWithLength(length) {}
Q_INVOKABLE ForeignWithLength(const LocalWithLength &withLength)
: LocalWithLength(withLength)
{}
};
#endif // WITHLENGTH_H