QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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#include <QString>
19
20using namespace Qt::StringLiterals;
21
22QString QgsMargins::toString() const
23{
24 if ( isNull() )
25 return QString();
26 else
27 return u"%1,%2,%3,%4"_s.arg( qgsDoubleToString( mLeft ), qgsDoubleToString( mTop ),
28 qgsDoubleToString( mRight ), qgsDoubleToString( mBottom ) );
29}
30
31QgsMargins QgsMargins::fromString( const QString &string )
32{
33 const QStringList margins = string.split( ',' );
34 if ( margins.count() != 4 )
35 return QgsMargins();
36
37 return QgsMargins( margins.at( 0 ).toDouble(),
38 margins.at( 1 ).toDouble(),
39 margins.at( 2 ).toDouble(),
40 margins.at( 3 ).toDouble() );
41}
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...
bool isNull() const
Returns true if all margins are is 0; otherwise returns false.
Definition qgsmargins.h:65
QString toString() const
Returns the margins encoded to a string.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition qgis.h:6817