* Loads the user entered batchlist file into a private variable for later use * * @param file The batchlist file to load * * @history 2010-03-26 Sharmila Prasad - Remove the restriction of the number of * columns in the batchlist file to 10. * @throws Isis::IException::User - The batchlist file could not be opened * @throws Isis::IException::User - The number of col
| 322 | * @throws Isis::IException::User - The batchlist does not contain any data |
| 323 | */ |
| 324 | void UserInterface::loadBatchList(const QString file) { |
| 325 | // Read in the batch list |
| 326 | TextFile temp; |
| 327 | try { |
| 328 | temp.Open(file); |
| 329 | } |
| 330 | catch (IException &e) { |
| 331 | QString msg = "The batchlist file [" + file + "] could not be opened"; |
| 332 | throw IException(IException::User, msg, _FILEINFO_); |
| 333 | } |
| 334 | |
| 335 | p_batchList.resize( temp.LineCount() ); |
| 336 | |
| 337 | for (int i = 0; i < temp.LineCount(); i++) { |
| 338 | QString t; |
| 339 | temp.GetLine(t); |
| 340 | |
| 341 | // Convert tabs to spaces but leave tabs inside quotes alone |
| 342 | t = IString(t).Replace("\t", " ", true).ToQt(); |
| 343 | |
| 344 | t = IString(t).Compress().ToQt().trimmed(); |
| 345 | // Allow " ," " , " or ", " as a valid single seperator |
| 346 | t = IString(t).Replace(" ,", ",", true).ToQt(); |
| 347 | t = IString(t).Replace(", ", ",", true).ToQt(); |
| 348 | // Convert all spaces to "," the use "," as delimiter |
| 349 | t = IString(t).Replace(" ", ",", true).ToQt(); |
| 350 | int j = 0; |
| 351 | |
| 352 | QStringList tokens = t.split(","); |
| 353 | |
| 354 | foreach (QString token, tokens) { |
| 355 | // removes quotes from tokens. NOTE: also removes escaped quotes. |
| 356 | token = token.remove( QRegularExpression("[\"']") ); |
| 357 | p_batchList[i].push_back(token); |
| 358 | j++ ; |
| 359 | } |
| 360 | |
| 361 | p_batchList[i].resize(j); |
| 362 | // Every row in the batchlist must have the same number of columns |
| 363 | if (i == 0) |
| 364 | continue; |
| 365 | if ( p_batchList[i - 1].size() != p_batchList[i].size() ) { |
| 366 | QString msg = "The number of columns must be constant in batchlist"; |
| 367 | throw IException(IException::User, msg, _FILEINFO_); |
| 368 | } |
| 369 | } |
| 370 | // The batchlist cannot be empty |
| 371 | if (p_batchList.size() < 1) { |
| 372 | QString msg = "The list file [" + file + "] does not contain any data"; |
| 373 | throw IException(IException::User, msg, _FILEINFO_); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | |
| 378 |