mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-18 15:17:07 +02:00
Remove for_const macro.
This commit is contained in:
parent
2a2607d026
commit
23e9e7b9f0
20 changed files with 179 additions and 139 deletions
Telegram/SourceFiles
|
@ -1510,7 +1510,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|
|||
return;
|
||||
}
|
||||
auto possiblyReadMentions = base::flat_set<MsgId>();
|
||||
for_const (auto &msgId, d.vmessages().v) {
|
||||
for (const auto &msgId : d.vmessages().v) {
|
||||
if (auto item = session().data().message(channel, msgId.v)) {
|
||||
if (item->isUnreadMedia() || item->isUnreadMention()) {
|
||||
item->markMediaRead();
|
||||
|
|
|
@ -500,74 +500,98 @@ void ApiWrap::sendMessageFail(
|
|||
}
|
||||
}
|
||||
|
||||
void ApiWrap::requestMessageData(ChannelData *channel, MsgId msgId, RequestMessageDataCallback callback) {
|
||||
auto &req = (channel ? _channelMessageDataRequests[channel][msgId] : _messageDataRequests[msgId]);
|
||||
void ApiWrap::requestMessageData(
|
||||
ChannelData *channel,
|
||||
MsgId msgId,
|
||||
RequestMessageDataCallback callback) {
|
||||
auto &requests = channel
|
||||
? _channelMessageDataRequests[channel][msgId]
|
||||
: _messageDataRequests[msgId];
|
||||
if (callback) {
|
||||
req.callbacks.append(callback);
|
||||
requests.callbacks.push_back(callback);
|
||||
}
|
||||
if (!requests.requestId) {
|
||||
_messageDataResolveDelayed.call();
|
||||
}
|
||||
if (!req.requestId) _messageDataResolveDelayed.call();
|
||||
}
|
||||
|
||||
QVector<MTPInputMessage> ApiWrap::collectMessageIds(const MessageDataRequests &requests) {
|
||||
QVector<MTPInputMessage> ApiWrap::collectMessageIds(
|
||||
const MessageDataRequests &requests) {
|
||||
auto result = QVector<MTPInputMessage>();
|
||||
result.reserve(requests.size());
|
||||
for (auto i = requests.cbegin(), e = requests.cend(); i != e; ++i) {
|
||||
if (i.value().requestId > 0) continue;
|
||||
result.push_back(MTP_inputMessageID(MTP_int(i.key())));
|
||||
for (const auto &[msgId, request] : requests) {
|
||||
if (request.requestId > 0) {
|
||||
continue;
|
||||
}
|
||||
result.push_back(MTP_inputMessageID(MTP_int(msgId)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ApiWrap::MessageDataRequests *ApiWrap::messageDataRequests(ChannelData *channel, bool onlyExisting) {
|
||||
auto ApiWrap::messageDataRequests(ChannelData *channel, bool onlyExisting)
|
||||
-> MessageDataRequests* {
|
||||
if (channel) {
|
||||
auto i = _channelMessageDataRequests.find(channel);
|
||||
if (i == _channelMessageDataRequests.cend()) {
|
||||
if (i == end(_channelMessageDataRequests)) {
|
||||
if (onlyExisting) {
|
||||
return nullptr;
|
||||
}
|
||||
i = _channelMessageDataRequests.insert(channel, MessageDataRequests());
|
||||
i = _channelMessageDataRequests.emplace(
|
||||
channel,
|
||||
MessageDataRequests()).first;
|
||||
}
|
||||
return &i.value();
|
||||
return &i->second;
|
||||
}
|
||||
return &_messageDataRequests;
|
||||
}
|
||||
|
||||
void ApiWrap::resolveMessageDatas() {
|
||||
if (_messageDataRequests.isEmpty() && _channelMessageDataRequests.isEmpty()) return;
|
||||
if (_messageDataRequests.empty() && _channelMessageDataRequests.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto ids = collectMessageIds(_messageDataRequests);
|
||||
const auto ids = collectMessageIds(_messageDataRequests);
|
||||
if (!ids.isEmpty()) {
|
||||
auto requestId = request(MTPmessages_GetMessages(
|
||||
const auto requestId = request(MTPmessages_GetMessages(
|
||||
MTP_vector<MTPInputMessage>(ids)
|
||||
)).done([this](const MTPmessages_Messages &result, mtpRequestId requestId) {
|
||||
)).done([=](
|
||||
const MTPmessages_Messages &result,
|
||||
mtpRequestId requestId) {
|
||||
gotMessageDatas(nullptr, result, requestId);
|
||||
}).fail([this](const MTP::Error &error, mtpRequestId requestId) {
|
||||
}).fail([=](const MTP::Error &error, mtpRequestId requestId) {
|
||||
finalizeMessageDataRequest(nullptr, requestId);
|
||||
}).afterDelay(kSmallDelayMs).send();
|
||||
for (auto &request : _messageDataRequests) {
|
||||
if (request.requestId > 0) continue;
|
||||
|
||||
for (auto &[msgId, request] : _messageDataRequests) {
|
||||
if (request.requestId > 0) {
|
||||
continue;
|
||||
}
|
||||
request.requestId = requestId;
|
||||
}
|
||||
}
|
||||
for (auto j = _channelMessageDataRequests.begin(); j != _channelMessageDataRequests.cend();) {
|
||||
if (j->isEmpty()) {
|
||||
if (j->second.empty()) {
|
||||
j = _channelMessageDataRequests.erase(j);
|
||||
continue;
|
||||
}
|
||||
auto ids = collectMessageIds(j.value());
|
||||
const auto ids = collectMessageIds(j->second);
|
||||
if (!ids.isEmpty()) {
|
||||
auto channel = j.key();
|
||||
auto requestId = request(MTPchannels_GetMessages(
|
||||
j.key()->inputChannel,
|
||||
const auto channel = j->first;
|
||||
const auto requestId = request(MTPchannels_GetMessages(
|
||||
channel->inputChannel,
|
||||
MTP_vector<MTPInputMessage>(ids)
|
||||
)).done([=](const MTPmessages_Messages &result, mtpRequestId requestId) {
|
||||
)).done([=](
|
||||
const MTPmessages_Messages &result,
|
||||
mtpRequestId requestId) {
|
||||
gotMessageDatas(channel, result, requestId);
|
||||
}).fail([=](const MTP::Error &error, mtpRequestId requestId) {
|
||||
finalizeMessageDataRequest(channel, requestId);
|
||||
}).afterDelay(kSmallDelayMs).send();
|
||||
|
||||
for (auto &request : *j) {
|
||||
if (request.requestId > 0) continue;
|
||||
for (auto &[msgId, request] : j->second) {
|
||||
if (request.requestId > 0) {
|
||||
continue;
|
||||
}
|
||||
request.requestId = requestId;
|
||||
}
|
||||
}
|
||||
|
@ -612,16 +636,16 @@ void ApiWrap::finalizeMessageDataRequest(
|
|||
auto requests = messageDataRequests(channel, true);
|
||||
if (requests) {
|
||||
for (auto i = requests->begin(); i != requests->cend();) {
|
||||
if (i.value().requestId == requestId) {
|
||||
for_const (auto &callback, i.value().callbacks) {
|
||||
callback(channel, i.key());
|
||||
if (i->second.requestId == requestId) {
|
||||
for (const auto &callback : i->second.callbacks) {
|
||||
callback(channel, i->first);
|
||||
}
|
||||
i = requests->erase(i);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
if (channel && requests->isEmpty()) {
|
||||
if (channel && requests->empty()) {
|
||||
_channelMessageDataRequests.remove(channel);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -416,11 +416,12 @@ public:
|
|||
|
||||
private:
|
||||
struct MessageDataRequest {
|
||||
using Callbacks = QList<RequestMessageDataCallback>;
|
||||
using Callbacks = std::vector<RequestMessageDataCallback>;
|
||||
|
||||
mtpRequestId requestId = 0;
|
||||
Callbacks callbacks;
|
||||
};
|
||||
using MessageDataRequests = QMap<MsgId, MessageDataRequest>;
|
||||
using MessageDataRequests = base::flat_map<MsgId, MessageDataRequest>;
|
||||
using SharedMediaType = Storage::SharedMediaType;
|
||||
|
||||
struct StickersByEmoji {
|
||||
|
@ -460,8 +461,11 @@ private:
|
|||
ChannelData *channel,
|
||||
mtpRequestId requestId);
|
||||
|
||||
QVector<MTPInputMessage> collectMessageIds(const MessageDataRequests &requests);
|
||||
MessageDataRequests *messageDataRequests(ChannelData *channel, bool onlyExisting = false);
|
||||
[[nodiscard]] QVector<MTPInputMessage> collectMessageIds(
|
||||
const MessageDataRequests &requests);
|
||||
[[nodiscard]] MessageDataRequests *messageDataRequests(
|
||||
ChannelData *channel,
|
||||
bool onlyExisting = false);
|
||||
|
||||
void gotChatFull(
|
||||
not_null<PeerData*> peer,
|
||||
|
@ -580,7 +584,9 @@ private:
|
|||
base::flat_map<QString, int> _modifyRequests;
|
||||
|
||||
MessageDataRequests _messageDataRequests;
|
||||
QMap<ChannelData*, MessageDataRequests> _channelMessageDataRequests;
|
||||
base::flat_map<
|
||||
ChannelData*,
|
||||
MessageDataRequests> _channelMessageDataRequests;
|
||||
SingleQueuedInvokation _messageDataResolveDelayed;
|
||||
|
||||
using PeerRequests = QMap<PeerData*, mtpRequestId>;
|
||||
|
|
|
@ -1452,7 +1452,7 @@ void RevokePublicLinkBox::Inner::mouseReleaseEvent(QMouseEvent *e) {
|
|||
void RevokePublicLinkBox::Inner::paintEvent(QPaintEvent *e) {
|
||||
Painter p(this);
|
||||
p.translate(0, _rowsTop);
|
||||
for_const (auto &row, _rows) {
|
||||
for (const auto &row : _rows) {
|
||||
paintChat(p, row, (row.peer == _selected));
|
||||
p.translate(0, _rowHeight);
|
||||
}
|
||||
|
|
|
@ -470,7 +470,7 @@ void StickersBox::getArchivedDone(
|
|||
|
||||
auto addedSet = false;
|
||||
auto changedSets = false;
|
||||
for_const (const auto &stickerSet, stickers.vsets().v) {
|
||||
for (const auto &stickerSet : stickers.vsets().v) {
|
||||
const MTPDstickerSet *setData = nullptr;
|
||||
switch (stickerSet.type()) {
|
||||
case mtpc_stickerSetCovered: {
|
||||
|
@ -2291,7 +2291,7 @@ int StickersBox::Inner::getRowIndex(uint64 setId) const {
|
|||
}
|
||||
|
||||
void StickersBox::Inner::setFullOrder(const StickersSetsOrder &order) {
|
||||
for_const (auto setId, order) {
|
||||
for (const auto setId : order) {
|
||||
auto index = getRowIndex(setId);
|
||||
if (index >= 0) {
|
||||
auto row = std::move(_rows[index]);
|
||||
|
|
|
@ -379,9 +379,12 @@ void FieldAutocomplete::updateFiltered(bool resetScroll) {
|
|||
|
||||
bool listAllSuggestions = _filter.isEmpty();
|
||||
if (_addInlineBots) {
|
||||
for_const (auto user, cRecentInlineBots()) {
|
||||
if (user->isInaccessible()) continue;
|
||||
if (!listAllSuggestions && filterNotPassedByUsername(user)) continue;
|
||||
for (const auto user : cRecentInlineBots()) {
|
||||
if (user->isInaccessible()
|
||||
|| (!listAllSuggestions
|
||||
&& filterNotPassedByUsername(user))) {
|
||||
continue;
|
||||
}
|
||||
mrows.push_back({ user });
|
||||
++recentInlineBots;
|
||||
}
|
||||
|
|
|
@ -32,12 +32,6 @@ inline bool in_range(Value &&value, From &&from, Till &&till) {
|
|||
|
||||
} // namespace base
|
||||
|
||||
// using for_const instead of plain range-based for loop to ensure usage of const_iterator
|
||||
// it is important for the copy-on-write Qt containers
|
||||
// if you have "QVector<T*> v" then "for (T * const p : v)" will still call QVector::detach(),
|
||||
// while "for_const (T *p, v)" won't and "for_const (T *&p, v)" won't compile
|
||||
#define for_const(range_declaration, range_expression) for (range_declaration : std::as_const(range_expression))
|
||||
|
||||
static const int32 ScrollMax = INT_MAX;
|
||||
|
||||
extern uint64 _SharedMemoryLocation[];
|
||||
|
|
|
@ -126,7 +126,7 @@ private:
|
|||
using HistoryDrafts = base::flat_map<DraftKey, std::unique_ptr<Draft>>;
|
||||
|
||||
inline bool draftStringIsEmpty(const QString &text) {
|
||||
for_const (auto ch, text) {
|
||||
for (const auto ch : text) {
|
||||
if (!ch.isSpace()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -182,10 +182,12 @@ private:
|
|||
not_null<ChannelData*> _channel;
|
||||
|
||||
QPointer<Ui::Checkbox> _allFlags;
|
||||
QMap<MTPDchannelAdminLogEventsFilter::Flags, QPointer<Ui::Checkbox>> _filterFlags;
|
||||
base::flat_map<
|
||||
MTPDchannelAdminLogEventsFilter::Flags,
|
||||
QPointer<Ui::Checkbox>> _filterFlags;
|
||||
|
||||
QPointer<Ui::Checkbox> _allUsers;
|
||||
QMap<not_null<UserData*>, QPointer<UserCheckbox>> _admins;
|
||||
base::flat_map<not_null<UserData*>, QPointer<UserCheckbox>> _admins;
|
||||
bool _restoringInvariant = false;
|
||||
|
||||
struct Row {
|
||||
|
@ -224,7 +226,7 @@ void FilterBox::Inner::createAllActionsCheckbox(const FilterValue &filter) {
|
|||
) | rpl::start_with_next([=](bool checked) {
|
||||
if (!std::exchange(_restoringInvariant, true)) {
|
||||
auto allChecked = _allFlags->checked();
|
||||
for_const (auto &&checkbox, _filterFlags) {
|
||||
for (const auto &[flag, checkbox] : _filterFlags) {
|
||||
checkbox->setChecked(allChecked);
|
||||
}
|
||||
_restoringInvariant = false;
|
||||
|
@ -241,12 +243,12 @@ void FilterBox::Inner::createActionsCheckboxes(const FilterValue &filter) {
|
|||
auto addFlag = [this, &filter](Flags flag, QString &&text) {
|
||||
auto checked = (filter.flags == 0) || (filter.flags & flag);
|
||||
auto checkbox = addRow(object_ptr<Ui::Checkbox>(this, std::move(text), checked, st::defaultBoxCheckbox), st::adminLogFilterLittleSkip);
|
||||
_filterFlags.insert(flag, checkbox);
|
||||
_filterFlags[flag] = checkbox;
|
||||
checkbox->checkedChanges(
|
||||
) | rpl::start_with_next([=](bool checked) {
|
||||
if (!std::exchange(_restoringInvariant, true)) {
|
||||
auto allChecked = true;
|
||||
for_const (auto &&checkbox, _filterFlags) {
|
||||
for (const auto &[flag, checkbox] : _filterFlags) {
|
||||
if (!checkbox->checked()) {
|
||||
allChecked = false;
|
||||
break;
|
||||
|
@ -285,7 +287,7 @@ void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) {
|
|||
) | rpl::start_with_next([=](bool checked) {
|
||||
if (!std::exchange(_restoringInvariant, true)) {
|
||||
auto allChecked = _allUsers->checked();
|
||||
for_const (auto &&checkbox, _admins) {
|
||||
for (const auto &[user, checkbox] : _admins) {
|
||||
checkbox->setChecked(allChecked);
|
||||
}
|
||||
_restoringInvariant = false;
|
||||
|
@ -297,14 +299,16 @@ void FilterBox::Inner::createAllUsersCheckbox(const FilterValue &filter) {
|
|||
}
|
||||
|
||||
void FilterBox::Inner::createAdminsCheckboxes(const std::vector<not_null<UserData*>> &admins, const FilterValue &filter) {
|
||||
for (auto user : admins) {
|
||||
auto checked = filter.allUsers || base::contains(filter.admins, user);
|
||||
auto checkbox = addRow(object_ptr<UserCheckbox>(this, user, checked), st::adminLogFilterLittleSkip);
|
||||
for (const auto user : admins) {
|
||||
const auto checked = filter.allUsers || base::contains(filter.admins, user);
|
||||
const auto checkbox = addRow(
|
||||
object_ptr<UserCheckbox>(this, user, checked),
|
||||
st::adminLogFilterLittleSkip);
|
||||
checkbox->checkedChanges(
|
||||
) | rpl::start_with_next([=](bool checked) {
|
||||
if (!std::exchange(_restoringInvariant, true)) {
|
||||
auto allChecked = true;
|
||||
for_const (auto &&checkbox, _admins) {
|
||||
for (const auto &[user, checkbox] : _admins) {
|
||||
if (!checkbox->checked()) {
|
||||
allChecked = false;
|
||||
break;
|
||||
|
@ -319,13 +323,13 @@ void FilterBox::Inner::createAdminsCheckboxes(const std::vector<not_null<UserDat
|
|||
}
|
||||
}
|
||||
}, checkbox->lifetime());
|
||||
_admins.insert(user, checkbox);
|
||||
_admins[user] = checkbox;
|
||||
}
|
||||
}
|
||||
|
||||
bool FilterBox::Inner::canSave() const {
|
||||
for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) {
|
||||
if (i.value()->checked()) {
|
||||
for (const auto &[flag, checkbox] : _filterFlags) {
|
||||
if (checkbox->checked()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -335,9 +339,9 @@ bool FilterBox::Inner::canSave() const {
|
|||
FilterValue FilterBox::Inner::filter() const {
|
||||
auto result = FilterValue();
|
||||
auto allChecked = true;
|
||||
for (auto i = _filterFlags.cbegin(), e = _filterFlags.cend(); i != e; ++i) {
|
||||
if (i.value()->checked()) {
|
||||
result.flags |= i.key();
|
||||
for (const auto &[flag, checkbox] : _filterFlags) {
|
||||
if (checkbox->checked()) {
|
||||
result.flags |= flag;
|
||||
} else {
|
||||
allChecked = false;
|
||||
}
|
||||
|
@ -348,9 +352,9 @@ FilterValue FilterBox::Inner::filter() const {
|
|||
result.allUsers = _allUsers->checked();
|
||||
if (!result.allUsers) {
|
||||
result.admins.reserve(_admins.size());
|
||||
for (auto i = _admins.cbegin(), e = _admins.cend(); i != e; ++i) {
|
||||
if (i.value()->checked()) {
|
||||
result.admins.push_back(i.key());
|
||||
for (const auto &[user, checkbox] : _admins) {
|
||||
if (checkbox->checked()) {
|
||||
result.admins.push_back(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -549,7 +549,7 @@ void ReplyKeyboard::resize(int width, int height) {
|
|||
int widthForText = widthForButtons;
|
||||
int widthOfText = 0;
|
||||
int maxMinButtonWidth = 0;
|
||||
for_const (auto &button, row) {
|
||||
for (const auto &button : row) {
|
||||
widthOfText += qMax(button.text.maxWidth(), 1);
|
||||
int minButtonWidth = _st->minButtonWidth(button.type);
|
||||
widthForText -= minButtonWidth;
|
||||
|
@ -559,7 +559,7 @@ void ReplyKeyboard::resize(int width, int height) {
|
|||
bool enough = (widthForButtons - s * maxMinButtonWidth) >= widthOfText;
|
||||
|
||||
float64 x = 0;
|
||||
for (Button &button : row) {
|
||||
for (auto &button : row) {
|
||||
int buttonw = qMax(button.text.maxWidth(), 1);
|
||||
float64 textw = buttonw, minw = _st->minButtonWidth(button.type);
|
||||
float64 w = textw;
|
||||
|
@ -587,10 +587,10 @@ void ReplyKeyboard::resize(int width, int height) {
|
|||
}
|
||||
|
||||
bool ReplyKeyboard::isEnoughSpace(int width, const style::BotKeyboardButton &st) const {
|
||||
for_const (auto &row, _rows) {
|
||||
for (const auto &row : _rows) {
|
||||
int s = row.size();
|
||||
int widthLeft = width - ((s - 1) * st.margin + s * 2 * st.padding);
|
||||
for_const (auto &button, row) {
|
||||
for (const auto &button : row) {
|
||||
widthLeft -= qMax(button.text.maxWidth(), 1);
|
||||
if (widthLeft < 0) {
|
||||
if (row.size() > 3) {
|
||||
|
@ -662,8 +662,8 @@ void ReplyKeyboard::paint(
|
|||
ClickHandlerPtr ReplyKeyboard::getLink(QPoint point) const {
|
||||
Assert(_width > 0);
|
||||
|
||||
for_const (auto &row, _rows) {
|
||||
for_const (auto &button, row) {
|
||||
for (const auto &row : _rows) {
|
||||
for (const auto &button : row) {
|
||||
QRect rect(button.rect);
|
||||
|
||||
// just ignore the buttons that didn't layout well
|
||||
|
|
|
@ -951,7 +951,7 @@ void HistoryService::setServiceText(const PreparedText &prepared) {
|
|||
prepared.text,
|
||||
Ui::ItemTextServiceOptions());
|
||||
auto linkIndex = 0;
|
||||
for_const (auto &link, prepared.links) {
|
||||
for (const auto &link : prepared.links) {
|
||||
// Link indices start with 1.
|
||||
_text.setLink(++linkIndex, link);
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ void GroupMembersWidget::sortMembers() {
|
|||
void GroupMembersWidget::updateOnlineCount() {
|
||||
bool onlyMe = true;
|
||||
int newOnlineCount = 0;
|
||||
for_const (auto item, items()) {
|
||||
for (const auto item : items()) {
|
||||
auto member = getMember(item);
|
||||
auto user = member->user();
|
||||
auto isOnline = !user->isBot() && Data::OnlineTextActive(member->onlineTill, _now);
|
||||
|
@ -433,7 +433,7 @@ void GroupMembersWidget::updateOnlineDisplay() {
|
|||
_now = base::unixtime::now();
|
||||
|
||||
bool changed = false;
|
||||
for_const (auto item, items()) {
|
||||
for (const auto item : items()) {
|
||||
if (!item->statusHasOnlineColor) {
|
||||
if (!item->peer->isSelf()) {
|
||||
continue;
|
||||
|
|
|
@ -63,8 +63,9 @@ void PeerListWidget::paintContents(Painter &p) {
|
|||
auto left = getListLeft();
|
||||
auto top = getListTop();
|
||||
|
||||
auto from = floorclamp(_visibleTop - top, _st.height, 0, _items.size());
|
||||
auto to = ceilclamp(_visibleBottom - top, _st.height, 0, _items.size());
|
||||
const auto count = int(_items.size());
|
||||
auto from = floorclamp(_visibleTop - top, _st.height, 0, count);
|
||||
auto to = ceilclamp(_visibleBottom - top, _st.height, 0, count);
|
||||
for (auto i = from; i < to; ++i) {
|
||||
auto y = top + i * _st.height;
|
||||
auto selected = (_pressed >= 0) ? (i == _pressed) : (i == _selected);
|
||||
|
@ -147,7 +148,7 @@ void PeerListWidget::mousePressEvent(QMouseEvent *e) {
|
|||
_pressed = _selected;
|
||||
_pressedRemove = _selectedRemove;
|
||||
if (_pressed >= 0 && !_pressedRemove) {
|
||||
auto item = _items[_pressed];
|
||||
const auto item = _items[_pressed];
|
||||
if (!item->ripple) {
|
||||
auto memberRowWidth = rowWidth();
|
||||
auto mask = Ui::RippleAnimation::rectMask(QSize(memberRowWidth, _st.height));
|
||||
|
@ -170,7 +171,7 @@ void PeerListWidget::mousePressReleased(Qt::MouseButton button) {
|
|||
auto pressed = std::exchange(_pressed, -1);
|
||||
auto pressedRemove = base::take(_pressedRemove);
|
||||
if (pressed >= 0 && pressed < _items.size()) {
|
||||
if (auto &ripple = _items[pressed]->ripple) {
|
||||
if (const auto &ripple = _items[pressed]->ripple) {
|
||||
ripple->lastStop();
|
||||
}
|
||||
if (pressed == _selected && pressedRemove == _selectedRemove && button == Qt::LeftButton) {
|
||||
|
@ -274,7 +275,7 @@ void PeerListWidget::preloadPhotos() {
|
|||
}
|
||||
|
||||
void PeerListWidget::refreshVisibility() {
|
||||
setVisible(!_items.isEmpty());
|
||||
setVisible(!_items.empty());
|
||||
}
|
||||
|
||||
} // namespace Profile
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
|
||||
int getListLeft() const;
|
||||
|
||||
const QList<Item*> &items() const {
|
||||
const std::vector<Item*> &items() const {
|
||||
return _items;
|
||||
}
|
||||
int itemsCount() const {
|
||||
|
@ -129,7 +129,7 @@ private:
|
|||
Fn<void(PeerData*)> _removedCallback;
|
||||
Fn<void(Item*)> _updateItemCallback;
|
||||
|
||||
QList<Item*> _items;
|
||||
std::vector<Item*> _items;
|
||||
|
||||
int _visibleTop = 0;
|
||||
int _visibleBottom = 0;
|
||||
|
|
|
@ -98,7 +98,7 @@ private:
|
|||
|
||||
int _oldCount;
|
||||
|
||||
QVector<SampleWidget*> _cornerSamples[4];
|
||||
std::vector<SampleWidget*> _cornerSamples[4];
|
||||
|
||||
};
|
||||
|
||||
|
@ -350,7 +350,8 @@ void NotificationsCount::setOverCorner(ScreenCorner corner) {
|
|||
if (corner == _overCorner) {
|
||||
return;
|
||||
}
|
||||
for_const (auto widget, _cornerSamples[static_cast<int>(_overCorner)]) {
|
||||
const auto index = static_cast<int>(_overCorner);
|
||||
for (const auto widget : _cornerSamples[index]) {
|
||||
widget->hideFast();
|
||||
}
|
||||
} else {
|
||||
|
@ -362,7 +363,7 @@ void NotificationsCount::setOverCorner(ScreenCorner corner) {
|
|||
_overCorner = corner;
|
||||
|
||||
auto &samples = _cornerSamples[static_cast<int>(_overCorner)];
|
||||
auto samplesAlready = samples.size();
|
||||
auto samplesAlready = int(samples.size());
|
||||
auto samplesNeeded = _oldCount;
|
||||
auto samplesLeave = qMin(samplesAlready, samplesNeeded);
|
||||
for (int i = 0; i != samplesLeave; ++i) {
|
||||
|
@ -394,8 +395,8 @@ void NotificationsCount::clearOverCorner() {
|
|||
Core::App().notifications().notifySettingsChanged(
|
||||
ChangeType::DemoIsHidden);
|
||||
|
||||
for_const (const auto &samples, _cornerSamples) {
|
||||
for_const (const auto widget, samples) {
|
||||
for (const auto &samples : _cornerSamples) {
|
||||
for (const auto widget : samples) {
|
||||
widget->hideFast();
|
||||
}
|
||||
}
|
||||
|
@ -426,8 +427,8 @@ void NotificationsCount::mouseReleaseEvent(QMouseEvent *e) {
|
|||
}
|
||||
|
||||
NotificationsCount::~NotificationsCount() {
|
||||
for_const (auto &samples, _cornerSamples) {
|
||||
for_const (auto widget, samples) {
|
||||
for (const auto &samples : _cornerSamples) {
|
||||
for (const auto widget : samples) {
|
||||
widget->detach();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2258,7 +2258,7 @@ void Account::readInstalledMasks() {
|
|||
}
|
||||
|
||||
void Account::writeSavedGifs() {
|
||||
auto &saved = _owner->session().data().stickers().savedGifs();
|
||||
const auto &saved = _owner->session().data().stickers().savedGifs();
|
||||
if (saved.isEmpty()) {
|
||||
if (_savedGifsKey) {
|
||||
ClearKey(_savedGifsKey, _basePath);
|
||||
|
@ -2267,7 +2267,7 @@ void Account::writeSavedGifs() {
|
|||
}
|
||||
} else {
|
||||
quint32 size = sizeof(quint32); // count
|
||||
for_const (auto gif, saved) {
|
||||
for (const auto gif : saved) {
|
||||
size += Serialize::Document::sizeInStream(gif);
|
||||
}
|
||||
|
||||
|
@ -2277,7 +2277,7 @@ void Account::writeSavedGifs() {
|
|||
}
|
||||
EncryptedDescriptor data(size);
|
||||
data.stream << quint32(saved.size());
|
||||
for_const (auto gif, saved) {
|
||||
for (const auto gif : saved) {
|
||||
Serialize::Document::writeToStream(data.stream, gif);
|
||||
}
|
||||
FileWriteDescriptor file(_savedGifsKey, _basePath);
|
||||
|
|
|
@ -188,7 +188,7 @@ QRect MultiSelect::Item::paintArea(int outerWidth) const {
|
|||
return rect();
|
||||
}
|
||||
auto yMin = 0, yMax = 0;
|
||||
for_const (auto ©, _copies) {
|
||||
for (const auto © : _copies) {
|
||||
accumulate_max(yMax, copy.y);
|
||||
if (yMin) {
|
||||
accumulate_min(yMin, copy.y);
|
||||
|
@ -671,7 +671,7 @@ void MultiSelect::Inner::computeItemsGeometry(int newWidth) {
|
|||
auto itemTop = 0;
|
||||
auto widthLeft = newWidth;
|
||||
auto maxVisiblePadding = qMax(_st.padding.left(), _st.padding.right());
|
||||
for_const (auto &item, _items) {
|
||||
for (const auto &item : _items) {
|
||||
auto itemWidth = item->getWidth();
|
||||
Assert(itemWidth <= newWidth);
|
||||
if (itemWidth > widthLeft) {
|
||||
|
@ -721,7 +721,7 @@ void MultiSelect::Inner::finishHeightAnimation() {
|
|||
}
|
||||
|
||||
void MultiSelect::Inner::setItemText(uint64 itemId, const QString &text) {
|
||||
for_const (auto &item, _items) {
|
||||
for (const auto &item : _items) {
|
||||
if (item->id() == itemId) {
|
||||
item->setText(text);
|
||||
updateItemsGeometry();
|
||||
|
@ -783,7 +783,7 @@ int MultiSelect::Inner::getItemsCount() const {
|
|||
QVector<uint64> MultiSelect::Inner::getItems() const {
|
||||
auto result = QVector<uint64>();
|
||||
result.reserve(_items.size());
|
||||
for_const (auto &item, _items) {
|
||||
for (const auto &item : _items) {
|
||||
result.push_back(item->id());
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -98,7 +98,7 @@ QPixmap Manager::hiddenUserpicPlaceholder() const {
|
|||
}
|
||||
|
||||
bool Manager::hasReplyingNotification() const {
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
if (notification->isReplying()) {
|
||||
return true;
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ void Manager::settingsChanged(ChangeType change) {
|
|||
if (change == ChangeType::Corner) {
|
||||
auto startPosition = notificationStartPosition();
|
||||
auto shiftDirection = notificationShiftDirection();
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
notification->updatePosition(startPosition, shiftDirection);
|
||||
}
|
||||
if (_hideAll) {
|
||||
|
@ -142,7 +142,7 @@ void Manager::settingsChanged(ChangeType change) {
|
|||
}
|
||||
|
||||
void Manager::demoMasterOpacityCallback() {
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
notification->updateOpacity();
|
||||
}
|
||||
if (_hideAll) {
|
||||
|
@ -173,7 +173,7 @@ void Manager::checkLastInput() {
|
|||
void Manager::startAllHiding() {
|
||||
if (!hasReplyingNotification()) {
|
||||
int notHidingCount = 0;
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
if (notification->isShowing()) {
|
||||
++notHidingCount;
|
||||
} else {
|
||||
|
@ -188,7 +188,7 @@ void Manager::startAllHiding() {
|
|||
}
|
||||
|
||||
void Manager::stopAllHiding() {
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
notification->stopHiding();
|
||||
}
|
||||
if (_hideAll) {
|
||||
|
@ -400,7 +400,7 @@ void Manager::doClearFromItem(not_null<HistoryItem*> item) {
|
|||
}), _queuedNotifications.cend());
|
||||
|
||||
auto showNext = false;
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
if (notification->unlinkItem(item)) {
|
||||
showNext = true;
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ bool Manager::doSkipFlashBounce() const {
|
|||
}
|
||||
|
||||
void Manager::doUpdateAll() {
|
||||
for_const (auto ¬ification, _notifications) {
|
||||
for (const auto ¬ification : _notifications) {
|
||||
notification->updateNotifyDisplay();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,11 +55,11 @@ public:
|
|||
fillSearchIndex();
|
||||
}
|
||||
|
||||
const OrderedSet<QString> &searchWords() const {
|
||||
const base::flat_set<QString> &searchWords() const {
|
||||
return _searchWords;
|
||||
}
|
||||
bool searchWordsContain(const QString &needle) const {
|
||||
for_const (auto &word, _searchWords) {
|
||||
for (const auto &word : _searchWords) {
|
||||
if (word.startsWith(needle)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
const OrderedSet<QChar> &searchStartChars() const {
|
||||
const base::flat_set<QChar> &searchStartChars() const {
|
||||
return _searchStartChars;
|
||||
}
|
||||
|
||||
|
@ -106,8 +106,8 @@ private:
|
|||
QString _valueString;
|
||||
Ui::Text::String _description = { st::windowMinWidth / 2 };
|
||||
|
||||
OrderedSet<QString> _searchWords;
|
||||
OrderedSet<QChar> _searchStartChars;
|
||||
base::flat_set<QString> _searchWords;
|
||||
base::flat_set<QChar> _searchStartChars;
|
||||
|
||||
int _top = 0;
|
||||
int _height = 0;
|
||||
|
@ -154,11 +154,16 @@ void EditorBlock::Row::fillValueString() {
|
|||
void EditorBlock::Row::fillSearchIndex() {
|
||||
_searchWords.clear();
|
||||
_searchStartChars.clear();
|
||||
auto toIndex = _name + ' ' + _copyOf + ' ' + TextUtilities::RemoveAccents(_description.toString()) + ' ' + _valueString;
|
||||
auto words = toIndex.toLower().split(SearchSplitter, base::QStringSkipEmptyParts);
|
||||
for_const (auto &word, words) {
|
||||
_searchWords.insert(word);
|
||||
_searchStartChars.insert(word[0]);
|
||||
const auto toIndex = _name
|
||||
+ ' ' + _copyOf
|
||||
+ ' ' + TextUtilities::RemoveAccents(_description.toString())
|
||||
+ ' ' + _valueString;
|
||||
const auto words = toIndex.toLower().split(
|
||||
SearchSplitter,
|
||||
base::QStringSkipEmptyParts);
|
||||
for (const auto &word : words) {
|
||||
_searchWords.emplace(word);
|
||||
_searchStartChars.emplace(word[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +257,7 @@ void EditorBlock::addToSearch(const Row &row) {
|
|||
if (!query.isEmpty()) resetSearch();
|
||||
|
||||
auto index = findRowIndex(&row);
|
||||
for_const (auto ch, row.searchStartChars()) {
|
||||
for (const auto ch : row.searchStartChars()) {
|
||||
_searchIndex[ch].insert(index);
|
||||
}
|
||||
|
||||
|
@ -264,12 +269,12 @@ void EditorBlock::removeFromSearch(const Row &row) {
|
|||
if (!query.isEmpty()) resetSearch();
|
||||
|
||||
auto index = findRowIndex(&row);
|
||||
for_const (auto ch, row.searchStartChars()) {
|
||||
auto it = _searchIndex.find(ch);
|
||||
if (it != _searchIndex.cend()) {
|
||||
it->remove(index);
|
||||
if (it->isEmpty()) {
|
||||
_searchIndex.erase(it);
|
||||
for (const auto ch : row.searchStartChars()) {
|
||||
const auto i = _searchIndex.find(ch);
|
||||
if (i != end(_searchIndex)) {
|
||||
i->second.remove(index);
|
||||
if (i->second.empty()) {
|
||||
_searchIndex.erase(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -339,7 +344,9 @@ void EditorBlock::scrollToSelected() {
|
|||
}
|
||||
|
||||
void EditorBlock::searchByQuery(QString query) {
|
||||
auto words = TextUtilities::PrepareSearchWords(query, &SearchSplitter);
|
||||
const auto words = TextUtilities::PrepareSearchWords(
|
||||
query,
|
||||
&SearchSplitter);
|
||||
query = words.isEmpty() ? QString() : words.join(' ');
|
||||
if (_searchQuery != query) {
|
||||
setSelected(-1);
|
||||
|
@ -348,28 +355,28 @@ void EditorBlock::searchByQuery(QString query) {
|
|||
_searchQuery = query;
|
||||
_searchResults.clear();
|
||||
|
||||
auto toFilter = OrderedSet<int>();
|
||||
for_const (auto &word, words) {
|
||||
auto toFilter = (base::flat_set<int>*)nullptr;
|
||||
for (const auto &word : words) {
|
||||
if (word.isEmpty()) continue;
|
||||
|
||||
auto testToFilter = _searchIndex.value(word[0]);
|
||||
if (testToFilter.isEmpty()) {
|
||||
toFilter.clear();
|
||||
const auto i = _searchIndex.find(word[0]);
|
||||
if (i == end(_searchIndex) || i->second.empty()) {
|
||||
toFilter = nullptr;
|
||||
break;
|
||||
} else if (toFilter.isEmpty() || testToFilter.size() < toFilter.size()) {
|
||||
toFilter = testToFilter;
|
||||
} else if (!toFilter || i->second.size() < toFilter->size()) {
|
||||
toFilter = &i->second;
|
||||
}
|
||||
}
|
||||
if (!toFilter.isEmpty()) {
|
||||
auto allWordsFound = [&words](const Row &row) {
|
||||
for_const (auto &word, words) {
|
||||
if (toFilter) {
|
||||
const auto allWordsFound = [&](const Row &row) {
|
||||
for (const auto &word : words) {
|
||||
if (!row.searchWordsContain(word)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
for_const (auto index, toFilter) {
|
||||
for (const auto index : *toFilter) {
|
||||
if (allWordsFound(_data[index])) {
|
||||
_searchResults.push_back(index);
|
||||
}
|
||||
|
@ -423,7 +430,7 @@ void EditorBlock::sortByDistance(const QColor &to) {
|
|||
template <typename Callback>
|
||||
void EditorBlock::enumerateRows(Callback callback) {
|
||||
if (isSearch()) {
|
||||
for_const (auto index, _searchResults) {
|
||||
for (const auto index : _searchResults) {
|
||||
if (!callback(_data[index])) {
|
||||
break;
|
||||
}
|
||||
|
@ -440,7 +447,7 @@ void EditorBlock::enumerateRows(Callback callback) {
|
|||
template <typename Callback>
|
||||
void EditorBlock::enumerateRows(Callback callback) const {
|
||||
if (isSearch()) {
|
||||
for_const (auto index, _searchResults) {
|
||||
for (const auto index : _searchResults) {
|
||||
if (!callback(_data[index])) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -144,8 +144,8 @@ private:
|
|||
QMap<QString, int> _indices;
|
||||
|
||||
QString _searchQuery;
|
||||
QVector<int> _searchResults;
|
||||
QMap<QChar, OrderedSet<int>> _searchIndex;
|
||||
std::vector<int> _searchResults;
|
||||
base::flat_map<QChar, base::flat_set<int>> _searchIndex;
|
||||
|
||||
int _selected = -1;
|
||||
int _pressed = -1;
|
||||
|
|
Loading…
Add table
Reference in a new issue