Back to index

unity  6.0.0
Filters.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU 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,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00018  */
00019 
00020 #include "Filters.h"
00021 
00022 namespace unity
00023 {
00024 namespace dash
00025 {
00026 
00027 FilterAdaptor::FilterAdaptor(DeeModel* model,
00028                              DeeModelIter* iter,
00029                              DeeModelTag* renderer_tag)
00030   : RowAdaptorBase(model, iter, renderer_tag)
00031 {
00032   renderer_name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 3));
00033 }
00034 
00035 FilterAdaptor::FilterAdaptor(FilterAdaptor const& other)
00036   : RowAdaptorBase(other.model_, other.iter_, other.tag_)
00037 {
00038   renderer_name.SetGetterFunction(sigc::bind(sigc::mem_fun(this, &RowAdaptorBase::GetStringAt), 3));
00039 }
00040 
00041 DeeModel* FilterAdaptor::model() const
00042 {
00043   return model_;
00044 }
00045 
00046 DeeModelIter* FilterAdaptor::iter() const
00047 {
00048   return iter_;
00049 }
00050 
00051 
00052 Filters::Filters()
00053 {
00054   row_added.connect(sigc::mem_fun(this, &Filters::OnRowAdded));
00055   row_changed.connect(sigc::mem_fun(this, &Filters::OnRowChanged));
00056   row_removed.connect(sigc::mem_fun(this, &Filters::OnRowRemoved));
00057 }
00058 
00059 Filters::Filters(ModelType model_type)
00060  : Model<FilterAdaptor>::Model(model_type)
00061 {
00062   row_added.connect(sigc::mem_fun(this, &Filters::OnRowAdded));
00063   row_changed.connect(sigc::mem_fun(this, &Filters::OnRowChanged));
00064   row_removed.connect(sigc::mem_fun(this, &Filters::OnRowRemoved));
00065 }
00066 
00067 Filters::~Filters()
00068 {}
00069 
00070 Filter::Ptr Filters::FilterAtIndex(std::size_t index)
00071 {
00072   FilterAdaptor adaptor = RowAtIndex(index);
00073   return filter_map_[adaptor.iter()];
00074 }
00075 
00076 void Filters::OnRowAdded(FilterAdaptor& filter)
00077 {
00078   Filter::Ptr ret = Filter::FilterFromIter(filter.model(), filter.iter());
00079 
00080   filter_map_[filter.iter()] = ret;
00081   filter_added(ret);
00082 }
00083 
00084 void Filters::OnRowChanged(FilterAdaptor& filter)
00085 {
00086   filter_changed(filter_map_[filter.iter()]);
00087 }
00088 
00089 void Filters::OnRowRemoved(FilterAdaptor& filter)
00090 {
00091   filter_removed(filter_map_[filter.iter()]);
00092   filter_map_.erase(filter.iter());
00093 }
00094 
00095 }
00096 }