Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
utils.cpp
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4
#
include
"utils.h"
5
6
#
include
<
QFileInfo
>
7
#
include
<
QFile
>
8
#
include
<
QTextStream
>
9
#
include
<
iostream
>
10
11
QT_BEGIN_NAMESPACE
12
13
using
namespace
Qt::StringLiterals;
14
15
namespace
Utils
{
16
17
void
printErr
(
const
QString &out)
18
{
19
std
::cerr << qPrintable(out) <<
std
::endl;
20
}
21
22
void
printOut
(
const
QString &out)
23
{
24
std
::cout << qPrintable(out) <<
std
::endl;
25
}
26
27
QMultiHash
<
QString
,
QString
>
getIncludeOptions
(
const
QFileInfo &root,
const
QStringList &paths)
28
{
29
QMultiHash<QString, QString> res;
30
const
qsizetype scanRootLen = root.absolutePath().size();
31
for
(
const
QString &fn : paths) {
32
int
offset = 0;
33
int
depth = 0;
34
do
{
35
offset = fn.lastIndexOf(u'/', offset - 1);
36
QString ffn = fn.mid(offset + 1);
37
res.insert(ffn, fn);
38
}
while
(++depth < 3 && offset > scanRootLen);
39
}
40
return
res;
41
}
42
43
QString
getIndentation
(
const
QString &line)
44
{
45
QString indentation;
46
for
(
const
QChar &c : line)
47
if
(c.isSpace())
48
indentation += c;
49
else
50
return
indentation;
51
return
indentation;
52
}
53
54
QStringList
readLines
(
const
QString &filename)
55
{
56
QFile file(filename);
57
if
(!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
58
printErr(
"ltext2id error: failed to open file %1 for reading.\n"_L1
.arg(filename));
59
return
{};
60
}
61
QTextStream in(&file);
62
return
in.readAll().split(
'\n'
);
63
}
64
65
void
writeLines
(
const
QString &filename,
const
QStringList &lines)
66
{
67
QFile file(filename);
68
if
(!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) {
69
printErr(
"ltext2id error: failed to open file %1 for writing.\n"_L1
.arg(filename));
70
return
;
71
}
72
QTextStream out(&file);
73
out << lines.join(
'\n'
);
74
}
75
76
}
// namespace Utils
77
78
QT_END_NAMESPACE
Utils::readLines
QStringList readLines(const QString &filename)
Definition
utils.cpp:54
Utils::printOut
void printOut(const QString &out)
Definition
utils.cpp:22
Utils::printErr
void printErr(const QString &out)
Definition
utils.cpp:17
Utils::writeLines
void writeLines(const QString &filename, const QStringList &lines)
Definition
utils.cpp:65
Utils::getIndentation
QString getIndentation(const QString &line)
Definition
utils.cpp:43
Utils::getIncludeOptions
QMultiHash< QString, QString > getIncludeOptions(const QFileInfo &root, const QStringList &paths)
Definition
utils.cpp:27
qdesigner_internal::Utils
Definition
qdesigner_utils_p.h:526
std
[33]
Definition
src_corelib_tools_qhash.cpp:421
qttools
src
linguist
ltext2id
utils.cpp
Generated on
for Qt by
1.18.0