Added refreshing of list in CountrySelectBox on update.

This commit is contained in:
23rd 2021-09-02 23:24:53 +03:00 committed by John Preston
parent e80a7907a9
commit 58da62b413
3 changed files with 29 additions and 5 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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) {