summaryrefslogtreecommitdiffstats
path: root/examples/widgets/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/widgets')
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.cpp39
-rw-r--r--examples/widgets/widgets/tooltips/sortingbox.h5
-rw-r--r--examples/widgets/widgets/validators/validatorwidget.h5
3 files changed, 31 insertions, 18 deletions
diff --git a/examples/widgets/widgets/tooltips/sortingbox.cpp b/examples/widgets/widgets/tooltips/sortingbox.cpp
index d993b098b2..733e567873 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.cpp
+++ b/examples/widgets/widgets/tooltips/sortingbox.cpp
@@ -106,6 +106,13 @@ SortingBox::SortingBox(QWidget *parent)
}
//! [4]
+//! [27]
+SortingBox::~SortingBox()
+{
+ qDeleteAll(shapeItems);
+}
+//! [27]
+
//! [5]
bool SortingBox::event(QEvent *event)
{
@@ -114,7 +121,7 @@ bool SortingBox::event(QEvent *event)
QHelpEvent *helpEvent = static_cast<QHelpEvent *>(event);
int index = itemAt(helpEvent->pos());
if (index != -1) {
- QToolTip::showText(helpEvent->globalPos(), shapeItems[index].toolTip());
+ QToolTip::showText(helpEvent->globalPos(), shapeItems[index]->toolTip());
} else {
QToolTip::hideText();
event->ignore();
@@ -144,13 +151,13 @@ void SortingBox::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
- for (const ShapeItem &shapeItem : qAsConst(shapeItems)) {
+ for (const ShapeItem *shapeItem : std::as_const(shapeItems)) {
//! [8] //! [9]
- painter.translate(shapeItem.position());
+ painter.translate(shapeItem->position());
//! [9] //! [10]
- painter.setBrush(shapeItem.color());
- painter.drawPath(shapeItem.path());
- painter.translate(-shapeItem.position());
+ painter.setBrush(shapeItem->color());
+ painter.drawPath(shapeItem->path());
+ painter.translate(-shapeItem->position());
}
}
//! [10]
@@ -161,7 +168,7 @@ void SortingBox::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) {
int index = itemAt(event->position().toPoint());
if (index != -1) {
- itemInMotion = &shapeItems[index];
+ itemInMotion = shapeItems[index];
previousPosition = event->position().toPoint();
shapeItems.move(index, shapeItems.size() - 1);
update();
@@ -216,11 +223,11 @@ void SortingBox::createNewTriangle()
//! [16]
//! [17]
-int SortingBox::itemAt(const QPoint &pos)
+qsizetype SortingBox::itemAt(const QPoint &pos)
{
- for (int i = shapeItems.size() - 1; i >= 0; --i) {
- const ShapeItem &item = shapeItems[i];
- if (item.path().contains(pos - item.position()))
+ for (qsizetype i = shapeItems.size() - 1; i >= 0; --i) {
+ const ShapeItem *item = shapeItems[i];
+ if (item->path().contains(pos - item->position()))
return i;
}
return -1;
@@ -255,11 +262,11 @@ void SortingBox::createShapeItem(const QPainterPath &path,
const QString &toolTip, const QPoint &pos,
const QColor &color)
{
- ShapeItem shapeItem;
- shapeItem.setPath(path);
- shapeItem.setToolTip(toolTip);
- shapeItem.setPosition(pos);
- shapeItem.setColor(color);
+ ShapeItem *shapeItem = new ShapeItem;
+ shapeItem->setPath(path);
+ shapeItem->setToolTip(toolTip);
+ shapeItem->setPosition(pos);
+ shapeItem->setColor(color);
shapeItems.append(shapeItem);
update();
}
diff --git a/examples/widgets/widgets/tooltips/sortingbox.h b/examples/widgets/widgets/tooltips/sortingbox.h
index 3d0cecea2b..90534ab13d 100644
--- a/examples/widgets/widgets/tooltips/sortingbox.h
+++ b/examples/widgets/widgets/tooltips/sortingbox.h
@@ -68,6 +68,7 @@ class SortingBox : public QWidget
public:
SortingBox(QWidget *parent = nullptr);
+ ~SortingBox();
protected:
bool event(QEvent *event) override;
@@ -88,7 +89,7 @@ private:
int updateButtonGeometry(QToolButton *button, int x, int y);
void createShapeItem(const QPainterPath &path, const QString &toolTip,
const QPoint &pos, const QColor &color);
- int itemAt(const QPoint &pos);
+ qsizetype itemAt(const QPoint &pos);
void moveItemTo(const QPoint &pos);
QPoint initialItemPosition(const QPainterPath &path);
QPoint randomItemPosition();
@@ -99,7 +100,7 @@ private:
const char *member);
//! [2]
- QList<ShapeItem> shapeItems;
+ QList<ShapeItem *> shapeItems;
QPainterPath circlePath;
QPainterPath squarePath;
QPainterPath trianglePath;
diff --git a/examples/widgets/widgets/validators/validatorwidget.h b/examples/widgets/widgets/validators/validatorwidget.h
index bcc4a9b91e..7b80c58504 100644
--- a/examples/widgets/widgets/validators/validatorwidget.h
+++ b/examples/widgets/widgets/validators/validatorwidget.h
@@ -48,6 +48,9 @@
**
****************************************************************************/
+#ifndef VALIDATORWIDGET_H
+#define VALIDATORWIDGET_H
+
#include <QWidget>
#include "ui_validators.h"
@@ -62,3 +65,5 @@ private slots:
void updateValidator();
void updateDoubleValidator();
};
+
+#endif // VALIDATORWIDGET_H