- Timestamp:
- Jun 30, 2009, 1:02:31 AM (15 years ago)
- Location:
- trunk/src
- Files:
-
- 1 added
- 8 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/globals.h
r30 r31 22 22 */ 23 23 24 #ifndef DEFINES_H25 #define DEFINES_H24 #ifndef GLOBALS_H 25 #define GLOBALS_H 26 26 27 // INCLUDES 28 #include <QtCore> 29 #include <QtGui> 30 31 // OS detection 32 #include "os.h" 33 34 // DEFINES 27 35 // Default values 28 36 #define DEF_RAND_MIN 1 … … 32 40 #define DEF_FONT_SIZE 12 33 41 #define DEF_FONT_COLOR Qt::black 42 43 // TSPSG Task file signature - letters TSPT 44 #define TSPT quint32(0x54535054) 45 // TSPSG Task file version 46 #define TSPT_VERSION quint8(1) 47 // TSPSG Task file metadata version 48 #define TSPT_META_VERSION quint8(1) 49 // TSPSG Task file metadata size in bytes (incl. version) 50 #define TSPT_META_SIZE 2 51 // ZKomModRd Task file signature - letters ZK 52 #define ZKT quint16(0x5A4B) 53 // ZKomModRd Task file version 54 #define ZKT_VERSION quint8(1) 34 55 35 56 // Decided, that static array with 100 of cities maximum hard limit … … 45 66 #define INFSTR "-----" 46 67 47 #endif // DEFINES_H68 #endif // GLOBALS_H -
trunk/src/main.cpp
r29 r31 22 22 */ 23 23 24 #include <QApplication>25 #include <QTranslator>26 #include <QMessageBox>27 24 #include "mainwindow.h" 28 25 -
trunk/src/mainwindow.cpp
r30 r31 22 22 */ 23 23 24 #include <QtGui>25 #ifndef Q_OS_WINCE26 #include <QPrintDialog>27 #endif // Q_OS_WINCE28 24 #include "mainwindow.h" 29 25 … … 44 40 actionSettingsLanguageAutodetect->setChecked(settings->value("Language","").toString().isEmpty()); 45 41 connect(actionFileNew,SIGNAL(triggered()),this,SLOT(actionFileNewTriggered())); 42 connect(actionFileOpen,SIGNAL(triggered()),this,SLOT(actionFileOpenTriggered())); 43 connect(actionFileSaveTask,SIGNAL(triggered()),this,SLOT(actionFileSaveTaskTriggered())); 46 44 connect(actionSettingsPreferences,SIGNAL(triggered()),this,SLOT(actionSettingsPreferencesTriggered())); 47 45 connect(actionSettingsLanguageAutodetect,SIGNAL(triggered(bool)),this,SLOT(actionSettingsLanguageAutodetectTriggered(bool))); … … 79 77 tspmodel->setNumCities(spinCities->value()); 80 78 taskView->setModel(tspmodel); 79 connect(tspmodel,SIGNAL(numCitiesChanged(int)),this,SLOT(numCitiesChanged(int))); 81 80 #ifdef Q_OS_WINCE 82 81 taskView->resizeColumnsToContents(); … … 153 152 } 154 153 154 void MainWindow::actionFileOpenTriggered() 155 { 156 QFileDialog od(this); 157 od.setAcceptMode(QFileDialog::AcceptOpen); 158 od.setFileMode(QFileDialog::ExistingFile); 159 QStringList filters(trUtf8("All Supported Formats") + " (*.tspt *.zkt)"); 160 filters.append(QString(trUtf8("%1 Task Files")).arg("TSPSG") + " (*.tspt)"); 161 filters.append(QString(trUtf8("%1 Task Files")).arg("ZKomModRd") + " (*.zkt)"); 162 filters.append(trUtf8("All Files") + " (*)"); 163 od.setNameFilters(filters); 164 if (od.exec() != QDialog::Accepted) 165 return; 166 QStringList files = od.selectedFiles(); 167 if (files.size() < 1) 168 return; 169 tspmodel->loadTask(files.first()); 170 } 171 172 void MainWindow::actionFileSaveTaskTriggered() 173 { 174 QFileDialog sd(this); 175 sd.setAcceptMode(QFileDialog::AcceptSave); 176 QStringList filters(QString(trUtf8("%1 Task File")).arg("TSPSG") + " (*.tspt)"); 177 filters.append(trUtf8("All Files") + " (*)"); 178 sd.setNameFilters(filters); 179 sd.setDefaultSuffix("tspt"); 180 if (sd.exec() != QDialog::Accepted) 181 return; 182 QStringList files = sd.selectedFiles(); 183 if (files.size() < 1) 184 return; 185 tspmodel->saveTask(files.first()); 186 } 187 155 188 void MainWindow::actionSettingsPreferencesTriggered() 156 189 { … … 209 242 about += QString::fromUtf8(" Copyright (C) 2007-%1 Lёppa <contacts[at]oleksii[dot]name>\n").arg(QDate::currentDate().toString("yyyy")); 210 243 about += "Qt library versions:\n"; 244 about += QString::fromUtf8(" OS: %1\n").arg(OS); 211 245 about += QString::fromUtf8(" Compile time: %1\n").arg(QT_VERSION_STR); 212 246 about += QString::fromUtf8(" Runtime: %1\n").arg(qVersion()); … … 281 315 QMainWindow::closeEvent(event); 282 316 } 317 318 void MainWindow::numCitiesChanged(int nCities) 319 { 320 spinCities->setValue(nCities); 321 } -
trunk/src/mainwindow.h
r30 r31 25 25 #define MAINWINDOW_H 26 26 27 #include <QMainWindow> 28 #include <QSettings> 27 #include "globals.h" 29 28 #ifdef Q_OS_WINCE 30 29 #include "ui_mainwindow.ce.h" … … 41 40 public: 42 41 MainWindow(QWidget *parent = 0); 43 void closeEvent(QCloseEvent * event);42 void closeEvent(QCloseEvent *); 44 43 private slots: 45 44 void actionFileNewTriggered(); 45 void actionFileOpenTriggered(); 46 void actionFileSaveTaskTriggered(); 46 47 void actionSettingsPreferencesTriggered(); 47 void actionSettingsLanguageAutodetectTriggered(bool checked);48 void groupSettingsLanguageListTriggered(QAction * action);48 void actionSettingsLanguageAutodetectTriggered(bool); 49 void groupSettingsLanguageListTriggered(QAction *); 49 50 void actionHelpAboutTriggered(); 50 51 #ifndef Q_OS_WINCE … … 53 54 void buttonSolveClicked(); 54 55 void buttonRandomClicked(); 55 void spinCitiesValueChanged(int n); 56 void spinCitiesValueChanged(int); 57 void numCitiesChanged(int); 56 58 private: 57 59 QSettings *settings; -
trunk/src/settingsdialog.cpp
r24 r31 22 22 */ 23 23 24 #include <QMessageBox>25 #include <QStatusTipEvent>26 #include <QFontDialog>27 #include <QColorDialog>28 #include "defines.h"29 24 #include "settingsdialog.h" 30 25 -
trunk/src/settingsdialog.h
r21 r31 25 25 #define SETTINGSDIALOG_H 26 26 27 #include <QDialog> 28 #include <QSettings> 27 #include "globals.h" 29 28 #ifdef Q_OS_WINCE 30 29 #include "ui_settingsdialog.ce.h" -
trunk/src/tspmodel.cpp
r29 r31 22 22 */ 23 23 24 #include <QtGui>25 24 #include "tspmodel.h" 26 25 … … 109 108 } 110 109 111 intCTSPModel::numCities() const110 quint16 CTSPModel::numCities() const 112 111 { 113 112 return nCities; … … 116 115 void CTSPModel::setNumCities(int n) 117 116 { 118 int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt();119 int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt();117 // int randMin = settings->value("MinCost",DEF_RAND_MIN).toInt(); 118 // int randMax = settings->value("MaxCost",DEF_RAND_MAX).toInt(); 120 119 if (n == nCities) 121 120 return; … … 127 126 table[r][c] = INFINITY; 128 127 else 129 table[r][c] = rand(randMin,randMax);128 table[r][c] = 0; // rand(randMin,randMax); 130 129 } 131 130 for (int r = nCities; r < n; r++) { … … 134 133 table[r][c] = INFINITY; 135 134 else 136 table[r][c] = rand(randMin,randMax);135 table[r][c] = 0; // rand(randMin,randMax); 137 136 } 138 137 } … … 148 147 table[r][c] = 0; 149 148 emit dataChanged(index(0,0),index(nCities - 1,nCities - 1)); 149 } 150 151 void CTSPModel::loadTask(QString fname) 152 { 153 QFile f(fname); 154 f.open(QIODevice::ReadOnly); 155 QDataStream ds(&f); 156 ds.setVersion(QDataStream::Qt_4_4); 157 quint32 sig; 158 ds >> sig; 159 ds.device()->reset(); 160 if (sig == TSPT) 161 loadTSPT(&ds); 162 else if ((sig >> 16) == ZKT) 163 loadZKT(&ds); 164 else 165 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:\nUnknown file format or file is corrupted."),QMessageBox::Ok).exec(); 166 f.close(); 167 } 168 169 void CTSPModel::loadTSPT(QDataStream *ds) 170 { 171 // Skipping signature 172 ds->skipRawData(sizeof(TSPT)); 173 // File version 174 quint8 version; 175 *ds >> version; 176 if (version > TSPT_VERSION) { 177 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:\nFile version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 178 return; 179 } 180 // Skipping metadata 181 ds->skipRawData(TSPT_META_SIZE); 182 // Cities number 183 quint16 size; 184 *ds >> size; 185 if (nCities != size) 186 emit numCitiesChanged(size); 187 // Costs 188 for (int r = 0; r < size; r++) 189 for (int c = 0; c < size; c++) 190 if (r != c) 191 *ds >> table[r][c]; 192 emit dataChanged(index(0,0),index(nCities - 1,nCities - 1)); 193 } 194 195 void CTSPModel::loadZKT(QDataStream *ds) 196 { 197 // Skipping signature 198 ds->skipRawData(sizeof(ZKT)); 199 // File version 200 quint16 version; 201 ds->readRawData(reinterpret_cast<char *>(&version),2); 202 if (version > ZKT_VERSION) { 203 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:\nFile version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 204 return; 205 } 206 // Cities number 207 quint8 size; 208 ds->readRawData(reinterpret_cast<char *>(&size),1); 209 if (nCities != size) 210 emit numCitiesChanged(size); 211 // Costs 212 double val; 213 for (int r = 0; r < size; r++) 214 for (int c = 0; c < size; c++) 215 if (r != c) { 216 ds->readRawData(reinterpret_cast<char *>(&val),8); 217 table[r][c] = val; 218 } else 219 ds->skipRawData(8); 220 emit dataChanged(index(0,0),index(nCities - 1,nCities - 1)); 221 } 222 223 void CTSPModel::saveTask(QString fname) 224 { 225 QFile f(fname); 226 f.open(QIODevice::WriteOnly); 227 QDataStream ds(&f); 228 ds.setVersion(QDataStream::Qt_4_4); 229 // File signature 230 ds << TSPT; 231 // File version 232 ds << TSPT_VERSION; 233 // File metadata version 234 ds << TSPT_META_VERSION; 235 // Metadata 236 ds << OSID; 237 // Number of cities 238 ds << nCities; 239 // Costs 240 for (int r = 0; r < nCities; r++) 241 for (int c = 0; c < nCities; c++) 242 if (r != c) 243 ds << table[r][c]; 244 f.close(); 150 245 } 151 246 -
trunk/src/tspmodel.h
r29 r31 25 25 #define TSPMODEL_H 26 26 27 #include <QAbstractTableModel> 28 #include <QSettings> 29 #include "defines.h" 27 #include "globals.h" 30 28 31 29 class CTSPModel: public QAbstractTableModel … … 40 38 bool setData(const QModelIndex &, const QVariant &, int); 41 39 Qt::ItemFlags flags(const QModelIndex &) const; 42 intnumCities() const;40 quint16 numCities() const; 43 41 void setNumCities(int); 44 42 void clear(); 43 void loadTask(QString); 44 void saveTask(QString); 45 45 void randomize(); 46 signals: 47 void numCitiesChanged(int); 46 48 private: 47 49 QSettings *settings; 48 50 double table[MAX_CITIES][MAX_CITIES]; 49 intnCities;51 quint16 nCities; 50 52 int rand(int, int); 53 void loadZKT(QDataStream *); 54 void loadTSPT(QDataStream *); 51 55 }; 52 56 -
trunk/src/tspsolver.h
r17 r31 25 25 #define TSPSOLVER_H 26 26 27 #include <QtCore>27 #include "globals.h" 28 28 29 29 typedef QList<double *> tMatrix;
Note: See TracChangeset
for help on using the changeset viewer.