diff options
| author | Michael Weghorn <[email protected]> | 2025-11-03 11:39:48 +0100 |
|---|---|---|
| committer | Michael Weghorn <[email protected]> | 2025-12-11 01:21:56 +0100 |
| commit | 952684f09f4579b9660b94c3a8a489efc41d3cb7 (patch) | |
| tree | f45e7c8e0495b83232474de93b92c9c8d5b4fc0e /src | |
| parent | aa85b050fe673869920382aa015ed66b99cfa51d (diff) | |
Don't allocate QColorLuminancePicker::pix on the heap
There's no reason to use a pointer for
this pixmap and allocate it on the heap.
Make use of the fact that a QPixmap can be a null
pixmap to indicate/detect the case when no actual pixmap
data are currently set.
Change-Id: Ibebacfdd5ee7e8d0563197b052dde88aa8ea8c7f
Reviewed-by: Richard Moe Gustavsen <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/widgets/dialogs/qcolordialog.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp index d51c408ab5c..ce46170bba5 100644 --- a/src/widgets/dialogs/qcolordialog.cpp +++ b/src/widgets/dialogs/qcolordialog.cpp @@ -662,7 +662,7 @@ private: int val2y(int val); void setVal(int v); - QPixmap *pix; + QPixmap pix; }; @@ -682,14 +682,12 @@ QColorLuminancePicker::QColorLuminancePicker(QWidget* parent) :QWidget(parent) { hue = 100; val = 100; sat = 100; - pix = nullptr; // setAttribute(WA_NoErase, true); setFocusPolicy(Qt::StrongFocus); } QColorLuminancePicker::~QColorLuminancePicker() { - delete pix; } void QColorLuminancePicker::keyPressEvent(QKeyEvent *event) @@ -725,7 +723,7 @@ void QColorLuminancePicker::setVal(int v) if (val == v) return; val = qMax(0, qMin(v,255)); - delete pix; pix=nullptr; + pix = QPixmap(); repaint(); emit newHsv(hue, sat, val); } @@ -744,8 +742,7 @@ void QColorLuminancePicker::paintEvent(QPaintEvent *) QRect r(0, foff, w, height() - 2*foff); int wi = r.width() - 2; int hi = r.height() - 2; - if (!pix || pix->height() != hi || pix->width() != wi) { - delete pix; + if (pix.isNull() || pix.height() != hi || pix.width() != wi) { QImage img(wi, hi, QImage::Format_RGB32); int y; uint *pixel = (uint *) img.scanLine(0); @@ -754,10 +751,10 @@ void QColorLuminancePicker::paintEvent(QPaintEvent *) std::fill(pixel, end, QColor::fromHsv(hue, sat, y2val(y + coff)).rgb()); pixel = end; } - pix = new QPixmap(QPixmap::fromImage(img)); + pix = QPixmap::fromImage(img); } QPainter p(this); - p.drawPixmap(1, coff, *pix); + p.drawPixmap(1, coff, pix); const QPalette &g = palette(); qDrawShadePanel(&p, r, g, true); p.setPen(g.windowText().color()); @@ -773,7 +770,7 @@ void QColorLuminancePicker::setCol(int h, int s , int v) val = v; hue = h; sat = s; - delete pix; pix=nullptr; + pix = QPixmap(); repaint(); } |
