| 56 | } |
| 57 | |
| 58 | std::optional<SourceReference> Okular::extractLilyPondSourceReference(const QUrl &url) |
| 59 | { |
| 60 | // Example URL is: textedit:///home/foo/bar.ly:42:42:42 |
| 61 | // The three numbers are apparently: line:beginning of column:end of column |
| 62 | |
| 63 | if (url.scheme() != QStringLiteral("textedit")) { |
| 64 | return std::nullopt; |
| 65 | } |
| 66 | |
| 67 | // There can be more, in case the filename contains : |
| 68 | if (url.fileName().count(QLatin1Char(':')) < 3) { |
| 69 | return std::nullopt; |
| 70 | } |
| 71 | |
| 72 | QStringList parts(url.path().split(QLatin1Char(':'))); |
| 73 | |
| 74 | bool ok; |
| 75 | // Take out the things we need |
| 76 | int columnEnd = parts.takeLast().toInt(&ok); // apparently we don't use this |
| 77 | Q_UNUSED(columnEnd); |
| 78 | if (!ok) { |
| 79 | return std::nullopt; |
| 80 | } |
| 81 | |
| 82 | auto column = parts.takeLast().toInt(&ok); |
| 83 | if (!ok) { |
| 84 | return std::nullopt; |
| 85 | } |
| 86 | |
| 87 | auto row = parts.takeLast().toInt(&ok); |
| 88 | if (!ok) { |
| 89 | return std::nullopt; |
| 90 | } |
| 91 | |
| 92 | // In case the path itself contains :, we need to reconstruct it after removing all the numbers |
| 93 | auto fileName = parts.join(QLatin1Char(':')); |
| 94 | if (fileName.isEmpty()) { |
| 95 | return std::nullopt; |
| 96 | } |
| 97 | |
| 98 | return std::make_optional<SourceReference>(fileName, row, column); |
| 99 | } |
| 100 | |
| 101 | QString Okular::sourceReferenceToolTip(const SourceReference &sourceReference) |
| 102 | { |