triage: set error line properly
This commit is contained in:
parent
f388c77042
commit
59731d70e8
|
@ -55,6 +55,12 @@ public:
|
||||||
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
||||||
int lineNumberAreaWidth();
|
int lineNumberAreaWidth();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set source code to show, goto error line and highlight that line.
|
||||||
|
* \param code The source code.
|
||||||
|
* \param errorLine line number
|
||||||
|
* \param symbols the related symbols, these are marked
|
||||||
|
*/
|
||||||
void setError(const QString &code, int errorLine, const QStringList &symbols);
|
void setError(const QString &code, int errorLine, const QStringList &symbols);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -134,17 +134,5 @@ void MainWindow::showResult(QListWidgetItem *item)
|
||||||
f.open(QIODevice::ReadOnly | QIODevice::Text);
|
f.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||||
QTextStream textStream(&f);
|
QTextStream textStream(&f);
|
||||||
const QString fileData = textStream.readAll();
|
const QString fileData = textStream.readAll();
|
||||||
ui->code->setPlainText(fileData);
|
ui->code->setError(fileData, lineNumber, QStringList());
|
||||||
for (int pos = 0, line = 1; pos < fileData.size(); ++pos) {
|
|
||||||
if (fileData[pos] == '\n') {
|
|
||||||
++line;
|
|
||||||
if (line == lineNumber) {
|
|
||||||
QTextCursor textCursor = ui->code->textCursor();
|
|
||||||
textCursor.setPosition(pos+1);
|
|
||||||
ui->code->setTextCursor(textCursor);
|
|
||||||
ui->code->centerCursor();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue