9#include "LayerManager.h"
12#include "AbstractDataPlugin.h"
13#include "AbstractDataPluginItem.h"
14#include "GeoPainter.h"
15#include "LayerInterface.h"
16#include "MarbleDebug.h"
17#include "RenderPlugin.h"
18#include "RenderState.h"
20#include <QElapsedTimer>
25class Q_DECL_HIDDEN LayerManager::Private
28 Private(LayerManager *parent);
31 void updateVisibility(
bool visible,
const QString &nameId);
33 LayerManager *
const q;
39 RenderState m_renderState;
41 bool m_showBackground;
42 bool m_showRuntimeTrace;
45LayerManager::Private::Private(LayerManager *parent)
48 , m_showBackground(true)
49 , m_showRuntimeTrace(false)
53LayerManager::Private::~Private() =
default;
55void LayerManager::Private::updateVisibility(
bool visible,
const QString &nameId)
57 Q_EMIT q->visibilityChanged(nameId, visible);
60LayerManager::LayerManager(
QObject *parent)
62 , d(new Private(this))
66LayerManager::~LayerManager()
71bool LayerManager::showBackground()
const
73 return d->m_showBackground;
76bool LayerManager::showRuntimeTrace()
const
78 return d->m_showRuntimeTrace;
81void LayerManager::addRenderPlugin(RenderPlugin *renderPlugin)
83 d->m_renderPlugins.append(renderPlugin);
85 connect(renderPlugin, SIGNAL(settingsChanged(
QString)),
this, SIGNAL(pluginSettingsChanged()));
87 connect(renderPlugin, SIGNAL(visibilityChanged(
bool,
QString)),
this, SLOT(updateVisibility(
bool,
QString)));
90 auto const dataPlugin = qobject_cast<AbstractDataPlugin *>(renderPlugin);
92 d->m_dataPlugins.append(dataPlugin);
98 return d->m_dataPlugins;
105 for (
auto plugin : d->m_dataPlugins) {
106 itemList.
append(plugin->whichItemAt(curpos));
113 d->m_renderState = RenderState(QStringLiteral(
"Marble"));
119 if (d->m_showBackground) {
120 renderPositions << QStringLiteral(
"STARS") << QStringLiteral(
"BEHIND_TARGET");
123 renderPositions << QStringLiteral(
"SURFACE") << QStringLiteral(
"HOVERS_ABOVE_SURFACE") << QStringLiteral(
"GRATICULE") << QStringLiteral(
"PLACEMARKS")
124 << QStringLiteral(
"ATMOSPHERE") << QStringLiteral(
"ORBIT") << QStringLiteral(
"ALWAYS_ON_TOP") << QStringLiteral(
"FLOAT_ITEM")
125 << QStringLiteral(
"USER_TOOLS");
128 for (
const auto &renderPosition : renderPositions) {
132 for (
auto renderPlugin : d->m_renderPlugins) {
133 if (renderPlugin && renderPlugin->renderPosition().contains(renderPosition)) {
134 if (renderPlugin->enabled() && renderPlugin->visible()) {
135 if (!renderPlugin->isInitialized()) {
136 renderPlugin->initialize();
137 Q_EMIT renderPluginInitialized(renderPlugin);
145 for (
auto layer : d->m_internalLayers) {
146 if (layer && layer->renderPosition().contains(renderPosition)) {
152 std::sort(layers.
begin(), layers.
end(), [](
const LayerInterface *
const one,
const LayerInterface *
const two) ->
bool {
153 Q_ASSERT(one && two);
154 return one->zValue() < two->zValue();
159 for (
auto layer : layers) {
161 layer->render(painter, viewport, renderPosition,
nullptr);
162 d->m_renderState.addChild(layer->renderState());
163 traceList.
append(QStringLiteral(
"%2 ms %3").arg(timer.
elapsed(), 3).arg(layer->runtimeTrace()));
167 if (d->m_showRuntimeTrace) {
168 const int totalElapsed = totalTime.
elapsed();
169 const int fps = 1000.0 / totalElapsed;
170 traceList.
append(QStringLiteral(
"Total: %1 ms (%2 fps)").arg(totalElapsed, 3).arg(fps));
180 for (
const auto &text : traceList) {
191void LayerManager::setShowBackground(
bool show)
193 d->m_showBackground = show;
196void LayerManager::setShowRuntimeTrace(
bool show)
198 d->m_showRuntimeTrace = show;
201void LayerManager::addLayer(LayerInterface *layer)
203 if (!d->m_internalLayers.contains(layer)) {
204 d->m_internalLayers.push_back(layer);
208void LayerManager::removeLayer(LayerInterface *layer)
210 d->m_internalLayers.removeAll(layer);
215 return d->m_internalLayers;
218RenderState LayerManager::renderState()
const
220 return d->m_renderState;
225#include "moc_LayerManager.cpp"
A painter that allows to draw geometric primitives on the map.
void drawText(const GeoDataCoordinates &position, const QString &text, qreal xOffset=0.0, qreal yOffset=0.0, qreal width=0.0, qreal height=0.0, const QTextOption &option=QTextOption())
Draws the given text at a given geographic position. The text is drawn starting at the given position...
A public class that controls what is visible in the viewport of a Marble map.
Binds a QML item to a specific geodetic location in screen coordinates.
qint64 elapsed() const const
void append(QList< T > &&value)
void push_back(parameter_type value)
QFontMetrics fontMetrics() const const
void setBackground(const QBrush &brush)
void setBackgroundMode(Qt::BGMode mode)
void setFont(const QFont &font)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)