Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const QRegularExpression regx(QStringLiteral(R"**((?:(X)([-+]?\d*\.?\d+)\s*(Y)([-+]?\d*\.?\d+))|(?:(X)([-+]?\d*\.?\d+))|(?:(Y)([-+]?\d*\.?\d+)))**"));
  2. QTextStream in(&file);
  3. while(!in.atEnd()) {
  4.     QString line = in.readLine();
  5.     const QRegularExpressionMatch reMatch = regx.match(line);
  6.     if(reMatch.hasMatch()){
  7.         if(reMatch.lastCapturedIndex()==4){ // matched both X and Y
  8.             const double lx = reMatch.captured(2).toDouble();
  9.             const double ly = reMatch.captured(4).toDouble();
  10.             qDebug()<<"X : " << lx << " ly" << ly;
  11.             if(lx<minX)
  12.                 minX=lx;
  13.             else if (lx>maxX)
  14.                 maxX=lx;
  15.             if(ly<minY)
  16.                 minY=ly;
  17.             else if (ly>maxY)
  18.                 maxY=ly;
  19.         }
  20.         else if(reMatch.captured(1).compare(QLatin1String("X"),Qt::CaseInsensitive)==0){ // matched X
  21.             const double lx = reMatch.captured(2).toDouble();
  22.             qDebug()<<"X : " << lx;
  23.             if(lx<minX)
  24.                 minX=lx;
  25.             else if (lx>maxX)
  26.                 maxX=lx;
  27.         }
  28.         else {// matched Y
  29.             const double ly = reMatch.captured(2).toDouble();
  30.             qDebug() << " ly" << ly;
  31.             if(ly<minY)
  32.                 minY=ly;
  33.             else if (ly>maxY)
  34.                 maxY=ly;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement