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
12class Q_DECL_HIDDEN RenderState::Private
13{
14public:
15 QString m_name;
16 QList<RenderState> m_children;
17 RenderStatus m_status;
18
19 Private( const QString &name=QString(), RenderStatus status=Complete );
20 RenderStatus status() const;
21 static RenderStatus minimumStatus(RenderStatus a, RenderStatus b);
22 QString toString( const RenderState &state, int indent ) const;
23};
24
25RenderState::RenderState( const QString &name, RenderStatus status ) :
26 d( new Private( name, status ) )
27{
28 // nothing to do
29}
30
31RenderState::RenderState( const RenderState &other ) :
32 d( new Private )
33{
34 *d = *other.d;
35}
36
37RenderState &RenderState::operator=( const RenderState &other )
38{
39 *d = *other.d;
40 return *this;
41}
42
43RenderState::~RenderState()
44{
45 delete d;
46}
47
48RenderStatus RenderState::status() const
49{
50 return d->status();
51}
52
53QString RenderState::name() const
54{
55 return d->m_name;
56}
57
58int RenderState::children() const
59{
60 return d->m_children.size();
61}
62
63RenderState RenderState::childAt( int index ) const
64{
65 return d->m_children.at( index );
66}
67
68void RenderState::addChild(const RenderState &child)
69{
70 d->m_children.push_back( child );
71}
72
73RenderState::operator QString() const
74{
75 return d->toString( *this, 0 );
76}
77
78RenderState::Private::Private( const QString &name, RenderStatus status ) :
79 m_name( name ),
80 m_status( status )
81{
82 // nothing to do
83}
84
85RenderStatus RenderState::Private::status() const
86{
87 RenderStatus status = Complete;
88 for( const RenderState &child: m_children ) {
89 status = minimumStatus( status, child.status() );
90 }
91 return minimumStatus( status, m_status );
92}
93
94RenderStatus RenderState::Private::minimumStatus(RenderStatus a, RenderStatus b)
95{
96 if ( a == Incomplete || b == Incomplete ) {
97 return Incomplete;
98 }
99 if ( a == WaitingForData || b == WaitingForData ) {
100 return WaitingForData;
101 }
102 if ( a == WaitingForUpdate || b == WaitingForUpdate ) {
103 return WaitingForUpdate;
104 }
105
106 Q_ASSERT( a == Complete || b == Complete );
107 return Complete;
108}
109
110QString RenderState::Private::toString( const RenderState &state, int level ) const
111{
112 QString const prefix = level > 0 ? "\n" : "";
113 QString const indent(level*2, QLatin1Char(' '));
115 switch ( state.status() ) {
116 case Marble::Complete: status = "Complete"; break;
117 case Marble::WaitingForUpdate: status = "Waiting for update"; break;
118 case Marble::WaitingForData: status = "Waiting for data"; break;
119 case Marble::Incomplete: status = "Incomplete"; break;
120 }
121 QString const name = ( state.name().isEmpty() ? "Anonymous renderer" : state.name() );
122 QString result = QString("%1%2%3: %4").arg( prefix, indent, name, status );
123
124 for( const RenderState &child: state.d->m_children ) {
125 result += toString( child, level+1 );
126 }
127 return result;
128}
129
130}
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 Jul 12 2024 11:58:56 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.