Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New class QgsMargins for storing margins (left/right/top/bottom)
Basically a direct port of QMarginF, but forced to always use double values, and with added toString()/fromString() methods.
- Loading branch information
1 parent
7a2be42
commit a7be996
Showing
7 changed files
with
534 additions
and
0 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,47 @@ | ||
class QgsMargins | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsmargins.h> | ||
%End | ||
|
||
public: | ||
|
||
QgsMargins(); | ||
QgsMargins( double left, double top, double right, double bottom ); | ||
|
||
bool isNull() const; | ||
|
||
double left() const; | ||
double top() const; | ||
double right() const; | ||
double bottom() const; | ||
|
||
void setLeft( double left ); | ||
void setTop( double top ); | ||
void setRight( double right ); | ||
void setBottom( double bottom ); | ||
|
||
QgsMargins &operator+=( const QgsMargins &margins ); | ||
QgsMargins &operator-=( const QgsMargins &margins ); | ||
QgsMargins &operator+=( double addend ); | ||
QgsMargins &operator-=( double subtrahend ); | ||
QgsMargins &operator*=( double factor ); | ||
QgsMargins &operator/=( double divisor ); | ||
|
||
QString toString() const; | ||
static QgsMargins fromString( const QString& string ); | ||
}; | ||
|
||
bool operator==( const QgsMargins &lhs, const QgsMargins &rhs ); | ||
bool operator!=( const QgsMargins &lhs, const QgsMargins &rhs ); | ||
QgsMargins operator+( const QgsMargins &m1, const QgsMargins &m2 ); | ||
QgsMargins operator-( const QgsMargins &m1, const QgsMargins &m2 ); | ||
QgsMargins operator+( const QgsMargins &lhs, double rhs ); | ||
QgsMargins operator+( double lhs, const QgsMargins &rhs ); | ||
QgsMargins operator-( const QgsMargins &lhs, double rhs ); | ||
QgsMargins operator*( const QgsMargins &margins, double factor ); | ||
QgsMargins operator*( double factor, const QgsMargins &margins ); | ||
QgsMargins operator/( const QgsMargins &margins, double divisor ); | ||
QgsMargins operator+( const QgsMargins &margins ); | ||
QgsMargins operator-( const QgsMargins &margins ); | ||
|
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,37 @@ | ||
/*************************************************************************** | ||
qgsmargins.cpp | ||
-------------- | ||
Date : January 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 "qgsmargins.h" | ||
|
||
QString QgsMargins::toString() const | ||
{ | ||
if ( isNull() ) | ||
return QString(); | ||
else | ||
return QStringLiteral( "%1,%2,%3,%4" ).arg( qgsDoubleToString( mLeft ), qgsDoubleToString( mTop ), | ||
qgsDoubleToString( mRight ), qgsDoubleToString( mBottom ) ); | ||
} | ||
|
||
QgsMargins QgsMargins::fromString( const QString& string ) | ||
{ | ||
QStringList margins = string.split( ',' ); | ||
if ( margins.count() != 4 ) | ||
return QgsMargins(); | ||
|
||
return QgsMargins( margins.at( 0 ).toDouble(), | ||
margins.at( 1 ).toDouble(), | ||
margins.at( 2 ).toDouble(), | ||
margins.at( 3 ).toDouble() ); | ||
} |
Oops, something went wrong.