Okular

sourcereference.cpp
1/*
2 SPDX-FileCopyrightText: 2007, 2008 Pino Toscano <pino@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "sourcereference.h"
8#include "sourcereference_p.h"
9
10#include <KLocalizedString>
11#include <QString>
12#include <QUrl>
13
14using namespace Okular;
15
16class SourceReference::Private
17{
18public:
19 Private()
20 : row(0)
21 , column(0)
22 {
23 }
24
25 QString filename;
26 int row;
27 int column;
28};
29
30SourceReference::SourceReference(const QString &fileName, int row, int column)
31 : d(new Private)
32{
33 d->filename = fileName;
34 d->row = row;
35 d->column = column;
36}
37
39{
40 delete d;
41}
42
44{
45 return d->filename;
46}
47
49{
50 return d->row;
51}
52
54{
55 return d->column;
56}
57
58bool Okular::extractLilyPondSourceReference(const QUrl &url, QString *file, int *row, int *col)
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 false;
65 }
66
67 // There can be more, in case the filename contains :
68 if (url.fileName().count(QLatin1Char(':')) < 3) {
69 return false;
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 false;
80 }
81
82 *col = parts.takeLast().toInt(&ok);
83 if (!ok) {
84 return false;
85 }
86
87 *row = parts.takeLast().toInt(&ok);
88 if (!ok) {
89 return false;
90 }
91
92 // In case the path itself contains :, we need to reconstruct it after removing all the numbers
93 *file = parts.join(QLatin1Char(':'));
94 return (!file->isEmpty());
95}
96
97QString Okular::sourceReferenceToolTip(const QString &source, int row, int col)
98{
99 Q_UNUSED(row);
100 Q_UNUSED(col);
101 return i18nc("'source' is a source file", "Source: %1", source);
102}
int column() const
Returns the column of the position in the source file.
int row() const
Returns the row of the position in the source file.
QString fileName() const
Returns the filename of the source.
~SourceReference()
Destroys the source reference.
SourceReference(const QString &fileName, int row, int column=0)
Creates a reference to the row row and column column of the source fileName.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
global.h
Definition action.h:17
qsizetype count() const const
bool isEmpty() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
QString fileName(ComponentFormattingOptions options) const const
QString path(ComponentFormattingOptions options) const const
QString scheme() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.