Marble

RenderState.cpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2//
3// SPDX-FileCopyrightText: 2014 Dennis Nienhüser <nienhueser@kde.org>
4//
5
6#include "RenderState.h"
7
8#include <QList>
9
10namespace Marble
11{
12
13class Q_DECL_HIDDEN RenderState::Private
14{
15public:
16 QString m_name;
17 QList<RenderState> m_children;
18 RenderStatus m_status;
19
20 Private(const QString &name = QString(), RenderStatus status = Complete);
21 RenderStatus status() const;
22 static RenderStatus minimumStatus(RenderStatus a, RenderStatus b);
23 QString toString(const RenderState &state, int indent) const;
24};
25
26RenderState::RenderState(const QString &name, RenderStatus status)
27 : d(new Private(name, status))
28{
29 // nothing to do
30}
31
32RenderState::RenderState(const RenderState &other)
33 : d(new Private)
34{
35 *d = *other.d;
36}
37
38RenderState &RenderState::operator=(const RenderState &other)
39{
40 *d = *other.d;
41 return *this;
42}
43
44RenderState::~RenderState()
45{
46 delete d;
47}
48
49RenderStatus RenderState::status() const
50{
51 return d->status();
52}
53
54QString RenderState::name() const
55{
56 return d->m_name;
57}
58
59int RenderState::children() const
60{
61 return d->m_children.size();
62}
63
64RenderState RenderState::childAt(int index) const
65{
66 return d->m_children.at(index);
67}
68
69void RenderState::addChild(const RenderState &child)
70{
71 d->m_children.push_back(child);
72}
73
74RenderState::operator QString() const
75{
76 return d->toString(*this, 0);
77}
78
79RenderState::Private::Private(const QString &name, RenderStatus status)
80 : m_name(name)
81 , m_status(status)
82{
83 // nothing to do
84}
85
86RenderStatus RenderState::Private::status() const
87{
88 RenderStatus status = Complete;
89 for (const RenderState &child : m_children) {
90 status = minimumStatus(status, child.status());
91 }
92 return minimumStatus(status, m_status);
93}
94
95RenderStatus RenderState::Private::minimumStatus(RenderStatus a, RenderStatus b)
96{
97 if (a == Incomplete || b == Incomplete) {
98 return Incomplete;
99 }
100 if (a == WaitingForData || b == WaitingForData) {
101 return WaitingForData;
102 }
103 if (a == WaitingForUpdate || b == WaitingForUpdate) {
104 return WaitingForUpdate;
105 }
106
107 Q_ASSERT(a == Complete || b == Complete);
108 return Complete;
109}
110
111QString RenderState::Private::toString(const RenderState &state, int level) const
112{
113 QString const prefix = level > 0 ? "\n" : "";
114 QString const indent(level * 2, QLatin1Char(' '));
116 switch (state.status()) {
117 case Marble::Complete:
118 status = "Complete";
119 break;
121 status = "Waiting for update";
122 break;
124 status = "Waiting for data";
125 break;
127 status = "Incomplete";
128 break;
129 }
130 QString const name = (state.name().isEmpty() ? "Anonymous renderer" : state.name());
131 QString result = QStringLiteral("%1%2%3: %4").arg(prefix, indent, name, status);
132
133 for (const RenderState &child : state.d->m_children) {
134 result += toString(child, level + 1);
135 }
136 return result;
137}
138
139}
Q_SCRIPTABLE CaptureState status()
char * toString(const EngineQuery &query)
QStringView level(QStringView ifopt)
QString name(StandardAction id)
Binds a QML item to a specific geodetic location in screen coordinates.
@ Incomplete
Data is missing and some error occurred when trying to retrieve it (e.g. network failure)
@ WaitingForData
Rendering is based on no or partial data, more data was requested (e.g. pending network queries)
@ Complete
All data is there and up to date.
@ WaitingForUpdate
Rendering is based on complete, but outdated data, data update was requested.
QString arg(Args &&... args) const const
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:14:14 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.