- Timestamp:
- Dec 18, 2009, 1:57:39 PM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/globals.h
r67 r78 46 46 //! Default number of cities 47 47 #define DEF_NUM_CITIES 5 48 //! Default value for showing or not solution step matrices 49 #define DEF_SHOW_MATRIX true 50 //! Default value for using or not city limit for showing solution steps matrices 51 #define DEF_USE_SHOW_MATRIX_LIMIT true 52 //! Default maximum number of cities to show solution step matrices 53 #define DEF_SHOW_MATRIX_CITY_LIMIT 15 48 54 //! Default font name 49 55 #define DEF_FONT_FAMILY "Courier New" … … 54 60 55 61 //! Maximum available number of cities 56 #define MAX_NUM_CITIES 3062 #define MAX_NUM_CITIES 50 57 63 //! Maximum allowed value for random generation limits 58 64 #define MAX_RAND_VALUE 1000 -
trunk/src/mainwindow.cpp
r76 r78 47 47 solutionText->setWordWrapMode(QTextOption::WordWrap); 48 48 #ifdef Q_OS_WINCE 49 // A little hack for toolbar icons to have sane size. 50 int s = qMin(QApplication::desktop()->screenGeometry().width(),QApplication::desktop()->screenGeometry().height()); 51 toolBar->setIconSize(QSize(s / 10,s / 10)); 49 // A little hack for toolbar icons to have a sane size. 50 toolBar->setIconSize(QSize(logicalDpiX() / 4, logicalDpiY() / 4)); 52 51 #endif 53 52 #ifndef QT_NO_PRINTER … … 129 128 tabWidget->setCurrentIndex(0); 130 129 solutionText->clear(); 131 enableSolutionActions(false);130 toggleSolutionActions(false); 132 131 QApplication::restoreOverrideCursor(); 133 132 } … … 137 136 if (!maybeSave()) 138 137 return; 139 QFileDialog od(this); 140 od.setAcceptMode(QFileDialog::AcceptOpen); 141 od.setFileMode(QFileDialog::ExistingFile); 138 142 139 QStringList filters(trUtf8("All Supported Formats") + " (*.tspt *.zkt)"); 143 140 filters.append(trUtf8("%1 Task Files").arg("TSPSG") + " (*.tspt)"); 144 141 filters.append(trUtf8("%1 Task Files").arg("ZKomModRd") + " (*.zkt)"); 145 142 filters.append(trUtf8("All Files") + " (*)"); 146 od.setNameFilters(filters); 147 if (od.exec() != QDialog::Accepted) 148 return; 149 QStringList files = od.selectedFiles(); 150 if (files.empty()) 151 return; 152 if (!tspmodel->loadTask(files.first())) 153 return; 154 setFileName(files.first()); 143 144 QString file = QFileDialog::getOpenFileName(this, trUtf8("Task Load"), QString(), filters.join(";;")); 145 if (file.isEmpty() || !QFileInfo(file).isFile()) 146 return; 147 if (!tspmodel->loadTask(file)) 148 return; 149 setFileName(file); 155 150 tabWidget->setCurrentIndex(0); 156 151 setWindowModified(false); 157 152 solutionText->clear(); 158 enableSolutionActions(false);153 toggleSolutionActions(false); 159 154 } 160 155 … … 176 171 { 177 172 static QString selectedFile; 178 if (selectedFile.isEmpty()) 179 #ifndef QT_NO_PRINTER 180 selectedFile = "solution.pdf"; 173 if (selectedFile.isEmpty()) { 174 if (fileName == trUtf8("Untitled") + ".tspt") { 175 #ifndef QT_NO_PRINTER 176 selectedFile = "solution.pdf"; 181 177 #else 182 selectedFile = "solution.html";178 selectedFile = "solution.html"; 183 179 #endif // QT_NO_PRINTER 184 QFileDialog sd(this); 185 sd.setAcceptMode(QFileDialog::AcceptSave); 180 } else { 181 #ifndef QT_NO_PRINTER 182 selectedFile = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".pdf"; 183 #else 184 selectedFile = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".html"; 185 #endif // QT_NO_PRINTER 186 } 187 } 188 186 189 QStringList filters; 187 190 #ifndef QT_NO_PRINTER 188 filters.append(trUtf8("PDF Files") + " (*.pdf)");191 filters.append(trUtf8("PDF Files") + " (*.pdf)"); 189 192 #endif 190 193 filters.append(trUtf8("HTML Files") + " (*.html *.htm)"); … … 193 196 #endif // QT_VERSION >= 0x040500 194 197 filters.append(trUtf8("All Files") + " (*)"); 195 sd.setNameFilters(filters); 196 sd.selectFile(selectedFile); 197 if (sd.exec() != QDialog::Accepted) 198 return; 199 QStringList files = sd.selectedFiles(); 200 if (files.empty()) 201 return; 202 selectedFile = files.first(); 198 199 QString file = QFileDialog::getSaveFileName(this, QString(), selectedFile, filters.join(";;")); 200 if (file.isEmpty()) 201 return; 202 selectedFile = file; 203 203 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 204 204 #ifndef QT_NO_PRINTER … … 302 302 { 303 303 //! \todo TODO: Normal about window :-) 304 QString about = QString::fromUtf8("<b>TSPSG: TSP Solver and Generator</b><br>"); 305 about += QString::fromUtf8(" Version: <b>"BUILD_VERSION"</b><br>"); 306 about += QString::fromUtf8(" Copyright: <b>© 2007-%1 Lёppa</b><br>").arg(QDate::currentDate().toString("yyyy")); 307 about += QString::fromUtf8(" <b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sourceforge.net/</a></b><br>"); 308 about += "<br>"; 304 QString title; 305 #ifdef Q_OS_WINCE 306 title += QString::fromUtf8("<b>TSPSG<br>TSP Solver and Generator</b><br>"); 307 #else 308 title += QString::fromUtf8("<b>TSPSG: TSP Solver and Generator</b><br>"); 309 #endif // Q_OS_WINCE 310 title += QString::fromUtf8("Version: <b>"BUILD_VERSION"</b><br>"); 311 title += QString::fromUtf8("<b>© 2007-%1 Lёppa</b><br>").arg(QDate::currentDate().toString("yyyy")); 312 title += QString::fromUtf8("<b><a href=\"http://tspsg.sourceforge.net/\">http://tspsg.sf.net/</a></b><br>"); 313 QString about; 309 314 about += QString::fromUtf8("Target OS: <b>%1</b><br>").arg(OS); 310 about += "Qt library:<br>"; 315 #ifndef STATIC_BUILD 316 about += "Qt library (shared):<br>"; 311 317 about += QString::fromUtf8(" Build time: <b>%1</b><br>").arg(QT_VERSION_STR); 312 318 about += QString::fromUtf8(" Runtime: <b>%1</b><br>").arg(qVersion()); 319 #else 320 about += QString::fromUtf8("Qt library: <b>%1</b> (static)<br>").arg(QT_VERSION_STR); 321 #endif // STATIC_BUILD 313 322 about += QString::fromUtf8("Built on <b>%1</b> at <b>%2</b><br>").arg(__DATE__).arg(__TIME__); 323 about += "<br>"; 314 324 about += QString::fromUtf8("Id: <b>"VERSIONID"</b><br>"); 315 325 about += QString::fromUtf8("Algorithm: <b>%1</b><br>").arg(CTSPSolver::getVersionId()); … … 329 339 330 340 QDialog *dlg = new QDialog(this); 331 QLabel *lblIcon = new QLabel(dlg); 341 QLabel *lblIcon = new QLabel(dlg), 342 *lblTitle = new QLabel(dlg); 332 343 QTextBrowser *txtAbout = new QTextBrowser(dlg); 333 QVBoxLayout *vb1 = new QVBoxLayout(), 334 *vb2 = new QVBoxLayout(); 344 QVBoxLayout *vb = new QVBoxLayout(); 335 345 QHBoxLayout *hb = new QHBoxLayout(); 336 346 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok, Qt::Horizontal, dlg); 337 347 338 lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(64, Qt::SmoothTransformation)); 339 340 vb1->addWidget(lblIcon); 341 vb1->addStretch(); 348 lblIcon->setPixmap(QPixmap(":/images/tspsg.png").scaledToWidth(logicalDpiX() * 2 / 3, Qt::SmoothTransformation)); 349 lblIcon->setAlignment(Qt::AlignTop); 350 lblTitle->setText(title); 351 352 hb->addWidget(lblIcon); 353 hb->addWidget(lblTitle); 354 hb->addStretch(); 342 355 343 356 // txtAbout->setTextInteractionFlags(txtAbout->textInteractionFlags() ^ Qt::TextEditable); … … 347 360 txtAbout->moveCursor(QTextCursor::Start); 348 361 349 hb->addLayout(vb1); 350 hb->addWidget(txtAbout); 351 352 vb2->addLayout(hb); 353 vb2->addWidget(bb); 354 362 vb->addLayout(hb); 363 vb->addWidget(txtAbout); 364 vb->addWidget(bb); 365 366 dlg->setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint); 355 367 dlg->setWindowTitle(trUtf8("About TSPSG")); 356 dlg->setLayout(vb 2);368 dlg->setLayout(vb); 357 369 358 370 connect(bb, SIGNAL(accepted()), dlg, SLOT(accept())); 359 371 360 dlg->resize(4 75, 350);372 dlg->resize(410, 300); 361 373 dlg->exec(); 362 374 … … 402 414 output.append("<p>" + trUtf8("Variant #%1").arg(spinVariant->value()) + "</p>"); 403 415 output.append("<p>" + trUtf8("Task:") + "</p>"); 404 outputMatrix(matrix, output);416 outputMatrix(matrix, output); 405 417 output.append("<hr>"); 406 418 output.append("<p>" + trUtf8("Solution of Variant #%1 task").arg(spinVariant->value()) + "</p>"); … … 411 423 if (n != spinCities->value()) { 412 424 output.append("<p>" + trUtf8("Step #%1").arg(n++) + "</p>"); 413 outputMatrix(*step, output); 425 if (settings->value("Output/ShowMatrix", DEF_SHOW_MATRIX).toBool() && settings->value("Output/UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT).toBool() && (spinCities->value() <= settings->value("Output/ShowMatrixCitiesLimit", DEF_SHOW_MATRIX_CITY_LIMIT).toInt())) { 426 outputMatrix(*step, output); 427 } 414 428 output.append("<p>" + trUtf8("Selected candidate for branching: %1.").arg(trUtf8("(%1;%2)").arg(step->candidate.nRow + 1).arg(step->candidate.nCol + 1)) + "</p>"); 415 429 if (!step->alts.empty()) { … … 444 458 } 445 459 output.append("<p></p>"); 460 446 461 solutionText->setHtml(output.join("")); 447 462 solutionText->setDocumentTitle(trUtf8("Solution of Variant #%1 task").arg(spinVariant->value())); … … 450 465 solutionText->moveCursor(QTextCursor::End); 451 466 452 enableSolutionActions();467 toggleSolutionActions(); 453 468 tabWidget->setCurrentIndex(1); 454 469 QApplication::restoreOverrideCursor(); … … 515 530 516 531 QMainWindow::closeEvent(ev); 517 }518 519 void MainWindow::enableSolutionActions(bool enable)520 {521 buttonSaveSolution->setEnabled(enable);522 actionFileSaveAsSolution->setEnabled(enable);523 solutionText->setEnabled(enable);524 if (!enable)525 output.clear();526 #ifndef QT_NO_PRINTER527 actionFilePrint->setEnabled(enable);528 actionFilePrintPreview->setEnabled(enable);529 #endif // QT_NO_PRINTER530 532 } 531 533 … … 688 690 689 691 bool MainWindow::saveTask() { 690 QFileDialog sd(this);691 sd.setAcceptMode(QFileDialog::AcceptSave);692 692 QStringList filters(trUtf8("%1 Task File").arg("TSPSG") + " (*.tspt)"); 693 693 filters.append(trUtf8("All Files") + " (*)"); 694 sd.setNameFilters(filters); 695 sd.setDefaultSuffix("tspt"); 696 if (fileName.endsWith(".tspt",Qt::CaseInsensitive)) 697 sd.selectFile(fileName); 694 QString file; 695 if (fileName.endsWith(".tspt", Qt::CaseInsensitive)) 696 file = fileName; 698 697 else 699 sd.selectFile(QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"); 700 if (sd.exec() != QDialog::Accepted) 698 file = QFileInfo(fileName).canonicalPath() + "/" + QFileInfo(fileName).completeBaseName() + ".tspt"; 699 700 file = QFileDialog::getSaveFileName(this, trUtf8("Task Save"), file, filters.join(";;")); 701 if (file.isEmpty()) 701 702 return false; 702 QStringList files = sd.selectedFiles(); 703 if (files.empty()) 704 return false; 705 if (tspmodel->saveTask(files.first())) { 706 setFileName(files.first()); 703 if (tspmodel->saveTask(file)) { 704 setFileName(file); 707 705 setWindowModified(false); 708 706 return true; … … 716 714 setWindowTitle(QString("%1[*] - %2").arg(QFileInfo(fileName).completeBaseName()).arg(trUtf8("Travelling Salesman Problem"))); 717 715 } 716 717 void MainWindow::toggleSolutionActions(bool enable) 718 { 719 buttonSaveSolution->setEnabled(enable); 720 actionFileSaveAsSolution->setEnabled(enable); 721 solutionText->setEnabled(enable); 722 if (!enable) 723 output.clear(); 724 #ifndef QT_NO_PRINTER 725 actionFilePrint->setEnabled(enable); 726 actionFilePrintPreview->setEnabled(enable); 727 #endif // QT_NO_PRINTER 728 } -
trunk/src/mainwindow.h
r74 r78 87 87 88 88 void closeEvent(QCloseEvent *ev); 89 void enableSolutionActions(bool enable = true);90 89 void initDocStyleSheet(); 91 90 void loadLangList(); … … 96 95 bool saveTask(); 97 96 void setFileName(const QString &fileName = trUtf8("Untitled") + ".tspt"); 97 void toggleSolutionActions(bool enable = true); 98 98 }; 99 99 -
trunk/src/settingsdialog.cpp
r67 r78 35 35 setupUi(this); 36 36 // Laying out elements 37 layoutCitiesLimit = new QHBoxLayout(); 38 layoutCitiesLimit->setMargin(0); 39 layoutCitiesLimit->setSpacing(0); 40 layoutCitiesLimit->addSpacing(10); 41 layoutCitiesLimit->addWidget(cbCitiesLimit); 42 layoutCitiesLimit->addWidget(spinCitiesLimit); 43 layoutCitiesLimit->addStretch(); 44 45 buttonBox->button(QDialogButtonBox::Save)->setIcon(QIcon(":/images/icons/button_ok.png")); 46 buttonBox->button(QDialogButtonBox::Save)->setStatusTip(trUtf8("Save new preferences")); 47 buttonBox->button(QDialogButtonBox::Save)->setCursor(QCursor(Qt::PointingHandCursor)); 48 buttonBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":/images/icons/button_cancel.png")); 49 buttonBox->button(QDialogButtonBox::Cancel)->setStatusTip(trUtf8("Close without saving preferences")); 50 buttonBox->button(QDialogButtonBox::Cancel)->setCursor(QCursor(Qt::PointingHandCursor)); 51 37 52 #ifdef Q_OS_WINCE 38 53 // Layout helper elements 39 54 QVBoxLayout *vbox1, *vbox2; 40 55 QHBoxLayout *hbox1, *hbox2; 41 QSpacerItem *spacer;42 56 43 57 labelRandMin->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Preferred); … … 48 62 vbox2->addWidget(groupRandomSettings); 49 63 vbox2->addWidget(groupOutputSettings); 50 spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding); 51 vbox2->addItem(spacer); 64 vbox2->addStretch(); 65 vbox2->addWidget(cbShowMatrix); 66 vbox2->addLayout(layoutCitiesLimit); 52 67 vbox2->addWidget(cbAutosize); 53 68 … … 62 77 hbox2->setSpacing(6); 63 78 hbox2->addWidget(buttonHelp); 64 spacer = new QSpacerItem(0,0,QSizePolicy::Expanding); 65 hbox2->addItem(spacer); 66 hbox2->addWidget(buttonOK); 67 hbox2->addWidget(buttonCancel); 79 hbox2->addStretch(); 80 hbox2->addWidget(buttonBox); 68 81 69 82 // Central layout … … 78 91 QVBoxLayout *vbox1, *vbox2, *vbox3; 79 92 QHBoxLayout *hbox1, *hbox2, *hbox3; 80 QSpacerItem *spacer;81 93 82 94 cbSaveState = new QCheckBox(bgWhite); … … 93 105 imgIcon->setFrameShape(QFrame::Panel); 94 106 imgIcon->setLineWidth(0); 95 imgIcon->setPixmap(QPixmap( QString::fromUtf8(":/images/icons/preferences_system.png")));107 imgIcon->setPixmap(QPixmap(":/images/icons/preferences_system.png")); 96 108 imgIcon->setStyleSheet("background-color: #0080C0;"); 97 109 imgIcon->setAlignment(Qt::AlignCenter); 110 imgIcon->setMinimumWidth(150); 98 111 99 112 labelHint = new QLabel(bgGrey); … … 131 144 hbox2->addWidget(groupRandomSettings); 132 145 hbox2->addWidget(groupOutputSettings); 133 spacer = new QSpacerItem(0,0,QSizePolicy::Expanding); 134 hbox2->addItem(spacer); 146 hbox2->addStretch(); 135 147 136 148 // Top right part (with white bg) 137 149 vbox2 = new QVBoxLayout(bgWhite); 138 spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding); 139 vbox2->addItem(spacer); 150 vbox2->addStretch(); 140 151 vbox2->addLayout(hbox2); 152 vbox2->addWidget(cbShowMatrix); 153 vbox2->addLayout(layoutCitiesLimit); 141 154 vbox2->addWidget(cbAutosize); 142 155 vbox2->addWidget(cbSaveState); 143 spacer = new QSpacerItem(0,0,QSizePolicy::Minimum,QSizePolicy::Expanding); 144 vbox2->addItem(spacer); 156 vbox2->addStretch(); 145 157 146 158 // Bottom part (with grey bg) … … 150 162 hbox3->addWidget(buttonHelp); 151 163 hbox3->addWidget(labelHint); 152 hbox3->addWidget(buttonOK); 153 hbox3->addWidget(buttonCancel); 164 hbox3->addWidget(buttonBox); 154 165 155 166 // Central layout … … 161 172 vbox1->addWidget(bgGrey); 162 173 #endif // Q_OS_WINCE 163 connect(buttonOK,SIGNAL(clicked()),this,SLOT(accept()));164 connect(buttonCancel,SIGNAL(clicked()),this,SLOT(reject()));165 174 connect(spinRandMin,SIGNAL(valueChanged(int)),this,SLOT(spinRandMinValueChanged(int))); 166 175 connect(buttonFont,SIGNAL(clicked()),this,SLOT(buttonFontClicked())); … … 169 178 setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint); 170 179 #ifndef Q_OS_WINCE 171 // Setting initial text of dialog hint label to own status tip 172 // text. 180 // Setting initial text of dialog hint label to own status tip text. 173 181 labelHint->setText(labelHint->statusTip()); 174 182 #endif // Q_OS_WINCE … … 182 190 cbSaveState->setChecked(settings->value("SavePos",false).toBool()); 183 191 #endif // Q_OS_WINCE 192 184 193 settings->beginGroup("Output"); 194 cbShowMatrix->setChecked(settings->value("ShowMatrix", DEF_SHOW_MATRIX).toBool()); 195 cbCitiesLimit->setEnabled(cbShowMatrix->isChecked()); 196 cbCitiesLimit->setChecked(settings->value("UseShowMatrixLimit", DEF_USE_SHOW_MATRIX_LIMIT && cbShowMatrix->isChecked()).toBool()); 197 spinCitiesLimit->setEnabled(cbShowMatrix->isChecked()); 198 spinCitiesLimit->setValue(settings->value("ShowMatrixCitiesLimit", DEF_SHOW_MATRIX_CITY_LIMIT).toInt()); 199 spinCitiesLimit->setMaximum(MAX_NUM_CITIES); 200 185 201 font = settings->value("Font",QFont(DEF_FONT_FAMILY,DEF_FONT_SIZE)).value<QFont>(); 186 202 color = settings->value("Color",DEF_FONT_COLOR).value<QColor>(); 187 203 settings->endGroup(); 204 205 adjustSize(); 188 206 } 189 207 … … 211 229 { 212 230 #ifndef Q_OS_WINCE 213 settings->setValue("SavePos",cbSaveState->isChecked()); 214 #endif // Q_OS_WINCE 215 settings->setValue("Autosize",cbAutosize->isChecked()); 216 settings->setValue("MinCost",spinRandMin->value()); 217 settings->setValue("MaxCost",spinRandMax->value()); 231 settings->setValue("SavePos", cbSaveState->isChecked()); 232 #endif // Q_OS_WINCE 233 settings->setValue("Autosize", cbAutosize->isChecked()); 234 settings->setValue("MinCost", spinRandMin->value()); 235 settings->setValue("MaxCost", spinRandMax->value()); 236 218 237 settings->beginGroup("Output"); 238 settings->setValue("ShowMatrix", cbShowMatrix->isChecked()); 239 settings->setValue("UseShowMatrixLimit", cbShowMatrix->isChecked() && cbCitiesLimit->isChecked()); 240 if (cbCitiesLimit->isChecked()) 241 settings->setValue("ShowMatrixCitiesLimit", spinCitiesLimit->value()); 219 242 if (newFont) 220 settings->setValue("Font", font);243 settings->setValue("Font", font); 221 244 if (newColor) 222 settings->setValue("Color", color);245 settings->setValue("Color", color); 223 246 settings->endGroup(); 224 247 QDialog::accept(); … … 261 284 labelHint->setText(labelHint->statusTip()); 262 285 return true; 263 // Making imgIcon square.264 } else if (ev->type() == QEvent::Show) {265 bool result = QDialog::event(ev);266 if (result)267 imgIcon->setMinimumWidth(imgIcon->height());268 return result;269 286 } else 270 287 return QDialog::event(ev); -
trunk/src/settingsdialog.h
r71 r78 51 51 bool newColor; 52 52 QSettings *settings; 53 QHBoxLayout *layoutCitiesLimit; 53 54 #ifndef Q_OS_WINCE 54 55 QCheckBox *cbSaveState; -
trunk/src/tspsolver.cpp
r77 r78 211 211 void CTSPSolver::cleanup() 212 212 { 213 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 213 214 route.clear(); 214 215 mayNotBeOptimal = false; 215 216 if (root != NULL) 216 217 deleteNode(root); 218 QApplication::restoreOverrideCursor(); 217 219 } 218 220 219 221 void CTSPSolver::deleteNode(SStep *&node) 220 222 { 223 static int x; 224 x++; 225 qDebug() << ">>>" << x; 221 226 if (node->plNode != NULL) 222 227 deleteNode(node->plNode); … … 225 230 delete node; 226 231 node = NULL; 232 qDebug() << "<<<" << x; 233 x--; 227 234 } 228 235
Note: See TracChangeset
for help on using the changeset viewer.