| 301 | } |
| 302 | |
| 303 | QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, |
| 304 | const QString &filter, |
| 305 | QString *selectedSuffixOut) |
| 306 | { |
| 307 | QString selectedFilter; |
| 308 | QString myDir; |
| 309 | if(dir.isEmpty()) // Default to user documents location |
| 310 | { |
| 311 | myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | myDir = dir; |
| 316 | } |
| 317 | /* Directly convert path to native OS path separators */ |
| 318 | QString result = QDir::toNativeSeparators(QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter)); |
| 319 | |
| 320 | /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ |
| 321 | QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); |
| 322 | QString selectedSuffix; |
| 323 | if(filter_re.exactMatch(selectedFilter)) |
| 324 | { |
| 325 | selectedSuffix = filter_re.cap(1); |
| 326 | } |
| 327 | |
| 328 | /* Add suffix if needed */ |
| 329 | QFileInfo info(result); |
| 330 | if(!result.isEmpty()) |
| 331 | { |
| 332 | if(info.suffix().isEmpty() && !selectedSuffix.isEmpty()) |
| 333 | { |
| 334 | /* No suffix specified, add selected suffix */ |
| 335 | if(!result.endsWith(".")) |
| 336 | result.append("."); |
| 337 | result.append(selectedSuffix); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /* Return selected suffix if asked to */ |
| 342 | if(selectedSuffixOut) |
| 343 | { |
| 344 | *selectedSuffixOut = selectedSuffix; |
| 345 | } |
| 346 | return result; |
| 347 | } |
| 348 | |
| 349 | QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, |
| 350 | const QString &filter, |
no outgoing calls
no test coverage detected