Fixed possible crashed on local zoom of charts in stats.

This commit is contained in:
23rd 2025-05-06 23:25:21 +03:00
parent 2a74736761
commit d369d988b0
3 changed files with 11 additions and 5 deletions

View file

@ -1275,9 +1275,13 @@ void ChartWidget::processLocalZoom(int xIndex) {
if (_footer->isHidden()) { if (_footer->isHidden()) {
return; return;
} }
_localZoomLifetime.destroy();
const auto wasZoom = _footer->xPercentageLimits(); const auto wasZoom = _footer->xPercentageLimits();
const auto header = Ui::CreateChild<Header>(this); const auto headerOwned
= _localZoomLifetime.make_state<base::unique_qptr<Header>>(
base::make_unique_q<Header>(this));
const auto header = headerOwned->get();
header->show(); header->show();
_header->geometryValue( _header->geometryValue(
) | rpl::start_with_next([=](const QRect &g) { ) | rpl::start_with_next([=](const QRect &g) {
@ -1290,7 +1294,8 @@ void ChartWidget::processLocalZoom(int xIndex) {
setAttribute(Qt::WA_TransparentForMouseEvents, !value); setAttribute(Qt::WA_TransparentForMouseEvents, !value);
}; };
const auto mouseTrackingLifetime = std::make_shared<rpl::lifetime>(); const auto mouseTrackingLifetime
= _localZoomLifetime.make_state<rpl::lifetime>();
_chartView->setUpdateCallback([=] { _chartArea->update(); }); _chartView->setUpdateCallback([=] { _chartArea->update(); });
const auto createMouseTracking = [=] { const auto createMouseTracking = [=] {
_chartArea->setMouseTracking(true); _chartArea->setMouseTracking(true);
@ -1322,7 +1327,7 @@ void ChartWidget::processLocalZoom(int xIndex) {
zoomOutButton->setTextTransform( zoomOutButton->setTextTransform(
Ui::RoundButton::TextTransform::NoTransform); Ui::RoundButton::TextTransform::NoTransform);
zoomOutButton->setClickedCallback([=] { zoomOutButton->setClickedCallback([=] {
auto lifetime = std::make_shared<rpl::lifetime>(); auto lifetime = _localZoomLifetime.make_state<rpl::lifetime>();
const auto animation = lifetime->make_state<Ui::Animations::Simple>(); const auto animation = lifetime->make_state<Ui::Animations::Simple>();
const auto currentXPercentage = _footer->xPercentageLimits(); const auto currentXPercentage = _footer->xPercentageLimits();
animation->start([=](float64 value) { animation->start([=](float64 value) {
@ -1365,7 +1370,7 @@ void ChartWidget::processLocalZoom(int xIndex) {
}; };
{ {
auto lifetime = std::make_shared<rpl::lifetime>(); auto lifetime = _localZoomLifetime.make_state<rpl::lifetime>();
const auto animation = lifetime->make_state<Ui::Animations::Simple>(); const auto animation = lifetime->make_state<Ui::Animations::Simple>();
_chartView->maybeLocalZoom({ _chartData, Type::Prepare }); _chartView->maybeLocalZoom({ _chartData, Type::Prepare });
animation->start([=](float64 value) { animation->start([=](float64 value) {

View file

@ -175,6 +175,7 @@ private:
rpl::event_stream<float64> _zoomRequests; rpl::event_stream<float64> _zoomRequests;
rpl::lifetime _waitingSizeLifetime; rpl::lifetime _waitingSizeLifetime;
rpl::lifetime _localZoomLifetime;
}; };

@ -1 +1 @@
Subproject commit 0b324ce83c219c817fdd3c94a23b55fec6fec637 Subproject commit 369d8b5172b6f70a3a9b2363cfa0f4fc5f620f56