Debian Codegraph @

src/Gui/Dialogs/DlgExpressionInput.h

raw
1 /***************************************************************************
2 * Copyright (c) 2015 Eivind Kvedalen <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 51 Franklin Street, *
19 * Fifth Floor, Boston, MA 02110-1301, USA *
20 * *
21 ***************************************************************************/
22
23 #ifndef GUI_DIALOG_DLGEXPRESSIONINPUT_H
24 #define GUI_DIALOG_DLGEXPRESSIONINPUT_H
25
26 #include <QDialog>
27 #include <QTreeWidget>
28 #include <QStandardItemModel>
29 #include <App/ObjectIdentifier.h>
30 #include <Base/Type.h>
31 #include <Base/Unit.h>
32 #include <memory>
33
34 #include "Dialogs/DlgAddProperty.h"
35
36 namespace Ui
37 {
38 class DlgExpressionInput;
39 }
40
41 namespace Base
42 {
43 class Quantity;
44 }
45
46 namespace App
47 {
48 class Path;
49 class Expression;
50 class DocumentObject;
51 } // namespace App
52
53 namespace Gui::Dialog
54 {
55
56 class GuiExport NumberRange
57 {
58 public:
59 void setRange(double minimum, double maximum);
60 void clearRange();
61 void throwIfOutOfRange(const Base::Quantity&) const;
62
63 private:
64 double minimum {};
65 double maximum {};
66 bool defined {false};
67 };
68
69 class GuiExport DlgExpressionInput: public QDialog
70 {
71 Q_OBJECT
72
73 public:
74 explicit DlgExpressionInput(
75 const App::ObjectIdentifier& _path,
76 std::shared_ptr<const App::Expression> _expression,
77 const Base::Unit& _impliedUnit,
78 QWidget* parent = nullptr
79 );
80 ~DlgExpressionInput() override;
81
82 void setRange(double minimum, double maximum);
83 void clearRange();
84 std::shared_ptr<App::Expression> getExpression() const
85 {
86 return expression;
87 }
88
89 bool discardedFormula() const
90 {
91 return discarded;
92 }
93
94 QPoint expressionPosition() const;
95
96 public Q_SLOTS:
97 void show();
98 void accept() override;
99
100 protected:
101 void mouseReleaseEvent(QMouseEvent* event) override;
102 void mousePressEvent(QMouseEvent* event) override;
103 void resizeEvent(QResizeEvent* event) override;
104
105 private:
106 Base::Type getTypePath();
107 Base::Type determineTypeVarSet();
108 bool typeOkForVarSet();
109 void initializeErrorFrame();
110 void initializeVarSets();
111 bool checkCyclicDependencyVarSet(const QString& text);
112 void checkExpression(const QString& text);
113 int getVarSetIndex(const App::Document* doc) const;
114 void preselectGroup();
115 void preselectVarSet();
116 QStandardItemModel* createVarSetModel();
117 void setupVarSets();
118 std::string getType();
119 void reportVarSetInfo(const QString& message);
120 bool reportName();
121 bool reportGroup(const QString& nameGroup);
122 void updateVarSetInfo(bool checkExpr = true);
123 void createBindingVarSet(App::Property* propVarSet, App::DocumentObject* varSet);
124 void acceptWithVarSet();
125 bool isPropertyNameValid(
126 const QString& nameProp,
127 const App::DocumentObject* obj,
128 QString& message
129 ) const;
130 bool isGroupNameValid(const QString& nameGroup, QString& message) const;
131 void setMsgText();
132
133 private Q_SLOTS:
134 void textChanged();
135 void setDiscarded();
136 void onCheckVarSets(int state);
137 void onVarSetSelected(int index);
138 void onTextChangedGroup(const QString&);
139 void namePropChanged(const QString&);
140 bool needReportOnVarSet();
141
142 private:
143 ::Ui::DlgExpressionInput* ui;
144 std::shared_ptr<App::Expression> expression;
145 App::ObjectIdentifier path;
146 bool discarded;
147 const Base::Unit impliedUnit;
148 NumberRange numberRange;
149
150 std::string message;
151
152 bool varSetsVisible;
153 QPushButton* okBtn = nullptr;
154 QPushButton* discardBtn = nullptr;
155
156 EditFinishedComboBox comboBoxGroup;
157 };
158
159 } // namespace Gui::Dialog
160
161
162 #endif // GUI_DIALOG_EXPRESSIONINPUT_H