Merge lp:~azzar1/unity/fix-850984 into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 2085
Proposed branch: lp:~azzar1/unity/fix-850984
Merge into: lp:unity
Diff against target: 475 lines (+329/-28)
9 files modified
plugins/unityshell/src/AbstractPlacesGroup.cpp (+44/-0)
plugins/unityshell/src/AbstractPlacesGroup.h (+51/-0)
plugins/unityshell/src/LensView.cpp (+10/-12)
plugins/unityshell/src/LensViewPrivate.cpp (+48/-0)
plugins/unityshell/src/LensViewPrivate.h (+40/-0)
plugins/unityshell/src/PlacesGroup.cpp (+3/-12)
plugins/unityshell/src/PlacesGroup.h (+3/-4)
tests/CMakeLists.txt (+5/-0)
tests/test_lensview_impl.cpp (+125/-0)
To merge this branch: bzr merge lp:~azzar1/unity/fix-850984
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Review via email: mp+96843@code.launchpad.net

Description of the change

The problem
===
Dash - Missing category separator line in dash

The fix
===

17 - bool found_one = false;
18 -
19 - for (rit = children.rbegin(); rit != children.rend(); ++rit)
20 - {
21 - PlacesGroup* group = static_cast<PlacesGroup*>(*rit);
22 -
23 - if (group->IsVisible())
24 - group->SetDrawSeparator(found_one);
25 -
26 - found_one = group->IsVisible();
27 - }

If the next group is not visibile the separator is not shown in the prev group.
This branch fixes it moving the logic side in another (testable) function. I'd love to
remove the static_cast too but I can't find an easy way right now.

The test
===
Adds a unit test for the logic side.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Overall looks very good to me.

133 + std::list<AbstractPlacesGroup*> groups;
134 +
135 + std::transform(children.begin(), children.end(), std::back_inserter(groups),
136 + [](Area* obj) -> AbstractPlacesGroup*
137 + {
138 + return static_cast<AbstractPlacesGroup*>(obj);
139 + });

I this really much more optimized, than using a normal loop? I mean, it's a nice C++ code, but it could look more cryptic than it really is :)

review: Approve
Revision history for this message
Andrea Azzarone (azzar1) wrote :

> Overall looks very good to me.
>
> 133 + std::list<AbstractPlacesGroup*> groups;
> 134 +
> 135 + std::transform(children.begin(), children.end(),
> std::back_inserter(groups),
> 136 + [](Area* obj) -> AbstractPlacesGroup*
> 137 + {
> 138 + return static_cast<AbstractPlacesGroup*>(obj);
> 139 + });
>
> I this really much more optimized, than using a normal loop? I mean, it's a
> nice C++ code, but it could look more cryptic than it really is :)

Not sure, how do you prefer?

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'plugins/unityshell/src/AbstractPlacesGroup.cpp'
2--- plugins/unityshell/src/AbstractPlacesGroup.cpp 1970-01-01 00:00:00 +0000
3+++ plugins/unityshell/src/AbstractPlacesGroup.cpp 2012-03-09 22:07:20 +0000
4@@ -0,0 +1,44 @@
5+/*
6+ * Copyright (C) 2012 Canonical Ltd
7+ *
8+ * This program is free software: you can redistribute it and/or modify
9+ * it under the terms of the GNU General Public License version 3 as
10+ * published by the Free Software Foundation.
11+ *
12+ * This program is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+ * GNU General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU General Public License
18+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19+ *
20+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
21+ */
22+
23+
24+#include "AbstractPlacesGroup.h"
25+
26+namespace unity
27+{
28+namespace dash
29+{
30+
31+NUX_IMPLEMENT_OBJECT_TYPE(AbstractPlacesGroup);
32+
33+AbstractPlacesGroup::AbstractPlacesGroup()
34+ : nux::View(NUX_TRACKER_LOCATION)
35+ , draw_separator(true)
36+{
37+}
38+
39+void AbstractPlacesGroup::Draw(nux::GraphicsEngine&, bool)
40+{
41+}
42+
43+void AbstractPlacesGroup::DrawContent(nux::GraphicsEngine&, bool)
44+{
45+}
46+
47+}
48+}
49
50=== added file 'plugins/unityshell/src/AbstractPlacesGroup.h'
51--- plugins/unityshell/src/AbstractPlacesGroup.h 1970-01-01 00:00:00 +0000
52+++ plugins/unityshell/src/AbstractPlacesGroup.h 2012-03-09 22:07:20 +0000
53@@ -0,0 +1,51 @@
54+/*
55+ * Copyright (C) 2012 Canonical Ltd
56+ *
57+ * This program is free software: you can redistribute it and/or modify
58+ * it under the terms of the GNU General Public License version 3 as
59+ * published by the Free Software Foundation.
60+ *
61+ * This program is distributed in the hope that it will be useful,
62+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
63+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64+ * GNU General Public License for more details.
65+ *
66+ * You should have received a copy of the GNU General Public License
67+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
68+ *
69+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
70+ */
71+
72+
73+#ifndef UNITYSHELL_ABSTRACTPLACESGROUP_H
74+#define UNITYSHELL_ABSTRACTPLACESGROUP_H
75+
76+#include <Nux/Nux.h>
77+#include <Nux/View.h>
78+#include <NuxCore/Property.h>
79+
80+namespace unity
81+{
82+namespace dash
83+{
84+
85+class AbstractPlacesGroup : public nux::View
86+{
87+ NUX_DECLARE_OBJECT_TYPE(AbstractPlacesGroup, nux::View);
88+public:
89+ AbstractPlacesGroup();
90+
91+ // Properties
92+ nux::Property<bool> draw_separator;
93+
94+protected:
95+ void Draw(nux::GraphicsEngine&, bool);
96+ void DrawContent(nux::GraphicsEngine&, bool);
97+
98+};
99+
100+}
101+}
102+
103+#endif
104+
105
106=== modified file 'plugins/unityshell/src/LensView.cpp'
107--- plugins/unityshell/src/LensView.cpp 2012-02-21 20:10:05 +0000
108+++ plugins/unityshell/src/LensView.cpp 2012-03-09 22:07:20 +0000
109@@ -18,6 +18,7 @@
110 */
111
112 #include "LensView.h"
113+#include "LensViewPrivate.h"
114
115 #include <boost/lexical_cast.hpp>
116
117@@ -345,18 +346,15 @@
118 gboolean LensView::FixRenderering(LensView* self)
119 {
120 std::list<Area*> children = self->scroll_layout_->GetChildren();
121- std::list<Area*>::reverse_iterator rit;
122- bool found_one = false;
123-
124- for (rit = children.rbegin(); rit != children.rend(); ++rit)
125- {
126- PlacesGroup* group = static_cast<PlacesGroup*>(*rit);
127-
128- if (group->IsVisible())
129- group->SetDrawSeparator(found_one);
130-
131- found_one = group->IsVisible();
132- }
133+ std::list<AbstractPlacesGroup*> groups;
134+
135+ std::transform(children.begin(), children.end(), std::back_inserter(groups),
136+ [](Area* obj) -> AbstractPlacesGroup*
137+ {
138+ return static_cast<AbstractPlacesGroup*>(obj);
139+ });
140+
141+ dash::impl::UpdateDrawSeparators(groups);
142
143 self->fix_renderering_id_ = 0;
144 return FALSE;
145
146=== added file 'plugins/unityshell/src/LensViewPrivate.cpp'
147--- plugins/unityshell/src/LensViewPrivate.cpp 1970-01-01 00:00:00 +0000
148+++ plugins/unityshell/src/LensViewPrivate.cpp 2012-03-09 22:07:20 +0000
149@@ -0,0 +1,48 @@
150+/*
151+ * Copyright (C) 2012 Canonical Ltd
152+ *
153+ * This program is free software: you can redistribute it and/or modify
154+ * it under the terms of the GNU General Public License version 3 as
155+ * published by the Free Software Foundation.
156+ *
157+ * This program is distributed in the hope that it will be useful,
158+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
159+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
160+ * GNU General Public License for more details.
161+ *
162+ * You should have received a copy of the GNU General Public License
163+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
164+ *
165+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
166+ */
167+
168+#include "LensViewPrivate.h"
169+#include "AbstractPlacesGroup.h"
170+
171+namespace unity
172+{
173+namespace dash
174+{
175+namespace impl
176+{
177+
178+void UpdateDrawSeparators(std::list<AbstractPlacesGroup*> groups)
179+{
180+ std::list<AbstractPlacesGroup*>::reverse_iterator rit;
181+ bool found_one = false;
182+
183+ for (rit = groups.rbegin(); rit != groups.rend(); ++rit)
184+ {
185+ if ((*rit)->IsVisible())
186+ {
187+ (*rit)->draw_separator = found_one;
188+ found_one = true;
189+ }
190+ }
191+}
192+
193+}
194+}
195+}
196+
197+
198
199=== added file 'plugins/unityshell/src/LensViewPrivate.h'
200--- plugins/unityshell/src/LensViewPrivate.h 1970-01-01 00:00:00 +0000
201+++ plugins/unityshell/src/LensViewPrivate.h 2012-03-09 22:07:20 +0000
202@@ -0,0 +1,40 @@
203+/*
204+ * Copyright (C) 2012 Canonical Ltd
205+ *
206+ * This program is free software: you can redistribute it and/or modify
207+ * it under the terms of the GNU General Public License version 3 as
208+ * published by the Free Software Foundation.
209+ *
210+ * This program is distributed in the hope that it will be useful,
211+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
212+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
213+ * GNU General Public License for more details.
214+ *
215+ * You should have received a copy of the GNU General Public License
216+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
217+ *
218+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
219+ */
220+
221+#ifndef UNITYSHELL_LENS_VIEW_PRIVATE_H
222+#define UNITYSHELL_LENS_VIEW_PRIVATE_H
223+
224+#include <list>
225+
226+namespace unity
227+{
228+namespace dash
229+{
230+
231+class AbstractPlacesGroup;
232+
233+namespace impl
234+{
235+
236+void UpdateDrawSeparators(std::list<AbstractPlacesGroup*> groups);
237+
238+} // namespace impl
239+} // namespace dash
240+} // namespace unity
241+
242+#endif
243
244=== modified file 'plugins/unityshell/src/PlacesGroup.cpp'
245--- plugins/unityshell/src/PlacesGroup.cpp 2012-02-23 05:16:34 +0000
246+++ plugins/unityshell/src/PlacesGroup.cpp 2012-03-09 22:07:20 +0000
247@@ -106,14 +106,13 @@
248 NUX_IMPLEMENT_OBJECT_TYPE(PlacesGroup);
249
250 PlacesGroup::PlacesGroup()
251- : View(NUX_TRACKER_LOCATION),
252+ : AbstractPlacesGroup(),
253 _child_view(nullptr),
254 _focus_layer(nullptr),
255 _idle_id(0),
256 _is_expanded(true),
257 _n_visible_items_in_unexpand_mode(0),
258- _n_total_items(0),
259- _draw_sep(true)
260+ _n_total_items(0)
261 {
262 SetAcceptKeyNavFocusOnMouseDown(false);
263 SetAcceptKeyNavFocusOnMouseEnter(false);
264@@ -380,7 +379,7 @@
265 graphics_engine.GetRenderStates().SetBlend(true);
266 graphics_engine.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
267
268- if (_draw_sep)
269+ if (draw_separator)
270 {
271 nux::Color col(0.15f, 0.15f, 0.15f, 0.15f);
272
273@@ -488,14 +487,6 @@
274 return _header_layout->GetGeometry().height;
275 }
276
277-void
278-PlacesGroup::SetDrawSeparator(bool draw_it)
279-{
280- _draw_sep = draw_it;
281-
282- QueueDraw();
283-}
284-
285 bool PlacesGroup::HeaderHasKeyFocus() const
286 {
287 return (_header_view && _header_view->HasKeyFocus());
288
289=== modified file 'plugins/unityshell/src/PlacesGroup.h'
290--- plugins/unityshell/src/PlacesGroup.h 2012-02-13 17:09:05 +0000
291+++ plugins/unityshell/src/PlacesGroup.h 2012-03-09 22:07:20 +0000
292@@ -27,6 +27,7 @@
293
294 #include <sigc++/sigc++.h>
295
296+#include "AbstractPlacesGroup.h"
297 #include "IconTexture.h"
298 #include "Introspectable.h"
299 #include "StaticCairoText.h"
300@@ -40,9 +41,9 @@
301 namespace unity
302 {
303
304-class PlacesGroup : public nux::View , public debug::Introspectable
305+class PlacesGroup : public dash::AbstractPlacesGroup, public debug::Introspectable
306 {
307- NUX_DECLARE_OBJECT_TYPE(PlacesGroup, nux::View);
308+ NUX_DECLARE_OBJECT_TYPE(PlacesGroup, dash::AbstractPlacesGroup);
309 public:
310
311 PlacesGroup();
312@@ -70,8 +71,6 @@
313 bool HeaderIsFocusable() const;
314 nux::View* GetHeaderFocusableView() const;
315
316- void SetDrawSeparator(bool draw_it);
317-
318 sigc::signal<void, PlacesGroup*> expanded;
319
320 protected:
321
322=== modified file 'tests/CMakeLists.txt'
323--- tests/CMakeLists.txt 2012-03-08 13:25:07 +0000
324+++ tests/CMakeLists.txt 2012-03-09 22:07:20 +0000
325@@ -123,8 +123,11 @@
326 test_main_xless.cpp
327 test_grabhandle.cpp
328 test_unityshell_private.cpp
329+ test_lensview_impl.cpp
330 ${UNITY_SRC}/AbstractLauncherIcon.h
331 ${UNITY_SRC}/AbstractLauncherIcon.cpp
332+ ${UNITY_SRC}/AbstractPlacesGroup.cpp
333+ ${UNITY_SRC}/AbstractPlacesGroup.h
334 ${UNITY_SRC}/AbstractShortcutHint.h
335 ${UNITY_SRC}/Animator.cpp
336 ${UNITY_SRC}/Animator.h
337@@ -140,6 +143,8 @@
338 ${UNITY_SRC}/IconTextureSource.cpp
339 ${UNITY_SRC}/LauncherModel.cpp
340 ${UNITY_SRC}/LauncherModel.h
341+ ${UNITY_SRC}/LensViewPrivate.cpp
342+ ${UNITY_SRC}/LensViewPrivate.h
343 ${UNITY_SRC}/FavoriteStorePrivate.cpp
344 ${UNITY_SRC}/FavoriteStorePrivate.h
345 ${UNITY_SRC}/MockLauncherIcon.h
346
347=== added file 'tests/test_lensview_impl.cpp'
348--- tests/test_lensview_impl.cpp 1970-01-01 00:00:00 +0000
349+++ tests/test_lensview_impl.cpp 2012-03-09 22:07:20 +0000
350@@ -0,0 +1,125 @@
351+/*
352+ * Copyright (C) 2012 Canonical Ltd
353+ *
354+ * This program is free software: you can redistribute it and/or modify
355+ * it under the terms of the GNU General Public License version 3 as
356+ * published by the Free Software Foundation.
357+ *
358+ * This program is distributed in the hope that it will be useful,
359+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
360+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
361+ * GNU General Public License for more details.
362+ *
363+ * You should have received a copy of the GNU General Public License
364+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
365+ *
366+ * Authored by: Andrea Azzarone <azzaronea@gmail.com>
367+ */
368+
369+#include <list>
370+#include <vector>
371+
372+#include <gmock/gmock.h>
373+
374+#include "LensViewPrivate.h"
375+#include "AbstractPlacesGroup.h"
376+
377+using namespace unity;
378+using namespace testing;
379+
380+namespace
381+{
382+
383+const int NUM_GROUPS = 4;
384+
385+class TestPlacesGroupImpl : public Test
386+{
387+public:
388+ TestPlacesGroupImpl()
389+ {
390+ for (int i=0; i<NUM_GROUPS; ++i)
391+ groups_vector.push_back(new dash::AbstractPlacesGroup);
392+ }
393+
394+ ~TestPlacesGroupImpl()
395+ {
396+ for (int i=0; i<NUM_GROUPS; ++i)
397+ delete groups_vector[i];
398+ }
399+
400+ std::list<dash::AbstractPlacesGroup*> GetList()
401+ {
402+ std::list<dash::AbstractPlacesGroup*> ret;
403+ std::copy(groups_vector.begin(), groups_vector.end(), std::back_inserter(ret));
404+ return ret;
405+ }
406+
407+ std::vector<dash::AbstractPlacesGroup*> groups_vector;
408+};
409+
410+
411+TEST_F(TestPlacesGroupImpl, TestUpdateDrawSeparatorsEmpty)
412+{
413+ std::list<dash::AbstractPlacesGroup*> groups;
414+
415+ // Just to make sure it doesn't crash.
416+ dash::impl::UpdateDrawSeparators(groups);
417+}
418+
419+TEST_F(TestPlacesGroupImpl, TestUpdateDrawSeparatorsAllVisible)
420+{
421+ groups_vector[0]->SetVisible(true);
422+ groups_vector[1]->SetVisible(true);
423+ groups_vector[2]->SetVisible(true);
424+ groups_vector[3]->SetVisible(true);
425+
426+ dash::impl::UpdateDrawSeparators(GetList());
427+
428+ EXPECT_TRUE(groups_vector[0]->draw_separator);
429+ EXPECT_TRUE(groups_vector[1]->draw_separator);
430+ EXPECT_TRUE(groups_vector[2]->draw_separator);
431+ EXPECT_FALSE(groups_vector[3]->draw_separator);
432+}
433+
434+TEST_F(TestPlacesGroupImpl, TestUpdateDrawSeparatorsLastInvisible)
435+{
436+ groups_vector[0]->SetVisible(true);
437+ groups_vector[1]->SetVisible(true);
438+ groups_vector[2]->SetVisible(true);
439+ groups_vector[3]->SetVisible(false);
440+
441+ dash::impl::UpdateDrawSeparators(GetList());
442+
443+ EXPECT_TRUE(groups_vector[0]->draw_separator);
444+ EXPECT_TRUE(groups_vector[1]->draw_separator);
445+ EXPECT_FALSE(groups_vector[2]->draw_separator);
446+}
447+
448+TEST_F(TestPlacesGroupImpl, TestUpdateDrawSeparatorsLastTwoInvisible)
449+{
450+ groups_vector[0]->SetVisible(true);
451+ groups_vector[1]->SetVisible(true);
452+ groups_vector[2]->SetVisible(false);
453+ groups_vector[3]->SetVisible(false);
454+
455+ dash::impl::UpdateDrawSeparators(GetList());
456+
457+ EXPECT_TRUE(groups_vector[0]->draw_separator);
458+ EXPECT_FALSE(groups_vector[1]->draw_separator);
459+}
460+
461+TEST_F(TestPlacesGroupImpl, TestUpdateDrawSeparators)
462+{
463+ groups_vector[0]->SetVisible(true);
464+ groups_vector[1]->SetVisible(false);
465+ groups_vector[2]->SetVisible(false);
466+ groups_vector[3]->SetVisible(true);
467+
468+ dash::impl::UpdateDrawSeparators(GetList());
469+
470+ EXPECT_TRUE(groups_vector[0]->draw_separator);
471+ EXPECT_FALSE(groups_vector[3]->draw_separator);
472+}
473+
474+}
475+