QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
qgsmargins.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmargins.cpp
3  --------------
4  Date : January 2017
5  Copyright : (C) 2017 by 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 "qgsmargins.h"
17 
18 QString QgsMargins::toString() const
19 {
20  if ( isNull() )
21  return QString();
22  else
23  return QStringLiteral( "%1,%2,%3,%4" ).arg( qgsDoubleToString( mLeft ), qgsDoubleToString( mTop ),
24  qgsDoubleToString( mRight ), qgsDoubleToString( mBottom ) );
25 }
26 
27 QgsMargins QgsMargins::fromString( const QString &string )
28 {
29  QStringList margins = string.split( ',' );
30  if ( margins.count() != 4 )
31  return QgsMargins();
32 
33  return QgsMargins( margins.at( 0 ).toDouble(),
34  margins.at( 1 ).toDouble(),
35  margins.at( 2 ).toDouble(),
36  margins.at( 3 ).toDouble() );
37 }
The QgsMargins class defines the four margins of a rectangle.
Definition: qgsmargins.h:38
QgsMargins()=default
Constructs a margins object with all margins set to 0.
static QgsMargins fromString(const QString &string)
Returns a QgsMargins object decoded from a string, or a null QgsMargins if the string could not be in...
Definition: qgsmargins.cpp:27
bool isNull() const
Returns true if all margins are is 0; otherwise returns false.
Definition: qgsmargins.h:63
QString toString() const
Returns the margins encoded to a string.
Definition: qgsmargins.cpp:18
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:276