dialogs_indexed_list.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "dialogs/dialogs_list.h"
  9. class History;
  10. namespace Dialogs {
  11. struct RowsByLetter;
  12. class Row;
  13. class IndexedList {
  14. public:
  15. IndexedList(SortMode sortMode, FilterId filterId = 0);
  16. RowsByLetter addToEnd(Key key);
  17. Row *addByName(Key key);
  18. void adjustByDate(const RowsByLetter &links);
  19. void moveToTop(Key key);
  20. bool updateHeight(Key key, float64 narrowRatio);
  21. bool updateHeights(float64 narrowRatio);
  22. // row must belong to this indexed list all().
  23. void movePinned(Row *row, int deltaSign);
  24. // For sortMode != SortMode::Date && != Complex
  25. void peerNameChanged(
  26. not_null<PeerData*> peer,
  27. const base::flat_set<QChar> &oldChars);
  28. //For sortMode == SortMode::Date || == Complex
  29. void peerNameChanged(
  30. FilterId filterId,
  31. not_null<PeerData*> peer,
  32. const base::flat_set<QChar> &oldChars);
  33. void remove(Key key, Row *replacedBy = nullptr);
  34. void clear();
  35. [[nodiscard]] const List &all() const {
  36. return _list;
  37. }
  38. [[nodiscard]] const List *filtered(QChar ch) const {
  39. const auto i = _index.find(ch);
  40. return (i != _index.end()) ? &i->second : nullptr;
  41. }
  42. [[nodiscard]] std::vector<not_null<Row*>> filtered(
  43. const QStringList &words) const;
  44. // Part of List interface is duplicated here for all() list.
  45. [[nodiscard]] int size() const { return all().size(); }
  46. [[nodiscard]] bool empty() const { return all().empty(); }
  47. [[nodiscard]] int height() const { return all().height(); }
  48. [[nodiscard]] bool contains(Key key) const {
  49. return all().contains(key);
  50. }
  51. [[nodiscard]] Row *getRow(Key key) const { return all().getRow(key); }
  52. [[nodiscard]] Row *rowAtY(int y) const { return all().rowAtY(y); }
  53. using iterator = List::iterator;
  54. using const_iterator = List::const_iterator;
  55. [[nodiscard]] const_iterator cbegin() const { return all().cbegin(); }
  56. [[nodiscard]] const_iterator cend() const { return all().cend(); }
  57. [[nodiscard]] const_iterator begin() const { return all().cbegin(); }
  58. [[nodiscard]] const_iterator end() const { return all().cend(); }
  59. [[nodiscard]] iterator begin() { return all().begin(); }
  60. [[nodiscard]] iterator end() { return all().end(); }
  61. [[nodiscard]] const_iterator cfind(Row *value) const {
  62. return all().cfind(value);
  63. }
  64. [[nodiscard]] const_iterator find(Row *value) const {
  65. return all().cfind(value);
  66. }
  67. [[nodiscard]] iterator find(Row *value) { return all().find(value); }
  68. [[nodiscard]] const_iterator findByY(int y) const {
  69. return all().findByY(y);
  70. }
  71. [[nodiscard]] iterator findByY(int y) { return all().findByY(y); }
  72. private:
  73. void adjustByName(
  74. Key key,
  75. const base::flat_set<QChar> &oldChars);
  76. void adjustNames(
  77. FilterId filterId,
  78. not_null<History*> history,
  79. const base::flat_set<QChar> &oldChars);
  80. SortMode _sortMode = SortMode();
  81. FilterId _filterId = 0;
  82. List _list, _empty;
  83. base::flat_map<QChar, List> _index;
  84. };
  85. } // namespace Dialogs