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

Method createMimeDataFromSelection

src/Gui/PythonConsole.cpp:1190–1225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1188}
1189
1190QMimeData* PythonConsole::createMimeDataFromSelection() const
1191{
1192 auto mime = new QMimeData();
1193
1194 switch (d->type) {
1195 case PythonConsoleP::Normal: {
1196 const QTextDocumentFragment fragment(textCursor());
1197 mime->setText(fragment.toPlainText());
1198 } break;
1199 case PythonConsoleP::Command: {
1200 QTextCursor cursor = textCursor();
1201 int s = cursor.selectionStart();
1202 int e = cursor.selectionEnd();
1203 QTextBlock b;
1204 QStringList lines;
1205 for (b = document()->begin(); b.isValid(); b = b.next()) {
1206 int pos = b.position();
1207 if (pos >= s && pos <= e) {
1208 if (b.userState() > -1 && b.userState() < pythonSyntax->maximumUserState()) {
1209 lines << stripPromptFrom(b.text());
1210 }
1211 }
1212 }
1213
1214 QString text = lines.join(QLatin1String("\n"));
1215 mime->setText(text);
1216 } break;
1217 case PythonConsoleP::History: {
1218 const QStringList& hist = d->history.values();
1219 QString text = hist.join(QLatin1String("\n"));
1220 mime->setText(text);
1221 } break;
1222 }
1223
1224 return mime;
1225}
1226
1227void PythonConsole::runSourceFromMimeData(const QString& source)
1228{

Callers

nothing calls this directly

Calls 11

stripPromptFromFunction · 0.85
toPlainTextMethod · 0.80
maximumUserStateMethod · 0.80
setTextMethod · 0.45
beginMethod · 0.45
isValidMethod · 0.45
nextMethod · 0.45
positionMethod · 0.45
textMethod · 0.45
joinMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected