Rename weak(QObject*) to make_weak(QObject*).

This commit is contained in:
John Preston 2017-11-30 22:04:13 +04:00
parent 2bbf17b672
commit 595af2c6d9
12 changed files with 49 additions and 39 deletions

View file

@ -436,9 +436,9 @@ void GroupInfoBox::createGroup(not_null<PeerListBox*> selectUsersBox, const QStr
}).fail([this, selectUsersBox](const RPCError &error) {
_creationRequestId = 0;
if (error.type() == qstr("NO_CHAT_TITLE")) {
auto guard = weak(this);
auto weak = make_weak(this);
selectUsersBox->closeBox();
if (guard) {
if (weak) {
_title->showError();
}
} else if (error.type() == qstr("USERS_TOO_FEW")) {
@ -471,16 +471,22 @@ void GroupInfoBox::onNext() {
if (_creating != CreatingGroupGroup) {
createChannel(title, description);
} else {
auto initBox = [title, weak = weak(this)](not_null<PeerListBox*> box) {
box->addButton(langFactory(lng_create_group_create), [box, title, weak] {
auto initBox = [title, weak = make_weak(this)](
not_null<PeerListBox*> box) {
auto create = [box, title, weak] {
if (weak) {
auto rows = box->peerListCollectSelectedRows();
if (!rows.empty()) {
weak->createGroup(box, title, rows);
}
}
});
box->addButton(langFactory(lng_cancel), [box] { box->closeBox(); });
};
box->addButton(
langFactory(lng_create_group_create),
std::move(create));
box->addButton(
langFactory(lng_cancel),
[box] { box->closeBox(); });
};
Ui::show(
Box<PeerListBox>(

View file

@ -271,7 +271,11 @@ void ChangePhoneBox::EnterCode::submit() {
hideError();
auto code = _code->getLastText().trimmed();
_requestId = MTP::send(MTPaccount_ChangePhone(MTP_string(_phone), MTP_string(_hash), MTP_string(code)), rpcDone([weak = weak(this)](const MTPUser &result) {
_requestId = MTP::send(MTPaccount_ChangePhone(
MTP_string(_phone),
MTP_string(_hash),
MTP_string(code)
), rpcDone([weak = make_weak(this)](const MTPUser &result) {
App::feedUser(result);
if (weak) {
Ui::hideLayer();

View file

@ -286,9 +286,9 @@ void PhotoCropBox::sendPhoto() {
tosend = cropped.copy();
}
auto guard = weak(this);
auto weak = make_weak(this);
_readyImages.fire(std::move(tosend));
if (guard) {
if (weak) {
closeBox();
}
}

View file

@ -203,11 +203,11 @@ void HistoryTopBarWidget::showMenu() {
return;
}
_menu.create(parentWidget());
_menu->setHiddenCallback([that = weak(this), menu = _menu.data()] {
_menu->setHiddenCallback([weak = make_weak(this), menu = _menu.data()] {
menu->deleteLater();
if (that && that->_menu == menu) {
that->_menu = nullptr;
that->_menuToggle->setForceRippled(false);
if (weak && weak->_menu == menu) {
weak->_menu = nullptr;
weak->_menuToggle->setForceRippled(false);
}
});
_menu->setShowStartCallback(base::lambda_guarded(this, [this, menu = _menu.data()] {

View file

@ -58,10 +58,10 @@ void TopBar::registerUpdateControlCallback(
QObject *guard,
Callback &&callback) {
_updateControlCallbacks[guard] =[
object = weak(guard),
weak = make_weak(guard),
callback = std::forward<Callback>(callback)
](anim::type animated) {
if (!object) {
if (!weak) {
return false;
}
callback(animated);
@ -505,11 +505,11 @@ void TopBar::performForward() {
_cancelSelectionClicks.fire({});
return;
}
auto callback = [items = std::move(items), that = weak(this)](
auto callback = [items = std::move(items), weak = make_weak(this)](
not_null<PeerData*> peer) {
App::main()->setForwardDraft(peer->id, items);
if (that) {
that->_cancelSelectionClicks.fire({});
if (weak) {
weak->_cancelSelectionClicks.fire({});
}
};
Ui::show(Box<PeerListBox>(

View file

@ -838,9 +838,9 @@ object_ptr<Ui::RpWidget> WrapWidget::createTopBarSurrogate(
Assert(_topBar != nullptr);
auto result = object_ptr<Ui::AbstractButton>(parent);
result->addClickHandler([wrap = weak(this)]{
if (wrap) {
wrap->showBackFromStack();
result->addClickHandler([weak = make_weak(this)]{
if (weak) {
weak->showBackFromStack();
}
});
result->setGeometry(_topBar->geometry());

View file

@ -1379,12 +1379,12 @@ void ListWidget::forwardItems(SelectedItemSet items) {
if (items.empty()) {
return;
}
auto that = weak(this);
auto weak = make_weak(this);
auto controller = std::make_unique<ChooseRecipientBoxController>(
[that, items = std::move(items)](not_null<PeerData*> peer) {
[weak, items = std::move(items)](not_null<PeerData*> peer) {
App::main()->setForwardDraft(peer->id, items);
if (that) {
that->clearSelected();
if (weak) {
weak->clearSelected();
}
});
Ui::show(Box<PeerListBox>(

View file

@ -1001,15 +1001,15 @@ void Messenger::registerLeaveSubscription(QWidget *widget) {
#ifdef Q_OS_MAC
if (auto topLevel = widget->window()) {
if (topLevel == _window.get()) {
auto guarded = weak(widget);
auto weak = make_weak(widget);
auto subscription = _window->leaveEvents()
| rpl::start_with_next([guarded] {
if (auto w = guarded.data()) {
| rpl::start_with_next([weak] {
if (const auto window = weak.data()) {
QEvent ev(QEvent::Leave);
QGuiApplication::sendEvent(w, &ev);
QGuiApplication::sendEvent(window, &ev);
}
});
_leaveSubscriptions.emplace_back(guarded, std::move(subscription));
_leaveSubscriptions.emplace_back(weak, std::move(subscription));
}
}
#endif // Q_OS_MAC

View file

@ -48,7 +48,7 @@ public:
return fire_forward(value);
}
auto events() const {
return make_producer<Value>([weak = weak()](
return make_producer<Value>([weak = make_weak()](
const auto &consumer) {
if (auto strong = weak.lock()) {
auto result = [weak, consumer] {
@ -82,7 +82,7 @@ private:
std::vector<consumer<Value, no_error>> consumers;
int depth = 0;
};
std::weak_ptr<Data> weak() const;
std::weak_ptr<Data> make_weak() const;
mutable std::shared_ptr<Data> _data;
@ -153,7 +153,7 @@ inline void event_stream<Value>::fire_forward(
}
template <typename Value>
inline auto event_stream<Value>::weak() const
inline auto event_stream<Value>::make_weak() const
-> std::weak_ptr<Data> {
if (!_data) {
_data = std::make_shared<Data>();

View file

@ -84,13 +84,13 @@ void AbstractButton::mouseReleaseEvent(QMouseEvent *e) {
onStateChanged(was, StateChangeSource::ByPress);
if (was & StateFlag::Over) {
_modifiers = e->modifiers();
auto test = weak(this);
auto weak = make_weak(this);
if (_clickedCallback) {
_clickedCallback();
} else {
emit clicked();
}
if (test) {
if (weak) {
_clicks.fire({});
}
} else {

View file

@ -435,12 +435,12 @@ protected:
};
template <typename Widget>
QPointer<Widget> weak(Widget *object) {
QPointer<Widget> make_weak(Widget *object) {
return QPointer<Widget>(object);
}
template <typename Widget>
QPointer<const Widget> weak(const Widget *object) {
QPointer<const Widget> make_weak(const Widget *object) {
return QPointer<const Widget>(object);
}

View file

@ -39,9 +39,9 @@ void SectionWidget::setGeometryWithTopMoved(
_topDelta = topDelta;
bool willBeResized = (size() != newGeometry.size());
if (geometry() != newGeometry) {
auto that = weak(this);
auto weak = make_weak(this);
setGeometry(newGeometry);
if (!that) {
if (!weak) {
return;
}
}