MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / createMimeDataFromSelection

Method createMimeDataFromSelection

src/Gui/MainWindow.cpp:2341–2427  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2339static QLatin1String _MimeDocObjXFile("application/x-documentobject-x-file");
2340
2341QMimeData* MainWindow::createMimeDataFromSelection() const
2342{
2343 std::vector<App::DocumentObject*> sel;
2344 std::set<App::DocumentObject*> objSet;
2345 for (auto& s : Selection().getCompleteSelection()) {
2346 if (s.pObject && s.pObject->isAttachedToDocument() && objSet.insert(s.pObject).second) {
2347 sel.push_back(s.pObject);
2348 }
2349 }
2350 if (sel.empty()) {
2351 return nullptr;
2352 }
2353
2354 auto all = App::Document::getDependencyList(sel);
2355 if (all.size() > sel.size()) {
2356 DlgObjectSelection dlg(sel, getMainWindow());
2357 if (dlg.exec() != QDialog::Accepted) {
2358 return nullptr;
2359 }
2360 sel = dlg.getSelections();
2361 if (sel.empty()) {
2362 return nullptr;
2363 }
2364 }
2365
2366 std::vector<App::Document*> unsaved;
2367 bool hasXLink = App::PropertyXLink::hasXLink(sel, &unsaved);
2368 if (!unsaved.empty()) {
2369 QMessageBox::critical(
2370 getMainWindow(),
2371 tr("Unsaved document"),
2372 tr("The exported object contains external link. Save the document"
2373 "at least once before exporting.")
2374 );
2375 return nullptr;
2376 }
2377
2378 unsigned int memsize = 1000; // ~ for the meta-information
2379 for (const auto& it : sel) {
2380 memsize += it->getMemSize();
2381 }
2382
2383 // if less than ~10 MB
2384 bool use_buffer = (memsize < 0xA00000);
2385 QByteArray res;
2386 std::string buffer;
2387 if (use_buffer) {
2388 try {
2389 buffer.reserve(memsize);
2390 }
2391 catch (const std::bad_alloc&) {
2392 use_buffer = false;
2393 }
2394 }
2395
2396 WaitCursor wc;
2397 QString mime;
2398 if (use_buffer) {

Callers 1

activatedMethod · 0.45

Calls 15

getCompleteSelectionMethod · 0.80
getSelectionsMethod · 0.80
reserveMethod · 0.80
getMainWindowFunction · 0.70
QByteArrayClass · 0.70
SelectionClass · 0.50
isAttachedToDocumentMethod · 0.45
insertMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected