3 #include <QFontDatabase> 15 return doj::alphanum_impl(this->text(0).toLocal8Bit(), other.text(0).toLocal8Bit()) < 0;
22 setEditTriggers(NoEditTriggers);
23 setDragEnabled(
false);
24 setDefaultDropAction(Qt::IgnoreAction);
25 setDragDropOverwriteMode(
false);
26 setDragDropMode(NoDragDrop);
27 viewport()->installEventFilter(
this);
28 setSelectionMode(ExtendedSelection);
29 setSelectionBehavior(QAbstractItemView::SelectRows);
30 setFocusPolicy(Qt::ClickFocus);
32 header()->setVisible(
false);
33 header()->setStretchLastSection(
true);
34 header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
35 setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
37 connect(
this, &QTreeWidget::itemDoubleClicked,
this, [
this](QTreeWidgetItem *item,
int column)
44 connect(selectionModel(), &QItemSelectionModel::selectionChanged,
this, [
this]()
50 setFocusPolicy(Qt::NoFocus);
54 setFocusPolicy(Qt::ClickFocus);
61 auto parts = item_name.split(
'/', QString::SplitBehavior::SkipEmptyParts);
62 if (parts.size() == 0)
67 QTreeWidgetItem* tree_parent = this->invisibleRootItem();
69 for (
int i = 0; i < parts.size(); i++)
71 bool is_leaf = (i == parts.size() - 1);
72 const auto& part = parts[i];
74 QTreeWidgetItem* matching_child =
nullptr;
76 for (
int c = 0;
c < tree_parent->childCount();
c++)
78 QTreeWidgetItem* tree_child = tree_parent->child(
c);
79 if (tree_child->text(0) == part)
81 matching_child = tree_child;
88 tree_parent = matching_child;
93 child_item->setText(0, part);
94 child_item->setText(1, is_leaf ?
"-" :
"");
96 QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
98 child_item->setFont(0, font);
100 font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
102 child_item->setFont(1, font);
103 child_item->setTextAlignment(1, Qt::AlignRight);
106 tree_parent = child_item;
108 auto current_flag = child_item->flags();
112 child_item->setFlags(current_flag | Qt::ItemIsSelectable);
113 child_item->setData(0, Qt::UserRole, item_name);
117 child_item->setFlags(current_flag & (~Qt::ItemIsSelectable));
126 invisibleRootItem()->sortChildren(0, Qt::AscendingOrder);
127 treeVisitor([&](QTreeWidgetItem* item) { item->sortChildren(0, Qt::AscendingOrder); });
128 header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
134 std::vector<std::string> non_hidden_list;
136 for (
const auto& item : selectedItems())
138 non_hidden_list.push_back(item->data(0, Qt::UserRole).toString().toStdString());
140 return non_hidden_list;
145 header()->setSectionResizeMode(0, QHeaderView::Fixed);
146 header()->setSectionResizeMode(1, QHeaderView::Fixed);
149 auto font = item->font(0);
151 item->setFont(0, font);
152 font = item->font(1);
154 item->setFont(1, font);
157 header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
158 header()->setSectionResizeMode(1, QHeaderView::Stretch);
163 bool updated =
false;
166 QStringList spaced_items = search_string.split(
' ');
168 auto hideFunc = [&](QTreeWidgetItem* item) {
169 QString
name = item->data(0, Qt::UserRole).toString();
176 if (search_string.isEmpty() ==
false)
178 for (
const auto& spaced_item : spaced_items)
180 if (name.contains(spaced_item, Qt::CaseInsensitive) ==
false)
192 if (toHide != item->isHidden())
197 item->setHidden(toHide);
200 auto parent = item->parent();
203 bool all_children_hidden =
true;
204 for (
int c = 0;
c < parent->childCount();
c++)
206 if (!parent->child(
c)->isHidden())
208 all_children_hidden =
false;
212 auto parent_hidden = parent->isHidden();
213 if (all_children_hidden != parent_hidden)
215 parent->setHidden(all_children_hidden);
216 parent = parent->parent();
233 auto removeFunc = [&](QTreeWidgetItem* item) {
234 QString curve_name = item->data(0, Qt::UserRole).toString();
235 if (curve_name == to_be_deleted)
238 auto parent_item = item->parent();
241 parent_item = invisibleRootItem();
243 parent_item->removeChild(item);
245 while (parent_item->childCount() == 0 && parent_item != invisibleRootItem())
247 auto prev_item = parent_item;
248 parent_item = parent_item->parent();
251 parent_item = invisibleRootItem();
253 parent_item->removeChild(prev_item);
264 setColumnHidden(1,hide);
269 std::function<void(QTreeWidgetItem*)> recursiveFunction;
270 recursiveFunction = [&](QTreeWidgetItem* item) {
272 for (
int c = 0;
c < item->childCount();
c++)
274 recursiveFunction(item->child(
c));
278 for (
int c = 0;
c < invisibleRootItem()->childCount();
c++)
280 recursiveFunction(invisibleRootItem()->child(
c));
286 int childCount = item->childCount();
287 for (
int i = 0; i < childCount; i++) {
288 const auto child = item->child(i);
290 if( !child->isExpanded() && child->childCount() > 0 ){
291 child->setExpanded(
true);
void expandChildren(QTreeWidgetItem *item)
std::vector< std::string > getSelectedNames() override
void removeCurve(const QString &name) override
void addItem(const QString &item_name) override
void treeVisitor(std::function< void(QTreeWidgetItem *)> visitor)
void refreshColumns() override
void refreshFontSize() override
CurveTreeView(CurveListPanel *parent)
void setViewResizeEnabled(bool) override
bool applyVisibilityFilter(const QString &filter_string) override
virtual void hideValuesColumn(bool hide) override