Skip to content

Commit d3836e5

Browse files
committedNov 7, 2017
Move population of layout gui registry from GUI->app
Since we don't want all the item type subclass config widgets to have to reside in gui, we need to populate the registry from app instead.
1 parent edea38f commit d3836e5

14 files changed

+116
-48
lines changed
 

‎python/core/layout/qgslayoutitemmap.sip

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ class QgsLayoutItemMap : QgsLayoutItem
2929
virtual QString stringType() const;
3030

3131

32+
static QgsLayoutItemMap *create( QgsLayout *layout, const QVariantMap &settings ) /Factory/;
33+
%Docstring
34+
Returns a new map item for the specified ``layout``.
35+
36+
The caller takes responsibility for deleting the returned object.
37+
:rtype: QgsLayoutItemMap
38+
%End
39+
3240
protected:
3341

3442
virtual void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );

‎python/gui/layout/qgslayoutitemguiregistry.sip

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,6 @@ class QgsLayoutItemGuiRegistry : QObject
159159

160160
~QgsLayoutItemGuiRegistry();
161161

162-
bool populate();
163-
%Docstring
164-
Populates the registry with standard item types. If called on a non-empty registry
165-
then this will have no effect and will return false.
166-
:rtype: bool
167-
%End
168-
169162

170163
QgsLayoutItemAbstractGuiMetadata *itemMetadata( int type ) const;
171164
%Docstring

‎src/app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ SET(QGIS_APP_SRCS
174174
composer/qgsatlascompositionwidget.cpp
175175

176176
layout/qgslayoutaddpagesdialog.cpp
177+
layout/qgslayoutapputils.cpp
177178
layout/qgslayoutdesignerdialog.cpp
178179
layout/qgslayoutguidewidget.cpp
179180
layout/qgslayoutappmenuprovider.cpp

‎src/app/layout/qgslayoutapputils.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/***************************************************************************
2+
qgslayoutapputils.cpp
3+
---------------------
4+
Date : October 2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#include "qgslayoutapputils.h"
17+
#include "qgsgui.h"
18+
#include "qgslayoutitemguiregistry.h"
19+
#include "qgslayoutitemregistry.h"
20+
#include "qgslayoutviewrubberband.h"
21+
22+
void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
23+
{
24+
QgsLayoutItemGuiRegistry *registry = QgsGui::layoutItemGuiRegistry();
25+
26+
registry->addItemGroup( QgsLayoutItemGuiGroup( QStringLiteral( "shapes" ), QObject::tr( "Shape" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicShape.svg" ) ) ) );
27+
28+
auto createRubberBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
29+
{
30+
return new QgsLayoutViewRectangularRubberBand( view );
31+
} );
32+
auto createEllipseBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
33+
{
34+
return new QgsLayoutViewEllipticalRubberBand( view );
35+
} );
36+
auto createTriangleBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
37+
{
38+
return new QgsLayoutViewTriangleRubberBand( view );
39+
} );
40+
41+
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutItem + 1002, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), nullptr, createRubberBand ) );
42+
43+
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutMap, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ), nullptr, createRubberBand ) );
44+
45+
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutRectangle, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), nullptr, createRubberBand, QStringLiteral( "shapes" ) ) );
46+
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutEllipse, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicCircle.svg" ) ), nullptr, createEllipseBand, QStringLiteral( "shapes" ) ) );
47+
registry->addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutTriangle, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicTriangle.svg" ) ), nullptr, createTriangleBand, QStringLiteral( "shapes" ) ) );
48+
}

‎src/app/layout/qgslayoutapputils.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/***************************************************************************
2+
qgslayoutapputils.h
3+
-------------------
4+
Date : October 2017
5+
Copyright : (C) 2017 Nyall Dawson
6+
Email : nyall dot dawson at gmail dot com
7+
***************************************************************************
8+
* *
9+
* This program is free software; you can redistribute it and/or modify *
10+
* it under the terms of the GNU General Public License as published by *
11+
* the Free Software Foundation; either version 2 of the License, or *
12+
* (at your option) any later version. *
13+
* *
14+
***************************************************************************/
15+
16+
#ifndef QGSLAYOUTAPPUTILS_H
17+
#define QGSLAYOUTAPPUTILS_H
18+
19+
#include "qgis.h"
20+
21+
/**
22+
* Utils for layout handling from app.
23+
*/
24+
class QgsLayoutAppUtils
25+
{
26+
27+
public:
28+
29+
/**
30+
* Registers the GUI handlers for known layout item types.
31+
*/
32+
static void registerGuiForKnownItemTypes();
33+
34+
};
35+
36+
#endif // QGSLAYOUTAPPUTILS_H

‎src/app/qgisapp.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ Q_GUI_EXPORT extern int qt_defaultDpiX();
206206
#include "qgslayertreeviewdefaultactions.h"
207207
#include "qgslayoutdesignerdialog.h"
208208
#include "qgslayoutmanager.h"
209+
#include "qgslayoutapputils.h"
209210
#include "qgslocatorwidget.h"
210211
#include "qgslocator.h"
211212
#include "qgsinbuiltlocatorfilters.h"
@@ -835,6 +836,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
835836
functionProfile( &QgisApp::legendLayerSelectionChanged, this, QStringLiteral( "Legend layer selection changed" ) );
836837
functionProfile( &QgisApp::init3D, this, QStringLiteral( "Initialize 3D support" ) );
837838
functionProfile( &QgisApp::initNativeProcessing, this, QStringLiteral( "Initialize native processing" ) );
839+
functionProfile( &QgisApp::initLayouts, this, QStringLiteral( "Initialize layouts support" ) );
838840

839841
QgsApplication::annotationRegistry()->addAnnotationType( QgsAnnotationMetadata( QStringLiteral( "FormAnnotationItem" ), &QgsFormAnnotation::create ) );
840842
connect( QgsProject::instance()->annotationManager(), &QgsAnnotationManager::annotationAdded, this, &QgisApp::annotationCreated );
@@ -10149,6 +10151,11 @@ void QgisApp::initNativeProcessing()
1014910151
QgsApplication::processingRegistry()->addProvider( new QgsNativeAlgorithms( QgsApplication::processingRegistry() ) );
1015010152
}
1015110153

10154+
void QgisApp::initLayouts()
10155+
{
10156+
QgsLayoutAppUtils::registerGuiForKnownItemTypes();
10157+
}
10158+
1015210159
void QgisApp::new3DMapCanvas()
1015310160
{
1015410161
#ifdef HAVE_3D

‎src/app/qgisapp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
17521752
void createDecorations();
17531753
void init3D();
17541754
void initNativeProcessing();
1755+
void initLayouts();
17551756

17561757
//! Creates a new 3D map dock without initializing its position or contents
17571758
Qgs3DMapCanvasDockWidget *createNew3DMapCanvasDock( const QString &name );

‎src/core/layout/qgslayoutitemmap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ QString QgsLayoutItemMap::stringType() const
3434
return QStringLiteral( "ItemMap" );
3535
}
3636

37+
QgsLayoutItemMap *QgsLayoutItemMap::create( QgsLayout *layout, const QVariantMap & )
38+
{
39+
return new QgsLayoutItemMap( layout );
40+
}
41+
3742
void QgsLayoutItemMap::draw( QgsRenderContext &, const QStyleOptionGraphicsItem * )
3843
{
3944

‎src/core/layout/qgslayoutitemmap.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class CORE_EXPORT QgsLayoutItemMap : public QgsLayoutItem
4141
int type() const override;
4242
QString stringType() const override;
4343

44+
/**
45+
* Returns a new map item for the specified \a layout.
46+
*
47+
* The caller takes responsibility for deleting the returned object.
48+
*/
49+
static QgsLayoutItemMap *create( QgsLayout *layout, const QVariantMap &settings ) SIP_FACTORY;
50+
4451
protected:
4552

4653
void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = nullptr ) override;

‎src/core/layout/qgslayoutitemregistry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "qgslayoutitemregistry.h"
1818
#include "qgslayoutitemshape.h"
19+
#include "qgslayoutitemmap.h"
1920
#include "qgslayoutitempage.h"
2021
#include "qgslayoutitemgroup.h"
2122
#include "qgsgloweffect.h"
@@ -48,6 +49,8 @@ bool QgsLayoutItemRegistry::populate()
4849

4950
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPage, QStringLiteral( "Page" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ), QgsLayoutItemPage::create ) );
5051

52+
addLayoutItemType( new QgsLayoutItemMetadata( LayoutMap, QStringLiteral( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ), QgsLayoutItemMap::create ) );
53+
5154
addLayoutItemType( new QgsLayoutItemMetadata( LayoutRectangle, QStringLiteral( "Rectangle" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), QgsLayoutItemRectangularShape::create ) );
5255
addLayoutItemType( new QgsLayoutItemMetadata( LayoutEllipse, QStringLiteral( "Ellipse" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicCircle.svg" ) ), QgsLayoutItemEllipseShape::create ) );
5356
addLayoutItemType( new QgsLayoutItemMetadata( LayoutTriangle, QStringLiteral( "Triangle" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicTriangle.svg" ) ), QgsLayoutItemTriangleShape::create ) );

‎src/gui/layout/qgslayoutitemguiregistry.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,6 @@ QgsLayoutItemGuiRegistry::~QgsLayoutItemGuiRegistry()
3636
qDeleteAll( mMetadata );
3737
}
3838

39-
bool QgsLayoutItemGuiRegistry::populate()
40-
{
41-
if ( !mMetadata.isEmpty() )
42-
return false;
43-
44-
addItemGroup( QgsLayoutItemGuiGroup( QStringLiteral( "shapes" ), tr( "Shape" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicShape.svg" ) ) ) );
45-
46-
auto createRubberBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
47-
{
48-
return new QgsLayoutViewRectangularRubberBand( view );
49-
} );
50-
auto createEllipseBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
51-
{
52-
return new QgsLayoutViewEllipticalRubberBand( view );
53-
} );
54-
auto createTriangleBand = ( []( QgsLayoutView * view )->QgsLayoutViewRubberBand *
55-
{
56-
return new QgsLayoutViewTriangleRubberBand( view );
57-
} );
58-
59-
addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutItem + 1002, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), nullptr, createRubberBand ) );
60-
addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutRectangle, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), nullptr, createRubberBand, QStringLiteral( "shapes" ) ) );
61-
addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutEllipse, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicCircle.svg" ) ), nullptr, createEllipseBand, QStringLiteral( "shapes" ) ) );
62-
addLayoutItemGuiMetadata( new QgsLayoutItemGuiMetadata( QgsLayoutItemRegistry::LayoutTriangle, QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicTriangle.svg" ) ), nullptr, createTriangleBand, QStringLiteral( "shapes" ) ) );
63-
return true;
64-
}
65-
6639
QgsLayoutItemAbstractGuiMetadata *QgsLayoutItemGuiRegistry::itemMetadata( int type ) const
6740
{
6841
return mMetadata.value( type );

‎src/gui/layout/qgslayoutitemguiregistry.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,6 @@ class GUI_EXPORT QgsLayoutItemGuiRegistry : public QObject
250250

251251
~QgsLayoutItemGuiRegistry();
252252

253-
/**
254-
* Populates the registry with standard item types. If called on a non-empty registry
255-
* then this will have no effect and will return false.
256-
*/
257-
bool populate();
258-
259253
//! QgsLayoutItemGuiRegistry cannot be copied.
260254
QgsLayoutItemGuiRegistry( const QgsLayoutItemGuiRegistry &rh ) = delete;
261255
//! QgsLayoutItemGuiRegistry cannot be copied.

‎src/gui/qgsgui.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,4 @@ QgsGui::QgsGui()
9696
mMapLayerActionRegistry = new QgsMapLayerActionRegistry();
9797
mSourceSelectProviderRegistry = new QgsSourceSelectProviderRegistry();
9898
mLayoutItemGuiRegistry = new QgsLayoutItemGuiRegistry();
99-
mLayoutItemGuiRegistry->populate();
10099
}

‎tests/src/gui/testqgslayoutview.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,6 @@ void TestQgsLayoutView::guiRegistry()
309309
QCOMPARE( registry.itemGroup( QStringLiteral( "g1" ) ).id, QStringLiteral( "g1" ) );
310310
// can't add duplicate group
311311
QVERIFY( !registry.addItemGroup( QgsLayoutItemGuiGroup( QStringLiteral( "g1" ) ) ) );
312-
313-
//test populate
314-
QgsLayoutItemGuiRegistry reg2;
315-
QVERIFY( reg2.itemTypes().isEmpty() );
316-
QVERIFY( reg2.populate() );
317-
QVERIFY( !reg2.itemTypes().isEmpty() );
318-
QVERIFY( !reg2.populate() );
319312
}
320313

321314
void TestQgsLayoutView::rubberBand()

0 commit comments

Comments
 (0)
Please sign in to comment.