aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/util/qquickpath_p_p.h
blob: 33684557b8922dd502ef035a74f4f9307284f265 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default

#ifndef QQUICKPATH_P_H
#define QQUICKPATH_P_H

//
//  W A R N I N G
//  -------------
//
// This file is not part of the Qt API.  It exists purely as an
// implementation detail.  This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//

#include <private/qtquickglobal_p.h>

QT_REQUIRE_CONFIG(quick_path);

#include "qquickpath_p.h"

#include <qqml.h>
#include <QtCore/QStringList>

#include <private/qobject_p.h>

QT_BEGIN_NAMESPACE

class Q_QUICK_EXPORT QQuickPathPrivate : public QObjectPrivate
{
    Q_DECLARE_PUBLIC(QQuickPath)

public:
    static QQuickPathPrivate* get(QQuickPath *path) { return path->d_func(); }
    static const QQuickPathPrivate* get(const QQuickPath *path) { return path->d_func(); }

    QQuickPathPrivate()
        : componentComplete(true), isShapePath(false), simplify(false)
          , processPending(false), asynchronous(false), useCustomPath(false)
    {}

    enum class ProcessPathPolicy {
        DontProcess,
        Process
    };
    void appendPathElement(QQuickPathElement *pathElement,
                           ProcessPathPolicy processPathPolicy = ProcessPathPolicy::Process)
    {
        if (pathElement && componentComplete) {
            enablePathElement(pathElement);
            _pathElements.append(pathElement);
            if (processPathPolicy == ProcessPathPolicy::Process)
                q_func()->processPath();
        } else {
            _pathElements.append(pathElement);
        }
    }

    void removeLastPathElement()
    {
        QQuickPathElement *pathElement = _pathElements.takeLast();
        if (pathElement && componentComplete) {
            disablePathElement(pathElement);
            q_func()->processPath();
        }
    }

    void replacePathElement(qsizetype position, QQuickPathElement *pathElement)
    {
        if (position >= _pathElements.length())
            _pathElements.resize(position + 1, nullptr);

        if (!componentComplete) {
            _pathElements[position] = pathElement;
            return;
        }

        bool changed = false;

        QQuickPathElement *oldElement = _pathElements.at(position);
        if (oldElement == pathElement)
            return;

        if (oldElement) {
            disablePathElement(oldElement);
            changed = true;
        }

        if (pathElement) {
            enablePathElement(pathElement);
            changed = true;
        }

        _pathElements[position] = pathElement;

        if (changed)
            q_func()->processPath();
    }

    enum class DeleteElementPolicy {
        DontDelete,
        Delete
    };
    void clearPathElements(DeleteElementPolicy deleteElementPolicy
        = QQuickPathPrivate::DeleteElementPolicy::DontDelete)
    {
        Q_Q(QQuickPath);
        q->disconnectPathElements();
        if (deleteElementPolicy == DeleteElementPolicy::Delete)
            qDeleteAll(_pathElements);
        _pathElements.clear();
        _pathCurves.clear();
        _pointCache.clear();
        _pathTexts.clear();
        _path.clear();
        emit q->changed();
    }

    QPainterPath _path;
    QList<QQuickPathElement*> _pathElements;
    mutable QVector<QPointF> _pointCache;
    QList<QQuickPath::AttributePoint> _attributePoints;
    QStringList _attributes;
    QList<QQuickCurve*> _pathCurves;
    QList<QQuickPathText*> _pathTexts;
    mutable QQuickCachedBezier prevBez;
    QQmlNullableValue<qreal> startX;
    QQmlNullableValue<qreal> startY;
    qreal pathLength = 0;
    QSizeF scale = QSizeF(1, 1);
    bool closed = false;
    bool componentComplete : 1;
    bool isShapePath : 1;
    bool simplify : 1;
    bool processPending : 1;
    bool asynchronous : 1;
    bool useCustomPath : 1;

private:
    void enablePathElement(QQuickPathElement *pathElement);
    void disablePathElement(QQuickPathElement *pathElement);
};

QT_END_NAMESPACE

#endif