Changeset 99 in tspsg-svn for trunk/src/tspmodel.cpp


Ignore:
Timestamp:
Mar 22, 2010, 9:45:16 PM (15 years ago)
Author:
laleppa
Message:
  • Fixed a bug when a solution couldn't be found for some tasks while the task had at least one solution (mostly, tasks with a lot of restrictions).
  • Fixed a bug when Save As dialog always appeared (even for non-Untitled files) when selecting Save in Unsaved Changes dialog.
  • Improved the solution algorithm.
  • Moved progress dialog from CTSPSolver to MainWindow?. CTSPSolver doesn't contain any GUI related code now.

+ Added routePartFound() signal to CTSPSolver which is emitted once every time a part of the route is found.
+ Added cancel() slot and wasCanceled() public function to CTSPSolver to be able to cancel a solution process and to know whether it was canceled.
+ Progress is now shown when generating a solution output.
+ Check for updates functionality (only in Windows version at this moment).

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        11*.idb
        2 *.ini
        32*.ncb
        43*.pdb
  • trunk/src/tspmodel.cpp

    r95 r99  
    8181        } else if (role == Qt::DisplayRole || role == Qt::EditRole) {
    8282                if (index.row() < nCities && index.column() < nCities)
    83                         if (table[index.row()][index.column()] == INFINITY)
     83                        if (table.at(index.row()).at(index.column()) == INFINITY)
    8484                                return tr(INFSTR);
    8585                        else
    8686//! \hack HACK: Converting to string to prevent spinbox in edit mode
    87                                 return QVariant(table[index.row()][index.column()]).toString();
     87                                return QVariant(table.at(index.row()).at(index.column())).toString();
    8888                else
    8989                        return QVariant();
     
    139139        if (!f.open(QIODevice::ReadOnly)) {
    140140                QApplication::restoreOverrideCursor();
    141                 QMessageBox(QMessageBox::Critical,tr("Task Load"),QString(tr("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec();
     141                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
     142                QMessageBox::critical(QApplication::activeWindow(), tr("Task Load"), QString(tr("Unable to open task file.\nError: %1")).arg(f.errorString()));
     143                QApplication::restoreOverrideCursor();
    142144                return false;
    143145        }
     
    163165                f.close();
    164166                QApplication::restoreOverrideCursor();
    165                 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unknown file format or file is corrupted."),QMessageBox::Ok).exec();
     167                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
     168                QMessageBox::critical(QApplication::activeWindow(), tr("Task Load"), tr("Unable to load task:") + "\n" + tr("Unknown file format or file is corrupted."));
     169                QApplication::restoreOverrideCursor();
    166170                return false;
    167171        }
     
    232236        if (!f.open(QIODevice::WriteOnly)) {
    233237                QApplication::restoreOverrideCursor();
    234                 QMessageBox(QMessageBox::Critical,tr("Task Save"),QString(tr("Unable to create task file.\nError: %1\nMaybe, file is read-only?")).arg(f.errorString()),QMessageBox::Ok).exec();
     238                QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), QString(tr("Unable to create task file.\nError: %1\nMaybe, file is read-only?")).arg(f.errorString()));
     239                f.remove();
    235240                return false;
    236241        }
     
    238243        ds.setVersion(QDataStream::Qt_4_4);
    239244        if (f.error() != QFile::NoError) {
    240                 f.close();
    241                 QApplication::restoreOverrideCursor();
    242                 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
     245                QApplication::restoreOverrideCursor();
     246                QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), tr("Unable to save task.\nError: %1").arg(f.errorString()));
     247                f.close();
     248                f.remove();
    243249                return false;
    244250        }
     
    246252        ds << TSPT;
    247253        if (f.error() != QFile::NoError) {
    248                 f.close();
    249                 QApplication::restoreOverrideCursor();
    250                 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
     254                QApplication::restoreOverrideCursor();
     255                QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), tr("Unable to save task.\nError: %1").arg(f.errorString()));
     256                f.close();
     257                f.remove();
    251258                return false;
    252259        }
     
    254261        ds << TSPT_VERSION;
    255262        if (f.error() != QFile::NoError) {
    256                 f.close();
    257                 QApplication::restoreOverrideCursor();
    258                 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
     263                QApplication::restoreOverrideCursor();
     264                QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), tr("Unable to save task.\nError: %1").arg(f.errorString()));
     265                f.close();
     266                f.remove();
    259267                return false;
    260268        }
     
    262270        ds << TSPT_META_VERSION;
    263271        if (f.error() != QFile::NoError) {
    264                 f.close();
    265                 QApplication::restoreOverrideCursor();
    266                 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
     272                QApplication::restoreOverrideCursor();
     273                QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), tr("Unable to save task.\nError: %1").arg(f.errorString()));
     274                f.close();
     275                f.remove();
    267276                return false;
    268277        }
     
    270279        ds << OSID;
    271280        if (f.error() != QFile::NoError) {
    272                 f.close();
    273                 QApplication::restoreOverrideCursor();
    274                 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
     281                QApplication::restoreOverrideCursor();
     282                QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), tr("Unable to save task.\nError: %1").arg(f.errorString()));
     283                f.close();
     284                f.remove();
    275285                return false;
    276286        }
     
    278288        ds << nCities;
    279289        if (f.error() != QFile::NoError) {
    280                 f.close();
    281                 QApplication::restoreOverrideCursor();
    282                 QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
     290                QApplication::restoreOverrideCursor();
     291                QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), tr("Unable to save task.\nError: %1").arg(f.errorString()));
     292                f.close();
     293                f.remove();
    283294                return false;
    284295        }
     
    289300                                ds << static_cast<double>(table[r][c]); // We cast to double because double may be float on some platforms and we store double values in file
    290301                                if (f.error() != QFile::NoError) {
     302                                        QApplication::restoreOverrideCursor();
     303                                        QMessageBox::critical(QApplication::activeWindow(), tr("Task Save"), tr("Unable to save task.\nError: %1").arg(f.errorString()));
    291304                                        f.close();
    292                                         QApplication::restoreOverrideCursor();
    293                                         QMessageBox(QMessageBox::Critical,tr("Task Save"),tr("Unable to save task.\nError: %1").arg(f.errorString()),QMessageBox::Ok).exec();
     305                                        f.remove();
    294306                                        return false;
    295307                                }
     
    369381                err = tr("Unknown error.");
    370382        QApplication::restoreOverrideCursor();
    371         QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + err,QMessageBox::Ok).exec();
     383        QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
     384        QMessageBox::critical(QApplication::activeWindow(), tr("Task Load"), tr("Unable to load task:") + "\n" + err);
     385        QApplication::restoreOverrideCursor();
    372386        return true;
    373387}
     
    386400        if (version > TSPT_VERSION) {
    387401                QApplication::restoreOverrideCursor();
    388                 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();
     402                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
     403                QMessageBox::critical(QApplication::activeWindow(), tr("Task Load"), tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."));
     404                QApplication::restoreOverrideCursor();
    389405                return false;
    390406        }
     
    400416        if ((size < 3) || (size > MAX_NUM_CITIES)) {
    401417                QApplication::restoreOverrideCursor();
    402                 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
     418                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
     419                QMessageBox::critical(QApplication::activeWindow(), tr("Task Load"), tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."));
     420                QApplication::restoreOverrideCursor();
    403421                return false;
    404422        }
     
    438456        if (version > ZKT_VERSION) {
    439457                QApplication::restoreOverrideCursor();
    440                 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec();
     458                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
     459                QMessageBox::critical(QApplication::activeWindow(), tr("Task Load"), tr("Unable to load task:") + "\n" + tr("File version is newer than application supports.\nPlease, try to update application."));
     460                QApplication::restoreOverrideCursor();
    441461                return false;
    442462        }
     
    448468        if ((size < 3) || (size > 5)) {
    449469                QApplication::restoreOverrideCursor();
    450                 QMessageBox(QMessageBox::Critical,tr("Task Load"),tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec();
     470                QApplication::setOverrideCursor(QCursor(Qt::ArrowCursor));
     471                QMessageBox::critical(QApplication::activeWindow(), tr("Task Load"), tr("Unable to load task:") + "\n" + tr("Unexpected data read.\nFile is possibly corrupted."));
     472                QApplication::restoreOverrideCursor();
    451473                return false;
    452474        }
Note: See TracChangeset for help on using the changeset viewer.