Changeset bb994a7ff8 in tspsg for src/mainwindow.cpp
- Timestamp:
- Oct 14, 2007, 6:23:11 PM (17 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 7177744fc7
- Parents:
- 7672bc895b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mainwindow.cpp
r7672bc895b rbb994a7ff8 1 1 /* 2 * 3 * 2 * TSPSG - TSP Solver and Generator 3 * Copyright (C) 2007 Lёppa <lacontacts[at]gmail[dot]com> 4 4 * 5 * 6 * 5 * $Id$ 6 * $URL$ 7 7 * 8 * 8 * This file is part of TSPSG. 9 9 * 10 * 11 * 12 * 13 * 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 14 * 15 * 16 * 17 * 18 * 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 19 * 20 * 21 * 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 22 */ 23 23 … … 28 28 29 29 MainWindow::MainWindow(QWidget *parent) 30 : QMainWindow(parent) 30 : QMainWindow(parent), randMin(1), randMax(10) 31 31 { 32 32 setupUi(this); 33 33 connect(actionSettingsSettings,SIGNAL(triggered()),this,SLOT(ChangeSettings())); 34 connect(buttonSolve,SIGNAL(clicked()),this,SLOT(Solve())); 35 connect(buttonRandom,SIGNAL(clicked()),this,SLOT(Random())); 34 36 connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(CitiesNumberChanged(int))); 35 37 // Centering MainWindow … … 38 40 rect.moveCenter(QApplication::desktop()->screenGeometry(QApplication::desktop()->primaryScreen()).center()); 39 41 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 45 void MainWindow::PrepareTable() 46 { 47 QTableWidgetItem *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()); 59 QFont font = item->font(); 60 font.setBold(true); 61 item->setFont(font); 62 } 63 item->setTextAlignment(Qt::AlignCenter); 64 tableTask->setItem(x,y,item); 65 } 47 66 } 48 67 tableTask->resizeRowsToContents(); … … 52 71 void MainWindow::CitiesNumberChanged(int n) 53 72 { 54 // Adding row, setting header and adjusting its size55 73 bool increased = tableTask->rowCount() < n ? true : false; 56 74 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) { 81 QTableWidgetItem *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); 60 85 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()); 92 QFont 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 } 69 103 } 70 104 … … 72 106 { 73 107 SettingsDialog 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 } 75 114 } 115 116 void 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 124 void MainWindow::Solve() 125 { 126 tabWidget->setCurrentIndex(1); 127 // TODO: Task solving goes here :-) 128 } 129
Note: See TracChangeset
for help on using the changeset viewer.