Index: src/tspmodel.cpp
===================================================================
--- src/tspmodel.cpp	(revision f1fb54b9f7060896ae686783ee1d8dcdce8d9409)
+++ src/tspmodel.cpp	(revision 1757eb594b8b3dff685100cc94067b0bf552099d)
@@ -1,5 +1,5 @@
 /*
  *  TSPSG: TSP Solver and Generator
- *  Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
+ *  Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name>
  *
  *  $Id$
@@ -82,5 +82,5 @@
 		if (index.row() < nCities && index.column() < nCities)
 			if (table[index.row()][index.column()] == INFINITY)
-				return trUtf8(INFSTR);
+				return tr(INFSTR);
 			else
 //! \hack HACK: Converting to string to prevent spinbox in edit mode
@@ -119,7 +119,7 @@
 	if (role == Qt::DisplayRole) {
 		if (orientation == Qt::Vertical)
-			return trUtf8("City %1").arg(section + 1);
+			return tr("City %1").arg(section + 1);
 		else
-			return trUtf8("%1").arg(section + 1);
+			return tr("%1").arg(section + 1);
 	}
 	return QVariant();
@@ -139,5 +139,5 @@
 	if (!f.open(QIODevice::ReadOnly)) {
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),QString(trUtf8("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Load"),QString(tr("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -163,5 +163,5 @@
 		f.close();
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unknown file format or file is corrupted."),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unknown file format or file is corrupted."),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -191,6 +191,6 @@
 void CTSPModel::randomize()
 {
-int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt();
-int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt();
+int randMin = settings->value("Task/RandMin",DEF_RAND_MIN).toInt();
+int randMax = settings->value("Task/RandMax",DEF_RAND_MAX).toInt();
 	for (int r = 0; r < nCities; r++)
 		for (int c = 0; c < nCities; c++)
@@ -226,5 +226,5 @@
 	if (!f.open(QIODevice::WriteOnly)) {
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),QString(trUtf8("Unable to create task file.\nError: %1\nMaybe, file is read-only?")).arg(f.errorString()),QMessageBox::Ok).exec();
+		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();
 		return false;
 	}
@@ -234,5 +234,5 @@
 		f.close();
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -242,5 +242,5 @@
 		f.close();
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -250,5 +250,5 @@
 		f.close();
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -258,5 +258,5 @@
 		f.close();
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -266,5 +266,5 @@
 		f.close();
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -274,5 +274,5 @@
 		f.close();
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -281,9 +281,9 @@
 		for (int c = 0; c < nCities; c++)
 			if (r != c) {
-				ds << table[r][c];
+				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
 				if (f.error() != QFile::NoError) {
 					f.close();
 					QApplication::restoreOverrideCursor();
-					QMessageBox(QMessageBox::Critical,trUtf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
+					QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
 					return false;
 				}
@@ -312,5 +312,5 @@
 		else {
 bool ok;
-double tmp = value.toDouble(&ok);
+qreal tmp = value.toReal(&ok);
 			if (!ok || tmp < 0)
 				return false;
@@ -354,11 +354,11 @@
 		return false;
 	else if (status == QDataStream::ReadPastEnd)
-		err = trUtf8("Unexpected end of file.");
+		err = tr("Unexpected end of file.");
 	else if (status == QDataStream::ReadCorruptData)
-		err = trUtf8("Corrupt data read. File possibly corrupted.");
+		err = tr("Corrupt data read. File possibly corrupted.");
 	else
-		err = trUtf8("Unknown error.");
+		err = tr("Unknown error.");
 	QApplication::restoreOverrideCursor();
-	QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + err,QMessageBox::Ok).exec();
+	QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + err,QMessageBox::Ok).exec();
 	return true;
 }
@@ -377,5 +377,5 @@
 	if (version > TSPT_VERSION) {
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();
+		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();
 		return false;
 	}
@@ -391,5 +391,5 @@
 	if ((size < 3) || (size > MAX_NUM_CITIES)) {
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -398,9 +398,12 @@
 		emit numCitiesChanged(size);
 	}
+
+double x; // We need this as qreal may be float on some platforms and we store double values in file
 	// Travel costs
 	for (int r = 0; r < size; r++)
 		for (int c = 0; c < size; c++)
 			if (r != c) {
-				*ds >> table[r][c];
+				*ds >> x;
+				table[r][c] = x;
 				if (loadError(ds->status())) {
 					clear();
@@ -426,5 +429,5 @@
 	if (version > ZKT_VERSION) {
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();
+		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();
 		return false;
 	}
@@ -436,5 +439,5 @@
 	if ((size < 3) || (size > 5)) {
 		QApplication::restoreOverrideCursor();
-		QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
+		QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
 		return false;
 	}
@@ -444,8 +447,8 @@
 	}
 	// Travel costs
-double val;
+qreal val;
 	for (int r = 0; r < 5; r++)
 		for (int c = 0; c < 5; c++)
-			if ((r != c) && (r < size)) {
+			if ((r != c) && (r < size) && (c < size)) {
 				ds->readRawData(reinterpret_cast<char *>(&val),8);
 				if (loadError(ds->status())) {
@@ -466,11 +469,12 @@
 }
 
-inline double CTSPModel::rand(int min, int max) const
-{
-double r;
-	if (settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool())
-		r = (double)qRound((double)qrand() / RAND_MAX * (max - min) * 100) / 100;
-	else
-		r = qRound((double)qrand() / RAND_MAX * (max - min));
+inline qreal CTSPModel::rand(int min, int max) const
+{
+qreal r;
+	if (settings->value("Task/FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) {
+qreal x = qPow(10, settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt());
+		r = (qreal)qRound((qreal)qrand() / RAND_MAX * (max - min) * x) / x;
+	} else
+		r = qRound((qreal)qrand() / RAND_MAX * (max - min));
 	return min + r;
 }
