Changeset 993d5af6f6 in tspsg for src/tspmodel.cpp
- Timestamp:
- Jun 30, 2009, 1:02:31 AM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 2b9257627c
- Parents:
- ac4cb71650
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tspmodel.cpp
rac4cb71650 r993d5af6f6 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
Note: See TracChangeset
for help on using the changeset viewer.