MCPcopy Create free account
hub / github.com/OpenBoard-org/OpenBoard / importFile

Method importFile

src/document/UBDocumentController.cpp:3195–3261  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3193}
3194
3195void UBDocumentController::importFile()
3196{
3197 UBDocumentManager *docManager = UBDocumentManager::documentManager();
3198
3199 QString defaultPath = UBSettings::settings()->lastImportFilePath->get().toString();
3200 if(defaultPath.isDetached())
3201 defaultPath = UBSettings::settings()->userDocumentDirectory();
3202 QStringList filePaths = QFileDialog::getOpenFileNames(mParentWidget, tr("Open Supported File(s)"),
3203 defaultPath, docManager->importFileFilter());
3204
3205 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
3206 QApplication::processEvents();
3207
3208 //same behavior as with an ubx : if multiples files are imported, we don't change the selection.
3209 bool multipleFilesImported = filePaths.size() > 1;
3210
3211 for (auto& filePath : filePaths)
3212 {
3213 QFileInfo fileInfo(filePath);
3214
3215 if (fileInfo.suffix().toLower() == "ubx")
3216 {
3217 UBApplication::boardController->ClearUndoStack();
3218
3219 UBPersistenceManager::persistenceManager()->createDocumentProxiesStructure(docManager->importUbx(filePath, UBSettings::userDocumentDirectory()), true);
3220 }
3221 else
3222 {
3223 UBSettings::settings()->lastImportFilePath->set(QVariant(fileInfo.absolutePath()));
3224
3225 if (filePath.length() > 0)
3226 {
3227 std::shared_ptr<UBDocumentProxy> createdDocument = nullptr;
3228 QApplication::processEvents();
3229 QFile selectedFile(filePath);
3230
3231 UBDocumentTreeModel *docModel = UBPersistenceManager::persistenceManager()->mDocumentTreeStructureModel;
3232
3233 QModelIndex selectedIndex = firstSelectedTreeIndex();
3234 QString groupName = "";
3235 if (selectedIndex.isValid())
3236 {
3237 groupName = docModel->isCatalog(selectedIndex)
3238 ? docModel->virtualPathForIndex(selectedIndex)
3239 : docModel->virtualDirForIndex(selectedIndex);
3240 }
3241
3242 UBApplication::showMessage(tr("Importing file %1...").arg(fileInfo.baseName()), true);
3243
3244 createdDocument = docManager->importFile(selectedFile, groupName);
3245
3246 if (createdDocument && !multipleFilesImported) {
3247 selectDocument(createdDocument, true, true, true);
3248 pageSelectionChanged();
3249
3250 } else {
3251 UBApplication::showMessage(tr("Failed to import file ... "));
3252 }

Callers

nothing calls this directly

Calls 13

userDocumentDirectoryMethod · 0.80
ClearUndoStackMethod · 0.80
importUbxMethod · 0.80
setMethod · 0.80
isCatalogMethod · 0.80
virtualPathForIndexMethod · 0.80
virtualDirForIndexMethod · 0.80
getMethod · 0.45
importFileFilterMethod · 0.45
sizeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected