PageRenderTime 39ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llui/llviewquery.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 151 lines | 98 code | 19 blank | 34 comment | 16 complexity | 625b4f960e5f78a24bad331068feb760 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewquery.cpp
  3. * @brief Implementation of view query class.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llview.h"
  28. #include "lluictrl.h"
  29. #include "llviewquery.h"
  30. void LLQuerySorter::operator() (LLView * parent, viewList_t &children) const {}
  31. filterResult_t LLLeavesFilter::operator() (const LLView* const view, const viewList_t & children) const
  32. {
  33. return filterResult_t(children.empty(), TRUE);
  34. }
  35. filterResult_t LLRootsFilter::operator() (const LLView* const view, const viewList_t & children) const
  36. {
  37. return filterResult_t(TRUE, FALSE);
  38. }
  39. filterResult_t LLVisibleFilter::operator() (const LLView* const view, const viewList_t & children) const
  40. {
  41. return filterResult_t(view->getVisible(), view->getVisible());
  42. }
  43. filterResult_t LLEnabledFilter::operator() (const LLView* const view, const viewList_t & children) const
  44. {
  45. return filterResult_t(view->getEnabled(), view->getEnabled());
  46. }
  47. filterResult_t LLTabStopFilter::operator() (const LLView* const view, const viewList_t & children) const
  48. {
  49. return filterResult_t(view->isCtrl() && static_cast<const LLUICtrl*>(view)->hasTabStop(),
  50. view->canFocusChildren());
  51. }
  52. filterResult_t LLCtrlFilter::operator() (const LLView* const view, const viewList_t & children) const
  53. {
  54. return filterResult_t(view->isCtrl(),TRUE);
  55. }
  56. //
  57. // LLViewQuery
  58. //
  59. viewList_t LLViewQuery::run(LLView* view) const
  60. {
  61. viewList_t result;
  62. // prefilter gets immediate children of view
  63. filterResult_t pre = runFilters(view, *view->getChildList(), mPreFilters);
  64. if(!pre.first && !pre.second)
  65. {
  66. // not including ourselves or the children
  67. // nothing more to do
  68. return result;
  69. }
  70. viewList_t filtered_children;
  71. filterResult_t post(TRUE, TRUE);
  72. if(pre.second)
  73. {
  74. // run filters on children
  75. filterChildren(view, filtered_children);
  76. // only run post filters if this element passed pre filters
  77. // so if you failed to pass the pre filter, you can't filter out children in post
  78. if (pre.first)
  79. {
  80. post = runFilters(view, filtered_children, mPostFilters);
  81. }
  82. }
  83. if(pre.first && post.first)
  84. {
  85. result.push_back(view);
  86. }
  87. if(pre.second && post.second)
  88. {
  89. result.insert(result.end(), filtered_children.begin(), filtered_children.end());
  90. }
  91. return result;
  92. }
  93. void LLViewQuery::filterChildren(LLView * view, viewList_t & filtered_children) const
  94. {
  95. LLView::child_list_t views(*(view->getChildList()));
  96. if (mSorterp)
  97. {
  98. (*mSorterp)(view, views); // sort the children per the sorter
  99. }
  100. for(LLView::child_list_iter_t iter = views.begin();
  101. iter != views.end();
  102. iter++)
  103. {
  104. viewList_t indiv_children = this->run(*iter);
  105. filtered_children.splice(filtered_children.end(), indiv_children);
  106. }
  107. }
  108. filterResult_t LLViewQuery::runFilters(LLView * view, const viewList_t children, const filterList_t filters) const
  109. {
  110. filterResult_t result = filterResult_t(TRUE, TRUE);
  111. for(filterList_const_iter_t iter = filters.begin();
  112. iter != filters.end();
  113. iter++)
  114. {
  115. filterResult_t filtered = (**iter)(view, children);
  116. result.first = result.first && filtered.first;
  117. result.second = result.second && filtered.second;
  118. }
  119. return result;
  120. }
  121. class SortByTabOrder : public LLQuerySorter, public LLSingleton<SortByTabOrder>
  122. {
  123. /*virtual*/ void operator() (LLView * parent, LLView::child_list_t &children) const
  124. {
  125. children.sort(LLCompareByTabOrder(parent->getCtrlOrder()));
  126. }
  127. };
  128. LLCtrlQuery::LLCtrlQuery() :
  129. LLViewQuery()
  130. {
  131. setSorter(SortByTabOrder::getInstance());
  132. }