| 751 | } |
| 752 | |
| 753 | void CodeEditor::checkFile(const QVector<MiniZincError>& mznErrors) |
| 754 | { |
| 755 | auto errorColor = theme.errorColor.get(darkMode); |
| 756 | auto warningColor = theme.warningColor.get(darkMode); |
| 757 | |
| 758 | QList<QTextEdit::ExtraSelection> allExtraSels = extraSelections(); |
| 759 | |
| 760 | QList<QTextEdit::ExtraSelection> extraSelections; |
| 761 | foreach (QTextEdit::ExtraSelection sel, allExtraSels) { |
| 762 | if (sel.format.underlineColor() != errorColor && sel.format.underlineColor() != warningColor) { |
| 763 | extraSelections.append(sel); |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | errors.clear(); |
| 768 | errorLines.clear(); |
| 769 | warningLines.clear(); |
| 770 | for (auto& it : mznErrors) { |
| 771 | QTextEdit::ExtraSelection sel; |
| 772 | QTextCharFormat format = sel.format; |
| 773 | format.setUnderlineStyle(QTextCharFormat::WaveUnderline); |
| 774 | format.setUnderlineColor(it.isWarning ? warningColor : errorColor); |
| 775 | QTextBlock block = document()->findBlockByNumber(it.first_line-1); |
| 776 | QTextBlock endblock = document()->findBlockByNumber(it.last_line-1); |
| 777 | if (block.isValid() && endblock.isValid()) { |
| 778 | QTextCursor cursor = textCursor(); |
| 779 | cursor.setPosition(block.position()); |
| 780 | int firstCol = it.first_col < it.last_col ? (it.first_col-1) : (it.last_col-1); |
| 781 | int lastCol = it.first_col < it.last_col ? (it.last_col) : (it.first_col); |
| 782 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, firstCol); |
| 783 | int startPos = cursor.position(); |
| 784 | cursor.setPosition(endblock.position(), QTextCursor::KeepAnchor); |
| 785 | cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, lastCol); |
| 786 | int endPos = cursor.position(); |
| 787 | sel.cursor = cursor; |
| 788 | sel.format = format; |
| 789 | extraSelections.append(sel); |
| 790 | CodeEditorError cee(startPos, endPos, QString(it.isWarning ? "Warning: %1" : "Error: %1").arg(it.msg)); |
| 791 | errors.append(cee); |
| 792 | for (int j=it.first_line; j<=it.last_line; j++) { |
| 793 | if (it.isWarning) { |
| 794 | warningLines.insert(j - 1); |
| 795 | } else { |
| 796 | errorLines.insert(j - 1); |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | setExtraSelections(extraSelections); |
| 802 | } |
| 803 | |
| 804 | void CodeEditor::shiftLeft() |
| 805 | { |