Skip to content

Commit

Permalink
Some improvements in Examples class.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Dec 26, 2024
1 parent 9e1e07b commit 0cf7691
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions examples/Examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Examples::Examples() : info_(QStringLiteral("Status"))
{
setWindowTitle("Wble library examples");
QHBoxLayout* widgetLayout = new QHBoxLayout(this);
QHBoxLayout* widgetLayout{new QHBoxLayout(this)};
QVBoxLayout* leftWidgetColumn = createLeftWidgetColumn();
widgetLayout->addLayout(leftWidgetColumn);
QVBoxLayout* rightWidgetColumn = createRightWidgetColumn();
Expand All @@ -30,7 +30,7 @@ Examples::Examples() : info_(QStringLiteral("Status"))

DoubleSlider* Examples::createDoubleSlider()
{
auto* slider = new DoubleSlider(MIN, MAX);
auto* slider{new DoubleSlider(MIN, MAX)};
QObject::connect(
slider, &DoubleSlider::currentMinChanged, &info_,
[&info = info_](double min)
Expand All @@ -46,41 +46,40 @@ DoubleSlider* Examples::createDoubleSlider()

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

filterNumbers->setCheckable(true);
return filterNumbers;
filter->setCheckable(true);
return filter;
}

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

filterNumbers->setCheckable(true);
return filterNumbers;
filter->setCheckable(true);
return filter;
}

FilterDates* Examples::createFilterDates()
{
auto* filterDates =
new FilterDates(QStringLiteral("Dates Filter"), QDate(2010, 9, 21),
QDate(2012, 2, 25), true);
auto* filterDates{new FilterDates(QStringLiteral("Dates Filter"),
QDate(2010, 9, 21), QDate(2012, 2, 25),
true)};
QObject::connect(
filterDates, &FilterDates::newDateFilter, &info_,
[&info = info_](QDate from, QDate to, bool filterEmptyDates)
Expand All @@ -96,25 +95,25 @@ FilterDates* Examples::createFilterDates()

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

filterNames->setCheckable(true);
return filterNames;
filter->setCheckable(true);
return filter;
}

QVBoxLayout* Examples::createLeftWidgetColumn()
{
auto* leftLayout = new QVBoxLayout();
auto* leftLayout{new QVBoxLayout()};
leftLayout->setSpacing(DEFAULT_SPACING);
auto* groupBox = new QGroupBox(QStringLiteral("Double Slider"));
auto* layout = new QVBoxLayout(groupBox);
auto* groupBox{new QGroupBox(QStringLiteral("Double Slider"))};
auto* layout{new QVBoxLayout(groupBox)};
layout->addWidget(createDoubleSlider());
groupBox->setLayout(layout);
leftLayout->addWidget(groupBox);
Expand All @@ -131,8 +130,8 @@ QGroupBox* Examples::wrapProgressBar(const QString& name,
ProgressBar* progressBar,
QPushButton* startStopButton)
{
auto* groupBox = new QGroupBox(name);
auto* layout = new QVBoxLayout();
auto* groupBox{new QGroupBox(name)};
auto* layout{new QVBoxLayout()};
layout->addWidget(progressBar);
layout->addWidget(startStopButton);
groupBox->setLayout(layout);
Expand All @@ -141,13 +140,13 @@ QGroupBox* Examples::wrapProgressBar(const QString& name,

QGroupBox* Examples::createProgressBarInfinite()
{
auto* progressBar = new ProgressBarInfinite(QStringLiteral("Title"));
auto* startStopButton = new QPushButton(QStringLiteral("start"));
auto* progressBar{new ProgressBarInfinite(QStringLiteral("Title"))};
auto* startStopButton{new QPushButton(QStringLiteral("start"))};
QObject::connect(
startStopButton, &QPushButton::clicked, progressBar,
[=]()
{
const bool running = progressBar->isRunning();
const bool running{progressBar->isRunning()};
if (running)
progressBar->stop();
else
Expand All @@ -161,10 +160,10 @@ QGroupBox* Examples::createProgressBarInfinite()

QGroupBox* Examples::createProgressBarCounter()
{
auto* progressBar =
new ProgressBarCounter(QStringLiteral("Title"), MAX_PROGRESS_BAR_VALUE);
auto* startStopButton = new QPushButton(QStringLiteral("start"));
auto* timer = new QTimer(progressBar);
auto* progressBar{new ProgressBarCounter(QStringLiteral("Title"),
MAX_PROGRESS_BAR_VALUE)};
auto* startStopButton{new QPushButton(QStringLiteral("start"))};
auto* timer{new QTimer(progressBar)};
timer->setInterval(40);
QObject::connect(timer, &QTimer::timeout, progressBar,
[=]()
Expand Down Expand Up @@ -203,7 +202,7 @@ QGroupBox* Examples::createProgressBarCounter()

QVBoxLayout* Examples::createRightWidgetColumn()
{
auto* rightLayout = new QVBoxLayout();
auto* rightLayout{new QVBoxLayout()};
rightLayout->setSpacing(DEFAULT_SPACING);
rightLayout->addWidget(createProgressBarInfinite());
rightLayout->addWidget(createProgressBarCounter());
Expand Down

0 comments on commit 0cf7691

Please sign in to comment.