Index: trunk/src/mainwindow.cpp
===================================================================
--- trunk/src/mainwindow.cpp	(revision 47)
+++ trunk/src/mainwindow.cpp	(revision 50)
@@ -46,8 +46,9 @@
 	actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
 	loadLangList();
-	spinCities->setValue(settings->value("NumCities",5).toInt());
+	spinCities->setMaximum(MAX_NUM_CITIES);
 	actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
 	connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
 	connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered()));
+	connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered()));
 	connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered()));
 	connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered()));
@@ -62,7 +63,8 @@
 	connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
 	connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked()));
+	connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked()));
 	connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
+	setCentralWidget(tabWidget);
 QRect rect = geometry();
-	setCentralWidget(tabWidget);
 #ifndef Q_OS_WINCE
 	if (settings->value("SavePos",false).toBool()) {
@@ -82,22 +84,22 @@
 	qsrand(QDateTime().currentDateTime().toTime_t());
 	tspmodel = new CTSPModel();
-	tspmodel->setNumCities(spinCities->value());
-	taskView->setModel(tspmodel);
 	connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
 	connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged()));
 	connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged()));
-	if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) {
+	if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1))))
 		setFileName(QCoreApplication::arguments().at(1));
-		setWindowModified(false);
-	} else
+	else {
 		setFileName();
-#ifdef Q_OS_WINCE
+		spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
+	}
+	taskView->setModel(tspmodel);
+	setWindowModified(false);
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif // Q_OS_WINCE
 }
 
 void MainWindow::enableSolutionActions(bool enable)
 {
+	buttonSaveSolution->setEnabled(enable);
 	actionFileSaveAsSolution->setEnabled(enable);
 	solutionText->setEnabled(enable);
@@ -173,9 +175,6 @@
 void MainWindow::spinCitiesValueChanged(int n)
 {
-#ifdef Q_OS_WINCE
 int count = tspmodel->numCities();
-#endif // Q_OS_WINCE
 	tspmodel->setNumCities(n);
-#ifdef Q_OS_WINCE
 	if (n > count)
 		for (int k = count; k < n; k++) {
@@ -183,5 +182,4 @@
 			taskView->resizeRowToContents(k);
 		}
-#endif // Q_OS_WINCE
 }
 
@@ -204,8 +202,6 @@
 		return;
 	tspmodel->clear();
-#ifdef Q_OS_WINCE
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif
 	setFileName();
 	setWindowModified(false);
@@ -238,8 +234,6 @@
 	}
 	setFileName(files.first());
-#ifdef Q_OS_WINCE
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif
 	tabWidget->setCurrentIndex(0);
 	setWindowModified(false);
@@ -247,4 +241,16 @@
 	enableSolutionActions(false);
 	QApplication::restoreOverrideCursor();
+}
+
+void MainWindow::actionFileSaveTriggered()
+{
+	if ((fileName == trUtf8("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive)))
+		saveTask();
+	else {
+		QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+		if (tspmodel->saveTask(fileName))
+			setWindowModified(false);
+		QApplication::restoreOverrideCursor();
+	}
 }
 
@@ -350,8 +356,11 @@
 	tspmodel->randomize();
 	setWindowModified(true);
-#ifdef Q_OS_WINCE
 	taskView->resizeColumnsToContents();
 	taskView->resizeRowsToContents();
-#endif // Q_OS_WINCE
+}
+
+void MainWindow::buttonBackToTaskClicked()
+{
+	tabWidget->setCurrentIndex(0);
 }
 
@@ -395,5 +404,5 @@
 	}
 CTSPSolver solver;
-sStep *root = solver.solve(spinCities->value(),matrix);
+sStep *root = solver.solve(n,matrix,this);
 	if (!root)
 		return;
@@ -542,4 +551,6 @@
 void MainWindow::numCitiesChanged(int nCities)
 {
+	blockSignals(true);
 	spinCities->setValue(nCities);
-}
+	blockSignals(false);
+}
