Commit 598a847b authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Make compile with strict flags

parent 57ace239
Pipeline #75317 failed with stage
in 2 minutes and 13 seconds
......@@ -9,7 +9,7 @@ set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_
project(kturtle VERSION ${RELEASE_SERVICE_VERSION})
set(QT_MIN_VERSION "5.15.0")
set(KF5_MIN_VERSION "5.83.0")
set(KF5_MIN_VERSION "5.85.0")
find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
......@@ -47,7 +47,12 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED
#Allows QString concatenation to use a single memory allocation per source line.
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
add_definitions(-DQT_NO_URL_CAST_FROM_STRING)
add_definitions(
-DQT_DISABLE_DEPRECATED_BEFORE=0x050e00
-DQT_DEPRECATED_WARNINGS_SINCE=0x060000
-DKF_DISABLE_DEPRECATED_BEFORE_AND_AT=0x055600
-DKF_DEPRECATED_WARNINGS_SINCE=0x060000
)
add_subdirectory (doc)
add_subdirectory (src)
add_subdirectory (icons)
......
......@@ -114,8 +114,8 @@ void Canvas::drawLine(double x1, double y1, double x2, double y2)
void Canvas::slotClear()
{
QList<QGraphicsItem*> list = _scene->items();
foreach (QGraphicsItem* item, list) {
const QList<QGraphicsItem*> list = _scene->items();
for (QGraphicsItem* item : list) {
// delete all but the turtle (who lives on a separate layer with z-value 1)
if ((item->zValue() != kTurtleZValue) && (item->zValue() != kCanvasFrameZValue))
delete item;
......
......@@ -26,7 +26,7 @@ class Canvas : public QGraphicsView
void saveAsSvg(const QString&, const QString&);
// void scene() { return _scene; }
public slots:
public Q_SLOTS:
void slotClear();
void slotGo(double x, double y) { turtle->setPos(x, y); };
void slotGoX(double x) { turtle->setPos(x, turtle->pos().y()); }
......
......@@ -162,5 +162,5 @@ void ColorPicker::copyProxy()
void ColorPicker::pasteProxy()
{
emit pasteText(resultBox->text());
Q_EMIT pasteText(resultBox->text());
}
......@@ -48,10 +48,10 @@ class ColorPicker : public QDialog
public:
explicit ColorPicker(QWidget* parent = nullptr);
signals:
Q_SIGNALS:
void pasteText(const QString&);
private slots:
private Q_SLOTS:
void updateResult(int r, int g, int b);
void redChanged(int);
void greenChanged(int);
......
......@@ -64,7 +64,7 @@ void Console::clearMarkings()
void Console::run()
{
QString errorMessage = emit execute(comboBox->currentText());
QString errorMessage = Q_EMIT execute(comboBox->currentText());
if (errorMessage.isNull()) {
comboBox->clearEditText();
return;
......@@ -74,7 +74,7 @@ void Console::run()
void Console::showError(const QString& msg)
{
comboBox->setStyleSheet("QComboBox:editable{background:" + ERROR_HIGHLIGHT_COLOR.name() + ";}");
comboBox->setStyleSheet(QStringLiteral("QComboBox:editable{background:") + ERROR_HIGHLIGHT_COLOR.name() + QStringLiteral(";}"));
comboBox->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
QString toolTipText(i18n("<p style='white-space:pre'><b>ERROR:</b> %1</p>", msg));
comboBox->setToolTip(toolTipText);
......@@ -85,6 +85,6 @@ void Console::executeActionTriggered()
QLineEdit* lineEdit = comboBox->lineEdit();
if (!lineEdit)
return;
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, QChar('\n'));
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, QStringLiteral("\n"));
QApplication::sendEvent(lineEdit, &event);
}
......@@ -24,12 +24,12 @@ class Console : public QWidgetAction
void showError(const QString&);
public slots:
public Q_SLOTS:
void run();
void clearMarkings();
void executeActionTriggered();
signals:
Q_SIGNALS:
QString execute(const QString&);
private:
......
......@@ -128,10 +128,10 @@ void DirectionCanvas::mousePressEvent(QMouseEvent *event)
if (event->buttons() & Qt::LeftButton) {
deg = translateMouseCoords(event->x() - (width() / 2), event->y() - (height() / 2));
update();
emit degreeChanged(deg);
Q_EMIT degreeChanged(deg);
} else if (event->buttons() & Qt::RightButton) {
previousDeg = translateMouseCoords(event->x() - (width() / 2), event->y() - (height() / 2));
emit previousDegreeChanged(previousDeg);
Q_EMIT previousDegreeChanged(previousDeg);
update();
}
}
......@@ -406,5 +406,5 @@ void DirectionDialog::copyProxy()
void DirectionDialog::pasteProxy()
{
emit pasteText(commandBox->text());
Q_EMIT pasteText(commandBox->text());
}
......@@ -27,10 +27,10 @@ class DirectionCanvas : public QWidget
explicit DirectionCanvas(QWidget* parent = nullptr);
void enableGreyTurtle(bool);
public slots:
public Q_SLOTS:
void updateDirections(double previousDeg, double deg);
signals:
Q_SIGNALS:
void degreeChanged(double deg);
void previousDegreeChanged(double deg);
......@@ -63,7 +63,7 @@ class DirectionDialog : public QDialog
Direction = 2
};
signals:
Q_SIGNALS:
void pasteText(const QString&);
private:
......@@ -87,7 +87,7 @@ class DirectionDialog : public QDialog
void updateCanvas();
void updateCommandBox();
private slots:
private Q_SLOTS:
void directionChanged(int value);
void changeCommand(int command);
void updateDegrees(double deg);
......
......@@ -124,7 +124,7 @@ void Editor::textChanged(int pos, int removed, int added)
for (QTextBlock block = editor->document()->begin(); block.isValid(); block = block.next()) lineCount++;
numbers->setWidth(qMax(1, 1 + static_cast<int>(std::floor(std::log10(static_cast<double>(lineCount) - 1)))));
emit contentChanged();
Q_EMIT contentChanged();
}
......@@ -169,7 +169,7 @@ bool Editor::openFile(const QUrl &_url)
setContent(localizedScript);
setCurrentUrl(url);
editor->document()->setModified(false);
emit fileOpened(url);
Q_EMIT fileOpened(url);
return true;
} else {
KMessageBox::error(this, job->errorString());
......@@ -207,7 +207,7 @@ bool Editor::saveFile(const QUrl &targetUrl)
bool pendingEOL = false; // to avoid writing a final EOL token
while ((t = tokenizer.getToken())->type() != Token::EndOfInput) {
if (pendingEOL) {
untranslated.append('\n');
untranslated.append(QLatin1Char('\n'));
pendingEOL = false;
}
if (localizedLooks.contains(t->look())) {
......@@ -241,7 +241,7 @@ bool Editor::saveFile(const QUrl &targetUrl)
setCurrentUrl(url);
editor->document()->setModified(false);
// MainWindow will add us to the recent file list
emit fileSaved(url);
Q_EMIT fileSaved(url);
}
}
delete savefile;
......@@ -276,7 +276,7 @@ bool Editor::maybeSave()
void Editor::setModified(bool b)
{
editor->document()->setModified(b);
emit modificationChanged();
Q_EMIT modificationChanged();
}
// TODO: improve find to be able to search within a selection
......@@ -329,7 +329,7 @@ void Editor::findPrev()
void Editor::setCurrentUrl(const QUrl &url)
{
m_currentUrl = url;
emit contentNameChanged(m_currentUrl.fileName());
Q_EMIT contentNameChanged(m_currentUrl.fileName());
}
void Editor::setOverwriteMode(bool b)
......@@ -347,11 +347,11 @@ void Editor::updateOnCursorPositionChange()
int row = 1;
int last_break = -1;
int next_break = 0;
for (int i = 0; i < s.length(); i++) {
if (s.at(i) == '\n' && i < pos) {
for (int i = 0; i < s.length(); i++) {
if (s.at(i) == QLatin1Char('\n') && i < pos) {
last_break = i;
row++;
} else if (s.at(i) == '\n' && i >= pos) {
} else if (s.at(i) == QLatin1Char('\n') && i >= pos) {
next_break = i;
break;
}
......@@ -365,7 +365,7 @@ void Editor::updateOnCursorPositionChange()
}
currentCol = pos - last_break;
currentLine = s.mid(last_break+1, next_break-last_break-1);
emit cursorPositionChanged();
Q_EMIT cursorPositionChanged();
}
Token* Editor::currentToken()
......@@ -420,8 +420,8 @@ QString Editor::toHtml(const QString& title, const QString& lang)
if (format) {
bool bold = format->fontWeight() > 50;
html += QStringLiteral("<span style=\"color: %1;%2\">%3</span>")
.arg(format->foreground().color().name())
.arg(bold ? " font-weight: bold;" : "")
.arg(format->foreground().color().name())
.arg(bold ? QStringLiteral(" font-weight: bold;") : QString())
.arg(escaped);
} else {
html += escaped;
......@@ -429,7 +429,7 @@ QString Editor::toHtml(const QString& title, const QString& lang)
token = tokenizer->getToken();
}
delete tokenizer;
return QString("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"%1\" lang=\"%1\">"
return QStringLiteral("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"%1\" lang=\"%1\">"
"<head><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\" />"
"<title>%2</title></head>"
"<body style=\"font-family: monospace;\">%3</body></html>").arg(lang).arg(title).arg(html);
......@@ -448,8 +448,8 @@ QString Editor::toHtml(const QString& title, const QString& lang)
// cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
//
// QString word = cursor.selectedText();
// emit mouseHover(word);
// emit mouseHover(helpEvent->pos(), word);
// Q_EMIT mouseHover(word);
// Q_EMIT mouseHover(helpEvent->pos(), word);
//
// // QToolTip::showText(helpEvent->globalPos(), word); // For testing
// }
......
......@@ -132,13 +132,17 @@ class TextEdit : public QTextEdit
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE {
QPainter painter(viewport());
painter.fillRect(currentLineRect(), QBrush(LINE_HIGHLIGHT_COLOR));
if (!currentWord.isNull())
foreach (const QRect &rect, coordsToRects(currentWord))
painter.fillRect(rect, QBrush(WORD_HIGHLIGHT_COLOR));
if (!currentError.isNull())
foreach (const QRect &rect, coordsToRects(currentError))
painter.fillRect(rect, QBrush(ERROR_HIGHLIGHT_COLOR));
painter.fillRect(currentLineRect(), QBrush(LINE_HIGHLIGHT_COLOR));
if (!currentWord.isNull()) {
const auto coordsToRectsList{coordsToRects(currentWord)};
for (const QRect &rect : coordsToRectsList)
painter.fillRect(rect, QBrush(WORD_HIGHLIGHT_COLOR));
}
if (!currentError.isNull()) {
const auto coordsToRectsLst{coordsToRects(currentError)};
for (const QRect &rect : coordsToRectsLst)
painter.fillRect(rect, QBrush(ERROR_HIGHLIGHT_COLOR));
}
painter.end();
QTextEdit::paintEvent(event);
}
......@@ -215,7 +219,7 @@ class Editor : public QFrame
}
public slots:
public Q_SLOTS:
bool newFile();
bool openFile(const QUrl &url = QUrl());
void openExample(const QString& example, const QString& exampleName);
......@@ -242,7 +246,7 @@ class Editor : public QFrame
void rehighlight() { highlighter->rehighlight(); }
signals:
Q_SIGNALS:
void contentNameChanged(const QString&);
void fileOpened(const QUrl&);
void fileSaved(const QUrl&);
......@@ -251,7 +255,7 @@ class Editor : public QFrame
void cursorPositionChanged();
protected slots:
protected Q_SLOTS:
void textChanged(int pos, int added, int removed);
// void cursorPositionChanged();
......@@ -259,7 +263,7 @@ class Editor : public QFrame
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private slots:
private Q_SLOTS:
void updateOnCursorPositionChange();
void highlightCurrentLine() { this->update(); }
......
......@@ -121,11 +121,11 @@ void ErrorDialog::setErrorList(ErrorList *list)
errorList = list;
errorTable->setRowCount(errorList->size());
int row = 0;
foreach (const ErrorMessage &error, *errorList) {
for (const ErrorMessage &error : *errorList) {
int col = 0;
QStringList itemTexts;
itemTexts << QString::number(error.token().startRow()) << error.text() << QString::number(error.code());
foreach (const QString &itemText, itemTexts) {
itemTexts << QString::number(error.token().startRow()) << error.text() << QString::number(error.code());
for (const QString &itemText : std::as_const(itemTexts)) {
errorTable->setItem(row, col, new QTableWidgetItem(itemText));
col++;
}
......@@ -140,7 +140,7 @@ void ErrorDialog::selectedErrorChangedProxy()
{
Q_ASSERT (errorList);
const Token* t = &errorList->at(errorTable->selectedItems().first()->row()).token();
emit currentlySelectedError(t->startRow(), t->startCol(), t->endRow(), t->endCol());
Q_EMIT currentlySelectedError(t->startRow(), t->startCol(), t->endRow(), t->endCol());
// //qDebug() << "EMITTED: " << t->startRow() << ", " << t->startCol() << ", " << t->endRow() << ", " << t->endCol();
}
......
......@@ -28,14 +28,14 @@ class ErrorDialog : public QDialog
void setErrorList(ErrorList*);
void clear();
signals:
Q_SIGNALS:
void currentlySelectedError(int, int, int, int);
public slots:
public Q_SLOTS:
void enable();
void disable();
private slots:
private Q_SLOTS:
void selectedErrorChangedProxy();
void helpRequested();
......
......@@ -226,7 +226,8 @@ void Inspector::updateTree(TreeNode* rootNode)
treeMap.clear();
treeView->clear();
QTreeWidgetItem* rootItem = walkTree(rootNode);
foreach (QTreeWidgetItem* item, rootItem->takeChildren()) {
const auto rootItemChildren = rootItem->takeChildren();
for (QTreeWidgetItem* item : rootItemChildren) {
treeView->addTopLevelItem(item);
}
delete rootItem;
......
......@@ -34,7 +34,7 @@ class Inspector : public QFrame
void clear();
public slots:
public Q_SLOTS:
void updateVariable(const QString& name, const Value& value);
void updateFunction(const QString& name, const QStringList& parameters);
void updateTree(TreeNode* rootNode);
......
......@@ -31,7 +31,7 @@
#
# statement the item is a statement and thus will be parsed as such
# constant the item is a constant so does not need any execution
# auto-emit the emit statement will be autogenerated works for many commands
# auto-Q_EMIT the Q_EMIT statement will be autogenerated works for many commands
# node the item can exist in the node tree and
......@@ -965,7 +965,7 @@ new_item()
globalVariableTable.insert(node->child(0)->token()->look(), node->child(1)->value());
}
// //qDebug() << "variableTable updated!";
emit variableTableUpdated(node->child(0)->token()->look(), node->child(1)->value());
Q_EMIT variableTableUpdated(node->child(0)->token()->look(), node->child(1)->value());
EOS
parse_item()
......@@ -1017,7 +1017,7 @@ EOS
QStringList parameters;
for (uint i = 0; i < node->child(1)->childCount(); i++)
parameters << node->child(1)->child(i)->token()->look();
emit functionTableUpdated(node->child(0)->token()->look(), parameters);
Q_EMIT functionTableUpdated(node->child(0)->token()->look(), parameters);
EOS
parse_item()
......@@ -1032,7 +1032,7 @@ new_item()
@type = "Reset"
@cat = "Command"
@look = "reset"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:none]
parse_item()
......@@ -1041,7 +1041,7 @@ new_item()
@cat = "Command"
@look = "clear"
@ali = "ccl"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:none]
parse_item()
......@@ -1049,7 +1049,7 @@ new_item()
@type = "Center"
@cat = "Command"
@look = "center"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:none]
parse_item()
......@@ -1057,7 +1057,7 @@ new_item()
@type = "Go"
@cat = "Command"
@look = "go"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number, :number]
parse_item()
......@@ -1066,7 +1066,7 @@ new_item()
@cat = "Command"
@look = "gox"
@ali = "gx"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1075,7 +1075,7 @@ new_item()
@cat = "Command"
@look = "goy"
@ali = "gy"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1084,7 +1084,7 @@ new_item()
@cat = "Command"
@look = "forward"
@ali = "fw"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1093,7 +1093,7 @@ new_item()
@cat = "Command"
@look = "backward"
@ali = "bw"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1102,7 +1102,7 @@ new_item()
@cat = "Command"
@look = "direction"
@ali = "dir"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1111,7 +1111,7 @@ new_item()
@cat = "Command"
@look = "turnleft"
@ali = "tl"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1120,7 +1120,7 @@ new_item()
@cat = "Command"
@look = "turnright"
@ali = "tr"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1129,7 +1129,7 @@ new_item()
@cat = "Command"
@look = "penwidth"
@ali = "pw"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1138,7 +1138,7 @@ new_item()
@cat = "Command"
@look = "penup"
@ali = "pu"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:none]
parse_item()
......@@ -1147,7 +1147,7 @@ new_item()
@cat = "Command"
@look = "pendown"
@ali = "pd"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:none]
parse_item()
......@@ -1156,7 +1156,7 @@ new_item()
@cat = "Command"
@look = "pencolor"
@ali = "pc"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number, :number, :number]
parse_item()
......@@ -1165,7 +1165,7 @@ new_item()
@cat = "Command"
@look = "canvascolor"
@ali = "cc"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number, :number, :number]
parse_item()
......@@ -1174,7 +1174,7 @@ new_item()
@cat = "Command"
@look = "canvassize"
@ali = "cs"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number, :number]
parse_item()
......@@ -1183,7 +1183,7 @@ new_item()
@cat = "Command"
@look = "spriteshow"
@ali = "ss"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:none]
parse_item()
......@@ -1192,7 +1192,7 @@ new_item()
@cat = "Command"
@look = "spritehide"
@ali = "sh"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:none]
parse_item()
......@@ -1200,7 +1200,7 @@ new_item()
@type = "Print"
@cat = "Command"
@look = "print"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:string]
@e_def = # define ourself because print handles any argument type
<<EOS
......@@ -1214,7 +1214,7 @@ new_item()
@type = "FontSize"
@cat = "Command"
@look = "fontsize"
@funct = "statement, node, auto-emit"
@funct = "statement, node, auto-Q_EMIT"
@args = [:number]
parse_item()
......@@ -1222,7 +1222,7 @@ parse_item()
# # @type = "WrapOn"
# # @cat = "Command"
# # @look = "wrapon"
# # @funct = "statement, node, auto-emit"
# # @funct = "statement, node, auto-Q_EMIT"
# # @args = [:none]
# # parse_item()
# #
......@@ -1230,7 +1230,7 @@ parse_item()
# # @type = "WrapOff"
# # @cat = "Command"
# # @look = "wrapoff"
# # @funct = "statement, node, auto-emit"
# # @funct = "statement, node, auto-Q_EMIT"
# # @args = [:none]
# # parse_item()
......@@ -1266,7 +1266,7 @@ new_item()
<<EOS
if (!checkParameterQuantity(node, 0, 20000+Token::GetX*100+90)) return;
double value = 0;
emit getX(value);
Q_EMIT getX(value);
node->value()->setNumber(value);
EOS
parse_item()
......@@ -1281,7 +1281,7 @@ new_item()
<<EOS
if (!checkParameterQuantity(node, 0, 20000+Token::GetY*100+90)) return;
double value = 0;
emit getY(value);
Q_EMIT getY(value);
node->value()->setNumber(value);
EOS
parse_item()
......@@ -1303,7 +1303,7 @@ new_item()
@e_def =