mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Added refreshing of list in CountrySelectBox on update.
This commit is contained in:
parent
e80a7907a9
commit
58da62b413
3 changed files with 29 additions and 5 deletions
|
@ -262,6 +262,7 @@ void CountriesInstance::setList(std::vector<Info> &&infos) {
|
|||
_list = std::move(infos);
|
||||
_byCode.clear();
|
||||
_byISO2.clear();
|
||||
_updated.fire({});
|
||||
}
|
||||
|
||||
const CountriesInstance::Map &CountriesInstance::byCode() {
|
||||
|
@ -454,6 +455,10 @@ FormatResult CountriesInstance::format(FormatArgs args) {
|
|||
};
|
||||
}
|
||||
|
||||
rpl::producer<> CountriesInstance::updated() const {
|
||||
return _updated.events();
|
||||
}
|
||||
|
||||
CountriesInstance &Instance() {
|
||||
return SingleInstance;
|
||||
}
|
||||
|
|
|
@ -55,12 +55,16 @@ public:
|
|||
|
||||
[[nodiscard]] FormatResult format(FormatArgs args);
|
||||
|
||||
[[nodiscard]] rpl::producer<> updated() const;
|
||||
|
||||
private:
|
||||
std::vector<Info> _list;
|
||||
|
||||
Map _byCode;
|
||||
Map _byISO2;
|
||||
|
||||
rpl::event_stream<> _updated;
|
||||
|
||||
};
|
||||
|
||||
CountriesInstance &Instance();
|
||||
|
|
|
@ -26,7 +26,7 @@ QString LastValidISO;
|
|||
|
||||
} // namespace
|
||||
|
||||
class CountrySelectBox::Inner : public TWidget {
|
||||
class CountrySelectBox::Inner : public RpWidget {
|
||||
public:
|
||||
Inner(QWidget *parent, const QString &iso, Type type);
|
||||
~Inner();
|
||||
|
@ -57,6 +57,7 @@ protected:
|
|||
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
void updateSelected() {
|
||||
updateSelected(mapFromGlobal(QCursor::pos()));
|
||||
}
|
||||
|
@ -179,7 +180,7 @@ CountrySelectBox::Inner::Inner(
|
|||
QWidget *parent,
|
||||
const QString &iso,
|
||||
Type type)
|
||||
: TWidget(parent)
|
||||
: RpWidget(parent)
|
||||
, _type(type)
|
||||
, _rowHeight(st::countryRowHeight) {
|
||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||
|
@ -190,6 +191,23 @@ CountrySelectBox::Inner::Inner(
|
|||
LastValidISO = iso;
|
||||
}
|
||||
|
||||
rpl::single(
|
||||
) | rpl::then(
|
||||
Countries::Instance().updated()
|
||||
) | rpl::start_with_next([=] {
|
||||
_mustScrollTo.fire(ScrollToRequest(0, 0));
|
||||
_list.clear();
|
||||
_namesList.clear();
|
||||
init();
|
||||
const auto filter = _filter;
|
||||
_filter = u"a"_q;
|
||||
updateFilter(filter);
|
||||
}, lifetime());
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::init() {
|
||||
const auto &byISO2 = Countries::Instance().byISO2();
|
||||
|
||||
const auto extractEntries = [&](const Countries::Info &info) {
|
||||
for (const auto &code : info.codes) {
|
||||
_list.push_back(Entry{
|
||||
|
@ -241,9 +259,6 @@ CountrySelectBox::Inner::Inner(
|
|||
}
|
||||
++index;
|
||||
}
|
||||
|
||||
_filter = u"a"_q;
|
||||
updateFilter();
|
||||
}
|
||||
|
||||
void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) {
|
||||
|
|
Loading…
Add table
Reference in a new issue