Skip to content

Commit

Permalink
ProjectIssuesWidget: optimize row printing
Browse files Browse the repository at this point in the history
It seems the model was dog slow. Why?

1) I queried the filename using IO on every draw
2) I created a new icon for every draw.

On Linux, those things worked fine. On Windows - it was a little bit
more problematic.

Solutions:

1) The short filename is part of the item. Computed only once.
2) Cache the icons. Using a global state.

Now scrolling is as fast as possible.
  • Loading branch information
diegoiast committed Jan 20, 2025
1 parent c9cefe5 commit de43351
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 12 additions & 2 deletions src/plugins/ProjectManager/CompilerOutputDecoders.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "CompilerOutputDecoders.h"

#include <QFileInfo>

void GccOutputDetector::processLine(const QString &line) {
auto match = regionPattern.match(line);
if (match.hasMatch()) {
Expand All @@ -13,7 +15,11 @@ void GccOutputDetector::processLine(const QString &line) {
auto columnNumber = match.captured(3).toInt() - 1;
auto type = match.captured(4);
auto message = match.captured(5);
currentStatus = CompileStatus{fileName, lineNmber, columnNumber, type, message};

auto fi = QFileInfo(fileName);
auto displayName = fi.fileName();
currentStatus =
CompileStatus{fileName, displayName, lineNmber, columnNumber, type, message};
} else if (!line.isEmpty()) {
if (!currentStatus.fileName.isEmpty()) {
currentStatus.message += "\n";
Expand Down Expand Up @@ -87,7 +93,11 @@ void ClOutputDetector::processLine(const QString &line) {
auto type = match.captured(4);
// auto code = match.captured(5);
auto message = match.captured(6);
compileStatuses.append(CompileStatus{fileName, lineNumber, columnNumber, type, message});

auto fi = QFileInfo(fileName);
auto displayName = fi.fileName();
compileStatuses.append(
CompileStatus{fileName, displayName, lineNumber, columnNumber, type, message});
}
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/ProjectManager/CompilerOutputDecoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

struct CompileStatus {
QString fileName;
QString displayName;
int row;
int col;
QString type;
Expand Down
17 changes: 9 additions & 8 deletions src/plugins/ProjectManager/ProjectIssuesWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "ui_ProjectIssuesWidget.h"
#include "widgets/qmdieditor.h"

auto typeToStatus(const QString &name) {
auto typeToStatus(const QString &name) -> int {
if (name.contains("error", Qt::CaseInsensitive)) {
return Qutepart::ERROR_BIT;
} else if (name.compare("warning", Qt::CaseInsensitive) == 0) {
Expand Down Expand Up @@ -44,7 +44,7 @@ class CenteredIconDelegate : public QStyledItemDelegate {

CompileStatusModel::CompileStatusModel(QObject *parent)
: QAbstractTableModel(parent), showWarnings(true), showErrors(true), showOthers(true) {
headers << "Type" << "Message" << "Location";
headers << tr("Type") << tr("Message") << tr("Location");
}

int CompileStatusModel::rowCount(const QModelIndex &parent) const {
Expand All @@ -63,8 +63,12 @@ QVariant CompileStatusModel::data(const QModelIndex &index, int role) const {
auto const &status = filteredStatuses.at(index.row());

if (index.column() == 0 && role == Qt::DecorationRole) {
auto static iconCache = QHash<int, QIcon>();
auto iconType = typeToStatus(status.type);
return Qutepart::iconForStatus(iconType);
if (!iconCache.contains(iconType)) {
iconCache[iconType] = Qutepart::iconForStatus(iconType);
}
return iconCache.value(iconType);
}

if (role == Qt::DisplayRole) {
Expand All @@ -73,11 +77,8 @@ QVariant CompileStatusModel::data(const QModelIndex &index, int role) const {
return {};
case 1:
return status.message;
case 2: {
auto fileInfo = QFileInfo(status.fileName);
auto fileName = fileInfo.fileName();
return QString("%1 (%2:%3)").arg(fileName).arg(status.row).arg(status.col);
}
case 2:
return QString("%1 (%2:%3)").arg(status.displayName).arg(status.row).arg(status.col);
default:
return {};
}
Expand Down

0 comments on commit de43351

Please sign in to comment.