Changeset 07e43cf61a in tspsg


Ignore:
Timestamp:
Oct 5, 2012, 5:30:23 PM (12 years ago)
Author:
Oleksii Serdiuk
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)
Message:

Improved compilation time by about 30%.

By reducing number of includes to only required minimum.

NOTE: Compilation time comparison was done by measuring compilation time
while using only one thread (i.e., "make -j1").

Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/globals.cpp

    r7a39458d16 r07e43cf61a  
    2424#include "globals.h"
    2525
     26#include <QFile>
     27#include <QObject>
     28#include <QSettings>
     29#include <QWidget>
     30
    2631#ifdef Q_OS_WINCE_WM
    2732#   include <shellapi.h>
    2833#endif
     34
     35bool 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}
    2943
    3044QSettings *initSettings(QObject *parent)
  • src/globals.h

    r7a39458d16 r07e43cf61a  
    3030
    3131// INCLUDES
    32 #include <QtCore>
     32#include <QtGlobal>
    3333#if QT_VERSION < QT_VERSION_CHECK(4,5,0)
    3434#   error You are using Qt version < 4.5 but minimum required version is 4.5.0. Compilation aborted.
     
    3939#   define QT_NO_STATUSTIP
    4040#endif
    41 #include <QtGui>
    4241#if defined(QT_NO_SVG) && !defined(NOSVG)
    4342#   define NOSVG
    4443#endif
    45 #if !defined(NOSVG)
    46 #   include <QtSvg>
    47 #endif // NOSVG
    48 #if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
    49 #   include <QtConcurrent>
    50 #   include <QtPrintSupport>
    51 #endif
    5244
    53 #ifndef HANDHELD
    54 #   include "qttoolbardialog.h"
    55 #endif
    56 
    57 // Version info
    58 #include "version.h"
    59 // OS and ARCH detection
    60 #include "os.h"
    6145// TSPSG Defaults
    6246#include "defaults.h"
    63 // TSPSolver
    64 #include "tspsolver.h"
    65 #ifndef HANDHELD
    66     // Eyecandy
    67 #   include "qtwin.h"
    68 #endif // HANDHELD
    6947
    7048// DEFINES
     
    8462/*!
    8563 * \def PATH_DOCS
    86  * \brief Bath to documentation files.
     64 * \brief Path to documentation files.
    8765 */
    8866#ifndef PATH_DOCS
     
    11189#define HQ_FACTOR 2
    11290
    113 // FUNCTIONS
    114 /*!
    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 
    12591/*!
    12692 * \brief Checks whether the updater app is installed/available.
     
    12995 *  On other systems this function always returns \c false.
    13096 */
    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 }
     97bool hasUpdater();
    13998
    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 
     99class QSettings;
     100class QObject;
    156101/*!
    157102 * \brief Creates QSettings instance with TSPSG-specific options.
     
    162107
    163108#ifndef HANDHELD
     109class QWidget;
    164110/*!
    165111 * \brief Enables or disables a mask for the \a widget.
     
    173119
    174120#ifndef DOXYGEN_EXCLUDE
    175 
    176 #ifndef QT_NO_PRINTER
    177     Q_DECLARE_METATYPE(QPrinter::PageSize)
    178     Q_DECLARE_METATYPE(QPrinter::Orientation)
    179 #endif
    180121
    181122#ifdef HANDHELD
  • src/main.cpp

    r7a39458d16 r07e43cf61a  
    2323
    2424#include "mainwindow.h"
     25
     26#include <QDateTime>
     27#include <QFontDatabase>
     28#include <QTextCodec>
     29#include <QTranslator>
     30#include "version.h"
     31
    2532#if QT_VERSION < QT_VERSION_CHECK(4,6,0)
    2633#   ifdef Q_CC_MSVC
  • src/mainwindow.cpp

    r7a39458d16 r07e43cf61a  
    2323
    2424#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
    2581
    2682#ifdef Q_OS_WIN32
     
    3288_C_ _R_ _Y_ _P_ _T_
    3389#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 */
     97inline bool isInteger(double x)
     98{
     99double 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 */
     108inline 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
    34119
    35120/*!
     
    571656#endif
    572657    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());
    574659    about += "<br>";
    575660    about += tr("This program is free software: you can redistribute it and/or modify<br>\n"
     
    738823void MainWindow::buttonSolveClicked()
    739824{
    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;
    744829    for (int r = 0; r < n; r++) {
    745830        row.clear();
     
    784869#endif
    785870
    786 CTSPSolver solver;
     871    TSPSolver::CTSPSolver solver;
    787872    solver.setCleanupOnCancel(false);
    788873    connect(&solver, SIGNAL(routePartFound(int)), &pd, SLOT(setValue(int)));
     
    792877        connect(&solver, SIGNAL(routePartFound(int)), SLOT(solverRoutePartFound(int)));
    793878#endif
    794 SStep *root = solver.solve(n, matrix);
     879    TSPSolver::SStep *root = solver.solve(n, matrix);
    795880#ifdef Q_OS_WIN32
    796881    if (tl != NULL)
     
    821906
    822907#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);
    824909        while (!f.isFinished()) {
    825910            QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
     
    899984    cur.insertHtml("<hr>");
    900985    cur.insertBlock(fmt_paragraph);
    901 int imgpos = cur.position();
     986    int imgpos = cur.position();
    902987    cur.insertText(tr("Variant #%1 Solution").arg(spinVariant->value()), fmt_default);
    903988    cur.endEditBlock();
    904989
    905 SStep *step = root;
    906 int c = n = 1;
     990    TSPSolver::SStep *step = root;
     991    int c = n = 1;
    907992    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())) {
    909994        if (pd.wasCanceled()) {
    910995            pd.setLabelText(tr("Memory cleanup..."));
     
    9181003#endif
    9191004#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);
    9211006            while (!f.isFinished()) {
    9221007                QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
     
    9521037        else
    9531038            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);
    9551040        if (!step->alts.empty()) {
    956             SStep::SCandidate cand;
     1041            TSPSolver::SStep::SCandidate cand;
    9571042            QString alts;
    9581043            foreach(cand, step->alts) {
     
    9741059        n++;
    9751060
    976         if (step->next == SStep::RightBranch) {
     1061        if (step->next == TSPSolver::SStep::RightBranch) {
    9771062            c++;
    9781063            step = step->prNode;
    979         } else if (step->next == SStep::LeftBranch) {
     1064        } else if (step->next == TSPSolver::SStep::LeftBranch) {
    9801065            step = step->plNode;
    9811066        } else
     
    10521137#endif
    10531138#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);
    10551140    while (!f.isFinished()) {
    10561141        QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
     
    12111296}
    12121297
    1213 void MainWindow::drawNode(QPainter &pic, int nstep, bool left, SStep *step)
     1298void MainWindow::drawNode(QPainter &pic, int nstep, bool left, TSPSolver::SStep *step)
    12141299{
    12151300qreal r; // Radius of graph node
     
    12681353        pic.drawLine(QPointF(x, y - r), QPointF(r * 2.25, y - 2 * r));
    12691354    } 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));
    12711356    }
    12721357
     
    15631648}
    15641649
    1565 void MainWindow::outputMatrix(QTextCursor &cur, const TMatrix &matrix)
     1650void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::TMatrix &matrix)
    15661651{
    15671652int n = spinCities->value();
     
    15831668}
    15841669
    1585 void MainWindow::outputMatrix(QTextCursor &cur, const SStep &step)
     1670void MainWindow::outputMatrix(QTextCursor &cur, const TSPSolver::SStep &step)
    15861671{
    15871672int n = spinCities->value();
     
    15971682                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);
    15981683            else {
    1599 SStep::SCandidate cand;
     1684    TSPSolver::SStep::SCandidate cand;
    16001685                cand.nRow = r;
    16011686                cand.nCol = c;
  • src/mainwindow.h

    r7a39458d16 r07e43cf61a  
    3232
    3333#include "ui_mainwindow.h"
    34 #include "settingsdialog.h"
     34#include "tspsolver.h"
    3535
    36 #include "tspmodel.h"
     36#include <QPicture>
    3737
    3838#ifdef Q_OS_WIN32
     
    4141#endif
    4242
    43 using namespace TSPSolver;
     43class CTSPModel;
     44
     45#ifndef HANDHELD
     46    class QtToolbarDialog;
     47    class QtToolBarManager;
     48#endif
     49
     50#ifndef QT_NO_PRINTER
     51    class QPrinter;
     52#endif
    4453
    4554/*!
     
    143152    void closeEvent(QCloseEvent *ev);
    144153    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);
    146155    void dropEvent(QDropEvent *ev);
    147156    QByteArray generateImage(const QString &format);
     
    152161    void loadToolbarList();
    153162    bool maybeSave();
    154     void outputMatrix(QTextCursor &cur, const TMatrix &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);
    156165#ifdef Q_OS_SYMBIAN
    157166    void resizeEvent(QResizeEvent *ev);
     
    166175
    167176#ifdef Q_OS_SYMBIAN
     177#include <QMessageBox>
    168178// A quickly hacked QMessageBox for Symbian that supports three buttons.
    169179class QSMessageBox: public QMessageBox {
  • src/pch.h

    r7a39458d16 r07e43cf61a  
    2727
    2828#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
    3045#endif // __cplusplus
  • src/settingsdialog.cpp

    r7a39458d16 r07e43cf61a  
    2323
    2424#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
    2544
    2645/*!
  • src/tspmodel.cpp

    r7a39458d16 r07e43cf61a  
    2424#include "tspmodel.h"
    2525
     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
    2635/*!
    2736 * \brief Class constructor.
     
    2938 */
    3039CTSPModel::CTSPModel(QObject *parent)
    31     : QAbstractTableModel(parent), nCities(0)
    32 {
    33     settings = initSettings(this);
    34 }
     40    : QAbstractTableModel(parent), settings(initSettings(this)), nCities(0) {}
    3541
    3642/*!
  • src/tspmodel.h

    r7a39458d16 r07e43cf61a  
    3030
    3131#include "globals.h"
     32
     33#include <QAbstractTableModel>
     34#include <QDataStream>
     35#include <QVector>
    3236
    3337/*!
  • src/tspsolver.cpp

    r7a39458d16 r07e43cf61a  
    2323
    2424#include "tspsolver.h"
     25
     26#include <QCoreApplication>
     27
     28#ifdef DEBUG
     29#   include <QDebug>
     30#endif
    2531
    2632//! \internal \brief A short for maximum double, used internally in the solution algorithm.
  • src/tspsolver.h

    r7a39458d16 r07e43cf61a  
    2929#define TSPSOLVER_H
    3030
    31 #include <QtCore>
    3231#include <limits>
     32
     33#include <QHash>
     34#include <QMutex>
     35#include <QObject>
     36#include <QStringList>
    3337
    3438/*!
Note: See TracChangeset for help on using the changeset viewer.