BPS C++ API  2.24.4
bpsmargins.h
Go to the documentation of this file.
1 
4 #ifndef BPSMARGINS_H
5 #define BPSMARGINS_H
6 
7 #include "bpscore_global.h"
8 #include <QMetaType>
9 #include <QVariant>
10 
15 {
16 public:
20  static int metaType();
21 
26 
31  BpsMargins(const BpsMargins& aMargins);
32 
37  BpsMargins(qreal aValue);
38 
44  BpsMargins(qreal aTopBottom, qreal aLeftRight);
45 
53  BpsMargins(qreal aTop, qreal aRight, qreal aBottom, qreal aLeft);
54 
58  QString toString() const;
59 
63  inline bool isNull() const;
64 
68  inline bool isValid() const;
69 
73  inline qreal top() const;
74 
78  inline qreal right() const;
79 
83  inline qreal bottom() const;
84 
88  inline qreal left() const;
89 
94  inline void setTop(qreal aValue);
95 
100  inline void setRight(qreal aValue);
101 
106  inline void setBottom(qreal aValue);
107 
112  inline void setLeft(qreal aValue);
113 
117  inline qreal& rtop();
118 
122  inline qreal& rright();
123 
127  inline qreal& rbottom();
128 
132  inline qreal& rleft();
133 
137  inline operator QVariant() const;
138 
144  inline BpsMargins& operator*=(qreal aFactor);
145 
151  inline BpsMargins& operator/=(qreal aDivisor);
152 
154  friend inline bool operator==(const BpsMargins& aFirst, const BpsMargins& aSecond);
155  friend inline bool operator!=(const BpsMargins& aFirst, const BpsMargins& aSecond);
156  friend inline const BpsMargins operator*(qreal aFactor, const BpsMargins& aMargins);
157  friend inline const BpsMargins operator*(const BpsMargins& aMargins, qreal aFactor);
158  friend inline const BpsMargins operator/(const BpsMargins& aMargins, qreal aDivisor);
160 
161 private:
163  qreal mTop, mRight, mBottom, mLeft;
165 };
166 
168 Q_DECLARE_METATYPE(BpsMargins)
169 Q_DECLARE_TYPEINFO(BpsMargins, Q_MOVABLE_TYPE);
171 
172 /************************************************************************/
173 /* S T R E A M F U N C T I O N S */
174 /************************************************************************/
175 
183 
191 
199 
200 /************************************************************************/
201 /* M E M B E R I N L I N E S */
202 /************************************************************************/
203 
204 inline bool BpsMargins::isNull() const
205 {
206  return qIsNull(mTop) && qIsNull(mRight) && qIsNull(mBottom) && qIsNull(mLeft);
207 } // isNull
208 
209 inline bool BpsMargins::isValid() const
210 {
211  return mTop>=0.0 && mRight>=0.0 && mBottom>=0.0 && mLeft>=0.0;
212 } // isValid
213 
214 inline qreal BpsMargins::top() const { return mTop; }
215 inline qreal BpsMargins::right() const { return mRight; }
216 inline qreal BpsMargins::bottom() const { return mBottom; }
217 inline qreal BpsMargins::left() const { return mLeft; }
218 
219 inline void BpsMargins::setTop(qreal aValue) { mTop = aValue; }
220 inline void BpsMargins::setRight(qreal aValue) { mRight = aValue; }
221 inline void BpsMargins::setBottom(qreal aValue) { mBottom = aValue; }
222 inline void BpsMargins::setLeft(qreal aValue) { mLeft = aValue; }
223 
224 inline qreal& BpsMargins::rtop() { return mTop; }
225 inline qreal& BpsMargins::rright() { return mRight; }
226 inline qreal& BpsMargins::rbottom() { return mBottom; }
227 inline qreal& BpsMargins::rleft() { return mLeft; }
228 
229 inline BpsMargins::operator QVariant() const
230 {
231  return QVariant::fromValue(*this);
232 } // operator QVariant
233 
234 inline BpsMargins& BpsMargins::operator*=(qreal aFactor)
235 {
236  mTop *= aFactor;
237  mRight *= aFactor;
238  mBottom *= aFactor;
239  mLeft *= aFactor;
240  return *this;
241 } // operator*=
242 
243 inline BpsMargins& BpsMargins::operator/=(qreal aDivisor)
244 {
245  Q_ASSERT(!qIsNull(aDivisor));
246  mTop /= aDivisor;
247  mRight /= aDivisor;
248  mBottom /= aDivisor;
249  mLeft /= aDivisor;
250  return *this;
251 } // operator/=
252 
253 
254 /************************************************************************/
255 /* F R I E N D I N L I N E S */
256 /************************************************************************/
257 
264 inline bool operator==(const BpsMargins& aFirst, const BpsMargins& aSecond)
265 {
266  return
267  qFuzzyCompare(aFirst.mTop, aSecond.mTop) &&
268  qFuzzyCompare(aFirst.mRight, aSecond.mRight) &&
269  qFuzzyCompare(aFirst.mBottom, aSecond.mBottom) &&
270  qFuzzyCompare(aFirst.mLeft, aSecond.mLeft);
271 } // operator==
272 
279 inline bool operator!=(const BpsMargins& aFirst, const BpsMargins& aSecond)
280 {
281  return
282  !qFuzzyCompare(aFirst.mTop, aSecond.mTop) ||
283  !qFuzzyCompare(aFirst.mRight, aSecond.mRight) ||
284  !qFuzzyCompare(aFirst.mBottom, aSecond.mBottom) ||
285  !qFuzzyCompare(aFirst.mLeft, aSecond.mLeft);
286 } // operator==
287 
294 inline const BpsMargins operator*(const BpsMargins& aMargins, qreal aFactor)
295 {
296  return
297  BpsMargins(
298  aMargins.mTop * aFactor,
299  aMargins.mRight * aFactor,
300  aMargins.mBottom * aFactor,
301  aMargins.mLeft * aFactor
302  );
303 } // operator*
304 
311 inline const BpsMargins operator*(qreal aFactor, const BpsMargins& aMargins)
312 {
313  return
314  BpsMargins(
315  aMargins.mTop * aFactor,
316  aMargins.mRight * aFactor,
317  aMargins.mBottom * aFactor,
318  aMargins.mLeft * aFactor
319  );
320 } // operator*
321 
328 inline const BpsMargins operator/(const BpsMargins &aMargins, qreal aDivisor)
329 {
330  Q_ASSERT(!qIsNull(aDivisor));
331  return
332  BpsMargins(
333  aMargins.mTop / aDivisor,
334  aMargins.mRight / aDivisor,
335  aMargins.mBottom / aDivisor,
336  aMargins.mLeft / aDivisor
337  );
338 } // operator/
339 
340 #endif // BPSMARGINS_H
Public include file for BPS CORE library macros.
#define BPSCORE_EXPORT
Declare class to be an import from the shared library.
Definition: bpscore_global.h:22
BPSCORE_EXPORT QDataStream & operator<<(QDataStream &aStream, const BpsDecimal &aDecimal)
Write the binary code of the decimal value to a data stream.
BPSCORE_EXPORT QDataStream & operator>>(QDataStream &aStream, BpsDecimal &aDecimal)
Read the binary code of the decimal value from a data stream.
This class is used to store margins top, right, bottom and left.
Definition: bpsmargins.h:15
bool isValid() const
Definition: bpsmargins.h:209
BpsMargins()
The default constructor creates an invalid margins object (all values = -1.0).
qreal & rtop()
Definition: bpsmargins.h:224
qreal left() const
Definition: bpsmargins.h:217
qreal right() const
Definition: bpsmargins.h:215
void setTop(qreal aValue)
Set the top margin value.
Definition: bpsmargins.h:219
qreal bottom() const
Definition: bpsmargins.h:216
qreal & rright()
Definition: bpsmargins.h:225
QString toString() const
BpsMargins & operator*=(qreal aFactor)
Multiply all margin values by a factor.
Definition: bpsmargins.h:234
void setBottom(qreal aValue)
Set the bottom margin value.
Definition: bpsmargins.h:221
BpsMargins(qreal aTop, qreal aRight, qreal aBottom, qreal aLeft)
Convenience constructor where the margin values are provided.
BpsMargins(const BpsMargins &aMargins)
The copy constructor.
qreal & rleft()
Definition: bpsmargins.h:227
BpsMargins & operator/=(qreal aDivisor)
Divide all margin values by a divisor.
Definition: bpsmargins.h:243
static int metaType()
bool operator==(const BpsMargins &aFirst, const BpsMargins &aSecond)
Compare two margin objects.
Definition: bpsmargins.h:264
void setLeft(qreal aValue)
Set the left margin value.
Definition: bpsmargins.h:222
BpsMargins(qreal aTopBottom, qreal aLeftRight)
Convenience constructor where the margin values are provided.
void setRight(qreal aValue)
Set the right margin value.
Definition: bpsmargins.h:220
BpsMargins(qreal aValue)
Convenience constructor where the margin values are provided.
const BpsMargins operator*(const BpsMargins &aMargins, qreal aFactor)
Multiply a margin object by a qreal.
Definition: bpsmargins.h:294
qreal & rbottom()
Definition: bpsmargins.h:226
const BpsMargins operator*(qreal aFactor, const BpsMargins &aMargins)
Multiply a qreal with a margin object.
Definition: bpsmargins.h:311
const BpsMargins operator/(const BpsMargins &aMargins, qreal aDivisor)
Divide a margin object by a qreal.
Definition: bpsmargins.h:328
bool operator!=(const BpsMargins &aFirst, const BpsMargins &aSecond)
Compare two margin objects.
Definition: bpsmargins.h:279
qreal top() const
Definition: bpsmargins.h:214
bool isNull() const
Definition: bpsmargins.h:204
QVariant fromValue(const T &value)