linear_chart_view.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "statistics/statistics_common.h"
  9. #include "statistics/view/abstract_chart_view.h"
  10. namespace Data {
  11. struct StatisticalChart;
  12. } // namespace Data
  13. namespace Statistic {
  14. struct Limits;
  15. class LinearChartView final : public AbstractChartView {
  16. public:
  17. LinearChartView(bool isDouble);
  18. ~LinearChartView() override final;
  19. void paint(QPainter &p, const PaintContext &c) override;
  20. void paintSelectedXIndex(
  21. QPainter &p,
  22. const PaintContext &c,
  23. int selectedXIndex,
  24. float64 progress) override;
  25. int findXIndexByPosition(
  26. const Data::StatisticalChart &chartData,
  27. const Limits &xPercentageLimits,
  28. const QRect &rect,
  29. float64 x) override;
  30. [[nodiscard]] HeightLimits heightLimits(
  31. Data::StatisticalChart &chartData,
  32. Limits xIndices) override;
  33. private:
  34. DoubleLineRatios _cachedLineRatios;
  35. [[nodiscard]] float64 lineRatio() const;
  36. struct CacheToken final {
  37. explicit CacheToken() = default;
  38. explicit CacheToken(
  39. Limits xIndices,
  40. Limits xPercentageLimits,
  41. Limits heightLimits,
  42. QSize rectSize)
  43. : xIndices(std::move(xIndices))
  44. , xPercentageLimits(std::move(xPercentageLimits))
  45. , heightLimits(std::move(heightLimits))
  46. , rectSize(std::move(rectSize)) {
  47. }
  48. bool operator==(const CacheToken &other) const {
  49. return (rectSize == other.rectSize)
  50. && (xIndices.min == other.xIndices.min)
  51. && (xIndices.max == other.xIndices.max)
  52. && (xPercentageLimits.min == other.xPercentageLimits.min)
  53. && (xPercentageLimits.max == other.xPercentageLimits.max)
  54. && (heightLimits.min == other.heightLimits.min)
  55. && (heightLimits.max == other.heightLimits.max);
  56. }
  57. bool operator!=(const CacheToken &other) const {
  58. return !(*this == other);
  59. }
  60. Limits xIndices;
  61. Limits xPercentageLimits;
  62. Limits heightLimits;
  63. QSize rectSize;
  64. };
  65. struct Cache final {
  66. QImage image;
  67. CacheToken lastToken;
  68. bool hq = false;
  69. };
  70. base::flat_map<int, Cache> _mainCaches;
  71. base::flat_map<int, Cache> _footerCaches;
  72. CachedSelectedPoints _selectedPoints;
  73. };
  74. } // namespace Statistic