[5515c2c2a7] | 1 | /* |
---|
[bb994a7ff8] | 2 | * TSPSG - TSP Solver and Generator |
---|
| 3 | * Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com> |
---|
[003e4193be] | 4 | * |
---|
[bb994a7ff8] | 5 | * $Id$ |
---|
| 6 | * $URL$ |
---|
[5515c2c2a7] | 7 | * |
---|
[bb994a7ff8] | 8 | * This file is part of TSPSG. |
---|
[5515c2c2a7] | 9 | * |
---|
[bb994a7ff8] | 10 | * TSPSG is free software: you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License as published by |
---|
| 12 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 13 | * (at your option) any later version. |
---|
[5515c2c2a7] | 14 | * |
---|
[bb994a7ff8] | 15 | * TSPSG is distributed in the hope that it will be useful, |
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 18 | * GNU General Public License for more details. |
---|
[5515c2c2a7] | 19 | * |
---|
[bb994a7ff8] | 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with TSPSG. If not, see <http://www.gnu.org/licenses/>. |
---|
[5515c2c2a7] | 22 | */ |
---|
| 23 | |
---|
| 24 | #include <QtGui> |
---|
| 25 | #include "mainwindow.h" |
---|
| 26 | |
---|
[67e53c96d7] | 27 | // TODO: Saving window state on close |
---|
[052d1b9331] | 28 | |
---|
[5515c2c2a7] | 29 | MainWindow::MainWindow(QWidget *parent) |
---|
[bb994a7ff8] | 30 | : QMainWindow(parent), randMin(1), randMax(10) |
---|
[5515c2c2a7] | 31 | { |
---|
| 32 | setupUi(this); |
---|
| 33 | connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings())); |
---|
[bb994a7ff8] | 34 | connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve())); |
---|
| 35 | connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random())); |
---|
[003e4193be] | 36 | connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int))); |
---|
[052d1b9331] | 37 | // Centering MainWindow |
---|
| 38 | // TODO: Loading of saved window state |
---|
| 39 | QRect rect = geometry(); |
---|
[2bc8e278b7] | 40 | rect.moveCenter(QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen()).center()); |
---|
[052d1b9331] | 41 | setGeometry(rect); |
---|
[fc9f661ded] | 42 | qsrand(QDateTime().currentDateTime().toTime_t()); |
---|
[2bc8e278b7] | 43 | tspmodel = new CTSPModel(); |
---|
| 44 | tspmodel->randMin = randMin; |
---|
| 45 | tspmodel->randMax = randMax; |
---|
| 46 | tspmodel->setNumCities(spinCities->value()); |
---|
| 47 | taskView->setModel(tspmodel); |
---|
[003e4193be] | 48 | } |
---|
[052d1b9331] | 49 | |
---|
[003e4193be] | 50 | void MainWindow::CitiesNumberChanged(int n) |
---|
| 51 | { |
---|
[2bc8e278b7] | 52 | tspmodel->setNumCities(n); |
---|
[5515c2c2a7] | 53 | } |
---|
| 54 | |
---|
| 55 | void MainWindow::ChangeSettings() |
---|
| 56 | { |
---|
| 57 | SettingsDialog sd(this); |
---|
[bb994a7ff8] | 58 | sd.spinRandMin->setValue(randMin); |
---|
| 59 | sd.spinRandMax->setValue(randMax); |
---|
| 60 | if (sd.exec() == QDialog::Accepted) { |
---|
| 61 | randMin = sd.spinRandMin->value(); |
---|
| 62 | randMax = sd.spinRandMax->value(); |
---|
| 63 | } |
---|
[5515c2c2a7] | 64 | } |
---|
[bb994a7ff8] | 65 | |
---|
| 66 | void MainWindow::Random() |
---|
| 67 | { |
---|
[2bc8e278b7] | 68 | tspmodel->randomize(); |
---|
[bb994a7ff8] | 69 | } |
---|
| 70 | |
---|
| 71 | void MainWindow::Solve() |
---|
| 72 | { |
---|
| 73 | // TODO: Task solving goes here :-) |
---|
[e664262f7d] | 74 | tMatrix matrix; |
---|
| 75 | double *row; |
---|
[2bc8e278b7] | 76 | int n = spinCities->value(); |
---|
[e664262f7d] | 77 | bool ok; |
---|
[2bc8e278b7] | 78 | for (int r = 0; r < n; r++) { |
---|
| 79 | row = new double[n]; |
---|
| 80 | for (int c = 0; c < n; c++) { |
---|
| 81 | row[c] = tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok); |
---|
| 82 | if (!ok) { |
---|
| 83 | QMessageBox(QMessageBox::Critical,trUtf8("Ошибка в данных"),QString(trUtf8("Ошибка в ячейке [Строка %1; Колонка %2]: Неверный формат данных.")).arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec(); |
---|
| 84 | return; |
---|
[e664262f7d] | 85 | } |
---|
| 86 | } |
---|
| 87 | matrix.append(row); |
---|
| 88 | } |
---|
| 89 | CTSPSolver solver; |
---|
| 90 | sStep *root = solver.solve(spinCities->value(),matrix); |
---|
| 91 | if (!root) |
---|
| 92 | QMessageBox(QMessageBox::Critical,trUtf8("Ошибка при решении"),trUtf8("Во время решения задачи возникла ошибка"),QMessageBox::Ok,this).exec(); |
---|
| 93 | // tabWidget->setCurrentIndex(1); |
---|
[bb994a7ff8] | 94 | } |
---|
| 95 | |
---|