Changeset 50 in tspsg-svn for trunk/src/mainwindow.cpp


Ignore:
Timestamp:
Aug 3, 2009, 5:15:46 PM (15 years ago)
Author:
laleppa
Message:

+ Implemented File/Save? action.
+ Added "Save Solution" and "Back to Task" buttons to Solution tab for better usability.

  • Increased maximum number of cities to 20. Solving for 18-20 cities is already takes much time, so I thought it doesn't make sense to increase more.
  • Columns and rows are now resized to contents on all platforms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mainwindow.cpp

    r47 r50  
    4646        actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList);
    4747        loadLangList();
    48         spinCities->setValue(settings->value("NumCities",5).toInt());
     48        spinCities->setMaximum(MAX_NUM_CITIES);
    4949        actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty());
    5050        connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered()));
    5151        connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered()));
     52        connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered()));
    5253        connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered()));
    5354        connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered()));
     
    6263        connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked()));
    6364        connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked()));
     65        connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked()));
    6466        connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int)));
     67        setCentralWidget(tabWidget);
    6568QRect rect = geometry();
    66         setCentralWidget(tabWidget);
    6769#ifndef Q_OS_WINCE
    6870        if (settings->value("SavePos",false).toBool()) {
     
    8284        qsrand(QDateTime().currentDateTime().toTime_t());
    8385        tspmodel = new CTSPModel();
    84         tspmodel->setNumCities(spinCities->value());
    85         taskView->setModel(tspmodel);
    8686        connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
    8787        connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged()));
    8888        connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged()));
    89         if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) {
     89        if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1))))
    9090                setFileName(QCoreApplication::arguments().at(1));
    91                 setWindowModified(false);
    92         } else
     91        else {
    9392                setFileName();
    94 #ifdef Q_OS_WINCE
     93                spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt());
     94        }
     95        taskView->setModel(tspmodel);
     96        setWindowModified(false);
    9597        taskView->resizeColumnsToContents();
    9698        taskView->resizeRowsToContents();
    97 #endif // Q_OS_WINCE
    9899}
    99100
    100101void MainWindow::enableSolutionActions(bool enable)
    101102{
     103        buttonSaveSolution->setEnabled(enable);
    102104        actionFileSaveAsSolution->setEnabled(enable);
    103105        solutionText->setEnabled(enable);
     
    173175void MainWindow::spinCitiesValueChanged(int n)
    174176{
    175 #ifdef Q_OS_WINCE
    176177int count = tspmodel->numCities();
    177 #endif // Q_OS_WINCE
    178178        tspmodel->setNumCities(n);
    179 #ifdef Q_OS_WINCE
    180179        if (n > count)
    181180                for (int k = count; k < n; k++) {
     
    183182                        taskView->resizeRowToContents(k);
    184183                }
    185 #endif // Q_OS_WINCE
    186184}
    187185
     
    204202                return;
    205203        tspmodel->clear();
    206 #ifdef Q_OS_WINCE
    207204        taskView->resizeColumnsToContents();
    208205        taskView->resizeRowsToContents();
    209 #endif
    210206        setFileName();
    211207        setWindowModified(false);
     
    238234        }
    239235        setFileName(files.first());
    240 #ifdef Q_OS_WINCE
    241236        taskView->resizeColumnsToContents();
    242237        taskView->resizeRowsToContents();
    243 #endif
    244238        tabWidget->setCurrentIndex(0);
    245239        setWindowModified(false);
     
    247241        enableSolutionActions(false);
    248242        QApplication::restoreOverrideCursor();
     243}
     244
     245void MainWindow::actionFileSaveTriggered()
     246{
     247        if ((fileName == trUtf8("Untitled") + ".tspt") || (!fileName.endsWith(".tspt",Qt::CaseInsensitive)))
     248                saveTask();
     249        else {
     250                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     251                if (tspmodel->saveTask(fileName))
     252                        setWindowModified(false);
     253                QApplication::restoreOverrideCursor();
     254        }
    249255}
    250256
     
    350356        tspmodel->randomize();
    351357        setWindowModified(true);
    352 #ifdef Q_OS_WINCE
    353358        taskView->resizeColumnsToContents();
    354359        taskView->resizeRowsToContents();
    355 #endif // Q_OS_WINCE
     360}
     361
     362void MainWindow::buttonBackToTaskClicked()
     363{
     364        tabWidget->setCurrentIndex(0);
    356365}
    357366
     
    395404        }
    396405CTSPSolver solver;
    397 sStep *root = solver.solve(spinCities->value(),matrix);
     406sStep *root = solver.solve(n,matrix,this);
    398407        if (!root)
    399408                return;
     
    542551void MainWindow::numCitiesChanged(int nCities)
    543552{
     553        blockSignals(true);
    544554        spinCities->setValue(nCities);
    545 }
     555        blockSignals(false);
     556}
Note: See TracChangeset for help on using the changeset viewer.