MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / validateInput

Method validateInput

Gui/SpinBoxValidator.cpp:76–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76bool
77NumericKnobValidator::validateInput(const QString& userText,
78 double* valueToDisplay) const
79{
80 int dimension;
81 bool allDimsVisible = true;
82
83 if (_imp->isDoubleGui) {
84 allDimsVisible = _imp->isDoubleGui->getAllDimensionsVisible();
85 } else if (_imp->isIntGui) {
86 allDimsVisible = _imp->isIntGui->getAllDimensionsVisible();
87 } else if (_imp->isColorGui) {
88 allDimsVisible = _imp->isColorGui->getAllDimensionsVisible();
89 } else {
90 assert(0);
91 }
92 if (!allDimsVisible) {
93 dimension = -1;
94 } else {
95 if (_imp->isDoubleGui) {
96 dimension = _imp->isDoubleGui->getDimensionForSpinBox(_imp->spinbox);
97 } else if (_imp->isIntGui) {
98 dimension = _imp->isIntGui->getDimensionForSpinBox(_imp->spinbox);
99 } else if (_imp->isColorGui) {
100 dimension = _imp->isColorGui->getDimensionForSpinBox(_imp->spinbox);
101 } else {
102 dimension = 0;
103 }
104 }
105
106 *valueToDisplay = 0;
107 std::string ret;
108 QString simplifiedUserText = userText.simplified();
109 bool isPersistentExpression = simplifiedUserText.startsWith( QLatin1Char('=') );
110 if (isPersistentExpression) {
111 simplifiedUserText.remove(0, 1);
112 }
113 std::string expr = simplifiedUserText.toStdString();
114 KnobGuiPtr knob = _imp->knobUi.lock();
115
116 if (!expr.empty() && knob) {
117 try {
118 knob->getKnob()->validateExpression(expr, 0, false, &ret);
119 } catch (...) {
120 return false;
121 }
122
123 if (isPersistentExpression) {
124 //Only set the expression if it starts with '='
125 knob->pushUndoCommand( new SetExpressionCommand(knob->getKnob(),
126 false,
127 dimension,
128 expr) );
129 }
130
131
132 bool ok = false;
133 *valueToDisplay = QString::fromUtf8( ret.c_str() ).toDouble(&ok);

Callers 1

Calls 10

removeMethod · 0.80
toStdStringMethod · 0.80
emptyMethod · 0.80
validateExpressionMethod · 0.80
lockMethod · 0.45
getKnobMethod · 0.45
pushUndoCommandMethod · 0.45

Tested by

no test coverage detected