- Timestamp:
- Aug 3, 2009, 5:15:46 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/resources/tspsg.qrc
r45 r50 3 3 <file>about.bmp</file> 4 4 <file>icon.png</file> 5 <file>icons/back.png</file> 5 6 <file>icons/button_cancel.png</file> 6 7 <file>icons/button_ok.png</file> -
trunk/src/globals.h
r42 r50 38 38 #define DEF_RAND_MIN 1 39 39 #define DEF_RAND_MAX 10 40 #define DEF_NUM_CITIES 5 40 41 #define DEF_OFFSET 100 41 42 #define DEF_FONT_FAMILY "Courier New" … … 56 57 #define ZKT_VERSION quint8(1) 57 58 59 // Maximum available number of cities 60 #define MAX_NUM_CITIES 20 58 61 // This value means infinity :-) 59 62 #ifndef INFINITY … … 63 66 #define INFSTR "---" 64 67 68 // Let's check that default number of cities is sane (<= MAX_NUM_CITIES) 69 #if DEF_NUM_CITIES > MAX_NUM_CITIES 70 #undef DEF_NUM_CITIES 71 #define DEF_NUM_CITIES MAX_NUM_CITIES 72 #endif 73 65 74 #endif // GLOBALS_H -
trunk/src/mainwindow.cpp
r47 r50 46 46 actionSettingsLanguageEnglish->setActionGroup(groupSettingsLanguageList); 47 47 loadLangList(); 48 spinCities->set Value(settings->value("NumCities",5).toInt());48 spinCities->setMaximum(MAX_NUM_CITIES); 49 49 actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty()); 50 50 connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered())); 51 51 connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered())); 52 connect(actionFileSave,SIGNAL(triggered()),this,SLOT(actionFileSaveTriggered())); 52 53 connect(actionFileSaveAsTask,SIGNAL(triggered()),this,SLOT(actionFileSaveAsTaskTriggered())); 53 54 connect(actionFileSaveAsSolution,SIGNAL(triggered()),this,SLOT(actionFileSaveAsSolutionTriggered())); … … 62 63 connect(buttonSolve,SIGNAL(clicked()),this,SLOT(buttonSolveClicked())); 63 64 connect(buttonRandom,SIGNAL(clicked()),this,SLOT(buttonRandomClicked())); 65 connect(buttonBackToTask,SIGNAL(clicked()),this,SLOT(buttonBackToTaskClicked())); 64 66 connect(spinCities,SIGNAL(valueChanged(int)),this,SLOT(spinCitiesValueChanged(int))); 67 setCentralWidget(tabWidget); 65 68 QRect rect = geometry(); 66 setCentralWidget(tabWidget);67 69 #ifndef Q_OS_WINCE 68 70 if (settings->value("SavePos",false).toBool()) { … … 82 84 qsrand(QDateTime().currentDateTime().toTime_t()); 83 85 tspmodel = new CTSPModel(); 84 tspmodel->setNumCities(spinCities->value());85 taskView->setModel(tspmodel);86 86 connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int))); 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) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) {89 if ((QCoreApplication::arguments().count() > 1) && (tspmodel->loadTask(QCoreApplication::arguments().at(1)))) 90 90 setFileName(QCoreApplication::arguments().at(1)); 91 setWindowModified(false); 92 } else 91 else { 93 92 setFileName(); 94 #ifdef Q_OS_WINCE 93 spinCities->setValue(settings->value("NumCities",DEF_NUM_CITIES).toInt()); 94 } 95 taskView->setModel(tspmodel); 96 setWindowModified(false); 95 97 taskView->resizeColumnsToContents(); 96 98 taskView->resizeRowsToContents(); 97 #endif // Q_OS_WINCE98 99 } 99 100 100 101 void MainWindow::enableSolutionActions(bool enable) 101 102 { 103 buttonSaveSolution->setEnabled(enable); 102 104 actionFileSaveAsSolution->setEnabled(enable); 103 105 solutionText->setEnabled(enable); … … 173 175 void MainWindow::spinCitiesValueChanged(int n) 174 176 { 175 #ifdef Q_OS_WINCE176 177 int count = tspmodel->numCities(); 177 #endif // Q_OS_WINCE178 178 tspmodel->setNumCities(n); 179 #ifdef Q_OS_WINCE180 179 if (n > count) 181 180 for (int k = count; k < n; k++) { … … 183 182 taskView->resizeRowToContents(k); 184 183 } 185 #endif // Q_OS_WINCE186 184 } 187 185 … … 204 202 return; 205 203 tspmodel->clear(); 206 #ifdef Q_OS_WINCE207 204 taskView->resizeColumnsToContents(); 208 205 taskView->resizeRowsToContents(); 209 #endif210 206 setFileName(); 211 207 setWindowModified(false); … … 238 234 } 239 235 setFileName(files.first()); 240 #ifdef Q_OS_WINCE241 236 taskView->resizeColumnsToContents(); 242 237 taskView->resizeRowsToContents(); 243 #endif244 238 tabWidget->setCurrentIndex(0); 245 239 setWindowModified(false); … … 247 241 enableSolutionActions(false); 248 242 QApplication::restoreOverrideCursor(); 243 } 244 245 void 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 } 249 255 } 250 256 … … 350 356 tspmodel->randomize(); 351 357 setWindowModified(true); 352 #ifdef Q_OS_WINCE353 358 taskView->resizeColumnsToContents(); 354 359 taskView->resizeRowsToContents(); 355 #endif // Q_OS_WINCE 360 } 361 362 void MainWindow::buttonBackToTaskClicked() 363 { 364 tabWidget->setCurrentIndex(0); 356 365 } 357 366 … … 395 404 } 396 405 CTSPSolver solver; 397 sStep *root = solver.solve( spinCities->value(),matrix);406 sStep *root = solver.solve(n,matrix,this); 398 407 if (!root) 399 408 return; … … 542 551 void MainWindow::numCitiesChanged(int nCities) 543 552 { 553 blockSignals(true); 544 554 spinCities->setValue(nCities); 545 } 555 blockSignals(false); 556 } -
trunk/src/mainwindow.h
r47 r50 46 46 void actionFileNewTriggered(); 47 47 void actionFileOpenTriggered(); 48 void actionFileSaveTriggered(); 48 49 void actionFileSaveAsTaskTriggered(); 49 50 void actionFileSaveAsSolutionTriggered(); … … 58 59 void buttonSolveClicked(); 59 60 void buttonRandomClicked(); 61 void buttonBackToTaskClicked(); 60 62 void spinCitiesValueChanged(int); 61 63 void numCitiesChanged(int); … … 63 65 private: 64 66 QSettings *settings; 67 #ifndef Q_OS_WINCE 65 68 QPrinter *printer; 69 #endif // Q_OS_WINCE 66 70 CTSPModel *tspmodel; 67 71 QString fileName; -
trunk/src/tspmodel.cpp
r49 r50 206 206 if (loadError(ds->status())) 207 207 return false; 208 // Cities number208 // Number of cities 209 209 quint16 size; 210 210 *ds >> size; 211 211 if (loadError(ds->status())) 212 212 return false; 213 if ( size < 3) {213 if ((size < 3) || (size > MAX_NUM_CITIES)) { 214 214 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 215 215 return false; 216 216 } 217 if (nCities != size) 217 if (nCities != size) { 218 setNumCities(size); 218 219 emit numCitiesChanged(size); 219 // Costs 220 } 221 // Travel costs 220 222 for (int r = 0; r < size; r++) 221 223 for (int c = 0; c < size; c++) … … 246 248 return false; 247 249 } 248 // Cities number250 // Number of cities 249 251 quint8 size; 250 252 ds->readRawData(reinterpret_cast<char *>(&size),1); … … 255 257 return false; 256 258 } 257 if (nCities != size) 259 if (nCities != size) { 260 setNumCities(size); 258 261 emit numCitiesChanged(size); 259 // Costs 262 } 263 // Travel costs 260 264 double val; 261 265 for (int r = 0; r < 5; r++) -
trunk/src/tspmodel.h
r47 r50 54 54 quint16 nCities; 55 55 bool loadError(QDataStream::Status); 56 bool loadTSPT(QDataStream *); 56 57 bool loadZKT(QDataStream *); 57 bool loadTSPT(QDataStream *);58 58 int rand(int, int) const; 59 59 }; -
trunk/src/tspsolver.cpp
r42 r50 97 97 for (int r = 0; r < nCities; r++) 98 98 for (int c = 0; c < nCities; c++) 99 if ((matrix[r][c] == 0) && !forbidden.values(r).contains(c)) { 99 // if ((matrix[r][c] == 0) && !forbidden.values(r).contains(c)) { 100 if (matrix[r][c] == 0) { 100 101 sum = findMinInRow(r,matrix,c) + findMinInCol(c,matrix,r); 101 102 if (sum > h) { … … 154 155 int nRow, nCol; 155 156 while (route.size() < nCities) { 156 forbidden.clear();157 // forbidden.clear(); 157 158 step->alts = findCandidate(step->matrix,nRow,nCol,s); 158 159 while (hasSubCycles(nRow,nCol)) { 159 forbidden[nRow] = nCol;160 // forbidden[nRow] = nCol; 160 161 step->matrix[nRow][nCol] = INFINITY; 161 162 step->price += align(step->matrix); … … 204 205 } 205 206 206 pd.reset(); 207 if (!root && !pd.wasCanceled()) { 208 pd.reset(); 209 QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("Unable to find solution.\nMaybe, this task has no solutions."),QMessageBox::Ok,parent).exec(); 210 } 211 207 212 qApp->processEvents(); 208 213 209 if (!root && !pd.wasCanceled()) {210 QMessageBox(QMessageBox::Warning,trUtf8("Solution Result"),trUtf8("This task has no solution."),QMessageBox::Ok,parent).exec();211 }212 213 214 return root; 214 215 } -
trunk/src/tspsolver.h
r46 r50 53 53 sStep *root; 54 54 QHash<int,int> route; 55 QHash<int,int> forbidden;55 // QHash<int,int> forbidden; 56 56 double align(tMatrix &); 57 57 void cleanup(); -
trunk/src/version.h
r45 r50 45 45 #endif // BUILD_NUMBER == 65535 46 46 47 // "Converting" number tostring47 // "Converting" x to quoted string 48 48 #define QUOTE_X(x) #x 49 49 #define QUOTE(x) QUOTE_X(x) -
trunk/ui/mainwindow.ce.ui
r48 r50 10 10 <x>0</x> 11 11 <y>0</y> 12 <width>2 25</width>13 <height>3 22</height>12 <width>247</width> 13 <height>339</height> 14 14 </rect> 15 15 </property> 16 16 <property name="windowTitle"> 17 <string>Travelling Salesman Problem [*]</string>17 <string>Travelling Salesman Problem</string> 18 18 </property> 19 19 <property name="windowIcon"> … … 30 30 <x>9</x> 31 31 <y>9</y> 32 <width>2 07</width>33 <height>2 48</height>32 <width>221</width> 33 <height>261</height> 34 34 </rect> 35 35 </property> … … 112 112 <property name="minimum"> 113 113 <number>3</number> 114 </property>115 <property name="maximum">116 <number>5</number>117 114 </property> 118 115 <property name="value"> … … 220 217 </widget> 221 218 </item> 219 <item> 220 <layout class="QHBoxLayout" name="horizontalLayout"> 221 <item> 222 <widget class="QPushButton" name="buttonSaveSolution"> 223 <property name="enabled"> 224 <bool>false</bool> 225 </property> 226 <property name="cursor"> 227 <cursorShape>PointingHandCursor</cursorShape> 228 </property> 229 <property name="statusTip"> 230 <string>Save solution to a file</string> 231 </property> 232 <property name="text"> 233 <string>Save Solution</string> 234 </property> 235 <property name="icon"> 236 <iconset resource="../resources/tspsg.qrc"> 237 <normaloff>:/images/icons/filesaveas.png</normaloff>:/images/icons/filesaveas.png</iconset> 238 </property> 239 </widget> 240 </item> 241 <item> 242 <spacer name="horizontalSpacer"> 243 <property name="orientation"> 244 <enum>Qt::Horizontal</enum> 245 </property> 246 <property name="sizeHint" stdset="0"> 247 <size> 248 <width>40</width> 249 <height>20</height> 250 </size> 251 </property> 252 </spacer> 253 </item> 254 <item> 255 <widget class="QPushButton" name="buttonBackToTask"> 256 <property name="cursor"> 257 <cursorShape>PointingHandCursor</cursorShape> 258 </property> 259 <property name="statusTip"> 260 <string>Go back to Task tab</string> 261 </property> 262 <property name="text"> 263 <string>Back to Task</string> 264 </property> 265 <property name="icon"> 266 <iconset resource="../resources/tspsg.qrc"> 267 <normaloff>:/images/icons/back.png</normaloff>:/images/icons/back.png</iconset> 268 </property> 269 </widget> 270 </item> 271 </layout> 272 </item> 222 273 </layout> 223 274 </widget> … … 229 280 <x>0</x> 230 281 <y>0</y> 231 <width>2 25</width>282 <width>247</width> 232 283 <height>22</height> 233 284 </rect> … … 247 298 </property> 248 299 <property name="title"> 249 <string>Save &As ...</string>300 <string>Save &As</string> 250 301 </property> 251 302 <property name="icon"> … … 363 414 </property> 364 415 <property name="statusTip"> 365 <string>Save solution steps and graph</string>416 <string>Save solution to a file</string> 366 417 </property> 367 418 </action> … … 437 488 <string>Open help contents</string> 438 489 </property> 490 <property name="shortcut"> 491 <string>Ctrl+F1</string> 492 </property> 439 493 </action> 440 494 <action name="actionHelpContextual"> … … 452 506 <string>Open context help</string> 453 507 </property> 508 <property name="shortcut"> 509 <string>F1</string> 510 </property> 454 511 </action> 455 512 <action name="actionHelpAbout"> … … 496 553 <property name="statusTip"> 497 554 <string>Save task to file</string> 498 </property>499 <property name="shortcut">500 <string>Ctrl+S</string>501 555 </property> 502 556 </action> … … 526 580 </property> 527 581 <property name="text"> 582 <string notr="true">&English</string> 583 </property> 584 <property name="iconText"> 528 585 <string notr="true">English</string> 529 586 </property> 530 <property name="iconText">531 <string notr="true">English</string>532 </property>533 587 </action> 534 588 <action name="actionFileSave"> 535 <property name="enabled">536 <bool>false</bool>537 </property>538 589 <property name="icon"> 539 590 <iconset resource="../resources/tspsg.qrc"> … … 548 599 <property name="statusTip"> 549 600 <string>Save current task</string> 601 </property> 602 <property name="shortcut"> 603 <string>Ctrl+S</string> 550 604 </property> 551 605 </action> … … 589 643 </hints> 590 644 </connection> 645 <connection> 646 <sender>buttonBackToTask</sender> 647 <signal>clicked()</signal> 648 <receiver>actionFileSaveAsSolution</receiver> 649 <slot>trigger()</slot> 650 <hints> 651 <hint type="sourcelabel"> 652 <x>172</x> 653 <y>299</y> 654 </hint> 655 <hint type="destinationlabel"> 656 <x>-1</x> 657 <y>-1</y> 658 </hint> 659 </hints> 660 </connection> 591 661 </connections> 592 662 </ui> -
trunk/ui/mainwindow.ui
r48 r50 7 7 <x>0</x> 8 8 <y>0</y> 9 <width> 491</width>10 <height>40 0</height>9 <width>502</width> 10 <height>407</height> 11 11 </rect> 12 12 </property> … … 24 24 <x>0</x> 25 25 <y>0</y> 26 <width> 481</width>27 <height> 311</height>26 <width>287</width> 27 <height>298</height> 28 28 </rect> 29 29 </property> … … 100 100 <property name="minimum"> 101 101 <number>3</number> 102 </property>103 <property name="maximum">104 <number>5</number>105 102 </property> 106 103 <property name="value"> … … 208 205 </widget> 209 206 </item> 207 <item> 208 <layout class="QHBoxLayout" name="horizontalLayout"> 209 <item> 210 <widget class="QPushButton" name="buttonSaveSolution"> 211 <property name="enabled"> 212 <bool>false</bool> 213 </property> 214 <property name="cursor"> 215 <cursorShape>PointingHandCursor</cursorShape> 216 </property> 217 <property name="statusTip"> 218 <string>Save solution to a file</string> 219 </property> 220 <property name="text"> 221 <string>Save Solution</string> 222 </property> 223 <property name="icon"> 224 <iconset resource="../resources/tspsg.qrc"> 225 <normaloff>:/images/icons/filesaveas.png</normaloff>:/images/icons/filesaveas.png</iconset> 226 </property> 227 </widget> 228 </item> 229 <item> 230 <spacer name="horizontalSpacer"> 231 <property name="orientation"> 232 <enum>Qt::Horizontal</enum> 233 </property> 234 <property name="sizeHint" stdset="0"> 235 <size> 236 <width>40</width> 237 <height>20</height> 238 </size> 239 </property> 240 </spacer> 241 </item> 242 <item> 243 <widget class="QPushButton" name="buttonBackToTask"> 244 <property name="cursor"> 245 <cursorShape>PointingHandCursor</cursorShape> 246 </property> 247 <property name="statusTip"> 248 <string>Go back to Task tab</string> 249 </property> 250 <property name="text"> 251 <string>Back to Task</string> 252 </property> 253 <property name="icon"> 254 <iconset resource="../resources/tspsg.qrc"> 255 <normaloff>:/images/icons/back.png</normaloff>:/images/icons/back.png</iconset> 256 </property> 257 </widget> 258 </item> 259 </layout> 260 </item> 210 261 </layout> 211 262 </widget> … … 217 268 <x>0</x> 218 269 <y>0</y> 219 <width> 491</width>270 <width>502</width> 220 271 <height>22</height> 221 272 </rect> … … 232 283 <widget class="QMenu" name="menuFileSaveAs"> 233 284 <property name="title"> 234 <string>Save &As ...</string>285 <string>Save &As</string> 235 286 </property> 236 287 <property name="icon"> … … 379 430 <string>&Solution...</string> 380 431 </property> 432 <property name="iconText"> 433 <string>Solution...</string> 434 </property> 381 435 <property name="toolTip"> 382 436 <string>Save solution</string> 383 437 </property> 384 438 <property name="statusTip"> 385 <string>Save solution steps and graph</string>439 <string>Save solution to a file</string> 386 440 </property> 387 441 </action> … … 457 511 <string>Open help contents</string> 458 512 </property> 513 <property name="shortcut"> 514 <string>Ctrl+F1</string> 515 </property> 459 516 </action> 460 517 <action name="actionHelpContextual"> … … 472 529 <string>Open context help</string> 473 530 </property> 531 <property name="shortcut"> 532 <string>F1</string> 533 </property> 474 534 </action> 475 535 <action name="actionHelpAbout"> … … 512 572 <property name="statusTip"> 513 573 <string>Save task to file</string> 514 </property>515 <property name="shortcut">516 <string>Ctrl+S</string>517 574 </property> 518 575 </action> … … 542 599 </property> 543 600 <property name="text"> 601 <string notr="true">&English</string> 602 </property> 603 <property name="iconText"> 544 604 <string notr="true">English</string> 545 605 </property> 546 <property name="iconText">547 <string notr="true">English</string>548 </property>549 606 </action> 550 607 <action name="actionFileSave"> 551 <property name="enabled">552 <bool>false</bool>553 </property>554 608 <property name="icon"> 555 609 <iconset resource="../resources/tspsg.qrc"> … … 567 621 <property name="statusTip"> 568 622 <string>Save current task</string> 623 </property> 624 <property name="shortcut"> 625 <string>Ctrl+S</string> 569 626 </property> 570 627 </action> … … 605 662 </hints> 606 663 </connection> 664 <connection> 665 <sender>buttonSaveSolution</sender> 666 <signal>clicked()</signal> 667 <receiver>actionFileSaveAsSolution</receiver> 668 <slot>trigger()</slot> 669 <hints> 670 <hint type="sourcelabel"> 671 <x>58</x> 672 <y>327</y> 673 </hint> 674 <hint type="destinationlabel"> 675 <x>-1</x> 676 <y>-1</y> 677 </hint> 678 </hints> 679 </connection> 607 680 </connections> 608 681 </ui>
Note: See TracChangeset
for help on using the changeset viewer.