| 253 | } |
| 254 | |
| 255 | QString getSaveFileName(QWidget *parent, const QString &caption, const QString &dir, |
| 256 | const QString &filter, |
| 257 | QString *selectedSuffixOut) |
| 258 | { |
| 259 | QString selectedFilter; |
| 260 | QString myDir; |
| 261 | if(dir.isEmpty()) // Default to user documents location |
| 262 | { |
| 263 | myDir = QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation); |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | myDir = dir; |
| 268 | } |
| 269 | /* Directly convert path to native OS path separators */ |
| 270 | QString result = QDir::toNativeSeparators(QFileDialog::getSaveFileName(parent, caption, myDir, filter, &selectedFilter)); |
| 271 | |
| 272 | /* Extract first suffix from filter pattern "Description (*.foo)" or "Description (*.foo *.bar ...) */ |
| 273 | QRegExp filter_re(".* \\(\\*\\.(.*)[ \\)]"); |
| 274 | QString selectedSuffix; |
| 275 | if(filter_re.exactMatch(selectedFilter)) |
| 276 | { |
| 277 | selectedSuffix = filter_re.cap(1); |
| 278 | } |
| 279 | |
| 280 | /* Add suffix if needed */ |
| 281 | QFileInfo info(result); |
| 282 | if(!result.isEmpty()) |
| 283 | { |
| 284 | if(info.suffix().isEmpty() && !selectedSuffix.isEmpty()) |
| 285 | { |
| 286 | /* No suffix specified, add selected suffix */ |
| 287 | if(!result.endsWith(".")) |
| 288 | result.append("."); |
| 289 | result.append(selectedSuffix); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /* Return selected suffix if asked to */ |
| 294 | if(selectedSuffixOut) |
| 295 | { |
| 296 | *selectedSuffixOut = selectedSuffix; |
| 297 | } |
| 298 | return result; |
| 299 | } |
| 300 | |
| 301 | QString getOpenFileName(QWidget *parent, const QString &caption, const QString &dir, |
| 302 | const QString &filter, |
no outgoing calls
no test coverage detected