Changeset 9cda6e0f5d in tspsg for src/mainwindow.cpp


Ignore:
Timestamp:
Apr 25, 2010, 4:36:27 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:
ca3d2a30fa
Parents:
345e7b6132
git-author:
Oleksii Serdiuk <contacts@…> (04/25/10 16:36:27)
git-committer:
Oleksii Serdiuk <contacts@…> (06/29/12 19:41:31)
Message:

+ Added SStep::next that indicates what branch was selected for the next step.
+ Added "Show solution graph" option.
+ New CTSPSolver::getTotalSteps() method that returns a total number of steps in the current solution.

  • Moved SCandidate declaration into SStep declaration.
  • Moved everything in tspsolver.h and tspsolver.cpp into TSPSolver namespace.
  • Force CopyAction? on file drop or it will be deleted after dropping in Windows if MoveAction? was selected.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    r345e7b6132 r9cda6e0f5d  
    510510        pb->setFormat(tr("Generating header"));
    511511        pd.setLabelText(tr("Generating solution output..."));
    512         pd.setMaximum(n);
     512        pd.setMaximum(solver.getTotalSteps() + 1);
    513513        pd.setValue(0);
    514514
     
    517517
    518518QPainter pic;
    519         pic.begin(&graph);
    520         pic.setRenderHint(QPainter::Antialiasing);
     519        if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
     520                pic.begin(&graph);
     521                pic.setRenderHint(QPainter::Antialiasing);
     522        }
    521523
    522524QTextDocument *doc = solutionText->document();
     
    529531        cur.insertText(tr("Task:"));
    530532        outputMatrix(cur, matrix);
    531         drawNode(pic, 0);
     533        if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool())
     534                drawNode(pic, 0);
    532535        cur.insertHtml("<hr>");
    533536        cur.insertBlock(fmt_paragraph);
     
    537540
    538541SStep *step = root;
    539         n = 1;
     542int c = n = 1;
    540543        pb->setFormat(tr("Generating step %v"));
    541         while (n < spinCities->value()) {
     544        while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) {
    542545                if (pd.wasCanceled()) {
    543546                        pd.setLabelText(tr("Cleaning up..."));
     
    553556                pd.setValue(n);
    554557
    555                 if (step->prNode->prNode != NULL || ((step->prNode->prNode == NULL) && (step->plNode->prNode == NULL))) {
    556                         if (n != spinCities->value()) {
    557                                 cur.beginEditBlock();
    558                                 cur.insertBlock(fmt_paragraph);
    559                                 cur.insertText(tr("Step #%1").arg(n++));
    560                                 if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && (!settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() || (settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt())))) {
    561                                         outputMatrix(cur, *step);
    562                                 }
    563                                 cur.insertBlock(fmt_paragraph);
    564                                 cur.insertText(tr("Selected candidate for branching: %1.").arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default);
    565                                 if (!step->alts.empty()) {
    566 SCandidate cand;
    567 QString alts;
    568                                         foreach(cand, step->alts) {
    569                                                 if (!alts.isEmpty())
    570                                                         alts += ", ";
    571                                                 alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
    572                                         }
    573                                         cur.insertBlock(fmt_paragraph);
    574                                         cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist);
    575                                 }
    576                                 cur.insertBlock(fmt_paragraph);
    577                                 cur.insertText(" ", fmt_default);
    578                                 cur.endEditBlock();
     558                cur.beginEditBlock();
     559                cur.insertBlock(fmt_paragraph);
     560                cur.insertText(tr("Step #%1").arg(n));
     561                if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && (!settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() || (settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixLimit", DEF_SHOW_MATRIX_LIMIT).toInt())))) {
     562                        outputMatrix(cur, *step);
     563                }
     564                cur.insertBlock(fmt_paragraph);
     565                cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default);
     566                if (!step->alts.empty()) {
     567                        SStep::SCandidate cand;
     568                        QString alts;
     569                        foreach(cand, step->alts) {
     570                                if (!alts.isEmpty())
     571                                        alts += ", ";
     572                                alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1);
    579573                        }
    580                 }
    581                 if (n < spinCities->value()) {
     574                        cur.insertBlock(fmt_paragraph);
     575                        cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist);
     576                }
     577                cur.insertBlock(fmt_paragraph);
     578                cur.insertText(" ", fmt_default);
     579                cur.endEditBlock();
     580
     581                if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
    582582                        if (step->prNode != NULL)
    583                                 drawNode(pic, n - 1, false, step->prNode);
     583                                drawNode(pic, n, false, step->prNode);
    584584                        if (step->plNode != NULL)
    585                                 drawNode(pic, n - 1, true, step->plNode);
    586                 }
    587                 if (step->prNode->prNode != NULL) {
     585                                drawNode(pic, n, true, step->plNode);
     586                }
     587                n++;
     588
     589                if (step->next == SStep::RightBranch) {
     590                        c++;
    588591                        step = step->prNode;
    589                 } else if (step->plNode->prNode != NULL) {
     592                } else if (step->next == SStep::LeftBranch) {
    590593                        step = step->plNode;
    591594                } else
     
    617620        }
    618621        cur.endEditBlock();
    619         pic.end();
     622
     623        if (settings->value("Output/ShowGraph", DEF_SHOW_GRAPH).toBool()) {
     624                pic.end();
    620625
    621626QImage i(graph.width() + 2, graph.height() + 2, QImage::Format_ARGB32);
    622         i.fill(0);
    623         pic.begin(&i);
    624         pic.drawPicture(1, 1, graph);
    625         pic.end();
    626         doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i);
     627                i.fill(0);
     628                pic.begin(&i);
     629                pic.drawPicture(1, 1, graph);
     630                pic.end();
     631                doc->addResource(QTextDocument::ImageResource, QUrl("tspsg://graph.pic"), i);
    627632
    628633QTextImageFormat img;
    629         img.setName("tspsg://graph.pic");
    630 
    631         cur.setPosition(imgpos);
    632         cur.insertImage(img, QTextFrameFormat::FloatRight);
     634                img.setName("tspsg://graph.pic");
     635
     636                cur.setPosition(imgpos);
     637                cur.insertImage(img, QTextFrameFormat::FloatRight);
     638        }
    633639
    634640        if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) {
     
    784790                }
    785791                pic.setBackgroundMode(Qt::OpaqueMode);
    786                 pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, isInteger(step->price) ?  QString("\n%1").arg(step->price) : QString("\n%1").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()));
     792                if (step->price != INFINITY) {
     793                        pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, isInteger(step->price) ?  QString("\n%1").arg(step->price) : QString("\n%1").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()));
     794                } else {
     795                        pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, "\n"INFSTR);
     796                }
    787797                pic.setBackgroundMode(Qt::TransparentMode);
    788798        } else {
     
    790800        }
    791801
    792         if (nstep == 1)
    793                 pic.drawLine(QPointF(r * 2.25, r * (3 * (nstep - 1) + 2)), QPointF(x, y - r));
    794         else
    795                 pic.drawLine(QPointF(r * 3.5, r * (3 * (nstep - 1) + 2)), QPointF(x, y - r));
     802        if (nstep == 1) {
     803                pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r));
     804        } else if (nstep > 1) {
     805                pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));
     806        }
    796807
    797808}
     
    806817                toggleSolutionActions(false);
    807818
    808                 ev->acceptProposedAction();
     819                ev->setDropAction(Qt::CopyAction);
     820                ev->accept();
    809821        }
    810822}
     
    9921004                                cur.insertText(isInteger(step.matrix.at(r).at(c)) ? QString("%1").arg(step.matrix.at(r).at(c)) : QString("%1").arg(step.matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()), fmt_selected);
    9931005                        else {
    994 SCandidate cand;
     1006SStep::SCandidate cand;
    9951007                                cand.nRow = r;
    9961008                                cand.nCol = c;
Note: See TracChangeset for help on using the changeset viewer.