Changeset b424a7e320 in tspsg for src/tspmodel.cpp
- Timestamp:
- Aug 2, 2009, 9:47:45 PM (15 years ago)
- Branches:
- 0.1.3.145-beta1-symbian, 0.1.4.170-beta2-bb10, appveyor, imgbot, master, readme
- Children:
- 6b3d3c1bbb
- Parents:
- 9aa0e521ed
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tspmodel.cpp
r9aa0e521ed rb424a7e320 154 154 } 155 155 156 voidCTSPModel::loadTask(QString fname)156 bool CTSPModel::loadTask(QString fname) 157 157 { 158 158 QFile f(fname); 159 159 if (!f.open(QIODevice::ReadOnly)) { 160 160 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),QString(trUtf8("Unable to open task file.\nError: %1")).arg(f.errorString()),QMessageBox::Ok).exec(); 161 return ;161 return false; 162 162 } 163 163 QDataStream ds(&f); … … 166 166 ds >> sig; 167 167 if (loadError(ds.status())) 168 return ;168 return false; 169 169 ds.device()->reset(); 170 170 if (sig == TSPT) 171 loadTSPT(&ds); 171 if (!loadTSPT(&ds)) { 172 f.close(); 173 return false; 174 } 172 175 else if ((sig >> 16) == ZKT) 173 loadZKT(&ds); 174 else 176 if (!loadZKT(&ds)) { 177 f.close(); 178 return false; 179 } 180 else { 175 181 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unknown file format or file is corrupted."),QMessageBox::Ok).exec(); 182 f.close(); 183 return false; 184 } 176 185 f.close(); 177 } 178 179 void CTSPModel::loadTSPT(QDataStream *ds) 186 return true; 187 } 188 189 bool CTSPModel::loadTSPT(QDataStream *ds) 180 190 { 181 191 // Skipping signature 182 192 ds->skipRawData(sizeof(TSPT)); 183 193 if (loadError(ds->status())) 184 return ;194 return false; 185 195 // File version 186 196 quint8 version; 187 197 *ds >> version; 188 198 if (loadError(ds->status())) 189 return ;199 return false; 190 200 if (version > TSPT_VERSION) { 191 201 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 192 return ;202 return false; 193 203 } 194 204 // Skipping metadata 195 205 ds->skipRawData(TSPT_META_SIZE); 196 206 if (loadError(ds->status())) 197 return ;207 return false; 198 208 // Cities number 199 209 quint16 size; 200 210 *ds >> size; 201 211 if (loadError(ds->status())) 202 return ;212 return false; 203 213 if (size < 3) { 204 214 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 205 return ;215 return false; 206 216 } 207 217 if (nCities != size) … … 214 224 if (loadError(ds->status())) { 215 225 clear(); 216 return ;226 return false; 217 227 } 218 228 } 219 229 emit dataChanged(index(0,0),index(nCities - 1,nCities - 1)); 220 } 221 222 void CTSPModel::loadZKT(QDataStream *ds) 230 return true; 231 } 232 233 bool CTSPModel::loadZKT(QDataStream *ds) 223 234 { 224 235 // Skipping signature 225 236 ds->skipRawData(sizeof(ZKT)); 226 237 if (loadError(ds->status())) 227 return ;238 return false; 228 239 // File version 229 240 quint16 version; 230 241 ds->readRawData(reinterpret_cast<char *>(&version),2); 231 242 if (loadError(ds->status())) 232 return ;243 return false; 233 244 if (version > ZKT_VERSION) { 234 245 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("File version is newer than application supports.\nPlease, try to update application."),QMessageBox::Ok).exec(); 235 return ;246 return false; 236 247 } 237 248 // Cities number … … 239 250 ds->readRawData(reinterpret_cast<char *>(&size),1); 240 251 if (loadError(ds->status())) 241 return ;252 return false; 242 253 if ((size < 3) || (size > 5)) { 243 254 QMessageBox(QMessageBox::Critical,trUtf8("Task Load"),trUtf8("Unable to load task:") + "\n" + trUtf8("Unexpected data read.\nFile is possibly corrupted."),QMessageBox::Ok).exec(); 244 return ;255 return false; 245 256 } 246 257 if (nCities != size) … … 254 265 if (loadError(ds->status())) { 255 266 clear(); 256 return ;267 return false; 257 268 } 258 269 table[r][c] = val; … … 261 272 if (loadError(ds->status())) { 262 273 clear(); 263 return ;274 return false; 264 275 } 265 276 } 266 277 emit dataChanged(index(0,0),index(nCities - 1,nCities - 1)); 278 return true; 267 279 } 268 280
Note: See TracChangeset
for help on using the changeset viewer.