Skip to content

Commit 1e62243

Browse files
Cleaned up help feature code. Added help option to model tree context menu.
1 parent d6f3a06 commit 1e62243

6 files changed

Lines changed: 69 additions & 158 deletions

File tree

FEBioStudio/DlgAddPhysicsItem.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ SOFTWARE.*/
3030
#include <QTreeWidgetItem>
3131
#include <QFormLayout>
3232
#include <QBoxLayout>
33+
#include <QMessageBox>
3334
#include <QLabel>
3435
#include <QToolButton>
3536
#include <QHeaderView>
@@ -43,6 +44,7 @@ SOFTWARE.*/
4344
#include <FEBioLink/FEBioClass.h>
4445
#include <FEBioLink/FEBioModule.h>
4546
#include <FSCore/FSCore.h>
47+
#include "HelpFeature.h"
4648

4749
using namespace std;
4850

@@ -106,8 +108,15 @@ class UIDlgAddPhysicsItem
106108
layout->addLayout(h);
107109
layout->addWidget(type);
108110

109-
dlg->SetLeftSideLayout(layout);
111+
QDialogButtonBox* bb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
110112

113+
layout->addWidget(bb);
114+
115+
dlg->setLayout(layout);
116+
117+
QObject::connect(bb, SIGNAL(accepted()), dlg, SLOT(accept()));
118+
QObject::connect(bb, SIGNAL(rejected()), dlg, SLOT(reject()));
119+
QObject::connect(bb, SIGNAL(helpRequested()), dlg, SLOT(on_help_clicked()));
111120
QObject::connect(type, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), dlg, SLOT(accept()));
112121
QObject::connect(flt, SIGNAL(textChanged(const QString&)), dlg, SLOT(Update()));
113122
QObject::connect(tb, SIGNAL(clicked()), dlg, SLOT(Update()));
@@ -118,7 +127,7 @@ class UIDlgAddPhysicsItem
118127
};
119128

120129
CDlgAddPhysicsItem::CDlgAddPhysicsItem(QString windowName, int superID, int baseClassID, FSModel* fem, bool includeModuleDependencies, bool showStepList, QWidget* parent)
121-
: CHelpDialog(parent), ui(new UIDlgAddPhysicsItem)
130+
: QDialog(parent), ui(new UIDlgAddPhysicsItem)
122131
{
123132
setWindowTitle(windowName);
124133
setMinimumSize(800, 600);
@@ -138,13 +147,11 @@ CDlgAddPhysicsItem::CDlgAddPhysicsItem(QString windowName, int superID, int base
138147
}
139148
}
140149

141-
m_module = FEBio::GetActiveModule();
142-
143150
unsigned int searchFlags = 0;
144151
if (ui->m_modDepends) searchFlags |= FEBio::ClassSearchFlags::IncludeModuleDependencies;
145152

146153
// set the types
147-
vector<FEBio::FEBioClassInfo> l = FEBio::FindAllClasses(m_module, ui->m_superID, ui->m_baseClassID, searchFlags);
154+
vector<FEBio::FEBioClassInfo> l = FEBio::FindAllClasses(FEBio::GetActiveModule(), ui->m_superID, ui->m_baseClassID, searchFlags);
148155
for (int i = 0; i < (int)l.size(); ++i)
149156
{
150157
FEBio::FEBioClassInfo& fac = l[i];
@@ -210,6 +217,20 @@ void CDlgAddPhysicsItem::Update()
210217
ui->type->model()->sort(0);
211218
}
212219

220+
void CDlgAddPhysicsItem::on_help_clicked()
221+
{
222+
if(ui->type->selectedItems().size() > 0)
223+
{
224+
int classID = ui->type->currentItem()->data(0, Qt::UserRole).toInt();
225+
226+
ShowHelp(ClassIDToURL(classID));
227+
}
228+
else
229+
{
230+
QMessageBox::information(this, "Help", "Please select an item before clicking Help.");
231+
}
232+
}
233+
213234
std::string CDlgAddPhysicsItem::GetName()
214235
{
215236
return ui->name->text().toStdString();
@@ -226,20 +247,6 @@ int CDlgAddPhysicsItem::GetClassID()
226247
return (it ? it->data(0, Qt::UserRole).toInt() : -1);
227248
}
228249

229-
void CDlgAddPhysicsItem::UpdateHelpURL()
230-
{
231-
if(ui->type->selectedItems().size() > 0)
232-
{
233-
int classID = ui->type->currentItem()->data(0, Qt::UserRole).toInt();
234-
235-
SetURL(ClassIDToURL(classID));
236-
}
237-
else
238-
{
239-
SetURL(QString());
240-
}
241-
}
242-
243250
class UIDlgCopyPhysicsItem
244251
{
245252
private:

FEBioStudio/DlgAddPhysicsItem.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
SOFTWARE.*/
2626

2727
#pragma once
28-
#include "HelpDialog.h"
28+
#include <QDialog>
2929

3030
class UIDlgAddPhysicsItem;
3131
class UIDlgCopyPhysicsItem;
3232
class FSModel;
3333
class FSModelComponent;
3434

35-
class CDlgAddPhysicsItem : public CHelpDialog
35+
class CDlgAddPhysicsItem : public QDialog
3636
{
3737
Q_OBJECT
3838

@@ -45,11 +45,9 @@ class CDlgAddPhysicsItem : public CHelpDialog
4545

4646
void ShowNameAndCategoryFields(bool b);
4747

48-
protected:
49-
void UpdateHelpURL();
50-
5148
public slots:
5249
void Update();
50+
void on_help_clicked();
5351

5452
private:
5553
UIDlgAddPhysicsItem* ui;
Lines changed: 4 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -24,88 +24,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2424
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
SOFTWARE.*/
2626

27-
#include <QCoreApplication>
28-
#include <QBoxLayout>
29-
#include <QDialogButtonBox>
30-
#include <QPushButton>
31-
#include <QTextBrowser>
3227
#include <QDesktopServices>
33-
#include <QMessageBox>
34-
#include <FEMLib/FSProject.h>
35-
#include "HelpDialog.h"
36-
#include "FEBioStudio.h"
37-
#include "MainWindow.h"
38-
#include <FEBioLink/FEBioModule.h>
39-
#include <FEBioLib/version.h>
28+
#include <QUrl>
29+
#include "HelpFeature.h"
4030
#include <FEBioLink/FEBioClass.h>
4131

4232
#define MANUAL_PATH "https://febiosoftware.github.io/febio-feature-manual/features/"
4333

44-
class Ui::CHelpDialog
45-
{
46-
public:
47-
QPushButton* helpButton;
48-
QHBoxLayout* helpLayout;
49-
50-
public:
51-
void setupUi(QWidget* parent)
52-
{
53-
QVBoxLayout* mainLayout = new QVBoxLayout;
54-
helpLayout = new QHBoxLayout;
55-
56-
mainLayout->addLayout(helpLayout);
57-
58-
QDialogButtonBox* bb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
59-
60-
helpButton = new QPushButton("Help");
61-
helpButton->setCheckable(true);
62-
63-
bb->addButton(helpButton, QDialogButtonBox::HelpRole);
64-
65-
mainLayout->addWidget(bb);
66-
67-
QObject::connect(bb, SIGNAL(accepted()), parent, SLOT(accept()));
68-
QObject::connect(bb, SIGNAL(rejected()), parent, SLOT(reject()));
69-
QObject::connect(bb, SIGNAL(helpRequested()), parent, SLOT(on_help_clicked()));
70-
71-
parent->setLayout(mainLayout);
72-
}
73-
};
74-
75-
76-
CHelpDialog::CHelpDialog(QWidget* parent) : QDialog(parent), ui(new Ui::CHelpDialog)
77-
{
78-
ui->setupUi(this);
79-
80-
m_module = FEBio::GetActiveModule();
81-
}
82-
83-
CHelpDialog::~CHelpDialog() { delete ui; }
84-
85-
void ShowHelp(const QString& url)
86-
{
87-
QDesktopServices::openUrl(QUrl(QString(MANUAL_PATH) + url));
88-
}
89-
90-
void CHelpDialog::on_help_clicked()
91-
{
92-
UpdateHelpURL();
93-
94-
if(m_url.isEmpty())
95-
{
96-
QMessageBox::information(this, "Help", "Please select an item before clicking Help.");
97-
}
98-
else
99-
{
100-
ShowHelp(m_url);
101-
}
102-
}
103-
104-
void CHelpDialog::SetLeftSideLayout(QLayout* layout)
105-
{
106-
ui->helpLayout->insertLayout(0, layout);
107-
}
108-
10934
QString ClassIDToURL(int classID)
11035
{
11136
QString url;
@@ -122,7 +47,7 @@ QString ClassIDToURL(int classID)
12247
return url;
12348
}
12449

125-
void CHelpDialog::SetURL(const QString& url)
50+
void ShowHelp(const QString& url)
12651
{
127-
m_url = url;
52+
QDesktopServices::openUrl(QUrl(QString(MANUAL_PATH) + url));
12853
}
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
SOFTWARE.*/
2626

2727
#pragma once
28-
#include <QDialog>
29-
30-
class QLayout;
31-
32-
namespace Ui {
33-
class CHelpDialog;
34-
};
35-
36-
class CHelpDialog : public QDialog
37-
{
38-
Q_OBJECT
39-
40-
public:
41-
CHelpDialog(QWidget* parent);
42-
virtual ~CHelpDialog();
43-
44-
protected slots:
45-
void on_help_clicked();
46-
47-
public:
48-
void SetLeftSideLayout(QLayout* layout);
49-
50-
virtual void UpdateHelpURL() = 0;
51-
52-
protected:
53-
void SetURL(const QString& url);
54-
55-
protected:
56-
int m_module;
57-
QString m_url;
58-
QString m_unselectedHelp;
59-
private:
60-
Ui::CHelpDialog* ui;
61-
};
28+
#include <QString>
6229

6330
QString ClassIDToURL(int classID);
6431
void ShowHelp(const QString& url);

FEBioStudio/ModelViewer.cpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ SOFTWARE.*/
6060
#include "FEObjectProps.h"
6161
#include "GLHighlighter.h"
6262
#include "Command.h"
63-
#include "HelpDialog.h" // for ShowHelp
63+
#include "HelpFeature.h"
6464
using namespace std;
6565

6666
class CDlgWarnings : public QDialog
@@ -413,26 +413,8 @@ void CModelViewer::on_helpButton_clicked()
413413
return;
414414
}
415415

416-
// find the class ID
417-
int classID = -1;
418-
GMaterial* gmat = dynamic_cast<GMaterial*>(m_currentObject);
419-
if (gmat)
420-
{
421-
FEBioMaterial* pm = dynamic_cast<FEBioMaterial*>(gmat->GetMaterialProperties());
422-
if (pm)
423-
{
424-
classID = FEBio::GetClassId(pm->GetSuperClassID(), pm->GetTypeString());
425-
}
426-
}
427-
FSModelComponent* pmc = dynamic_cast<FSModelComponent*>(m_currentObject);
428-
if (pmc)
429-
{
430-
classID = FEBio::GetClassId(pmc->GetSuperClassID(), pmc->GetTypeString());
431-
}
432-
433-
// show the help page
434-
QString url = ClassIDToURL(classID);
435-
if (url.isEmpty())
416+
QString url = HelpURLFromObject(m_currentObject);
417+
if (url.isEmpty())
436418
{
437419
QMessageBox::critical(this, "Help", "No help available for this item.");
438420
}
@@ -2202,6 +2184,13 @@ void CModelViewer::ShowContextMenu(CModelTreeItem* data, QPoint pt)
22022184
return;
22032185
}
22042186

2187+
QString url = HelpURLFromObject(data->obj);
2188+
if (!url.isEmpty())
2189+
{
2190+
menu.addSeparator();
2191+
menu.addAction("View Help", [=](){ ShowHelp(url); });
2192+
}
2193+
22052194
if (del)
22062195
{
22072196
menu.addSeparator();
@@ -2733,4 +2722,26 @@ void CModelViewer::OnExportNRRD()
27332722
QMessageBox::critical(GetMainWindow(), "Export image", msg);
27342723
}
27352724
}
2725+
}
2726+
2727+
QString CModelViewer::HelpURLFromObject(FSObject* po)
2728+
{
2729+
// find the class ID
2730+
int classID = -1;
2731+
GMaterial* gmat = dynamic_cast<GMaterial*>(po);
2732+
if (gmat)
2733+
{
2734+
FEBioMaterial* pm = dynamic_cast<FEBioMaterial*>(gmat->GetMaterialProperties());
2735+
if (pm)
2736+
{
2737+
classID = FEBio::GetClassId(pm->GetSuperClassID(), pm->GetTypeString());
2738+
}
2739+
}
2740+
FSModelComponent* pmc = dynamic_cast<FSModelComponent*>(po);
2741+
if (pmc)
2742+
{
2743+
classID = FEBio::GetClassId(pmc->GetSuperClassID(), pmc->GetTypeString());
2744+
}
2745+
2746+
return ClassIDToURL(classID);
27362747
}

FEBioStudio/ModelViewer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ public slots:
207207
signals:
208208
void currentObjectChanged(FSObject* po);
209209

210+
private:
211+
QString HelpURLFromObject(FSObject* po);
212+
210213
private:
211214
Ui::CModelViewer* ui;
212215
FSObject* m_currentObject; // object whose properties are displayed

0 commit comments

Comments
 (0)