Skip to content
Permalink
Browse files

[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
  • Loading branch information
nyalldawson committed Jun 30, 2017
1 parent 33c63d5 commit cd979d8ab089fd1c821a15a5f1c507eb8363a1be
@@ -153,6 +153,11 @@
%Include composer/qgscomposermultiframecommand.sip
%Include composer/qgscomposertexttable.sip
%Include composer/qgspaperitem.sip
%Include layout/qgslayoutmeasurement.sip
%Include layout/qgslayoutmeasurementconverter.sip
%Include layout/qgspagesizeregistry.sip
%Include layout/qgslayoutpoint.sip
%Include layout/qgslayoutsize.sip
%Include metadata/qgslayermetadata.sip
%Include metadata/qgslayermetadatavalidator.sip
%Include processing/qgsprocessingalgorithm.sip
@@ -378,7 +383,3 @@
%Include layertree/qgslayertreeregistrybridge.sip
%Include symbology-ng/qgsarrowsymbollayer.sip
%Include composer/qgscomposerutils.sip
%Include layout/qgslayoutmeasurement.sip
%Include layout/qgslayoutmeasurementconverter.sip
%Include layout/qgslayoutpoint.sip
%Include layout/qgslayoutsize.sip
@@ -0,0 +1,109 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgspagesizeregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsPageSize
{
%Docstring
A named page size for layouts.
.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgspagesizeregistry.h"
%End
public:

QgsPageSize();

QgsPageSize( const QString &name, const QgsLayoutSize &size );
%Docstring
Constructor for QgsPageSize, accepting the ``name`` of the page size and
page ``size``.
%End

QgsPageSize( const QgsLayoutSize &size );
%Docstring
Constructor for QgsPageSize, accepting a page ``size``.
%End

QString name;
%Docstring
Name of page size
%End

QgsLayoutSize size;
%Docstring
Page size
%End

bool operator==( const QgsPageSize &other ) const;
bool operator!=( const QgsPageSize &other ) const;
%Docstring
:rtype: bool
%End
};

class QgsPageSizeRegistry
{
%Docstring
A registry for known page sizes.

QgsPageSizeRegistry is not usually directly created, but rather accessed through
QgsApplication.pageSizeRegistry().

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgspagesizeregistry.h"
%End
public:

QgsPageSizeRegistry();
%Docstring
Creates a registry and populates it with known sizes
%End

void add( const QgsPageSize &size );
%Docstring
Adds a page ``size`` to the registry.
%End

QList< QgsPageSize > entries() const;
%Docstring
Returns a list of page sizes in the registry.
:rtype: list of QgsPageSize
%End

QList< QgsPageSize > find( const QString &name ) const;
%Docstring
Finds matching page sizes from the registry, using a case insensitive match
on the page size ``name``.
:rtype: list of QgsPageSize
%End

bool decodePageSize( const QString &string, QgsPageSize &size );
%Docstring
Decodes a ``string`` representing a preset page size.
The decoded page size will be stored in the ``size`` argument.
:return: true if string was successfully decoded
:rtype: bool
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgspagesizeregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -675,6 +675,13 @@ Returns path to the build output directory. Valid only when running from build d
:rtype: QgsProcessingRegistry
%End

static QgsPageSizeRegistry *pageSizeRegistry();
%Docstring
Returns the application's page size registry, used for managing layout page sizes.
.. versionadded:: 3.0
:rtype: QgsPageSizeRegistry
%End


static QgsActionScopeRegistry *actionScopeRegistry();
%Docstring
@@ -345,6 +345,7 @@ SET(QGIS_CORE_SRCS

layout/qgslayoutmeasurement.cpp
layout/qgslayoutmeasurementconverter.cpp
layout/qgspagesizeregistry.cpp
layout/qgslayoutpoint.cpp
layout/qgslayoutsize.cpp

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

layout/qgslayoutmeasurement.h
layout/qgslayoutmeasurementconverter.h
layout/qgspagesizeregistry.h
layout/qgslayoutpoint.h
layout/qgslayoutsize.h

metadata/qgslayermetadata.h
metadata/qgslayermetadatavalidator.h

@@ -1050,6 +1057,7 @@ INCLUDE_DIRECTORIES(
fieldformatter
geometry
layertree
layout
metadata
pal
processing
@@ -0,0 +1,126 @@
/***************************************************************************
qgspagesizeregistry.cpp
------------------------
begin : June 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgspagesizeregistry.h"

//
// QgsPageSizeRegistry
//

QgsPageSizeRegistry::QgsPageSizeRegistry()
{
add( QgsPageSize( QStringLiteral( "A6" ), QgsLayoutSize( 105, 148 ) ) );
add( QgsPageSize( QStringLiteral( "A5" ), QgsLayoutSize( 148, 210 ) ) );
add( QgsPageSize( QStringLiteral( "A4" ), QgsLayoutSize( 210, 297 ) ) );
add( QgsPageSize( QStringLiteral( "A3" ), QgsLayoutSize( 297, 420 ) ) );
add( QgsPageSize( QStringLiteral( "A2" ), QgsLayoutSize( 420, 594 ) ) );
add( QgsPageSize( QStringLiteral( "A1" ), QgsLayoutSize( 594, 841 ) ) );
add( QgsPageSize( QStringLiteral( "A0" ), QgsLayoutSize( 841, 1189 ) ) );
add( QgsPageSize( QStringLiteral( "B6" ), QgsLayoutSize( 125, 176 ) ) );
add( QgsPageSize( QStringLiteral( "B5" ), QgsLayoutSize( 176, 250 ) ) );
add( QgsPageSize( QStringLiteral( "B4" ), QgsLayoutSize( 250, 353 ) ) );
add( QgsPageSize( QStringLiteral( "B3" ), QgsLayoutSize( 353, 500 ) ) );
add( QgsPageSize( QStringLiteral( "B2" ), QgsLayoutSize( 500, 707 ) ) );
add( QgsPageSize( QStringLiteral( "B1" ), QgsLayoutSize( 707, 1000 ) ) );
add( QgsPageSize( QStringLiteral( "B0" ), QgsLayoutSize( 1000, 1414 ) ) );
add( QgsPageSize( QStringLiteral( "Legal" ), QgsLayoutSize( 215.9, 355.6 ) ) );
add( QgsPageSize( QStringLiteral( "Letter" ), QgsLayoutSize( 215.9, 279.4 ) ) );
add( QgsPageSize( QStringLiteral( "ANSI A" ), QgsLayoutSize( 215.9, 279.4 ) ) );
add( QgsPageSize( QStringLiteral( "ANSI B" ), QgsLayoutSize( 279.4, 431.8 ) ) );
add( QgsPageSize( QStringLiteral( "ANSI C" ), QgsLayoutSize( 431.8, 558.8 ) ) );
add( QgsPageSize( QStringLiteral( "ANSI D" ), QgsLayoutSize( 558.8, 863.6 ) ) );
add( QgsPageSize( QStringLiteral( "ANSI E" ), QgsLayoutSize( 863.6, 1117.6 ) ) );
add( QgsPageSize( QStringLiteral( "Arch A" ), QgsLayoutSize( 228.6, 304.8 ) ) );
add( QgsPageSize( QStringLiteral( "Arch B" ), QgsLayoutSize( 304.8, 457.2 ) ) );
add( QgsPageSize( QStringLiteral( "Arch C" ), QgsLayoutSize( 457.2, 609.6 ) ) );
add( QgsPageSize( QStringLiteral( "Arch D" ), QgsLayoutSize( 609.6, 914.4 ) ) );
add( QgsPageSize( QStringLiteral( "Arch E" ), QgsLayoutSize( 914.4, 1219.2 ) ) );
add( QgsPageSize( QStringLiteral( "Arch E1" ), QgsLayoutSize( 762, 1066.8 ) ) );
add( QgsPageSize( QStringLiteral( "Arch E2" ), QgsLayoutSize( 660, 965 ) ) );
add( QgsPageSize( QStringLiteral( "Arch E3" ), QgsLayoutSize( 686, 991 ) ) );
}

void QgsPageSizeRegistry::add( const QgsPageSize &size )
{
mPageSizes.append( size );
}

QList<QgsPageSize> QgsPageSizeRegistry::entries() const
{
QList< QgsPageSize > result;
QList< QgsPageSize >::const_iterator it = mPageSizes.constBegin();
for ( ; it != mPageSizes.constEnd(); ++it )
{
result.push_back( *it );
}
return result;
}

QList<QgsPageSize> QgsPageSizeRegistry::find( const QString &name ) const
{
QList< QgsPageSize > result;
QList< QgsPageSize >::const_iterator it = mPageSizes.constBegin();
for ( ; it != mPageSizes.constEnd(); ++it )
{
if ( ( *it ).name.compare( name, Qt::CaseInsensitive ) == 0 )
{
result.push_back( *it );
}
}
return result;
}

bool QgsPageSizeRegistry::decodePageSize( const QString &pageSizeName, QgsPageSize &pageSize )
{
QList< QgsPageSize > matches = find( pageSizeName.trimmed() );
if ( matches.length() > 0 )
{
pageSize = matches.at( 0 );
return true;
}
return false;
}

//
// QgsPageSize
//

QgsPageSize::QgsPageSize()
: size( QgsLayoutSize( 0.0, 0.0 ) )
{
}

QgsPageSize::QgsPageSize( const QString &pageName, const QgsLayoutSize &pageSize )
: name( pageName )
, size( pageSize )
{
}

QgsPageSize::QgsPageSize( const QgsLayoutSize &pageSize )
: size( pageSize )
{

}

bool QgsPageSize::operator==( const QgsPageSize &other ) const
{
return ( name == other.name && size == other.size );
}

bool QgsPageSize::operator!=( const QgsPageSize &other ) const
{
return ( ! operator==( other ) );
}

0 comments on commit cd979d8

Please sign in to comment.
You can’t perform that action at this time.