File indexing completed on 2025-01-05 03:59:30
0001 // SPDX-License-Identifier: LGPL-2.1-or-later 0002 // 0003 // SPDX-FileCopyrightText: 2009 Bastian Holst <bastianholst@gmx.de> 0004 // 0005 0006 // Self 0007 #include "AbstractDataPlugin.h" 0008 0009 // Qt 0010 #include <QTimer> 0011 #include <QRegion> 0012 0013 // Marble 0014 #include "AbstractDataPluginModel.h" 0015 #include "AbstractDataPluginItem.h" 0016 #include "GeoPainter.h" 0017 #include "GeoSceneLayer.h" 0018 #include "MarbleModel.h" 0019 #include "ViewportParams.h" 0020 0021 #include "digikam_debug.h" 0022 0023 namespace Marble 0024 { 0025 0026 class AbstractDataPluginPrivate 0027 { 0028 public: 0029 AbstractDataPluginPrivate() 0030 : m_model( nullptr ), 0031 m_numberOfItems( 10 ) 0032 { 0033 m_updateTimer.setSingleShot( true ); 0034 } 0035 0036 ~AbstractDataPluginPrivate() { 0037 delete m_model; 0038 } 0039 0040 AbstractDataPluginModel *m_model; 0041 quint32 m_numberOfItems; 0042 QTimer m_updateTimer; 0043 }; 0044 0045 AbstractDataPlugin::AbstractDataPlugin( const MarbleModel *marbleModel ) 0046 : RenderPlugin( marbleModel ), 0047 d( new AbstractDataPluginPrivate ) 0048 { 0049 connect( &d->m_updateTimer, SIGNAL(timeout()), this, SIGNAL(repaintNeeded()) ); 0050 } 0051 0052 AbstractDataPlugin::~AbstractDataPlugin() 0053 { 0054 delete d; 0055 } 0056 0057 bool AbstractDataPlugin::isInitialized() const 0058 { 0059 return model() != nullptr; 0060 } 0061 0062 QStringList AbstractDataPlugin::backendTypes() const 0063 { 0064 return QStringList( name() ); 0065 } 0066 0067 QString AbstractDataPlugin::renderPolicy() const 0068 { 0069 return QString::fromUtf8( "ALWAYS" ); 0070 } 0071 0072 QStringList AbstractDataPlugin::renderPosition() const 0073 { 0074 return QStringList( QString::fromUtf8("ALWAYS_ON_TOP") ); 0075 } 0076 0077 bool AbstractDataPlugin::render( GeoPainter *painter, ViewportParams *viewport, 0078 const QString& renderPos, GeoSceneLayer * layer) 0079 { 0080 Q_UNUSED( renderPos ); 0081 Q_UNUSED( layer ); 0082 0083 QList<AbstractDataPluginItem*> items = d->m_model->items( viewport, numberOfItems() ); 0084 painter->save(); 0085 0086 // Paint the most important item at last 0087 for( int i = items.size() - 1; i >= 0; --i ) { 0088 items.at( i )->paintEvent( painter, viewport ); 0089 } 0090 0091 painter->restore(); 0092 0093 return true; 0094 } 0095 0096 AbstractDataPluginModel *AbstractDataPlugin::model() 0097 { 0098 return d->m_model; 0099 } 0100 0101 const AbstractDataPluginModel *AbstractDataPlugin::model() const 0102 { 0103 return d->m_model; 0104 } 0105 0106 void AbstractDataPlugin::setModel( AbstractDataPluginModel* model ) 0107 { 0108 if ( d->m_model ) { 0109 disconnect( d->m_model, SIGNAL(itemsUpdated()), this, SLOT(delayedUpdate()) ); 0110 delete d->m_model; 0111 } 0112 d->m_model = model; 0113 0114 connect( d->m_model, SIGNAL(itemsUpdated()), this, SLOT(delayedUpdate()) ); 0115 connect( d->m_model, SIGNAL(favoriteItemsChanged(QStringList)), this, 0116 SLOT(favoriteItemsChanged(QStringList)) ); 0117 connect( d->m_model, SIGNAL(favoriteItemsOnlyChanged()), this, 0118 SIGNAL(favoriteItemsOnlyChanged()) ); 0119 0120 Q_EMIT favoritesModelChanged(); 0121 } 0122 0123 quint32 AbstractDataPlugin::numberOfItems() const 0124 { 0125 return d->m_numberOfItems; 0126 } 0127 0128 void AbstractDataPlugin::setNumberOfItems( quint32 number ) 0129 { 0130 bool changed = ( number != d->m_numberOfItems ); 0131 d->m_numberOfItems = number; 0132 0133 if ( changed ) 0134 Q_EMIT changedNumberOfItems( number ); 0135 } 0136 0137 QList<AbstractDataPluginItem *> AbstractDataPlugin::whichItemAt( const QPoint& curpos ) 0138 { 0139 if ( d->m_model && enabled() && visible()) { 0140 return d->m_model->whichItemAt( curpos ); 0141 } 0142 else { 0143 return QList<AbstractDataPluginItem *>(); 0144 } 0145 } 0146 0147 RenderPlugin::RenderType AbstractDataPlugin::renderType() const 0148 { 0149 return OnlineRenderType; 0150 } 0151 0152 void AbstractDataPlugin::setFavoriteItemsOnly( bool favoriteOnly ) 0153 { 0154 if ( d->m_model && d->m_model->isFavoriteItemsOnly() != favoriteOnly ) { 0155 d->m_model->setFavoriteItemsOnly( favoriteOnly ); 0156 } 0157 } 0158 0159 bool AbstractDataPlugin::isFavoriteItemsOnly() const 0160 { 0161 return d->m_model && d->m_model->isFavoriteItemsOnly(); 0162 } 0163 0164 QObject *AbstractDataPlugin::favoritesModel() 0165 { 0166 return d->m_model ? d->m_model->favoritesModel() : nullptr; 0167 } 0168 0169 void AbstractDataPlugin::favoriteItemsChanged( const QStringList& favoriteItems ) 0170 { 0171 Q_UNUSED( favoriteItems ) 0172 } 0173 0174 void AbstractDataPlugin::delayedUpdate() 0175 { 0176 if ( !d->m_updateTimer.isActive() ) 0177 { 0178 d->m_updateTimer.start( 500 ); 0179 } 0180 } 0181 0182 } // namespace Marble 0183 0184 #include "moc_AbstractDataPlugin.cpp"