MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / newInput

Method newInput

src/Gui/InputField.cpp:265–338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263}
264
265void InputField::newInput(const QString& text)
266{
267 Quantity res;
268 try {
269 QString input = text;
270 fixup(input);
271
272 if (isBound()) {
273 std::shared_ptr<Expression> e(
274 ExpressionParser::parse(getPath().getDocumentObject(), input.toUtf8())
275 );
276
277 setExpression(e);
278
279 std::unique_ptr<Expression> evalRes(getExpression()->eval());
280
281 auto* value = freecad_cast<NumberExpression*>(evalRes.get());
282 if (value) {
283 res.setValue(value->getValue());
284 res.setUnit(value->getUnit());
285 }
286 }
287 else {
288 res = Quantity::parse(input.toStdString());
289 }
290 }
291 catch (Base::Exception& e) {
292 QString errorText = QString::fromLatin1(e.what());
293 if (iconLabel->isHidden()) {
294 iconLabel->setVisible(true);
295 }
296 Q_EMIT parseError(errorText);
297 validInput = false;
298 return;
299 }
300
301 if (res.isDimensionless()) {
302 res.setUnit(this->actUnit);
303 }
304
305 // check if unit fits!
306 if (actUnit != Unit::One && !res.isDimensionless() && actUnit != res.getUnit()) {
307 if (iconLabel->isHidden()) {
308 iconLabel->setVisible(true);
309 }
310 Q_EMIT parseError(QStringLiteral("Wrong unit"));
311 validInput = false;
312 return;
313 }
314
315 if (iconLabel->isVisible()) {
316 iconLabel->setVisible(false);
317 }
318 validInput = true;
319
320 if (res.getValue() > Maximum) {
321 res.setValue(Maximum);
322 }

Callers

nothing calls this directly

Calls 15

getExpressionFunction · 0.85
getDocumentObjectMethod · 0.80
evalMethod · 0.80
toStdStringMethod · 0.80
isDimensionlessMethod · 0.80
isBoundFunction · 0.50
parseFunction · 0.50
getPathFunction · 0.50
getMethod · 0.45
setValueMethod · 0.45
getValueMethod · 0.45
setUnitMethod · 0.45

Tested by

no test coverage detected