neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_item_presentation_model.hpp
Go to the documentation of this file.
1// i_item_presentation_model.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program 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, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <boost/format.hpp>
25#include <neogfx/gfx/color.hpp>
33
34namespace neogfx
35{
36 class i_drag_drop_item;
37 class i_drag_drop_target;
38
39 enum class item_cell_flags : uint32_t
40 {
41 Invalid = 0x00000000,
42 Enabled = 0x00000001,
43 Selectable = 0x00000002,
44 Editable = 0x00000004,
45 EditableWhenFocused = 0x00000008,
46 EditableOnInputEvent = 0x00000010,
47 Checkable = 0x00000020,
48 CheckableBiState = 0x00000040,
49 CheckableTriState = 0x00000080,
50 Draggable = 0x00001000,
51 Droppable = 0x00002000,
52
54 };
55
56 typedef std::optional<item_cell_flags> optional_item_cell_flags;
57
58 enum class item_cell_selection_flags : uint8_t
59 {
60 None = 0x00,
61 Current = 0x01,
62 Selected = 0x02
63 };
64}
65
78
79namespace neogfx
80{
82 {
83 return static_cast<item_cell_flags>(static_cast<uint32_t>(lhs) | static_cast<uint32_t>(rhs));
84 }
85
87 {
88 return static_cast<item_cell_flags>(static_cast<uint32_t>(lhs)& static_cast<uint32_t>(rhs));
89 }
90
92 {
93 lhs = lhs | rhs;
94 return lhs;
95 }
96
98 {
99 lhs = lhs & rhs;
100 return lhs;
101 }
102
104 {
105 return static_cast<item_cell_flags>(~static_cast<uint32_t>(flags));
106 }
107
109 {
110 return static_cast<item_cell_selection_flags>(static_cast<uint32_t>(aLhs) | static_cast<uint32_t>(aRhs));
111 }
112
114 {
115 return static_cast<item_cell_selection_flags>(static_cast<uint32_t>(aLhs) & static_cast<uint32_t>(aRhs));
116 }
117
119 {
120 return static_cast<item_cell_selection_flags>(static_cast<uint32_t>(aLhs) ^ static_cast<uint32_t>(aRhs));
121 }
122
124 {
125 lhs = lhs | rhs;
126 return lhs;
127 }
128
130 {
131 lhs = lhs & rhs;
132 return lhs;
133 }
134
136 {
137 lhs = lhs ^ rhs;
138 return lhs;
139 }
140
142 {
143 return static_cast<item_cell_selection_flags>(~static_cast<uint32_t>(aLhs));
144 }
145
146 struct item_presentation_model_index : item_index<item_presentation_model_index>
147 {
148 typedef item_presentation_model_index abstract_type; // todo: create abstract interface
149 using item_index::item_index;
150 };
151 typedef std::optional<item_presentation_model_index> optional_item_presentation_model_index;
152
153 class i_item_sort_predicate
154 {
155 public:
156 virtual ~i_item_sort_predicate() = default;
157 public:
158 virtual bool compare(item_model_index aLhs, item_model_index aRhs) const noexcept = 0;
159 };
160
161 class item_sort_predicate : public i_item_sort_predicate
162 {
163 public:
164 item_sort_predicate(std::function<bool(item_model_index aLhs, item_model_index aRhs)> const& aPredicate) :
165 iPredicate{ aPredicate }
166 {
167 }
168 public:
169 bool compare(item_model_index aLhs, item_model_index aRhs) const noexcept override
170 {
171 return iPredicate(aLhs, aRhs);
172 }
173 private:
174 std::function<bool(item_model_index aLhs, item_model_index aRhs)> iPredicate;
175 };
176
177 class i_item_presentation_model : public i_reference_counted, public i_property_owner
178 {
179 public:
180 declare_event(visual_appearance_changed)
181 declare_event(column_info_changed, item_presentation_model_index::column_type)
182 declare_event(item_model_changed, const i_item_model&)
183 declare_event(item_added, item_presentation_model_index const&)
184 declare_event(item_changed, item_presentation_model_index const&)
185 declare_event(item_removing, item_presentation_model_index const&)
186 declare_event(item_removed, item_presentation_model_index const&)
187 declare_event(item_expanding, item_presentation_model_index const&)
188 declare_event(item_collapsing, item_presentation_model_index const&)
189 declare_event(item_expanded, item_presentation_model_index const&)
190 declare_event(item_collapsed, item_presentation_model_index const&)
191 declare_event(item_toggled, item_presentation_model_index const&)
192 declare_event(item_checked, item_presentation_model_index const&)
193 declare_event(item_unchecked, item_presentation_model_index const&)
194 declare_event(item_indeterminate, item_presentation_model_index const&)
195 declare_event(items_updating)
196 declare_event(items_updated)
197 declare_event(items_sorting)
198 declare_event(items_sorted)
199 declare_event(items_filtering)
200 declare_event(items_filtered)
201 declare_event(dragging_item, i_drag_drop_item const&)
202 declare_event(dragging_item_render_info, i_drag_drop_item const&, bool&, size&)
203 declare_event(dragging_item_render, i_drag_drop_item const&, i_graphics_context&, point const&)
204 declare_event(dragging_item_cancelled, i_drag_drop_item const&)
205 declare_event(item_dropped, i_drag_drop_item const&, i_drag_drop_target&)
206 public:
207 typedef i_item_presentation_model abstract_type;
208 struct cell_meta_type
209 {
211 item_cell_selection_flags selection = item_cell_selection_flags::None;
212 button_checked_state checked = false;
213 bool expanded = false;
215 optional_size extents;
216 };
217 class i_meta_visitor
218 {
219 public:
220 virtual void visit(cell_meta_type& aMeta) = 0;
221 };
222 enum class sort_direction
223 {
224 Ascending,
225 Descending
226 };
227 typedef std::optional<sort_direction> optional_sort_direction;
228 typedef std::pair<item_presentation_model_index::column_type, sort_direction> sort_by_param;
229 typedef std::optional<sort_by_param> optional_sort_by_param;
230 typedef std::string filter_search_key;
231 enum class filter_search_type
232 {
233 Prefix,
234 Glob,
235 Regex
236 };
237 enum class case_sensitivity
238 {
239 CaseInsensitive,
240 CaseSensitive
241 };
242 typedef std::tuple<item_presentation_model_index::column_type, filter_search_key, filter_search_type, case_sensitivity> filter;
243 typedef std::optional<filter> optional_filter;
244 public:
245 struct no_item_model : std::logic_error { no_item_model() : std::logic_error("neogfx::i_item_presentation_model::no_item_model") {} };
246 struct bad_index : std::logic_error { bad_index() : std::logic_error("neogfx::i_item_presentation_model::bad_index") {} };
247 struct no_mapped_row : std::logic_error { no_mapped_row() : std::logic_error("neogfx::i_item_presentation_model::no_mapped_row") {} };
248 struct already_attached : std::logic_error { already_attached() : std::logic_error("neogfx::i_item_presentation_model::already_attached") {} };
249 struct not_attached : std::logic_error { not_attached() : std::logic_error("neogfx::i_item_presentation_model::not_attached") {} };
250 public:
251 virtual ~i_item_presentation_model() = default;
252 public:
253 virtual bool attached() const = 0;
254 virtual i_widget& attachment() const = 0;
255 virtual void attach(i_ref_ptr<i_widget> const& aWidget) = 0;
256 virtual void detach() = 0;
257 public:
258 virtual bool updating() const = 0;
259 virtual void begin_update() = 0;
260 virtual void end_update() = 0;
261 virtual bool has_item_model() const = 0;
262 virtual i_item_model& item_model() const = 0;
263 virtual void set_item_model(i_item_model& aItemModel) = 0;
264 virtual item_model_index to_item_model_index(item_presentation_model_index const& aIndex) const = 0;
265 virtual bool has_item_model_index(item_model_index const& aIndex) const = 0;
266 virtual item_presentation_model_index from_item_model_index(item_model_index const& aIndex, bool aIgnoreColumn = false) const = 0;
267 public:
268 virtual uint32_t rows() const = 0;
269 virtual uint32_t columns() const = 0;
270 virtual uint32_t columns(item_presentation_model_index const& aIndex) const = 0;
271 public:
272 virtual void accept(i_meta_visitor& aVisitor, bool aIgnoreCollapsedState = false) = 0;
273 public:
274 virtual dimension column_width(item_presentation_model_index::column_type aColumnIndex, i_units_context const& aUnitsContext, bool aExtendIntoPadding = true) const = 0;
275 virtual std::string const& column_heading_text(item_presentation_model_index::column_type aColumnIndex) const = 0;
276 virtual size column_heading_extents(item_presentation_model_index::column_type aColumnIndex, i_units_context const& aUnitsContext) const = 0;
277 virtual void set_column_heading_text(item_presentation_model_index::column_type aColumnIndex, std::string const& aHeadingText) = 0;
278 virtual item_cell_flags column_flags(item_presentation_model_index::column_type aColumnIndex) const = 0;
279 virtual void set_column_flags(item_presentation_model_index::column_type aColumnIndex, item_cell_flags aFlags) = 0;
280 virtual optional_size column_image_size(item_presentation_model_index::column_type aColumnIndex) const = 0;
281 virtual void set_column_image_size(item_presentation_model_index::column_type aColumnIndex, optional_size const& aImageSize) = 0;
282 public:
283 virtual bool expand(item_presentation_model_index const& aIndex) = 0;
284 virtual bool collapse(item_presentation_model_index const& aIndex) = 0;
285 virtual bool toggle_expanded(item_presentation_model_index const& aIndex) = 0;
286 virtual bool expand_to(item_model_index const& aIndex) = 0;
287 public:
288 virtual button_checked_state const& checked_state(item_presentation_model_index const& aIndex) = 0;
289 virtual bool is_checked(item_presentation_model_index const& aIndex) const = 0;
290 virtual bool is_unchecked(item_presentation_model_index const& aIndex) const = 0;
291 virtual bool is_indeterminate(item_presentation_model_index const& aIndex) const = 0;
292 virtual void set_checked_state(item_presentation_model_index const& aIndex, button_checked_state const& aState) = 0;
293 virtual void check(item_presentation_model_index const& aIndex) = 0;
294 virtual void uncheck(item_presentation_model_index const& aIndex) = 0;
295 virtual void set_indeterminate(item_presentation_model_index const& aIndex) = 0;
296 virtual void set_checked(item_presentation_model_index const& aIndex, bool aChecked) = 0;
297 virtual void toggle_check(item_presentation_model_index const& aIndex) = 0;
298 public:
299 virtual font const& default_font() const = 0;
300 virtual void set_default_font(optional_font const& aDefaultFont) = 0;
301 virtual size cell_spacing(i_units_context const& aUnitsContext) const = 0;
302 virtual void set_cell_spacing(optional_size const& aSpacing, i_units_context const& aUnitsContext) = 0;
303 virtual neogfx::padding cell_padding(i_units_context const& aUnitsContext) const = 0;
304 virtual void set_cell_padding(optional_padding const& aPadding, i_units_context const& aUnitsContext) = 0;
305 virtual bool alternating_row_color() const = 0;
306 virtual void set_alternating_row_color(bool aAlternatingColor) = 0;
307 public:
308 virtual dimension item_height(item_presentation_model_index const& aIndex, i_units_context const& aUnitsContext) const = 0;
309 virtual double total_height(i_units_context const& aUnitsContext) const = 0;
310 virtual double item_position(item_presentation_model_index const& aIndex, i_units_context const& aUnitsContext) const = 0;
311 virtual std::pair<item_presentation_model_index::value_type, coordinate> item_at(double aPosition, i_units_context const& aUnitsContext) const = 0;
312 public:
313 virtual item_cell_flags cell_flags(item_presentation_model_index const& aIndex) const = 0;
314 virtual void set_cell_flags(item_presentation_model_index const& aIndex, item_cell_flags aFlags) = 0;
315 virtual cell_meta_type& cell_meta(item_presentation_model_index const& aIndex) const = 0;
316 public:
317 virtual std::string cell_to_string(item_presentation_model_index const& aIndex) const = 0;
318 virtual item_cell_data string_to_cell_data(item_presentation_model_index const& aIndex, std::string const& aString) const = 0;
319 virtual item_cell_data string_to_cell_data(item_presentation_model_index const& aIndex, std::string const& aString, bool& aError) const = 0;
320 virtual boost::basic_format<char> cell_format(item_presentation_model_index const& aIndex) const = 0;
321 virtual optional_color cell_color(item_presentation_model_index const& aIndex, color_role aColorRole) const = 0;
322 virtual optional_font cell_font(item_presentation_model_index const& aIndex) const = 0;
323 virtual optional_size cell_image_size(item_presentation_model_index const& aIndex) const = 0;
324 virtual optional_size cell_check_box_size(item_presentation_model_index const& aIndex, i_units_context const& aUnitsContext) const = 0;
325 virtual optional_size cell_tree_expander_size(item_presentation_model_index const& aIndex, i_units_context const& aUnitsContext) const = 0;
326 virtual optional_texture cell_image(item_presentation_model_index const& aIndex) const = 0;
327 virtual neogfx::glyph_text& cell_glyph_text(item_presentation_model_index const& aIndex) const = 0;
328 virtual size cell_extents(item_presentation_model_index const& aIndex, i_units_context const& aUnitsContext) const = 0;
329 virtual dimension indent(item_presentation_model_index const& aIndex, i_units_context const& aUnitsContext) const = 0;
330 public:
331 virtual void sort(i_item_sort_predicate const& aPredicate) = 0;
332 virtual bool sortable() const = 0;
333 virtual void set_sortable(bool aSortable) = 0;
334 virtual optional_sort_by_param sorting_by() const = 0;
335 virtual void sort_by(item_presentation_model_index::column_type aColumnIndex, optional_sort_direction const& aSortDirection = optional_sort_direction{}) = 0;
336 virtual void reset_sort() = 0;
337 public:
338 virtual optional_item_presentation_model_index find_item(filter_search_key const& aFilterSearchKey, item_presentation_model_index::column_type aColumnIndex = 0, filter_search_type aFilterSearchType = filter_search_type::Prefix, case_sensitivity aCaseSensitivity = case_sensitivity::CaseInsensitive) const = 0;
339 public:
340 virtual bool filtering() const = 0;
341 virtual optional_filter filtering_by() const = 0;
342 virtual void filter_by(item_presentation_model_index::column_type aColumnIndex, filter_search_key const& aFilterSearchKey, filter_search_type aFilterSearchType = filter_search_type::Prefix, case_sensitivity aCaseSensitivity = case_sensitivity::CaseInsensitive) = 0;
343 virtual void reset_filter() = 0;
344 // helpers
345 public:
346 bool column_editable(item_presentation_model_index::column_type aColumnIndex) const
347 {
348 return (column_flags(aColumnIndex) & item_cell_flags::Editable) == item_cell_flags::Editable;
349 }
350 void set_column_editable(item_presentation_model_index::column_type aColumnIndex, bool aEditable = true)
351 {
352 if (aEditable)
353 {
354 set_column_flags(aColumnIndex, column_flags(aColumnIndex) | item_cell_flags::Editable);
355 if ((column_flags(aColumnIndex) & (item_cell_flags::EditableWhenFocused | item_cell_flags::EditableOnInputEvent)) == item_cell_flags::Invalid)
356 set_column_flags(aColumnIndex, column_flags(aColumnIndex) | item_cell_flags::EditableWhenFocused);
357 }
358 else
359 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~item_cell_flags::Editable);
360 }
361 bool column_editable_when_focused(item_presentation_model_index::column_type aColumnIndex) const
362 {
363 return column_editable(aColumnIndex) && (column_flags(aColumnIndex) & item_cell_flags::EditableWhenFocused) == item_cell_flags::EditableWhenFocused;
364 }
365 void set_column_editable_when_focused(item_presentation_model_index::column_type aColumnIndex, bool aEditableWhenFocused = true)
366 {
367 if (aEditableWhenFocused)
368 set_column_flags(aColumnIndex, (column_flags(aColumnIndex) | item_cell_flags::Editable | item_cell_flags::EditableWhenFocused) & ~item_cell_flags::EditableOnInputEvent);
369 else
370 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~(item_cell_flags::Editable | item_cell_flags::EditableWhenFocused));
371 }
372 bool column_editable_on_input_event(item_presentation_model_index::column_type aColumnIndex) const
373 {
374 return column_editable(aColumnIndex) && (column_flags(aColumnIndex) & item_cell_flags::EditableOnInputEvent) == item_cell_flags::EditableOnInputEvent;
375 }
376 void set_column_editable_on_input_event(item_presentation_model_index::column_type aColumnIndex, bool aEditableOnInputEvent = true)
377 {
378 if (aEditableOnInputEvent)
379 set_column_flags(aColumnIndex, (column_flags(aColumnIndex) | item_cell_flags::Editable | item_cell_flags::EditableOnInputEvent) & ~item_cell_flags::EditableWhenFocused);
380 else
381 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~(item_cell_flags::Editable | item_cell_flags::EditableOnInputEvent));
382 }
383 bool column_selectable(item_model_index::column_type aColumnIndex) const
384 {
385 return (column_flags(aColumnIndex) & item_cell_flags::Selectable) == item_cell_flags::Selectable;
386 }
387 void set_column_selectable(item_model_index::column_type aColumnIndex, bool aSelectable = true)
388 {
389 if (aSelectable)
390 set_column_flags(aColumnIndex, column_flags(aColumnIndex) | item_cell_flags::Selectable);
391 else
392 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~item_cell_flags::Selectable);
393 }
394 bool column_read_only(item_model_index::column_type aColumnIndex) const
395 {
396 return (column_flags(aColumnIndex) & item_cell_flags::Editable) != item_cell_flags::Editable;
397 }
398 void set_column_read_only(item_model_index::column_type aColumnIndex, bool aReadOnly = true)
399 {
400 if (aReadOnly)
401 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~item_cell_flags::Editable);
402 else
403 set_column_flags(aColumnIndex, column_flags(aColumnIndex) | item_cell_flags::Editable);
404 }
405 bool column_checkable(item_model_index::column_type aColumnIndex) const
406 {
407 return (column_flags(aColumnIndex) & item_cell_flags::Checkable) == item_cell_flags::Checkable;
408 }
409 void set_column_checkable(item_model_index::column_type aColumnIndex, bool aCheckable = true)
410 {
411 if (aCheckable)
412 {
413 set_column_flags(aColumnIndex, column_flags(aColumnIndex) | item_cell_flags::Checkable);
414 if ((column_flags(aColumnIndex) & (item_cell_flags::CheckableBiState | item_cell_flags::CheckableTriState)) == item_cell_flags::Invalid)
415 set_column_flags(aColumnIndex, column_flags(aColumnIndex) | item_cell_flags::CheckableBiState);
416 }
417 else
418 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~item_cell_flags::Checkable);
419 }
420 bool column_bi_state_checkable(item_model_index::column_type aColumnIndex) const
421 {
422 return column_checkable(aColumnIndex) && (column_flags(aColumnIndex) & item_cell_flags::CheckableBiState) == item_cell_flags::CheckableBiState;
423 }
424 void set_column_bi_state_checkable(item_model_index::column_type aColumnIndex, bool aCheckableBiState = true)
425 {
426 if (aCheckableBiState)
427 set_column_flags(aColumnIndex, (column_flags(aColumnIndex) | item_cell_flags::Checkable | item_cell_flags::CheckableBiState) & ~item_cell_flags::CheckableTriState);
428 else
429 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~(item_cell_flags::Checkable | item_cell_flags::CheckableBiState));
430 }
431 bool column_tri_state_checkable(item_model_index::column_type aColumnIndex) const
432 {
433 return column_checkable(aColumnIndex) && (column_flags(aColumnIndex) & item_cell_flags::CheckableTriState) == item_cell_flags::CheckableTriState;
434 }
435 void set_column_tri_state_checkable(item_model_index::column_type aColumnIndex, bool aCheckableTriState = true)
436 {
437 if (aCheckableTriState)
438 set_column_flags(aColumnIndex, (column_flags(aColumnIndex) | item_cell_flags::Checkable | item_cell_flags::CheckableTriState) & ~item_cell_flags::CheckableBiState);
439 else
440 set_column_flags(aColumnIndex, column_flags(aColumnIndex) & ~(item_cell_flags::Checkable | item_cell_flags::CheckableTriState));
441 }
442 bool cell_editable(item_presentation_model_index const& aIndex) const
443 {
444 return (cell_flags(aIndex) & item_cell_flags::Editable) == item_cell_flags::Editable;
445 }
446 void set_cell_editable(item_presentation_model_index const& aIndex, bool aEditable = true)
447 {
448 if (aEditable)
449 {
450 set_cell_flags(aIndex, cell_flags(aIndex) | item_cell_flags::Editable);
451 if ((cell_flags(aIndex) & (item_cell_flags::EditableWhenFocused | item_cell_flags::EditableOnInputEvent)) == item_cell_flags::Invalid)
452 set_cell_flags(aIndex, cell_flags(aIndex) | item_cell_flags::EditableWhenFocused);
453 }
454 else
455 set_cell_flags(aIndex, cell_flags(aIndex) & ~item_cell_flags::Editable);
456 }
457 bool cell_editable_when_focused(item_presentation_model_index const& aIndex) const
458 {
459 return cell_editable(aIndex) && (cell_flags(aIndex) & item_cell_flags::EditableWhenFocused) == item_cell_flags::EditableWhenFocused;
460 }
461 void set_cell_editable_when_focused(item_presentation_model_index const& aIndex, bool aEditableWhenFocused = true)
462 {
463 if (aEditableWhenFocused)
464 set_cell_flags(aIndex, (cell_flags(aIndex) | item_cell_flags::Editable | item_cell_flags::EditableWhenFocused) & ~item_cell_flags::EditableOnInputEvent);
465 else
466 set_cell_flags(aIndex, cell_flags(aIndex) & ~(item_cell_flags::Editable | item_cell_flags::EditableWhenFocused));
467 }
468 bool cell_editable_on_input_event(item_presentation_model_index const& aIndex) const
469 {
470 return cell_editable(aIndex) && (cell_flags(aIndex) & item_cell_flags::EditableOnInputEvent) == item_cell_flags::EditableOnInputEvent;
471 }
472 void set_cell_editable_on_input_event(item_presentation_model_index const& aIndex, bool aEditableOnInputEvent = true)
473 {
474 if (aEditableOnInputEvent)
475 set_cell_flags(aIndex, (cell_flags(aIndex) | item_cell_flags::Editable | item_cell_flags::EditableOnInputEvent) & ~item_cell_flags::EditableWhenFocused);
476 else
477 set_cell_flags(aIndex, cell_flags(aIndex) & ~(item_cell_flags::Editable | item_cell_flags::EditableOnInputEvent));
478 }
479 bool cell_selectable(item_presentation_model_index const& aIndex) const
480 {
481 return (cell_flags(aIndex) & item_cell_flags::Selectable) == item_cell_flags::Selectable;
482 }
483 void set_cell_selectable(item_presentation_model_index const& aIndex, bool aSelectable = true)
484 {
485 if (aSelectable)
486 set_cell_flags(aIndex, cell_flags(aIndex) | item_cell_flags::Selectable);
487 else
488 set_cell_flags(aIndex, cell_flags(aIndex) & ~item_cell_flags::Selectable);
489 }
490 bool cell_read_only(item_presentation_model_index const& aIndex) const
491 {
492 return (cell_flags(aIndex) & item_cell_flags::Editable) != item_cell_flags::Editable;
493 }
494 void set_cell_read_only(item_presentation_model_index const& aIndex, bool aReadOnly = true)
495 {
496 if (aReadOnly)
497 set_cell_flags(aIndex, cell_flags(aIndex) & ~item_cell_flags::Editable);
498 else
499 set_cell_flags(aIndex, cell_flags(aIndex) | item_cell_flags::Editable);
500 }
501 bool cell_checkable(item_presentation_model_index const& aIndex) const
502 {
503 return (cell_flags(aIndex) & item_cell_flags::Checkable) == item_cell_flags::Checkable;
504 }
505 void set_cell_checkable(item_presentation_model_index const& aIndex, bool aCheckable = true)
506 {
507 if (aCheckable)
508 {
509 set_cell_flags(aIndex, cell_flags(aIndex) | item_cell_flags::Checkable);
510 if ((cell_flags(aIndex) & (item_cell_flags::CheckableBiState | item_cell_flags::CheckableTriState)) == item_cell_flags::Invalid)
511 set_cell_flags(aIndex, cell_flags(aIndex) | item_cell_flags::CheckableBiState);
512 }
513 else
514 set_cell_flags(aIndex, cell_flags(aIndex) & ~item_cell_flags::Checkable);
515 }
516 bool cell_bi_state_checkable(item_presentation_model_index const& aIndex) const
517 {
518 return cell_checkable(aIndex) && (cell_flags(aIndex) & item_cell_flags::CheckableBiState) == item_cell_flags::CheckableBiState;
519 }
520 void set_cell_bi_state_checkable(item_presentation_model_index const& aIndex, bool aCheckableBiState = true)
521 {
522 if (aCheckableBiState)
523 set_cell_flags(aIndex, (cell_flags(aIndex) | item_cell_flags::Checkable | item_cell_flags::CheckableBiState) & ~item_cell_flags::CheckableTriState);
524 else
525 set_cell_flags(aIndex, cell_flags(aIndex) & ~(item_cell_flags::Checkable | item_cell_flags::CheckableBiState));
526 }
527 bool cell_tri_state_checkable(item_presentation_model_index const& aIndex) const
528 {
529 return cell_checkable(aIndex) && (cell_flags(aIndex) & item_cell_flags::CheckableTriState) == item_cell_flags::CheckableTriState;
530 }
531 void set_cell_tri_state_checkable(item_presentation_model_index const& aIndex, bool aCheckableTriState = true)
532 {
533 if (aCheckableTriState)
534 set_cell_flags(aIndex, (cell_flags(aIndex) | item_cell_flags::Checkable | item_cell_flags::CheckableTriState) & ~item_cell_flags::CheckableBiState);
535 else
536 set_cell_flags(aIndex, cell_flags(aIndex) & ~(item_cell_flags::Checkable | item_cell_flags::CheckableTriState));
537 }
538 };
539
540 class scoped_item_update
541 {
542 public:
543 scoped_item_update(i_item_presentation_model& aPresentationModel) :
544 iPresentationModel{ aPresentationModel }
545 {
546 iPresentationModel.begin_update();
547 }
548 ~scoped_item_update()
549 {
550 iPresentationModel.end_update();
551 }
552 private:
553 i_item_presentation_model& iPresentationModel;
554 };
555}
#define end_declare_enum(enumName)
Definition i_enum.hpp:62
#define declare_enum_string(enumName, enumEnumerator)
Definition i_enum.hpp:59
#define begin_declare_enum(enumName)
Definition i_enum.hpp:52
constexpr font_style & operator&=(font_style &aLhs, font_style aRhs)
Definition font.hpp:81
constexpr style_aspect operator&(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:60
audio_channel operator^(audio_channel lhs, audio_channel rhs)
optional< color > optional_color
Definition color.hpp:1069
audio_channel operator~(audio_channel lhs)
default_geometry_value_type dimension
std::optional< glyph_text > optional_glyph_text
std::optional< item_cell_flags > optional_item_cell_flags
std::optional< texture > optional_texture
Definition texture.hpp:82
basic_item_model< void * > item_model
constexpr font_style & operator|=(font_style &aLhs, font_style aRhs)
Definition font.hpp:76
constexpr style_aspect operator|(style_aspect aLhs, style_aspect aRhs)
Definition i_style.hpp:55
optional< size > optional_size
constexpr font_style & operator^=(font_style &aLhs, font_style aRhs)
Definition font.hpp:86
basic_size< coordinate > size
Definition plf_hive.h:79
constexpr decltype(auto) visit(Visitor &&vis, neolib::variant< Types... > &&var)
Definition variant.hpp:60
#define declare_event(declName,...)
Definition i_event.hpp:305