From 8ca5059da7dd941871f8bf660cdd52e2be342658 Mon Sep 17 00:00:00 2001 From: Diego Iastrubni Date: Wed, 15 Jan 2025 19:19:16 +0200 Subject: [PATCH] ProjectIssuesWidget, ProjectBuildModel: build issues As the new feature of qutepart is available, we can now properly mark lines with build erros/warnings. --- .../ProjectManager/ProjectIssuesWidget.cpp | 79 +++++++++++-------- .../ProjectManager/ProjectManagerPlg.cpp | 35 +++++--- .../ProjectManager/ProjectManagerPlg.h | 1 + src/widgets/qmdieditor.cpp | 7 +- src/widgets/qmdieditor.h | 23 +++++- 5 files changed, 93 insertions(+), 52 deletions(-) diff --git a/src/plugins/ProjectManager/ProjectIssuesWidget.cpp b/src/plugins/ProjectManager/ProjectIssuesWidget.cpp index dea1f63..a7c0bf7 100644 --- a/src/plugins/ProjectManager/ProjectIssuesWidget.cpp +++ b/src/plugins/ProjectManager/ProjectIssuesWidget.cpp @@ -1,10 +1,24 @@ #include #include #include +#include +#include #include "ProjectIssuesWidget.h" #include "pluginmanager.h" #include "ui_ProjectIssuesWidget.h" +#include "widgets/qmdieditor.h" + +auto typeToStatus(const QString &name) { + if (name.contains("error", Qt::CaseInsensitive)) { + return Qutepart::ERROR_BIT; + } else if (name.compare("warning", Qt::CaseInsensitive) == 0) { + return Qutepart::WARNING_BIT; + } else if (name.contains("info", Qt::CaseInsensitive) == 0) { + return Qutepart::INFO_BIT; + } + return 0; +} class CenteredIconDelegate : public QStyledItemDelegate { public: @@ -13,20 +27,16 @@ class CenteredIconDelegate : public QStyledItemDelegate { void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override { if (index.column() == 0) { // Only for the first column - QIcon icon = qvariant_cast(index.data(Qt::DecorationRole)); + auto icon = qvariant_cast(index.data(Qt::DecorationRole)); if (!icon.isNull()) { - QRect iconRect = option.rect; - QSize iconSize = option.decorationSize; - - // Center the icon in the cell - int x = iconRect.x() + (iconRect.width() - iconSize.width()) / 2; - int y = iconRect.y() + (iconRect.height() - iconSize.height()) / 2; - + auto iconRect = option.rect; + auto iconSize = option.decorationSize; + auto x = iconRect.x() + (iconRect.width() - iconSize.width()) / 2; + auto y = iconRect.y() + (iconRect.height() - iconSize.height()) / 2; icon.paint(painter, x, y, iconSize.width(), iconSize.height()); return; } } - QStyledItemDelegate::paint(painter, option, index); } }; @@ -52,27 +62,8 @@ QVariant CompileStatusModel::data(const QModelIndex &index, int role) const { auto const &status = filteredStatuses.at(index.row()); if (index.column() == 0 && role == Qt::DecorationRole) { - QString iconName; - if (status.type.toLower().contains("error")) { - iconName = "data-error"; - } else if (status.type.toLower() == "warning") { - iconName = "data-warning"; - } else { - iconName = "data-information"; - } - - if (!QIcon::hasThemeIcon(iconName)) { - qDebug() << "Error : icon not foundm using build it icons" << iconName; - - if (status.type.toLower() == "error") { - return qApp->style()->standardIcon(QStyle::SP_MessageBoxCritical); - } else if (status.type.toLower() == "warning") { - return qApp->style()->standardIcon(QStyle::SP_MessageBoxWarning); - } else { - return qApp->style()->standardIcon(QStyle::SP_MessageBoxInformation); - } - } - return QIcon::fromTheme(iconName); + auto iconType = typeToStatus(status.type); + return Qutepart::iconForStatus(iconType); } if (role == Qt::DisplayRole) { @@ -235,21 +226,41 @@ ProjectIssuesWidget::ProjectIssuesWidget(PluginManager *parent) ProjectIssuesWidget::~ProjectIssuesWidget() { delete ui; } void ProjectIssuesWidget::processLine(const QString &rawLines) { - auto static re = QRegularExpression(R"((.+):(\d+):(\d+):\s+(.+):\s+(.+))"); + auto static gcc_output_re = QRegularExpression(R"((.+):(\d+):(\d+):\s+(.+):\s+(.+))"); + auto lines = rawLines.split("\n"); for (auto const &r : lines) { - auto match = QRegularExpressionMatch(re.match(r)); + auto match = QRegularExpressionMatch(gcc_output_re.match(r)); if (!match.hasMatch()) { continue; } auto file = match.captured(1); - auto line = match.captured(2).toInt(); - auto column = match.captured(3).toInt(); + // gcc works starts at line 1, we at line + auto line = match.captured(2).toInt() - 1; + auto column = match.captured(3).toInt() - 1; auto type = match.captured(4); auto message = match.captured(5); auto item = CompileStatus{file, line, column, type, message}; model->addItem(item); + + auto client = manager->clientForFileName(file); + if (auto editor = dynamic_cast(client)) { + editor->setMetaDataMessage(line, message); + switch (typeToStatus(type)) { + case Qutepart::ERROR_BIT: + editor->setLineError(line, true); + break; + case Qutepart::WARNING_BIT: + editor->setLineWarning(line, true); + break; + case Qutepart::INFO_BIT: + editor->setLineInfo(line, true); + break; + default: + break; + } + } } } diff --git a/src/plugins/ProjectManager/ProjectManagerPlg.cpp b/src/plugins/ProjectManager/ProjectManagerPlg.cpp index 75a0402..b368ada 100644 --- a/src/plugins/ProjectManager/ProjectManagerPlg.cpp +++ b/src/plugins/ProjectManager/ProjectManagerPlg.cpp @@ -12,6 +12,10 @@ #include #include +#include +#include +#include +#include #include "GenericItems.h" #include "ProjectBuildConfig.h" @@ -21,8 +25,6 @@ #include "kitdefinitionmodel.h" #include "kitdetector.h" #include "pluginmanager.h" -#include "qmdihost.h" -#include "qmdiserver.h" #include "ui_BuildRunOutput.h" #include "ui_ProjectManagerGUI.h" @@ -283,19 +285,11 @@ void ProjectManagerPlugin::on_client_merged(qmdiHost *host) { }); connect(&runProcess, &QProcess::readyReadStandardOutput, this, [this]() { auto output = this->runProcess.readAllStandardOutput(); - auto cursor = this->outputPanel->commandOuput->textCursor(); - cursor.movePosition(QTextCursor::End); - cursor.insertText(output); - this->outputPanel->commandOuput->setTextCursor(cursor); - this->projectIssues->processLine(output); + processBuildOutput(output); }); connect(&runProcess, &QProcess::readyReadStandardError, this, [this]() { auto output = this->runProcess.readAllStandardError(); - auto cursor = this->outputPanel->commandOuput->textCursor(); - cursor.movePosition(QTextCursor::End); - cursor.insertText(output); - this->outputPanel->commandOuput->setTextCursor(cursor); - this->projectIssues->processLine(output); + processBuildOutput(output); }); connect(&runProcess, QOverload::of(&QProcess::finished), this, [this](int exitCode, QProcess::ExitStatus exitStatus) { @@ -691,6 +685,15 @@ void ProjectManagerPlugin::do_runTask(const TaskInfo *task) { runProcess.setProgram(QString::fromStdString(kit->filePath)); } + auto manager = getManager(); + auto count = manager->visibleTabs(); + for (auto i = 0; i < count; i++) { + auto client = manager->getMdiClient(i); + if (auto editor = dynamic_cast(client)) { + editor->removeMetaData(); + } + } + runProcess.start(); if (!runProcess.waitForStarted()) { if (kit) { @@ -768,6 +771,14 @@ void ProjectManagerPlugin::projectFile_modified(const QString &path) { qDebug("Config file modified - %s", path.toStdString().data()); } +auto ProjectManagerPlugin::processBuildOutput(const QString &line) -> void { + auto cursor = this->outputPanel->commandOuput->textCursor(); + cursor.movePosition(QTextCursor::End); + cursor.insertText(line); + this->outputPanel->commandOuput->setTextCursor(cursor); + this->projectIssues->processLine(line); +} + auto ProjectManagerPlugin::updateTasksUI(std::shared_ptr buildConfig) -> void { if (!buildConfig || buildConfig->tasksInfo.size() == 0) { this->gui->taskButton->setText("..."); diff --git a/src/plugins/ProjectManager/ProjectManagerPlg.h b/src/plugins/ProjectManager/ProjectManagerPlg.h index a1c1cdf..88d16f8 100644 --- a/src/plugins/ProjectManager/ProjectManagerPlg.h +++ b/src/plugins/ProjectManager/ProjectManagerPlg.h @@ -68,6 +68,7 @@ class ProjectManagerPlugin : public IPlugin { void projectFile_modified(const QString &path); private: + auto processBuildOutput(const QString &line) -> void; auto updateTasksUI(std::shared_ptr buildConfig) -> void; auto updateExecutablesUI(std::shared_ptr buildConfig) -> void; diff --git a/src/widgets/qmdieditor.cpp b/src/widgets/qmdieditor.cpp index fced12a..ae27266 100644 --- a/src/widgets/qmdieditor.cpp +++ b/src/widgets/qmdieditor.cpp @@ -336,10 +336,7 @@ bool qmdiEditor::canCloseClient() { return true; } -QString qmdiEditor::mdiClientFileName() -{ - return fileName; -} +QString qmdiEditor::mdiClientFileName() { return fileName; } /** * @brief Return status of editor @@ -755,7 +752,7 @@ bool qmdiEditor::saveFile(const QString &newFileName) { textEditor->removeModifications(); fileSystemWatcher->addPath(newFileName); setModificationsLookupEnabled(modificationsEnabledState); - + auto w = dynamic_cast(this->mdiServer); auto i = w->indexOf(this); w->setTabText(i, mdiClientName); diff --git a/src/widgets/qmdieditor.h b/src/widgets/qmdieditor.h index 4128c0b..6036215 100644 --- a/src/widgets/qmdieditor.h +++ b/src/widgets/qmdieditor.h @@ -48,7 +48,6 @@ class qmdiEditor : public QWidget, public qmdiClient { virtual std::optional> get_coordinates() const override; void setupActions(); - inline const QString &getFileName() const { return fileName; } inline bool getModificationsLookupEnabled() const { return fileModifications; } void setModificationsLookupEnabled(bool); inline void setEditorFont(QFont newFont) { textEditor->setFont(newFont); } @@ -127,6 +126,28 @@ class qmdiEditor : public QWidget, public qmdiClient { inline void setSmartHomeEnd(bool b) { textEditor->setSmartHomeEnd(b); } inline void setDrawSolidEdge(bool b) { textEditor->setDrawSolidEdge(b); } inline void setLineLengthEdge(int l) { textEditor->setLineLengthEdge(l); } + inline void removeMetaData() { textEditor->removeMetaData(); } + inline void setMetaDataMessage(int lineNumber, const QString &message) { + textEditor->setLineMessage(lineNumber, message); + } + inline void setLineBookmark(int lineNumber, bool value) { + textEditor->setLineBookmark(lineNumber, value); + } + inline void setLineWarning(int lineNumber, bool value) { + textEditor->setLineWarning(lineNumber, value); + } + inline void setLineError(int lineNumber, bool value) { + textEditor->setLineError(lineNumber, value); + } + inline void setLineInfo(int lineNumber, bool value) { + textEditor->setLineInfo(lineNumber, value); + } + inline void setLineBreakpoint(int lineNumber, bool value) { + textEditor->setLineBreakpoint(lineNumber, value); + } + inline void setLineExecuting(int lineNumber, bool value) { + textEditor->setLineExecuting(lineNumber, value); + } protected: void focusInEvent(QFocusEvent *event) override;