Changeset 345e7b6132 in tspsg


Ignore:
Timestamp:
Apr 20, 2010, 11:18:18 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:
9cda6e0f5d
Parents:
b574c383b7
git-author:
Oleksii Serdiuk <contacts@…> (04/20/10 23:18:18)
git-committer:
Oleksii Serdiuk <contacts@…> (06/29/12 19:41:31)
Message:

+ Added solution graph generation.

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/mainwindow.cpp

    rb574c383b7 r345e7b6132  
    513513        pd.setValue(0);
    514514
    515 #ifdef DEBUG
    516 QTime t;
    517         t.start();
    518 #endif
    519515        solutionText->clear();
    520 #ifdef DEBUG
    521         qDebug() << "Clear:" << t.elapsed();
    522         t.restart();
    523 #endif
    524516        solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value()));
     517
     518QPainter pic;
     519        pic.begin(&graph);
     520        pic.setRenderHint(QPainter::Antialiasing);
    525521
    526522QTextDocument *doc = solutionText->document();
     
    529525        cur.beginEditBlock();
    530526        cur.setBlockFormat(fmt_paragraph);
    531         cur.insertText(tr("Variant #%1").arg(spinVariant->value()), fmt_default);
     527        cur.insertText(tr("Variant #%1 Task").arg(spinVariant->value()), fmt_default);
    532528        cur.insertBlock(fmt_paragraph);
    533529        cur.insertText(tr("Task:"));
    534530        outputMatrix(cur, matrix);
     531        drawNode(pic, 0);
    535532        cur.insertHtml("<hr>");
    536533        cur.insertBlock(fmt_paragraph);
    537         cur.insertText(tr("Solution of Variant #%1 Task").arg(spinVariant->value()), fmt_default);
     534int imgpos = cur.position();
     535        cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default);
    538536        cur.endEditBlock();
    539537
     
    581579                        }
    582580                }
    583                 if (step->prNode->prNode != NULL)
     581                if (n < spinCities->value()) {
     582                        if (step->prNode != NULL)
     583                                drawNode(pic, n - 1, false, step->prNode);
     584                        if (step->plNode != NULL)
     585                                drawNode(pic, n - 1, true, step->plNode);
     586                }
     587                if (step->prNode->prNode != NULL) {
    584588                        step = step->prNode;
    585                 else if (step->plNode->prNode != NULL)
     589                } else if (step->plNode->prNode != NULL) {
    586590                        step = step->plNode;
    587                 else
     591                } else
    588592                        break;
    589593        }
     
    613617        }
    614618        cur.endEditBlock();
    615 #ifdef DEBUG
    616         qDebug() << "Generate:" << t.elapsed();
    617 #endif
     619        pic.end();
     620
     621QImage 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
     628QTextImageFormat img;
     629        img.setName("tspsg://graph.pic");
     630
     631        cur.setPosition(imgpos);
     632        cur.insertImage(img, QTextFrameFormat::FloatRight);
    618633
    619634        if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) {
     
    744759}
    745760
     761void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)
     762{
     763const int r = 35;
     764qreal x, y;
     765        if (step != NULL)
     766                x = left ? r : r * 3.5;
     767        else
     768                x = r * 2.25;
     769        y = r * (3 * nstep + 1);
     770
     771        pic.drawEllipse(QPointF(x, y), r, r);
     772
     773        if (step != NULL) {
     774QFont font;
     775                if (left) {
     776                        font = pic.font();
     777                        font.setStrikeOut(true);
     778                        pic.setFont(font);
     779                }
     780                pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("(%1;%2)").arg(step->pNode->candidate.nRow + 1).arg(step->pNode->candidate.nCol + 1) + "\n");
     781                if (left) {
     782                        font.setStrikeOut(false);
     783                        pic.setFont(font);
     784                }
     785                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()));
     787                pic.setBackgroundMode(Qt::TransparentMode);
     788        } else {
     789                pic.drawText(QRectF(x - r, y - r, r * 2, r * 2), Qt::AlignCenter, tr("Root"));
     790        }
     791
     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));
     796
     797}
     798
    746799void MainWindow::dropEvent(QDropEvent *ev)
    747800{
     
    783836        fmt_table.setCellSpacing(5);
    784837
    785         fmt_center.setAlignment(Qt::AlignHCenter);
     838        fmt_cell.setAlignment(Qt::AlignHCenter);
    786839
    787840QColor color = settings->value("Output/Colors/Text", DEF_TEXT_COLOR).value<QColor>();
     
    913966                for (int c = 0; c < n; c++) {
    914967                        cur = table->cellAt(r, c).firstCursorPosition();
    915                         cur.setBlockFormat(fmt_center);
     968                        cur.setBlockFormat(fmt_cell);
    916969                        cur.setBlockCharFormat(fmt_default);
    917970                        if (matrix.at(r).at(c) == INFINITY)
     
    933986                for (int c = 0; c < n; c++) {
    934987                        cur = table->cellAt(r, c).firstCursorPosition();
    935                         cur.setBlockFormat(fmt_center);
     988                        cur.setBlockFormat(fmt_cell);
    936989                        if (step.matrix.at(r).at(c) == INFINITY)
    937990                                cur.insertText(INFSTR, fmt_default);
  • src/mainwindow.h

    rb574c383b7 r345e7b6132  
    101101#endif // Q_OS_WINCE_WM
    102102
     103        // The solution graph SVG
     104        QPicture graph;
     105
    103106        // Formats
    104107        QTextTableFormat fmt_table;
    105108        QTextBlockFormat fmt_paragraph,
    106                 fmt_center;
     109                fmt_cell;
    107110        QTextCharFormat fmt_default,
    108111                fmt_selected,
     
    112115        void closeEvent(QCloseEvent *ev);
    113116        void dragEnterEvent(QDragEnterEvent *ev);
     117        void drawNode(QPainter &pic, int nstep, bool left = false, SStep *step = NULL);
    114118        void dropEvent(QDropEvent *ev);
    115119        bool hasUpdater() const;
Note: See TracChangeset for help on using the changeset viewer.