* code fold works now

* correctly parse compiler output
This commit is contained in:
royqh1979@gmail.com 2021-05-27 01:05:49 +08:00
parent fc9099a9da
commit 7f0ab217e8
8 changed files with 145 additions and 81 deletions

View File

@ -56,11 +56,12 @@ QString Compiler::getFileNameFromOutputLine(QString &line) {
} }
temp = line.mid(0,pos); temp = line.mid(0,pos);
line.remove(0,pos+1); line.remove(0,pos+1);
if (temp.compare("<stdin>", Qt::CaseInsensitive)!=0 && !QFile(temp).exists()) { line=line.trimmed();
continue; // if (temp.compare("<stdin>", Qt::CaseInsensitive)!=0 && !QFile(temp).exists()) {
} // continue;
// }
if (QFile(temp).fileName() == QLatin1String("ld.exe")) { // skip ld.exe if (QFileInfo(temp).fileName() == QLatin1String("ld.exe")) { // skip ld.exe
continue; continue;
} else { } else {
break; break;
@ -79,6 +80,7 @@ int Compiler::getLineNumberFromOutputLine(QString &line)
} }
if (pos>=0) { if (pos>=0) {
result = line.mid(0,pos).toInt(); result = line.mid(0,pos).toInt();
if (result > 0)
line.remove(0,pos+1); line.remove(0,pos+1);
} }
return result; return result;
@ -138,6 +140,7 @@ void Compiler::processOutput(QString &line)
line.remove(0,inFilePrefix.length()); line.remove(0,inFilePrefix.length());
issue->filename = getFileNameFromOutputLine(line); issue->filename = getFileNameFromOutputLine(line);
issue->line = getLineNumberFromOutputLine(line); issue->line = getLineNumberFromOutputLine(line);
if (issue->line > 0)
issue->column = getColunmnFromOutputLine(line); issue->column = getColunmnFromOutputLine(line);
issue->type = getIssueTypeFromOutputLine(line); issue->type = getIssueTypeFromOutputLine(line);
issue->description = inFilePrefix + issue->filename; issue->description = inFilePrefix + issue->filename;
@ -147,6 +150,7 @@ void Compiler::processOutput(QString &line)
line.remove(0,fromPrefix.length()); line.remove(0,fromPrefix.length());
issue->filename = getFileNameFromOutputLine(line); issue->filename = getFileNameFromOutputLine(line);
issue->line = getLineNumberFromOutputLine(line); issue->line = getLineNumberFromOutputLine(line);
if (issue->line > 0)
issue->column = getColunmnFromOutputLine(line); issue->column = getColunmnFromOutputLine(line);
issue->type = getIssueTypeFromOutputLine(line); issue->type = getIssueTypeFromOutputLine(line);
issue->description = " from " + issue->filename; issue->description = " from " + issue->filename;
@ -162,6 +166,7 @@ void Compiler::processOutput(QString &line)
// assume regular main.cpp:line:col: message // assume regular main.cpp:line:col: message
issue->filename = getFileNameFromOutputLine(line); issue->filename = getFileNameFromOutputLine(line);
issue->line = getLineNumberFromOutputLine(line); issue->line = getLineNumberFromOutputLine(line);
if (issue->line > 0)
issue->column = getColunmnFromOutputLine(line); issue->column = getColunmnFromOutputLine(line);
issue->type = getIssueTypeFromOutputLine(line); issue->type = getIssueTypeFromOutputLine(line);
issue->description = line.trimmed(); issue->description = line.trimmed();
@ -302,10 +307,10 @@ void Compiler::runCommand(const QString &cmd, const QString &arguments, const Q
process.setWorkingDirectory(workingDir); process.setWorkingDirectory(workingDir);
process.connect(&process, &QProcess::readyReadStandardError,[&process,this](){ process.connect(&process, &QProcess::readyReadStandardError,[&process,this](){
this->error(process.readAllStandardError()); this->error(QString::fromLocal8Bit( process.readAllStandardError()));
}); });
process.connect(&process, &QProcess::readyReadStandardOutput,[&process,this](){ process.connect(&process, &QProcess::readyReadStandardOutput,[&process,this](){
this->log(process.readAllStandardOutput()); this->log(QString::fromLocal8Bit( process.readAllStandardOutput()));
}); });
process.start(); process.start();
if (!inputText.isEmpty()) if (!inputText.isEmpty())

View File

@ -53,15 +53,23 @@ Editor::Editor(QWidget *parent, const QString& filename,
mParentPageControl->addTab(this,QString()); mParentPageControl->addTab(this,QString());
updateCaption(); updateCaption();
} }
PSynHighlighter highlighter;
if (!isNew) { if (!isNew) {
loadFile(); loadFile();
setHighlighter(highlighterManager.createHighlighter(mFilename)); highlighter = highlighterManager.createHighlighter(mFilename);
} else { } else {
if (mEncodingOption == ENCODING_AUTO_DETECT) if (mEncodingOption == ENCODING_AUTO_DETECT)
mFileEncoding = ENCODING_ASCII; mFileEncoding = ENCODING_ASCII;
else else
mFileEncoding = mEncodingOption; mFileEncoding = mEncodingOption;
setHighlighter(highlighterManager.createCppHighlighter()); highlighter=highlighterManager.createCppHighlighter();
}
if (highlighter) {
setHighlighter(highlighter);
setUseCodeFolding(true);
} else {
setUseCodeFolding(false);
} }
//SynEditCppHighlighter highlighter; //SynEditCppHighlighter highlighter;

View File

@ -179,6 +179,12 @@
</property> </property>
<item> <item>
<widget class="IssuesTable" name="tableIssues"> <widget class="IssuesTable" name="tableIssues">
<property name="font">
<font>
<weight>50</weight>
<bold>false</bold>
</font>
</property>
<property name="editTriggers"> <property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set> <set>QAbstractItemView::NoEditTriggers</set>
</property> </property>

View File

@ -85,9 +85,17 @@ SynEditFoldRanges::SynEditFoldRanges()
} }
PSynEditFoldRange SynEditFoldRanges::addByParts(PSynEditFoldRange aParent, PSynEditFoldRanges aAllFold, int aFromLine, PSynEditFoldRegion aFoldRegion, int aToLine) PSynEditFoldRange SynEditFoldRanges::addByParts(PSynEditFoldRange aParent,
PSynEditFoldRanges aAllFold,
int aFromLine,
PSynEditFoldRegion aFoldRegion,
int aToLine)
{ {
PSynEditFoldRange range=std::make_shared<SynEditFoldRange>(aParent,aAllFold, aFromLine,aFoldRegion,aToLine); PSynEditFoldRange range=std::make_shared<SynEditFoldRange>(aParent,aAllFold, aFromLine,aFoldRegion,aToLine);
mRanges.append(range);
if (aAllFold && aAllFold.get()!=this) {
aAllFold->add(range);
}
return range; return range;
} }

View File

@ -125,6 +125,7 @@ SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent)
mContentImage = std::make_shared<QImage>(clientWidth(),clientHeight(),QImage::Format_ARGB32); mContentImage = std::make_shared<QImage>(clientWidth(),clientHeight(),QImage::Format_ARGB32);
mUseCodeFolding = true;
m_blinkTimerId = 0; m_blinkTimerId = 0;
m_blinkStatus = 0; m_blinkStatus = 0;
qDebug()<<"init SynEdit: 10"; qDebug()<<"init SynEdit: 10";
@ -1255,9 +1256,10 @@ void SynEdit::rescanForFoldRanges()
void SynEdit::scanForFoldRanges(PSynEditFoldRanges TopFoldRanges) void SynEdit::scanForFoldRanges(PSynEditFoldRanges TopFoldRanges)
{ {
PSynEditFoldRanges parentFoldRanges = TopFoldRanges;
// Recursively scan for folds (all types) // Recursively scan for folds (all types)
for (int i= 0 ; i< mCodeFolding.foldRegions.count() ; i++ ) { for (int i= 0 ; i< mCodeFolding.foldRegions.count() ; i++ ) {
findSubFoldRange(TopFoldRanges, i,PSynEditFoldRange()); findSubFoldRange(TopFoldRanges, i,parentFoldRanges,PSynEditFoldRange());
} }
} }
@ -1291,11 +1293,9 @@ int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString
return -1; return -1;
} }
void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex, PSynEditFoldRange Parent) void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,PSynEditFoldRanges& parentFoldRanges, PSynEditFoldRange Parent)
{ {
PSynEditFoldRange CollapsedFold; PSynEditFoldRange CollapsedFold;
PSynEditFoldRanges ParentFoldRanges;
ParentFoldRanges = TopFoldRanges;
int Line = 0; int Line = 0;
QString CurLine; QString CurLine;
@ -1330,13 +1330,13 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,
if (lineHasChar(Line,pos,mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol, if (lineHasChar(Line,pos,mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol,
mCodeFolding.foldRegions.get(FoldIndex)->highlight)<0) { mCodeFolding.foldRegions.get(FoldIndex)->highlight)<0) {
// Add it to the top list of folds // Add it to the top list of folds
Parent = ParentFoldRanges->addByParts( Parent = parentFoldRanges->addByParts(
Parent, Parent,
TopFoldRanges, TopFoldRanges,
Line + 1, Line + 1,
mCodeFolding.foldRegions.get(FoldIndex), mCodeFolding.foldRegions.get(FoldIndex),
Line + 1); Line + 1);
ParentFoldRanges = Parent->subFoldRanges; parentFoldRanges = Parent->subFoldRanges;
// Skip until a newline // Skip until a newline
break; break;
@ -1350,6 +1350,11 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,
if (Parent) { if (Parent) {
Parent->toLine = Line + 1; Parent->toLine = Line + 1;
Parent = Parent->parent; Parent = Parent->parent;
if (!Parent) {
parentFoldRanges = TopFoldRanges;
} else {
parentFoldRanges = Parent->subFoldRanges;
}
} }
// Skip until a newline // Skip until a newline
@ -1562,6 +1567,19 @@ void SynEdit::doScrolled(int)
invalidate(); invalidate();
} }
bool SynEdit::useCodeFolding() const
{
return mUseCodeFolding;
}
void SynEdit::setUseCodeFolding(bool value)
{
if (mUseCodeFolding!=value) {
mUseCodeFolding = value;
rescan();
}
}
PSynHighlighter SynEdit::highlighter() const PSynHighlighter SynEdit::highlighter() const
{ {
return mHighlighter; return mHighlighter;
@ -1684,7 +1702,7 @@ void SynEdit::paintEvent(QPaintEvent *event)
// Then the gutter area if it was (partly) invalidated. // Then the gutter area if it was (partly) invalidated.
if (rcClip.left() < mGutterWidth) { if (rcClip.left() < mGutterWidth) {
rcDraw = rcClip; rcDraw = rcClip;
rcDraw.setRight(mGutterWidth+1); rcDraw.setRight(mGutterWidth);
textPainter.paintGutter(rcDraw); textPainter.paintGutter(rcDraw);
} }

View File

@ -301,7 +301,7 @@ private:
void rescanForFoldRanges(); void rescanForFoldRanges();
void scanForFoldRanges(PSynEditFoldRanges TopFoldRanges); void scanForFoldRanges(PSynEditFoldRanges TopFoldRanges);
int lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName); int lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName);
void findSubFoldRange(PSynEditFoldRanges TopFoldRanges,int FoldIndex, PSynEditFoldRange Parent); void findSubFoldRange(PSynEditFoldRanges TopFoldRanges,int FoldIndex,PSynEditFoldRanges& parentFoldRanges, PSynEditFoldRange Parent);
PSynEditFoldRange collapsedFoldStartAtLine(int Line); PSynEditFoldRange collapsedFoldStartAtLine(int Line);
void setSelTextPrimitiveEx(SynSelectionMode PasteMode, void setSelTextPrimitiveEx(SynSelectionMode PasteMode,
const QString& Value, bool AddToUndoList); const QString& Value, bool AddToUndoList);
@ -462,6 +462,9 @@ bool event(QEvent *event) override;
PSynHighlighter highlighter() const; PSynHighlighter highlighter() const;
void setHighlighter(const PSynHighlighter &highlighter); void setHighlighter(const PSynHighlighter &highlighter);
bool useCodeFolding() const;
void setUseCodeFolding(bool value);
protected: protected:
void focusInEvent(QFocusEvent *event) override; void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override; void focusOutEvent(QFocusEvent *event) override;

View File

@ -138,71 +138,71 @@ void SynEditTextPainter::paintGutter(const QRect& clip)
} }
// Draw the folding lines and squares // Draw the folding lines and squares
// if (edit->mUseCodeFolding) { if (edit->mUseCodeFolding) {
// for (cRow = aFirstRow; cRow<=aLastRow; cRow++) { for (cRow = aFirstRow; cRow<=aLastRow; cRow++) {
// vLine = edit->rowToLine(cRow); vLine = edit->rowToLine(cRow);
// if ((vLine > edit->mLines->count()) && (edit->mLines->count() != 0)) if ((vLine > edit->mLines->count()) && (edit->mLines->count() != 0))
// break; break;
// // Form a rectangle for the square the user can click on // Form a rectangle for the square the user can click on
// //rcFold.Left := Gutter.RealGutterWidth(CharWidth) - Gutter.RightOffset; //rcFold.Left := Gutter.RealGutterWidth(CharWidth) - Gutter.RightOffset;
// rcFold.setLeft(edit->mGutterWidth - edit->mGutter.rightOffset()); rcFold.setLeft(edit->mGutterWidth - edit->mGutter.rightOffset());
// rcFold.setRight(rcFold.left() + edit->mGutter.rightOffset() - 4); rcFold.setRight(rcFold.left() + edit->mGutter.rightOffset() - 4);
// rcFold.setTop((cRow - edit->mTopLine) * edit->mTextHeight); rcFold.setTop((cRow - edit->mTopLine) * edit->mTextHeight);
// rcFold.setBottom(rcFold.top() + edit->mTextHeight); rcFold.setBottom(rcFold.top() + edit->mTextHeight);
// painter->setPen(edit->mCodeFolding.folderBarLinesColor); painter->setPen(edit->mCodeFolding.folderBarLinesColor);
// // Need to paint a line? // Need to paint a line?
// if (edit->foldAroundLine(vLine)) { if (edit->foldAroundLine(vLine)) {
// x = rcFold.left() + (rcFold.width() / 2); x = rcFold.left() + (rcFold.width() / 2);
// painter->drawLine(x,rcFold.top(), x, rcFold.bottom()); painter->drawLine(x,rcFold.top(), x, rcFold.bottom());
// } }
// // Need to paint a line end? // Need to paint a line end?
// if (edit->foldEndAtLine(vLine)) { if (edit->foldEndAtLine(vLine)) {
// x = rcFold.left() + (rcFold.width() / 2); x = rcFold.left() + (rcFold.width() / 2);
// painter->drawLine(x,rcFold.top(), x, rcFold.top() + rcFold.height() / 2); painter->drawLine(x,rcFold.top(), x, rcFold.top() + rcFold.height() / 2);
// painter->drawLine(x, painter->drawLine(x,
// rcFold.top() + rcFold.height() / 2, rcFold.top() + rcFold.height() / 2,
// rcFold.right() - 2 , rcFold.right() - 2 ,
// rcFold.top() + rcFold.height() / 2); rcFold.top() + rcFold.height() / 2);
// } }
// // Any fold ranges beginning on this line? // Any fold ranges beginning on this line?
// PSynEditFoldRange FoldRange = edit->foldStartAtLine(vLine); PSynEditFoldRange FoldRange = edit->foldStartAtLine(vLine);
// if (FoldRange) { if (FoldRange) {
// // Draw the bottom part of a line // Draw the bottom part of a line
// if (!FoldRange->collapsed) { if (!FoldRange->collapsed) {
// x = rcFold.left() + (rcFold.width() / 2); x = rcFold.left() + (rcFold.width() / 2);
// painter->drawLine(x, rcFold.top() + rcFold.height() / 2, painter->drawLine(x, rcFold.top() + rcFold.height() / 2,
// x, rcFold.bottom()); x, rcFold.bottom());
// } }
// // make a square rect // make a square rect
// inflateRect(rcFold,-2, 0); inflateRect(rcFold,-2, 0);
// rcFold.setTop( rcFold.setTop(
// rcFold.top() + ((edit->mTextHeight - rcFold.width()) / 2)); rcFold.top() + ((edit->mTextHeight - rcFold.width()) / 2));
// rcFold.setBottom(rcFold.top() + rcFold.width()); rcFold.setBottom(rcFold.top() + rcFold.width());
// // Paint the square the user can click on // Paint the square the user can click on
// painter->setBrush(edit->mGutter.color()); painter->setBrush(edit->mGutter.color());
// painter->setPen(edit->mCodeFolding.folderBarLinesColor); painter->setPen(edit->mCodeFolding.folderBarLinesColor);
// painter->drawRect(rcFold); painter->drawRect(rcFold);
// // Paint minus sign // Paint minus sign
// painter->drawLine( painter->drawLine(
// rcFold.left() + 2, rcFold.top() + (rcFold.height() / 2 ), rcFold.left() + 2, rcFold.top() + (rcFold.height() / 2 ),
// rcFold.right() - 2, rcFold.top() + (rcFold.height() / 2 )); rcFold.right() - 2, rcFold.top() + (rcFold.height() / 2 ));
// // Paint vertical line of plus sign // Paint vertical line of plus sign
// if (FoldRange->collapsed) { if (FoldRange->collapsed) {
// x = rcFold.left() + (rcFold.width() / 2); x = rcFold.left() + (rcFold.width() / 2);
// painter->drawLine(x, rcFold.top() + 2, painter->drawLine(x, rcFold.top() + 2,
// x, rcFold.bottom() + 2); x, rcFold.bottom() + 2);
// } }
// } }
// } }
// } }
// // the gutter separator if visible // // the gutter separator if visible
// if (edit->mGutter.borderStyle <> gbsNone) and (AClip.Right >= fGutterWidth - 2) then // if (edit->mGutter.borderStyle <> gbsNone) and (AClip.Right >= fGutterWidth - 2) then
@ -351,6 +351,7 @@ void SynEditTextPainter::PaintToken(const QString &Token, int TokenCols, int Col
int nX; int nX;
if (Last >= First && rcToken.right() > rcToken.left()) { if (Last >= First && rcToken.right() > rcToken.left()) {
// qDebug()<<"Paint Token"<<Token<<ColumnsBefore<<TokenCols<<First<<Last;
nX = ColumnToXValue(First); nX = ColumnToXValue(First);
First -= ColumnsBefore; First -= ColumnsBefore;
Last -= ColumnsBefore; Last -= ColumnsBefore;
@ -575,6 +576,8 @@ void SynEditTextPainter::AddHighlightToken(const QString &Token, int ColumnsBefo
SynFontStyles Style; SynFontStyles Style;
bool bSpacesTest,bIsSpaces; bool bSpacesTest,bIsSpaces;
// qDebug()<<"Add highlight token"<<Token<<ColumnsBefore<<TokenColumns<<cLine;
if (p_Attri) { if (p_Attri) {
Foreground = p_Attri->foreground(); Foreground = p_Attri->foreground();
Background = p_Attri->background(); Background = p_Attri->background();
@ -861,7 +864,7 @@ void SynEditTextPainter::PaintLines()
throw BaseError(SynEdit::tr("The highlighter seems to be in an infinite loop")); throw BaseError(SynEdit::tr("The highlighter seems to be in an infinite loop"));
} }
nTokenColumnsBefore = edit->charToColumn(vLine,edit->mHighlighter->getTokenPos()+1)-1; nTokenColumnsBefore = edit->charToColumn(vLine,edit->mHighlighter->getTokenPos()+1)-1;
nTokenColumnLen = edit->stringColumns(sToken, nTokenColumnsBefore-1); nTokenColumnLen = edit->stringColumns(sToken, nTokenColumnsBefore);
if (nTokenColumnsBefore + nTokenColumnLen >= vFirstChar) { if (nTokenColumnsBefore + nTokenColumnLen >= vFirstChar) {
if (nTokenColumnsBefore + nTokenColumnLen >= vLastChar) { if (nTokenColumnsBefore + nTokenColumnLen >= vLastChar) {
if (nTokenColumnsBefore >= vLastChar) if (nTokenColumnsBefore >= vLastChar)

View File

@ -11,7 +11,6 @@ IssuesTable::IssuesTable(QWidget *parent):
this->setColumnWidth(0,200); this->setColumnWidth(0,200);
this->setColumnWidth(1,45); this->setColumnWidth(1,45);
this->setColumnWidth(2,45); this->setColumnWidth(2,45);
} }
IssuesModel *IssuesTable::issuesModel() IssuesModel *IssuesTable::issuesModel()
@ -138,6 +137,20 @@ QVariant IssuesModel::data(const QModelIndex &index, int role) const
default: default:
return QVariant(); return QVariant();
} }
case Qt::FontRole: {
QFont newFont=((IssuesTable *)parent())->font();
switch(issue->type) {
case CompileIssueType::Error:
case CompileIssueType::Warning:
{
newFont.setBold(true);
break;
}
default:
newFont.setBold(issue->line == 0);
}
return newFont;
}
default: default:
return QVariant(); return QVariant();
} }