mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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);
|
_list = std::move(infos);
|
||||||
_byCode.clear();
|
_byCode.clear();
|
||||||
_byISO2.clear();
|
_byISO2.clear();
|
||||||
|
_updated.fire({});
|
||||||
}
|
}
|
||||||
|
|
||||||
const CountriesInstance::Map &CountriesInstance::byCode() {
|
const CountriesInstance::Map &CountriesInstance::byCode() {
|
||||||
|
@ -454,6 +455,10 @@ FormatResult CountriesInstance::format(FormatArgs args) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<> CountriesInstance::updated() const {
|
||||||
|
return _updated.events();
|
||||||
|
}
|
||||||
|
|
||||||
CountriesInstance &Instance() {
|
CountriesInstance &Instance() {
|
||||||
return SingleInstance;
|
return SingleInstance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,12 +55,16 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] FormatResult format(FormatArgs args);
|
[[nodiscard]] FormatResult format(FormatArgs args);
|
||||||
|
|
||||||
|
[[nodiscard]] rpl::producer<> updated() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Info> _list;
|
std::vector<Info> _list;
|
||||||
|
|
||||||
Map _byCode;
|
Map _byCode;
|
||||||
Map _byISO2;
|
Map _byISO2;
|
||||||
|
|
||||||
|
rpl::event_stream<> _updated;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
CountriesInstance &Instance();
|
CountriesInstance &Instance();
|
||||||
|
|
|
@ -26,7 +26,7 @@ QString LastValidISO;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
class CountrySelectBox::Inner : public TWidget {
|
class CountrySelectBox::Inner : public RpWidget {
|
||||||
public:
|
public:
|
||||||
Inner(QWidget *parent, const QString &iso, Type type);
|
Inner(QWidget *parent, const QString &iso, Type type);
|
||||||
~Inner();
|
~Inner();
|
||||||
|
@ -57,6 +57,7 @@ protected:
|
||||||
void mouseReleaseEvent(QMouseEvent *e) override;
|
void mouseReleaseEvent(QMouseEvent *e) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void init();
|
||||||
void updateSelected() {
|
void updateSelected() {
|
||||||
updateSelected(mapFromGlobal(QCursor::pos()));
|
updateSelected(mapFromGlobal(QCursor::pos()));
|
||||||
}
|
}
|
||||||
|
@ -179,7 +180,7 @@ CountrySelectBox::Inner::Inner(
|
||||||
QWidget *parent,
|
QWidget *parent,
|
||||||
const QString &iso,
|
const QString &iso,
|
||||||
Type type)
|
Type type)
|
||||||
: TWidget(parent)
|
: RpWidget(parent)
|
||||||
, _type(type)
|
, _type(type)
|
||||||
, _rowHeight(st::countryRowHeight) {
|
, _rowHeight(st::countryRowHeight) {
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||||
|
@ -190,6 +191,23 @@ CountrySelectBox::Inner::Inner(
|
||||||
LastValidISO = iso;
|
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) {
|
const auto extractEntries = [&](const Countries::Info &info) {
|
||||||
for (const auto &code : info.codes) {
|
for (const auto &code : info.codes) {
|
||||||
_list.push_back(Entry{
|
_list.push_back(Entry{
|
||||||
|
@ -241,9 +259,6 @@ CountrySelectBox::Inner::Inner(
|
||||||
}
|
}
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
_filter = u"a"_q;
|
|
||||||
updateFilter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) {
|
void CountrySelectBox::Inner::paintEvent(QPaintEvent *e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue