Debian Codegraph @

GUIWidgets/QtWidgets/QtDialog.cpp

raw
1 /* Copyright (c) 2023, DyssolTEC.
2 * All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */
3
4 #include "QtDialog.h"
5
6 #include "DyssolStringConstants.h"
7 #include <QKeyEvent>
8 #include <QMessageBox>
9 #include <QCoreApplication>
10 #include <QDesktopServices>
11 #include <QLabel>
12 #include <QLineEdit>
13
14 void CDyssolBaseWidget::SetChildWidgets(std::initializer_list<CDyssolBaseWidget*> _widgets)
15 {
16 m_childWidgets = _widgets;
17 }
18
19 void CDyssolBaseWidget::AddChildWidget(CDyssolBaseWidget* _widget)
20 {
21 m_childWidgets.push_back(_widget);
22 }
23
24 void CDyssolBaseWidget::SetPointers(CFlowsheet* _flowsheet, CModelsManager* _modelsManager, QSettings* _settings)
25 {
26 m_flowsheet = _flowsheet;
27 m_modelsManager = _modelsManager;
28 m_settings = _settings;
29 m_settings = _settings;
30 for (auto* w : m_childWidgets)
31 w->SetPointers(_flowsheet, _modelsManager, _settings);
32 OnPointersSet();
33 }
34
35 CModelsManager* CDyssolBaseWidget::GetModelsManager() const
36 {
37 return m_modelsManager;
38 }
39
40 QSettings* CDyssolBaseWidget::GetSettings() const
41 {
42 return m_settings;
43 }
44
45 void CDyssolBaseWidget::ShowLabel(QLabel* _labelWidget) const
46 {
47 const QString text = _labelWidget->text().remove(QRegExp{ R"(\[[^\]]*\])" }).trimmed();
48 _labelWidget->setText(text);
49 }
50
51 void CDyssolBaseWidget::ShowValue(QLineEdit* _valueWidget, double _value) const
52 {
53 _valueWidget->setText(QString::number(_value));
54 }
55
56 void CDyssolBaseWidget::ShowValueAndLabel(QLineEdit* _valueWidget, QLabel* _labelWidget, double _value) const
57 {
58 ShowLabel(_labelWidget);
59 ShowValue(_valueWidget, _value);
60 }
61
62 double CDyssolBaseWidget::ReadValue(const QLineEdit* _valueWidget) const
63 {
64 return _valueWidget->text().toDouble();
65 }
66
67
68 CQtDialog::CQtDialog(QWidget* _parent)
69 : CQtDialog{ _parent, Qt::WindowFlags() }
70 {
71 }
72
73 CQtDialog::CQtDialog(QWidget* _parent, Qt::WindowFlags _flags)
74 : QDialog{ _parent, _flags }
75 {
76 // disable context menu
77 setContextMenuPolicy(Qt::NoContextMenu);
78 }
79
80 void CQtDialog::SetHelpLink(const QString& _helpLink)
81 {
82 m_helpLink = _helpLink;
83 }
84
85 QString CQtDialog::GetHelpLink()
86 {
87 return m_helpLink;
88 }
89
90 void CQtDialog::OpenHelp(const QString& _link)
91 {
92 if (_link.isEmpty())
93 {
94 QMessageBox::information(this, StrConst::Dyssol_MainWindowName, "No help file available.");
95 return;
96 }
97
98 // try to open like remote url from web
99 QDesktopServices::openUrl(QUrl(StrConst::Dyssol_HelpURL + _link));
100 }
101
102 void CQtDialog::OnPointersSet()
103 {
104 CDyssolBaseWidget::OnPointersSet();
105 UpdateFromFlowsheet();
106 }
107
108 void CQtDialog::UpdateFromFlowsheet()
109 {
110 if (isVisible())
111 UpdateWholeView();
112 }
113
114 void CQtDialog::setVisible(bool _flag)
115 {
116 if (!isVisible() && _flag)
117 UpdateWholeView();
118 QDialog::setVisible(_flag);
119 }
120
121 void CQtDialog::keyPressEvent(QKeyEvent* _event)
122 {
123 if (_event->key() == Qt::Key_F1)
124 OpenHelp(m_helpLink);
125 else
126 QDialog::keyPressEvent(_event);
127 }