Skip to content

Commit cd979d8

Browse files
committedJun 30, 2017
[layout] Create a page size registry for layout
Adds a new QgsPageSize class and QgsPageSizeRegistry registry (attached to QgsApplication), which stores and manages known page sizes
1 parent 33c63d5 commit cd979d8

File tree

10 files changed

+523
-4
lines changed

10 files changed

+523
-4
lines changed
 

‎python/core/core_auto.sip

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@
153153
%Include composer/qgscomposermultiframecommand.sip
154154
%Include composer/qgscomposertexttable.sip
155155
%Include composer/qgspaperitem.sip
156+
%Include layout/qgslayoutmeasurement.sip
157+
%Include layout/qgslayoutmeasurementconverter.sip
158+
%Include layout/qgspagesizeregistry.sip
159+
%Include layout/qgslayoutpoint.sip
160+
%Include layout/qgslayoutsize.sip
156161
%Include metadata/qgslayermetadata.sip
157162
%Include metadata/qgslayermetadatavalidator.sip
158163
%Include processing/qgsprocessingalgorithm.sip
@@ -378,7 +383,3 @@
378383
%Include layertree/qgslayertreeregistrybridge.sip
379384
%Include symbology-ng/qgsarrowsymbollayer.sip
380385
%Include composer/qgscomposerutils.sip
381-
%Include layout/qgslayoutmeasurement.sip
382-
%Include layout/qgslayoutmeasurementconverter.sip
383-
%Include layout/qgslayoutpoint.sip
384-
%Include layout/qgslayoutsize.sip
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgspagesizeregistry.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsPageSize
13+
{
14+
%Docstring
15+
A named page size for layouts.
16+
.. versionadded:: 3.0
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgspagesizeregistry.h"
21+
%End
22+
public:
23+
24+
QgsPageSize();
25+
26+
QgsPageSize( const QString &name, const QgsLayoutSize &size );
27+
%Docstring
28+
Constructor for QgsPageSize, accepting the ``name`` of the page size and
29+
page ``size``.
30+
%End
31+
32+
QgsPageSize( const QgsLayoutSize &size );
33+
%Docstring
34+
Constructor for QgsPageSize, accepting a page ``size``.
35+
%End
36+
37+
QString name;
38+
%Docstring
39+
Name of page size
40+
%End
41+
42+
QgsLayoutSize size;
43+
%Docstring
44+
Page size
45+
%End
46+
47+
bool operator==( const QgsPageSize &other ) const;
48+
bool operator!=( const QgsPageSize &other ) const;
49+
%Docstring
50+
:rtype: bool
51+
%End
52+
};
53+
54+
class QgsPageSizeRegistry
55+
{
56+
%Docstring
57+
A registry for known page sizes.
58+
59+
QgsPageSizeRegistry is not usually directly created, but rather accessed through
60+
QgsApplication.pageSizeRegistry().
61+
62+
.. versionadded:: 3.0
63+
%End
64+
65+
%TypeHeaderCode
66+
#include "qgspagesizeregistry.h"
67+
%End
68+
public:
69+
70+
QgsPageSizeRegistry();
71+
%Docstring
72+
Creates a registry and populates it with known sizes
73+
%End
74+
75+
void add( const QgsPageSize &size );
76+
%Docstring
77+
Adds a page ``size`` to the registry.
78+
%End
79+
80+
QList< QgsPageSize > entries() const;
81+
%Docstring
82+
Returns a list of page sizes in the registry.
83+
:rtype: list of QgsPageSize
84+
%End
85+
86+
QList< QgsPageSize > find( const QString &name ) const;
87+
%Docstring
88+
Finds matching page sizes from the registry, using a case insensitive match
89+
on the page size ``name``.
90+
:rtype: list of QgsPageSize
91+
%End
92+
93+
bool decodePageSize( const QString &string, QgsPageSize &size );
94+
%Docstring
95+
Decodes a ``string`` representing a preset page size.
96+
The decoded page size will be stored in the ``size`` argument.
97+
:return: true if string was successfully decoded
98+
:rtype: bool
99+
%End
100+
101+
};
102+
103+
/************************************************************************
104+
* This file has been generated automatically from *
105+
* *
106+
* src/core/layout/qgspagesizeregistry.h *
107+
* *
108+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
109+
************************************************************************/

‎python/core/qgsapplication.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,13 @@ Returns path to the build output directory. Valid only when running from build d
675675
:rtype: QgsProcessingRegistry
676676
%End
677677

678+
static QgsPageSizeRegistry *pageSizeRegistry();
679+
%Docstring
680+
Returns the application's page size registry, used for managing layout page sizes.
681+
.. versionadded:: 3.0
682+
:rtype: QgsPageSizeRegistry
683+
%End
684+
678685

679686
static QgsActionScopeRegistry *actionScopeRegistry();
680687
%Docstring

‎src/core/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ SET(QGIS_CORE_SRCS
345345

346346
layout/qgslayoutmeasurement.cpp
347347
layout/qgslayoutmeasurementconverter.cpp
348+
layout/qgspagesizeregistry.cpp
348349
layout/qgslayoutpoint.cpp
349350
layout/qgslayoutsize.cpp
350351

@@ -900,6 +901,12 @@ SET(QGIS_CORE_HDRS
900901
composer/qgscomposertexttable.h
901902
composer/qgspaperitem.h
902903

904+
layout/qgslayoutmeasurement.h
905+
layout/qgslayoutmeasurementconverter.h
906+
layout/qgspagesizeregistry.h
907+
layout/qgslayoutpoint.h
908+
layout/qgslayoutsize.h
909+
903910
metadata/qgslayermetadata.h
904911
metadata/qgslayermetadatavalidator.h
905912

@@ -1050,6 +1057,7 @@ INCLUDE_DIRECTORIES(
10501057
fieldformatter
10511058
geometry
10521059
layertree
1060+
layout
10531061
metadata
10541062
pal
10551063
processing
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/***************************************************************************
2+
qgspagesizeregistry.cpp
3+
------------------------
4+
begin : June 2017
5+
copyright : (C) 2017 by Nyall Dawson
6+
email : nyall dot dawson at gmail dot com
7+
***************************************************************************/
8+
/***************************************************************************
9+
* *
10+
* This program is free software; you can redistribute it and/or modify *
11+
* it under the terms of the GNU General Public License as published by *
12+
* the Free Software Foundation; either version 2 of the License, or *
13+
* (at your option) any later version. *
14+
* *
15+
***************************************************************************/
16+
17+
#include "qgspagesizeregistry.h"
18+
19+
//
20+
// QgsPageSizeRegistry
21+
//
22+
23+
QgsPageSizeRegistry::QgsPageSizeRegistry()
24+
{
25+
add( QgsPageSize( QStringLiteral( "A6" ), QgsLayoutSize( 105, 148 ) ) );
26+
add( QgsPageSize( QStringLiteral( "A5" ), QgsLayoutSize( 148, 210 ) ) );
27+
add( QgsPageSize( QStringLiteral( "A4" ), QgsLayoutSize( 210, 297 ) ) );
28+
add( QgsPageSize( QStringLiteral( "A3" ), QgsLayoutSize( 297, 420 ) ) );
29+
add( QgsPageSize( QStringLiteral( "A2" ), QgsLayoutSize( 420, 594 ) ) );
30+
add( QgsPageSize( QStringLiteral( "A1" ), QgsLayoutSize( 594, 841 ) ) );
31+
add( QgsPageSize( QStringLiteral( "A0" ), QgsLayoutSize( 841, 1189 ) ) );
32+
add( QgsPageSize( QStringLiteral( "B6" ), QgsLayoutSize( 125, 176 ) ) );
33+
add( QgsPageSize( QStringLiteral( "B5" ), QgsLayoutSize( 176, 250 ) ) );
34+
add( QgsPageSize( QStringLiteral( "B4" ), QgsLayoutSize( 250, 353 ) ) );
35+
add( QgsPageSize( QStringLiteral( "B3" ), QgsLayoutSize( 353, 500 ) ) );
36+
add( QgsPageSize( QStringLiteral( "B2" ), QgsLayoutSize( 500, 707 ) ) );
37+
add( QgsPageSize( QStringLiteral( "B1" ), QgsLayoutSize( 707, 1000 ) ) );
38+
add( QgsPageSize( QStringLiteral( "B0" ), QgsLayoutSize( 1000, 1414 ) ) );
39+
add( QgsPageSize( QStringLiteral( "Legal" ), QgsLayoutSize( 215.9, 355.6 ) ) );
40+
add( QgsPageSize( QStringLiteral( "Letter" ), QgsLayoutSize( 215.9, 279.4 ) ) );
41+
add( QgsPageSize( QStringLiteral( "ANSI A" ), QgsLayoutSize( 215.9, 279.4 ) ) );
42+
add( QgsPageSize( QStringLiteral( "ANSI B" ), QgsLayoutSize( 279.4, 431.8 ) ) );
43+
add( QgsPageSize( QStringLiteral( "ANSI C" ), QgsLayoutSize( 431.8, 558.8 ) ) );
44+
add( QgsPageSize( QStringLiteral( "ANSI D" ), QgsLayoutSize( 558.8, 863.6 ) ) );
45+
add( QgsPageSize( QStringLiteral( "ANSI E" ), QgsLayoutSize( 863.6, 1117.6 ) ) );
46+
add( QgsPageSize( QStringLiteral( "Arch A" ), QgsLayoutSize( 228.6, 304.8 ) ) );
47+
add( QgsPageSize( QStringLiteral( "Arch B" ), QgsLayoutSize( 304.8, 457.2 ) ) );
48+
add( QgsPageSize( QStringLiteral( "Arch C" ), QgsLayoutSize( 457.2, 609.6 ) ) );
49+
add( QgsPageSize( QStringLiteral( "Arch D" ), QgsLayoutSize( 609.6, 914.4 ) ) );
50+
add( QgsPageSize( QStringLiteral( "Arch E" ), QgsLayoutSize( 914.4, 1219.2 ) ) );
51+
add( QgsPageSize( QStringLiteral( "Arch E1" ), QgsLayoutSize( 762, 1066.8 ) ) );
52+
add( QgsPageSize( QStringLiteral( "Arch E2" ), QgsLayoutSize( 660, 965 ) ) );
53+
add( QgsPageSize( QStringLiteral( "Arch E3" ), QgsLayoutSize( 686, 991 ) ) );
54+
}
55+
56+
void QgsPageSizeRegistry::add( const QgsPageSize &size )
57+
{
58+
mPageSizes.append( size );
59+
}
60+
61+
QList<QgsPageSize> QgsPageSizeRegistry::entries() const
62+
{
63+
QList< QgsPageSize > result;
64+
QList< QgsPageSize >::const_iterator it = mPageSizes.constBegin();
65+
for ( ; it != mPageSizes.constEnd(); ++it )
66+
{
67+
result.push_back( *it );
68+
}
69+
return result;
70+
}
71+
72+
QList<QgsPageSize> QgsPageSizeRegistry::find( const QString &name ) const
73+
{
74+
QList< QgsPageSize > result;
75+
QList< QgsPageSize >::const_iterator it = mPageSizes.constBegin();
76+
for ( ; it != mPageSizes.constEnd(); ++it )
77+
{
78+
if ( ( *it ).name.compare( name, Qt::CaseInsensitive ) == 0 )
79+
{
80+
result.push_back( *it );
81+
}
82+
}
83+
return result;
84+
}
85+
86+
bool QgsPageSizeRegistry::decodePageSize( const QString &pageSizeName, QgsPageSize &pageSize )
87+
{
88+
QList< QgsPageSize > matches = find( pageSizeName.trimmed() );
89+
if ( matches.length() > 0 )
90+
{
91+
pageSize = matches.at( 0 );
92+
return true;
93+
}
94+
return false;
95+
}
96+
97+
//
98+
// QgsPageSize
99+
//
100+
101+
QgsPageSize::QgsPageSize()
102+
: size( QgsLayoutSize( 0.0, 0.0 ) )
103+
{
104+
}
105+
106+
QgsPageSize::QgsPageSize( const QString &pageName, const QgsLayoutSize &pageSize )
107+
: name( pageName )
108+
, size( pageSize )
109+
{
110+
}
111+
112+
QgsPageSize::QgsPageSize( const QgsLayoutSize &pageSize )
113+
: size( pageSize )
114+
{
115+
116+
}
117+
118+
bool QgsPageSize::operator==( const QgsPageSize &other ) const
119+
{
120+
return ( name == other.name && size == other.size );
121+
}
122+
123+
bool QgsPageSize::operator!=( const QgsPageSize &other ) const
124+
{
125+
return ( ! operator==( other ) );
126+
}

0 commit comments

Comments
 (0)