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


Ignore:
Timestamp:
Jul 16, 2009, 6:00:27 PM (15 years ago)
Author:
laleppa
Message:

+ Task save prompt before creating or opening task and closing application if current task was modified.

  • Translation updates.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mainwindow.cpp

    r33 r37  
    4545        connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool)));
    4646        connect(groupSettingsLanguageList,SIGNAL(triggered(QAction *)),this,SLOT(groupSettingsLanguageListTriggered(QAction *)));
     47        connect(actionHelpAboutQt,SIGNAL(triggered()),qApp,SLOT(aboutQt()));
    4748        connect(actionHelpAbout,SIGNAL(triggered()),this,SLOT(actionHelpAboutTriggered()));
    4849#ifndef Q_OS_WINCE
     
    7879        taskView->setModel(tspmodel);
    7980        connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int)));
     81        connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged()));
     82        connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged()));
    8083#ifdef Q_OS_WINCE
    8184        taskView->resizeColumnsToContents();
     
    149152void MainWindow::actionFileNewTriggered()
    150153{
     154        if (isWindowModified()) {
     155int res = QMessageBox(QMessageBox::Warning,trUtf8("New Task"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,this).exec();
     156                if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask()))
     157                        return;
     158        }
    151159        tspmodel->clear();
     160        setWindowModified(false);
    152161}
    153162
    154163void MainWindow::actionFileOpenTriggered()
    155164{
     165        if (isWindowModified()) {
     166int res = QMessageBox(QMessageBox::Warning,trUtf8("Task Open"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,this).exec();
     167                if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask()))
     168                        return;
     169        }
    156170QFileDialog od(this);
    157171        od.setAcceptMode(QFileDialog::AcceptOpen);
     
    168182                return;
    169183        tspmodel->loadTask(files.first());
     184        setWindowModified(false);
    170185}
    171186
    172187void MainWindow::actionFileSaveTaskTriggered()
    173188{
     189        saveTask();
     190}
     191
     192bool MainWindow::saveTask() {
    174193QFileDialog sd(this);
    175194        sd.setAcceptMode(QFileDialog::AcceptSave);
     
    179198        sd.setDefaultSuffix("tspt");
    180199        if (sd.exec() != QDialog::Accepted)
    181                 return;
     200                return false;
    182201QStringList files = sd.selectedFiles();
    183202        if (files.size() < 1)
    184                 return;
    185         tspmodel->saveTask(files.first());
     203                return false;
     204        if (tspmodel->saveTask(files.first())) {
     205                setWindowModified(false);
     206                return true;
     207        } else
     208                return false;
    186209}
    187210
     
    208231{
    209232        tspmodel->randomize();
     233        setWindowModified(true);
    210234#ifdef Q_OS_WINCE
    211235        taskView->resizeColumnsToContents();
     
    244268QString about = QString::fromUtf8("TSPSG - TSP Solver and Generator\n");
    245269about += QString::fromUtf8("    Copyright (C) 2007-%1 Lёppa <contacts[at]oleksii[dot]name>\n").arg(QDate::currentDate().toString("yyyy"));
    246         about += "Qt library versions:\n";
    247         about += QString::fromUtf8("    OS: %1\n").arg(OS);
     270        about += QString::fromUtf8("Target OS: %1\n").arg(OS);
     271        about += "Qt library:\n";
    248272        about += QString::fromUtf8("    Compile time: %1\n").arg(QT_VERSION_STR);
    249273        about += QString::fromUtf8("    Runtime: %1\n").arg(qVersion());
     
    312336void MainWindow::closeEvent(QCloseEvent *event)
    313337{
     338        if (isWindowModified()) {
     339int res = QMessageBox(QMessageBox::Warning,trUtf8("Application Close"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,this).exec();
     340                if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask())) {
     341                        event->ignore();
     342                        return;
     343                }
     344        }
    314345        settings->setValue("NumCities",spinCities->value());
    315346#ifndef Q_OS_WINCE
     
    328359}
    329360
     361void MainWindow::dataChanged()
     362{
     363        setWindowModified(true);
     364}
     365
    330366void MainWindow::numCitiesChanged(int nCities)
    331367{
Note: See TracChangeset for help on using the changeset viewer.