| 1188 | } |
| 1189 | |
| 1190 | QMimeData* 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 | |
| 1227 | void PythonConsole::runSourceFromMimeData(const QString& source) |
| 1228 | { |
nothing calls this directly
no test coverage detected