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

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2009-2010 Bastian Holst <bastianholst@gmx.de>
0004 //
0005 
0006 #ifndef MARBLE_MARBLEGRAPHICSITEMPRIVATE_H
0007 #define MARBLE_MARBLEGRAPHICSITEMPRIVATE_H
0008 
0009 // Marble
0010 #include "AbstractMarbleGraphicsLayout.h"
0011 #include "MarbleGraphicsItem.h"
0012 
0013 // Qt
0014 #include<QDebug>
0015 #include<QList>
0016 #include<QSet>
0017 #include<QSize>
0018 #include<QSizeF>
0019 #include<QRect>
0020 #include<QPixmap>
0021 
0022 namespace Marble
0023 {
0024 
0025 class MarbleGraphicsItemPrivate
0026 {
0027  public:
0028     explicit MarbleGraphicsItemPrivate( MarbleGraphicsItem *marbleGraphicsItem,
0029                                         MarbleGraphicsItem *parent = nullptr )
0030         : m_repaintNeeded( true ),
0031           m_cacheMode( MarbleGraphicsItem::NoCache ),
0032           m_visibility( true ),
0033           m_parent( parent ),
0034           m_children(),
0035           m_layout( nullptr ),
0036           m_marbleGraphicsItem( marbleGraphicsItem )
0037     {
0038         if ( m_parent ) {
0039             m_parent->d_func()->addChild(m_marbleGraphicsItem);
0040         }
0041     }
0042 
0043     virtual ~MarbleGraphicsItemPrivate()
0044     {
0045         // Remove from parent
0046         if ( m_parent ) {
0047             m_parent->d_func()->removeChild(m_marbleGraphicsItem);
0048         }
0049 
0050         // Delete all children
0051         qDeleteAll( m_children.values() ); // delete using a copy, since children may invalidate m_children's iterator
0052 
0053         // Delete Layout
0054         delete m_layout;
0055     }
0056 
0057     void addChild( MarbleGraphicsItem *child )
0058     {
0059         m_children.insert( child );
0060     }
0061 
0062     void removeChild( MarbleGraphicsItem *child )
0063     {
0064         m_children.remove( child );
0065     }
0066 
0067     virtual QVector<QPointF> positions() const = 0;
0068 
0069     virtual QVector<QPointF> absolutePositions() const = 0;
0070 
0071     /**
0072      * @brief Used to get the set of screen bounding rects
0073      */
0074     QVector<QRectF> boundingRects() const;
0075 
0076     virtual void setProjection( const ViewportParams *viewport ) = 0;
0077 
0078     void updateChildPositions()
0079     {
0080         // This has to be done recursively because we need a correct size from all children.
0081         for ( MarbleGraphicsItem *item: m_children ) {
0082             item->d_func()->updateChildPositions();
0083         }
0084 
0085         // Adjust positions
0086         if ( m_layout ) {
0087             m_layout->updatePositions( m_marbleGraphicsItem );
0088         }
0089     }
0090 
0091     QSizeF m_size;
0092 
0093     bool m_repaintNeeded;
0094 
0095     MarbleGraphicsItem::CacheMode m_cacheMode;
0096 
0097     QPixmap m_pixmap;
0098 
0099     bool m_visibility;
0100 
0101     // The parent of the item
0102     MarbleGraphicsItem *const m_parent;
0103     // The set of children.
0104     QSet<MarbleGraphicsItem *> m_children;
0105 
0106     // The layout handling the positions of the children
0107     AbstractMarbleGraphicsLayout *m_layout;
0108 
0109     MarbleGraphicsItem *const m_marbleGraphicsItem;
0110 };
0111 
0112 }
0113 
0114 #endif