OGS
ProcessView.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 "ProcessView.h"
5
6#include <QFileDialog>
7#include <QMenu>
8
10#include "CondItem.h"
11#include "ProcessModel.h"
12#include "ProcessVarItem.h"
13#include "SelectMeshDialog.h"
14
15ProcessView::ProcessView(QWidget* parent) : QTreeView(parent) {}
16
18{
19 setAlternatingRowColors(true);
20 resizeColumnToContents(0);
21 setColumnWidth(1, 50);
22 setColumnWidth(2, 50);
23}
24
25void ProcessView::on_Clicked(QModelIndex idx)
26{
27 qDebug("%d, %d", idx.parent().row(), idx.row());
28}
29
30void ProcessView::selectionChanged(const QItemSelection& selected,
31 const QItemSelection& deselected)
32{
33 if (!selected.isEmpty())
34 {
35 emit clearConditionView();
36 const QModelIndex idx = *(selected.indexes().begin());
37
38 if (idx.parent().isValid()) // not root node
39 {
40 CondItem const* const item = dynamic_cast<CondItem*>(
41 static_cast<ProcessModel*>(this->model())->getItem(idx));
42 if (item != nullptr)
43 {
44 emit conditionSelected(item->getCondition());
45 }
46 }
47 else
48 {
49 CondItem const* const item = dynamic_cast<CondItem*>(
50 static_cast<ProcessModel*>(this->model())
51 ->getItem(idx)
52 ->child(0));
53 if (item != nullptr)
54 {
55 emit processVarSelected(item->getCondition());
56 }
57 }
58 }
59 emit itemSelectionChanged(selected, deselected);
60 QTreeView::selectionChanged(selected, deselected);
61}
62
63void ProcessView::contextMenuEvent(QContextMenuEvent* event)
64{
65 Q_UNUSED(event);
66
67 const QModelIndex idx(this->selectionModel()->currentIndex());
68 QMenu menu;
69
70 if (isProcessVarItem(idx))
71 {
72 // QAction* saveCondAction = menu.addAction("Save FEM Conditions...");
73 QAction* removeProcessVarAction =
74 menu.addAction("Remove process variable");
75 // connect(saveCondAction, SIGNAL(triggered()), this,
76 // SLOT(saveConditions()));
77 connect(removeProcessVarAction, SIGNAL(triggered()), this,
78 SLOT(removeProcessVar()));
79 }
80 else if (isConditionItem(idx))
81 {
82 QAction* removeCondAction = menu.addAction("Remove condition");
83 connect(removeCondAction, SIGNAL(triggered()), this,
84 SLOT(removeCondition()));
85 // QAction* editCondAction = menu.addAction("Edit condition");
86 // connect(editCondAction, SIGNAL(triggered()), this,
87 // SLOT(editCondition())); else editCondAction->setEnabled(false);
88 }
89
90 menu.exec(event->globalPos());
91}
92
94{
95 CondItem* item = dynamic_cast<CondItem*>(
96 static_cast<ProcessModel*>(this->model())
97 ->getItem(this->selectionModel()->currentIndex()));
98 if (item)
99 {
100 emit clearConditionView();
101 emit conditionRemoved(
102 QString::fromStdString(item->getCondition()->getProcessVarName()),
103 item->getName());
104 }
105}
106
108{
109 ProcessVarItem* item = dynamic_cast<ProcessVarItem*>(
110 static_cast<ProcessModel*>(this->model())
111 ->getItem(this->selectionModel()->currentIndex()));
112 if (item)
113 {
114 emit clearConditionView();
115 emit processVarRemoved(item->getName());
116 }
117}
118/*
119void ProcessView::editCondition()
120{
121 CondItem* item =
122dynamic_cast<CondItem*>(static_cast<ProcessModel*>(this->model())->getItem(this->selectionModel()->currentIndex()));
123
124 if (item)
125 {
126 FEMConditionSetupDialog dlg(*(item->getItem()));
127 connect(&dlg, SIGNAL(createFEMCondition(std::vector<FEMCondition*>)),
128this, SLOT(replaceCondition(std::vector<FEMCondition*>))); dlg.exec();
129 }
130}
131
132void ProcessView::replaceCondition(std::vector<FEMCondition*> conditions)
133{
134 static_cast<ProcessModel*>(this->model())->replaceCondition(this->selectionModel()->currentIndex(),
135conditions[0]); this->reset();
136}
137
138void ProcessView::saveConditions()
139{
140 emit saveConditionsRequested();
141}
142*/
143bool ProcessView::isProcessVarItem(const QModelIndex& idx) const
144{
145 return (dynamic_cast<ProcessVarItem*>(
146 static_cast<ProcessModel*>(this->model())->getItem(idx)) !=
147 nullptr);
148}
149
150bool ProcessView::isConditionItem(const QModelIndex& idx) const
151{
152 return (dynamic_cast<CondItem*>(
153 static_cast<ProcessModel*>(this->model())->getItem(idx)) !=
154 nullptr);
155}
A TreeItem containing a boundary condition or source term.
Definition CondItem.h:19
DataHolderLib::FemCondition * getCondition() const
Returns the FEM Condition associated with the item.
Definition CondItem.h:29
QString const getName() const
Definition CondItem.h:31
std::string const getProcessVarName() const
Returns the name of the associated process variable.
A model implementing a tree structure for process-relevant information such as process types,...
A TreeItem representing process variable information.
QString getName() const
void conditionSelected(DataHolderLib::FemCondition *cond)
void processVarRemoved(QString const &)
void on_Clicked(QModelIndex idx)
bool isProcessVarItem(const QModelIndex &idx) const
void conditionRemoved(QString const &, QString const &)
bool isConditionItem(const QModelIndex &idx) const
void updateView()
Update the view to visualise changes made to the underlying data.
void itemSelectionChanged(QItemSelection const &selected, QItemSelection const &deselected)
ProcessView(QWidget *parent=nullptr)
Constructor.
void removeProcessVar()
void processVarSelected(DataHolderLib::FemCondition *cond)
void contextMenuEvent(QContextMenuEvent *e) override
void removeCondition()
void clearConditionView()
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected) override
Instructions if the selection of items in the view has changed.
TreeItem * getItem(const QModelIndex &index) const