Refactor widget creation in app.cpp to consistently use std::make_unique for Wt::WPushButton and Wt::WAnchor, enhancing memory management and code clarity.

This commit is contained in:
Torsten Schulz (local)
2025-11-16 14:31:26 +01:00
parent 4aa0089434
commit 6df39afd51

View File

@@ -817,7 +817,7 @@ void App::showAdminStarts() {
} }
Wt::WContainerWidget* App::createSmileyButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEdit* inputLine, std::shared_ptr<int> cursorPosition) { Wt::WContainerWidget* App::createSmileyButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEdit* inputLine, std::shared_ptr<int> cursorPosition) {
auto smileyButton = inputLayout->addNew<Wt::WContainerWidget>(); auto smileyButton = inputLayout->addWidget(std::make_unique<Wt::WContainerWidget>());
smileyButton->addNew<Wt::WImage>(Wt::WLink("/smileys.png")); smileyButton->addNew<Wt::WImage>(Wt::WLink("/smileys.png"));
smileyButton->setStyleClass("no-style"); smileyButton->setStyleClass("no-style");
smileyButton->setToolTip("Add a smiley"); smileyButton->setToolTip("Add a smiley");
@@ -837,7 +837,7 @@ Wt::WContainerWidget* App::createSmileyBar(Wt::WContainerWidget* parent, Wt::WLi
} }
Wt::WPushButton* App::createSendButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEdit* inputLine) { Wt::WPushButton* App::createSendButton(Wt::WHBoxLayout* inputLayout, Wt::WLineEdit* inputLine) {
auto sendButton = inputLayout->addNew<Wt::WPushButton>("Send"); auto sendButton = inputLayout->addWidget(std::make_unique<Wt::WPushButton>("Send"));
auto sendMessageFunction = [=, this]() { auto sendMessageFunction = [=, this]() {
sendMessage(inputLine); sendMessage(inputLine);
}; };
@@ -1420,9 +1420,9 @@ void App::showPartnerSites() {
contentContainer_->setOverflow(Wt::Overflow::Auto); contentContainer_->setOverflow(Wt::Overflow::Auto);
auto linkContainer = contentContainer_->addNew<Wt::WContainerWidget>(); auto linkContainer = contentContainer_->addNew<Wt::WContainerWidget>();
auto contentLayout = linkContainer->setLayout(std::make_unique<Wt::WVBoxLayout>()); auto contentLayout = linkContainer->setLayout(std::make_unique<Wt::WVBoxLayout>());
contentLayout->addNew<Wt::WText>("<h1>Partners</h1>"); contentLayout->addWidget(std::make_unique<Wt::WText>("<h1>Partners</h1>"));
if (userName == "") { if (userName == "") {
auto hpLink = contentLayout->addNew<Wt::WText>("Back to main page"); auto hpLink = contentLayout->addWidget(std::make_unique<Wt::WText>("Back to main page"));
hpLink->clicked().connect(this, &App::showLogin); hpLink->clicked().connect(this, &App::showLogin);
} }
rapidcsv::Document doc("../docroot/links.csv"); rapidcsv::Document doc("../docroot/links.csv");
@@ -1431,7 +1431,7 @@ void App::showPartnerSites() {
auto name = doc.GetCell<std::string>(0, i); auto name = doc.GetCell<std::string>(0, i);
auto link = Wt::WLink(url); auto link = Wt::WLink(url);
link.setTarget(Wt::LinkTarget::NewWindow); link.setTarget(Wt::LinkTarget::NewWindow);
contentLayout->addNew<Wt::WAnchor>(link, name); contentLayout->addWidget(std::make_unique<Wt::WAnchor>(link, name));
} }
} }