Back to index

unity  6.0.0
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
unity::dash::MultiRangeFilter Class Reference

#include <MultiRangeFilter.h>

Inheritance diagram for unity::dash::MultiRangeFilter:
Inheritance graph
[legend]
Collaboration diagram for unity::dash::MultiRangeFilter:
Collaboration graph
[legend]

List of all members.

Public Types

typedef std::shared_ptr
< MultiRangeFilter
Ptr
typedef std::vector
< FilterOption::Ptr
Options
typedef std::map< std::string,
unity::glib::Variant
Hints

Public Member Functions

 MultiRangeFilter (DeeModel *model, DeeModelIter *iter)
void Clear ()
bool IsValid () const

Static Public Member Functions

static Filter::Ptr FilterFromIter (DeeModel *model, DeeModelIter *iter)

Public Attributes

nux::ROProperty< Optionsoptions
sigc::signal< void,
FilterOption::Ptr
option_added
sigc::signal< void,
FilterOption::Ptr
option_removed
nux::ROProperty< std::string > id
nux::ROProperty< std::string > name
nux::ROProperty< std::string > icon_hint
nux::ROProperty< std::string > renderer_name
nux::ROProperty< bool > visible
nux::ROProperty< bool > collapsed
nux::ROProperty< bool > filtering
sigc::signal< void > removed

Protected Member Functions

void Update (Filter::Hints &hints)
void Refresh ()
void IgnoreChanges (bool ignore)

Protected Attributes

DeeModel * model_
DeeModelIter * iter_
glib::SignalManager signal_manager_

Private Member Functions

void UpdateState ()
Options const & get_options () const
int PositionOfId (std::string const &id)
void OptionChanged (bool is_active, std::string const &id)

Private Attributes

Options options_
int left_pos_
int right_pos_
bool ignore_changes_

Detailed Description

Definition at line 30 of file MultiRangeFilter.h.


Member Typedef Documentation

typedef std::map<std::string, unity::glib::Variant> unity::dash::Filter::Hints [inherited]

Definition at line 70 of file Filter.h.

Definition at line 34 of file MultiRangeFilter.h.

Reimplemented from unity::dash::Filter.

Definition at line 33 of file MultiRangeFilter.h.


Constructor & Destructor Documentation

unity::dash::MultiRangeFilter::MultiRangeFilter ( DeeModel *  model,
DeeModelIter *  iter 
)

Definition at line 34 of file MultiRangeFilter.cpp.

  : Filter(model, iter)
  , left_pos_(-1)
  , right_pos_(-1)
  , ignore_changes_(false)
{
  options.SetGetterFunction(sigc::mem_fun(this, &MultiRangeFilter::get_options));
  Refresh();
}

Here is the call graph for this function:


Member Function Documentation

Implements unity::dash::Filter.

Definition at line 44 of file MultiRangeFilter.cpp.

{
  left_pos_ = -1;
  right_pos_ = -1;

  ignore_changes_ = true;
  
  for(auto option: options_)
    option->active = false;

  ignore_changes_ = false;

  UpdateState();
}

Here is the call graph for this function:

Filter::Ptr unity::dash::Filter::FilterFromIter ( DeeModel *  model,
DeeModelIter *  iter 
) [static, inherited]

Definition at line 82 of file Filter.cpp.

{
  std::string renderer = dee_model_get_string(model, iter, 3);

  if (renderer == "filter-ratings")
    return std::make_shared<RatingsFilter>(model, iter);
  else if (renderer == "filter-radiooption")
    return std::make_shared<RadioOptionFilter>(model, iter);
  else if (renderer == "filter-checkoption")
    return std::make_shared<CheckOptionFilter>(model, iter);
  else if (renderer == "filter-checkoption-compact")
    return std::make_shared<CheckOptionFilter>(model, iter);
  else if (renderer == "filter-multirange")
    return std::make_shared<MultiRangeFilter>(model, iter);
  else
    return std::make_shared<RatingsFilter>(model, iter);
}

Here is the caller graph for this function:

Definition at line 158 of file MultiRangeFilter.cpp.

{
  return options_;
}

Here is the caller graph for this function:

void unity::dash::Filter::IgnoreChanges ( bool  ignore) [protected, inherited]

Definition at line 111 of file Filter.cpp.

{
  ignore_changes_ = ignore;
}

Here is the caller graph for this function:

bool unity::dash::Filter::IsValid ( ) const [inherited]

Definition at line 100 of file Filter.cpp.

{
  return model_ && iter_;
}

Here is the caller graph for this function:

void unity::dash::MultiRangeFilter::OptionChanged ( bool  is_active,
std::string const &  id 
) [private]

Definition at line 89 of file MultiRangeFilter.cpp.

{
  if (ignore_changes_)
    return;

  int position = PositionOfId(id);

  if (is_active)
  {
    if (left_pos_ == -1 && right_pos_ == -1)
    {
      left_pos_ = position;
      right_pos_ = position;
    }
    else if (left_pos_ > position)
    {
      left_pos_ = position;
    }
    else if (right_pos_ < position)
    {
      right_pos_ = position;
    }
  }
  else
  {
    // Reset if the one and only block is deactivated
    if (position == right_pos_ && position == left_pos_)
    {
      left_pos_ = -1;
      right_pos_ = -1;
    }
    // If the deactivated block is on either end, remove it
    else if (position == right_pos_)
    {
      right_pos_ = position - 1;
    }
    else if (position == left_pos_)
    {
      left_pos_ = position + 1;
    }
    // It's in the middle of the range, see which side to shorten
    else if (position < (left_pos_ + ((right_pos_ - left_pos_)/2.0f)))
    {
      left_pos_ = position;
    }
    else
    {
      right_pos_ = position;
    }
  }

  ignore_changes_ = true;
  int i = 0;
  for(auto option: options_)
  {
    if (i < left_pos_)
      option->active = false;
    else if (i <= right_pos_)
      option->active = true;
    else
      option->active = false;

    i++;
  }
  ignore_changes_ = false;

  UpdateState();
}

Here is the call graph for this function:

Here is the caller graph for this function:

int unity::dash::MultiRangeFilter::PositionOfId ( std::string const &  id) [private]

Definition at line 202 of file MultiRangeFilter.cpp.

{
  int i = 0;
  for (auto option: options_)
  {
    if (option->id == id)
      return i;
    i++;
  }
  return -1;
}

Here is the caller graph for this function:

void unity::dash::Filter::Refresh ( ) [protected, inherited]

Definition at line 105 of file Filter.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::dash::MultiRangeFilter::Update ( Filter::Hints hints) [protected, virtual]

Implements unity::dash::Filter.

Definition at line 59 of file MultiRangeFilter.cpp.

{
  GVariant* options_variant = hints["options"];
  GVariantIter* options_iter;

  g_variant_get(options_variant, "a(sssb)", &options_iter);

  char *id = NULL;
  char *name = NULL;
  char *icon_hint = NULL;
  gboolean active = false;

  for (auto option: options_)
    option_removed.emit(option);

  options_.clear();

  while (g_variant_iter_loop(options_iter, "(sssb)", &id, &name, &icon_hint, &active))
  {
    FilterOption::Ptr option(new FilterOption(id, name, icon_hint, active));

    std::string data(id);
    option->active.changed.connect(sigc::bind(sigc::mem_fun(this, &MultiRangeFilter::OptionChanged), data));
    options_.push_back(option);
    option_added.emit(option);
  }

  g_variant_iter_free(options_iter);
}

Here is the call graph for this function:

Definition at line 163 of file MultiRangeFilter.cpp.

{
  if (!IsValid())
    return;
  gboolean raw_filtering = FALSE;

  GVariantBuilder options;
  g_variant_builder_init(&options, G_VARIANT_TYPE("a(sssb)"));

  for(auto option: options_)
  {
    std::string id = option->id;
    std::string name = option->name;
    std::string icon_hint = option->icon_hint;
    bool active = option->active;

    raw_filtering = raw_filtering ? TRUE : active;

    g_variant_builder_add(&options, "(sssb)",
                          id.c_str(), name.c_str(),
                          icon_hint.c_str(), active ? TRUE : FALSE);
  }
  
  GVariantBuilder hints;
  g_variant_builder_init(&hints, G_VARIANT_TYPE("a{sv}"));
  g_variant_builder_add(&hints, "{sv}", "options", g_variant_builder_end(&options));

  IgnoreChanges(true);
  dee_model_set_value(model_,iter_,
                      FilterColumn::RENDERER_STATE,
                      g_variant_builder_end(&hints));
  dee_model_set_value(model_, iter_,
                      FilterColumn::FILTERING,
                      g_variant_new("b", raw_filtering));
  IgnoreChanges(false);

  filtering.EmitChanged(filtering);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

nux::ROProperty<bool> unity::dash::Filter::collapsed [inherited]

Definition at line 85 of file Filter.h.

nux::ROProperty<bool> unity::dash::Filter::filtering [inherited]

Definition at line 86 of file Filter.h.

nux::ROProperty<std::string> unity::dash::Filter::icon_hint [inherited]

Definition at line 82 of file Filter.h.

nux::ROProperty<std::string> unity::dash::Filter::id [inherited]

Definition at line 80 of file Filter.h.

Reimplemented from unity::dash::Filter.

Definition at line 58 of file MultiRangeFilter.h.

DeeModelIter* unity::dash::Filter::iter_ [protected, inherited]

Definition at line 112 of file Filter.h.

Definition at line 56 of file MultiRangeFilter.h.

DeeModel* unity::dash::Filter::model_ [protected, inherited]

Definition at line 111 of file Filter.h.

nux::ROProperty<std::string> unity::dash::Filter::name [inherited]

Definition at line 81 of file Filter.h.

Definition at line 42 of file MultiRangeFilter.h.

Definition at line 43 of file MultiRangeFilter.h.

Definition at line 40 of file MultiRangeFilter.h.

Definition at line 55 of file MultiRangeFilter.h.

sigc::signal<void> unity::dash::Filter::removed [inherited]

Definition at line 88 of file Filter.h.

nux::ROProperty<std::string> unity::dash::Filter::renderer_name [inherited]

Definition at line 83 of file Filter.h.

Definition at line 57 of file MultiRangeFilter.h.

Definition at line 113 of file Filter.h.

nux::ROProperty<bool> unity::dash::Filter::visible [inherited]

Definition at line 84 of file Filter.h.


The documentation for this class was generated from the following files: