|
22 | 22 | #include <QDebug> |
23 | 23 | #include <counterrotationdlg.h> |
24 | 24 | #include <QString> |
25 | | -#include <QRegExp> |
| 25 | +#include <QRegularExpression> |
26 | 26 | #include "surfacemanager.h" |
27 | 27 |
|
28 | 28 | QString AstigReportTitle = ""; |
@@ -304,22 +304,36 @@ void define_input::compute(){ |
304 | 304 | emit computeStandAstig( this, rotationList); |
305 | 305 | } |
306 | 306 |
|
307 | | -QString getNumberFromQString(const QString &xString) |
308 | | -{ |
309 | 307 |
|
310 | | - QStringList l = xString.split("/"); |
311 | | - QString fn = l[l.size()-1]; |
312 | | - QRegExp xRegExp("(\\d+([\\.p]\\d+)?)"); |
313 | | - xRegExp.indexIn(fn); |
314 | | - QString c = xRegExp.cap(); |
315 | | - c.replace("p","."); |
316 | | - if (c == ""){ |
317 | | - xRegExp.indexIn(l[l.size()-2]); |
318 | | - c = xRegExp.cap(); |
319 | | - c.replace("p","."); |
320 | | - } |
321 | | - return c; |
| 308 | +/** |
| 309 | + * @brief Extracts a numeric value from a given QString, replacing 'p' with '.' for decimal representation. |
| 310 | + * |
| 311 | + * This function splits the input string by '/' and attempts to find a number (integer or decimal) |
| 312 | + * in the last segment. If not found, it checks the second-to-last segment. The number can contain |
| 313 | + * digits and may use 'p' as a decimal separator, which will be replaced by '.' in the output. |
| 314 | + * |
| 315 | + * @param xString The input QString from which to extract the number. |
| 316 | + * @return QString The extracted number as a string, or an empty string if no number is found. |
| 317 | + */ |
| 318 | +QString getNumberFromQString(const QString &xString) { |
| 319 | + QStringList l = xString.split("/"); |
| 320 | + QString fn = l[l.size()-1]; |
| 321 | + static const QRegularExpression xRegExp("(\\d+(?:[\\.p]\\d+)?)"); |
| 322 | + QRegularExpressionMatch match = xRegExp.match(fn); |
| 323 | + QString c; |
| 324 | + if(match.hasMatch()) { |
| 325 | + c = match.captured(1).replace("p","."); |
| 326 | + } else { |
| 327 | + match = xRegExp.match(l[l.size()-2]); |
| 328 | + if(match.hasMatch()) { |
| 329 | + c = match.captured(1).replace("p","."); |
| 330 | + } else { |
| 331 | + c = ""; |
| 332 | + } |
| 333 | + } |
| 334 | + return c; |
322 | 335 | } |
| 336 | + |
323 | 337 | void define_input::browse(){ |
324 | 338 |
|
325 | 339 | QStringList fileNames = QFileDialog::getOpenFileNames(this, |
|
0 commit comments