Back to index

unity  6.0.0
ResultView.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright 2011 Canonical Ltd.
00004  *
00005  * This program is free software: you can redistribute it and/or modify it
00006  * under the terms of the GNU Lesser General Public License version 3, as
00007  * published by the  Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License version 3 along with this program.  If not, see
00017  * <http://www.gnu.org/licenses/>
00018  *
00019  * Authored by: Gordon Allott <gord.allott@canonical.com>
00020  *
00021  */
00022 
00023 
00024 #include "ResultView.h"
00025 #include "unity-shared/IntrospectableWrappers.h"
00026 #include <UnityCore/Variant.h>
00027 #include <Nux/HLayout.h>
00028 #include <Nux/VLayout.h>
00029 #include <Nux/Button.h>
00030 #include <NuxCore/Logger.h>
00031 
00032 namespace unity
00033 {
00034 namespace dash
00035 {
00036 namespace
00037 {
00038 nux::logging::Logger logger("unity.dash.results");
00039 }
00040 
00041 NUX_IMPLEMENT_OBJECT_TYPE(ResultView);
00042 
00043 ResultView::ResultView(NUX_FILE_LINE_DECL)
00044   : View(NUX_FILE_LINE_PARAM)
00045   , expanded(true)
00046   , renderer_(NULL)
00047 {
00048   expanded.changed.connect([&](bool value)
00049   {
00050     QueueRelayout();
00051     NeedRedraw();
00052   });
00053 }
00054 
00055 ResultView::~ResultView()
00056 {
00057   ClearIntrospectableWrappers();
00058 
00059   for (auto result : results_)
00060   {
00061     renderer_->Unload(result);
00062   }
00063 
00064   renderer_->UnReference();
00065 }
00066 
00067 void ResultView::Draw(nux::GraphicsEngine& GfxContext, bool force_draw)
00068 {
00069 
00070 }
00071 
00072 void ResultView::SetModelRenderer(ResultRenderer* renderer)
00073 {
00074   if (renderer_ != NULL)
00075     renderer_->UnReference();
00076 
00077   renderer_ = renderer;
00078   renderer->NeedsRedraw.connect([&]()
00079   {
00080     NeedRedraw();
00081   });
00082   renderer_->SinkReference();
00083 
00084   NeedRedraw();
00085 }
00086 
00087 void ResultView::AddResult(Result& result)
00088 {
00089   results_.push_back(result);
00090   renderer_->Preload(result);
00091 
00092   NeedRedraw();
00093 }
00094 
00095 void ResultView::RemoveResult(Result& result)
00096 {
00097   ResultList::iterator it;
00098   std::string uri = result.uri;
00099 
00100   for (it = results_.begin(); it != results_.end(); it++)
00101   {
00102     if (result.uri == (*it).uri)
00103     {
00104       results_.erase(it);
00105       break;
00106     }
00107   }
00108   renderer_->Unload(result);
00109 }
00110 
00111 ResultView::ResultList ResultView::GetResultList()
00112 {
00113   return results_;
00114 }
00115 
00116 
00117 long ResultView::ComputeContentSize()
00118 {
00119   return View::ComputeContentSize();
00120 }
00121 
00122 
00123 void ResultView::DrawContent(nux::GraphicsEngine& GfxContent, bool force_draw)
00124 {
00125   nux::Geometry base = GetGeometry();
00126   GfxContent.PushClippingRectangle(base);
00127 
00128   if (GetCompositionLayout())
00129     GetCompositionLayout()->ProcessDraw(GfxContent, force_draw);
00130 
00131   GfxContent.PopClippingRectangle();
00132 }
00133 
00134 std::string ResultView::GetName() const
00135 {
00136   return "ResultView";
00137 }
00138 
00139 void ResultView::AddProperties(GVariantBuilder* builder)
00140 {
00141   unity::variant::BuilderWrapper(builder)
00142     .add("expanded", expanded);
00143 }
00144 
00145 debug::Introspectable::IntrospectableList ResultView::GetIntrospectableChildren()
00146 {
00147   ClearIntrospectableWrappers();
00148 
00149   for (auto result: results_)
00150   {
00151     introspectable_children_.push_back(new debug::ResultWrapper(result));
00152   }
00153   return introspectable_children_;
00154 }
00155 
00156 void ResultView::ClearIntrospectableWrappers()
00157 {
00158   // delete old results, then add new results
00159   for (auto old_result: introspectable_children_)
00160   {
00161     delete old_result;
00162   }
00163   introspectable_children_.clear();
00164 }
00165 
00166 }
00167 }