Changeset 07e43cf61a in tspsg for src
- 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)
- Location:
- src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/globals.cpp
r7a39458d16 r07e43cf61a 24 24 #include "globals.h" 25 25 26 #include <QFile> 27 #include <QObject> 28 #include <QSettings> 29 #include <QWidget> 30 26 31 #ifdef Q_OS_WINCE_WM 27 32 # include <shellapi.h> 28 33 #endif 34 35 bool hasUpdater() 36 { 37 #ifdef Q_OS_WIN32 38 return QFile::exists("updater/Update.exe"); 39 #else // Q_OS_WIN32 40 return false; 41 #endif // Q_OS_WIN32 42 } 29 43 30 44 QSettings *initSettings(QObject *parent) -
src/globals.h
r7a39458d16 r07e43cf61a 30 30 31 31 // INCLUDES 32 #include <Qt Core>32 #include <QtGlobal> 33 33 #if QT_VERSION < QT_VERSION_CHECK(4,5,0) 34 34 # error You are using Qt version < 4.5 but minimum required version is 4.5.0. Compilation aborted. … … 39 39 # define QT_NO_STATUSTIP 40 40 #endif 41 #include <QtGui>42 41 #if defined(QT_NO_SVG) && !defined(NOSVG) 43 42 # define NOSVG 44 43 #endif 45 #if !defined(NOSVG)46 # include <QtSvg>47 #endif // NOSVG48 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)49 # include <QtConcurrent>50 # include <QtPrintSupport>51 #endif52 44 53 #ifndef HANDHELD54 # include "qttoolbardialog.h"55 #endif56 57 // Version info58 #include "version.h"59 // OS and ARCH detection60 #include "os.h"61 45 // TSPSG Defaults 62 46 #include "defaults.h" 63 // TSPSolver64 #include "tspsolver.h"65 #ifndef HANDHELD66 // Eyecandy67 # include "qtwin.h"68 #endif // HANDHELD69 47 70 48 // DEFINES … … 84 62 /*! 85 63 * \def PATH_DOCS 86 * \brief Bath to documentation files.64 * \brief Path to documentation files. 87 65 */ 88 66 #ifndef PATH_DOCS … … 111 89 #define HQ_FACTOR 2 112 90 113 // FUNCTIONS114 /*!115 * \brief Checks whether \a x contains an integer value.116 * \param x A value to check.117 * \return \c true if \a x countains an integer, oherwise \c false.118 */119 inline bool isInteger(double x)120 {121 double i;122 return (modf(x, &i) == 0.0);123 }124 125 91 /*! 126 92 * \brief Checks whether the updater app is installed/available. … … 129 95 * On other systems this function always returns \c false. 130 96 */ 131 inline bool hasUpdater() 132 { 133 #ifdef Q_OS_WIN32 134 return QFile::exists("updater/Update.exe"); 135 #else // Q_OS_WIN32 136 return false; 137 #endif // Q_OS_WIN32 138 } 97 bool hasUpdater(); 139 98 140 /*! 141 * \brief Converts \a in into Base64 format with lines wrapped at 64 characters. 142 * \param in A byte array to be converted. 143 * \return Converted byte array. 144 */ 145 inline QByteArray toWrappedBase64(const QByteArray &in) 146 { 147 QByteArray out, base64(in.toBase64()); 148 for (int i = 0; i <= base64.size() - 64; i += 64) { 149 out.append(QByteArray::fromRawData(base64.data() + i, 64)).append('\n'); 150 } 151 if (int rest = base64.size() % 64) 152 out.append(QByteArray::fromRawData(base64.data() + base64.size() - rest, rest)); 153 return out; 154 } 155 99 class QSettings; 100 class QObject; 156 101 /*! 157 102 * \brief Creates QSettings instance with TSPSG-specific options. … … 162 107 163 108 #ifndef HANDHELD 109 class QWidget; 164 110 /*! 165 111 * \brief Enables or disables a mask for the \a widget. … … 173 119 174 120 #ifndef DOXYGEN_EXCLUDE 175 176 #ifndef QT_NO_PRINTER177 Q_DECLARE_METATYPE(QPrinter::PageSize)178 Q_DECLARE_METATYPE(QPrinter::Orientation)179 #endif180 121 181 122 #ifdef HANDHELD -
src/main.cpp
r7a39458d16 r07e43cf61a 23 23 24 24 #include "mainwindow.h" 25 26 #include <QDateTime> 27 #include <QFontDatabase> 28 #include <QTextCodec> 29 #include <QTranslator> 30 #include "version.h" 31 25 32 #if QT_VERSION < QT_VERSION_CHECK(4,6,0) 26 33 # ifdef Q_CC_MSVC -
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; -
src/mainwindow.h
r7a39458d16 r07e43cf61a 32 32 33 33 #include "ui_mainwindow.h" 34 #include " settingsdialog.h"34 #include "tspsolver.h" 35 35 36 #include "tspmodel.h"36 #include <QPicture> 37 37 38 38 #ifdef Q_OS_WIN32 … … 41 41 #endif 42 42 43 using namespace TSPSolver; 43 class CTSPModel; 44 45 #ifndef HANDHELD 46 class QtToolbarDialog; 47 class QtToolBarManager; 48 #endif 49 50 #ifndef QT_NO_PRINTER 51 class QPrinter; 52 #endif 44 53 45 54 /*! … … 143 152 void closeEvent(QCloseEvent *ev); 144 153 void dragEnterEvent(QDragEnterEvent *ev); 145 void drawNode(QPainter &pic, int nstep, bool left = false, SStep *step = NULL);154 void drawNode(QPainter &pic, int nstep, bool left = false, TSPSolver::SStep *step = NULL); 146 155 void dropEvent(QDropEvent *ev); 147 156 QByteArray generateImage(const QString &format); … … 152 161 void loadToolbarList(); 153 162 bool maybeSave(); 154 void outputMatrix(QTextCursor &cur, const T Matrix &matrix);155 void outputMatrix(QTextCursor &cur, const SStep &step);163 void outputMatrix(QTextCursor &cur, const TSPSolver::TMatrix &matrix); 164 void outputMatrix(QTextCursor &cur, const TSPSolver::SStep &step); 156 165 #ifdef Q_OS_SYMBIAN 157 166 void resizeEvent(QResizeEvent *ev); … … 166 175 167 176 #ifdef Q_OS_SYMBIAN 177 #include <QMessageBox> 168 178 // A quickly hacked QMessageBox for Symbian that supports three buttons. 169 179 class QSMessageBox: public QMessageBox { -
src/pch.h
r7a39458d16 r07e43cf61a 27 27 28 28 #ifdef __cplusplus 29 #include "globals.h" 29 # include "globals.h" 30 # include <QtCore> 31 # include <QtGui> 32 # if defined(QT_NO_SVG) && !defined(NOSVG) 33 # define NOSVG 34 # endif 35 # if !defined(NOSVG) 36 # include <QtSvg> 37 # endif // NOSVG 38 # if QT_VERSION >= QT_VERSION_CHECK(5,0,0) 39 # include <QtConcurrent> 40 # include <QtPrintSupport> 41 # endif 42 # ifndef HANDHELD 43 # include "qttoolbardialog.h" 44 # endif 30 45 #endif // __cplusplus -
src/settingsdialog.cpp
r7a39458d16 r07e43cf61a 23 23 24 24 #include "settingsdialog.h" 25 26 #include <QColorDialog> 27 #include <QFontDialog> 28 #include <QImageWriter> 29 #include <QMessageBox> 30 #include <QSettings> 31 32 #ifdef HANDHELD 33 # include <QScrollArea> 34 #endif 35 36 #if !defined(QT_NO_STATUSTIP) 37 # include <QStatusTipEvent> 38 #endif 39 40 #ifndef HANDHELD 41 // Eyecandy 42 # include "qtwin.h" 43 #endif // HANDHELD 25 44 26 45 /*! -
src/tspmodel.cpp
r7a39458d16 r07e43cf61a 24 24 #include "tspmodel.h" 25 25 26 #include <QApplication> 27 #include <QFile> 28 #include <QMessageBox> 29 #include <QSettings> 30 #include <QtCore/qmath.h> 31 32 #include "tspsolver.h" 33 #include "os.h" 34 26 35 /*! 27 36 * \brief Class constructor. … … 29 38 */ 30 39 CTSPModel::CTSPModel(QObject *parent) 31 : QAbstractTableModel(parent), nCities(0) 32 { 33 settings = initSettings(this); 34 } 40 : QAbstractTableModel(parent), settings(initSettings(this)), nCities(0) {} 35 41 36 42 /*! -
src/tspmodel.h
r7a39458d16 r07e43cf61a 30 30 31 31 #include "globals.h" 32 33 #include <QAbstractTableModel> 34 #include <QDataStream> 35 #include <QVector> 32 36 33 37 /*! -
src/tspsolver.cpp
r7a39458d16 r07e43cf61a 23 23 24 24 #include "tspsolver.h" 25 26 #include <QCoreApplication> 27 28 #ifdef DEBUG 29 # include <QDebug> 30 #endif 25 31 26 32 //! \internal \brief A short for maximum double, used internally in the solution algorithm. -
src/tspsolver.h
r7a39458d16 r07e43cf61a 29 29 #define TSPSOLVER_H 30 30 31 #include <QtCore>32 31 #include <limits> 32 33 #include <QHash> 34 #include <QMutex> 35 #include <QObject> 36 #include <QStringList> 33 37 34 38 /*!
Note: See TracChangeset
for help on using the changeset viewer.