Changeset 0ac9690913 in tspsg for src


Ignore:
Timestamp:
Dec 7, 2009, 5:06:44 PM (14 years ago)
Author:
Oleksii Serdiuk
Branches:
0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
Children:
a218bf2cb2
Parents:
3b1caa32d0
Message:

+ Toolbar state and position is now saved and restored with Main Window state and position.

  • Made some small improvements to the code.
  • Fixed some errors in the documentation.
  • Made source code more "documentation friendly".
Location:
src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/main.cpp

    r3b1caa32d0 r0ac9690913  
    3333#endif
    3434
     35#ifdef STATIC_BUILD
     36        Q_IMPORT_PLUGIN(qjpeg)
     37        Q_IMPORT_PLUGIN(qsvg)
     38#endif
     39
    3540int main(int argc, char *argv[])
    3641{
  • src/mainwindow.cpp

    r3b1caa32d0 r0ac9690913  
    8383        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
    8484        setCentralWidget(tabWidget);
    85 #ifndef Q_OS_WINCE
    86 QRect rect = geometry();
    87         if (settings->value("SavePos",false).toBool()) {
     85
     86        if (settings->value("SavePos", false).toBool()) {
    8887                // Loading of saved window state
    8988                settings->beginGroup("MainWindow");
    90                 resize(settings->value("Size",size()).toSize());
    91                 move(settings->value("Position",pos()).toPoint());
    92                 if (settings->value("Maximized",false).toBool())
    93                         setWindowState(windowState() | Qt::WindowMaximized);
     89#ifndef Q_OS_WINCE
     90                restoreGeometry(settings->value("Geometry").toByteArray());
     91#endif // Q_OS_WINCE
     92                restoreState(settings->value("State").toByteArray());
    9493                settings->endGroup();
     94#ifndef Q_OS_WINCE
    9595        } else {
    9696                // Centering main window
     97QRect rect = geometry();
    9798                rect.moveCenter(QApplication::desktop()->availableGeometry(this).center());
    9899                setGeometry(rect);
    99         }
    100100#endif // Q_OS_WINCE
     101        }
     102
    101103        qsrand(QDateTime().currentDateTime().toTime_t());
    102         tspmodel = new CTSPModel();
     104        tspmodel = new CTSPModel(this);
    103105        taskView->setModel(tspmodel);
    104106        connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
     
    440442}
    441443
    442 void MainWindow::closeEvent(QCloseEvent *event)
     444void MainWindow::closeEvent(QCloseEvent *ev)
    443445{
    444446        if (!maybeSave()) {
    445                 event->ignore();
    446                 return;
    447         }
    448         settings->setValue("NumCities",spinCities->value());
     447                ev->ignore();
     448                return;
     449        }
     450        settings->setValue("NumCities", spinCities->value());
     451
     452        // Saving Main Window state
     453        if (settings->value("SavePos", false).toBool()) {
     454                settings->beginGroup("MainWindow");
    449455#ifndef Q_OS_WINCE
    450         // Saving windows state
    451         if (settings->value("SavePos",false).toBool()) {
    452                 settings->beginGroup("MainWindow");
    453                 settings->setValue("Maximized",isMaximized());
    454                 if (!isMaximized()) {
    455                         settings->setValue("Size",size());
    456                         settings->setValue("Position",pos());
    457                 }
     456                settings->setValue("Geometry", saveGeometry());
     457#endif // Q_OS_WINCE
     458                settings->setValue("State", saveState());
    458459                settings->endGroup();
    459460        }
    460 #endif // Q_OS_WINCE
    461         QMainWindow::closeEvent(event);
     461
     462        QMainWindow::closeEvent(ev);
    462463}
    463464
     
    520521}
    521522
    522 bool MainWindow::loadLanguage(QString lang)
     523bool MainWindow::loadLanguage(const QString &lang)
    523524{
    524525// i18n
    525526bool ad = false;
    526         if (lang.isEmpty()) {
     527QString lng = lang;
     528        if (lng.isEmpty()) {
    527529                ad = settings->value("Language","").toString().isEmpty();
    528                 lang = settings->value("Language",QLocale::system().name()).toString();
     530                lng = settings->value("Language",QLocale::system().name()).toString();
    529531        }
    530532static QTranslator *qtTranslator; // Qt library translator
     
    541543        }
    542544        translator = new QTranslator();
    543         if (lang.compare("en") && !lang.startsWith("en_")) {
     545        if (lng.compare("en") && !lng.startsWith("en_")) {
    544546                // Trying to load system Qt library translation...
    545                 if (qtTranslator->load("qt_" + lang,QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
     547                if (qtTranslator->load("qt_" + lng,QLibraryInfo::location(QLibraryInfo::TranslationsPath)))
    546548                        qApp->installTranslator(qtTranslator);
    547549                else
    548550                        // No luck. Let's try to load bundled one.
    549                         if (qtTranslator->load("qt_" + lang,PATH_I18N))
     551                        if (qtTranslator->load("qt_" + lng,PATH_I18N))
    550552                                qApp->installTranslator(qtTranslator);
    551553                        else {
     
    555557                        }
    556558                // Now let's load application translation.
    557                 if (translator->load(lang,PATH_I18N))
     559                if (translator->load(lng,PATH_I18N))
    558560                        qApp->installTranslator(translator);
    559561                else {
     
    581583}
    582584
    583 void MainWindow::outputMatrix(tMatrix matrix, QStringList &output, int nRow, int nCol)
     585void MainWindow::outputMatrix(const tMatrix &matrix, QStringList &output, int nRow, int nCol)
    584586{
    585587int n = spinCities->value();
     
    589591                line = "<tr>";
    590592                for (int c = 0; c < n; c++) {
    591                         if (matrix[r][c] == INFINITY)
     593                        if (matrix.at(r).at(c) == INFINITY)
    592594                                line += "<td align=\"center\">"INFSTR"</td>";
    593595                        else if ((r == nRow) && (c == nCol))
    594                                 line += "<td align=\"center\" class=\"selected\">" + QVariant(matrix[r][c]).toString() + "</td>";
     596                                line += "<td align=\"center\" class=\"selected\">" + QVariant(matrix.at(r).at(c)).toString() + "</td>";
    595597                        else
    596                                 line += "<td align=\"center\">" + QVariant(matrix[r][c]).toString() + "</td>";
     598                                line += "<td align=\"center\">" + QVariant(matrix.at(r).at(c)).toString() + "</td>";
    597599                }
    598600                line += "</tr>";
     
    626628}
    627629
    628 void MainWindow::setFileName(QString fileName)
     630void MainWindow::setFileName(const QString &fileName)
    629631{
    630632        this->fileName = fileName;
  • src/mainwindow.h

    r3b1caa32d0 r0ac9690913  
    6060#endif // QT_NO_PRINTER
    6161        void actionSettingsPreferencesTriggered();
    62         void actionSettingsLanguageAutodetectTriggered(bool);
    63         void groupSettingsLanguageListTriggered(QAction *);
     62        void actionSettingsLanguageAutodetectTriggered(bool checked);
     63        void groupSettingsLanguageListTriggered(QAction *action);
    6464        void actionHelpAboutTriggered();
    6565// Buttons
     
    6969
    7070        void dataChanged();
    71         void dataChanged(const QModelIndex &, const QModelIndex &);
    72         void numCitiesChanged(int);
     71        void dataChanged(const QModelIndex &tl, const QModelIndex &br);
     72        void numCitiesChanged(int nCities);
    7373#ifndef QT_NO_PRINTER
    7474        void printPreview(QPrinter *printer);
    7575#endif // QT_NO_PRINTER
    76         void spinCitiesValueChanged(int);
     76        void spinCitiesValueChanged(int nCities);
    7777
    7878private:
     
    8686        CTSPModel *tspmodel;
    8787
    88         void closeEvent(QCloseEvent *);
     88        void closeEvent(QCloseEvent *ev);
    8989        void enableSolutionActions(bool enable = true);
    9090        void initDocStyleSheet();
    9191        void loadLangList();
    92         bool loadLanguage(QString lang = "");
     92        bool loadLanguage(const QString &lang = QString());
    9393        bool maybeSave();
    94         void outputMatrix(tMatrix, QStringList &, int nRow = -1, int nCol = -1);
     94        void outputMatrix(const tMatrix &matrix, QStringList &output, int nRow = -1, int nCol = -1);
    9595        bool saveTask();
    96         void setFileName(QString fileName = trUtf8("Untitled") + ".tspt");
     96        void setFileName(const QString &fileName = trUtf8("Untitled") + ".tspt");
    9797};
    9898
  • src/settingsdialog.h

    r3b1caa32d0 r0ac9690913  
    5757        QFrame *lineVertical;
    5858
    59         bool event(QEvent *);
     59        bool event(QEvent *ev);
    6060#endif // Q_OS_WINCE
    6161
     
    6464        void buttonColorClicked();
    6565        void buttonFontClicked();
    66         void spinRandMinValueChanged(int);
     66        void spinRandMinValueChanged(int val);
    6767};
    6868
  • src/tspmodel.cpp

    r3b1caa32d0 r0ac9690913  
    133133 * \sa saveTask()
    134134 */
    135 bool CTSPModel::loadTask(QString fname)
     135bool CTSPModel::loadTask(const QString &fname)
    136136{
    137137        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     
    220220 * \sa loadTask()
    221221 */
    222 bool CTSPModel::saveTask(QString fname)
     222bool CTSPModel::saveTask(const QString &fname)
    223223{
    224224        QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  • src/tspmodel.h

    r3b1caa32d0 r0ac9690913  
    4242        CTSPModel(QObject *parent = 0);
    4343        void clear();
    44         int columnCount(const QModelIndex &) const;
    45         QVariant data(const QModelIndex &, int) const;
    46         Qt::ItemFlags flags(const QModelIndex &) const;
    47         QVariant headerData(int, Qt::Orientation, int) const;
    48         bool loadTask(QString);
     44        int columnCount(const QModelIndex &parent = QModelIndex()) const;
     45        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
     46        Qt::ItemFlags flags(const QModelIndex &index) const;
     47        QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
     48        bool loadTask(const QString &fname);
    4949        quint16 numCities() const;
    5050        void randomize();
    51         int rowCount(const QModelIndex &) const;
    52         bool saveTask(QString);
    53         bool setData(const QModelIndex &, const QVariant &, int);
    54         void setNumCities(int);
     51        int rowCount(const QModelIndex &parent = QModelIndex()) const;
     52        bool saveTask(const QString &fname);
     53        bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
     54        void setNumCities(int n);
    5555
    5656signals:
  • src/tspsolver.cpp

    r3b1caa32d0 r0ac9690913  
    209209}
    210210
    211 bool CTSPSolver::findCandidate(tMatrix matrix, int &nRow, int &nCol)
     211bool CTSPSolver::findCandidate(const tMatrix &matrix, int &nRow, int &nCol) const
    212212{
    213213        nRow = -1;
     
    232232}
    233233
    234 double CTSPSolver::findMinInCol(int nCol, tMatrix matrix, int exr)
     234double CTSPSolver::findMinInCol(int nCol, const tMatrix &matrix, int exr) const
    235235{
    236236double min = INFINITY;
     
    241241}
    242242
    243 double CTSPSolver::findMinInRow(int nRow, tMatrix matrix, int exc)
     243double CTSPSolver::findMinInRow(int nRow, const tMatrix &matrix, int exc) const
    244244{
    245245double min = INFINITY;
     
    250250}
    251251
    252 bool CTSPSolver::hasSubCycles(int nRow, int nCol)
     252bool CTSPSolver::hasSubCycles(int nRow, int nCol) const
    253253{
    254254        if ((nRow < 0) || (nCol < 0) || route.isEmpty() || !(route.size() < nCities - 1) || !route.contains(nCol))
  • src/tspsolver.h

    r3b1caa32d0 r0ac9690913  
    7676        static QString getVersionId();
    7777        bool isOptimal() const;
    78         sStep *solve(int, tMatrix, QWidget *parent = 0);
     78        sStep *solve(int numCities, tMatrix task, QWidget *parent = 0);
    7979
    8080private:
     
    8585//      QHash<int,int> forbidden;
    8686
    87         double align(tMatrix &);
     87        double align(tMatrix &matrix);
    8888        void cleanup();
    89         bool findCandidate(tMatrix, int &, int &);
    90         double findMinInCol(int, tMatrix, int exr = -1);
    91         double findMinInRow(int, tMatrix, int exc = -1);
    92         bool hasSubCycles(int, int);
    93         void subCol(tMatrix &, int, double);
    94         void subRow(tMatrix &, int, double);
     89        bool findCandidate(const tMatrix &matrix, int &nRow, int &nCol) const;
     90        double findMinInCol(int nCol, const tMatrix &matrix, int exr = -1) const;
     91        double findMinInRow(int nRow, const tMatrix &matrix, int exc = -1) const;
     92        bool hasSubCycles(int nRow, int nCol) const;
     93        void subCol(tMatrix &matrix, int nCol, double val);
     94        void subRow(tMatrix &matrix, int nRow, double val);
    9595};
    9696
  • src/version.h

    r3b1caa32d0 r0ac9690913  
    5757//! Minor version of current TSPSG build
    5858#define BUILD_VERSION_MINOR 1
    59 //! TSPSG release number
     59/*!
     60 * \brief TSPSG release number
     61 *
     62 *  Release number meanings:
     63 *    - 1  --  3: <b>alpha</b> 1 to 3
     64 *    - 4  --  7: <b>beta</b> 1 to 4
     65 *    - 8  -- 10: <b>rc</b> 1 to 3
     66 *    - 11 --  x: <b>release</b> 1 to x-10
     67 */
    6068#define BUILD_RELEASE 2
    6169
     
    6371 * \brief Current TSPSG build number
    6472 *
    65  * This will only change on releases and will be the same as revision number.
    66  *
    67  * Build number meanings:
    68  *   - 1  --  3: <b>alpha</b> 1 to 3
    69  *   - 4  --  7: <b>beta</b> 1 to 4
    70  *   - 8  -- 10: <b>rc</b> 1 to 3
    71  *   - 11 --  x: <b>release</b> 1 to x-10
     73 *  This will only change on releases and will be the same as revision number.
    7274 */
    7375#define BUILD_NUMBER 65535
     
    7779 * \brief TSPSG build status
    7880 *
    79  * Determined based on BUILD_NUMBER.
     81 * Determined based on BUILD_NUMBER and BUILD_RELEASE.
    8082 */
    8183#if BUILD_NUMBER == 65535
    8284        #define BUILD_STATUS (dev build)
    83 #elif BUILD_RELEASE < 4
    84         #define BUILD_STATUS (alpha)
    85 #elif BUILD_RELEASE < 8
    86         #define BUILD_STATUS (beta)
    87 #elif BUILD_RELEASE < 11
    88         #define BUILD_STATUS (rc)
     85#else
     86        #if BUILD_RELEASE < 4
     87                #define BUILD_STATUS (alpha)
     88        #elif BUILD_RELEASE < 8
     89                #define BUILD_STATUS (beta)
     90        #elif BUILD_RELEASE < 11
     91                #define BUILD_STATUS (rc)
     92        #else
     93                #define BUILD_STATUS
     94        #endif
    8995#endif // BUILD_NUMBER == 65535
    9096
Note: See TracChangeset for help on using the changeset viewer.