Changeset 1757eb594b in tspsg for src/mainwindow.cpp


Ignore:
Timestamp:
Jan 12, 2010, 3:11:24 PM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
fcd8c1e4c1
Parents:
64f288c0f8
Message:

+ Added Fractional accuracy (in decimail places) to settings.
+ Created defaults.h file. Moved all default defines there.

  • Replaced all double types with qreal.
  • Replaced all calls to trUtf8() with tr() as we use setCodecForTr() to set UTF-8 encoding as default and tr() is enough.
  • Replaced all 2009 with 2010 in copyrights.
  • Fixed an error when loading .zkt file with less than 5 cities.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    r64f288c0f8 r1757eb594b  
    11/*
    22 *  TSPSG: TSP Solver and Generator
    3  *  Copyright (C) 2007-2009 Lёppa <contacts[at]oleksii[dot]name>
     3 *  Copyright (C) 2007-2010 Lёppa <contacts[at]oleksii[dot]name>
    44 *
    55 *  $Id$
     
    124124                return;
    125125
    126 QStringList filters(trUtf8("All Supported Formats") + " (*.tspt *.zkt)");
    127         filters.append(trUtf8("%1 Task Files").arg("TSPSG") + " (*.tspt)");
    128         filters.append(trUtf8("%1 Task Files").arg("ZKomModRd") + " (*.zkt)");
    129         filters.append(trUtf8("All Files") + " (*)");
     126QStringList 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") + " (*)");
    130130
    131131QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
    132 QString file = QFileDialog::getOpenFileName(this, trUtf8("Task Load"), QString(), filters.join(";;"), NULL, opts);
     132QString file = QFileDialog::getOpenFileName(this, tr("Task Load"), QString(), filters.join(";;"), NULL, opts);
    133133        if (file.isEmpty() || !QFileInfo(file).isFile())
    134134                return;
     
    144144void MainWindow::actionFileSaveTriggered()
    145145{
    146         if ((fileName == trUtf8("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive)))
     146        if ((fileName == tr("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive)))
    147147                saveTask();
    148148        else
     
    160160static QString selectedFile;
    161161        if (selectedFile.isEmpty()) {
    162                 if (fileName == trUtf8("Untitled") + ".tspt") {
     162                if (fileName == tr("Untitled") + ".tspt") {
    163163#ifndef QT_NO_PRINTER
    164164                        selectedFile = "solution.pdf";
     
    177177QStringList filters;
    178178#ifndef QT_NO_PRINTER
    179         filters.append(trUtf8("PDF Files") + " (*.pdf)");
     179        filters.append(tr("PDF Files") + " (*.pdf)");
    180180#endif
    181         filters.append(trUtf8("HTML Files") + " (*.html *.htm)");
     181        filters.append(tr("HTML Files") + " (*.html *.htm)");
    182182#if QT_VERSION >= 0x040500
    183         filters.append(trUtf8("OpenDocument Files") + " (*.odt)");
     183        filters.append(tr("OpenDocument Files") + " (*.odt)");
    184184#endif // QT_VERSION >= 0x040500
    185         filters.append(trUtf8("All Files") + " (*)");
     185        filters.append(tr("All Files") + " (*)");
    186186
    187187QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
     
    252252        if (sd.colorChanged() || sd.fontChanged()) {
    253253                initDocStyleSheet();
    254                 if (!output.isEmpty() && sd.colorChanged() && (QMessageBox(QMessageBox::Question,trUtf8("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)) {
    255255                        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    256256                        solutionText->clear();
     
    265265        if (checked) {
    266266                settings->remove("Language");
    267                 QMessageBox(QMessageBox::Information,trUtf8("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();
    268268        } else
    269269                settings->setValue("Language",groupSettingsLanguageList->checkedAction()->data().toString());
     
    274274        if (actionSettingsLanguageAutodetect->isChecked()) {
    275275                // We have language autodetection. It needs to be disabled to change language.
    276                 if (QMessageBox(QMessageBox::Question,trUtf8("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) {
    277277                        actionSettingsLanguageAutodetect->trigger();
    278278                } else
    279279                        return;
    280280        }
    281 bool untitled = (fileName == trUtf8("Untitled") + ".tspt");
     281bool untitled = (fileName == tr("Untitled") + ".tspt");
    282282        if (loadLanguage(action->data().toString())) {
    283283                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     
    357357
    358358        dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint);
    359         dlg->setWindowTitle(trUtf8("About TSPSG"));
     359        dlg->setWindowTitle(tr("About TSPSG"));
    360360        dlg->setLayout(vb);
    361361
     
    383383{
    384384TMatrix matrix;
    385 QList<double> row;
     385QList<qreal> row;
    386386int n = spinCities->value();
    387387bool ok;
     
    389389                row.clear();
    390390                for (int c = 0; c < n; c++) {
    391                         row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok));
     391                        row.append(tspmodel->index(r,c).data(Qt::UserRole).toReal(&ok));
    392392                        if (!ok) {
    393                                 QMessageBox(QMessageBox::Critical,trUtf8("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();
    394394                                return;
    395395                        }
     
    404404QColor color = settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>();
    405405        output.clear();
    406         output.append("<p>" + trUtf8("Variant #%1").arg(spinVariant->value()) + "</p>");
    407         output.append("<p>" + trUtf8("Task:") + "</p>");
     406        output.append("<p>" + tr("Variant #%1").arg(spinVariant->value()) + "</p>");
     407        output.append("<p>" + tr("Task:") + "</p>");
    408408        outputMatrix(matrix, output);
    409409        output.append("<hr>");
    410         output.append("<p>" + trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>");
     410        output.append("<p>" + tr("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>");
    411411SStep *step = root;
    412412        n = 1;
     
    414414                if (step->prNode->prNode != NULL || ((step->prNode->prNode == NULL) && (step->plNode->prNode == NULL))) {
    415415                        if (n != spinCities->value()) {
    416                                 output.append("<p>" + trUtf8("Step #%1").arg(n++) + "</p>");
     416                                output.append("<p>" + tr("Step #%1").arg(n++) + "</p>");
    417417                                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())) {
    418418                                        outputMatrix(*step, output);
    419419                                }
    420                                 output.append("<p>" + trUtf8("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>");
    421421                                if (!step->alts.empty()) {
    422422SCandidate cand;
     
    425425                                                if (!alts.isEmpty())
    426426                                                        alts += ", ";
    427                                                 alts += trUtf8("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
     427                                                alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
    428428                                        }
    429                                         output.append("<p class=\"hasalts\">" + trUtf8("%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>");
    430430                                }
    431431                                output.append("<p>&nbsp;</p>");
     
    440440        }
    441441        if (solver.isOptimal())
    442                 output.append("<p>" + trUtf8("Optimal path:") + "</p>");
     442                output.append("<p>" + tr("Optimal path:") + "</p>");
    443443        else
    444                 output.append("<p>" + trUtf8("Resulting path:") + "</p>");
     444                output.append("<p>" + tr("Resulting path:") + "</p>");
    445445        output.append("<p>&nbsp;&nbsp;" + solver.getSortedPath() + "</p>");
    446446        if (isInteger(step->price))
    447                 output.append("<p>" + trUtf8("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>");
    448448        else
    449                 output.append("<p>" + trUtf8("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>");
    450450        if (!solver.isOptimal()) {
    451451                output.append("<p>&nbsp;</p>");
    452                 output.append("<p>" + trUtf8("<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>");
    453453        }
    454454        output.append("<p></p>");
    455455
    456456        solutionText->setHtml(output.join(""));
    457         solutionText->setDocumentTitle(trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()));
     457        solutionText->setDocumentTitle(tr("Solution of Variant #%1 task").arg(spinVariant->value()));
    458458
    459459        if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) {
     
    624624                translator = NULL;
    625625                if (!ad)
    626                         QMessageBox(QMessageBox::Warning,trUtf8("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();
    627627                return false;
    628628        }
     
    634634        if (!isWindowModified())
    635635                return true;
    636 int res = QMessageBox(QMessageBox::Warning,trUtf8("Unsaved Changes"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,this).exec();
     636int 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();
    637637        if (res == QMessageBox::Save)
    638638                return saveTask();
     
    654654                                line += "<td align=\"center\">"INFSTR"</td>";
    655655                        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());
    657657                }
    658658                line += "</tr>";
     
    673673                                line += "<td align=\"center\">"INFSTR"</td>";
    674674                        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());
    676676                        else {
    677677SCandidate cand;
     
    679679                                cand.nCol = c;
    680680                                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());
    682682                                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());
    684684                        }
    685685                }
     
    716716
    717717bool MainWindow::saveTask() {
    718 QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)");
    719         filters.append(trUtf8("All Files") + " (*)");
     718QStringList filters(tr("%1 Task File").arg("TSPSG") + " (*.tspt)");
     719        filters.append(tr("All Files") + " (*)");
    720720QString file;
    721721        if (fileName.endsWith(".tspt", Qt::CaseInsensitive))
     
    725725
    726726QFileDialog::Options opts = settings->value("UseNativeDialogs", DEF_USE_NATIVE_DIALOGS).toBool() ? QFileDialog::Options() : QFileDialog::DontUseNativeDialog;
    727         file = QFileDialog::getSaveFileName(this, trUtf8("Task Save"), file, filters.join(";;"), NULL, opts);
     727        file = QFileDialog::getSaveFileName(this, tr("Task Save"), file, filters.join(";;"), NULL, opts);
    728728
    729729        if (file.isEmpty())
     
    740740{
    741741        this->fileName = fileName;
    742         setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(trUtf8("Travelling Salesman Problem")));
     742        setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(tr("Travelling Salesman Problem")));
    743743}
    744744
Note: See TracChangeset for help on using the changeset viewer.