llviewquery.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * @file llviewquery.h
  3. * @brief Query algorithm for flattening and filtering the view hierarchy.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLVIEWQUERY_H
  33. #define LL_LLVIEWQUERY_H
  34. #include <list>
  35. #include "llsingleton.h"
  36. class LLView;
  37. typedef std::list<LLView*> view_list_t;
  38. typedef std::pair<bool, bool> filter_result_t;
  39. // Abstract base class for all query filters.
  40. class LLQueryFilter
  41. {
  42. public:
  43. virtual ~LLQueryFilter() = default;
  44. virtual filter_result_t operator()(const LLView* const view,
  45. const view_list_t& children) const = 0;
  46. };
  47. class LLQuerySorter
  48. {
  49. public:
  50. virtual ~LLQuerySorter() = default;
  51. virtual void operator()(LLView* parent, view_list_t &children) const;
  52. };
  53. class LLLeavesFilter : public LLQueryFilter, public LLSingleton<LLLeavesFilter>
  54. {
  55. friend class LLSingleton<LLLeavesFilter>;
  56. filter_result_t operator()(const LLView* const view,
  57. const view_list_t& children) const override;
  58. };
  59. class LLRootsFilter : public LLQueryFilter, public LLSingleton<LLRootsFilter>
  60. {
  61. friend class LLSingleton<LLRootsFilter>;
  62. filter_result_t operator()(const LLView* const view,
  63. const view_list_t& children) const override;
  64. };
  65. class LLVisibleFilter : public LLQueryFilter, public LLSingleton<LLVisibleFilter>
  66. {
  67. friend class LLSingleton<LLVisibleFilter>;
  68. filter_result_t operator()(const LLView* const view,
  69. const view_list_t& children) const override;
  70. };
  71. class LLEnabledFilter : public LLQueryFilter, public LLSingleton<LLEnabledFilter>
  72. {
  73. friend class LLSingleton<LLEnabledFilter>;
  74. filter_result_t operator()(const LLView* const view,
  75. const view_list_t& children) const override;
  76. };
  77. class LLTabStopFilter : public LLQueryFilter, public LLSingleton<LLTabStopFilter>
  78. {
  79. friend class LLSingleton<LLTabStopFilter>;
  80. filter_result_t operator()(const LLView* const view,
  81. const view_list_t& children) const override;
  82. };
  83. class LLCtrlFilter : public LLQueryFilter, public LLSingleton<LLCtrlFilter>
  84. {
  85. friend class LLSingleton<LLCtrlFilter>;
  86. filter_result_t operator()(const LLView* const view,
  87. const view_list_t& children) const override;
  88. };
  89. template <class T>
  90. class LLWidgetTypeFilter : public LLQueryFilter
  91. {
  92. LL_INLINE filter_result_t operator()(const LLView* const view,
  93. const view_list_t& children) const override
  94. {
  95. return filter_result_t(dynamic_cast<const T*>(view) != NULL, true);
  96. }
  97. };
  98. // Algorithm for flattening
  99. class LLViewQuery
  100. {
  101. public:
  102. typedef std::list<const LLQueryFilter*> filter_list_t;
  103. typedef filter_list_t::iterator filter_list_iter_t;
  104. typedef filter_list_t::const_iterator filter_list_const_iter_t;
  105. LL_INLINE LLViewQuery()
  106. : mSorterp(NULL)
  107. {
  108. }
  109. virtual ~LLViewQuery() = default;
  110. LL_INLINE void addPreFilter(const LLQueryFilter* prefilter)
  111. {
  112. mPreFilters.push_back(prefilter);
  113. }
  114. LL_INLINE void addPostFilter(const LLQueryFilter* postfilter)
  115. {
  116. mPostFilters.push_back(postfilter);
  117. }
  118. LL_INLINE const filter_list_t& getPreFilters() const { return mPreFilters; }
  119. LL_INLINE const filter_list_t& getPostFilters() const { return mPostFilters; }
  120. LL_INLINE void setSorter(const LLQuerySorter* sorter) { mSorterp = sorter; }
  121. LL_INLINE const LLQuerySorter* getSorter() const { return mSorterp; }
  122. view_list_t run(LLView* view) const;
  123. // Syntactic sugar
  124. LL_INLINE view_list_t operator()(LLView* view) const { return run(view); }
  125. // Override this method to provide iteration over other types of children
  126. virtual void filterChildren(LLView* view,
  127. view_list_t& filtered_children) const;
  128. private:
  129. filter_result_t runFilters(LLView* view, const view_list_t& children,
  130. const filter_list_t& filters) const;
  131. private:
  132. filter_list_t mPreFilters;
  133. filter_list_t mPostFilters;
  134. const LLQuerySorter* mSorterp;
  135. };
  136. class LLCtrlQuery : public LLViewQuery
  137. {
  138. public:
  139. LLCtrlQuery();
  140. };
  141. #endif // LL_LLVIEWQUERY_H