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