Seamly2D
Code documentation
edit_formula_dialog.h
Go to the documentation of this file.
1 /******************************************************************************
2 * @file edit_formula_dialog.h
3 ** @author DSCaskey <dscaskey@gmail.com>
4 ** @date 10 Jun, 2023
5 **
6 ** @brief
7 ** @copyright
8 ** This source code is part of the Seamly2D project, a pattern making
9 ** program to create and model patterns of clothing.
10 ** Copyright (C) 2017-2023 Seamly2D project
11 ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
12 **
13 ** Seamly2D is free software: you can redistribute it and/or modify
14 ** it under the terms of the GNU General Public License as published by
15 ** the Free Software Foundation, either version 3 of the License, or
16 ** (at your option) any later version.
17 **
18 ** Seamly2D is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
22 **
23 ** You should have received a copy of the GNU General Public License
24 ** along with Seamly2D. If not, see <http://www.gnu.org/licenses/>.
25 **
26 *************************************************************************/
27 
28 /************************************************************************
29  **
30  ** @file dialogeditwrongformula.h
31  ** @author Roman Telezhynskyi <dismine(at)gmail.com>
32  ** @date 29 5, 2014
33  **
34  ** @brief
35  ** @copyright
36  ** This source code is part of the Valentina project, a pattern making
37  ** program, whose allow create and modeling patterns of clothing.
38  ** Copyright (C) 2013-2015 Valentina project
39  ** <https://github.com/fashionfreedom/seamly2d> All Rights Reserved.
40  **
41  ** Valentina is free software: you can redistribute it and/or modify
42  ** it under the terms of the GNU General Public License as published by
43  ** the Free Software Foundation, either version 3 of the License, or
44  ** (at your option) any later version.
45  **
46  ** Valentina is distributed in the hope that it will be useful,
47  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
48  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49  ** GNU General Public License for more details.
50  **
51  ** You should have received a copy of the GNU General Public License
52  ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
53  **
54  *************************************************************************/
55 
56 #ifndef EDIT_FORMULA_DIALOG_H
57 #define EDIT_FORMULA_DIALOG_H
58 
59 #include <qcompilerdetection.h>
60 #include <QMap>
61 #include <QMetaObject>
62 #include <QObject>
63 #include <QString>
64 #include <QTableWidgetItem>
65 #include <QtGlobal>
66 
67 #include "../tools/dialogtool.h"
68 
71 
72 template <class T> class QSharedPointer;
73 class VMeasurement;
74 
75 namespace Ui
76 {
77 class EditFormulaDialog;
78 }
79 
80 /**
81  * @brief The EditFormulaDialog class dialog for editing wrong formula.
82  *
83  * When math parser find in formula error user can try fix issue. Dialog will show all variables that user can use in
84  * this formula. Dialog check fixed variant of formula.
85  *
86  * Don't implemant button "Apply" for this dialog!!
87  */
89 {
90  Q_OBJECT
91 public:
92  EditFormulaDialog(const VContainer *data, const quint32 &toolId, QWidget *parent = nullptr);
93  virtual ~EditFormulaDialog() Q_DECL_OVERRIDE;
94 
95  QString GetFormula() const;
96  void SetFormula(const QString &value);
97  void setCheckZero(bool value);
98  void setCheckLessThanZero(bool value);
99  void setPostfix(const QString &value);
100 
101 public slots:
102  virtual void DialogAccepted() Q_DECL_OVERRIDE;
103  virtual void DialogRejected() Q_DECL_OVERRIDE;
104  virtual void EvalFormula() Q_DECL_OVERRIDE;
105  void valueChanged(int row);
106  void tabChanged(int row);
107  void insertVariable();
108  void insertValue(QTableWidgetItem * item);
109  void measurements();
110  void lineLengths();
111  void arcRadii();
112  void curveAngles();
113  void curveLengths();
114  void controlPointLengths();
115  void lineAngles();
116  void customVariables();
117  void functions();
118 
119 protected:
120  virtual void CheckState() Q_DECL_FINAL;
121  virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
122  virtual void showEvent( QShowEvent *event ) Q_DECL_OVERRIDE;
123  virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
124 
125 private slots:
126  void filterVariables(const QString &filter);
127 
128 private:
129  Q_DISABLE_COPY(EditFormulaDialog)
131 
132  QString m_formula; //! @brief formula string with formula
133  QString m_undoFormula; //! @brief copy of formula string used to perform undo
136  QString m_postfix;
138 
139  void initializeVariables();
140 
141  template <class key, class val>
142  void showVariable(const QMap<key, val> &var);
143  void showMeasurements(const QMap<QString, QSharedPointer<VMeasurement> > &var);
144  void showFunctions();
145 
146  void setDescription(const QString &name, qreal value, const QString &unit,
147  const QString &type, const QString &description);
148  void clearFormula();
149  void undoFormula();
150 };
151 
152 
153 #endif // EDIT_FORMULA_DIALOG_H
The DialogTool class parent for all dialog of tools.
Definition: dialogtool.h:107
quint32 toolId
Definition: dialogtool.h:225
const VContainer * data
data container with data
Definition: dialogtool.h:177
The EditFormulaDialog class dialog for editing wrong formula.
QString GetFormula() const
void SetFormula(const QString &value)
void insertVariable()
insertVariable insert variable into line edit
void customVariables()
customVariables show custom variables in list
void curveLengths()
curveLengths show lengths of curve variables in list
void filterVariables(const QString &filter)
virtual void EvalFormula() Q_DECL_OVERRIDE
void setCheckZero(bool value)
void insertValue(QTableWidgetItem *item)
insertValue insert variable into line edit
void measurements()
measurements show measurements in list
bool m_checkZero
copy of formula string used to perform undo
virtual void DialogAccepted() Q_DECL_OVERRIDE
EditFormulaDialog(const VContainer *data, const quint32 &toolId, QWidget *parent=nullptr)
virtual ~EditFormulaDialog() Q_DECL_OVERRIDE
void controlPointLengths()
controlPointLengths show lengths of control point variables in list
void setCheckLessThanZero(bool value)
void lineAngles()
lineAngles show angles of line variables in list
void curveAngles()
curveAngles show angles of curve variables in list
QString m_undoFormula
formula string with formula
void valueChanged(int row)
valueChanged show description when current variable changed
void showFunctions()
showFunctions show functions in list
void lineLengths()
lineLengths show lengths of line variables in list
void arcRadii()
arcRadii show radii of arc variables in list
void tabChanged(int row)
menu tabChanged
virtual void CheckState() Q_DECL_FINAL
CheckState enable, when all is correct, or disable, when something wrong, button ok.
void functions()
functions show functions in list
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE
closeEvent handle when dialog cloded
virtual void DialogRejected() Q_DECL_OVERRIDE
void showVariable(const QMap< key, val > &var)
showVariable show variables in list
virtual void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE
Ui::EditFormulaDialog * ui
void showMeasurements(const QMap< QString, QSharedPointer< VMeasurement > > &var)
showMeasurements show measurements in table
void setPostfix(const QString &value)
virtual void showEvent(QShowEvent *event) Q_DECL_OVERRIDE
showEvent handle when window show
void setDescription(const QString &name, qreal value, const QString &unit, const QString &type, const QString &description)
The VContainer class container of all variables.
Definition: vcontainer.h:141
The VMeasurement class keep data row of multisize table.
Definition: vmeasurement.h:74
@ Custom
@ LineAngles
@ ArcRadii
@ CurveLengths
@ Functions
@ CurveAngles
@ CPLengths
@ Measurements
@ LineLengths