Merge lp:~marcustomlinson/unity-js-scopes/filters into lp:unity-js-scopes

Proposed by Marcus Tomlinson
Status: Work in progress
Proposed branch: lp:~marcustomlinson/unity-js-scopes/filters
Merge into: lp:unity-js-scopes
Diff against target: 832 lines (+725/-0)
10 files modified
src/bindings/src/addon.cc (+63/-0)
src/bindings/src/filter-group.cc (+39/-0)
src/bindings/src/filter-group.h (+40/-0)
src/bindings/src/range-input-filter.cc (+180/-0)
src/bindings/src/range-input-filter.h (+65/-0)
src/bindings/src/search-reply.cc (+10/-0)
src/bindings/src/value-slider-filter.cc (+131/-0)
src/bindings/src/value-slider-filter.h (+61/-0)
src/bindings/src/value-slider-labels.cc (+90/-0)
src/bindings/src/value-slider-labels.h (+46/-0)
To merge this branch: bzr merge lp:~marcustomlinson/unity-js-scopes/filters
Reviewer Review Type Date Requested Status
WebApps Pending
Review via email: mp+294489@code.launchpad.net

Commit message

Added filters support

To post a comment you must log in.

Unmerged revisions

150. By Marcus Tomlinson

ValueSliderFilter complete

149. By Marcus Tomlinson

RangeInputFilter complete

148. By Marcus Tomlinson

FilterGroup complete

147. By Marcus Tomlinson

ValueSliderLabels complete

146. By Marcus Tomlinson

Fix ValueSliderLabels

145. By Marcus Tomlinson

Fix ValueSliderFilter

144. By Marcus Tomlinson

Fix RangeInputFilter

143. By Marcus Tomlinson

Minimal classes to build

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/bindings/src/addon.cc'
--- src/bindings/src/addon.cc 2016-02-25 13:48:52 +0000
+++ src/bindings/src/addon.cc 2016-05-12 12:10:04 +0000
@@ -37,11 +37,13 @@
37#include "canned-query.h"37#include "canned-query.h"
38#include "categorised-result.h"38#include "categorised-result.h"
39#include "department.h"39#include "department.h"
40#include "filter-group.h"
40#include "online-account-client.h"41#include "online-account-client.h"
41#include "option-selector-filter.h"42#include "option-selector-filter.h"
42#include "preview-query.h"43#include "preview-query.h"
43#include "preview-reply.h"44#include "preview-reply.h"
44#include "preview-widget.h"45#include "preview-widget.h"
46#include "range-input-filter.h"
45#include "scope-base.h"47#include "scope-base.h"
46#include "scope.h"48#include "scope.h"
47#include "search-query.h"49#include "search-query.h"
@@ -49,6 +51,8 @@
49#include "search-metadata.h"51#include "search-metadata.h"
50#include "registry.h"52#include "registry.h"
51#include "result.h"53#include "result.h"
54#include "value-slider-filter.h"
55#include "value-slider-labels.h"
52#include "variant.h"56#include "variant.h"
5357
54// TODO static58// TODO static
@@ -456,6 +460,61 @@
456 .add_member("token_secret", &unity::scopes::OnlineAccountClient::ServiceStatus::token_secret)460 .add_member("token_secret", &unity::scopes::OnlineAccountClient::ServiceStatus::token_secret)
457 .add_member("error", &unity::scopes::OnlineAccountClient::ServiceStatus::error);461 .add_member("error", &unity::scopes::OnlineAccountClient::ServiceStatus::error);
458462
463 v8cpp::Class<FilterGroup> filter_group(isolate);
464 filter_group
465 .set_constructor<std::string, std::string>()
466 .add_method("id", &FilterGroup::id)
467 .add_method("label", &FilterGroup::label);
468
469 v8cpp::Class<RangeInputFilter> range_input_filter(isolate);
470 range_input_filter
471 .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
472 .add_method("set_display_hints", &RangeInputFilter::set_display_hints)
473 .add_method("display_hints", &RangeInputFilter::display_hints)
474 .add_method("id", &RangeInputFilter::id)
475 .add_method("filter_type", &RangeInputFilter::filter_type)
476 .add_method("set_title", &RangeInputFilter::set_title)
477 .add_method("title", &RangeInputFilter::title)
478 .add_method("filter_group", &RangeInputFilter::filter_group)
479 .add_method("start_prefix_label", &RangeInputFilter::start_prefix_label)
480 .add_method("start_postfix_label", &RangeInputFilter::start_postfix_label)
481 .add_method("end_prefix_label", &RangeInputFilter::end_prefix_label)
482 .add_method("end_postfix_label", &RangeInputFilter::end_postfix_label)
483 .add_method("central_label", &RangeInputFilter::central_label)
484 .add_method("default_start_value", &RangeInputFilter::default_start_value)
485 .add_method("default_end_value", &RangeInputFilter::default_end_value)
486 .add_method("has_start_value", &RangeInputFilter::has_start_value)
487 .add_method("has_end_value", &RangeInputFilter::has_end_value)
488 .add_method("start_value", &RangeInputFilter::start_value)
489 .add_method("end_value", &RangeInputFilter::end_value)
490 .add_method("update_state", &RangeInputFilter::update_state);
491
492 v8cpp::Class<ValueSliderFilter> value_slider_filter(isolate);
493 value_slider_filter
494 .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
495 .add_method("set_display_hints", &ValueSliderFilter::set_display_hints)
496 .add_method("display_hints", &ValueSliderFilter::display_hints)
497 .add_method("id", &ValueSliderFilter::id)
498 .add_method("filter_type", &ValueSliderFilter::filter_type)
499 .add_method("set_title", &ValueSliderFilter::set_title)
500 .add_method("title", &ValueSliderFilter::title)
501 .add_method("filter_group", &ValueSliderFilter::filter_group)
502 .add_method("set_default_value", &ValueSliderFilter::set_default_value)
503 .add_method("default_value", &ValueSliderFilter::default_value)
504 .add_method("min", &ValueSliderFilter::min)
505 .add_method("max", &ValueSliderFilter::max)
506 .add_method("has_value", &ValueSliderFilter::has_value)
507 .add_method("value", &ValueSliderFilter::value)
508 .add_method("labels", &ValueSliderFilter::labels)
509 .add_method("update_state", &ValueSliderFilter::update_state);
510
511 v8cpp::Class<ValueSliderLabels> value_slider_labels(isolate);
512 value_slider_labels
513 .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
514 .add_method("min_label", &ValueSliderLabels::min_label)
515 .add_method("max_label", &ValueSliderLabels::max_label)
516 .add_method("extra_labels", &ValueSliderLabels::extra_labels);
517
459 v8cpp::Module module(isolate);518 v8cpp::Module module(isolate);
460 module.add_class("js_scope", js_scope);519 module.add_class("js_scope", js_scope);
461 module.add_class("scope_base", scope_base);520 module.add_class("scope_base", scope_base);
@@ -468,6 +527,7 @@
468 module.add_class("CategoryRenderer", category_renderer);527 module.add_class("CategoryRenderer", category_renderer);
469 module.add_class("ColumnLayout", column_layout);528 module.add_class("ColumnLayout", column_layout);
470 module.add_class("Department", department);529 module.add_class("Department", department);
530 module.add_class("FilterGroup", filter_group);
471 module.add_class("FilterOption", filter_option);531 module.add_class("FilterOption", filter_option);
472 module.add_class("FilterState", filter_state);532 module.add_class("FilterState", filter_state);
473 module.add_class("Location", location);533 module.add_class("Location", location);
@@ -478,12 +538,15 @@
478 module.add_class("PreviewWidget", preview_widget);538 module.add_class("PreviewWidget", preview_widget);
479 module.add_class("PreviewQuery", preview_query);539 module.add_class("PreviewQuery", preview_query);
480 module.add_class("PreviewReply", preview_reply);540 module.add_class("PreviewReply", preview_reply);
541 module.add_class("RangeInputFilter", range_input_filter);
481 module.add_class("Registry", registry);542 module.add_class("Registry", registry);
482 module.add_class("Result", result);543 module.add_class("Result", result);
483 module.add_class("ScopeMetadata", scope_metadata);544 module.add_class("ScopeMetadata", scope_metadata);
484 module.add_class("SearchReply", search_reply);545 module.add_class("SearchReply", search_reply);
485 module.add_class("SearchQuery", search_query);546 module.add_class("SearchQuery", search_query);
486 module.add_class("SearchMetadata", search_metadata);547 module.add_class("SearchMetadata", search_metadata);
548 module.add_class("ValueSliderFilter", value_slider_filter);
549 module.add_class("ValueSliderLabels", value_slider_labels);
487 module.add_class("Variant", variant);550 module.add_class("Variant", variant);
488 module.add_class("VariantBase", variant_base);551 module.add_class("VariantBase", variant_base);
489552
490553
=== added file 'src/bindings/src/filter-group.cc'
--- src/bindings/src/filter-group.cc 1970-01-01 00:00:00 +0000
+++ src/bindings/src/filter-group.cc 2016-05-12 12:10:04 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "filter-group.h"
20
21
22FilterGroup::FilterGroup(std::string const& id, std::string const& label)
23 : filter_group_(unity::scopes::FilterGroup::create(id, label)){
24}
25
26std::string FilterGroup::id() const
27{
28 return filter_group_->id();
29}
30
31std::string FilterGroup::label() const
32{
33 return filter_group_->label();
34}
35
36unity::scopes::FilterGroup::SCPtr FilterGroup::get_filter_group() const
37{
38 return filter_group_;
39}
040
=== added file 'src/bindings/src/filter-group.h'
--- src/bindings/src/filter-group.h 1970-01-01 00:00:00 +0000
+++ src/bindings/src/filter-group.h 2016-05-12 12:10:04 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _UNITY_JS_FILTER_GROUP_H_
20#define _UNITY_JS_FILTER_GROUP_H_
21
22#include <unity/scopes/FilterGroup.h>
23
24class FilterGroup
25{
26public:
27 FilterGroup(std::string const& id, std::string const& label);
28
29 std::string id() const;
30 std::string label() const;
31
32 unity::scopes::FilterGroup::SCPtr get_filter_group() const;
33
34private:
35 unity::scopes::FilterGroup::SCPtr filter_group_;
36};
37
38#endif // _UNITY_JS_FILTER_GROUP_H_
39
40
041
=== added file 'src/bindings/src/range-input-filter.cc'
--- src/bindings/src/range-input-filter.cc 1970-01-01 00:00:00 +0000
+++ src/bindings/src/range-input-filter.cc 2016-05-12 12:10:04 +0000
@@ -0,0 +1,180 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "common.h"
20#include "range-input-filter.h"
21
22RangeInputFilter::RangeInputFilter(v8::FunctionCallbackInfo<v8::Value> const& args)
23{
24 if (args.Length() == 6)
25 {
26 auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
27 auto b = v8cpp::from_v8<std::string>(args.GetIsolate(), args[1]);
28 auto c = v8cpp::from_v8<std::string>(args.GetIsolate(), args[2]);
29 auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
30 auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
31 auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
32
33 filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f);
34 }
35 else if (args.Length() == 7)
36 {
37 auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
38 auto b = v8cpp::from_v8<std::string>(args.GetIsolate(), args[1]);
39 auto c = v8cpp::from_v8<std::string>(args.GetIsolate(), args[2]);
40 auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
41 auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
42 auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
43 auto g = v8cpp::from_v8<std::shared_ptr<FilterGroup>>(args.GetIsolate(), args[6]);
44
45 filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f, g->get_filter_group());
46 filter_group_ = g;
47 }
48 else if (args.Length() == 8)
49 {
50 auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
51 auto b = unity::scopesjs::to_variant(args[1]);
52 auto c = unity::scopesjs::to_variant(args[2]);
53 auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
54 auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
55 auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
56 auto g = v8cpp::from_v8<std::string>(args.GetIsolate(), args[6]);
57 auto h = v8cpp::from_v8<std::string>(args.GetIsolate(), args[7]);
58
59 filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f, g, h);
60 }
61 else if (args.Length() == 9)
62 {
63 auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
64 auto b = unity::scopesjs::to_variant(args[1]);
65 auto c = unity::scopesjs::to_variant(args[2]);
66 auto d = v8cpp::from_v8<std::string>(args.GetIsolate(), args[3]);
67 auto e = v8cpp::from_v8<std::string>(args.GetIsolate(), args[4]);
68 auto f = v8cpp::from_v8<std::string>(args.GetIsolate(), args[5]);
69 auto g = v8cpp::from_v8<std::string>(args.GetIsolate(), args[6]);
70 auto h = v8cpp::from_v8<std::string>(args.GetIsolate(), args[7]);
71 auto i = v8cpp::from_v8<std::shared_ptr<FilterGroup>>(args.GetIsolate(), args[8]);
72
73 filter_ = unity::scopes::RangeInputFilter::create(a, b, c, d, e, f, g, h, i->get_filter_group());
74 filter_group_ = i;
75 }
76 else
77 {
78 throw std::runtime_error("Invalid number of arguments");
79 }
80}
81
82void RangeInputFilter::set_display_hints(int hints)
83{
84 filter_->set_display_hints(hints);
85}
86
87int RangeInputFilter::display_hints() const
88{
89 return filter_->display_hints();
90}
91
92std::string RangeInputFilter::id() const
93{
94 return filter_->id();
95}
96
97std::string RangeInputFilter::filter_type() const
98{
99 return filter_->filter_type();
100}
101
102void RangeInputFilter::set_title(std::string const& title)
103{
104 filter_->set_title(title);
105}
106
107std::string RangeInputFilter::title() const
108{
109 return filter_->title();
110}
111
112std::shared_ptr<FilterGroup> RangeInputFilter::filter_group() const
113{
114 return filter_group_;
115}
116
117std::string RangeInputFilter::start_prefix_label() const
118{
119 return filter_->start_prefix_label();
120}
121
122std::string RangeInputFilter::start_postfix_label() const
123{
124 return filter_->start_postfix_label();
125}
126
127std::string RangeInputFilter::end_prefix_label() const
128{
129 return filter_->end_prefix_label();
130}
131
132std::string RangeInputFilter::end_postfix_label() const
133{
134 return filter_->end_postfix_label();
135}
136
137std::string RangeInputFilter::central_label() const
138{
139 return filter_->central_label();
140}
141
142unity::scopes::Variant RangeInputFilter::default_start_value() const
143{
144 return filter_->default_start_value();
145}
146
147unity::scopes::Variant RangeInputFilter::default_end_value() const
148{
149 return filter_->default_end_value();
150}
151
152bool RangeInputFilter::has_start_value(unity::scopes::FilterState const& filter_state) const
153{
154 return filter_->has_start_value(filter_state);
155}
156
157bool RangeInputFilter::has_end_value(unity::scopes::FilterState const& filter_state) const
158{
159 return filter_->has_end_value(filter_state);
160}
161
162double RangeInputFilter::start_value(unity::scopes::FilterState const& filter_state) const
163{
164 return filter_->start_value(filter_state);
165}
166
167double RangeInputFilter::end_value(unity::scopes::FilterState const& filter_state) const
168{
169 return filter_->end_value(filter_state);
170}
171
172void RangeInputFilter::update_state(unity::scopes::FilterState& filter_state, unity::scopes::Variant const& start_value, unity::scopes::Variant const& end_value) const
173{
174 return filter_->update_state(filter_state, start_value, end_value);
175}
176
177unity::scopes::RangeInputFilter::SPtr RangeInputFilter::get_filter()
178{
179 return filter_;
180}
0181
=== added file 'src/bindings/src/range-input-filter.h'
--- src/bindings/src/range-input-filter.h 1970-01-01 00:00:00 +0000
+++ src/bindings/src/range-input-filter.h 2016-05-12 12:10:04 +0000
@@ -0,0 +1,65 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _UNITY_JS_RANGE_INPUT_FILTER_H_
20#define _UNITY_JS_RANGE_INPUT_FILTER_H_
21
22#include "filter-group.h"
23
24#include <unity/scopes/RangeInputFilter.h>
25
26#include <v8-cpp.h>
27
28class RangeInputFilter
29{
30public:
31 RangeInputFilter(v8::FunctionCallbackInfo<v8::Value> const& args);
32
33 // FilterBase
34 void set_display_hints(int hints);
35 int display_hints() const;
36 std::string id() const;
37 std::string filter_type() const;
38 void set_title(std::string const& title);
39 std::string title() const;
40 std::shared_ptr<FilterGroup> filter_group() const;
41
42 // RangeInputFilter
43 std::string start_prefix_label() const;
44 std::string start_postfix_label() const;
45 std::string end_prefix_label() const;
46 std::string end_postfix_label() const;
47 std::string central_label() const;
48 unity::scopes::Variant default_start_value() const;
49 unity::scopes::Variant default_end_value() const;
50 bool has_start_value(unity::scopes::FilterState const& filter_state) const;
51 bool has_end_value(unity::scopes::FilterState const& filter_state) const;
52 double start_value(unity::scopes::FilterState const& filter_state) const;
53 double end_value(unity::scopes::FilterState const& filter_state) const;
54 void update_state(unity::scopes::FilterState& filter_state, unity::scopes::Variant const& start_value, unity::scopes::Variant const& end_value) const;
55
56 unity::scopes::RangeInputFilter::SPtr get_filter();
57
58private:
59 unity::scopes::RangeInputFilter::SPtr filter_;
60 std::shared_ptr<FilterGroup> filter_group_;
61};
62
63#endif // _UNITY_JS_RANGE_INPUT_FILTER_H_
64
65
066
=== modified file 'src/bindings/src/search-reply.cc'
--- src/bindings/src/search-reply.cc 2015-11-08 15:49:12 +0000
+++ src/bindings/src/search-reply.cc 2016-05-12 12:10:04 +0000
@@ -20,6 +20,8 @@
2020
21#include "categorised-result.h"21#include "categorised-result.h"
22#include "option-selector-filter.h"22#include "option-selector-filter.h"
23#include "range-input-filter.h"
24#include "value-slider-filter.h"
2325
24#include <stdexcept>26#include <stdexcept>
2527
@@ -42,6 +44,14 @@
42 auto f = v8cpp::from_v8<std::shared_ptr<OptionSelectorFilter>>(isolate, fv);44 auto f = v8cpp::from_v8<std::shared_ptr<OptionSelectorFilter>>(isolate, fv);
43 filter_bases.push_back(f->get_filter());45 filter_bases.push_back(f->get_filter());
44 } catch(...) { }46 } catch(...) { }
47 try {
48 auto f = v8cpp::from_v8<std::shared_ptr<RangeInputFilter>>(isolate, fv);
49 filter_bases.push_back(f->get_filter());
50 } catch(...) { }
51 try {
52 auto f = v8cpp::from_v8<std::shared_ptr<ValueSliderFilter>>(isolate, fv);
53 filter_bases.push_back(f->get_filter());
54 } catch(...) { }
45 }55 }
46 return filter_bases;56 return filter_bases;
47}57}
4858
=== added file 'src/bindings/src/value-slider-filter.cc'
--- src/bindings/src/value-slider-filter.cc 1970-01-01 00:00:00 +0000
+++ src/bindings/src/value-slider-filter.cc 2016-05-12 12:10:04 +0000
@@ -0,0 +1,131 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "value-slider-filter.h"
20
21ValueSliderFilter::ValueSliderFilter(v8::FunctionCallbackInfo<v8::Value> const& args)
22{
23 if (args.Length() == 5)
24 {
25 auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
26 auto b = v8cpp::from_v8<double>(args.GetIsolate(), args[1]);
27 auto c = v8cpp::from_v8<double>(args.GetIsolate(), args[2]);
28 auto d = v8cpp::from_v8<double>(args.GetIsolate(), args[3]);
29 auto e = v8cpp::from_v8<std::shared_ptr<ValueSliderLabels>>(args.GetIsolate(), args[4]);
30
31 filter_ = unity::scopes::ValueSliderFilter::create(a, b, c, d, e->get_labels());
32 labels_ = e;
33 }
34 else if (args.Length() == 6)
35 {
36 auto a = v8cpp::from_v8<std::string>(args.GetIsolate(), args[0]);
37 auto b = v8cpp::from_v8<double>(args.GetIsolate(), args[1]);
38 auto c = v8cpp::from_v8<double>(args.GetIsolate(), args[2]);
39 auto d = v8cpp::from_v8<double>(args.GetIsolate(), args[3]);
40 auto e = v8cpp::from_v8<std::shared_ptr<ValueSliderLabels>>(args.GetIsolate(), args[4]);
41 auto f = v8cpp::from_v8<std::shared_ptr<FilterGroup>>(args.GetIsolate(), args[5]);
42
43 filter_ = unity::scopes::ValueSliderFilter::create(a, b, c, d, e->get_labels(), f->get_filter_group());
44 labels_ = e;
45 filter_group_ = f;
46 }
47 else
48 {
49 throw std::runtime_error("Invalid number of arguments");
50 }
51}
52
53void ValueSliderFilter::set_display_hints(int hints)
54{
55 filter_->set_display_hints(hints);
56}
57
58int ValueSliderFilter::display_hints() const
59{
60 return filter_->display_hints();
61}
62
63std::string ValueSliderFilter::id() const
64{
65 return filter_->id();
66}
67
68std::string ValueSliderFilter::filter_type() const
69{
70 return filter_->filter_type();
71}
72
73void ValueSliderFilter::set_title(std::string const& title)
74{
75 return filter_->set_title(title);
76}
77
78std::string ValueSliderFilter::title() const
79{
80 return filter_->title();
81}
82
83std::shared_ptr<FilterGroup> ValueSliderFilter::filter_group() const
84{
85 return filter_group_;
86}
87
88void ValueSliderFilter::set_default_value(double val)
89{
90 return filter_->set_default_value(val);
91}
92
93double ValueSliderFilter::default_value() const
94{
95 return filter_->default_value();
96}
97
98double ValueSliderFilter::min() const
99{
100 return filter_->min();
101}
102
103double ValueSliderFilter::max() const
104{
105 return filter_->max();
106}
107
108bool ValueSliderFilter::has_value(unity::scopes::FilterState const& filter_state) const
109{
110 return filter_->has_value(filter_state);
111}
112
113double ValueSliderFilter::value(unity::scopes::FilterState const& filter_state) const
114{
115 return filter_->value(filter_state);
116}
117
118std::shared_ptr<ValueSliderLabels> ValueSliderFilter::labels() const
119{
120 return labels_;
121}
122
123void ValueSliderFilter::update_state(unity::scopes::FilterState& filter_state, double value) const
124{
125 return filter_->update_state(filter_state, value);
126}
127
128unity::scopes::ValueSliderFilter::SPtr ValueSliderFilter::get_filter()
129{
130 return filter_;
131}
0132
=== added file 'src/bindings/src/value-slider-filter.h'
--- src/bindings/src/value-slider-filter.h 1970-01-01 00:00:00 +0000
+++ src/bindings/src/value-slider-filter.h 2016-05-12 12:10:04 +0000
@@ -0,0 +1,61 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _UNITY_JS_VALUE_SLIDER_FILTER_H_
20#define _UNITY_JS_VALUE_SLIDER_FILTER_H_
21
22#include "value-slider-labels.h"
23#include "filter-group.h"
24
25#include <unity/scopes/ValueSliderFilter.h>
26
27class ValueSliderFilter
28{
29public:
30 ValueSliderFilter(v8::FunctionCallbackInfo<v8::Value> const& args);
31
32 // FilterBase
33 void set_display_hints(int hints);
34 int display_hints() const;
35 std::string id() const;
36 std::string filter_type() const;
37 void set_title(std::string const& title);
38 std::string title() const;
39 std::shared_ptr<FilterGroup> filter_group() const;
40
41 // ValueSliderFilter
42 void set_default_value(double val);
43 double default_value() const;
44 double min() const;
45 double max() const;
46 bool has_value(unity::scopes::FilterState const& filter_state) const;
47 double value(unity::scopes::FilterState const& filter_state) const;
48 std::shared_ptr<ValueSliderLabels> labels() const;
49 void update_state(unity::scopes::FilterState& filter_state, double value) const;
50
51 unity::scopes::ValueSliderFilter::SPtr get_filter();
52
53private:
54 unity::scopes::ValueSliderFilter::SPtr filter_;
55 std::shared_ptr<FilterGroup> filter_group_;
56 std::shared_ptr<ValueSliderLabels> labels_;
57};
58
59#endif // _UNITY_JS_VALUE_SLIDER_FILTER_H_
60
61
062
=== added file 'src/bindings/src/value-slider-labels.cc'
--- src/bindings/src/value-slider-labels.cc 1970-01-01 00:00:00 +0000
+++ src/bindings/src/value-slider-labels.cc 2016-05-12 12:10:04 +0000
@@ -0,0 +1,90 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "value-slider-labels.h"
20
21#include "common.h"
22
23//std::string const& min_label, std::string const& max_label, ValueLabelPairList const& extra_labels
24
25ValueSliderLabels::ValueSliderLabels(v8::FunctionCallbackInfo<v8::Value> const& args)
26{
27 if (args.Length() != 2 && args.Length() != 3) {
28 throw std::runtime_error("Invalid number of arguments");
29 }
30 if (!args[0]->IsString()) {
31 throw std::runtime_error("Invalid argument type");
32 }
33 if (!args[1]->IsString()) {
34 throw std::runtime_error("Invalid argument type");
35 }
36
37 std::string min_label =
38 *(v8::String::Utf8Value(args[0]->ToString()));
39
40 std::string max_label =
41 *(v8::String::Utf8Value(args[1]->ToString()));
42
43 if (args.Length() == 3)
44 {
45 ValueLabelPairList extra_labels;
46
47 try
48 {
49 auto extra_labels_a = unity::scopesjs::to_variant(args[2]).get_array();
50
51 for (auto const& label : extra_labels_a)
52 {
53 auto label_pair = label.get_array();
54 if (label_pair.size() == 2)
55 {
56 extra_labels.push_back(ValueLabelPair(label_pair[0].get_double(), label_pair[1].get_string()));
57 }
58 }
59 } catch(...)
60 {
61 throw std::runtime_error("ValueSliderLabels::ValueSliderLabels: Malformed 'extra_labels' argument! Expected format: [[2, \"2\"], [4, \"4\"]]");
62 }
63
64 labels_ = std::make_shared<unity::scopes::ValueSliderLabels>(unity::scopes::ValueSliderLabels(min_label, max_label, extra_labels));
65 }
66 else
67 {
68 labels_ = std::make_shared<unity::scopes::ValueSliderLabels>(unity::scopes::ValueSliderLabels(min_label, max_label));
69 }
70}
71
72std::string ValueSliderLabels::min_label() const
73{
74 return labels_->min_label();
75}
76
77std::string ValueSliderLabels::max_label() const
78{
79 return labels_->max_label();
80}
81
82ValueLabelPairList ValueSliderLabels::extra_labels() const
83{
84 return labels_->extra_labels();
85}
86
87unity::scopes::ValueSliderLabels ValueSliderLabels::get_labels() const
88{
89 return *labels_;
90}
091
=== added file 'src/bindings/src/value-slider-labels.h'
--- src/bindings/src/value-slider-labels.h 1970-01-01 00:00:00 +0000
+++ src/bindings/src/value-slider-labels.h 2016-05-12 12:10:04 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This file is part of unity-js-scopes.
5 *
6 * unity-js-scopes is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * unity-js-scopes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef _UNITY_JS_VALUE_SLIDER_LABELS_H_
20#define _UNITY_JS_VALUE_SLIDER_LABELS_H_
21
22#include <unity/scopes/ValueSliderLabels.h>
23
24#include <v8-cpp.h>
25
26typedef std::pair<double, std::string> ValueLabelPair;
27typedef std::vector<ValueLabelPair> ValueLabelPairList;
28
29class ValueSliderLabels
30{
31public:
32 ValueSliderLabels(v8::FunctionCallbackInfo<v8::Value> const& args);
33
34 std::string min_label() const;
35 std::string max_label() const;
36 ValueLabelPairList extra_labels() const;
37
38 unity::scopes::ValueSliderLabels get_labels() const;
39
40private:
41 std::shared_ptr<unity::scopes::ValueSliderLabels> labels_;
42};
43
44#endif // _UNITY_JS_VALUE_SLIDER_LABELS_H_
45
46

Subscribers

People subscribed via source and target branches

to all changes: