llviewquery.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "llview.h"
00035 #include "lluictrl.h"
00036 #include "llviewquery.h"
00037 
00038 void LLQuerySorter::operator() (LLView * parent, viewList_t &children) const {}
00039 
00040 filterResult_t LLNoLeavesFilter::operator() (const LLView* const view, const viewList_t & children) const 
00041 {
00042         return filterResult_t(!(view->getChildList()->size() == 0), TRUE);
00043 }
00044 
00045 filterResult_t LLVisibleFilter::operator() (const LLView* const view, const viewList_t & children) const 
00046 {
00047         return filterResult_t(view->getVisible(), view->getVisible());
00048 }
00049 filterResult_t LLEnabledFilter::operator() (const LLView* const view, const viewList_t & children) const 
00050 {
00051         return filterResult_t(view->getEnabled(), view->getEnabled());
00052 }
00053 filterResult_t LLTabStopFilter::operator() (const LLView* const view, const viewList_t & children) const 
00054 {
00055         return filterResult_t(view->isCtrl() && static_cast<const LLUICtrl*>(view)->hasTabStop(),
00056                                                 view->canFocusChildren());
00057 }
00058 
00059 // LLViewQuery
00060 
00061 LLViewQuery::LLViewQuery(): mPreFilters(), mPostFilters(), mSorterp() 
00062 {
00063 }
00064 
00065 void LLViewQuery::addPreFilter(const LLQueryFilter* prefilter) { mPreFilters.push_back(prefilter); }
00066 
00067 void LLViewQuery::addPostFilter(const LLQueryFilter* postfilter) {      mPostFilters.push_back(postfilter); }
00068 
00069 const LLViewQuery::filterList_t & LLViewQuery::getPreFilters() const { return mPreFilters; }
00070 
00071 const LLViewQuery::filterList_t & LLViewQuery::getPostFilters() const { return mPostFilters; }
00072 
00073 void LLViewQuery::setSorter(const LLQuerySorter* sorterp) { mSorterp = sorterp; }
00074 const LLQuerySorter* LLViewQuery::getSorter() const { return mSorterp; }
00075 
00076 viewList_t LLViewQuery::run(LLView * view) const
00077 {
00078         viewList_t result;
00079 
00080         filterResult_t pre = runFilters(view, viewList_t(), mPreFilters);
00081         if(!pre.first && !pre.second)
00082         {
00083                 // skip post filters completely if we're not including ourselves or the children
00084                 return result;
00085         }
00086         if(pre.second)
00087         {
00088                 // run filters on children
00089                 viewList_t filtered_children;
00090                 filterChildren(view, filtered_children);
00091                 filterResult_t post = runFilters(view, filtered_children, mPostFilters);
00092                 if(pre.first && post.first)
00093                 {
00094                         result.push_back(view);
00095                 }
00096                 if(post.second)
00097                 {
00098                         result.insert(result.end(), filtered_children.begin(), filtered_children.end());
00099                 }
00100         }
00101         else 
00102         {
00103                 if(pre.first) 
00104                 {
00105                         result.push_back(view);
00106                 }
00107         }
00108         return result;
00109 }
00110 
00111 void LLViewQuery::filterChildren(LLView * view, viewList_t & filtered_children) const
00112 {
00113         LLView::child_list_t views(*(view->getChildList()));
00114         (*mSorterp)(view, views); // sort the children per the sorter
00115         for(LLView::child_list_iter_t iter = views.begin();
00116                         iter != views.end();
00117                         iter++)
00118                 {
00119                         viewList_t indiv_children = this->run(*iter);
00120                         filtered_children.insert(filtered_children.end(), indiv_children.begin(), indiv_children.end());
00121                 }
00122 }
00123 
00124 filterResult_t LLViewQuery::runFilters(LLView * view, const viewList_t children, const filterList_t filters) const
00125 {
00126         filterResult_t result = filterResult_t(TRUE, TRUE);
00127         for(filterList_const_iter_t iter = filters.begin();
00128                 iter != filters.end();
00129                 iter++)
00130         {
00131                 filterResult_t filtered = (**iter)(view, children);
00132                 result.first = result.first && filtered.first;
00133                 result.second = result.second && filtered.second;
00134         }
00135         return result;
00136 }
00137 
00138 class SortByTabOrder : public LLQuerySorter, public LLSingleton<SortByTabOrder>
00139 {
00140         /*virtual*/ void operator() (LLView * parent, LLView::child_list_t &children) const 
00141         {
00142                 children.sort(LLCompareByTabOrder(parent->getCtrlOrder()));
00143         }
00144 };
00145 
00146 LLCtrlQuery::LLCtrlQuery() : 
00147         LLViewQuery()
00148 {
00149         setSorter(SortByTabOrder::getInstance());
00150 }
00151 

Generated on Thu Jul 1 06:09:35 2010 for Second Life Viewer by  doxygen 1.4.7