Unity Scopes API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
unity::scopes::RatingFilter Class Reference

A filter that allows for rating-based selection. More...

#include <unity/scopes/RatingFilter.h>

Inheritance diagram for unity::scopes::RatingFilter:

Public Member Functions

FilterOption::SCPtr add_option (std::string const &id, std::string const &label)
 Adds a new option to the filter. More...
 
void set_on_icon (std::string const &on_icon)
 Set a custom icon for the "on" state. More...
 
void set_off_icon (std::string const &off_icon)
 Set a custom icon for the "off" state. More...
 
std::string label () const
 Get the label of this filter. More...
 
std::string on_icon () const
 Get custom icon for the "on" state. More...
 
std::string off_icon () const
 Get custom icon for the "off" state. More...
 
std::list< FilterOption::SCPtr > options () const
 Get all options of this filter, in the order they were added. More...
 
bool has_active_rating (FilterState const &filter_state) const
 Check if a rating option is active. More...
 
FilterOption::SCPtr active_rating (FilterState const &filter_state) const
 Get active option from an instance of FilterState for this filter. More...
 
void update_state (FilterState &filter_state, FilterOption::SCPtr option, bool active) const
 Marks given FilterOption of this filter instance as active (or not active) in a FilterState object. More...
 
- Public Member Functions inherited from unity::scopes::FilterBase
void set_display_hints (int hints)
 Sets display hints for the Shell UI. More...
 
int display_hints () const
 Get display hints of this filter. More...
 
std::string id () const
 Get the identifier of this filter. More...
 
std::string filter_type () const
 Get the type name of this filter. More...
 

Static Public Member Functions

static RatingFilter::UPtr create (std::string const &id, std::string const &label)
 Creates RatingFilter widget. More...
 
static RatingFilter::UPtr create (std::string const &id, std::string const &label, int top_rating)
 Creates RatingFilter widget. More...
 
static void update_state (FilterState &filter_state, std::string const &filter_id, std::string const &option_id, bool value)
 Marks an option of a filter active/inactive in a FilterState object, without having an instance of OptionSelectorFilter. More...
 

Additional Inherited Members

- Public Types inherited from unity::scopes::FilterBase
enum  DisplayHints { Default = 0, Primary = 1 }
 Display hints for the Shell UI. More...
 

Detailed Description

A filter that allows for rating-based selection.

Displays filter with a set of options, where every option has a label and icon. Only one option can be active at a time. The active option uses the icon in "on" state (see unity::scopes::RatingFilter::set_on_icon() ). All other icons are "off" (see unity::scopes::RatingFilter::set_off_icon() ). By default, "on" and "off" icons are bright and dim star respectively.

This filter is best suited for rating-based filtering.

Member Function Documentation

FilterOption::SCPtr unity::scopes::RatingFilter::active_rating ( FilterState const &  filter_state) const

Get active option from an instance of FilterState for this filter.

Returns
The active option or nullptr if no option is active.
FilterOption::SCPtr unity::scopes::RatingFilter::add_option ( std::string const &  id,
std::string const &  label 
)

Adds a new option to the filter.

Parameters
idA unique identifier of the option.
labelA display label for the option
Returns
Instance of FilterOption
RatingFilter::UPtr unity::scopes::RatingFilter::create ( std::string const &  id,
std::string const &  label 
)
static

Creates RatingFilter widget.

Creates an empty RatingFilter widget. Use unity::scopes::RatingFilter::add_option() to add rating options to it.

Parameters
idA unique identifier for the filter that can be used to identify it later among several filters.
labelA display label for this filter
Returns
Instance of RatingFilter
RatingFilter::UPtr unity::scopes::RatingFilter::create ( std::string const &  id,
std::string const &  label,
int  top_rating 
)
static

Creates RatingFilter widget.

Creates a RatingFilter widget and populates it with some standard rating options. This is a convienience factory method, that fills RatingFilter in with options for ratings from 1 up to top_rating. Options are created with identifiers "1", "2" and so on, and labels "1+", "2+" etc., except for that last label, which is just the number (no plus sign). The maximum top_rating allowed is 10.

Parameters
idA unique identifier for the filter that can be used to identify it later among several filters.
labelA display label for this filter
top_ratingThe maximum rating allowed.
Returns
Instance of RatingFilter
bool unity::scopes::RatingFilter::has_active_rating ( FilterState const &  filter_state) const

Check if a rating option is active.

Parameters
filter_stateThe state of filters
Returns
true if a rating option is active.
std::string unity::scopes::RatingFilter::label ( ) const

Get the label of this filter.

Returns
The filter label.
std::string unity::scopes::RatingFilter::off_icon ( ) const

Get custom icon for the "off" state.

If empty, then the default icon will be used.

Returns
icon uri or empty string
std::string unity::scopes::RatingFilter::on_icon ( ) const

Get custom icon for the "on" state.

If empty, then the default icon will be used.

Returns
icon uri or empty string
std::list< FilterOption::SCPtr > unity::scopes::RatingFilter::options ( ) const

Get all options of this filter, in the order they were added.

Returns
The list of options.
void unity::scopes::RatingFilter::set_off_icon ( std::string const &  off_icon)

Set a custom icon for the "off" state.

If not set, a dim star icon will be used by default.

Parameters
off_iconicon uri
void unity::scopes::RatingFilter::set_on_icon ( std::string const &  on_icon)

Set a custom icon for the "on" state.

If not set, a star icon will be used by default.

Parameters
on_iconicon uri
void unity::scopes::RatingFilter::update_state ( FilterState filter_state,
FilterOption::SCPtr  option,
bool  active 
) const

Marks given FilterOption of this filter instance as active (or not active) in a FilterState object.

Records the given FilterOption as "selected" in the FilterState. This is meant to be used to modify a FilterState received with a search request before sending it back to the client (UI shell). Only one option can be active at a time - marking an option active automatically deactivates any other option.

void unity::scopes::RatingFilter::update_state ( FilterState filter_state,
std::string const &  filter_id,
std::string const &  option_id,
bool  value 
)
static

Marks an option of a filter active/inactive in a FilterState object, without having an instance of OptionSelectorFilter.

Updates an instance of FilterState, without the need for an OptionSelectorFilter instance. This is meant to be used when creating a canned Query that references another scope.


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