source: tspsg/src/mainwindow.cpp @ 5354a01311

0.1.3.145-beta1-symbian0.1.4.170-beta2-bb10appveyorimgbotreadme
Last change on this file since 5354a01311 was 5354a01311, checked in by Oleksii Serdiuk, 15 years ago

+ Windows CE (WM6, actually, but should work on other versions) support:

  • added optimized for wince forms (recommended minimal resolution is 240x320);
  • removed unsupported under wince features from menus (e.g., printing);
  • added preprocessor directives to remove code for unsupported under wince features.
  • Fixed wrong encoding in some files to UTF-8.
  • Updated copyright and e-mail.
  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 *  TSPSG - TSP Solver and Generator
3 *  Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
4 *
5 *  $Id$
6 *  $URL$
7 *
8 *  This file is part of TSPSG.
9 *
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.
14 *
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.
19 *
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/>.
22 */
23
24#include <QtGui>
25#ifndef Q_OS_WINCE
26        #include <QPrintDialog>
27#endif // Q_OS_WINCE
28#include "mainwindow.h"
29
30// TODO: Saving window state on close
31
32MainWindow::MainWindow(QWidget *parent)
33        : QMainWindow(parent), randMin(1), randMax(10)
34{
35        setupUi(this);
36        connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
37#ifndef Q_OS_WINCE
38        connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(PrintSetup()));
39#endif // Q_OS_WINCE
40        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve()));
41        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random()));
42        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int)));
43QRect rect = geometry();
44#ifdef Q_OS_WINCE
45        // HACK: Fix for all tabWidget elements becoming "unclickable" if making it central widget.
46        rect.setSize(QApplication::desktop()->availableGeometry().size());
47        rect.setHeight(rect.height() - (QApplication::desktop()->screenGeometry().height() - QApplication::desktop()->availableGeometry().height()));
48        tabWidget->resize(rect.width(),rect.height() - toolBar->size().height());
49#else
50        // Centering MainWindow
51        // TODO: Loading of saved window state
52        rect.moveCenter(QApplication::desktop()->availableGeometry().center());
53#endif // Q_OS_WINCE
54        setGeometry(rect);
55        qsrand(QDateTime().currentDateTime().toTime_t());
56        tspmodel = new CTSPModel();
57        tspmodel->randMin = randMin;
58        tspmodel->randMax = randMax;
59        tspmodel->setNumCities(spinCities->value());
60        taskView->setModel(tspmodel);
61}
62
63void MainWindow::CitiesNumberChanged(int n)
64{
65        tspmodel->setNumCities(n);
66}
67
68void MainWindow::ChangeSettings()
69{
70SettingsDialog sd(this);
71        sd.spinRandMin->setValue(randMin);
72        sd.spinRandMax->setValue(randMax);
73        if (sd.exec() == QDialog::Accepted) {
74                randMin = sd.spinRandMin->value();
75                randMax = sd.spinRandMax->value();
76        }
77}
78
79#ifndef Q_OS_WINCE
80void MainWindow::PrintSetup()
81{
82QPrintDialog pd;
83        pd.exec();
84}
85#endif // Q_OS_WINCE
86
87void MainWindow::Random()
88{
89        tspmodel->randomize();
90}
91
92void MainWindow::Solve()
93{
94        // TODO: Task solving goes here :-)
95tMatrix matrix;
96double *row;
97int n = spinCities->value();
98bool ok;
99        for (int r = 0; r < n; r++) {
100                row = new double[n];
101                for (int c = 0; c < n; c++) {
102                        row[c] = tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok);
103                        if (!ok) {
104                                QMessageBox(QMessageBox::Critical,trUtf8("Ошибка в данных"),QString(trUtf8("Ошибка в ячейке [Строка %1; Колонка %2]: Неверный формат данных.")).arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();
105                                return;
106                        }
107                }
108                matrix.append(row);
109        }
110CTSPSolver solver;
111sStep *root = solver.solve(spinCities->value(),matrix);
112        if (!root)
113                QMessageBox(QMessageBox::Critical,trUtf8("Ошибка при решении"),trUtf8("Во время решения задачи возникла ошибка"),QMessageBox::Ok,this).exec();
114        // tabWidget->setCurrentIndex(1);
115}
Note: See TracBrowser for help on using the repository browser.