Changeset 87 in tspsg-svn for trunk/src/tspmodel.cpp
- Timestamp:
- Jan 12, 2010, 3:11:24 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tspmodel.cpp
r81 r87 1 1 /* 2 2 * TSPSG: TSP Solver and Generator 3 * Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 82 82 if (index.row() < nCities && index.column() < nCities) 83 83 if (table[index.row()][index.column()] == INFINITY) 84 return tr Utf8(INFSTR);84 return tr(INFSTR); 85 85 else 86 86 //! \hack HACK: Converting to string to prevent spinbox in edit mode … … 119 119 if (role == Qt::DisplayRole) { 120 120 if (orientation == Qt::Vertical) 121 return tr Utf8("City %1").arg(section + 1);121 return tr("City %1").arg(section + 1); 122 122 else 123 return tr Utf8("%1").arg(section + 1);123 return tr("%1").arg(section + 1); 124 124 } 125 125 return QVariant(); … … 139 139 if (!f.open(QIODevice::ReadOnly)) { 140 140 QApplication::restoreOverrideCursor(); 141 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),QString(trUtf8("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec();141 QMessageBox(QMessageBox::Critical,tr("Task Load"),QString(tr("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec(); 142 142 return false; 143 143 } … … 163 163 f.close(); 164 164 QApplication::restoreOverrideCursor(); 165 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unknown file format or file is corrupted."),QMessageBox::Ok).exec();165 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unknown file format or file is corrupted."),QMessageBox::Ok).exec(); 166 166 return false; 167 167 } … … 191 191 void CTSPModel::randomize() 192 192 { 193 int randMin = settings->value(" MinCost",DEF_RAND_MIN).toInt();194 int randMax = settings->value(" MaxCost",DEF_RAND_MAX).toInt();193 int randMin = settings->value("Task/RandMin",DEF_RAND_MIN).toInt(); 194 int randMax = settings->value("Task/RandMax",DEF_RAND_MAX).toInt(); 195 195 for (int r = 0; r < nCities; r++) 196 196 for (int c = 0; c < nCities; c++) … … 226 226 if (!f.open(QIODevice::WriteOnly)) { 227 227 QApplication::restoreOverrideCursor(); 228 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),QString(trUtf8("Unable to create task file.\nError: %1\nMaybe, file is read-only?")).arg(f.errorString()),QMessageBox::Ok).exec();228 QMessageBox(QMessageBox::Critical,tr("Task Save"),QString(tr("Unable to create task file.\nError: %1\nMaybe, file is read-only?")).arg(f.errorString()),QMessageBox::Ok).exec(); 229 229 return false; 230 230 } … … 234 234 f.close(); 235 235 QApplication::restoreOverrideCursor(); 236 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();236 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 237 237 return false; 238 238 } … … 242 242 f.close(); 243 243 QApplication::restoreOverrideCursor(); 244 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();244 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 245 245 return false; 246 246 } … … 250 250 f.close(); 251 251 QApplication::restoreOverrideCursor(); 252 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();252 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 253 253 return false; 254 254 } … … 258 258 f.close(); 259 259 QApplication::restoreOverrideCursor(); 260 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();260 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 261 261 return false; 262 262 } … … 266 266 f.close(); 267 267 QApplication::restoreOverrideCursor(); 268 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();268 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 269 269 return false; 270 270 } … … 274 274 f.close(); 275 275 QApplication::restoreOverrideCursor(); 276 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();276 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 277 277 return false; 278 278 } … … 281 281 for (int c = 0; c < nCities; c++) 282 282 if (r != c) { 283 ds << table[r][c];283 ds << static_cast<double>(table[r][c]); // We cast to double because qreal may be float on some platforms and we store double values in file 284 284 if (f.error() != QFile::NoError) { 285 285 f.close(); 286 286 QApplication::restoreOverrideCursor(); 287 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();287 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 288 288 return false; 289 289 } … … 312 312 else { 313 313 bool ok; 314 double tmp = value.toDouble(&ok);314 qreal tmp = value.toReal(&ok); 315 315 if (!ok || tmp < 0) 316 316 return false; … … 354 354 return false; 355 355 else if (status == QDataStream::ReadPastEnd) 356 err = tr Utf8("Unexpected end of file.");356 err = tr("Unexpected end of file."); 357 357 else if (status == QDataStream::ReadCorruptData) 358 err = tr Utf8("Corrupt data read. File possibly corrupted.");358 err = tr("Corrupt data read. File possibly corrupted."); 359 359 else 360 err = tr Utf8("Unknown error.");360 err = tr("Unknown error."); 361 361 QApplication::restoreOverrideCursor(); 362 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + err,QMessageBox::Ok).exec();362 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + err,QMessageBox::Ok).exec(); 363 363 return true; 364 364 } … … 377 377 if (version > TSPT_VERSION) { 378 378 QApplication::restoreOverrideCursor(); 379 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();379 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 380 380 return false; 381 381 } … … 391 391 if ((size < 3) || (size > MAX_NUM_CITIES)) { 392 392 QApplication::restoreOverrideCursor(); 393 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();393 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 394 394 return false; 395 395 } … … 398 398 emit numCitiesChanged(size); 399 399 } 400 401 double x; // We need this as qreal may be float on some platforms and we store double values in file 400 402 // Travel costs 401 403 for (int r = 0; r < size; r++) 402 404 for (int c = 0; c < size; c++) 403 405 if (r != c) { 404 *ds >> table[r][c]; 406 *ds >> x; 407 table[r][c] = x; 405 408 if (loadError(ds->status())) { 406 409 clear(); … … 426 429 if (version > ZKT_VERSION) { 427 430 QApplication::restoreOverrideCursor(); 428 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();431 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 429 432 return false; 430 433 } … … 436 439 if ((size < 3) || (size > 5)) { 437 440 QApplication::restoreOverrideCursor(); 438 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();441 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 439 442 return false; 440 443 } … … 444 447 } 445 448 // Travel costs 446 doubleval;449 qreal val; 447 450 for (int r = 0; r < 5; r++) 448 451 for (int c = 0; c < 5; c++) 449 if ((r != c) && (r < size) ) {452 if ((r != c) && (r < size) && (c < size)) { 450 453 ds->readRawData(reinterpret_cast<char *>(&val),8); 451 454 if (loadError(ds->status())) { … … 466 469 } 467 470 468 inline double CTSPModel::rand(int min, int max) const 469 { 470 double r; 471 if (settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) 472 r = (double)qRound((double)qrand() / RAND_MAX * (max - min) * 100) / 100; 473 else 474 r = qRound((double)qrand() / RAND_MAX * (max - min)); 471 inline qreal CTSPModel::rand(int min, int max) const 472 { 473 qreal r; 474 if (settings->value("Task/FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) { 475 qreal x = qPow(10, settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 476 r = (qreal)qRound((qreal)qrand() / RAND_MAX * (max - min) * x) / x; 477 } else 478 r = qRound((qreal)qrand() / RAND_MAX * (max - min)); 475 479 return min + r; 476 480 }
Note: See TracChangeset
for help on using the changeset viewer.