Changeset 317ba0432e in tspsg for src/mainwindow.cpp
- Timestamp:
- Apr 19, 2010, 10:33:02 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- b574c383b7
- Parents:
- a23f4c292f
- git-author:
- Oleksii Serdiuk <contacts@…> (04/19/10 22:33:02)
- git-committer:
- Oleksii Serdiuk <contacts@…> (06/29/12 19:41:27)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mainwindow.cpp
ra23f4c292f r317ba0432e 512 512 pd.setValue(0); 513 513 514 #ifdef DEBUG 515 QTime t; 516 t.start(); 517 #endif 514 518 solutionText->clear(); 515 solutionText->setDocumentTitle(tr("Solution of Variant #%1 task").arg(spinVariant->value())); 516 solutionText->append("<p>" + tr("Variant #%1").arg(spinVariant->value()) + "</p>"); 517 solutionText->append("<p>" + tr("Task:") + "</p>"); 518 solutionText->append(outputMatrix(matrix)); 519 solutionText->append("<hr><p>" + tr("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>"); 519 #ifdef DEBUG 520 qDebug() << "Clear:" << t.elapsed(); 521 t.restart(); 522 #endif 523 solutionText->setDocumentTitle(tr("Solution of Variant #%1 Task").arg(spinVariant->value())); 524 525 QTextDocument *doc = solutionText->document(); 526 QTextCursor cur(doc); 527 528 cur.beginEditBlock(); 529 cur.setBlockFormat(fmt_paragraph); 530 cur.insertText(tr("Variant #%1").arg(spinVariant->value()), fmt_default); 531 cur.insertBlock(fmt_paragraph); 532 cur.insertText(tr("Task:")); 533 outputMatrix(cur, matrix); 534 cur.insertHtml("<hr>"); 535 cur.insertBlock(fmt_paragraph); 536 cur.insertText(tr("Solution of Variant #%1 Task").arg(spinVariant->value()), fmt_default); 537 cur.endEditBlock(); 538 520 539 SStep *step = root; 521 540 n = 1; … … 523 542 while (n < spinCities->value()) { 524 543 if (pd.wasCanceled()) { 544 pd.setLabelText(tr("Cleaning up...")); 545 pd.setMaximum(0); 546 pd.setCancelButton(NULL); 547 pd.show(); 548 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); 549 solver.cleanup(true); 525 550 solutionText->clear(); 551 toggleSolutionActions(false); 526 552 return; 527 553 } … … 530 556 if (step->prNode->prNode != NULL || ((step->prNode->prNode == NULL) && (step->plNode->prNode == NULL))) { 531 557 if (n != spinCities->value()) { 532 solutionText->append("<p>" + tr("Step #%1").arg(n++) + "</p>"); 558 cur.beginEditBlock(); 559 cur.insertBlock(fmt_paragraph); 560 cur.insertText(tr("Step #%1").arg(n++)); 533 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())))) { 534 solutionText->append(outputMatrix(*step));562 outputMatrix(cur, *step); 535 563 } 536 solutionText->append("<p>" + tr("Selected candidate for branching: %1.").arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)) + "</p>"); 564 cur.insertBlock(fmt_paragraph); 565 cur.insertText(tr("Selected candidate for branching: %1.").arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default); 537 566 if (!step->alts.empty()) { 538 567 SCandidate cand; … … 543 572 alts += tr("(%1;%2)").arg(cand.nRow + 1).arg(cand.nCol + 1); 544 573 } 545 solutionText->append("<p class=\"hasalts\">" + tr("%n alternate candidate(s) for branching: %1.","",step->alts.count()).arg(alts) + "</p>"); 574 cur.insertBlock(fmt_paragraph); 575 cur.insertText(tr("%n alternate candidate(s) for branching: %1.", "", step->alts.count()).arg(alts), fmt_altlist); 546 576 } 547 solutionText->append("<p> </p>"); 577 cur.insertBlock(fmt_paragraph); 578 cur.insertText(" ", fmt_default); 579 cur.endEditBlock(); 548 580 } 549 581 } … … 558 590 pd.setValue(n); 559 591 592 cur.beginEditBlock(); 593 cur.insertBlock(fmt_paragraph); 560 594 if (solver.isOptimal()) 561 solutionText->append("<p>" + tr("Optimal path:") + "</p>");595 cur.insertText(tr("Optimal path:")); 562 596 else 563 solutionText->append("<p>" + tr("Resulting path:") + "</p>"); 564 solutionText->append("<p> " + solver.getSortedPath() + "</p>"); 597 cur.insertText(tr("Resulting path:")); 598 599 cur.insertBlock(fmt_paragraph); 600 cur.insertText(" " + solver.getSortedPath()); 601 602 cur.insertBlock(fmt_paragraph); 565 603 if (isInteger(step->price)) 566 solutionText->append("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>");604 cur.insertHtml("<p>" + tr("The price is <b>%n</b> unit(s).", "", qRound(step->price)) + "</p>"); 567 605 else 568 solutionText->append("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>");606 cur.insertHtml("<p>" + tr("The price is <b>%1</b> units.").arg(step->price, 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt()) + "</p>"); 569 607 if (!solver.isOptimal()) { 570 solutionText->append("<p> </p>"); 571 solutionText->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>"); 572 } 608 cur.insertBlock(fmt_paragraph); 609 cur.insertText(" "); 610 cur.insertBlock(fmt_paragraph); 611 cur.insertHtml("<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>"); 612 } 613 cur.endEditBlock(); 614 #ifdef DEBUG 615 qDebug() << "Generate:" << t.elapsed(); 616 #endif 573 617 574 618 if (settings->value("Output/ScrollToEnd", DEF_SCROLL_TO_END).toBool()) { 575 // Scrolling to the end of t ext.619 // Scrolling to the end of the text. 576 620 solutionText->moveCursor(QTextCursor::End); 577 621 } else … … 701 745 void MainWindow::initDocStyleSheet() 702 746 { 703 QColor color = settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>(); 747 solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE)).value<QFont>()); 748 749 fmt_paragraph.setTopMargin(0); 750 fmt_paragraph.setRightMargin(10); 751 fmt_paragraph.setBottomMargin(0); 752 fmt_paragraph.setLeftMargin(10); 753 754 fmt_table.setTopMargin(5); 755 fmt_table.setRightMargin(10); 756 fmt_table.setBottomMargin(5); 757 fmt_table.setLeftMargin(10); 758 fmt_table.setBorder(0); 759 fmt_table.setBorderStyle(QTextFrameFormat::BorderStyle_None); 760 fmt_table.setCellSpacing(5); 761 762 fmt_center.setAlignment(Qt::AlignHCenter); 763 764 QColor color = settings->value("Output/Colors/Text", DEF_TEXT_COLOR).value<QColor>(); 704 765 QColor hilight; 705 766 if (color.value() < 192) 706 hilight.setHsv(color.hue(), color.saturation(),127 + qRound(color.value() / 2));767 hilight.setHsv(color.hue(), color.saturation(), 127 + qRound(color.value() / 2)); 707 768 else 708 hilight.setHsv(color.hue(),color.saturation(),color.value() / 2); 709 solutionText->document()->setDefaultStyleSheet("* {color: " + color.name() +";} p {margin: 0px 10px;} table {margin: 5px;} td {padding: 1px 5px;} .hasalts {color: " + hilight.name() + ";} .selected {color: #A00000; font-weight: bold;} .alternate {color: #008000; font-weight: bold;}"); 710 solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>()); 769 hilight.setHsv(color.hue(), color.saturation(), color.value() / 2); 770 771 solutionText->document()->setDefaultStyleSheet(QString("* {color: %1;}").arg(color.name())); 772 fmt_default.setForeground(QBrush(color)); 773 774 fmt_selected.setForeground(QBrush(settings->value("Output/Colors/Selected", DEF_SELECTED_COLOR).value<QColor>())); 775 fmt_selected.setFontWeight(QFont::Bold); 776 777 fmt_alternate.setForeground(QBrush(settings->value("Output/Colors/Alternate", DEF_ALTERNATE_COLOR).value<QColor>())); 778 fmt_alternate.setFontWeight(QFont::Bold); 779 fmt_altlist.setForeground(QBrush(hilight)); 780 781 solutionText->setTextColor(color); 711 782 } 712 783 … … 811 882 } 812 883 813 QString MainWindow::outputMatrix(const TMatrix &matrix) const 884 void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix) 814 885 { 815 886 int n = spinCities->value(); 816 Q String output(""), line;817 output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); 887 QTextTable *table = cur.insertTable(n, n, fmt_table); 888 818 889 for (int r = 0; r < n; r++) { 819 line = "<tr>";820 890 for (int c = 0; c < n; c++) { 891 cur = table->cellAt(r, c).firstCursorPosition(); 892 cur.setBlockFormat(fmt_center); 893 cur.setBlockCharFormat(fmt_default); 821 894 if (matrix.at(r).at(c) == INFINITY) 822 line += "<td align=\"center\">"INFSTR"</td>";895 cur.insertText(INFSTR); 823 896 else 824 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()); 825 } 826 line += "</tr>"; 827 output.append(line); 828 } 829 output.append("</table>"); 830 return output; 831 } 832 833 QString MainWindow::outputMatrix(const SStep &step) const 897 cur.insertText(isInteger(matrix.at(r).at(c)) ? QString("%1").arg(matrix.at(r).at(c)) : QString("%1").arg(matrix.at(r).at(c), 0, 'f', settings->value("Task/FractionalAccuracy", DEF_FRACTIONAL_ACCURACY).toInt())); 898 } 899 QApplication::processEvents(); 900 } 901 cur.movePosition(QTextCursor::End); 902 } 903 904 void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step) 834 905 { 835 906 int n = spinCities->value(); 836 Q String output(""), line;837 output.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"); 907 QTextTable *table = cur.insertTable(n, n, fmt_table); 908 838 909 for (int r = 0; r < n; r++) { 839 line = "<tr>";840 910 for (int c = 0; c < n; c++) { 911 cur = table->cellAt(r, c).firstCursorPosition(); 912 cur.setBlockFormat(fmt_center); 841 913 if (step.matrix.at(r).at(c) == INFINITY) 842 line += "<td align=\"center\">"INFSTR"</td>";914 cur.insertText(INFSTR, fmt_default); 843 915 else if ((r == step.candidate.nRow) && (c == step.candidate.nCol)) 844 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());916 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); 845 917 else { 846 918 SCandidate cand; … … 848 920 cand.nCol = c; 849 921 if (step.alts.contains(cand)) 850 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());922 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_alternate); 851 923 else 852 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());924 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_default); 853 925 } 854 926 } 855 line += "</tr>"; 856 output.append(line); 857 } 858 output.append("</table>"); 859 return output; 927 QApplication::processEvents(); 928 } 929 930 cur.movePosition(QTextCursor::End); 860 931 } 861 932 … … 958 1029 #endif // Q_OS_WINCE_WM 959 1030 960 solutionText->document()->setDefaultFont(settings->value("Output/Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>()); 961 solutionText->setTextColor(settings->value("Output/Color",DEF_FONT_COLOR).value<QColor>()); 1031 solutionText->document()->setDefaultFont(settings->value("Output/Font", QFont(DEF_FONT_FAMILY, DEF_FONT_SIZE)).value<QFont>()); 962 1032 solutionText->setWordWrapMode(QTextOption::WordWrap); 963 1033
Note: See TracChangeset
for help on using the changeset viewer.