-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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
1 parent
33c63d5
commit cd979d8
Showing
10 changed files
with
523 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ) ); | ||
} |
Oops, something went wrong.