source: tspsg/src/mainwindow.cpp @ 799ba1e3f2

0.1.3.145-beta1-symbian0.1.4.170-beta2-bb10appveyorimgbotreadme
Last change on this file since 799ba1e3f2 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
RevLine 
[5515c2c2a7]1/*
[bb994a7ff8]2 *  TSPSG - TSP Solver and Generator
[5354a01311]3 *  Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
[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>
[5354a01311]25#ifndef Q_OS_WINCE
26        #include <QPrintDialog>
27#endif // Q_OS_WINCE
[5515c2c2a7]28#include "mainwindow.h"
29
[67e53c96d7]30// TODO: Saving window state on close
[052d1b9331]31
[5515c2c2a7]32MainWindow::MainWindow(QWidget *parent)
[bb994a7ff8]33        : QMainWindow(parent), randMin(1), randMax(10)
[5515c2c2a7]34{
35        setupUi(this);
36        connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
[5354a01311]37#ifndef Q_OS_WINCE
38        connect(actionFilePrintSetup,SIGNAL(triggered()),this,SLOT(PrintSetup()));
39#endif // Q_OS_WINCE
[bb994a7ff8]40        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve()));
41        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random()));
[003e4193be]42        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int)));
[5354a01311]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
[052d1b9331]50        // Centering MainWindow
51        // TODO: Loading of saved window state
[5354a01311]52        rect.moveCenter(QApplication::desktop()->availableGeometry().center());
53#endif // Q_OS_WINCE
[052d1b9331]54        setGeometry(rect);
[fc9f661ded]55        qsrand(QDateTime().currentDateTime().toTime_t());
[2bc8e278b7]56        tspmodel = new CTSPModel();
57        tspmodel->randMin = randMin;
58        tspmodel->randMax = randMax;
59        tspmodel->setNumCities(spinCities->value());
60        taskView->setModel(tspmodel);
[003e4193be]61}
[052d1b9331]62
[003e4193be]63void MainWindow::CitiesNumberChanged(int n)
64{
[2bc8e278b7]65        tspmodel->setNumCities(n);
[5515c2c2a7]66}
67
68void MainWindow::ChangeSettings()
69{
70SettingsDialog sd(this);
[bb994a7ff8]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        }
[5515c2c2a7]77}
[bb994a7ff8]78
[5354a01311]79#ifndef Q_OS_WINCE
80void MainWindow::PrintSetup()
81{
82QPrintDialog pd;
83        pd.exec();
84}
85#endif // Q_OS_WINCE
86
[bb994a7ff8]87void MainWindow::Random()
88{
[2bc8e278b7]89        tspmodel->randomize();
[bb994a7ff8]90}
91
92void MainWindow::Solve()
93{
94        // TODO: Task solving goes here :-)
[e664262f7d]95tMatrix matrix;
96double *row;
[2bc8e278b7]97int n = spinCities->value();
[e664262f7d]98bool ok;
[2bc8e278b7]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;
[e664262f7d]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);
[bb994a7ff8]115}
Note: See TracBrowser for help on using the repository browser.