Changeset 07e43cf61a in tspsg for src/mainwindow.cpp


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").

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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;
Note: See TracChangeset for help on using the changeset viewer.