Skip to content

Commit 92bf081

Browse files
committed
Compile with Qt6
1 parent a07c384 commit 92bf081

13 files changed

Lines changed: 62 additions & 62 deletions

CloudCompare-PythonRuntime.qrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<file>images/editor/ccPencil.png</file>
2121
<file>images/editor/ccSave.png</file>
2222
<file>images/editor/dbHObjectSymbol.png</file>
23-
<!-- <file>images/editor/dbHObjectSymbolLocked.png</file>-->
23+
<file>images/editor/dbHObjectSymbolLocked.png</file>
2424
<file>images/editor/dbLockSymbol.png</file>
2525
<file>images/editor/smallTrash.png</file>
2626
<file>images/editor/smallValidate.png</file>
1.04 KB
Loading

src/CodeEditor/PythonEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ void PythonEditor::readSettings()
550550
const QByteArray geometry = settings.value("geometry", QByteArray()).toByteArray();
551551
if (geometry.isEmpty())
552552
{
553-
const QRect availableGeometry = QApplication::desktop()->availableGeometry(this);
553+
const QRect availableGeometry = this->screen()->availableGeometry();;
554554
resize(availableGeometry.width() / 3, availableGeometry.height() / 2);
555555
move((availableGeometry.width() - width()) / 2,
556556
(availableGeometry.height() - height()) / 2);

src/PackageManager.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@
1818
#include "PythonInterpreter.h"
1919
#include "Resources.h"
2020

21-
#include <QDialog>
2221
#include <QDir>
2322
#include <QIcon>
2423
#include <QInputDialog>
2524
#include <QMessageBox>
2625
#include <QPlainTextEdit>
2726
#include <QProcess>
28-
#include <QRegExp>
27+
#include <QRegularExpression>
2928
#include <QTableWidgetItem>
30-
#include <QTextCodec>
3129
#include <QtGlobal>
3230

3331
#include <ccLog.h>
@@ -292,12 +290,12 @@ void PackageManager::refreshInstalledPackagesList()
292290
m_pythonProcess->setArguments(arguments);
293291

294292
QEventLoop loop;
295-
QObject::connect(
293+
connect(
296294
m_pythonProcess,
297-
static_cast<void (QProcess::*)(int, QProcess::ExitStatus)>(&QProcess::finished),
295+
&QProcess::finished,
298296
&loop,
299297
&QEventLoop::quit);
300-
QObject::connect(m_pythonProcess, &QProcess::errorOccurred, &loop, &QEventLoop::quit);
298+
connect(m_pythonProcess, &QProcess::errorOccurred, &loop, &QEventLoop::quit);
301299
m_pythonProcess->start(QIODevice::ReadOnly);
302300
if (m_pythonProcess->state() != QProcess::ProcessState::Starting &&
303301
m_pythonProcess->state() != QProcess::ProcessState::Running)
@@ -316,11 +314,11 @@ void PackageManager::refreshInstalledPackagesList()
316314
}
317315

318316
const QString output =
319-
QTextCodec::codecForName("utf-8")->toUnicode(m_pythonProcess->readAllStandardOutput());
317+
QString::fromUtf8(m_pythonProcess->readAllStandardOutput());
320318

321-
const QVector<QStringRef> lines = output.splitRef("\n");
319+
const QStringList lines = output.split("\n");
322320

323-
const QRegExp regex(R"((\S*)(?:\s*)(\S*)(?:\s*)(\S?))");
321+
const QRegularExpression regex(R"((\S*)(?:\s*)(\S*)(?:\s*)(\S?))");
324322

325323
// First line is a header, second is separator
326324
// and last one seems to always be empty
@@ -333,15 +331,15 @@ void PackageManager::refreshInstalledPackagesList()
333331

334332
for (int i{2}; i < lines.size() - 1; ++i)
335333
{
336-
const QStringRef &currentLine = lines[i];
334+
const QString &currentLine = lines[i];
337335

338336
// Do it this way to avoid an extra allocation
339-
int pos = regex.indexIn(currentLine.toString());
340-
if (pos != -1)
337+
const QRegularExpressionMatch match = regex.match(currentLine);
338+
if (match.hasMatch())
341339
{
342340
for (int j = 1; j < 3; ++j)
343341
{
344-
const QString lol = regex.cap(j);
342+
const QString lol = match.captured(j);
345343
auto *thing = new QTableWidgetItem(lol);
346344
if (j != 1)
347345
{
@@ -353,7 +351,7 @@ void PackageManager::refreshInstalledPackagesList()
353351
}
354352

355353
const QString errorOutput =
356-
QTextCodec::codecForName("utf-8")->toUnicode(m_pythonProcess->readAllStandardError());
354+
QString::fromUtf8(m_pythonProcess->readAllStandardError());
357355

358356
if (!errorOutput.isEmpty())
359357
{
@@ -469,13 +467,12 @@ void PackageManager::executeCommand(const QStringList &arguments)
469467
m_outputDialog->clear();
470468
m_pythonProcess->setArguments(arguments);
471469
m_pythonProcess->start(QIODevice::ReadOnly);
472-
QTextCodec *utf8Codec = QTextCodec::codecForName("utf-8");
473470

474471
while (m_pythonProcess->state() != QProcess::ProcessState::NotRunning)
475472
{
476473
if (m_pythonProcess->waitForReadyRead())
477474
{
478-
const QString output = utf8Codec->toUnicode(m_pythonProcess->readAll());
475+
const QString output = QString::fromUtf8(m_pythonProcess->readAll());
479476
m_outputDialog->appendPlainText(output);
480477
QApplication::processEvents();
481478
}

src/PythonConfig.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
#include <QDir>
2323
#include <QMessageBox>
2424
#include <QProcess>
25-
#include <QTextCodec>
2625
#include <QVector>
2726
#include <QtGlobal>
27+
#include <QStringView>
2828

2929
#if !defined(USE_EMBEDDED_MODULES) && defined(Q_OS_WINDOWS)
3030
static QString WindowsBundledSitePackagesPath()
@@ -36,9 +36,9 @@ static QString WindowsBundledSitePackagesPath()
3636

3737
//================================================================================
3838

39-
Version::Version(const QStringRef &versionStr) : Version()
39+
Version::Version(const QString &versionStr) : Version()
4040
{
41-
QVector<QStringRef> parts = versionStr.split('.');
41+
const QStringList parts = versionStr.split('.');
4242
if (parts.size() == 3)
4343
{
4444
major = parts[0].toUInt();
@@ -63,13 +63,12 @@ static Version GetPythonExeVersion(QProcess &pythonProcess)
6363
pythonProcess.start(QIODevice::ReadOnly);
6464
pythonProcess.waitForFinished();
6565

66-
const QString versionStr =
67-
QTextCodec::codecForName("utf-8")->toUnicode(pythonProcess.readAllStandardOutput());
66+
const QString versionStr = QString::fromUtf8(pythonProcess.readAllStandardOutput());
6867

69-
QVector<QStringRef> splits = versionStr.splitRef(" ");
68+
const QStringList splits = versionStr.split(" ");
7069
if (splits.size() == 2 && splits[0].contains("Python"))
7170
{
72-
return Version(splits[1]);
71+
return Version(splits.at(1));
7372
}
7473
return Version{};
7574
}
@@ -113,7 +112,7 @@ PyVenvCfg PyVenvCfg::FromFile(const QString &path)
113112
}
114113
else if (name == "version")
115114
{
116-
cfg.version = Version(QStringRef(&value));
115+
cfg.version = Version(value);
117116
}
118117
}
119118
}
@@ -398,8 +397,7 @@ void PythonConfig::initFromPythonExecutable(const QString &pythonExecutable)
398397
pythonProcess.start(QIODevice::ReadOnly);
399398
pythonProcess.waitForFinished();
400399

401-
const QString result =
402-
QTextCodec::codecForName("utf-8")->toUnicode(pythonProcess.readAllStandardOutput());
400+
const QString result = QString::fromUtf8(pythonProcess.readAllStandardOutput());
403401

404402
QStringList pathsAndHome = result.split('\n');
405403

src/PythonConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct Version
4141
{
4242
}
4343

44-
explicit Version(const QStringRef &versionStr);
44+
explicit Version(const QString &versionStr);
4545

4646
/// Checks whether the Python version number described by
4747
/// this instance is compatible with the Python version the plugin

src/PythonHighlighter.cpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static const QStringList s_Operators = {"=",
5757
"<<"};
5858

5959
// Python braces
60-
static const QStringList s_Braces = {"\\{", "\\}", "\\(", "\\)", R"([)", R"(])"};
60+
static const QStringList s_Braces = {"\\{", "\\}", "\\(", "\\)", R"(\[)", R"(\])"};
6161

6262
QString PythonHighlighter::CodeElementName(PythonHighlighter::CodeElement e)
6363
{
@@ -145,7 +145,7 @@ void PythonHighlighter::initialize()
145145
m_highlightingRules += HighlightingRule(CodeElement::Definition, R"(\bclass\b\s*(\w+))", 1);
146146

147147
// From '#' until a newline
148-
m_highlightingRules += HighlightingRule(CodeElement::Comment, "#[^\\n]*", 0);
148+
m_highlightingRules += HighlightingRule(CodeElement::Comment, "#[^\r\n]*", 0);
149149

150150
// Numeric literals
151151
m_highlightingRules += HighlightingRule(CodeElement::Numbers, "\\b[+-]?[0-9]+[lL]?\\b", 0);
@@ -160,22 +160,18 @@ void PythonHighlighter::highlightPythonBlock(const QString &text)
160160
if (text.isEmpty())
161161
return;
162162

163-
int index = -1;
164-
165163
// Do other syntax formatting
166164
for (const auto &rule : m_highlightingRules)
167165
{
168-
index = rule.pattern.indexIn(text, 0);
169-
170-
// We actually want the index of the nth match
171-
while (index >= 0)
166+
QRegularExpressionMatchIterator i = rule.pattern.globalMatch(text);
167+
while (i.hasNext())
172168
{
173-
index = rule.pattern.pos(rule.matchIndex);
174-
int length = rule.pattern.cap(rule.matchIndex).length();
169+
QRegularExpressionMatch match = i.next();
170+
const int index = match.capturedStart(rule.matchIndex);
171+
const int length = match.captured(rule.matchIndex).length();
175172
if (length > 0)
176173
{
177174
setFormat(index, length, rule.format);
178-
index = rule.pattern.indexIn(text, index + length);
179175
}
180176
}
181177
}
@@ -196,7 +192,7 @@ inside a multi-line string when this function is finished.
196192
*/
197193
bool PythonHighlighter::matchMultiLine(const QString &text, const HighlightingRule &rule)
198194
{
199-
int start, add, end, length;
195+
int start, add, length;
200196

201197
// If inside triple-single quotes, start at 0
202198
if (previousBlockState() == rule.matchIndex)
@@ -207,36 +203,42 @@ bool PythonHighlighter::matchMultiLine(const QString &text, const HighlightingRu
207203
// Otherwise, look for the delimiter on this line
208204
else
209205
{
210-
start = rule.pattern.indexIn(text);
211-
// Move past this match
212-
add = rule.pattern.matchedLength();
206+
QRegularExpressionMatch match = rule.pattern.match(text);
207+
if (match.hasMatch()) {
208+
start = match.capturedStart(0);
209+
add = match.capturedLength(0);
210+
} else {
211+
start = -1;
212+
add = 0;
213+
}
213214
}
214215

215-
// As long as there's a delimiter match on this line...
216216
while (start >= 0)
217217
{
218218
// Look for the ending delimiter
219-
end = rule.pattern.indexIn(text, start + add);
220-
// Ending delimiter on this line?
219+
QRegularExpressionMatch endMatch = rule.pattern.match(text, start + add);
220+
int end = endMatch.hasMatch() ? endMatch.capturedStart(0) : -1;
221+
221222
if (end >= add)
222223
{
223-
length = end - start + add + rule.pattern.matchedLength();
224+
// Ending delimiter on this line
225+
length = end - start + add + endMatch.capturedLength(0);
224226
setCurrentBlockState(0);
225227
}
226-
// No; multi-line string
227228
else
228229
{
230+
// No; multi-line string
229231
setCurrentBlockState(rule.matchIndex);
230232
length = text.length() - start + add;
231233
}
232234

233-
// Apply formatting
234235
setFormat(start, length, rule.format);
235236

236237
// Look for the next match
237-
start = rule.pattern.indexIn(text, start + length);
238+
QRegularExpressionMatch nextMatch = rule.pattern.match(text, start + length);
239+
start = nextMatch.hasMatch() ? nextMatch.capturedStart(0) : -1;
240+
add = nextMatch.hasMatch() ? nextMatch.capturedLength(0) : 0;
238241
}
239242

240-
// Return True if still inside a multi-line string, False otherwise
241243
return currentBlockState() == rule.matchIndex;
242-
}
244+
}

src/PythonHighlighter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#define PYTHON_HIGHLIGHTER_H
2424

2525
#include <QSyntaxHighlighter>
26+
#include <QRegularExpression>
2627

2728
class ColorScheme;
2829

@@ -59,14 +60,14 @@ class PythonHighlighter final : public QSyntaxHighlighter
5960
struct HighlightingRule
6061
{
6162
CodeElement element = CodeElement::End;
62-
QRegExp pattern;
63+
QRegularExpression pattern;
6364
QTextCharFormat format;
6465
int matchIndex = 0;
6566

6667
HighlightingRule() = default;
6768

6869
HighlightingRule(const CodeElement e, const QString &p, const int i)
69-
: element(e), pattern(QRegExp(p)), matchIndex(i)
70+
: element(e), pattern(QRegularExpression(p)), matchIndex(i)
7071
{
7172
}
7273
};

src/PythonInterpreter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <QDir>
2727
#include <QListWidgetItem>
2828
#include <QMessageBox>
29-
#include <QTextCodec>
3029

3130
#include <ccLog.h>
3231

@@ -45,7 +44,7 @@ static py::dict CreateGlobals()
4544
{
4645
py::dict globals;
4746
globals["__name__"] = "__main__";
48-
// Someday we should require pybind11 > 2.6 and use py::detail::ensure_builtins_in_globals ?
47+
// TODO Someday we should require pybind11 > 2.6 and use py::detail::ensure_builtins_in_globals ?
4948
globals["__builtins__"] = PyEval_GetBuiltins();
5049
return globals;
5150
}

src/PythonRepl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void PythonRepl::setupUI()
176176

177177
codeEdit()->installEventFilter(keyPressEater);
178178
codeEdit()->resize(codeEdit()->width(), 20);
179-
codeEdit()->setTabStopWidth(codeEdit()->fontMetrics().width(' ') * 8);
179+
codeEdit()->setTabStopDistance(codeEdit()->fontMetrics().horizontalAdvance(' ') * 8);
180180

181181
QFont font("Monospace");
182182
font.setStyleHint(QFont::TypeWriter);

0 commit comments

Comments
 (0)