| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "graphs2d/qabstractseries_p.h" |
| 5 | #include <QtGraphs/qareaseries.h> |
| 6 | #include <private/qareaseries_p.h> |
| 7 | #include <private/qgraphsview_p.h> |
| 8 | |
| 9 | QT_BEGIN_NAMESPACE |
| 10 | |
| 11 | /*! |
| 12 | \class QAreaSeries |
| 13 | \inmodule QtGraphs |
| 14 | \ingroup graphs_2D |
| 15 | \brief The QAreaSeries class presents data in area graphs. |
| 16 | |
| 17 | An area graph is used to draw an area composed by points. |
| 18 | The points are defined by two series: upperSeries and lowerSeries. |
| 19 | The area between the series is drawn as a graph. If only the upperSeries |
| 20 | is defined, the area is then between the bottom of the graph and the upper series. |
| 21 | */ |
| 22 | /*! |
| 23 | \qmltype AreaSeries |
| 24 | \nativetype QAreaSeries |
| 25 | \inqmlmodule QtGraphs |
| 26 | \ingroup graphs_qml_2D |
| 27 | \inherits AbstractSeries |
| 28 | |
| 29 | \brief Presents data in area graphs. |
| 30 | |
| 31 | An area graph is used to draw an area composed by points. |
| 32 | The points are defined by two series: upperSeries and lowerSeries. |
| 33 | The area between the series is drawn as a graph. If only the upperSeries |
| 34 | is defined, the area is then between the bottom of the graph and the upper series. |
| 35 | |
| 36 | \image graphs2d-area.png |
| 37 | */ |
| 38 | |
| 39 | /*! |
| 40 | \property QAreaSeries::color |
| 41 | \brief The fill color of the area. |
| 42 | The default value is \c Qt::transparent, meaning the color is defined by the theme. |
| 43 | */ |
| 44 | /*! |
| 45 | \qmlproperty color AreaSeries::color |
| 46 | The fill color of the area. |
| 47 | The default value is \c transparent, meaning the color is defined by the theme. |
| 48 | */ |
| 49 | |
| 50 | /*! |
| 51 | \property QAreaSeries::selectedColor |
| 52 | \brief The fill color of the area when selected. |
| 53 | The default value is \c Qt::transparent, meaning the selected color is defined by the theme. |
| 54 | */ |
| 55 | /*! |
| 56 | \qmlproperty color AreaSeries::selectedColor |
| 57 | The fill color of the area when selected. |
| 58 | The default value is \c transparent, meaning the selected color is defined by the theme. |
| 59 | */ |
| 60 | |
| 61 | /*! |
| 62 | \property QAreaSeries::borderColor |
| 63 | \brief The border color of the area. |
| 64 | The default value is \c Qt::transparent, meaning the border color is defined by the theme. |
| 65 | */ |
| 66 | /*! |
| 67 | \qmlproperty color AreaSeries::borderColor |
| 68 | The border color of the area. |
| 69 | The default value is \c transparent, meaning the border color is defined by the theme. |
| 70 | */ |
| 71 | |
| 72 | /*! |
| 73 | \property QAreaSeries::selectedBorderColor |
| 74 | \brief The border color of the area when selected. |
| 75 | The default value is \c Qt::transparent, meaning the selected border color is defined by the theme. |
| 76 | */ |
| 77 | /*! |
| 78 | \qmlproperty color AreaSeries::selectedBorderColor |
| 79 | The border color of the area when selected. |
| 80 | The default value is \c transparent, meaning the selected border color is defined by the theme. |
| 81 | */ |
| 82 | |
| 83 | /*! |
| 84 | \property QAreaSeries::borderWidth |
| 85 | \brief The width of the line that encloses the area. |
| 86 | The default value is \c -1, meaning the border width is defined by the theme. |
| 87 | */ |
| 88 | /*! |
| 89 | \qmlproperty real AreaSeries::borderWidth |
| 90 | The width of the line that encloses the area. |
| 91 | The default value is \c -1, meaning the border width is defined by the theme. |
| 92 | */ |
| 93 | |
| 94 | /*! |
| 95 | \property QAreaSeries::selected |
| 96 | \brief Sets this area as selected. |
| 97 | The default value is \c false. |
| 98 | */ |
| 99 | /*! |
| 100 | \qmlproperty bool AreaSeries::selected |
| 101 | Sets this area as selected. |
| 102 | The default value is \c false. |
| 103 | */ |
| 104 | |
| 105 | /*! |
| 106 | \property QAreaSeries::upperSeries |
| 107 | \brief Sets the upper boundary of the area. No area is drawn if this is null. |
| 108 | */ |
| 109 | /*! |
| 110 | \qmlproperty XYSeries AreaSeries::upperSeries |
| 111 | Sets the upper boundary of the area. No area is drawn if this is null. |
| 112 | */ |
| 113 | |
| 114 | /*! |
| 115 | \property QAreaSeries::lowerSeries |
| 116 | \brief Sets the lower boundary of the area. If this is null, the graph bottom |
| 117 | is considered the lower bound. |
| 118 | */ |
| 119 | /*! |
| 120 | \qmlproperty XYSeries AreaSeries::lowerSeries |
| 121 | Sets the lower boundary of the area. If this is null, the graph bottom |
| 122 | is considered the lower bound. |
| 123 | */ |
| 124 | |
| 125 | /*! |
| 126 | \qmlsignal AreaSeries::colorChanged(color newColor) |
| 127 | This signal is emitted when the area \l color changes to \a newColor. |
| 128 | */ |
| 129 | |
| 130 | /*! |
| 131 | \qmlsignal AreaSeries::selectedColorChanged(color newSelectedColor) |
| 132 | This signal is emitted when the color of a selected area changes to |
| 133 | \a newSelectedColor. |
| 134 | */ |
| 135 | |
| 136 | /*! |
| 137 | \qmlsignal AreaSeries::borderColorChanged(color newBorderColor) |
| 138 | This signal is emitted when the area border color changes to |
| 139 | \a newBorderColor. |
| 140 | */ |
| 141 | |
| 142 | /*! |
| 143 | \qmlsignal AreaSeries::selectedBorderColorChanged(color newSelectedBorderColor); |
| 144 | This signal is emitted when the border color of a selected area changes to |
| 145 | \a newSelectedBorderColor. |
| 146 | */ |
| 147 | |
| 148 | /*! |
| 149 | \qmlsignal AreaSeries::borderWidthChanged(); |
| 150 | This signal is emitted when the width of the area border width changes. |
| 151 | */ |
| 152 | |
| 153 | /*! |
| 154 | \qmlsignal AreaSeries::selectedChanged(); |
| 155 | This signal is emitted when the current area is selected. |
| 156 | */ |
| 157 | |
| 158 | /*! |
| 159 | \qmlsignal AreaSeries::upperSeriesChanged(); |
| 160 | This signal is emitted when the upper series changes. |
| 161 | */ |
| 162 | |
| 163 | /*! |
| 164 | \qmlsignal AreaSeries::lowerSeriesChanged(); |
| 165 | This signal is emitted when the lower series changes. |
| 166 | */ |
| 167 | |
| 168 | /*! |
| 169 | \qmlsignal AreaSeries::clicked(point point) |
| 170 | This signal is emitted when the user clicks or taps an area graph. |
| 171 | The \a point specifies the event triggered position. |
| 172 | */ |
| 173 | |
| 174 | /*! |
| 175 | \qmlsignal AreaSeries::doubleClicked(point point) |
| 176 | This signal is emitted when the user double-clicks or double-taps an area graph. |
| 177 | The \a point specifies the event triggered position. |
| 178 | This signal always occurs after \l clicked. |
| 179 | */ |
| 180 | |
| 181 | /*! |
| 182 | \qmlsignal AreaSeries::pressed(point point) |
| 183 | This signal is emitted when the user clicks or taps the area graph and holds down |
| 184 | the mouse button or gesture. |
| 185 | The \a point specifies the event triggered position. |
| 186 | */ |
| 187 | |
| 188 | /*! |
| 189 | \qmlsignal AreaSeries::released(point point) |
| 190 | This signal is emitted when the user releases a pressed click or tap. |
| 191 | The \a point specifies the event triggered position. |
| 192 | */ |
| 193 | |
| 194 | QAreaSeries::QAreaSeries(QObject *parent) |
| 195 | : QAbstractSeries(*(new QAreaSeriesPrivate()), parent) |
| 196 | {} |
| 197 | |
| 198 | QAreaSeries::~QAreaSeries() {} |
| 199 | |
| 200 | QAreaSeries::QAreaSeries(QAreaSeriesPrivate &dd, QObject *parent) |
| 201 | : QAbstractSeries(dd, parent) |
| 202 | {} |
| 203 | |
| 204 | QAbstractSeries::SeriesType QAreaSeries::type() const |
| 205 | { |
| 206 | return QAbstractSeries::SeriesType::Area; |
| 207 | } |
| 208 | |
| 209 | QColor QAreaSeries::color() const |
| 210 | { |
| 211 | Q_D(const QAreaSeries); |
| 212 | return d->m_color; |
| 213 | } |
| 214 | |
| 215 | void QAreaSeries::setColor(QColor newColor) |
| 216 | { |
| 217 | Q_D(QAreaSeries); |
| 218 | if (color() == newColor) { |
| 219 | qCDebug(lcProperties2D, "%s value is already set to: %s" , |
| 220 | qUtf8Printable(QLatin1String(__FUNCTION__)), qUtf8Printable(newColor.name())); |
| 221 | return; |
| 222 | } |
| 223 | d->m_color = newColor; |
| 224 | emit colorChanged(newColor); |
| 225 | } |
| 226 | |
| 227 | QColor QAreaSeries::selectedColor() const |
| 228 | { |
| 229 | Q_D(const QAreaSeries); |
| 230 | return d->m_selectedColor; |
| 231 | } |
| 232 | |
| 233 | void QAreaSeries::setSelectedColor(QColor newSelectedColor) |
| 234 | { |
| 235 | Q_D(QAreaSeries); |
| 236 | if (selectedColor() == newSelectedColor) { |
| 237 | qCDebug(lcProperties2D, "%s value is already set to: %s" , |
| 238 | qUtf8Printable(QLatin1String(__FUNCTION__)), |
| 239 | qUtf8Printable(newSelectedColor.name())); |
| 240 | return; |
| 241 | } |
| 242 | d->m_selectedColor = newSelectedColor; |
| 243 | emit selectedColorChanged(newSelectedColor); |
| 244 | } |
| 245 | |
| 246 | QColor QAreaSeries::borderColor() const |
| 247 | { |
| 248 | Q_D(const QAreaSeries); |
| 249 | return d->m_borderColor; |
| 250 | } |
| 251 | |
| 252 | void QAreaSeries::setBorderColor(QColor newBorderColor) |
| 253 | { |
| 254 | Q_D(QAreaSeries); |
| 255 | if (d->m_borderColor == newBorderColor) { |
| 256 | qCDebug(lcProperties2D, "%s value is already set to: %s" , |
| 257 | qUtf8Printable(QLatin1String(__FUNCTION__)), |
| 258 | qUtf8Printable(newBorderColor.name())); |
| 259 | return; |
| 260 | } |
| 261 | d->m_borderColor = newBorderColor; |
| 262 | emit borderColorChanged(newBorderColor); |
| 263 | } |
| 264 | |
| 265 | QColor QAreaSeries::selectedBorderColor() const |
| 266 | { |
| 267 | Q_D(const QAreaSeries); |
| 268 | return d->m_selectedBorderColor; |
| 269 | } |
| 270 | |
| 271 | void QAreaSeries::setSelectedBorderColor(QColor newSelectedBorderColor) |
| 272 | { |
| 273 | Q_D(QAreaSeries); |
| 274 | if (d->m_selectedBorderColor == newSelectedBorderColor) { |
| 275 | qCDebug(lcProperties2D, "%s value is already set to: %s" , |
| 276 | qUtf8Printable(QLatin1String(__FUNCTION__)), |
| 277 | qUtf8Printable(newSelectedBorderColor.name())); |
| 278 | return; |
| 279 | } |
| 280 | d->m_selectedBorderColor = newSelectedBorderColor; |
| 281 | emit selectedBorderColorChanged(newSelectedBorderColor); |
| 282 | } |
| 283 | |
| 284 | qreal QAreaSeries::borderWidth() const |
| 285 | { |
| 286 | Q_D(const QAreaSeries); |
| 287 | return d->m_borderWidth; |
| 288 | } |
| 289 | |
| 290 | void QAreaSeries::setBorderWidth(qreal newBorderWidth) |
| 291 | { |
| 292 | Q_D(QAreaSeries); |
| 293 | if (qFuzzyCompare(p1: d->m_borderWidth, p2: newBorderWidth)) { |
| 294 | qCDebug(lcProperties2D, "%s value is already set to: %.1f" , |
| 295 | qUtf8Printable(QLatin1String(__FUNCTION__)), newBorderWidth); |
| 296 | return; |
| 297 | } |
| 298 | d->m_borderWidth = newBorderWidth; |
| 299 | emit borderWidthChanged(); |
| 300 | } |
| 301 | |
| 302 | bool QAreaSeries::isSelected() const |
| 303 | { |
| 304 | Q_D(const QAreaSeries); |
| 305 | return d->m_selected; |
| 306 | } |
| 307 | |
| 308 | void QAreaSeries::setSelected(bool newSelected) |
| 309 | { |
| 310 | Q_D(QAreaSeries); |
| 311 | if (d->m_selected == newSelected) { |
| 312 | qCDebug(lcProperties2D) << __FUNCTION__ |
| 313 | << "value is already set to:" << newSelected; |
| 314 | return; |
| 315 | } |
| 316 | d->m_selected = newSelected; |
| 317 | emit selectedChanged(); |
| 318 | } |
| 319 | |
| 320 | QXYSeries *QAreaSeries::upperSeries() const |
| 321 | { |
| 322 | Q_D(const QAreaSeries); |
| 323 | return d->m_upperSeries; |
| 324 | } |
| 325 | |
| 326 | void QAreaSeries::setUpperSeries(QXYSeries *newUpperSeries) |
| 327 | { |
| 328 | Q_D(QAreaSeries); |
| 329 | if (d->m_upperSeries == newUpperSeries) { |
| 330 | qCDebug(lcProperties2D) << __FUNCTION__ |
| 331 | << "value is already set to:" << newUpperSeries; |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | if (d->m_upperSeries) |
| 336 | disconnect(sender: newUpperSeries, signal: &QXYSeries::update, receiver: this, slot: &QAreaSeries::update); |
| 337 | |
| 338 | d->m_upperSeries = newUpperSeries; |
| 339 | |
| 340 | connect(sender: newUpperSeries, signal: &QXYSeries::update, context: this, slot: &QAreaSeries::update); |
| 341 | |
| 342 | emit upperSeriesChanged(); |
| 343 | } |
| 344 | |
| 345 | QXYSeries *QAreaSeries::lowerSeries() const |
| 346 | { |
| 347 | Q_D(const QAreaSeries); |
| 348 | return d->m_lowerSeries; |
| 349 | } |
| 350 | |
| 351 | void QAreaSeries::setLowerSeries(QXYSeries *newLowerSeries) |
| 352 | { |
| 353 | Q_D(QAreaSeries); |
| 354 | if (d->m_lowerSeries == newLowerSeries) { |
| 355 | qCDebug(lcProperties2D) << __FUNCTION__ |
| 356 | << "value is already set to:" << newLowerSeries; |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | if (d->m_lowerSeries) |
| 361 | disconnect(sender: newLowerSeries, signal: &QXYSeries::update, receiver: this, slot: &QAreaSeries::update); |
| 362 | |
| 363 | d->m_lowerSeries = newLowerSeries; |
| 364 | |
| 365 | connect(sender: newLowerSeries, signal: &QXYSeries::update, context: this, slot: &QAreaSeries::update); |
| 366 | |
| 367 | emit lowerSeriesChanged(); |
| 368 | } |
| 369 | |
| 370 | QAreaSeriesPrivate::QAreaSeriesPrivate() |
| 371 | : QAbstractSeriesPrivate(QAbstractSeries::SeriesType::Area) |
| 372 | {} |
| 373 | |
| 374 | QT_END_NAMESPACE |
| 375 | |