summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <nienhueser@kde.org>2016-09-04 11:03:41 (GMT)
committerDennis Nienhüser <nienhueser@kde.org>2016-09-04 11:03:41 (GMT)
commitf644c48a9109420363810fa74b94c647ec2ef87f (patch)
treede447c5e52b9dd49225f5ef979b6c796a1613a33
parent7e767314ced51c9e5212d77235bc907427691938 (diff)
Allow construction with only QCoreApplication (not QApplication)
Lazily create QWidget, QPixmap, QFont... dependend stuff
-rw-r--r--src/plugins/render/annotate/AnnotatePlugin.cpp97
-rw-r--r--src/plugins/render/measure/MeasureToolPlugin.cpp11
-rw-r--r--src/plugins/render/measure/MeasureToolPlugin.h4
-rw-r--r--src/plugins/render/progress/ProgressFloatItem.cpp24
-rw-r--r--src/plugins/render/satellites/SatellitesPlugin.cpp12
5 files changed, 85 insertions, 63 deletions
diff --git a/src/plugins/render/annotate/AnnotatePlugin.cpp b/src/plugins/render/annotate/AnnotatePlugin.cpp
index fbe8f10..3adec01 100644
--- a/src/plugins/render/annotate/AnnotatePlugin.cpp
+++ b/src/plugins/render/annotate/AnnotatePlugin.cpp
@@ -62,12 +62,12 @@ AnnotatePlugin::AnnotatePlugin( const MarbleModel *model )
m_isInitialized( false ),
m_widgetInitialized( false ),
m_marbleWidget( 0 ),
- m_overlayRmbMenu( new QMenu( m_marbleWidget ) ),
- m_polygonRmbMenu( new QMenu( m_marbleWidget ) ),
- m_nodeRmbMenu( new QMenu( m_marbleWidget ) ),
- m_textAnnotationRmbMenu( new QMenu( m_marbleWidget ) ),
- m_polylineRmbMenu( new QMenu( m_marbleWidget ) ),
- m_annotationDocument( new GeoDataDocument ),
+ m_overlayRmbMenu(nullptr),
+ m_polygonRmbMenu(nullptr),
+ m_nodeRmbMenu(nullptr),
+ m_textAnnotationRmbMenu(nullptr),
+ m_polylineRmbMenu(nullptr),
+ m_annotationDocument(nullptr),
m_movedItem( 0 ),
m_focusItem( 0 ),
m_polylinePlacemark( 0 ),
@@ -81,40 +81,6 @@ AnnotatePlugin::AnnotatePlugin( const MarbleModel *model )
setEnabled( true );
setVisible( true );
connect( this, SIGNAL(visibilityChanged(bool,QString)), SLOT(enableModel(bool)) );
-
- m_annotationDocument->setName( tr("Annotations") );
- m_annotationDocument->setDocumentRole( UserDocument );
-
- // Default polygon style
- GeoDataStyle::Ptr defaultPolygonStyle(new GeoDataStyle);
- GeoDataPolyStyle polyStyle;
- GeoDataLineStyle edgeStyle;
- GeoDataLabelStyle labelStyle;
- QColor polygonColor = QApplication::palette().highlight().color();
- QColor edgeColor = QApplication::palette().light().color();
- QColor labelColor = QApplication::palette().brightText().color();
- polygonColor.setAlpha( 80 );
- polyStyle.setColor( polygonColor );
- edgeStyle.setColor( edgeColor );
- labelStyle.setColor( labelColor );
- defaultPolygonStyle->setId(QStringLiteral("polygon"));
- defaultPolygonStyle->setPolyStyle( polyStyle );
- defaultPolygonStyle->setLineStyle( edgeStyle );
- defaultPolygonStyle->setLabelStyle( labelStyle );
- m_annotationDocument->addStyle( defaultPolygonStyle );
-
-
- // Default polyline style
- GeoDataStyle::Ptr defaultPolylineStyle(new GeoDataStyle);
- GeoDataLineStyle lineStyle;
- QColor polylineColor = Qt::white;
- lineStyle.setColor( polylineColor );
- lineStyle.setWidth( 1 );
- defaultPolylineStyle->setId(QStringLiteral("polyline"));
- defaultPolylineStyle->setLineStyle( lineStyle );
- defaultPolylineStyle->setLabelStyle( labelStyle );
- m_annotationDocument->addStyle( defaultPolylineStyle );
-
}
AnnotatePlugin::~AnnotatePlugin()
@@ -211,6 +177,42 @@ void AnnotatePlugin::initialize()
m_drawingPolyline = false;
m_addingPlacemark = false;
+ delete m_annotationDocument;
+ m_annotationDocument = new GeoDataDocument;
+
+ m_annotationDocument->setName( tr("Annotations") );
+ m_annotationDocument->setDocumentRole( UserDocument );
+
+ // Default polygon style
+ GeoDataStyle::Ptr defaultPolygonStyle(new GeoDataStyle);
+ GeoDataPolyStyle polyStyle;
+ GeoDataLineStyle edgeStyle;
+ GeoDataLabelStyle labelStyle;
+ QColor polygonColor = QApplication::palette().highlight().color();
+ QColor edgeColor = QApplication::palette().light().color();
+ QColor labelColor = QApplication::palette().brightText().color();
+ polygonColor.setAlpha( 80 );
+ polyStyle.setColor( polygonColor );
+ edgeStyle.setColor( edgeColor );
+ labelStyle.setColor( labelColor );
+ defaultPolygonStyle->setId(QStringLiteral("polygon"));
+ defaultPolygonStyle->setPolyStyle( polyStyle );
+ defaultPolygonStyle->setLineStyle( edgeStyle );
+ defaultPolygonStyle->setLabelStyle( labelStyle );
+ m_annotationDocument->addStyle( defaultPolygonStyle );
+
+
+ // Default polyline style
+ GeoDataStyle::Ptr defaultPolylineStyle(new GeoDataStyle);
+ GeoDataLineStyle lineStyle;
+ QColor polylineColor = Qt::white;
+ lineStyle.setColor( polylineColor );
+ lineStyle.setWidth( 1 );
+ defaultPolylineStyle->setId(QStringLiteral("polyline"));
+ defaultPolylineStyle->setLineStyle( lineStyle );
+ defaultPolylineStyle->setLabelStyle( labelStyle );
+ m_annotationDocument->addStyle( defaultPolylineStyle );
+
m_isInitialized = true;
}
}
@@ -1031,6 +1033,9 @@ void AnnotatePlugin::addContextItems()
void AnnotatePlugin::setupTextAnnotationRmbMenu()
{
+ delete m_textAnnotationRmbMenu;
+ m_textAnnotationRmbMenu = new QMenu;
+
QAction *cutItem = new QAction( tr( "Cut"), m_textAnnotationRmbMenu );
m_textAnnotationRmbMenu->addAction( cutItem );
connect( cutItem, SIGNAL(triggered()), this, SLOT(cutItem()) );
@@ -1152,6 +1157,9 @@ void AnnotatePlugin::setupGroundOverlayModel()
void AnnotatePlugin::setupOverlayRmbMenu()
{
+ delete m_overlayRmbMenu;
+ m_overlayRmbMenu = new QMenu;
+
QAction *editOverlay = new QAction( tr( "Properties" ), m_overlayRmbMenu );
m_overlayRmbMenu->addAction( editOverlay );
connect( editOverlay, SIGNAL(triggered()), this, SLOT(editOverlay()) );
@@ -1274,6 +1282,9 @@ void AnnotatePlugin::clearOverlayFrames()
void AnnotatePlugin::setupPolygonRmbMenu()
{
+ delete m_polygonRmbMenu;
+ m_polygonRmbMenu = new QMenu;
+
QAction *deselectNodes = new QAction( tr( "Deselect All Nodes" ), m_polygonRmbMenu );
m_polygonRmbMenu->addAction( deselectNodes );
connect( deselectNodes, SIGNAL(triggered()), this, SLOT(deselectNodes()) );
@@ -1453,6 +1464,9 @@ void AnnotatePlugin::editPolygon()
void AnnotatePlugin::setupNodeRmbMenu()
{
+ delete m_nodeRmbMenu;
+ m_nodeRmbMenu = new QMenu;
+
QAction *selectNode = new QAction( tr( "Select Node" ), m_nodeRmbMenu );
m_nodeRmbMenu->addAction( selectNode );
connect( selectNode, SIGNAL(triggered()), this, SLOT(selectNode()) );
@@ -1519,6 +1533,9 @@ void AnnotatePlugin::deleteNode()
void AnnotatePlugin::setupPolylineRmbMenu()
{
+ delete m_polylineRmbMenu;
+ m_polylineRmbMenu = new QMenu;
+
QAction *deselectNodes = new QAction( tr( "Deselect All Nodes" ), m_polylineRmbMenu );
m_polylineRmbMenu->addAction( deselectNodes );
connect( deselectNodes, SIGNAL(triggered()), this, SLOT(deselectNodes()) );
diff --git a/src/plugins/render/measure/MeasureToolPlugin.cpp b/src/plugins/render/measure/MeasureToolPlugin.cpp
index 69b23b8..64e09e2 100644
--- a/src/plugins/render/measure/MeasureToolPlugin.cpp
+++ b/src/plugins/render/measure/MeasureToolPlugin.cpp
@@ -36,13 +36,12 @@ namespace Marble
MeasureToolPlugin::MeasureToolPlugin( const MarbleModel *marbleModel )
: RenderPlugin( marbleModel ),
m_measureLineString( GeoDataLineString( Tessellate ) ),
- m_mark(QStringLiteral(":/mark.png")),
#ifdef Q_OS_MACX
m_font_regular( QFont( QStringLiteral( "Sans Serif" ), 10, 50, false ) ),
#else
m_font_regular( QFont( QStringLiteral( "Sans Serif" ), 8, 50, false ) ),
#endif
- m_fontascent( QFontMetrics( m_font_regular ).ascent() ),
+ m_fontascent(-1),
m_pen( Qt::red ),
m_addMeasurePointAction( 0 ),
m_removeLastMeasurePointAction( 0 ),
@@ -134,11 +133,12 @@ QIcon MeasureToolPlugin::icon () const
void MeasureToolPlugin::initialize ()
{
+ m_fontascent = QFontMetrics( m_font_regular ).ascent();
}
bool MeasureToolPlugin::isInitialized () const
{
- return true;
+ return m_fontascent >= 0;
}
QDialog *MeasureToolPlugin::configDialog()
@@ -537,11 +537,14 @@ QString MeasureToolPlugin::meterToPreferredUnit(qreal meters, bool isSquare) con
.arg(unitString);
}
-void MeasureToolPlugin::drawMeasurePoints( GeoPainter *painter ) const
+void MeasureToolPlugin::drawMeasurePoints( GeoPainter *painter )
{
// Paint the marks.
GeoDataLineString::const_iterator itpoint = m_measureLineString.constBegin();
GeoDataLineString::const_iterator const endpoint = m_measureLineString.constEnd();
+ if (m_mark.isNull()) {
+ m_mark = QPixmap(QStringLiteral(":/mark.png"));
+ }
for (; itpoint != endpoint; ++itpoint )
{
painter->drawPixmap( *itpoint, m_mark );
diff --git a/src/plugins/render/measure/MeasureToolPlugin.h b/src/plugins/render/measure/MeasureToolPlugin.h
index dd42f46..984a2b5 100644
--- a/src/plugins/render/measure/MeasureToolPlugin.h
+++ b/src/plugins/render/measure/MeasureToolPlugin.h
@@ -82,7 +82,7 @@ class MeasureToolPlugin : public RenderPlugin, public DialogConfigurationInterfa
bool eventFilter( QObject *object, QEvent *event );
private:
- void drawMeasurePoints( GeoPainter *painter ) const;
+ void drawMeasurePoints( GeoPainter *painter );
void drawInfobox( GeoPainter *painter ) const;
void drawSegments( GeoPainter *painter );
void addContextItems();
@@ -107,7 +107,7 @@ class MeasureToolPlugin : public RenderPlugin, public DialogConfigurationInterfa
GeoDataLineString m_measureLineString;
GeoDataLatLonAltBox m_latLonAltBox;
- const QPixmap m_mark;
+ QPixmap m_mark;
QFont m_font_regular;
int m_fontascent;
diff --git a/src/plugins/render/progress/ProgressFloatItem.cpp b/src/plugins/render/progress/ProgressFloatItem.cpp
index e960e1e..a465857 100644
--- a/src/plugins/render/progress/ProgressFloatItem.cpp
+++ b/src/plugins/render/progress/ProgressFloatItem.cpp
@@ -53,18 +53,6 @@ ProgressFloatItem::ProgressFloatItem( const MarbleModel *marbleModel )
m_repaintTimer.setInterval( 1000 );
connect( &m_repaintTimer, SIGNAL(timeout()), this, SIGNAL(repaintNeeded()) );
- // The icon resembles the pie chart
- QImage canvas( 16, 16, QImage::Format_ARGB32 );
- canvas.fill( Qt::transparent );
- QPainter painter( &canvas );
- painter.setRenderHint( QPainter::Antialiasing, true );
- painter.setPen( QColor ( Qt::black ) );
- painter.drawEllipse( 1, 1, 14, 14 );
- painter.setPen( Qt::NoPen );
- painter.setBrush( QBrush( QColor( Qt::darkGray ) ) );
- painter.drawPie( 2, 2, 12, 12, 1440, -1325 ); // 23 percent of a full circle
- m_icon = QIcon( QPixmap::fromImage( canvas ) );
-
// Plugin is enabled by default
setEnabled( true );
@@ -141,6 +129,18 @@ void ProgressFloatItem::initialize()
}
m_fontSize = fontSize - 1;
+ // The icon resembles the pie chart
+ QImage canvas( 16, 16, QImage::Format_ARGB32 );
+ canvas.fill( Qt::transparent );
+ QPainter painter( &canvas );
+ painter.setRenderHint( QPainter::Antialiasing, true );
+ painter.setPen( QColor ( Qt::black ) );
+ painter.drawEllipse( 1, 1, 14, 14 );
+ painter.setPen( Qt::NoPen );
+ painter.setBrush( QBrush( QColor( Qt::darkGray ) ) );
+ painter.drawPie( 2, 2, 12, 12, 1440, -1325 ); // 23 percent of a full circle
+ m_icon = QIcon( QPixmap::fromImage( canvas ) );
+
m_isInitialized = true;
}
diff --git a/src/plugins/render/satellites/SatellitesPlugin.cpp b/src/plugins/render/satellites/SatellitesPlugin.cpp
index d9ad3fe..06323dc 100644
--- a/src/plugins/render/satellites/SatellitesPlugin.cpp
+++ b/src/plugins/render/satellites/SatellitesPlugin.cpp
@@ -35,16 +35,12 @@ SatellitesPlugin::SatellitesPlugin( const MarbleModel *marbleModel )
: RenderPlugin( marbleModel ),
m_satModel( 0 ),
m_isInitialized( false ),
- m_configDialog( new SatellitesConfigDialog() )
+ m_configDialog(nullptr)
{
connect( this, SIGNAL(settingsChanged(QString)), SLOT(updateSettings()) );
connect( this, SIGNAL(enabledChanged(bool)), SLOT(enableModel(bool)) );
connect( this, SIGNAL(visibilityChanged(bool,QString)), SLOT(visibleModel(bool)) );
- connect( m_configDialog, SIGNAL(activatePluginClicked()), this, SLOT(activate()) );
- connect( this, SIGNAL(visibilityChanged(bool,QString)),
- m_configDialog, SLOT(setDialogActive(bool)) );
-
setVisible( false );
setSettings(QHash<QString, QVariant>());
@@ -152,6 +148,12 @@ void SatellitesPlugin::initialize()
marbleModel()->clock() );
m_configModel = new SatellitesConfigModel( this );
+
+ delete m_configDialog;
+ m_configDialog = new SatellitesConfigDialog();
+ connect( m_configDialog, SIGNAL(activatePluginClicked()), this, SLOT(activate()) );
+ connect( this, SIGNAL(visibilityChanged(bool,QString)),
+ m_configDialog, SLOT(setDialogActive(bool)) );
m_configDialog->configWidget()->treeView->setModel( m_configModel );
connect( m_satModel, SIGNAL(fileParsed(QString)),