Changeset 47 in tspsg-svn for trunk/src/mainwindow.cpp
- Timestamp:
- Aug 2, 2009, 9:47:45 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mainwindow.cpp
r45 r47 87 87 connect(tspmodel,SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),this,SLOT(dataChanged())); 88 88 connect(tspmodel,SIGNAL(layoutChanged()),this,SLOT(dataChanged())); 89 if ( QCoreApplication::arguments().count() > 1) {90 tspmodel->loadTask(QCoreApplication::arguments().at(1));89 if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) { 90 setFileName(QCoreApplication::arguments().at(1)); 91 91 setWindowModified(false); 92 } 92 } else 93 setFileName(); 93 94 #ifdef Q_OS_WINCE 94 95 taskView->resizeColumnsToContents(); … … 164 165 } 165 166 167 void MainWindow::setFileName(QString fileName) 168 { 169 this->fileName = fileName; 170 setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(trUtf8("Travelling Salesman Problem"))); 171 } 172 166 173 void MainWindow::spinCitiesValueChanged(int n) 167 174 { … … 179 186 } 180 187 188 bool MainWindow::maybeSave() 189 { 190 if (!isWindowModified()) 191 return true; 192 int res = QMessageBox(QMessageBox::Warning,trUtf8("Unsaved Changes"),trUtf8("Would you like to save changes in current task?"),QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,this).exec(); 193 if (res == QMessageBox::Save) 194 return saveTask(); 195 else if (res == QMessageBox::Cancel) 196 return false; 197 else 198 return true; 199 } 181 200 182 201 void MainWindow::actionFileNewTriggered() 183 202 { 184 if (isWindowModified()) { 185 int 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(); 186 if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask())) 187 return; 188 } 203 if (!maybeSave()) 204 return; 189 205 tspmodel->clear(); 206 #ifdef Q_OS_WINCE 207 taskView->resizeColumnsToContents(); 208 taskView->resizeRowsToContents(); 209 #endif 210 setFileName(); 190 211 setWindowModified(false); 191 212 tabWidget->setCurrentIndex(0); … … 196 217 void MainWindow::actionFileOpenTriggered() 197 218 { 198 if (isWindowModified()) { 199 int 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(); 200 if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask())) 201 return; 202 } 219 if (!maybeSave()) 220 return; 203 221 QFileDialog od(this); 204 222 od.setAcceptMode(QFileDialog::AcceptOpen); 205 223 od.setFileMode(QFileDialog::ExistingFile); 206 224 QStringList filters(trUtf8("All Supported Formats") + " (*.tspt *.zkt)"); 207 filters.append( QString(trUtf8("%1 Task Files")).arg("TSPSG") + " (*.tspt)");208 filters.append( QString(trUtf8("%1 Task Files")).arg("ZKomModRd") + " (*.zkt)");225 filters.append(trUtf8("%1 Task Files").arg("TSPSG") + " (*.tspt)"); 226 filters.append(trUtf8("%1 Task Files").arg("ZKomModRd") + " (*.zkt)"); 209 227 filters.append(trUtf8("All Files") + " (*)"); 210 228 od.setNameFilters(filters); … … 212 230 return; 213 231 QStringList files = od.selectedFiles(); 214 if (files.size() < 1) 215 return; 216 tspmodel->loadTask(files.first()); 232 if (files.empty()) 233 return; 234 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 235 if (!tspmodel->loadTask(files.first())) { 236 QApplication::restoreOverrideCursor(); 237 return; 238 } 239 setFileName(files.first()); 240 #ifdef Q_OS_WINCE 241 taskView->resizeColumnsToContents(); 242 taskView->resizeRowsToContents(); 243 #endif 244 tabWidget->setCurrentIndex(0); 217 245 setWindowModified(false); 218 246 solutionText->clear(); 219 247 enableSolutionActions(false); 248 QApplication::restoreOverrideCursor(); 220 249 } 221 250 … … 264 293 QFileDialog sd(this); 265 294 sd.setAcceptMode(QFileDialog::AcceptSave); 266 QStringList filters( QString(trUtf8("%1 Task File")).arg("TSPSG") + " (*.tspt)");295 QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)"); 267 296 filters.append(trUtf8("All Files") + " (*)"); 268 297 sd.setNameFilters(filters); 269 298 sd.setDefaultSuffix("tspt"); 299 if (fileName.endsWith(".tspt",Qt::CaseInsensitive)) 300 sd.selectFile(fileName); 301 else 302 sd.selectFile(QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"); 270 303 if (sd.exec() != QDialog::Accepted) 271 304 return false; 272 305 QStringList files = sd.selectedFiles(); 273 if (files. size() < 1)306 if (files.empty()) 274 307 return false; 308 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 275 309 if (tspmodel->saveTask(files.first())) { 310 setFileName(files.first()); 276 311 setWindowModified(false); 312 QApplication::restoreOverrideCursor(); 277 313 return true; 278 } else 279 return false; 314 } 315 QApplication::restoreOverrideCursor(); 316 return false; 280 317 } 281 318 … … 351 388 row.append(tspmodel->index(r,c).data(Qt::UserRole).toDouble(&ok)); 352 389 if (!ok) { 353 QMessageBox(QMessageBox::Critical,trUtf8("Data error"), QString(trUtf8("Error in cell [Row %1; Column %2]: Invalid data format.")).arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec();390 QMessageBox(QMessageBox::Critical,trUtf8("Data error"),trUtf8("Error in cell [Row %1; Column %2]: Invalid data format.").arg(r + 1).arg(c + 1),QMessageBox::Ok,this).exec(); 354 391 return; 355 392 } … … 467 504 return; 468 505 } 506 bool untitled = (fileName == trUtf8("Untitled") + ".tspt"); 469 507 if (loadLanguage(action->data().toString())) { 470 508 settings->setValue("Language",action->data().toString()); 471 509 retranslateUi(this); 510 if (untitled) 511 setFileName(); 472 512 } 473 513 } … … 475 515 void MainWindow::closeEvent(QCloseEvent *event) 476 516 { 477 if (isWindowModified()) { 478 int 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(); 479 if ((res == QMessageBox::Cancel) || ((res == QMessageBox::Yes) && !saveTask())) { 480 event->ignore(); 481 return; 482 } 517 if (!maybeSave()) { 518 event->ignore(); 519 return; 483 520 } 484 521 settings->setValue("NumCities",spinCities->value());
Note: See TracChangeset
for help on using the changeset viewer.