Skip to content

Commit

Permalink
ProjectIssuesWidget, ProjectBuildModel: build issues
Browse files Browse the repository at this point in the history
As the new feature of qutepart is available, we can now properly mark
lines with build erros/warnings.
  • Loading branch information
diegoiast committed Jan 15, 2025
1 parent 9f7fa83 commit 8ca5059
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 52 deletions.
79 changes: 45 additions & 34 deletions src/plugins/ProjectManager/ProjectIssuesWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
#include <QFileInfo>
#include <QHeaderView>
#include <QStyledItemDelegate>
#include <qutepart/qutepart.h>
#include <qutepart/theme.h>

#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:
Expand All @@ -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<QIcon>(index.data(Qt::DecorationRole));
auto icon = qvariant_cast<QIcon>(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);
}
};
Expand All @@ -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) {
Expand Down Expand Up @@ -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<qmdiEditor *>(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;
}
}
}
}

Expand Down
35 changes: 23 additions & 12 deletions src/plugins/ProjectManager/ProjectManagerPlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <QTimer>

#include <CommandPaletteWidget/CommandPalette>
#include <qmdihost.h>
#include <qmdiserver.h>
#include <qmditabwidget.h>
#include <widgets/qmdieditor.h>

#include "GenericItems.h"
#include "ProjectBuildConfig.h"
Expand All @@ -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"

Expand Down Expand Up @@ -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<int, QProcess::ExitStatus>::of(&QProcess::finished), this,
[this](int exitCode, QProcess::ExitStatus exitStatus) {
Expand Down Expand Up @@ -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<qmdiEditor *>(client)) {
editor->removeMetaData();
}
}

runProcess.start();
if (!runProcess.waitForStarted()) {
if (kit) {
Expand Down Expand Up @@ -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<ProjectBuildConfig> buildConfig) -> void {
if (!buildConfig || buildConfig->tasksInfo.size() == 0) {
this->gui->taskButton->setText("...");
Expand Down
1 change: 1 addition & 0 deletions src/plugins/ProjectManager/ProjectManagerPlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectBuildConfig> buildConfig) -> void;
auto updateExecutablesUI(std::shared_ptr<ProjectBuildConfig> buildConfig) -> void;

Expand Down
7 changes: 2 additions & 5 deletions src/widgets/qmdieditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,7 @@ bool qmdiEditor::canCloseClient() {
return true;
}

QString qmdiEditor::mdiClientFileName()
{
return fileName;
}
QString qmdiEditor::mdiClientFileName() { return fileName; }

/**
* @brief Return status of editor
Expand Down Expand Up @@ -755,7 +752,7 @@ bool qmdiEditor::saveFile(const QString &newFileName) {
textEditor->removeModifications();
fileSystemWatcher->addPath(newFileName);
setModificationsLookupEnabled(modificationsEnabledState);

auto w = dynamic_cast<QTabWidget *>(this->mdiServer);
auto i = w->indexOf(this);
w->setTabText(i, mdiClientName);
Expand Down
23 changes: 22 additions & 1 deletion src/widgets/qmdieditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class qmdiEditor : public QWidget, public qmdiClient {
virtual std::optional<std::tuple<int, int, int>> 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); }
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8ca5059

Please sign in to comment.