Changeset 07e43cf61a in tspsg for src/mainwindow.cpp
- Timestamp:
- Oct 5, 2012, 5:30:23 PM (12 years ago)
- Branches:
- appveyor, imgbot, master, readme
- Children:
- 47c811cc09
- Parents:
- 7a39458d16
- git-author:
- Oleksii Serdiuk <contacts@…> (10/05/12 17:30:23)
- git-committer:
- Oleksii Serdiuk <contacts@…> (10/05/12 21:58:30)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mainwindow.cpp
r7a39458d16 r07e43cf61a 23 23 24 24 #include "mainwindow.h" 25 #include "settingsdialog.h" 26 #include "tspmodel.h" 27 28 #include <QBuffer> 29 #include <QCloseEvent> 30 #include <QDate> 31 #include <QDesktopServices> 32 #include <QDesktopWidget> 33 #include <QFileDialog> 34 #include <QImageWriter> 35 #include <QLibraryInfo> 36 #include <QMessageBox> 37 #include <QPageSetupDialog> 38 #include <QPainter> 39 #include <QProgressBar> 40 #include <QProgressDialog> 41 #include <QSettings> 42 #include <QStatusBar> 43 #include <QStyleFactory> 44 #include <QTextCodec> 45 #include <QTextDocumentWriter> 46 #include <QTextBrowser> 47 #include <QTextStream> 48 #include <QTextTable> 49 #include <QTranslator> 50 51 #ifdef Q_OS_WINCE_WM 52 # include <QScrollArea> 53 #endif 54 55 #ifndef QT_NO_PRINTER 56 # include <QPrinter> 57 # include <QPrintDialog> 58 # include <QPrintPreviewDialog> 59 #endif 60 61 #if !defined(NOSVG) 62 # include <QSvgGenerator> 63 #endif // NOSVG 64 65 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) 66 # include <QtConcurrent> 67 #endif 68 69 #include "os.h" 70 71 #ifndef HANDHELD 72 # include "qttoolbardialog.h" 73 // Eyecandy 74 # include "qtwin.h" 75 #endif // HANDHELD 76 77 #ifndef QT_NO_PRINTER 78 Q_DECLARE_METATYPE(QPrinter::PageSize) 79 Q_DECLARE_METATYPE(QPrinter::Orientation) 80 #endif 25 81 26 82 #ifdef Q_OS_WIN32 … … 32 88 _C_ _R_ _Y_ _P_ _T_ 33 89 #endif 90 91 // BEGIN HELPER FUNCTIONS 92 /*! 93 * \brief Checks whether \a x contains an integer value. 94 * \param x A value to check. 95 * \return \c true if \a x countains an integer, oherwise \c false. 96 */ 97 inline bool isInteger(double x) 98 { 99 double i; 100 return (modf(x, &i) == 0.0); 101 } 102 103 /*! 104 * \brief Converts \a in into Base64 format with lines wrapped at 64 characters. 105 * \param in A byte array to be converted. 106 * \return Converted byte array. 107 */ 108 inline QByteArray toWrappedBase64(const QByteArray &in) 109 { 110 QByteArray out, base64(in.toBase64()); 111 for (int i = 0; i <= base64.size() - 64; i += 64) { 112 out.append(QByteArray::fromRawData(base64.data() + i, 64)).append('\n'); 113 } 114 if (int rest = base64.size() % 64) 115 out.append(QByteArray::fromRawData(base64.data() + base64.size() - rest, rest)); 116 return out; 117 } 118 // END HELPER FUNCTIONS 34 119 35 120 /*! … … 571 656 #endif 572 657 about += tr("Build <b>%1</b>, built on <b>%2</b> at <b>%3</b>%5 with <b>%4</b> compiler.").arg(BUILD_NUMBER).arg(__DATE__).arg(__TIME__).arg(COMPILER).arg(tag) + "<br>"; 573 about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), CTSPSolver::getVersionId());658 about += QString("%1: <b>%2</b><br>").arg(tr("Algorithm"), TSPSolver::CTSPSolver::getVersionId()); 574 659 about += "<br>"; 575 660 about += tr("This program is free software: you can redistribute it and/or modify<br>\n" … … 738 823 void MainWindow::buttonSolveClicked() 739 824 { 740 TMatrix matrix;741 QList<double> row;742 int n = spinCities->value();743 bool ok;825 TSPSolver::TMatrix matrix; 826 QList<double> row; 827 int n = spinCities->value(); 828 bool ok; 744 829 for (int r = 0; r < n; r++) { 745 830 row.clear(); … … 784 869 #endif 785 870 786 CTSPSolver solver;871 TSPSolver::CTSPSolver solver; 787 872 solver.setCleanupOnCancel(false); 788 873 connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int))); … … 792 877 connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int))); 793 878 #endif 794 SStep *root = solver.solve(n, matrix);879 TSPSolver::SStep *root = solver.solve(n, matrix); 795 880 #ifdef Q_OS_WIN32 796 881 if (tl != NULL) … … 821 906 822 907 #ifndef QT_NO_CONCURRENT 823 QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);908 QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false); 824 909 while (!f.isFinished()) { 825 910 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); … … 899 984 cur.insertHtml("<hr>"); 900 985 cur.insertBlock(fmt_paragraph); 901 int imgpos = cur.position();986 int imgpos = cur.position(); 902 987 cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default); 903 988 cur.endEditBlock(); 904 989 905 SStep *step = root;906 int c = n = 1;990 TSPSolver::SStep *step = root; 991 int c = n = 1; 907 992 pb->setFormat(tr("Generating step %v")); 908 while ((step->next != SStep::NoNextStep) && (c < spinCities->value())) {993 while ((step->next != TSPSolver::SStep::NoNextStep) && (c < spinCities->value())) { 909 994 if (pd.wasCanceled()) { 910 995 pd.setLabelText(tr("Memory cleanup...")); … … 918 1003 #endif 919 1004 #ifndef QT_NO_CONCURRENT 920 QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);1005 QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false); 921 1006 while (!f.isFinished()) { 922 1007 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); … … 952 1037 else 953 1038 cur.insertBlock(fmt_paragraph); 954 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);1039 cur.insertText(tr("Selected route %1 %2 part.").arg((step->next == TSPSolver::SStep::RightBranch) ? tr("with") : tr("without")).arg(tr("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)), fmt_default); 955 1040 if (!step->alts.empty()) { 956 SStep::SCandidate cand;1041 TSPSolver::SStep::SCandidate cand; 957 1042 QString alts; 958 1043 foreach(cand, step->alts) { … … 974 1059 n++; 975 1060 976 if (step->next == SStep::RightBranch) {1061 if (step->next == TSPSolver::SStep::RightBranch) { 977 1062 c++; 978 1063 step = step->prNode; 979 } else if (step->next == SStep::LeftBranch) {1064 } else if (step->next == TSPSolver::SStep::LeftBranch) { 980 1065 step = step->plNode; 981 1066 } else … … 1052 1137 #endif 1053 1138 #ifndef QT_NO_CONCURRENT 1054 QFuture<void> f = QtConcurrent::run(&solver, &CTSPSolver::cleanup, false);1139 QFuture<void> f = QtConcurrent::run(&solver, &TSPSolver::CTSPSolver::cleanup, false); 1055 1140 while (!f.isFinished()) { 1056 1141 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); … … 1211 1296 } 1212 1297 1213 void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)1298 void MainWindow::drawNode(QPainter &pic, int nstep, bool left, TSPSolver::SStep *step) 1214 1299 { 1215 1300 qreal r; // Radius of graph node … … 1268 1353 pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r)); 1269 1354 } else if (nstep > 1) { 1270 pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == SStep::RightBranch) ? r * 3.5 : r, y - 2 * r));1355 pic.drawLine(QPointF(x, y - r), QPointF((step->pNode->pNode->next == TSPSolver::SStep::RightBranch) ? r * 3.5 : r, y - 2 * r)); 1271 1356 } 1272 1357 … … 1563 1648 } 1564 1649 1565 void MainWindow::outputMatrix(QTextCursor &cur, const T Matrix &matrix)1650 void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::TMatrix &matrix) 1566 1651 { 1567 1652 int n = spinCities->value(); … … 1583 1668 } 1584 1669 1585 void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step)1670 void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::SStep &step) 1586 1671 { 1587 1672 int n = spinCities->value(); … … 1597 1682 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); 1598 1683 else { 1599 SStep::SCandidate cand;1684 TSPSolver::SStep::SCandidate cand; 1600 1685 cand.nRow = r; 1601 1686 cand.nCol = c;
Note: See TracChangeset
for help on using the changeset viewer.