summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedrich W. H. Kossebau <kossebau@kde.org>2016-10-07 05:09:22 (GMT)
committerFriedrich W. H. Kossebau <kossebau@kde.org>2016-10-07 05:09:22 (GMT)
commitcafdd1e7322b96af4f155a6e1d433bdd2a44de8c (patch)
treeb5a9a9159fea2de62d30828dff14de42d4270127
parent3e280f9061d48eeeb97a29e213d6931a88dbd53e (diff)
Qt'fy access to pimpl objects for MarbleGraphicsItem & subclasses
Also remove separate pimpl objects and make subclasses of MarbleGraphicsItemPrivate: FrameGraphicsItemPrivate, LabelGraphicsItemPrivate, WidgetGraphicsItemPrivate
-rw-r--r--src/lib/marble/graphicsview/BillboardGraphicsItem.cpp41
-rw-r--r--src/lib/marble/graphicsview/BillboardGraphicsItem.h5
-rw-r--r--src/lib/marble/graphicsview/FrameGraphicsItem.cpp42
-rw-r--r--src/lib/marble/graphicsview/FrameGraphicsItem.h5
-rw-r--r--src/lib/marble/graphicsview/FrameGraphicsItem_p.h17
-rw-r--r--src/lib/marble/graphicsview/LabelGraphicsItem.cpp21
-rw-r--r--src/lib/marble/graphicsview/LabelGraphicsItem.h3
-rw-r--r--src/lib/marble/graphicsview/LabelGraphicsItem_p.h9
-rw-r--r--src/lib/marble/graphicsview/MarbleGraphicsItem.cpp114
-rw-r--r--src/lib/marble/graphicsview/MarbleGraphicsItem.h10
-rw-r--r--src/lib/marble/graphicsview/MarbleGraphicsItem_p.h6
-rw-r--r--src/lib/marble/graphicsview/ScreenGraphicsItem.cpp59
-rw-r--r--src/lib/marble/graphicsview/ScreenGraphicsItem.h5
-rw-r--r--src/lib/marble/graphicsview/WidgetGraphicsItem.cpp27
-rw-r--r--src/lib/marble/graphicsview/WidgetGraphicsItem.h3
-rw-r--r--src/lib/marble/graphicsview/WidgetGraphicsItem_p.h8
16 files changed, 213 insertions, 162 deletions
diff --git a/src/lib/marble/graphicsview/BillboardGraphicsItem.cpp b/src/lib/marble/graphicsview/BillboardGraphicsItem.cpp
index 2752c3a..471b0b7 100644
--- a/src/lib/marble/graphicsview/BillboardGraphicsItem.cpp
+++ b/src/lib/marble/graphicsview/BillboardGraphicsItem.cpp
@@ -19,11 +19,11 @@
namespace Marble
{
-class Q_DECL_HIDDEN BillboardGraphicsItem::Private : public MarbleGraphicsItemPrivate
+class BillboardGraphicsItemPrivate : public MarbleGraphicsItemPrivate
{
public:
- Private( BillboardGraphicsItem *parent ) :
- MarbleGraphicsItemPrivate( parent ),
+ BillboardGraphicsItemPrivate(BillboardGraphicsItem *parent)
+ : MarbleGraphicsItemPrivate(parent),
m_alignment( Qt::AlignHCenter | Qt::AlignVCenter )
{
}
@@ -89,32 +89,37 @@ class Q_DECL_HIDDEN BillboardGraphicsItem::Private : public MarbleGraphicsItemPr
};
BillboardGraphicsItem::BillboardGraphicsItem()
- : MarbleGraphicsItem( new Private( this ) )
+ : MarbleGraphicsItem(new BillboardGraphicsItemPrivate(this))
{
}
GeoDataCoordinates BillboardGraphicsItem::coordinate() const
{
- return p()->m_coordinates;
+ Q_D(const BillboardGraphicsItem);
+ return d->m_coordinates;
}
void BillboardGraphicsItem::setCoordinate( const GeoDataCoordinates &coordinates )
{
- p()->m_coordinates = coordinates;
+ Q_D(BillboardGraphicsItem);
+ d->m_coordinates = coordinates;
}
QVector<QPointF> BillboardGraphicsItem::positions() const
{
- return p()->positions();
+ Q_D(const BillboardGraphicsItem);
+ return d->positions();
}
QVector<QRectF> BillboardGraphicsItem::boundingRects() const
{
+ Q_D(const BillboardGraphicsItem);
+
QVector<QRectF> rects;
- rects.reserve(p()->m_positions.size());
+ rects.reserve(d->m_positions.size());
- QSizeF const size = p()->m_size;
- foreach(const QPointF &point, p()->m_positions) {
+ QSizeF const size = d->m_size;
+ foreach (const QPointF &point, d->m_positions) {
rects << QRectF(point, size);
}
return rects;
@@ -132,22 +137,14 @@ QRectF BillboardGraphicsItem::containsRect( const QPointF &point ) const
Qt::Alignment BillboardGraphicsItem::alignment() const
{
- return p()->m_alignment;
+ Q_D(const BillboardGraphicsItem);
+ return d->m_alignment;
}
void BillboardGraphicsItem::setAlignment(Qt::Alignment alignment)
{
- p()->m_alignment = alignment;
-}
-
-BillboardGraphicsItem::Private *BillboardGraphicsItem::p()
-{
- return static_cast<Private *>( d );
-}
-
-const BillboardGraphicsItem::Private *BillboardGraphicsItem::p() const
-{
- return static_cast<Private *>( d );
+ Q_D(BillboardGraphicsItem);
+ d->m_alignment = alignment;
}
} // Marble namespace
diff --git a/src/lib/marble/graphicsview/BillboardGraphicsItem.h b/src/lib/marble/graphicsview/BillboardGraphicsItem.h
index 6355226..6dc41c8 100644
--- a/src/lib/marble/graphicsview/BillboardGraphicsItem.h
+++ b/src/lib/marble/graphicsview/BillboardGraphicsItem.h
@@ -21,6 +21,7 @@ class QPointF;
namespace Marble
{
class GeoDataCoordinates;
+class BillboardGraphicsItemPrivate;
/**
* @brief Base class for all 2D labels (a.k.a. billboards) in 3D space.
@@ -63,9 +64,7 @@ class MARBLE_EXPORT BillboardGraphicsItem : public MarbleGraphicsItem
QRectF containsRect( const QPointF &point ) const;
private:
- class Private;
- Private *p();
- const Private *p() const;
+ Q_DECLARE_PRIVATE(BillboardGraphicsItem)
};
} // Marble namespace
diff --git a/src/lib/marble/graphicsview/FrameGraphicsItem.cpp b/src/lib/marble/graphicsview/FrameGraphicsItem.cpp
index 261f42f..8a90526 100644
--- a/src/lib/marble/graphicsview/FrameGraphicsItem.cpp
+++ b/src/lib/marble/graphicsview/FrameGraphicsItem.cpp
@@ -25,34 +25,45 @@
using namespace Marble;
FrameGraphicsItem::FrameGraphicsItem( MarbleGraphicsItem *parent )
- : ScreenGraphicsItem( parent ),
- d( new FrameGraphicsItemPrivate( this ) )
+ : ScreenGraphicsItem(new FrameGraphicsItemPrivate(this, parent))
{
+ Q_D(FrameGraphicsItem);
+ d->updateSize();
+}
+
+FrameGraphicsItem::FrameGraphicsItem(FrameGraphicsItemPrivate *dd)
+ : ScreenGraphicsItem(dd)
+{
+ Q_D(FrameGraphicsItem);
+ d->updateSize();
}
FrameGraphicsItem::~FrameGraphicsItem()
{
- delete d;
}
FrameGraphicsItem::FrameType FrameGraphicsItem::frame() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_frame;
}
void FrameGraphicsItem::setFrame( FrameType type )
{
+ Q_D(FrameGraphicsItem);
d->m_frame = type;
setPadding( padding() );
}
qreal FrameGraphicsItem::margin() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_margin;
}
void FrameGraphicsItem::setMargin( qreal margin )
{
+ Q_D(FrameGraphicsItem);
d->m_margin = margin;
d->updateSize();
update();
@@ -60,11 +71,13 @@ void FrameGraphicsItem::setMargin( qreal margin )
qreal FrameGraphicsItem::marginTop() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_marginTop;
}
void FrameGraphicsItem::setMarginTop( qreal marginTop )
{
+ Q_D(FrameGraphicsItem);
d->m_marginTop = marginTop;
d->updateSize();
update();
@@ -72,11 +85,13 @@ void FrameGraphicsItem::setMarginTop( qreal marginTop )
qreal FrameGraphicsItem::marginBottom() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_marginBottom;
}
void FrameGraphicsItem::setMarginBottom( qreal marginBottom )
{
+ Q_D(FrameGraphicsItem);
d->m_marginBottom = marginBottom;
d->updateSize();
update();
@@ -84,11 +99,13 @@ void FrameGraphicsItem::setMarginBottom( qreal marginBottom )
qreal FrameGraphicsItem::marginLeft() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_marginLeft;
}
void FrameGraphicsItem::setMarginLeft( qreal marginLeft )
{
+ Q_D(FrameGraphicsItem);
d->m_marginLeft = marginLeft;
d->updateSize();
update();
@@ -96,11 +113,13 @@ void FrameGraphicsItem::setMarginLeft( qreal marginLeft )
qreal FrameGraphicsItem::marginRight() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_marginRight;
}
void FrameGraphicsItem::setMarginRight( qreal marginRight )
{
+ Q_D(FrameGraphicsItem);
d->m_marginRight = marginRight;
d->updateSize();
update();
@@ -108,11 +127,13 @@ void FrameGraphicsItem::setMarginRight( qreal marginRight )
qreal FrameGraphicsItem::borderWidth() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_borderWidth;
}
void FrameGraphicsItem::setBorderWidth( qreal width )
{
+ Q_D(FrameGraphicsItem);
d->m_borderWidth = width;
d->updateSize();
update();
@@ -120,11 +141,13 @@ void FrameGraphicsItem::setBorderWidth( qreal width )
qreal FrameGraphicsItem::padding() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_padding;
}
void FrameGraphicsItem::setPadding( qreal width )
{
+ Q_D(FrameGraphicsItem);
if ( width >= 0 ) {
d->m_padding = width;
d->updateSize();
@@ -133,39 +156,46 @@ void FrameGraphicsItem::setPadding( qreal width )
QBrush FrameGraphicsItem::borderBrush() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_borderBrush;
}
void FrameGraphicsItem::setBorderBrush( const QBrush &brush )
{
+ Q_D(FrameGraphicsItem);
d->m_borderBrush = brush;
update();
}
Qt::PenStyle FrameGraphicsItem::borderStyle () const
{
+ Q_D(const FrameGraphicsItem);
return d->m_borderStyle;
}
void FrameGraphicsItem::setBorderStyle( Qt::PenStyle style )
{
+ Q_D(FrameGraphicsItem);
d->m_borderStyle = style;
update();
}
QBrush FrameGraphicsItem::background() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_backgroundBrush;
}
void FrameGraphicsItem::setBackground( const QBrush &background )
{
+ Q_D(FrameGraphicsItem);
d->m_backgroundBrush = background;
update();
}
QRectF FrameGraphicsItem::contentRect() const
{
+ Q_D(const FrameGraphicsItem);
qreal marginTop = ( d->m_marginTop == 0.0 ) ? d->m_margin : d->m_marginTop;
qreal marginLeft = ( d->m_marginLeft == 0.0 ) ? d->m_margin : d->m_marginLeft;
@@ -179,11 +209,13 @@ QRectF FrameGraphicsItem::contentRect() const
QSizeF FrameGraphicsItem::contentSize() const
{
+ Q_D(const FrameGraphicsItem);
return d->m_contentSize;
}
QRectF FrameGraphicsItem::paintedRect() const
{
+ Q_D(const FrameGraphicsItem);
qreal marginTop = ( d->m_marginTop == 0.0 ) ? d->m_margin : d->m_marginTop;
qreal marginBottom = ( d->m_marginBottom == 0.0 ) ? d->m_margin : d->m_marginBottom;
qreal marginLeft = ( d->m_marginLeft == 0.0 ) ? d->m_margin : d->m_marginLeft;
@@ -199,12 +231,14 @@ QRectF FrameGraphicsItem::paintedRect() const
void FrameGraphicsItem::setContentSize( const QSizeF& size )
{
+ Q_D(FrameGraphicsItem);
d->m_contentSize = size;
d->updateSize();
}
QPainterPath FrameGraphicsItem::backgroundShape() const
{
+ Q_D(const FrameGraphicsItem);
QPainterPath path;
if ( d->m_frame == RectFrame || d->m_frame == ShadowFrame ) {
QRectF renderedRect = paintedRect();
@@ -220,6 +254,7 @@ QPainterPath FrameGraphicsItem::backgroundShape() const
void FrameGraphicsItem::paintBackground( QPainter *painter )
{
+ Q_D(FrameGraphicsItem);
painter->save();
painter->setPen( QPen( d->m_borderBrush, d->m_borderWidth, d->m_borderStyle ) );
painter->setBrush( d->m_backgroundBrush );
@@ -230,6 +265,7 @@ void FrameGraphicsItem::paintBackground( QPainter *painter )
void FrameGraphicsItem::paint( QPainter *painter )
{
+ Q_D(FrameGraphicsItem);
painter->save();
// Needs to be done here cause we don't want the margin translation
diff --git a/src/lib/marble/graphicsview/FrameGraphicsItem.h b/src/lib/marble/graphicsview/FrameGraphicsItem.h
index a110f4a..c876ecd 100644
--- a/src/lib/marble/graphicsview/FrameGraphicsItem.h
+++ b/src/lib/marble/graphicsview/FrameGraphicsItem.h
@@ -183,10 +183,11 @@ class MARBLE_EXPORT FrameGraphicsItem : public ScreenGraphicsItem
*/
virtual void paintBackground( QPainter *painter );
+ explicit FrameGraphicsItem(FrameGraphicsItemPrivate *dd);
+
private:
Q_DISABLE_COPY( FrameGraphicsItem )
-
- FrameGraphicsItemPrivate * const d;
+ Q_DECLARE_PRIVATE(FrameGraphicsItem)
};
} // namespace Marble
diff --git a/src/lib/marble/graphicsview/FrameGraphicsItem_p.h b/src/lib/marble/graphicsview/FrameGraphicsItem_p.h
index 97914fe..88fee84 100644
--- a/src/lib/marble/graphicsview/FrameGraphicsItem_p.h
+++ b/src/lib/marble/graphicsview/FrameGraphicsItem_p.h
@@ -13,6 +13,7 @@
// Marble
#include "FrameGraphicsItem.h"
+#include "ScreenGraphicsItem_p.h"
// Qt
#include<QDebug>
@@ -21,11 +22,13 @@
namespace Marble
{
-class FrameGraphicsItemPrivate
+class FrameGraphicsItemPrivate : public ScreenGraphicsItemPrivate
{
public:
- explicit FrameGraphicsItemPrivate( FrameGraphicsItem *parent )
- : m_frame( FrameGraphicsItem::NoFrame ),
+ FrameGraphicsItemPrivate(FrameGraphicsItem *frameGraphicsItem,
+ MarbleGraphicsItem *parent)
+ : ScreenGraphicsItemPrivate(frameGraphicsItem, parent),
+ m_frame(FrameGraphicsItem::NoFrame),
m_contentSize( 0.0, 0.0 ),
m_margin( 0.0 ),
m_marginTop( 0.0 ),
@@ -36,10 +39,8 @@ class FrameGraphicsItemPrivate
m_borderWidth( 1.0 ),
m_borderBrush( QBrush( Qt::black ) ),
m_borderStyle( Qt::SolidLine ),
- m_backgroundBrush( QBrush( QColor( 192, 192, 192, 192 ) ) ),
- m_parent( parent )
+ m_backgroundBrush(QBrush(QColor(192, 192, 192, 192)))
{
- updateSize();
}
void updateSize()
@@ -54,7 +55,7 @@ class FrameGraphicsItemPrivate
totalSize += QSizeF( marginLeft + marginRight, marginTop + marginBottom );
totalSize += QSizeF( m_padding * 2, m_padding * 2 );
- m_parent->setSize( totalSize );
+ m_marbleGraphicsItem->setSize(totalSize);
}
FrameGraphicsItem::FrameType m_frame;
@@ -74,8 +75,6 @@ class FrameGraphicsItemPrivate
QBrush m_borderBrush;
Qt::PenStyle m_borderStyle;
QBrush m_backgroundBrush;
-
- FrameGraphicsItem * const m_parent;
};
} // namespace Marble
diff --git a/src/lib/marble/graphicsview/LabelGraphicsItem.cpp b/src/lib/marble/graphicsview/LabelGraphicsItem.cpp
index 1f6721d..cf2fb15 100644
--- a/src/lib/marble/graphicsview/LabelGraphicsItem.cpp
+++ b/src/lib/marble/graphicsview/LabelGraphicsItem.cpp
@@ -20,9 +20,9 @@
using namespace Marble;
-LabelGraphicsItemPrivate::LabelGraphicsItemPrivate( LabelGraphicsItem *parent )
- : m_text(),
- m_parent( parent )
+LabelGraphicsItemPrivate::LabelGraphicsItemPrivate(LabelGraphicsItem *labelGraphicsItem,
+ MarbleGraphicsItem *parent)
+ : FrameGraphicsItemPrivate(labelGraphicsItem, parent)
{
}
@@ -33,6 +33,7 @@ QFont LabelGraphicsItemPrivate::font()
void LabelGraphicsItem::setContentSize( const QSizeF &contentSize )
{
+ Q_D(LabelGraphicsItem);
QSizeF updatedSize = contentSize;
if ( updatedSize.isEmpty() ) {
updatedSize.setHeight( 0 );
@@ -53,23 +54,23 @@ void LabelGraphicsItem::setContentSize( const QSizeF &contentSize )
// ----------------------------------------------------------------
LabelGraphicsItem::LabelGraphicsItem( MarbleGraphicsItem *parent )
- : FrameGraphicsItem( parent ),
- d( new LabelGraphicsItemPrivate( this ) )
+ : FrameGraphicsItem(new LabelGraphicsItemPrivate(this, parent))
{
}
LabelGraphicsItem::~LabelGraphicsItem()
{
- delete d;
}
QString LabelGraphicsItem::text() const
{
+ Q_D(const LabelGraphicsItem);
return d->m_text;
}
void LabelGraphicsItem::setText( const QString& text )
{
+ Q_D(LabelGraphicsItem);
clear();
d->m_text = text;
QFontMetrics metrics( d->font() );
@@ -79,11 +80,13 @@ void LabelGraphicsItem::setText( const QString& text )
QImage LabelGraphicsItem::image() const
{
+ Q_D(const LabelGraphicsItem);
return d->m_image;
}
void LabelGraphicsItem::setImage( const QImage& image, const QSize& size )
{
+ Q_D(LabelGraphicsItem);
clear();
d->m_image = image;
if ( size.isEmpty() ) {
@@ -96,11 +99,13 @@ void LabelGraphicsItem::setImage( const QImage& image, const QSize& size )
QIcon LabelGraphicsItem::icon() const
{
+ Q_D(const LabelGraphicsItem);
return d->m_icon;
}
void LabelGraphicsItem::setIcon( const QIcon& icon, const QSize& size )
{
+ Q_D(LabelGraphicsItem);
clear();
d->m_icon = icon;
setContentSize( size );
@@ -108,11 +113,13 @@ void LabelGraphicsItem::setIcon( const QIcon& icon, const QSize& size )
QSizeF LabelGraphicsItem::minimumSize() const
{
+ Q_D(const LabelGraphicsItem);
return d->m_minimumSize;
}
void LabelGraphicsItem::setMinimumSize( const QSizeF& size )
{
+ Q_D(LabelGraphicsItem);
const QSizeF oldContentSize = contentSize();
d->m_minimumSize = size;
setContentSize( oldContentSize );
@@ -120,6 +127,7 @@ void LabelGraphicsItem::setMinimumSize( const QSizeF& size )
void LabelGraphicsItem::clear()
{
+ Q_D(LabelGraphicsItem);
d->m_text.clear();
d->m_image = QImage();
d->m_icon = QIcon();
@@ -128,6 +136,7 @@ void LabelGraphicsItem::clear()
void LabelGraphicsItem::paintContent( QPainter *painter )
{
+ Q_D(LabelGraphicsItem);
painter->save();
if ( !d->m_text.isNull() ) {
diff --git a/src/lib/marble/graphicsview/LabelGraphicsItem.h b/src/lib/marble/graphicsview/LabelGraphicsItem.h
index 15223a0..43b7602 100644
--- a/src/lib/marble/graphicsview/LabelGraphicsItem.h
+++ b/src/lib/marble/graphicsview/LabelGraphicsItem.h
@@ -57,8 +57,7 @@ class MARBLE_EXPORT LabelGraphicsItem : public FrameGraphicsItem
private:
Q_DISABLE_COPY( LabelGraphicsItem )
-
- LabelGraphicsItemPrivate * const d;
+ Q_DECLARE_PRIVATE(LabelGraphicsItem)
};
} // namespace Marble
diff --git a/src/lib/marble/graphicsview/LabelGraphicsItem_p.h b/src/lib/marble/graphicsview/LabelGraphicsItem_p.h
index e38aa56..cc76f65 100644
--- a/src/lib/marble/graphicsview/LabelGraphicsItem_p.h
+++ b/src/lib/marble/graphicsview/LabelGraphicsItem_p.h
@@ -11,6 +11,8 @@
#ifndef MARBLE_LABELGRAPHICSITEMPRIVATE_H
#define MARBLE_LABELGRAPHICSITEMPRIVATE_H
+#include "FrameGraphicsItem_p.h"
+
#include <QString>
#include <QSizeF>
#include <QImage>
@@ -23,10 +25,11 @@ namespace Marble
class LabelGraphicsItem;
-class LabelGraphicsItemPrivate
+class LabelGraphicsItemPrivate : public FrameGraphicsItemPrivate
{
public:
- explicit LabelGraphicsItemPrivate( LabelGraphicsItem *parent );
+ LabelGraphicsItemPrivate(LabelGraphicsItem *labelGraphicsItem,
+ MarbleGraphicsItem *parent);
// TODO: This has to go up to MarbleGraphicsItem
static QFont font();
@@ -36,8 +39,6 @@ class LabelGraphicsItemPrivate
QIcon m_icon;
QSizeF m_minimumSize;
-
- LabelGraphicsItem *m_parent;
};
} // namespace Marble
diff --git a/src/lib/marble/graphicsview/MarbleGraphicsItem.cpp b/src/lib/marble/graphicsview/MarbleGraphicsItem.cpp
index adacbde..19cec82 100644
--- a/src/lib/marble/graphicsview/MarbleGraphicsItem.cpp
+++ b/src/lib/marble/graphicsview/MarbleGraphicsItem.cpp
@@ -24,31 +24,33 @@
using namespace Marble;
-MarbleGraphicsItem::MarbleGraphicsItem( MarbleGraphicsItemPrivate *d_ptr )
- : d( d_ptr )
+MarbleGraphicsItem::MarbleGraphicsItem(MarbleGraphicsItemPrivate *dd)
+ : d_ptr(dd)
{
}
-
+
MarbleGraphicsItem::~MarbleGraphicsItem()
{
- delete d;
+ delete d_ptr;
}
bool MarbleGraphicsItem::paintEvent( QPainter *painter, const ViewportParams *viewport )
{
- if ( !p()->m_visibility ) {
+ Q_D(MarbleGraphicsItem);
+
+ if (!d->m_visibility) {
return true;
}
- if ( p()->m_repaintNeeded ) {
- p()->updateChildPositions();
- p()->m_pixmap = QPixmap();
- p()->m_repaintNeeded = false;
+ if (d->m_repaintNeeded) {
+ d->updateChildPositions();
+ d->m_pixmap = QPixmap();
+ d->m_repaintNeeded = false;
}
setProjection( viewport );
- if ( p()->positions().size() == 0 ) {
+ if (d->positions().size() == 0) {
return true;
}
@@ -61,20 +63,20 @@ bool MarbleGraphicsItem::paintEvent( QPainter *painter, const ViewportParams *vi
const QSize neededPixmapSize = scale * size().toSize() + QSize( 1, 1 ); // adding a pixel for rounding errors
- if ( p()->m_pixmap.size() != neededPixmapSize ||
- p()->m_pixmap.devicePixelRatio() != scale ) {
+ if (d->m_pixmap.size() != neededPixmapSize ||
+ d->m_pixmap.devicePixelRatio() != scale) {
if ( size().isValid() && !size().isNull() ) {
- p()->m_pixmap = QPixmap( neededPixmapSize );
- p()->m_pixmap.setDevicePixelRatio( scale );
+ d->m_pixmap = QPixmap(neededPixmapSize);
+ d->m_pixmap.setDevicePixelRatio(scale);
}
else {
mDebug() << "Warning: Invalid pixmap size suggested: " << d->m_size;
}
- p()->m_pixmap.fill( Qt::transparent );
- QPainter pixmapPainter( &p()->m_pixmap );
+ d->m_pixmap.fill(Qt::transparent);
+ QPainter pixmapPainter(&d->m_pixmap);
// We paint in best quality here, as we only have to paint once.
pixmapPainter.setRenderHint( QPainter::Antialiasing, true );
// The cache image will get a 0.5 pixel bounding to save antialiasing effects.
@@ -82,24 +84,24 @@ bool MarbleGraphicsItem::paintEvent( QPainter *painter, const ViewportParams *vi
paint( &pixmapPainter );
// Paint children
- foreach ( MarbleGraphicsItem *item, p()->m_children ) {
+ foreach (MarbleGraphicsItem *item, d->m_children) {
item->paintEvent( &pixmapPainter, viewport );
}
}
- foreach( const QPointF& position, p()->positions() ) {
- painter->drawPixmap( position, p()->m_pixmap );
+ foreach (const QPointF& position, d->positions()) {
+ painter->drawPixmap(position, d->m_pixmap);
}
}
else {
- foreach( const QPointF& position, p()->positions() ) {
+ foreach (const QPointF& position, d->positions()) {
painter->save();
painter->translate( position );
paint( painter );
// Paint children
- foreach ( MarbleGraphicsItem *item, p()->m_children ) {
+ foreach (MarbleGraphicsItem *item, d->m_children) {
item->paintEvent( painter, viewport );
}
@@ -112,7 +114,8 @@ bool MarbleGraphicsItem::paintEvent( QPainter *painter, const ViewportParams *vi
bool MarbleGraphicsItem::contains( const QPointF& point ) const
{
- foreach( const QRectF& rect, d->boundingRects() ) {
+ Q_D(const MarbleGraphicsItem);
+ foreach (const QRectF& rect, d->boundingRects()) {
if( rect.contains( point ) )
return true;
}
@@ -141,53 +144,61 @@ QVector<QRectF> MarbleGraphicsItemPrivate::boundingRects() const
QSizeF MarbleGraphicsItem::size() const
{
- return p()->m_size;
+ Q_D(const MarbleGraphicsItem);
+ return d->m_size;
}
AbstractMarbleGraphicsLayout *MarbleGraphicsItem::layout() const
{
- return p()->m_layout;
+ Q_D(const MarbleGraphicsItem);
+ return d->m_layout;
}
void MarbleGraphicsItem::setLayout( AbstractMarbleGraphicsLayout *layout )
{
+ Q_D(MarbleGraphicsItem);
// Deleting the old layout
- delete p()->m_layout;
- p()->m_layout = layout;
+ delete d->m_layout;
+ d->m_layout = layout;
update();
}
MarbleGraphicsItem::CacheMode MarbleGraphicsItem::cacheMode() const
{
- return p()->m_cacheMode;
+ Q_D(const MarbleGraphicsItem);
+ return d->m_cacheMode;
}
void MarbleGraphicsItem::setCacheMode( CacheMode mode )
{
- p()->m_cacheMode = mode;
- if ( p()->m_cacheMode == NoCache ) {
- p()->m_repaintNeeded = true;
+ Q_D(MarbleGraphicsItem);
+ d->m_cacheMode = mode;
+ if (d->m_cacheMode == NoCache) {
+ d->m_repaintNeeded = true;
}
}
void MarbleGraphicsItem::update()
{
- p()->m_repaintNeeded = true;
+ Q_D(MarbleGraphicsItem);
+ d->m_repaintNeeded = true;
// Update the parent.
- if ( p()->m_parent ) {
- p()->m_parent->update();
+ if (d->m_parent) {
+ d->m_parent->update();
}
}
bool MarbleGraphicsItem::visible() const
{
- return p()->m_visibility;
+ Q_D(const MarbleGraphicsItem);
+ return d->m_visibility;
}
void MarbleGraphicsItem::setVisible( bool visible )
{
- p()->m_visibility = visible;
+ Q_D(MarbleGraphicsItem);
+ d->m_visibility = visible;
}
void MarbleGraphicsItem::hide()
@@ -202,8 +213,9 @@ void MarbleGraphicsItem::show()
void MarbleGraphicsItem::setSize( const QSizeF& size )
{
- if ( p()->m_size != size ) {
- p()->m_size = size;
+ Q_D(MarbleGraphicsItem);
+ if (d->m_size != size) {
+ d->m_size = size;
update();
}
}
@@ -237,18 +249,19 @@ bool MarbleGraphicsItem::eventFilter( QObject *object, QEvent *e )
{
return false;
}
-
+
+ Q_D(const MarbleGraphicsItem);
QMouseEvent *event = static_cast<QMouseEvent*> (e);
-
- if( !p()->m_children.isEmpty() ) {
- const QVector<QPointF> absolutePositions = p()->absolutePositions();
-
+
+ if (!d->m_children.isEmpty()) {
+ const QVector<QPointF> absolutePositions = d->absolutePositions();
+
foreach( const QPointF& absolutePosition, absolutePositions ) {
QPoint shiftedPos = event->pos() - absolutePosition.toPoint();
if ( QRect( QPoint( 0, 0 ), size().toSize() ).contains( shiftedPos ) ) {
- foreach( MarbleGraphicsItem *child, p()->m_children ) {
- const QVector<QRectF> childRects = child->d->boundingRects();
+ foreach (MarbleGraphicsItem *child, d->m_children) {
+ const QVector<QRectF> childRects = child->d_func()->boundingRects();
foreach( const QRectF& childRect, childRects ) {
if( childRect.toRect().contains( shiftedPos ) ) {
@@ -265,17 +278,8 @@ bool MarbleGraphicsItem::eventFilter( QObject *object, QEvent *e )
return false;
}
-MarbleGraphicsItemPrivate *MarbleGraphicsItem::p()
-{
- return d;
-}
-
-const MarbleGraphicsItemPrivate *MarbleGraphicsItem::p() const
-{
- return d;
-}
-
void MarbleGraphicsItem::setProjection( const ViewportParams *viewport )
{
- p()->setProjection( viewport );
+ Q_D(MarbleGraphicsItem);
+ d->setProjection(viewport);
}
diff --git a/src/lib/marble/graphicsview/MarbleGraphicsItem.h b/src/lib/marble/graphicsview/MarbleGraphicsItem.h
index 66ba5a7..2a14aef 100644
--- a/src/lib/marble/graphicsview/MarbleGraphicsItem.h
+++ b/src/lib/marble/graphicsview/MarbleGraphicsItem.h
@@ -13,6 +13,8 @@
#include "marble_export.h"
+#include <QtGlobal>
+
class QEvent;
class QObject;
class QPainter;
@@ -122,7 +124,7 @@ class MARBLE_EXPORT MarbleGraphicsItem
virtual void setProjection(const ViewportParams *viewport );
protected:
- explicit MarbleGraphicsItem( MarbleGraphicsItemPrivate *d_ptr );
+ explicit MarbleGraphicsItem(MarbleGraphicsItemPrivate *dd);
/**
* Paints the item in item coordinates. This has to be reimplemented by the subclass
@@ -138,11 +140,11 @@ class MARBLE_EXPORT MarbleGraphicsItem
*/
void update();
- MarbleGraphicsItemPrivate * const d;
+ protected:
+ MarbleGraphicsItemPrivate * const d_ptr;
private:
- MarbleGraphicsItemPrivate* p();
- const MarbleGraphicsItemPrivate* p() const;
+ Q_DECLARE_PRIVATE(MarbleGraphicsItem)
};
} // Namespace Marble
diff --git a/src/lib/marble/graphicsview/MarbleGraphicsItem_p.h b/src/lib/marble/graphicsview/MarbleGraphicsItem_p.h
index f9a6b35..d55986b 100644
--- a/src/lib/marble/graphicsview/MarbleGraphicsItem_p.h
+++ b/src/lib/marble/graphicsview/MarbleGraphicsItem_p.h
@@ -41,7 +41,7 @@ class MarbleGraphicsItemPrivate
m_marbleGraphicsItem( marbleGraphicsItem )
{
if ( m_parent ) {
- m_parent->p()->addChild( m_marbleGraphicsItem );
+ m_parent->d_func()->addChild(m_marbleGraphicsItem);
}
}
@@ -49,7 +49,7 @@ class MarbleGraphicsItemPrivate
{
// Remove from parent
if ( m_parent ) {
- m_parent->p()->removeChild( m_marbleGraphicsItem );
+ m_parent->d_func()->removeChild(m_marbleGraphicsItem);
}
// Delete all children
@@ -84,7 +84,7 @@ class MarbleGraphicsItemPrivate
{
// This has to be done recursively because we need a correct size from all children.
foreach ( MarbleGraphicsItem *item, m_children ) {
- item->p()->updateChildPositions();
+ item->d_func()->updateChildPositions();
}
// Adjust positions
diff --git a/src/lib/marble/graphicsview/ScreenGraphicsItem.cpp b/src/lib/marble/graphicsview/ScreenGraphicsItem.cpp
index cc6ef4b..ba5145e 100644
--- a/src/lib/marble/graphicsview/ScreenGraphicsItem.cpp
+++ b/src/lib/marble/graphicsview/ScreenGraphicsItem.cpp
@@ -27,8 +27,8 @@ ScreenGraphicsItem::ScreenGraphicsItem( MarbleGraphicsItem *parent )
{
}
-ScreenGraphicsItem::ScreenGraphicsItem( ScreenGraphicsItemPrivate *d_ptr )
- : MarbleGraphicsItem( d_ptr )
+ScreenGraphicsItem::ScreenGraphicsItem(ScreenGraphicsItemPrivate *dd)
+ : MarbleGraphicsItem(dd)
{
}
@@ -38,32 +38,38 @@ ScreenGraphicsItem::~ScreenGraphicsItem()
QPointF ScreenGraphicsItem::position() const
{
- return p()->m_position;
+ Q_D(const ScreenGraphicsItem);
+ return d->m_position;
}
void ScreenGraphicsItem::setPosition( const QPointF& position )
{
- p()->m_position = position;
+ Q_D(ScreenGraphicsItem);
+ d->m_position = position;
}
QPointF ScreenGraphicsItem::positivePosition() const
{
- return p()->positivePosition();
+ Q_D(const ScreenGraphicsItem);
+ return d->positivePosition();
}
QVector<QPointF> ScreenGraphicsItem::absolutePositions() const
{
- return p()->absolutePositions();
+ Q_D(const ScreenGraphicsItem);
+ return d->absolutePositions();
}
ScreenGraphicsItem::GraphicsItemFlags ScreenGraphicsItem::flags() const
{
- return p()->m_flags;
+ Q_D(const ScreenGraphicsItem);
+ return d->m_flags;
}
void ScreenGraphicsItem::setFlags( ScreenGraphicsItem::GraphicsItemFlags flags )
{
- p()->m_flags = flags;
+ Q_D(ScreenGraphicsItem);
+ d->m_flags = flags;
}
bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e )
@@ -72,13 +78,14 @@ bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e )
if ( !widget ) {
return MarbleGraphicsItem::eventFilter( object, e );
}
-
- if ( !p()->m_floatItemMoving ) {
+
+ Q_D(ScreenGraphicsItem);
+ if (!d->m_floatItemMoving) {
if ( MarbleGraphicsItem::eventFilter( object, e ) ) {
return true;
}
-
- if ( !visible() || !p()->isMovable() ) {
+
+ if (!visible() || !d->isMovable()) {
return false;
}
@@ -94,8 +101,8 @@ bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e )
// Click and move above a float item triggers moving the float item
if ( contains( event->pos() ) ) {
if ( event->button() == Qt::LeftButton ) {
- p()->m_floatItemMoveStartPos = event->pos();
- p()->m_floatItemMoving = true;
+ d->m_floatItemMoveStartPos = event->pos();
+ d->m_floatItemMoving = true;
return true;
}
}
@@ -118,22 +125,22 @@ bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e )
if ( e->type() == QEvent::MouseMove && event->buttons() & Qt::LeftButton ) {
const QPoint &point = event->pos();
QPointF position = positivePosition();
- qreal newX = qMax<qreal>( 0, position.x()+point.x()-p()->m_floatItemMoveStartPos.x() );
- qreal newY = qMax<qreal>( 0, position.y()+point.y()-p()->m_floatItemMoveStartPos.y() );
+ qreal newX = qMax<qreal>(0, position.x() + point.x() - d->m_floatItemMoveStartPos.x());
+ qreal newY = qMax<qreal>(0, position.y() + point.y() - d->m_floatItemMoveStartPos.y());
// docking behavior
const qreal dockArea = 60.0; // Alignment area width/height
const qreal dockJump = 30.0; // Alignment indicator jump size
if ( widget->width()-size().width()-newX < dockArea ) {
newX = qMin( qreal( -1.0 ), size().width() + newX-widget->width() );
- if ( p()->m_floatItemMoveStartPos.x() < event->pos().x() ) {
+ if (d->m_floatItemMoveStartPos.x() < event->pos().x()) {
// Indicate change to right alignment with a short jump
newX = qMax( newX, -(dockArea-dockJump) );
}
}
if ( widget->height()-size().height()-newY < dockArea ) {
newY = qMin( qreal( -1.0 ), size().height() + newY-widget->height() );
- if (p()->m_floatItemMoveStartPos.y()<event->pos().y()) {
+ if (d->m_floatItemMoveStartPos.y() < event->pos().y()) {
// Indicate change to bottom alignment with a short jump
newY = qMax( newY, -( dockArea - dockJump ) );
}
@@ -144,7 +151,7 @@ bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e )
// antialiasing could result into painting on these pixels to.
QRect newFloatItemRect = QRectF( positivePosition() - QPoint( 1, 1 ),
size() + QSize( 2, 2 ) ).toRect();
- p()->m_floatItemMoveStartPos = event->pos();
+ d->m_floatItemMoveStartPos = event->pos();
QRegion dirtyRegion( floatItemRect.toRect() );
dirtyRegion = dirtyRegion.united( newFloatItemRect );
@@ -155,11 +162,11 @@ bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e )
}
if ( e->type() == QEvent::MouseButtonRelease ) {
- p()->m_floatItemMoving = false;
+ d->m_floatItemMoving = false;
}
// Use a special cursor as long as the item is moved
- if ( p()->m_floatItemMoving ) {
+ if (d->m_floatItemMoving) {
widget->setCursor(QCursor(Qt::SizeAllCursor));
return true;
}
@@ -168,13 +175,3 @@ bool ScreenGraphicsItem::eventFilter( QObject *object, QEvent *e )
return MarbleGraphicsItem::eventFilter( object, e );
}
}
-
-ScreenGraphicsItemPrivate *ScreenGraphicsItem::p()
-{
- return static_cast<ScreenGraphicsItemPrivate *>( d );
-}
-
-const ScreenGraphicsItemPrivate *ScreenGraphicsItem::p() const
-{
- return static_cast<const ScreenGraphicsItemPrivate *>( d );
-}
diff --git a/src/lib/marble/graphicsview/ScreenGraphicsItem.h b/src/lib/marble/graphicsview/ScreenGraphicsItem.h
index 49104db..cc3a37a 100644
--- a/src/lib/marble/graphicsview/ScreenGraphicsItem.h
+++ b/src/lib/marble/graphicsview/ScreenGraphicsItem.h
@@ -92,13 +92,12 @@ class MARBLE_EXPORT ScreenGraphicsItem : public MarbleGraphicsItem
void setFlags( GraphicsItemFlags flags );
protected:
- explicit ScreenGraphicsItem( ScreenGraphicsItemPrivate *d_ptr );
+ explicit ScreenGraphicsItem(ScreenGraphicsItemPrivate *dd);
virtual bool eventFilter( QObject *, QEvent * );
private:
- ScreenGraphicsItemPrivate *p();
- const ScreenGraphicsItemPrivate *p() const;
+ Q_DECLARE_PRIVATE(ScreenGraphicsItem)
};
} // Namespace Marble
diff --git a/src/lib/marble/graphicsview/WidgetGraphicsItem.cpp b/src/lib/marble/graphicsview/WidgetGraphicsItem.cpp
index 633f59e..b7ad8f8 100644
--- a/src/lib/marble/graphicsview/WidgetGraphicsItem.cpp
+++ b/src/lib/marble/graphicsview/WidgetGraphicsItem.cpp
@@ -24,7 +24,9 @@
using namespace Marble;
-WidgetGraphicsItemPrivate::WidgetGraphicsItemPrivate() :
+WidgetGraphicsItemPrivate::WidgetGraphicsItemPrivate(WidgetGraphicsItem *widgetGraphicsItem,
+ MarbleGraphicsItem *parent)
+ : ScreenGraphicsItemPrivate(widgetGraphicsItem, parent),
m_widget(0), m_marbleWidget(0), m_activeWidget( 0 )
{
// nothing to do
@@ -36,18 +38,19 @@ WidgetGraphicsItemPrivate::~WidgetGraphicsItemPrivate()
}
WidgetGraphicsItem::WidgetGraphicsItem( MarbleGraphicsItem *parent )
- : ScreenGraphicsItem( parent ),
- d( new WidgetGraphicsItemPrivate() )
+ : ScreenGraphicsItem(new WidgetGraphicsItemPrivate(this, parent))
{
}
-
-WidgetGraphicsItem::~WidgetGraphicsItem() {
- delete d;
+
+WidgetGraphicsItem::~WidgetGraphicsItem()
+{
}
-
-void WidgetGraphicsItem::setWidget( QWidget *widget ) {
+
+void WidgetGraphicsItem::setWidget(QWidget *widget)
+{
+ Q_D(WidgetGraphicsItem);
d->m_widget = widget;
-
+
QSize size = widget->sizeHint().expandedTo( widget->size() );
size = size.expandedTo( widget->minimumSize() );
size = size.boundedTo( widget->maximumSize() );
@@ -55,12 +58,15 @@ void WidgetGraphicsItem::setWidget( QWidget *widget ) {
widget->resize( size );
}
-QWidget *WidgetGraphicsItem::widget() const {
+QWidget *WidgetGraphicsItem::widget() const
+{
+ Q_D(const WidgetGraphicsItem);
return d->m_widget;
}
void WidgetGraphicsItem::paint( QPainter *painter )
{
+ Q_D(WidgetGraphicsItem);
if( d->m_widget == 0 )
return;
@@ -70,6 +76,7 @@ void WidgetGraphicsItem::paint( QPainter *painter )
bool WidgetGraphicsItem::eventFilter( QObject *object, QEvent *e )
{
+ Q_D(WidgetGraphicsItem);
if ( !visible() || d->m_widget == 0 ) {
return false;
}
diff --git a/src/lib/marble/graphicsview/WidgetGraphicsItem.h b/src/lib/marble/graphicsview/WidgetGraphicsItem.h
index 1367ff8..f80867d 100644
--- a/src/lib/marble/graphicsview/WidgetGraphicsItem.h
+++ b/src/lib/marble/graphicsview/WidgetGraphicsItem.h
@@ -42,8 +42,7 @@ class MARBLE_EXPORT WidgetGraphicsItem : public ScreenGraphicsItem
private:
Q_DISABLE_COPY( WidgetGraphicsItem )
-
- WidgetGraphicsItemPrivate * const d;
+ Q_DECLARE_PRIVATE(WidgetGraphicsItem)
};
} // Namespace Marble
diff --git a/src/lib/marble/graphicsview/WidgetGraphicsItem_p.h b/src/lib/marble/graphicsview/WidgetGraphicsItem_p.h
index e3033b7..ad2a876 100644
--- a/src/lib/marble/graphicsview/WidgetGraphicsItem_p.h
+++ b/src/lib/marble/graphicsview/WidgetGraphicsItem_p.h
@@ -11,6 +11,7 @@
#ifndef MARBLE_WIDGETGRAPHICSITEMPRIVATE_H
#define MARBLE_WIDGETGRAPHICSITEMPRIVATE_H
+#include "ScreenGraphicsItem_p.h"
#include "WidgetGraphicsItem.h"
class QWidget;
@@ -18,11 +19,12 @@ class QWidget;
namespace Marble
{
-class WidgetGraphicsItemPrivate
+class WidgetGraphicsItemPrivate : public ScreenGraphicsItemPrivate
{
public:
- WidgetGraphicsItemPrivate();
-
+ WidgetGraphicsItemPrivate(WidgetGraphicsItem *widgetGraphicsItem,
+ MarbleGraphicsItem *parent);
+
~WidgetGraphicsItemPrivate();
QWidget *m_widget;