Changeset bb994a7ff8 in tspsg for src


Ignore:
Timestamp:
Oct 14, 2007, 6:23:11 PM (17 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
7177744fc7
Parents:
7672bc895b
Message:

Some code changes :-)

Location:
src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/main.cpp

    r7672bc895b rbb994a7ff8  
    11/*
    2  *      TSPSG - TSP Solver and Generator
    3  *      Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
     2 *  TSPSG - TSP Solver and Generator
     3 *  Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
    44 *
    5  *      $Id$
    6  *      $URL$
     5 *  $Id$
     6 *  $URL$
    77 *
    8  *      This file is part of TSPSG.
     8 *  This file is part of TSPSG.
    99 *
    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.
     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.
    1414 *
    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.
     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.
    1919 *
    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/>.
     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/>.
    2222 */
    2323
     
    2929{
    3030QApplication app(argc, argv);
    31 // l18n
     31/*/ i18n
     32// TODO: Make English as program's "native" language
    3233QLocale *qlocale = &QLocale::system();
    3334QTranslator translator;
     
    3839        // application's "native" we're trying to load English
    3940        else if (qlocale->languageToString(qlocale->language()).compare("Russian") && translator.load("English","i18n"))
    40                 app.installTranslator(&translator);//*/
    41 
     41                app.installTranslator(&translator);
     42//*/
    4243MainWindow mainwindow;
    4344        mainwindow.show();
  • src/mainwindow.cpp

    r7672bc895b rbb994a7ff8  
    11/*
    2  *      TSPSG - TSP Solver and Generator
    3  *      Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
     2 *  TSPSG - TSP Solver and Generator
     3 *  Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
    44 *
    5  *      $Id$
    6  *      $URL$
     5 *  $Id$
     6 *  $URL$
    77 *
    8  *      This file is part of TSPSG.
     8 *  This file is part of TSPSG.
    99 *
    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.
     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.
    1414 *
    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.
     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.
    1919 *
    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/>.
     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/>.
    2222 */
    2323
     
    2828
    2929MainWindow::MainWindow(QWidget *parent)
    30         : QMainWindow(parent)
     30        : QMainWindow(parent), randMin(1), randMax(10)
    3131{
    3232        setupUi(this);
    3333        connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings()));
     34        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve()));
     35        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random()));
    3436        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int)));
    3537        // Centering MainWindow
     
    3840    rect.moveCenter(QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen()).center());
    3941        setGeometry(rect);
    40         for (int k = 0; k < tableTask->rowCount(); k++) {
    41                 QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ")+QVariant(k + 1).toString());
    42                 tableTask->setVerticalHeaderItem(k,item);
    43         }
    44         for (int k = 0; k < tableTask->columnCount(); k++) {
    45                 QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ")+QVariant(k + 1).toString());
    46                 tableTask->setHorizontalHeaderItem(k,item);
     42        PrepareTable();
     43}
     44
     45void MainWindow::PrepareTable()
     46{
     47QTableWidgetItem *item;
     48        for (int y = 0; y < spinCities->value(); y++) {
     49                item = new QTableWidgetItem(trUtf8("Город ") + QVariant(y + 1).toString());
     50                tableTask->setVerticalHeaderItem(y,item);
     51                item = new QTableWidgetItem(trUtf8("Город ") + QVariant(y + 1).toString());
     52                tableTask->setHorizontalHeaderItem(y,item);
     53                for (int x = 0; x < spinCities->value(); x++) {
     54                        if (y == x) {
     55                                item = new QTableWidgetItem("...");
     56                                item->setFlags(item->flags() ^ Qt::ItemIsEditable);
     57                        } else {
     58                                item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     59QFont font = item->font();
     60                                font.setBold(true);
     61                                item->setFont(font);
     62                        }
     63                        item->setTextAlignment(Qt::AlignCenter);
     64                        tableTask->setItem(x,y,item);
     65                }
    4766        }
    4867        tableTask->resizeRowsToContents();
     
    5271void MainWindow::CitiesNumberChanged(int n)
    5372{
    54         // Adding row, setting header and adjusting its size
    5573bool increased = tableTask->rowCount() < n ? true : false;
    5674        tableTask->setRowCount(n);
    57 QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ")+QVariant(n).toString());
    58         tableTask->setVerticalHeaderItem(n - 1,item);
    59         if (increased)
     75        tableTask->setColumnCount(n);
     76        for (int k = 0; k < n; k++)
     77//              tableTask->setColumnWidth(k,tableTask->viewport()->width() / n);
     78        // If number of cities increased we need to reset headers and set
     79        // appropriate sizes for new column and row.
     80        if (increased) {
     81QTableWidgetItem *item = new QTableWidgetItem(trUtf8("Город ") + QVariant(n).toString());
     82                tableTask->setVerticalHeaderItem(n - 1,item);
     83                item = new QTableWidgetItem(trUtf8("Город ") + QVariant(n).toString());
     84                tableTask->setHorizontalHeaderItem(n - 1,item);
    6085                tableTask->resizeRowToContents(n - 1);
    61         // Adding column, setting header and adjusting its size
    62         increased = tableTask->columnCount() < n ? true : false;
    63         tableTask->setColumnCount(n);
    64         item = new QTableWidgetItem(trUtf8("Город ")+QVariant(n).toString());
    65         tableTask->setHorizontalHeaderItem(n - 1,item);
    66         if (increased)
    67         tableTask->resizeColumnToContents(n - 1);
    68         tableTask->setMinimumSize(tableTask->sizeHint());
     86                tableTask->resizeColumnToContents(n - 1);
     87                item = new QTableWidgetItem("...");
     88                item->setFlags(item->flags() ^ Qt::ItemIsEditable);
     89                tableTask->setItem(spinCities->value() - 1,spinCities->value() - 1,item);
     90                for (int k = 0; k < spinCities->value() - 1; k++) {
     91                        item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     92QFont font = item->font();
     93                        font.setBold(true);
     94                        item->setFont(font);
     95                        tableTask->setItem(k,spinCities->value() - 1,item);
     96                        item = new QTableWidgetItem(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     97                        font = item->font();
     98                        font.setBold(true);
     99                        item->setFont(font);
     100                        tableTask->setItem(spinCities->value() - 1,k,item);
     101                }
     102        }
    69103}
    70104
     
    72106{
    73107SettingsDialog sd(this);
    74         sd.exec();
     108        sd.spinRandMin->setValue(randMin);
     109        sd.spinRandMax->setValue(randMax);
     110        if (sd.exec() == QDialog::Accepted) {
     111                randMin = sd.spinRandMin->value();
     112                randMax = sd.spinRandMax->value();
     113        }
    75114}
     115
     116void MainWindow::Random()
     117{
     118        for (int y = 0; y < spinCities->value(); y++)
     119                for (int x = 0; x < spinCities->value(); x++)
     120                        if (x != y)
     121                                tableTask->item(x,y)->setText(QVariant(randMin + qrand() * randMax / RAND_MAX).toString());
     122}
     123
     124void MainWindow::Solve()
     125{
     126        tabWidget->setCurrentIndex(1);
     127        // TODO: Task solving goes here :-)
     128}
     129
  • src/mainwindow.h

    r7672bc895b rbb994a7ff8  
    11/*
    2  *      TSPSG - TSP Solver and Generator
    3  *      Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
     2 *  TSPSG - TSP Solver and Generator
     3 *  Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
    44 *
    5  *      $Id$
    6  *      $URL$
     5 *  $Id$
     6 *  $URL$
    77 *
    8  *      This file is part of TSPSG.
     8 *  This file is part of TSPSG.
    99 *
    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.
     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.
    1414 *
    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.
     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.
    1919 *
    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/>.
     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/>.
    2222 */
    2323
     
    3636private slots:
    3737        void ChangeSettings();
     38        void Solve();
     39        void Random();
    3840        void CitiesNumberChanged(int n);
     41private:
     42        void PrepareTable();
     43        int randMin;
     44        int randMax;
    3945};
    4046
  • src/settingsdialog.cpp

    r7672bc895b rbb994a7ff8  
    11/*
    2  *      TSPSG - TSP Solver and Generator
    3  *      Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
     2 *  TSPSG - TSP Solver and Generator
     3 *  Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
    44 *
    5  *      $Id$
    6  *      $URL$
     5 *  $Id$
     6 *  $URL$
    77 *
    8  *      This file is part of TSPSG.
     8 *  This file is part of TSPSG.
    99 *
    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.
     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.
    1414 *
    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.
     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.
    1919 *
    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/>.
     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/>.
    2222 */
    2323
  • src/settingsdialog.h

    r7672bc895b rbb994a7ff8  
    11/*
    2  *      TSPSG - TSP Solver and Generator
    3  *      Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
     2 *  TSPSG - TSP Solver and Generator
     3 *  Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com>
    44 *
    5  *      $Id$
    6  *      $URL$
     5 *  $Id$
     6 *  $URL$
    77 *
    8  *      This file is part of TSPSG.
     8 *  This file is part of TSPSG.
    99 *
    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.
     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.
    1414 *
    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.
     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.
    1919 *
    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/>.
     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/>.
    2222 */
    2323
     
    2828#include "ui_settingsdialog.h"
    2929
    30 class SettingsDialog: public QDialog, Ui::SettingsDialog
     30class SettingsDialog: public QDialog, public Ui::SettingsDialog
    3131{
    3232        Q_OBJECT
Note: See TracChangeset for help on using the changeset viewer.