Debian Codegraph @

GUIWidgets/QtWidgets/QtDialog.h

raw
1 /* Copyright (c) 2023, DyssolTEC.
2 * All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */
3
4 #pragma once
5
6 #include "ModelsManager.h"
7 #include <QDialog>
8 #include <QSettings>
9
10 class CFlowsheet;
11 class QLabel;
12 class QLineEdit;
13 class QTableWidgetItem;
14
15 class CDyssolBaseWidget
16 {
17 protected:
18 CFlowsheet* m_flowsheet{}; // Pointer to the global flowsheet.
19 QSettings* m_settings{}; // Pointer to global settings.
20 CModelsManager* m_modelsManager{}; // Pointer to models manager.
21
22 std::vector<CDyssolBaseWidget*> m_childWidgets{}; // Pointers to child widgets.
23
24 public:
25 CDyssolBaseWidget() = default;
26 CDyssolBaseWidget(const CDyssolBaseWidget& _other) = default;
27 CDyssolBaseWidget(CDyssolBaseWidget&& _other) noexcept = default;
28 CDyssolBaseWidget& operator=(const CDyssolBaseWidget& _other) = default;
29 CDyssolBaseWidget& operator=(CDyssolBaseWidget&& _other) noexcept = default;
30 virtual ~CDyssolBaseWidget() = default;
31
32 /**
33 * \brief Sets pointers to child widgets.
34 * \param _widgets List of pointers to child widgets.
35 */
36 void SetChildWidgets(std::initializer_list<CDyssolBaseWidget*> _widgets);
37 /**
38 * \brief Adds a pointer to a child widget.
39 * \param _widget Pointer to a child widget.
40 */
41 void AddChildWidget(CDyssolBaseWidget* _widget);
42 /**
43 * \brief Sets all required pointers.
44 * Also sets the pointers to all child widgets.
45 * \param _flowsheet Pointer to the flowsheet.
46 * \param _modelsManager Pointer to models manager.
47 * \param _settings pointer to global settings.
48 */
49 virtual void SetPointers(CFlowsheet* _flowsheet, CModelsManager* _modelsManager, QSettings* _settings);
50 /**
51 * \brief Is called after all external pointers are set.
52 */
53 virtual void OnPointersSet() {}
54
55 /**
56 * \brief Returns pointer to models manager.
57 * \return Pointer to models manager.
58 */
59 [[nodiscard]] CModelsManager* GetModelsManager() const;
60 /**
61 * \brief Returns pointer to global settings.
62 * \return Pointer to global settings.
63 */
64 [[nodiscard]] QSettings* GetSettings() const;
65
66 /**
67 * \brief Shows a label.
68 * Current text in the item is used as label.
69 * \param _labelWidget Widget to set label.
70 */
71 void ShowLabel(QLabel* _labelWidget) const;
72 /**
73 * \brief Sets the given value to the QLineEdit
74 * \param _valueWidget Widget to set the value.
75 * \param _value Value in SI.
76 */
77 void ShowValue(QLineEdit* _valueWidget, double _value) const;
78 /**
79 * \brief Sets the given value to the QLineEdit
80 * \param _valueWidget Widget to set the value.
81 * \param _labelWidget Widget to set label.
82 * \param _value Value in SI.
83 */
84 void ShowValueAndLabel(QLineEdit* _valueWidget, QLabel* _labelWidget, double _value) const;
85
86 /**
87 * \brief Reads the value from QLineEdit.
88 * Converts it from the selected measurement unit to SI.
89 * The type of the measurement unit is read from the property "UnitType" in the value widget.
90 * \param _valueWidget Widget to read the value from.
91 * \return Value in SI.
92 */
93 double ReadValue(const QLineEdit* _valueWidget) const;
94 };
95
96 class CQtDialog
97 : public QDialog
98 , public CDyssolBaseWidget
99 {
100 Q_OBJECT
101
102 QString m_helpLink;
103
104 public:
105 CQtDialog(QWidget* _parent);
106 CQtDialog(QWidget* _parent, Qt::WindowFlags _flags);
107
108 void SetHelpLink(const QString& _helpLink);
109 QString GetHelpLink();
110
111 /**
112 * Opens help file.
113 */
114 void OpenHelp(const QString& _link);
115 /**
116 * \brief Is called after all external pointers are set.
117 */
118 void OnPointersSet() override;
119 /**
120 * \brief Updates all information on the widget.
121 */
122 virtual void UpdateWholeView() {}
123 /**
124 * \brief Is called upon loading of a new flowsheet or changes in the flowsheet data.
125 */
126 virtual void UpdateFromFlowsheet();
127 /**
128 * \brief Is called upon loading of a new materials database or changes in the database data.
129 */
130 virtual void UpdateFromMaterialsDB() {}
131
132 /**
133 * \brief Reaction on the change of visibility of the dialog.
134 * \param _flag
135 */
136 void setVisible(bool _flag) override;
137 /**
138 * \brief Reaction on the key event.
139 * \param _event Event.
140 */
141 void keyPressEvent(QKeyEvent* _event) override;
142
143 signals:
144 /**
145 * \brief Signal is emitted when data on the dialog are changed.
146 */
147 void DataChanged();
148 };