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