Changeset 1757eb594b in tspsg for src
- Timestamp:
- Jan 12, 2010, 3:11:24 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- fcd8c1e4c1
- Parents:
- 64f288c0f8
- Location:
- src
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
src/globals.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file globals.h 3 * \author Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 37 37 // OS and ARCH detection 38 38 #include "os.h" 39 // TSPSG Defaults 40 #include "defaults.h" 39 41 40 42 // DEFINES 41 // Default values42 //! Default minimum for random numbers generation43 #define DEF_RAND_MIN 144 //! Default maximum for random numbers generation45 #define DEF_RAND_MAX 1046 //! Default number of cities47 #define DEF_NUM_CITIES 548 /*!49 * \def DEF_USE_NATIVE_DIALOGS50 * \brief Default for "Use native file dialog".51 */52 #ifdef Q_OS_WINCE53 #define DEF_USE_NATIVE_DIALOGS false54 #else55 #define DEF_USE_NATIVE_DIALOGS true56 #endif // Q_OS_WINCE57 //! Default for "Automatically resize rows and columns to their contents"58 #define DEF_AUTOSIZE true59 //! Default for "Save main window state and position"60 #define DEF_SAVEPOS false61 //! Default for "Fractional random values"62 #define DEF_FRACTIONAL_RANDOM false63 //! Default for "Show solution steps' matrices for every solution step"64 #define DEF_SHOW_MATRIX true65 //! Default for "Show or hide solution steps' matrices based on number of cities in the task"66 #define DEF_USE_SHOW_MATRIX_LIMIT true67 //! Default for "Maximum number of cities to show solution steps' matrices"68 #define DEF_SHOW_MATRIX_LIMIT 1569 //! Default for "Scroll to the end of output after solving"70 #define DEF_SCROLL_TO_END true71 //! Default font name72 #define DEF_FONT_FAMILY "Courier New"73 //! Default font size74 #define DEF_FONT_SIZE 1075 //! Default font color76 #define DEF_FONT_COLOR Qt::black77 78 43 //! Maximum available number of cities 79 44 #define MAX_NUM_CITIES 50 … … 131 96 * \return \c true if \a x countains an integer, oherwise \c false. 132 97 */ 133 inline bool isInteger( doublex)98 inline bool isInteger(qreal x) 134 99 { 135 doublei;100 qreal i; 136 101 return (modf(x, &i) == 0.0); 137 102 } -
src/main.cpp
r64f288c0f8 r1757eb594b 1 1 /* 2 2 * TSPSG: TSP Solver and Generator 3 * Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ -
src/mainwindow.cpp
r64f288c0f8 r1757eb594b 1 1 /* 2 2 * TSPSG: TSP Solver and Generator 3 * Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 124 124 return; 125 125 126 QStringList filters(tr Utf8("All Supported Formats") + " (*.tspt *.zkt)");127 filters.append(tr Utf8("%1 Task Files").arg("TSPSG") + " (*.tspt)");128 filters.append(tr Utf8("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");129 filters.append(tr Utf8("All Files") + " (*)");126 QStringList filters(tr("All Supported Formats") + " (*.tspt *.zkt)"); 127 filters.append(tr("%1 Task Files").arg("TSPSG") + " (*.tspt)"); 128 filters.append(tr("%1 Task Files").arg("ZKomModRd") + " (*.zkt)"); 129 filters.append(tr("All Files") + " (*)"); 130 130 131 131 QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; 132 QString file = QFileDialog::getOpenFileName(this, tr Utf8("Task Load"), QString(), filters.join(";;"), NULL, opts);132 QString file = QFileDialog::getOpenFileName(this, tr("Task Load"), QString(), filters.join(";;"), NULL, opts); 133 133 if (file.isEmpty() || !QFileInfo(file).isFile()) 134 134 return; … … 144 144 void MainWindow::actionFileSaveTriggered() 145 145 { 146 if ((fileName == tr Utf8("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive)))146 if ((fileName == tr("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive))) 147 147 saveTask(); 148 148 else … … 160 160 static QString selectedFile; 161 161 if (selectedFile.isEmpty()) { 162 if (fileName == tr Utf8("Untitled") + ".tspt") {162 if (fileName == tr("Untitled") + ".tspt") { 163 163 #ifndef QT_NO_PRINTER 164 164 selectedFile = "solution.pdf"; … … 177 177 QStringList filters; 178 178 #ifndef QT_NO_PRINTER 179 filters.append(tr Utf8("PDF Files") + " (*.pdf)");179 filters.append(tr("PDF Files") + " (*.pdf)"); 180 180 #endif 181 filters.append(tr Utf8("HTML Files") + " (*.html *.htm)");181 filters.append(tr("HTML Files") + " (*.html *.htm)"); 182 182 #if QT_VERSION >= 0x040500 183 filters.append(tr Utf8("OpenDocument Files") + " (*.odt)");183 filters.append(tr("OpenDocument Files") + " (*.odt)"); 184 184 #endif // QT_VERSION >= 0x040500 185 filters.append(tr Utf8("All Files") + " (*)");185 filters.append(tr("All Files") + " (*)"); 186 186 187 187 QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; … … 252 252 if (sd.colorChanged() || sd.fontChanged()) { 253 253 initDocStyleSheet(); 254 if (!output.isEmpty() && sd.colorChanged() && (QMessageBox(QMessageBox::Question,tr Utf8("Settings Changed"),trUtf8("You have changed color settings.\nDo you wish to apply them to current solution text?"),QMessageBox::Yes | QMessageBox::No,this).exec() == QMessageBox::Yes)) {254 if (!output.isEmpty() && sd.colorChanged() && (QMessageBox(QMessageBox::Question,tr("Settings Changed"),tr("You have changed color settings.\nDo you wish to apply them to current solution text?"),QMessageBox::Yes | QMessageBox::No,this).exec() == QMessageBox::Yes)) { 255 255 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 256 256 solutionText->clear(); … … 265 265 if (checked) { 266 266 settings->remove("Language"); 267 QMessageBox(QMessageBox::Information,tr Utf8("Language change"),trUtf8("Language will be autodetected on next application start."),QMessageBox::Ok,this).exec();267 QMessageBox(QMessageBox::Information,tr("Language change"),tr("Language will be autodetected on next application start."),QMessageBox::Ok,this).exec(); 268 268 } else 269 269 settings->setValue("Language",groupSettingsLanguageList->checkedAction()->data().toString()); … … 274 274 if (actionSettingsLanguageAutodetect->isChecked()) { 275 275 // We have language autodetection. It needs to be disabled to change language. 276 if (QMessageBox(QMessageBox::Question,tr Utf8("Language change"),trUtf8("You have language autodetection turned on.\nIt needs to be off.\nDo you wish to turn it off?"),QMessageBox::Yes | QMessageBox::No,this).exec() == QMessageBox::Yes) {276 if (QMessageBox(QMessageBox::Question,tr("Language change"),tr("You have language autodetection turned on.\nIt needs to be off.\nDo you wish to turn it off?"),QMessageBox::Yes | QMessageBox::No,this).exec() == QMessageBox::Yes) { 277 277 actionSettingsLanguageAutodetect->trigger(); 278 278 } else 279 279 return; 280 280 } 281 bool untitled = (fileName == tr Utf8("Untitled") + ".tspt");281 bool untitled = (fileName == tr("Untitled") + ".tspt"); 282 282 if (loadLanguage(action->data().toString())) { 283 283 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); … … 357 357 358 358 dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); 359 dlg->setWindowTitle(tr Utf8("About TSPSG"));359 dlg->setWindowTitle(tr("About TSPSG")); 360 360 dlg->setLayout(vb); 361 361 … … 383 383 { 384 384 TMatrix matrix; 385 QList< double> row;385 QList<qreal> row; 386 386 int n = spinCities->value(); 387 387 bool ok; … … 389 389 row.clear(); 390 390 for (int c = 0; c < n; c++) { 391 row.append(tspmodel->index(r,c).data(Qt::UserRole).to Double(&ok));391 row.append(tspmodel->index(r,c).data(Qt::UserRole).toReal(&ok)); 392 392 if (!ok) { 393 QMessageBox(QMessageBox::Critical,tr Utf8("Data error"),trUtf8("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();393 QMessageBox(QMessageBox::Critical,tr("Data error"),tr("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec(); 394 394 return; 395 395 } … … 404 404 QColor color = settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>(); 405 405 output.clear(); 406 output.append("<p>" + tr Utf8("Variant #%1").arg(spinVariant->value()) + "</p>");407 output.append("<p>" + tr Utf8("Task:") + "</p>");406 output.append("<p>" + tr("Variant #%1").arg(spinVariant->value()) + "</p>"); 407 output.append("<p>" + tr("Task:") + "</p>"); 408 408 outputMatrix(matrix, output); 409 409 output.append("<hr>"); 410 output.append("<p>" + tr Utf8("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>");410 output.append("<p>" + tr("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>"); 411 411 SStep *step = root; 412 412 n = 1; … … 414 414 if (step->prNode->prNode != NULL || ((step->prNode->prNode == NULL) && (step->plNode->prNode == NULL))) { 415 415 if (n != spinCities->value()) { 416 output.append("<p>" + tr Utf8("Step #%1").arg(n++) + "</p>");416 output.append("<p>" + tr("Step #%1").arg(n++) + "</p>"); 417 417 if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt())) { 418 418 outputMatrix(*step, output); 419 419 } 420 output.append("<p>" + tr Utf8("Selected candidate for branching: %1.").arg(trUtf8("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)) + "</p>");420 output.append("<p>" + tr("Selected candidate for branching: %1.").arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)) + "</p>"); 421 421 if (!step->alts.empty()) { 422 422 SCandidate cand; … … 425 425 if (!alts.isEmpty()) 426 426 alts += ", "; 427 alts += tr Utf8("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);427 alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); 428 428 } 429 output.append("<p class=\"hasalts\">" + tr Utf8("%n alternate candidate(s) for branching: %1.","",step->alts.count()).arg(alts) + "</p>");429 output.append("<p class=\"hasalts\">" + tr("%n alternate candidate(s) for branching: %1.","",step->alts.count()).arg(alts) + "</p>"); 430 430 } 431 431 output.append("<p> </p>"); … … 440 440 } 441 441 if (solver.isOptimal()) 442 output.append("<p>" + tr Utf8("Optimal path:") + "</p>");442 output.append("<p>" + tr("Optimal path:") + "</p>"); 443 443 else 444 output.append("<p>" + tr Utf8("Resulting path:") + "</p>");444 output.append("<p>" + tr("Resulting path:") + "</p>"); 445 445 output.append("<p> " + solver.getSortedPath() + "</p>"); 446 446 if (isInteger(step->price)) 447 output.append("<p>" + tr Utf8("The price is <b>%n</b> unit(s).", "", step->price) + "</p>");447 output.append("<p>" + tr("The price is <b>%n</b> unit(s).", "", step->price) + "</p>"); 448 448 else 449 output.append("<p>" + tr Utf8("The price is <b>%1</b> units.").arg(step->price, 0, 'f', 2) + "</p>");449 output.append("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>"); 450 450 if (!solver.isOptimal()) { 451 451 output.append("<p> </p>"); 452 output.append("<p>" + tr Utf8("<b>WARNING!!!</b><br>This result is a record, but it may not be optimal.<br>Iterations need to be continued to check whether this result is optimal or get an optimal one.") + "</p>");452 output.append("<p>" + tr("<b>WARNING!!!</b><br>This result is a record, but it may not be optimal.<br>Iterations need to be continued to check whether this result is optimal or get an optimal one.") + "</p>"); 453 453 } 454 454 output.append("<p></p>"); 455 455 456 456 solutionText->setHtml(output.join("")); 457 solutionText->setDocumentTitle(tr Utf8("Solution of Variant #%1 task").arg(spinVariant->value()));457 solutionText->setDocumentTitle(tr("Solution of Variant #%1 task").arg(spinVariant->value())); 458 458 459 459 if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { … … 624 624 translator = NULL; 625 625 if (!ad) 626 QMessageBox(QMessageBox::Warning,tr Utf8("Language Change"),trUtf8("Unable to load translation language."),QMessageBox::Ok,this).exec();626 QMessageBox(QMessageBox::Warning,tr("Language Change"),tr("Unable to load translation language."),QMessageBox::Ok,this).exec(); 627 627 return false; 628 628 } … … 634 634 if (!isWindowModified()) 635 635 return true; 636 int res = QMessageBox(QMessageBox::Warning,tr Utf8("Unsaved Changes"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,this).exec();636 int res = QMessageBox(QMessageBox::Warning,tr("Unsaved Changes"),tr("Would you like to save changes in current task?"),QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,this).exec(); 637 637 if (res == QMessageBox::Save) 638 638 return saveTask(); … … 654 654 line += "<td align=\"center\">"INFSTR"</td>"; 655 655 else 656 line += isInteger(matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c), 0, 'f', 2);656 line += isInteger(matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 657 657 } 658 658 line += "</tr>"; … … 673 673 line += "<td align=\"center\">"INFSTR"</td>"; 674 674 else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) 675 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', 2);675 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"selected\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 676 676 else { 677 677 SCandidate cand; … … 679 679 cand.nCol = c; 680 680 if (step.alts.contains(cand)) 681 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', 2);681 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\" class=\"alternate\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 682 682 else 683 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', 2);683 line += isInteger(step.matrix.at(r).at(c)) ? QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c)) : QString("<td align=\"center\">%1</td>").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 684 684 } 685 685 } … … 716 716 717 717 bool MainWindow::saveTask() { 718 QStringList filters(tr Utf8("%1 Task File").arg("TSPSG") + " (*.tspt)");719 filters.append(tr Utf8("All Files") + " (*)");718 QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)"); 719 filters.append(tr("All Files") + " (*)"); 720 720 QString file; 721 721 if (fileName.endsWith(".tspt", Qt::CaseInsensitive)) … … 725 725 726 726 QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog; 727 file = QFileDialog::getSaveFileName(this, tr Utf8("Task Save"), file, filters.join(";;"), NULL, opts);727 file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts); 728 728 729 729 if (file.isEmpty()) … … 740 740 { 741 741 this->fileName = fileName; 742 setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(tr Utf8("Travelling Salesman Problem")));742 setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(tr("Travelling Salesman Problem"))); 743 743 } 744 744 -
src/mainwindow.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file mainwindow.h 3 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 39 39 /*! 40 40 * \brief Class for handling Main Window UI and logic. 41 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>41 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 42 42 */ 43 43 class MainWindow: public QMainWindow, Ui::MainWindow … … 98 98 void retranslateUi(bool all = true); 99 99 bool saveTask(); 100 void setFileName(const QString &fileName = tr Utf8("Untitled") + ".tspt");100 void setFileName(const QString &fileName = tr("Untitled") + ".tspt"); 101 101 void setupUi(); 102 102 void toggleSolutionActions(bool enable = true); -
src/os.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file os.h 3 * \author Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ -
src/resource.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file resource.h 3 * \author Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ -
src/settingsdialog.cpp
r64f288c0f8 r1757eb594b 1 1 /* 2 2 * TSPSG: TSP Solver and Generator 3 * Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 34 34 { 35 35 setupUi(this); 36 // Laying out elements 37 /* layoutCitiesLimit = new QHBoxLayout(); 38 layoutCitiesLimit->setMargin(0); 39 layoutCitiesLimit->setSpacing(0); 40 layoutCitiesLimit->addSpacing(10); 41 layoutCitiesLimit->addWidget(cbCitiesLimit); 42 layoutCitiesLimit->addWidget(spinCitiesLimit); 43 layoutCitiesLimit->addStretch(); 44 */ 36 45 37 buttonBox->button(QDialogButtonBox::Save)->setIcon(QIcon(":/images/icons/button_ok.png")); 46 buttonBox->button(QDialogButtonBox::Save)->setStatusTip(tr Utf8("Save new preferences"));38 buttonBox->button(QDialogButtonBox::Save)->setStatusTip(tr("Save new preferences")); 47 39 buttonBox->button(QDialogButtonBox::Save)->setCursor(QCursor(Qt::PointingHandCursor)); 48 40 buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":/images/icons/button_cancel.png")); 49 buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr Utf8("Close without saving preferences"));41 buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(tr("Close without saving preferences")); 50 42 buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor)); 51 43 … … 80 72 cbSaveState->setObjectName("cbSaveState"); 81 73 #ifndef QT_NO_STATUSTIP 82 cbSaveState->setStatusTip(tr Utf8("Restore main window state and position on application restart"));74 cbSaveState->setStatusTip(tr("Restore main window state and position on application restart")); 83 75 #endif // QT_NO_STATUSTIP 84 cbSaveState->setText(tr Utf8("Save main window state and position"));76 cbSaveState->setText(tr("Save main window state and position")); 85 77 cbSaveState->setCursor(QCursor(Qt::PointingHandCursor)); 86 78 … … 105 97 labelHint->setWordWrap(true); 106 98 #ifndef QT_NO_STATUSTIP 107 labelHint->setStatusTip(tr Utf8("Hover mouse pointer over dialog elements to get additional help"));99 labelHint->setStatusTip(tr("Hover mouse pointer over dialog elements to get additional help")); 108 100 #endif // QT_NO_STATUSTIP 109 101 … … 121 113 122 114 vbox1 = static_cast<QVBoxLayout *>(tabGeneral->layout()); 123 vbox1->insertWidget(vbox 2->indexOf(cbUseNativeDialogs) + 1, cbSaveState);115 vbox1->insertWidget(vbox1->indexOf(cbUseNativeDialogs) + 1, cbSaveState); 124 116 125 117 // Bottom part (with grey bg) … … 152 144 settings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "TSPSG", "tspsg", this); 153 145 154 spinRandMin->setMaximum(MAX_RAND_VALUE);155 spinRandMin->setValue(settings->value("MinCost",DEF_RAND_MIN).toInt());156 spinRandMax->setMaximum(MAX_RAND_VALUE);157 spinRandMax->setValue(settings->value("MaxCost",DEF_RAND_MAX).toInt());158 cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool());159 146 cbAutosize->setChecked(settings->value("Autosize", DEF_AUTOSIZE).toBool()); 160 147 cbUseNativeDialogs->setChecked(settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool()); … … 162 149 cbSaveState->setChecked(settings->value("SavePos", DEF_SAVEPOS).toBool()); 163 150 #endif // Q_OS_WINCE 151 152 settings->beginGroup("Task"); 153 spinFractionalAccuracy->setValue(settings->value("FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 154 spinRandMin->setMaximum(MAX_RAND_VALUE); 155 spinRandMin->setValue(settings->value("RandMin",DEF_RAND_MIN).toInt()); 156 spinRandMax->setMaximum(MAX_RAND_VALUE); 157 spinRandMax->setValue(settings->value("RandMax",DEF_RAND_MAX).toInt()); 158 cbFractionalRandom->setChecked(settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()); 159 settings->endGroup(); 164 160 165 161 settings->beginGroup("Output"); … … 206 202 settings->setValue("UseNativeDialogs", cbUseNativeDialogs->isChecked()); 207 203 settings->setValue("Autosize", cbAutosize->isChecked()); 208 settings->setValue("MinCost", spinRandMin->value()); 209 settings->setValue("MaxCost", spinRandMax->value()); 204 205 settings->beginGroup("Task"); 206 settings->setValue("FractionalAccuracy", spinFractionalAccuracy->value()); 207 settings->setValue("RandMin", spinRandMin->value()); 208 settings->setValue("RandMax", spinRandMax->value()); 210 209 settings->setValue("FractionalRandom", cbFractionalRandom->isChecked()); 210 settings->endGroup(); 211 211 212 212 settings->beginGroup("Output"); -
src/settingsdialog.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file settingsdialog.h 3 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 35 35 /*! 36 36 * \brief Class for handling Settings Dialog UI and logic. 37 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>37 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 38 38 */ 39 39 class SettingsDialog: public QDialog, Ui::SettingsDialog -
src/tspmodel.cpp
r64f288c0f8 r1757eb594b 1 1 /* 2 2 * TSPSG: TSP Solver and Generator 3 * Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 82 82 if (index.row() < nCities && index.column() < nCities) 83 83 if (table[index.row()][index.column()] == INFINITY) 84 return tr Utf8(INFSTR);84 return tr(INFSTR); 85 85 else 86 86 //! \hack HACK: Converting to string to prevent spinbox in edit mode … … 119 119 if (role == Qt::DisplayRole) { 120 120 if (orientation == Qt::Vertical) 121 return tr Utf8("City %1").arg(section + 1);121 return tr("City %1").arg(section + 1); 122 122 else 123 return tr Utf8("%1").arg(section + 1);123 return tr("%1").arg(section + 1); 124 124 } 125 125 return QVariant(); … … 139 139 if (!f.open(QIODevice::ReadOnly)) { 140 140 QApplication::restoreOverrideCursor(); 141 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),QString(trUtf8("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec();141 QMessageBox(QMessageBox::Critical,tr("Task Load"),QString(tr("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec(); 142 142 return false; 143 143 } … … 163 163 f.close(); 164 164 QApplication::restoreOverrideCursor(); 165 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unknown file format or file is corrupted."),QMessageBox::Ok).exec();165 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unknown file format or file is corrupted."),QMessageBox::Ok).exec(); 166 166 return false; 167 167 } … … 191 191 void CTSPModel::randomize() 192 192 { 193 int randMin = settings->value(" MinCost",DEF_RAND_MIN).toInt();194 int randMax = settings->value(" MaxCost",DEF_RAND_MAX).toInt();193 int randMin = settings->value("Task/RandMin",DEF_RAND_MIN).toInt(); 194 int randMax = settings->value("Task/RandMax",DEF_RAND_MAX).toInt(); 195 195 for (int r = 0; r < nCities; r++) 196 196 for (int c = 0; c < nCities; c++) … … 226 226 if (!f.open(QIODevice::WriteOnly)) { 227 227 QApplication::restoreOverrideCursor(); 228 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),QString(trUtf8("Unable to create task file.\nError: %1\nMaybe, file is read-only?")).arg(f.errorString()),QMessageBox::Ok).exec();228 QMessageBox(QMessageBox::Critical,tr("Task Save"),QString(tr("Unable to create task file.\nError: %1\nMaybe, file is read-only?")).arg(f.errorString()),QMessageBox::Ok).exec(); 229 229 return false; 230 230 } … … 234 234 f.close(); 235 235 QApplication::restoreOverrideCursor(); 236 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();236 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 237 237 return false; 238 238 } … … 242 242 f.close(); 243 243 QApplication::restoreOverrideCursor(); 244 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();244 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 245 245 return false; 246 246 } … … 250 250 f.close(); 251 251 QApplication::restoreOverrideCursor(); 252 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();252 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 253 253 return false; 254 254 } … … 258 258 f.close(); 259 259 QApplication::restoreOverrideCursor(); 260 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();260 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 261 261 return false; 262 262 } … … 266 266 f.close(); 267 267 QApplication::restoreOverrideCursor(); 268 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();268 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 269 269 return false; 270 270 } … … 274 274 f.close(); 275 275 QApplication::restoreOverrideCursor(); 276 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();276 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 277 277 return false; 278 278 } … … 281 281 for (int c = 0; c < nCities; c++) 282 282 if (r != c) { 283 ds << table[r][c];283 ds << static_cast<double>(table[r][c]); // We cast to double because qreal may be float on some platforms and we store double values in file 284 284 if (f.error() != QFile::NoError) { 285 285 f.close(); 286 286 QApplication::restoreOverrideCursor(); 287 QMessageBox(QMessageBox::Critical,tr Utf8("Task Save"),trUtf8("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();287 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec(); 288 288 return false; 289 289 } … … 312 312 else { 313 313 bool ok; 314 double tmp = value.toDouble(&ok);314 qreal tmp = value.toReal(&ok); 315 315 if (!ok || tmp < 0) 316 316 return false; … … 354 354 return false; 355 355 else if (status == QDataStream::ReadPastEnd) 356 err = tr Utf8("Unexpected end of file.");356 err = tr("Unexpected end of file."); 357 357 else if (status == QDataStream::ReadCorruptData) 358 err = tr Utf8("Corrupt data read. File possibly corrupted.");358 err = tr("Corrupt data read. File possibly corrupted."); 359 359 else 360 err = tr Utf8("Unknown error.");360 err = tr("Unknown error."); 361 361 QApplication::restoreOverrideCursor(); 362 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + err,QMessageBox::Ok).exec();362 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + err,QMessageBox::Ok).exec(); 363 363 return true; 364 364 } … … 377 377 if (version > TSPT_VERSION) { 378 378 QApplication::restoreOverrideCursor(); 379 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();379 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 380 380 return false; 381 381 } … … 391 391 if ((size < 3) || (size > MAX_NUM_CITIES)) { 392 392 QApplication::restoreOverrideCursor(); 393 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();393 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 394 394 return false; 395 395 } … … 398 398 emit numCitiesChanged(size); 399 399 } 400 401 double x; // We need this as qreal may be float on some platforms and we store double values in file 400 402 // Travel costs 401 403 for (int r = 0; r < size; r++) 402 404 for (int c = 0; c < size; c++) 403 405 if (r != c) { 404 *ds >> table[r][c]; 406 *ds >> x; 407 table[r][c] = x; 405 408 if (loadError(ds->status())) { 406 409 clear(); … … 426 429 if (version > ZKT_VERSION) { 427 430 QApplication::restoreOverrideCursor(); 428 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();431 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 429 432 return false; 430 433 } … … 436 439 if ((size < 3) || (size > 5)) { 437 440 QApplication::restoreOverrideCursor(); 438 QMessageBox(QMessageBox::Critical,tr Utf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();441 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 439 442 return false; 440 443 } … … 444 447 } 445 448 // Travel costs 446 doubleval;449 qreal val; 447 450 for (int r = 0; r < 5; r++) 448 451 for (int c = 0; c < 5; c++) 449 if ((r != c) && (r < size) ) {452 if ((r != c) && (r < size) && (c < size)) { 450 453 ds->readRawData(reinterpret_cast<char *>(&val),8); 451 454 if (loadError(ds->status())) { … … 466 469 } 467 470 468 inline double CTSPModel::rand(int min, int max) const 469 { 470 double r; 471 if (settings->value("FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) 472 r = (double)qRound((double)qrand() / RAND_MAX * (max - min) * 100) / 100; 473 else 474 r = qRound((double)qrand() / RAND_MAX * (max - min)); 471 inline qreal CTSPModel::rand(int min, int max) const 472 { 473 qreal r; 474 if (settings->value("Task/FractionalRandom", DEF_FRACTIONAL_RANDOM).toBool()) { 475 qreal x = qPow(10, settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()); 476 r = (qreal)qRound((qreal)qrand() / RAND_MAX * (max - min) * x) / x; 477 } else 478 r = qRound((qreal)qrand() / RAND_MAX * (max - min)); 475 479 return min + r; 476 480 } -
src/tspmodel.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file tspmodel.h 3 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 33 33 /*! 34 34 * \brief This class implements table model for manipulating a task. 35 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>35 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 36 36 */ 37 37 class CTSPModel: public QAbstractTableModel … … 64 64 private: 65 65 QSettings *settings; 66 QVector<QVector< double> > table;66 QVector<QVector<qreal> > table; 67 67 quint16 nCities; 68 68 bool loadError(QDataStream::Status); 69 69 bool loadTSPT(QDataStream *); 70 70 bool loadZKT(QDataStream *); 71 doublerand(int, int) const;71 qreal rand(int, int) const; 72 72 }; 73 73 -
src/tspsolver.cpp
r64f288c0f8 r1757eb594b 1 1 /* 2 2 * TSPSG: TSP Solver and Generator 3 * Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 40 40 41 41 int i = 0; // We start from City 1 42 QString path = tr Utf8("City %1").arg(1) + " -> ";42 QString path = tr("City %1").arg(1) + " -> "; 43 43 while ((i = route[i]) != 0) { 44 path += tr Utf8("City %1").arg(i + 1) + " -> ";44 path += tr("City %1").arg(i + 1) + " -> "; 45 45 } 46 46 // And finish in City 1, too 47 path += tr Utf8("City %1").arg(1);47 path += tr("City %1").arg(1); 48 48 49 49 return path; … … 89 89 QProgressBar *pb = new QProgressBar(&pd); 90 90 pb->setAlignment(Qt::AlignCenter); 91 pb->setFormat(tr Utf8("%v of %m parts found"));91 pb->setFormat(tr("%v of %m parts found")); 92 92 pd.setBar(pb); 93 93 pd.setMaximum(nCities); 94 94 pd.setMinimumDuration(1000); 95 pd.setLabelText(tr Utf8("Calculating optimal route..."));96 pd.setWindowTitle(tr Utf8("Solution Progress"));95 pd.setLabelText(tr("Calculating optimal route...")); 96 pd.setWindowTitle(tr("Solution Progress")); 97 97 pd.setWindowModality(Qt::ApplicationModal); 98 98 pd.setValue(0); … … 106 106 int nRow, nCol; 107 107 bool firstStep = true; 108 doublecheck;108 qreal check; 109 109 while (this->route.size() < nCities) { 110 110 // forbidden.clear(); … … 168 168 if (!root && !pd.wasCanceled()) { 169 169 pd.reset(); 170 QMessageBox(QMessageBox::Warning,tr Utf8("Solution Result"),trUtf8("Unable to find solution.\nMaybe, this task has no solutions."),QMessageBox::Ok,parent).exec();170 QMessageBox(QMessageBox::Warning,tr("Solution Result"),tr("Unable to find solution.\nMaybe, this task has no solutions."),QMessageBox::Ok,parent).exec(); 171 171 } 172 172 … … 188 188 /* Privates **********************************************************/ 189 189 190 doubleCTSPSolver::align(TMatrix &matrix)191 { 192 doubler = 0;193 doublemin;190 qreal CTSPSolver::align(TMatrix &matrix) 191 { 192 qreal r = 0; 193 qreal min; 194 194 for (int k = 0; k < nCities; k++) { 195 195 min = findMinInRow(k,matrix); … … 240 240 QList<SCandidate> alts; 241 241 SCandidate cand; 242 doubleh = -1;243 doublesum;242 qreal h = -1; 243 qreal sum; 244 244 for (int r = 0; r < nCities; r++) 245 245 for (int c = 0; c < nCities; c++) … … 261 261 } 262 262 263 doubleCTSPSolver::findMinInCol(int nCol, const TMatrix &matrix, int exr) const264 { 265 doublemin = INFINITY;263 qreal CTSPSolver::findMinInCol(int nCol, const TMatrix &matrix, int exr) const 264 { 265 qreal min = INFINITY; 266 266 for (int k = 0; k < nCities; k++) 267 267 if ((k != exr) && (min > matrix.at(k).at(nCol))) … … 270 270 } 271 271 272 doubleCTSPSolver::findMinInRow(int nRow, const TMatrix &matrix, int exc) const273 { 274 doublemin = INFINITY;272 qreal CTSPSolver::findMinInRow(int nRow, const TMatrix &matrix, int exc) const 273 { 274 qreal min = INFINITY; 275 275 for (int k = 0; k < nCities; k++) 276 276 if (((k != exc)) && (min > matrix.at(nRow).at(k))) … … 293 293 } 294 294 295 void CTSPSolver::subCol(TMatrix &matrix, int nCol, doubleval)295 void CTSPSolver::subCol(TMatrix &matrix, int nCol, qreal val) 296 296 { 297 297 for (int k = 0; k < nCities; k++) … … 300 300 } 301 301 302 void CTSPSolver::subRow(TMatrix &matrix, int nRow, doubleval)302 void CTSPSolver::subRow(TMatrix &matrix, int nRow, qreal val) 303 303 { 304 304 for (int k = 0; k < nCities; k++) -
src/tspsolver.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file tspsolver.h 3 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 34 34 35 35 //! A matrix of city-to-city travel costs. 36 typedef QList<QList< double> > TMatrix;36 typedef QList<QList<qreal> > TMatrix; 37 37 38 38 /*! … … 60 60 struct SStep { 61 61 TMatrix matrix; //!< This step's matrix 62 doubleprice; //!< The price of travel to this step62 qreal price; //!< The price of travel to this step 63 63 SCandidate candidate; //!< A candiadate for branching in the current matrix 64 64 QList<SCandidate> alts; //!< A list of alternative branching candidates … … 75 75 /*! 76 76 * \brief This class solves Travelling Salesman Problem task. 77 * \author Copyright © 2007-20 09Lёppa <contacts[at]oleksii[dot]name>77 * \author Copyright © 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 78 78 * 79 79 * \todo TODO: Deletion of solution tree on destroy and cleanup. … … 98 98 // QHash<int,int> forbidden; 99 99 100 doublealign(TMatrix &matrix);100 qreal align(TMatrix &matrix); 101 101 void cleanup(); 102 102 void deleteNode(SStep *&node); 103 103 QList<SCandidate> findCandidate(const TMatrix &matrix, int &nRow, int &nCol) const; 104 doublefindMinInCol(int nCol, const TMatrix &matrix, int exr = -1) const;105 doublefindMinInRow(int nRow, const TMatrix &matrix, int exc = -1) const;104 qreal findMinInCol(int nCol, const TMatrix &matrix, int exr = -1) const; 105 qreal findMinInRow(int nRow, const TMatrix &matrix, int exc = -1) const; 106 106 bool hasSubCycles(int nRow, int nCol) const; 107 void subCol(TMatrix &matrix, int nCol, doubleval);108 void subRow(TMatrix &matrix, int nRow, doubleval);107 void subCol(TMatrix &matrix, int nCol, qreal val); 108 void subRow(TMatrix &matrix, int nRow, qreal val); 109 109 }; 110 110 -
src/version.h
r64f288c0f8 r1757eb594b 1 1 /*! 2 2 * \file version.h 3 * \author Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>3 * \author Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 4 4 * 5 5 * $Id$ … … 29 29 * \image html tspsg.png 30 30 * <b>TSPSG: TSP Solver and Generator</b> 31 * \author Copyright (C) 2007-20 09Lёppa <contacts[at]oleksii[dot]name>31 * \author Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name> 32 32 * 33 33 * $Id$
Note: See TracChangeset
for help on using the changeset viewer.