OGS
ElementTreeView.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#include "ElementTreeView.h"
5
6#include <QModelIndex>
7
8#include "Base/TreeItem.h"
9#include "ElementTreeModel.h"
10
11ElementTreeView::ElementTreeView(QWidget* parent) : QTreeView(parent) {}
12
14{
15 setAlternatingRowColors(true);
16 setColumnWidth(0, 150);
17 std::size_t nColumns =
18 (this->model() != nullptr) ? this->model()->columnCount() : 0;
19 for (std::size_t i = 1; i < nColumns; i++)
20 {
21 resizeColumnToContents(i);
22 }
23 this->expandAll();
24}
25
26void ElementTreeView::selectionChanged(const QItemSelection& selected,
27 const QItemSelection& deselected)
28{
29 Q_UNUSED(deselected);
30 if (!selected.isEmpty())
31 {
33 const QModelIndex idx = *(selected.indexes().begin());
34
35 if (idx.parent().isValid())
36 { // not root node
37 if (idx.parent().parent().isValid()) // not property node
38 {
39 const TreeItem* tree_item =
40 static_cast<TreeModel*>(this->model())->getItem(idx);
41 const unsigned node_index =
42 tree_item->data(0).toString().mid(5).toUInt();
43 emit nodeSelected(
44 static_cast<ElementTreeModel*>(this->model())->getSource(),
45 node_index, false);
46 }
47 }
48 }
49}
A model for the display of information concerning element information implemented as a TreeModel.
void nodeSelected(vtkUnstructuredGridAlgorithm const *const, unsigned, bool)
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
Is called when the selection of this view changes.
ElementTreeView(QWidget *parent=nullptr)
Constructor.
void removeSelectedMeshComponent()
Objects nodes for the TreeModel.
Definition TreeItem.h:17
virtual QVariant data(int column) const
Definition TreeItem.cpp:83
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:19