Add `const` qualifiers where possible

This commit is contained in:
Alexander Montag 2024-09-29 15:57:13 +00:00
parent 6200f61162
commit 5a66160bce
No known key found for this signature in database
GPG Key ID: 07FE50B35A2B7524
2 changed files with 13 additions and 13 deletions

View File

@ -114,7 +114,7 @@ void TreeSearch::_highlight_tree_item(TreeItem *p_tree_item) {
} }
// if the cached draw method is already applied, do nothing. // if the cached draw method is already applied, do nothing.
if (callable_cache.has(p_tree_item) && parent_draw_method == callable_cache.get(p_tree_item)){ if (callable_cache.has(p_tree_item) && parent_draw_method == callable_cache.get(p_tree_item)) {
return; return;
} }
@ -138,7 +138,7 @@ void TreeSearch::_highlight_tree_item(TreeItem *p_tree_item) {
} }
// custom draw callback for highlighting (bind the parent_drw_method to this) // custom draw callback for highlighting (bind the parent_drw_method to this)
void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Callable p_parent_draw_method) { void TreeSearch::_draw_highlight_item(TreeItem *p_tree_item, const Rect2 p_rect, const Callable p_parent_draw_method) {
if (!p_tree_item) { if (!p_tree_item) {
return; return;
} }
@ -250,12 +250,12 @@ void TreeSearch::_update_number_matches() {
} }
} }
String TreeSearch::_get_search_mask() { String TreeSearch::_get_search_mask() const {
ERR_FAIL_COND_V(!search_panel, ""); ERR_FAIL_COND_V(!search_panel, "");
return search_panel->get_text(); return search_panel->get_text();
} }
void TreeSearch::_find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_accum) { void TreeSearch::_find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_accum) const {
if (!p_tree_item) { if (!p_tree_item) {
return; return;
} }
@ -381,7 +381,7 @@ void TreeSearch::_select_next_match() {
} }
template <typename T> template <typename T>
inline bool TreeSearch::_vector_has_bsearch(Vector<T *> p_vec, T *element) { inline bool TreeSearch::_vector_has_bsearch(Vector<T *> &p_vec, T *element) const {
int idx = p_vec.bsearch(element, true); int idx = p_vec.bsearch(element, true);
bool in_array = idx >= 0 && idx < p_vec.size(); bool in_array = idx >= 0 && idx < p_vec.size();
@ -517,7 +517,7 @@ TreeSearch::TreeSearchMode TreeSearchPanel::get_search_mode() {
return TreeSearch::TreeSearchMode::FILTER; return TreeSearch::TreeSearchMode::FILTER;
} }
String TreeSearchPanel::get_text() { String TreeSearchPanel::get_text() const {
if (!line_edit_search) { if (!line_edit_search) {
return String(); return String();
} }

View File

@ -75,22 +75,23 @@ private:
void _highlight_tree_item(TreeItem *p_tree_item); void _highlight_tree_item(TreeItem *p_tree_item);
// Custom draw-Callback (bind inherited Callable). // Custom draw-Callback (bind inherited Callable).
void _draw_highlight_item(TreeItem *p_tree_item, Rect2 p_rect, Callable p_parent_draw_method); void _draw_highlight_item(TreeItem *p_tree_item, const Rect2 p_rect, const Callable p_parent_draw_method);
void _update_matching_entries(const String &p_search_mask); void _update_matching_entries(const String &p_search_mask);
void _update_ordered_tree_items(TreeItem *p_tree_item); void _update_ordered_tree_items(TreeItem *p_tree_item);
void _update_number_matches(); void _update_number_matches();
void _find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_accum); void _find_matching_entries(TreeItem *p_tree_item, const String &p_search_mask, Vector<TreeItem *> &p_accum) const;
String _get_search_mask(); String _get_search_mask() const;
StringSearchIndices _substring_bounds(const String &p_searchable, const String &p_search_mask) const; StringSearchIndices _substring_bounds(const String &p_searchable, const String &p_search_mask) const;
void _select_item(TreeItem *p_item); void _select_item(TreeItem *p_item);
void _select_first_match(); void _select_first_match();
void _select_next_match(); void _select_next_match();
// TODO: make p_vec `const` once Vector::bsearch is const. See: https://github.com/godotengine/godot/pull/90341
template <typename T> template <typename T>
bool _vector_has_bsearch(Vector<T *> p_vec, T *element); bool _vector_has_bsearch(Vector<T *> &p_vec, T *element) const;
protected: protected:
static void _bind_methods() {} static void _bind_methods() {}
@ -121,8 +122,7 @@ private:
CheckBox *check_button_filter_highlight; CheckBox *check_button_filter_highlight;
void _initialize_controls(); void _initialize_controls();
void _add_spacer(float width_multiplier = 1.f); void _add_spacer(float width_multiplier = 1.f);
void _on_draw_highlight(TreeItem *p_item, Rect2 p_rect);
void _notification(int p_what); void _notification(int p_what);
protected: protected:
@ -130,7 +130,7 @@ protected:
public: public:
TreeSearch::TreeSearchMode get_search_mode(); TreeSearch::TreeSearchMode get_search_mode();
String get_text(); String get_text() const;
void show_and_focus(); void show_and_focus();
TreeSearchPanel(); TreeSearchPanel();
}; };