File indexing completed on 2024-05-05 03:49:48

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012-2016 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
0004 //
0005 
0006 #include "FloatItemsLayer.h"
0007 
0008 #include "AbstractFloatItem.h"
0009 #include "GeoPainter.h"
0010 #include "ViewportParams.h"
0011 
0012 namespace Marble
0013 {
0014 
0015 FloatItemsLayer::FloatItemsLayer(QObject *parent) :
0016     QObject(parent),
0017     m_floatItems()
0018 {
0019 }
0020 
0021 QStringList FloatItemsLayer::renderPosition() const
0022 {
0023     return QStringList(QStringLiteral("FLOAT_ITEM"));
0024 }
0025 
0026 bool FloatItemsLayer::render(GeoPainter *painter,
0027                              ViewportParams *viewport,
0028                              const QString &renderPos,
0029                              GeoSceneLayer *layer)
0030 {
0031     Q_UNUSED(renderPos)
0032     Q_UNUSED(layer)
0033 
0034     for (AbstractFloatItem *item: m_floatItems) {
0035         if (!item->enabled()) {
0036             continue;
0037         }
0038 
0039         if (!item->isInitialized()) {
0040             item->initialize();
0041             emit renderPluginInitialized(item);
0042         }
0043 
0044         if (item->visible()) {
0045             item->paintEvent(painter, viewport);
0046         }
0047     }
0048 
0049     return true;
0050 }
0051 
0052 void FloatItemsLayer::addFloatItem(AbstractFloatItem *floatItem)
0053 {
0054     Q_ASSERT(floatItem && "must not add a null float item to FloatItemsLayer");
0055 
0056     connect(floatItem, SIGNAL(settingsChanged(QString)),
0057             this,      SIGNAL(pluginSettingsChanged()));
0058     connect(floatItem, SIGNAL(repaintNeeded(QRegion)),
0059             this,      SIGNAL(repaintNeeded(QRegion)));
0060     connect(floatItem, SIGNAL(visibilityChanged(bool,QString)),
0061             this,      SLOT(updateVisibility(bool,QString)));
0062 
0063     m_floatItems.append( floatItem );
0064 }
0065 
0066 QList<AbstractFloatItem *> FloatItemsLayer::floatItems() const
0067 {
0068     return m_floatItems;
0069 }
0070 
0071 QString FloatItemsLayer::runtimeTrace() const
0072 {
0073     return QStringLiteral("Float Items: %1").arg(m_floatItems.size());
0074 }
0075 
0076 void FloatItemsLayer::updateVisibility(bool visible, const QString &nameId)
0077 {
0078     emit visibilityChanged(nameId, visible);
0079 }
0080 
0081 }
0082 
0083 #include "moc_FloatItemsLayer.cpp"