Use base::weak_qptr / base::make_weak.

This commit is contained in:
John Preston
2025-07-18 10:07:39 +04:00
parent 321c7120df
commit b754ad5248
189 changed files with 556 additions and 555 deletions
@@ -404,7 +404,9 @@ auto ApiWrap::fileRequest(const Data::FileLocation &location, int64 offset) {
}).toDC(MTP::ShiftDcId(location.dcId, MTP::kExportMediaDcShift)));
}
ApiWrap::ApiWrap(QPointer<MTP::Instance> weak, Fn<void(FnMut<void()>)> runner)
ApiWrap::ApiWrap(
base::weak_qptr<MTP::Instance> weak,
Fn<void(FnMut<void()>)> runner)
: _mtp(weak, std::move(runner))
, _fileCache(std::make_unique<LoadedFileCache>(kLocationCacheSize)) {
}
@@ -40,7 +40,9 @@ struct Settings;
class ApiWrap {
public:
ApiWrap(QPointer<MTP::Instance> weak, Fn<void(FnMut<void()>)> runner);
ApiWrap(
base::weak_qptr<MTP::Instance> weak,
Fn<void(FnMut<void()>)> runner);
rpl::producer<MTP::Error> errors() const;
rpl::producer<Output::Result> ioErrors() const;
@@ -96,11 +96,11 @@ Environment PrepareEnvironment(not_null<Main::Session*> session) {
return result;
}
QPointer<Ui::BoxContent> SuggestStart(not_null<Main::Session*> session) {
base::weak_qptr<Ui::BoxContent> SuggestStart(not_null<Main::Session*> session) {
ClearSuggestStart(session);
return Ui::show(
Box<SuggestBox>(session),
Ui::LayerOption::KeepOther).data();
Ui::LayerOption::KeepOther).get();
}
void ClearSuggestStart(not_null<Main::Session*> session) {
@@ -277,7 +277,7 @@ void PanelController::showCriticalError(const QString &text) {
void PanelController::showError(const QString &text) {
auto box = Ui::MakeInformBox(text);
const auto weak = Ui::MakeWeak(box.data());
const auto weak = base::make_weak(box.data());
const auto hidden = _panel->isHidden();
_panel->showBox(
std::move(box),
@@ -24,7 +24,7 @@ class Session;
namespace Export {
namespace View {
QPointer<Ui::BoxContent> SuggestStart(not_null<Main::Session*> session);
base::weak_qptr<Ui::BoxContent> SuggestStart(not_null<Main::Session*> session);
void ClearSuggestStart(not_null<Main::Session*> session);
bool IsDefaultPath(not_null<Main::Session*> session, const QString &path);
void ResolveSettings(not_null<Main::Session*> session, Settings &settings);
@@ -79,7 +79,7 @@ private:
base::unique_qptr<Ui::SeparatePanel> _panel;
State _state;
QPointer<Ui::BoxContent> _confirmStopBox;
base::weak_qptr<Ui::BoxContent> _confirmStopBox;
rpl::event_stream<rpl::producer<>> _panelCloseEvents;
bool _stopRequested = false;
rpl::lifetime _lifetime;
@@ -51,8 +51,8 @@ private:
void hideCurrentInstance();
void setInstanceProgress(Instance &instance, float64 progress);
void toggleInstance(Instance &data, bool shown);
void instanceOpacityCallback(QPointer<Ui::FlatLabel> label);
void removeOldInstance(QPointer<Ui::FlatLabel> label);
void instanceOpacityCallback(base::weak_qptr<Ui::FlatLabel> label);
void removeOldInstance(base::weak_qptr<Ui::FlatLabel> label);
void paintInstance(QPainter &p, const Instance &data);
void updateControlsGeometry(int newWidth);
@@ -146,7 +146,7 @@ void ProgressWidget::Row::toggleInstance(Instance &instance, bool shown) {
if (instance.hiding != shown) {
return;
}
const auto label = Ui::MakeWeak(instance.label->entity());
const auto label = base::make_weak(instance.label->entity());
instance.opacity.start(
[=] { instanceOpacityCallback(label); },
shown ? 0. : 1.,
@@ -158,10 +158,10 @@ void ProgressWidget::Row::toggleInstance(Instance &instance, bool shown) {
}
void ProgressWidget::Row::instanceOpacityCallback(
QPointer<Ui::FlatLabel> label) {
base::weak_qptr<Ui::FlatLabel> label) {
update();
const auto i = ranges::find(_old, label, [](const Instance &instance) {
return Ui::MakeWeak(instance.label->entity());
return base::make_weak(instance.label->entity());
});
if (i != end(_old) && i->hiding && !i->opacity.animating()) {
crl::on_main(this, [=] {
@@ -170,9 +170,10 @@ void ProgressWidget::Row::instanceOpacityCallback(
}
}
void ProgressWidget::Row::removeOldInstance(QPointer<Ui::FlatLabel> label) {
void ProgressWidget::Row::removeOldInstance(
base::weak_qptr<Ui::FlatLabel> label) {
const auto i = ranges::find(_old, label, [](const Instance &instance) {
return Ui::MakeWeak(instance.label->entity());
return base::make_weak(instance.label->entity());
});
if (i != end(_old)) {
_old.erase(i);
@@ -320,20 +320,20 @@ void SettingsWidget::addLocationLabel(
}
void SettingsWidget::chooseFormat() {
const auto shared = std::make_shared<QPointer<Ui::GenericBox>>();
const auto shared = std::make_shared<base::weak_qptr<Ui::GenericBox>>();
const auto callback = [=](Format format) {
changeData([&](Settings &data) {
data.format = format;
});
if (const auto weak = shared->data()) {
weak->closeBox();
if (const auto strong = shared->get()) {
strong->closeBox();
}
};
auto box = Box(
ChooseFormatBox,
readData().format,
callback);
*shared = Ui::MakeWeak(box.data());
*shared = base::make_weak(box.data());
_showBoxCallback(std::move(box));
}
@@ -602,18 +602,18 @@ void SettingsWidget::editDateLimit(
? base::unixtime::parse(min).date()
: QDate::currentDate();
const auto month = highlighted;
const auto shared = std::make_shared<QPointer<Ui::CalendarBox>>();
const auto shared = std::make_shared<base::weak_qptr<Ui::CalendarBox>>();
const auto finalize = [=](not_null<Ui::CalendarBox*> box) {
box->addLeftButton(std::move(resetLabel), crl::guard(this, [=] {
done(0);
if (const auto weak = shared->data()) {
if (const auto weak = shared->get()) {
weak->closeBox();
}
}));
};
const auto callback = crl::guard(this, [=](const QDate &date) {
done(base::unixtime::serialize(date.startOfDay()));
if (const auto weak = shared->data()) {
if (const auto weak = shared->get()) {
weak->closeBox();
}
});
@@ -630,7 +630,7 @@ void SettingsWidget::editDateLimit(
? base::unixtime::parse(max).date()
: QDate::currentDate()),
});
*shared = Ui::MakeWeak(box.data());
*shared = base::make_weak(box.data());
_showBoxCallback(std::move(box));
}