From 485b87c9629c7e4e90b2b90394b1500ea0b9142b Mon Sep 17 00:00:00 2001 From: przemek83 <4788832+przemek83@users.noreply.github.com> Date: Thu, 26 Dec 2024 14:50:42 +0100 Subject: [PATCH] Use automatic memory instead of dynamic one for storing DoubleSlider example object. --- examples/Examples.cpp | 14 ++++++-------- examples/Examples.h | 7 +++++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/examples/Examples.cpp b/examples/Examples.cpp index 21b917e..05bbee3 100644 --- a/examples/Examples.cpp +++ b/examples/Examples.cpp @@ -9,7 +9,6 @@ #include #include -#include #include #include #include @@ -17,7 +16,7 @@ #include #include -Examples::Examples() : info_(QStringLiteral("Status")) +Examples::Examples() : info_(QStringLiteral("Status")), doubleSlider_{MIN, MAX} { setWindowTitle("Wble library examples"); QHBoxLayout* widgetLayout{new QHBoxLayout(this)}; @@ -28,16 +27,15 @@ Examples::Examples() : info_(QStringLiteral("Status")) setLayout(widgetLayout); } -DoubleSlider* Examples::createDoubleSlider() +DoubleSlider* Examples::getDoubleSlider() { - auto* slider{new DoubleSlider(MIN, MAX)}; - QObject::connect(slider, &DoubleSlider::currentMinChanged, this, + QObject::connect(&doubleSlider_, &DoubleSlider::currentMinChanged, this, &Examples::doubleSliderMinChanged); - QObject::connect(slider, &DoubleSlider::currentMaxChanged, this, + QObject::connect(&doubleSlider_, &DoubleSlider::currentMaxChanged, this, &Examples::doubleSliderMaxChanged); - return slider; + return &doubleSlider_; } FilterNumbers* Examples::createFilterIntegers() @@ -110,7 +108,7 @@ QVBoxLayout* Examples::createLeftWidgetColumn() leftLayout->setSpacing(DEFAULT_SPACING); auto* groupBox{new QGroupBox(QStringLiteral("Double Slider"))}; auto* layout{new QVBoxLayout(groupBox)}; - layout->addWidget(createDoubleSlider()); + layout->addWidget(getDoubleSlider()); groupBox->setLayout(layout); leftLayout->addWidget(groupBox); leftLayout->addWidget(createFilterIntegers()); diff --git a/examples/Examples.h b/examples/Examples.h index 7a8fd56..e6ac9fe 100644 --- a/examples/Examples.h +++ b/examples/Examples.h @@ -3,7 +3,8 @@ #include #include -class DoubleSlider; +#include + class FilterNumbers; class FilterDates; class FilterStrings; @@ -18,7 +19,7 @@ class Examples : public QWidget Examples(); private: - DoubleSlider* createDoubleSlider(); + DoubleSlider* getDoubleSlider(); FilterNumbers* createFilterIntegers(); FilterNumbers* createFilterDoubles(); FilterDates* createFilterDates(); @@ -39,6 +40,8 @@ class Examples : public QWidget QLabel info_; + DoubleSlider doubleSlider_; + private slots: void doubleSliderMinChanged(double min); void doubleSliderMaxChanged(double max);