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