OGS
ElementTreeView.cpp
Go to the documentation of this file.
1
16#include "ElementTreeView.h"
17
18#include <QModelIndex>
19
20#include "Base/TreeItem.h"
21#include "ElementTreeModel.h"
22
23ElementTreeView::ElementTreeView(QWidget* parent) : QTreeView(parent) {}
24
26{
27 setAlternatingRowColors(true);
28 setColumnWidth(0, 150);
29 std::size_t nColumns =
30 (this->model() != nullptr) ? this->model()->columnCount() : 0;
31 for (std::size_t i = 1; i < nColumns; i++)
32 {
33 resizeColumnToContents(i);
34 }
35 this->expandAll();
36}
37
38void ElementTreeView::selectionChanged(const QItemSelection& selected,
39 const QItemSelection& deselected)
40{
41 Q_UNUSED(deselected);
42 if (!selected.isEmpty())
43 {
45 const QModelIndex idx = *(selected.indexes().begin());
46
47 if (idx.parent().isValid())
48 { // not root node
49 if (idx.parent().parent().isValid()) // not property node
50 {
51 const TreeItem* tree_item =
52 static_cast<TreeModel*>(this->model())->getItem(idx);
53 const unsigned node_index =
54 tree_item->data(0).toString().mid(5).toUInt();
55 emit nodeSelected(
56 static_cast<ElementTreeModel*>(this->model())->getSource(),
57 node_index, false);
58 }
59 }
60 }
61}
Definition of the ElementTreeModel class.
Definition of the ElementTreeView class.
Definition of the TreeItem class.
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:28
virtual QVariant data(int column) const
Definition TreeItem.cpp:94
A hierarchical model for a tree implemented as a double-linked list.
Definition TreeModel.h:30