Debian Codegraph @

modules/objectdb_profiler/editor/data_viewers/shared_controls.h

raw symbols SCIP
1 /**************************************************************************/
2 /* shared_controls.h */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #pragma once
32
33 #include "scene/gui/box_container.h"
34 #include "scene/gui/panel_container.h"
35 #include "scene/gui/tree.h"
36
37 class LineEdit;
38 class MenuButton;
39
40 class SpanningHeader : public PanelContainer {
41 GDCLASS(SpanningHeader, PanelContainer);
42
43 public:
44 SpanningHeader(const String &p_text);
45 };
46
47 class DarkPanelContainer : public PanelContainer {
48 GDCLASS(DarkPanelContainer, PanelContainer);
49
50 public:
51 DarkPanelContainer();
52 };
53
54 // Utility class that creates a filter text box and a sort menu.
55 // Takes a reference to a tree and applies the sort and filter to the tree.
56 class TreeSortAndFilterBar : public HBoxContainer {
57 GDCLASS(TreeSortAndFilterBar, HBoxContainer);
58
59 public:
60 // The ways a column can be sorted, either alphabetically or numerically.
61 enum SortType {
62 NUMERIC_SORT = 0,
63 ALPHA_SORT,
64 SORT_TYPE_MAX
65 };
66
67 // Returned when a new sort is added. Each new sort can be either ascending or descending,
68 // so we return the index of each sort option.
69 struct SortOptionIndexes {
70 int ascending;
71 int descending;
72 };
73
74 protected:
75 // Context needed to sort the tree in a certain way.
76 // Combines a sort type, the column to apply it, and if it's ascending or descending.
77 struct SortItem {
78 SortItem() {}
79 SortItem(int p_id, const String &p_label, SortType p_type, bool p_ascending, int p_column) :
80 id(p_id), label(p_label), type(p_type), ascending(p_ascending), column(p_column) {}
81 int id = 0;
82 String label;
83 SortType type = SortType::NUMERIC_SORT;
84 bool ascending = false;
85 int column = 0;
86 };
87
88 struct TreeItemColumn {
89 TreeItemColumn() {}
90 TreeItemColumn(TreeItem *p_item, int p_column) :
91 item(p_item), column(p_column) {}
92 TreeItem *item = nullptr;
93 int column;
94 };
95
96 struct TreeItemAlphaComparator {
97 bool operator()(const TreeItemColumn &p_a, const TreeItemColumn &p_b) const {
98 return NoCaseComparator()(p_a.item->get_text(p_a.column), p_b.item->get_text(p_b.column));
99 }
100 };
101
102 struct TreeItemNumericComparator {
103 bool operator()(const TreeItemColumn &p_a, const TreeItemColumn &p_b) const {
104 return p_a.item->get_text(p_a.column).to_int() < p_b.item->get_text(p_b.column).to_int();
105 }
106 };
107
108 LineEdit *filter_edit = nullptr;
109 MenuButton *sort_button = nullptr;
110 Tree *managed_tree = nullptr;
111 HashMap<int, SortItem> sort_items;
112 int current_sort = 0;
113
114 void _apply_filter(TreeItem *p_current_node = nullptr);
115 void _apply_sort();
116 void _sort_changed(int p_id);
117 void _filter_changed(const String &p_filter);
118
119 public:
120 TreeSortAndFilterBar(Tree *p_managed_tree, const String &p_filter_placeholder_text);
121 void _notification(int p_what);
122 SortOptionIndexes add_sort_option(const String &p_new_option, SortType p_sort_type, int p_sort_column, bool p_is_default = false);
123 void clear_filter();
124 void clear();
125 void select_sort(int p_item_id);
126 void apply();
127 };