From f2d1f3f1c7b9ab7e356b186d4187f46108d67b8c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 26 Dec 2014 21:43:40 +0100 Subject: QColor: plaster API with Q_DECL_NOTHROW This is mostly straight-forward, but some things are worth noting: 1. Yes, this is necessary. The noexcept operator looks for noexcept tagging, not at the contents of the function to determine whether to return true. The more conditionally-noexcept functions are used, the more important it becomes that low-level classes are correctly marked noexcept. In that, it is like constexpr. 2. In accordance with the rules governing noexcept specifications for the standard library itself, the get*() functions, as well as any function taking (but not returning) channel values as ints or qreals, or taking QStrings are not marked as noexcept, since they have preconditions and thus a narrow contract. Narrow-contract functions should not be noexcept. All other functions have wide contracts (ie. no preconditions). 3. Any function returning QString can throw (bad_alloc). Consequently, they, too, are not marked nothrow. Change-Id: I023356ba1b9a4b057e613cd45380a89b222dc09d Reviewed-by: Thiago Macieira --- src/gui/painting/qcolor.h | 138 +++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 69 deletions(-) (limited to 'src/gui/painting/qcolor.h') diff --git a/src/gui/painting/qcolor.h b/src/gui/painting/qcolor.h index 3ce73b6177..6338eedd22 100644 --- a/src/gui/painting/qcolor.h +++ b/src/gui/painting/qcolor.h @@ -66,28 +66,28 @@ public: enum Spec { Invalid, Rgb, Hsv, Cmyk, Hsl }; enum NameFormat { HexRgb, HexArgb }; - QColor(); - QColor(Qt::GlobalColor color); + QColor() Q_DECL_NOTHROW; + QColor(Qt::GlobalColor color) Q_DECL_NOTHROW; QColor(int r, int g, int b, int a = 255); - QColor(QRgb rgb); - QColor(QRgba64 rgba64); + QColor(QRgb rgb) Q_DECL_NOTHROW; + QColor(QRgba64 rgba64) Q_DECL_NOTHROW; QColor(const QString& name); QColor(const char *name); - QColor(Spec spec); + QColor(Spec spec) Q_DECL_NOTHROW; #if QT_VERSION < QT_VERSION_CHECK(6,0,0) - QColor(const QColor &color); // ### Qt 6: remove all of these, the trivial ones are fine. + QColor(const QColor &color) Q_DECL_NOTHROW; // ### Qt 6: remove all of these, the trivial ones are fine. # ifdef Q_COMPILER_RVALUE_REFS QColor(QColor &&other) Q_DECL_NOTHROW : cspec(other.cspec), ct(other.ct) {} QColor &operator=(QColor &&other) Q_DECL_NOTHROW { cspec = other.cspec; ct = other.ct; return *this; } # endif - QColor &operator=(const QColor &); + QColor &operator=(const QColor &) Q_DECL_NOTHROW; #endif // Qt < 6 - QColor &operator=(Qt::GlobalColor color); + QColor &operator=(Qt::GlobalColor color) Q_DECL_NOTHROW; - bool isValid() const; + bool isValid() const Q_DECL_NOTHROW; // ### Qt 6: merge overloads QString name() const; @@ -96,25 +96,25 @@ public: static QStringList colorNames(); - inline Spec spec() const + inline Spec spec() const Q_DECL_NOTHROW { return cspec; } - int alpha() const; + int alpha() const Q_DECL_NOTHROW; void setAlpha(int alpha); - qreal alphaF() const; + qreal alphaF() const Q_DECL_NOTHROW; void setAlphaF(qreal alpha); - int red() const; - int green() const; - int blue() const; + int red() const Q_DECL_NOTHROW; + int green() const Q_DECL_NOTHROW; + int blue() const Q_DECL_NOTHROW; void setRed(int red); void setGreen(int green); void setBlue(int blue); - qreal redF() const; - qreal greenF() const; - qreal blueF() const; + qreal redF() const Q_DECL_NOTHROW; + qreal greenF() const Q_DECL_NOTHROW; + qreal blueF() const Q_DECL_NOTHROW; void setRedF(qreal red); void setGreenF(qreal green); void setBlueF(qreal blue); @@ -125,26 +125,26 @@ public: void getRgbF(qreal *r, qreal *g, qreal *b, qreal *a = Q_NULLPTR) const; void setRgbF(qreal r, qreal g, qreal b, qreal a = 1.0); - QRgb rgba() const; - void setRgba(QRgb rgba); + QRgba64 rgba64() const Q_DECL_NOTHROW; + void setRgba64(QRgba64 rgba) Q_DECL_NOTHROW; - QRgba64 rgba64() const; - void setRgba64(QRgba64 rgba); + QRgb rgba() const Q_DECL_NOTHROW; + void setRgba(QRgb rgba) Q_DECL_NOTHROW; - QRgb rgb() const; - void setRgb(QRgb rgb); + QRgb rgb() const Q_DECL_NOTHROW; + void setRgb(QRgb rgb) Q_DECL_NOTHROW; - int hue() const; // 0 <= hue < 360 - int saturation() const; - int hsvHue() const; // 0 <= hue < 360 - int hsvSaturation() const; - int value() const; + int hue() const Q_DECL_NOTHROW; // 0 <= hue < 360 + int saturation() const Q_DECL_NOTHROW; + int hsvHue() const Q_DECL_NOTHROW; // 0 <= hue < 360 + int hsvSaturation() const Q_DECL_NOTHROW; + int value() const Q_DECL_NOTHROW; - qreal hueF() const; // 0.0 <= hueF < 360.0 - qreal saturationF() const; - qreal hsvHueF() const; // 0.0 <= hueF < 360.0 - qreal hsvSaturationF() const; - qreal valueF() const; + qreal hueF() const Q_DECL_NOTHROW; // 0.0 <= hueF < 360.0 + qreal saturationF() const Q_DECL_NOTHROW; + qreal hsvHueF() const Q_DECL_NOTHROW; // 0.0 <= hueF < 360.0 + qreal hsvSaturationF() const Q_DECL_NOTHROW; + qreal valueF() const Q_DECL_NOTHROW; void getHsv(int *h, int *s, int *v, int *a = Q_NULLPTR) const; void setHsv(int h, int s, int v, int a = 255); @@ -152,15 +152,15 @@ public: void getHsvF(qreal *h, qreal *s, qreal *v, qreal *a = Q_NULLPTR) const; void setHsvF(qreal h, qreal s, qreal v, qreal a = 1.0); - int cyan() const; - int magenta() const; - int yellow() const; - int black() const; + int cyan() const Q_DECL_NOTHROW; + int magenta() const Q_DECL_NOTHROW; + int yellow() const Q_DECL_NOTHROW; + int black() const Q_DECL_NOTHROW; - qreal cyanF() const; - qreal magentaF() const; - qreal yellowF() const; - qreal blackF() const; + qreal cyanF() const Q_DECL_NOTHROW; + qreal magentaF() const Q_DECL_NOTHROW; + qreal yellowF() const Q_DECL_NOTHROW; + qreal blackF() const Q_DECL_NOTHROW; void getCmyk(int *c, int *m, int *y, int *k, int *a = Q_NULLPTR); void setCmyk(int c, int m, int y, int k, int a = 255); @@ -168,13 +168,13 @@ public: void getCmykF(qreal *c, qreal *m, qreal *y, qreal *k, qreal *a = Q_NULLPTR); void setCmykF(qreal c, qreal m, qreal y, qreal k, qreal a = 1.0); - int hslHue() const; // 0 <= hue < 360 - int hslSaturation() const; - int lightness() const; + int hslHue() const Q_DECL_NOTHROW; // 0 <= hue < 360 + int hslSaturation() const Q_DECL_NOTHROW; + int lightness() const Q_DECL_NOTHROW; - qreal hslHueF() const; // 0.0 <= hueF < 360.0 - qreal hslSaturationF() const; - qreal lightnessF() const; + qreal hslHueF() const Q_DECL_NOTHROW; // 0.0 <= hueF < 360.0 + qreal hslSaturationF() const Q_DECL_NOTHROW; + qreal lightnessF() const Q_DECL_NOTHROW; void getHsl(int *h, int *s, int *l, int *a = Q_NULLPTR) const; void setHsl(int h, int s, int l, int a = 255); @@ -182,21 +182,21 @@ public: void getHslF(qreal *h, qreal *s, qreal *l, qreal *a = Q_NULLPTR) const; void setHslF(qreal h, qreal s, qreal l, qreal a = 1.0); - QColor toRgb() const; - QColor toHsv() const; - QColor toCmyk() const; - QColor toHsl() const; + QColor toRgb() const Q_DECL_NOTHROW; + QColor toHsv() const Q_DECL_NOTHROW; + QColor toCmyk() const Q_DECL_NOTHROW; + QColor toHsl() const Q_DECL_NOTHROW; - QColor convertTo(Spec colorSpec) const Q_REQUIRED_RESULT; + QColor convertTo(Spec colorSpec) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; - static QColor fromRgb(QRgb rgb); - static QColor fromRgba(QRgb rgba); + static QColor fromRgb(QRgb rgb) Q_DECL_NOTHROW; + static QColor fromRgba(QRgb rgba) Q_DECL_NOTHROW; static QColor fromRgb(int r, int g, int b, int a = 255); static QColor fromRgbF(qreal r, qreal g, qreal b, qreal a = 1.0); - static QColor fromRgba64(ushort r, ushort g, ushort b, ushort a = USHRT_MAX); - static QColor fromRgba64(QRgba64 rgba); + static QColor fromRgba64(ushort r, ushort g, ushort b, ushort a = USHRT_MAX) Q_DECL_NOTHROW; + static QColor fromRgba64(QRgba64 rgba) Q_DECL_NOTHROW; static QColor fromHsv(int h, int s, int v, int a = 255); static QColor fromHsvF(qreal h, qreal s, qreal v, qreal a = 1.0); @@ -207,13 +207,13 @@ public: static QColor fromHsl(int h, int s, int l, int a = 255); static QColor fromHslF(qreal h, qreal s, qreal l, qreal a = 1.0); - QColor light(int f = 150) const Q_REQUIRED_RESULT; - QColor lighter(int f = 150) const Q_REQUIRED_RESULT; - QColor dark(int f = 200) const Q_REQUIRED_RESULT; - QColor darker(int f = 200) const Q_REQUIRED_RESULT; + QColor light(int f = 150) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + QColor lighter(int f = 150) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + QColor dark(int f = 200) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; + QColor darker(int f = 200) const Q_DECL_NOTHROW Q_REQUIRED_RESULT; - bool operator==(const QColor &c) const; - bool operator!=(const QColor &c) const; + bool operator==(const QColor &c) const Q_DECL_NOTHROW; + bool operator!=(const QColor &c) const Q_DECL_NOTHROW; operator QVariant() const; @@ -221,7 +221,7 @@ public: private: - void invalidate(); + void invalidate() Q_DECL_NOTHROW; bool setColorFromString(const QString &name); Spec cspec; @@ -264,7 +264,7 @@ private: #endif }; -inline QColor::QColor() +inline QColor::QColor() Q_DECL_NOTHROW { invalidate(); } inline QColor::QColor(int r, int g, int b, int a) @@ -277,18 +277,18 @@ inline QColor::QColor(const QString& aname) { setNamedColor(aname); } #if QT_VERSION < QT_VERSION_CHECK(6,0,0) -inline QColor::QColor(const QColor &acolor) +inline QColor::QColor(const QColor &acolor) Q_DECL_NOTHROW : cspec(acolor.cspec) { ct.argb = acolor.ct.argb; } #endif -inline bool QColor::isValid() const +inline bool QColor::isValid() const Q_DECL_NOTHROW { return cspec != Invalid; } -inline QColor QColor::lighter(int f) const +inline QColor QColor::lighter(int f) const Q_DECL_NOTHROW { return light(f); } -inline QColor QColor::darker(int f) const +inline QColor QColor::darker(int f) const Q_DECL_NOTHROW { return dark(f); } QT_END_NAMESPACE -- cgit v1.2.3