Skip to content

Commit e4314e2

Browse files
committed
Added option to delete a watch variable from the FEBio monitor's model panel.
1 parent 4489897 commit e4314e2

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

FEBioMonitor/FEBioModelPanel.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,13 @@ class CFEBioDataModel : public QAbstractItemModel
141141
}
142142
else if (row == N)
143143
{
144-
beginInsertRows(QModelIndex(), row, row + 1);
145-
m_doc->AddWatchVariable(value.toString());
146-
endInsertRows();
144+
QString v = value.toString();
145+
if (!v.isEmpty())
146+
{
147+
beginInsertRows(QModelIndex(), row, row + 1);
148+
m_doc->AddWatchVariable(value.toString());
149+
endInsertRows();
150+
}
147151
}
148152
}
149153
return false;
@@ -165,6 +169,8 @@ class CFEBioDataModel : public QAbstractItemModel
165169
endResetModel();
166170
}
167171

172+
FEBioMonitorDoc* GetDocument() { return m_doc; }
173+
168174
private:
169175
FEBioMonitorDoc* m_doc;
170176
};
@@ -223,6 +229,20 @@ class Ui::CFEBioModelPanel
223229
m_tree->setModel(nullptr);
224230
}
225231
}
232+
233+
void deleteSelection()
234+
{
235+
if (m_data == nullptr) return;
236+
FEBioMonitorDoc* doc = m_data->GetDocument(); assert(doc);
237+
if (doc == nullptr) return;
238+
QModelIndexList indices = m_tree->selectionModel()->selectedIndexes();
239+
if (indices.size() == 2) // size==2 because we have two columns.
240+
{
241+
QModelIndex i = indices[0];
242+
doc->DeleteWatchVariable(i.row());
243+
m_data->update();
244+
}
245+
}
226246
};
227247

228248
CFEBioModelPanel::CFEBioModelPanel(CMainWindow* wnd, QWidget* parent) : CWindowPanel(wnd, parent), ui(new Ui::CFEBioModelPanel)
@@ -235,6 +255,14 @@ FEBioMonitorDoc* CFEBioModelPanel::GetCurrentDocument()
235255
return dynamic_cast<FEBioMonitorDoc*>(GetMainWindow()->GetDocument());
236256
}
237257

258+
void CFEBioModelPanel::keyPressEvent(QKeyEvent* e)
259+
{
260+
if (e->key() == Qt::Key_Delete)
261+
{
262+
ui->deleteSelection();
263+
}
264+
}
265+
238266
void CFEBioModelPanel::Clear()
239267
{
240268
ui->reset();

FEBioMonitor/FEBioModelPanel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class CFEBioModelPanel : public CWindowPanel
4646

4747
FEBioMonitorDoc* GetCurrentDocument();
4848

49+
void keyPressEvent(QKeyEvent* e) override;
50+
4951
public slots:
5052
void launchMatrixInspector();
5153

FEBioMonitor/FEBioMonitorDoc.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ bool FEBioMonitorDoc::processFEBioEvent(FEModel* fem, int nevent)
622622

623623
if (nevent == CB_INIT) InitDefaultWatchVariables();
624624
UpdateAllWatchVariables();
625-
emit updateViews(false, updateGL);
625+
emit updateViews(nevent == CB_INIT, updateGL);
626626
m->mutex.lock();
627627

628628
constexpr double eps = std::numeric_limits<double>::epsilon();
@@ -631,7 +631,7 @@ bool FEBioMonitorDoc::processFEBioEvent(FEModel* fem, int nevent)
631631
{
632632
m->outputBuffer += "\n[paused on " + eventToString(nevent) + "]\n";
633633
emit outputReady();
634-
emit updateViews(true, true);
634+
emit updateViews(false, true);
635635
m->isPaused = true;
636636
jobIsPaused.wait(&m->mutex);
637637
m->isPaused = false;
@@ -695,6 +695,11 @@ void FEBioMonitorDoc::SetWatchVariable(int n, const QString& name)
695695
UpdateWatchVariable(*var);
696696
}
697697

698+
void FEBioMonitorDoc::DeleteWatchVariable(int n)
699+
{
700+
m->watches.removeAt(n);
701+
}
702+
698703
void FEBioMonitorDoc::InitDefaultWatchVariables()
699704
{
700705
m->watches.clear();

FEBioMonitor/FEBioMonitorDoc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ class FEBioMonitorDoc : public CGLModelDocument
174174
int GetWatchVariables() const;
175175
void SetWatchVariable(int n, const QString& name);
176176

177+
void DeleteWatchVariable(int n);
178+
177179
public:
178180
FEGlobalMatrix* GetStiffnessMatrix();
179181

0 commit comments

Comments
 (0)