Skip to content

Commit

Permalink
Replace multiple uses in examples of dynamic memory by automiatic mem…
Browse files Browse the repository at this point in the history
…ory.
  • Loading branch information
przemek83 committed Dec 26, 2024
1 parent 485b87c commit 41b087d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
49 changes: 22 additions & 27 deletions examples/Examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,19 @@
#include <QVBoxLayout>
#include <QWindow>

#include <wble/FilterDates.h>
#include <wble/FilterDoubles.h>
#include <wble/FilterIntegers.h>
#include <wble/FilterStrings.h>
#include <wble/ProgressBarCounter.h>
#include <wble/ProgressBarInfinite.h>

Examples::Examples() : info_(QStringLiteral("Status")), doubleSlider_{MIN, MAX}
Examples::Examples()
: info_(QStringLiteral("Status")),
doubleSlider_{MIN, MAX},
filterIntegers_{QStringLiteral("Integers Filter"), MIN, MAX},
filterDoubles_{QStringLiteral("Doubles Filter"), MIN, MAX},
filterDates_{QStringLiteral("Dates Filter"), QDate(2010, 9, 21),
QDate(2012, 2, 25), true},
filterStrings_{QStringLiteral("Names Filter"),
QStringList{QStringLiteral("a"), QStringLiteral("b"),
QStringLiteral("c"), QStringLiteral("d")}}
{
setWindowTitle("Wble library examples");
QHBoxLayout* widgetLayout{new QHBoxLayout(this)};
Expand All @@ -40,66 +45,56 @@ DoubleSlider* Examples::getDoubleSlider()

FilterNumbers* Examples::createFilterIntegers()
{
auto* filter{
new FilterIntegers(QStringLiteral("Integers Filter"), MIN, MAX)};
QObject::connect(
filter, &FilterIntegers::newNumericFilter, &info_,
&filterIntegers_, &FilterIntegers::newNumericFilter, &info_,
[&info = info_](int min, int max)
{
info.setText("Integers Filter: " + QString::number(min) + " | " +
QString::number(max));
});

filter->setCheckable(true);
return filter;
filterIntegers_.setCheckable(true);
return &filterIntegers_;
}

FilterNumbers* Examples::createFilterDoubles()
{
auto* filter{new FilterDoubles(QStringLiteral("Doubles Filter"), MIN, MAX)};
QObject::connect(
filter, &FilterDoubles::newNumericFilter, &info_,
&filterDoubles_, &FilterDoubles::newNumericFilter, &info_,
[&info = info_](double min, double max)
{
info.setText("Doubles Filter: " + QString::number(min) + " | " +
QString::number(max));
});

filter->setCheckable(true);
return filter;
filterDoubles_.setCheckable(true);
return &filterDoubles_;
}

FilterDates* Examples::createFilterDates()
{
auto* filterDates{new FilterDates(QStringLiteral("Dates Filter"),
QDate(2010, 9, 21), QDate(2012, 2, 25),
true)};
QObject::connect(
filterDates, &FilterDates::newDateFilter, &info_,
&filterDates_, &FilterDates::newDateFilter, &info_,
[&info = info_](QDate from, QDate to, bool filterEmptyDates)
{
info.setText("Dates Filter: " + from.toString() + " | " +
to.toString() + " | " +
(filterEmptyDates ? "yes" : "no"));
});

filterDates->setCheckable(true);
return filterDates;
filterDates_.setCheckable(true);
return &filterDates_;
}

FilterStrings* Examples::createFilterStrings()
{
auto* filter{new FilterStrings(
QStringLiteral("Names Filter"),
QStringList{QStringLiteral("a"), QStringLiteral("b"),
QStringLiteral("c"), QStringLiteral("d")})};
QObject::connect(filter, &FilterStrings::newStringFilter, &info_,
QObject::connect(&filterStrings_, &FilterStrings::newStringFilter, &info_,
[&info = info_](const QStringList& bannedItems) {
info.setText("Names Filter: " + bannedItems.join(','));
});

filter->setCheckable(true);
return filter;
filterStrings_.setCheckable(true);
return &filterStrings_;
}

QVBoxLayout* Examples::createLeftWidgetColumn()
Expand Down
11 changes: 8 additions & 3 deletions examples/Examples.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include <QWidget>

#include <wble/DoubleSlider.h>
#include <wble/FilterDates.h>
#include <wble/FilterDoubles.h>
#include <wble/FilterIntegers.h>
#include <wble/FilterStrings.h>

class FilterNumbers;
class FilterDates;
class FilterStrings;
class QVBoxLayout;
class QGroupBox;
class ProgressBar;
Expand Down Expand Up @@ -41,6 +42,10 @@ class Examples : public QWidget
QLabel info_;

DoubleSlider doubleSlider_;
FilterIntegers filterIntegers_;
FilterDoubles filterDoubles_;
FilterDates filterDates_;
FilterStrings filterStrings_;

private slots:
void doubleSliderMinChanged(double min);
Expand Down

0 comments on commit 41b087d

Please sign in to comment.