From 4b0772d9949486058fbdb7e636b4076a073fa3d8 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 5 Apr 2024 09:42:00 +0800 Subject: [PATCH] refactor --- RedPandaIDE/cpprefacter.cpp | 15 +- RedPandaIDE/debugger/gdbmidebugger.cpp | 2 +- RedPandaIDE/editor.cpp | 133 +++++++++--------- RedPandaIDE/mainwindow.cpp | 122 ++++++++-------- .../editorcolorschemewidget.cpp | 1 + .../settingsdialog/editorsnippetwidget.cpp | 1 + .../settingsdialog/formattergeneralwidget.cpp | 1 + RedPandaIDE/widgets/cpudialog.cpp | 1 + RedPandaIDE/widgets/filepropertiesdialog.cpp | 10 +- RedPandaIDE/widgets/searchinfiledialog.cpp | 24 ++-- libs/qsynedit/qsynedit/document.cpp | 1 - libs/qsynedit/qsynedit/document.h | 1 - libs/qsynedit/qsynedit/exporter/exporter.cpp | 3 +- libs/qsynedit/qsynedit/exporter/exporter.h | 17 ++- .../qsynedit/exporter/rtfexporter.cpp | 2 + .../qsynedit/formatter/cppformatter.cpp | 17 +-- libs/qsynedit/qsynedit/painter.cpp | 8 +- libs/qsynedit/qsynedit/painter.h | 6 +- libs/qsynedit/qsynedit/qsynedit.cpp | 30 +++- libs/qsynedit/qsynedit/qsynedit.h | 27 ++-- libs/qsynedit/qsynedit/syntaxer/syntaxer.h | 2 +- 21 files changed, 240 insertions(+), 184 deletions(-) diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index 75ce14de..5a62af36 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -14,15 +14,16 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include +#include +#include +#include +#include #include "cpprefacter.h" #include "mainwindow.h" #include "settings.h" #include "editor.h" #include "editorlist.h" -#include -#include -#include -#include #include "syntaxermanager.h" #include "project.h" @@ -238,7 +239,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile( } editor.setSyntaxer(syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::CPP)); int posY = 0; - while (posY < editor.document()->count()) { + while (posY < editor.lineCount()) { QString line = editor.document()->getLine(posY); if (line.isEmpty()) { posY++; @@ -299,7 +300,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & oldEditor->clearSelection(); oldEditor->addGroupBreak(); oldEditor->beginEditing(); - while (posY < oldEditor->document()->count()) { + while (posY < oldEditor->lineCount()) { QString line = oldEditor->document()->getLine(posY); if (posY == 0) { syntaxer->resetState(); @@ -351,7 +352,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & QStringList newContents; int posY = 0; - while (posY < editor.document()->count()) { + while (posY < editor.lineCount()) { QString line = editor.document()->getLine(posY); if (posY == 0) { editor.syntaxer()->resetState(); diff --git a/RedPandaIDE/debugger/gdbmidebugger.cpp b/RedPandaIDE/debugger/gdbmidebugger.cpp index 78f00f9e..04a01f14 100644 --- a/RedPandaIDE/debugger/gdbmidebugger.cpp +++ b/RedPandaIDE/debugger/gdbmidebugger.cpp @@ -1145,7 +1145,7 @@ void GDBMIDebuggerClient::setBreakpointCondition(PBreakpoint breakpoint) QString("%1").arg(breakpoint->number)); } else { postCommand("-break-condition", - QString("%1 \"%2\"").arg(breakpoint->number).arg(condition)); + QString("%1 %2").arg(breakpoint->number).arg(condition)); } } diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index a4478331..e16d9b23 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -21,22 +21,6 @@ #include #include #include -#include -#include "settings.h" -#include "mainwindow.h" -#include "systemconsts.h" -#include -#include -#include -#include -#include -#include "qsynedit/syntaxer/cpp.h" -#include "qsynedit/syntaxer/asm.h" -#include "syntaxermanager.h" -#include "qsynedit/exporter/rtfexporter.h" -#include "qsynedit/exporter/htmlexporter.h" -#include "qsynedit/exporter/qtsupportedhtmlexporter.h" -#include "qsynedit/constants.h" #include #include #include @@ -49,6 +33,23 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "settings.h" +#include "mainwindow.h" +#include "systemconsts.h" +#include "syntaxermanager.h" #include "iconsmanager.h" #include "debugger/debugger.h" #include "editorlist.h" @@ -864,12 +865,12 @@ void Editor::keyPressEvent(QKeyEvent *event) s=trimLeft(lineText()); if (s.startsWith("* ")) { handled = true; - int right = document()->getLine(caretY()-1).length()-caretX(); + int right = lineText(caretY()).length()-caretX(); s=lineBreak()+"* "; insertString(s,false); QSynedit::BufferCoord p = caretXY(); p.line++; - p.ch = document()->getLine(p.line-1).length()+1; + p.ch = lineText(p.line).length()+1; if (right>0) { p.ch -=right+1; } @@ -1167,7 +1168,7 @@ void Editor::mouseMoveEvent(QMouseEvent *event) QSynedit::BufferCoord p; TipType reason = getTipType(event->pos(),p); if (reason == TipType::Preprocessor) { - QString s = document()->getLine(p.line - 1); + QString s = lineText(p.line); if (mParser->isIncludeNextLine(s) || mParser->isIncludeLine(s)) updateHoverLink(p.line); } else if (reason == TipType::Identifier) { @@ -1269,17 +1270,17 @@ void Editor::onGetEditingAreas(int line, QSynedit::EditingAreaList &areaList) areaList.append(p); } } - QString lineText = document()->getLine(line-1); - if (mParser && mParser->isIncludeLine(lineText)) { + QString s = lineText(line); + if (mParser && mParser->isIncludeLine(s)) { if (line == mHoverModifiedLine) { int i=0; - while (i',syntaxer(), foregroundColor(), areaList); + if (i',syntaxer(), foregroundColor(), areaList); } else { - setIncludeUnderline(lineText,i,'"',syntaxer(), foregroundColor(), areaList); + setIncludeUnderline(s,i,'"',syntaxer(), foregroundColor(), areaList); } } } @@ -1322,11 +1323,11 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to background = syntaxer()->commentAttribute()->background(); return; } - QString lineText = document()->getLine(line-1); - if (mParser->isIncludeLine(lineText) && attr->tokenType() != QSynedit::TokenType::Comment) { + QString s = lineText(line); + if (mParser->isIncludeLine(s) && attr->tokenType() != QSynedit::TokenType::Comment) { // #include header names (<>) - int pos1=lineText.indexOf("<")+1; - int pos2=lineText.indexOf(">",pos1); + int pos1=s.indexOf("<")+1; + int pos2=s.indexOf(">",pos1); if (pos1>0 && pos2>0 && pos1identifierAttribute()->styles(); foreground = syntaxer()->identifierAttribute()->foreground(); @@ -1356,8 +1357,8 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); if ((pEndPos.line>=1) && (pEndPos.ch>=0) - && (pEndPos.ch+1 < document()->getLine(pEndPos.line-1).length()) - && (document()->getLine(pEndPos.line-1)[pEndPos.ch+1] == '(')) { + && (pEndPos.ch+1 < lineText(pEndPos.line).length()) + && (lineText(pEndPos.line)[pEndPos.ch+1] == '(')) { kind = StatementKind::Function; } else { kind = StatementKind::Variable; @@ -1488,7 +1489,7 @@ void Editor::mouseReleaseEvent(QMouseEvent *event) QSynedit::BufferCoord p; if (mParser && pointToCharLine(event->pos(),p)) { cancelHoverLink(); - QString s = document()->getLine(p.line - 1); + QString s = lineText(p.line); if (mParser->isIncludeNextLine(s)) { QString filename = mParser->getHeaderFileName(mFilename,s, true); pMainWindow->openFile(filename); @@ -1748,20 +1749,20 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT int start; QSynedit::PTokenAttribute attr; PSyntaxIssueList lst; - if ((line<1) || (line>document()->count())) + if ((line<1) || (line>lineCount())) return; pError = std::make_shared(); p.ch = startChar; p.line = line; - if (startChar >= document()->getLine(line-1).length()) { + if (startChar >= lineText(line).length()) { start = 1; - token = document()->getLine(line-1); + token = lineText(line); } else if (endChar < 1) { if (!getTokenAttriAtRowColEx(p,token,start,attr)) return; } else { start = startChar; - token = document()->getLine(line-1).mid(start-1,endChar-startChar); + token = lineText(line).mid(start-1,endChar-startChar); } pError->startChar = start; pError->endChar = start + token.length(); @@ -1855,8 +1856,8 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes) { if ((!changes.testFlag(QSynedit::StatusChange::ReadOnly) && !changes.testFlag(QSynedit::StatusChange::InsertMode) - && (document()->count()!=mLineCount) - && (document()->count()!=0) && ((mLineCount>0) || (document()->count()>1))) + && (lineCount()!=mLineCount) + && (lineCount()!=0) && ((mLineCount>0) || (lineCount()>1))) || (mCurrentLineModified && !changes.testFlag(QSynedit::StatusChange::ReadOnly) @@ -1874,7 +1875,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes) // reparse(); // } } - mLineCount = document()->count(); + mLineCount = lineCount(); if (changes.testFlag(QSynedit::StatusChange::ModifyChanged)) { updateCaption(); } @@ -2109,7 +2110,7 @@ void Editor::onTooltipTimer() case TipType::Preprocessor: // When hovering above a preprocessor line, determine if we want to show an include or a identifier hint if (mParser) { - s = document()->getLine(p.line - 1); + s = lineText(p.line); isIncludeNextLine = mParser->isIncludeNextLine(s); if (!isIncludeNextLine) isIncludeLine = mParser->isIncludeLine(s); @@ -2146,7 +2147,7 @@ void Editor::onTooltipTimer() QSynedit::PTokenAttribute attr; int start; if (getTokenAttriAtRowColEx(p,s,start,attr)) { - QString line=document()->getLine(p.line-1); + QString line=lineText(p.line); int idx=start-2; if (idx>=0 && idx=document()->count() || line<0) + if (line>=lineCount() || line<0) break; QStringList tokens; if (line==0) { @@ -2612,7 +2613,7 @@ QString Editor::getWordForCompletionSearch(const QSynedit::BufferCoord &pos,bool QString result = ""; QString s; - s = document()->getLine(pos.line - 1); + s = lineText(pos.line); int len = s.length(); int wordBegin = pos.ch - 1 - 1; //BufferCoord::Char starts with 1 @@ -2797,10 +2798,10 @@ bool Editor::handleParentheseSkip() if (status != QuoteStatus::NotQuote) return false; - if (document()->count()==0) + if (lineCount()==0) return false; if (syntaxer()->supportBraceLevel()) { - QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1); + QSynedit::SyntaxState lastLineState = document()->getSyntaxState(lineCount()-1); if (lastLineState.parenthesisLevel==0) { setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over return true; @@ -2844,10 +2845,10 @@ bool Editor::handleBracketSkip() if (getCurrentChar() != ']') return false; - if (document()->count()==0) + if (lineCount()==0) return false; if (syntaxer()->supportBraceLevel()) { - QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1); + QSynedit::SyntaxState lastLineState = document()->getSyntaxState(lineCount()-1); if (lastLineState.bracketLevel==0) { setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over return true; @@ -2920,10 +2921,10 @@ bool Editor::handleBraceCompletion() QSynedit::BufferCoord oldSelEnd = blockEnd(); bool shouldBreakLine = false; bool shouldAddEndLine = false; - QString s1=document()->getLine(oldSelBegin.line-1).left(oldSelBegin.ch-1).trimmed(); + QString s1=lineText(oldSelBegin.line).left(oldSelBegin.ch-1).trimmed(); if (s1.isEmpty() ) { - QString s2 = document()->getLine(oldSelEnd.line-1); + QString s2 = lineText(oldSelEnd.line); if (s2.left(oldSelEnd.ch-1).trimmed().isEmpty()) { shouldBreakLine = true; } else if (oldSelEnd.ch > trimRight(s2).length()) { @@ -2957,11 +2958,11 @@ bool Editor::handleBraceSkip() if (getCurrentChar() != '}') return false; - if (document()->count()==0) + if (lineCount()==0) return false; if (syntaxer()->supportBraceLevel()) { - QSynedit::SyntaxState lastLineState = document()->getSyntaxState(document()->count()-1); + QSynedit::SyntaxState lastLineState = document()->getSyntaxState(lineCount()-1); if (lastLineState.braceLevel==0) { bool oldInsertMode = insertMode(); setInsertMode(false); //set mode to overwrite @@ -4125,7 +4126,7 @@ Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos) // do not allow when dragging selection if (isPointInSelection(pos)) return TipType::Selection; - } else if (mParser && mParser->isIncludeLine(document()->getLine(pos.line-1))) { + } else if (mParser && mParser->isIncludeLine(lineText(pos.line))) { return TipType::Preprocessor; } else if (attr->tokenType() == QSynedit::TokenType::Identifier) { return TipType::Identifier; @@ -4273,7 +4274,7 @@ void Editor::updateFunctionTip(bool showTip) int bracketLevel = 0; int paramsCount = 1; int currentParamPos = 1; - if (currentLine>=document()->count()) + if (currentLine>=lineCount()) return; QChar ch=lastNonSpaceChar(currentLine,currentChar); @@ -4398,7 +4399,7 @@ void Editor::updateFunctionTip(bool showTip) QString s = getWordAtPosition(this, functionNamePos, pWordBegin,pWordEnd, WordPurpose::wpInformation); int x = pWordBegin.ch-1-1; - QString line = document()->getLine(pWordBegin.line-1); + QString line = lineText(pWordBegin.line); bool hasPreviousWord=false; while (x>=0) { QChar ch=line[x]; @@ -4502,7 +4503,7 @@ void Editor::popUserCodeInTabStops() tabStopBegin = mTabStopEnd + p->x; tabStopEnd = mTabStopEnd + p->endX; } else { - int n=countLeadingWhitespaceChars(document()->getLine(caretY()-1+p->y)); + int n=countLeadingWhitespaceChars(lineText(caretY()+p->y)); // qDebug()<x; tabStopBegin = n+p->x+1; tabStopEnd = n+p->endX+1; @@ -4547,8 +4548,8 @@ void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int c if (kind == StatementKind::Unknown) { if ((pEndPos.line>=1) && (pEndPos.ch>=0) - && (pEndPos.ch < document()->getLine(pEndPos.line-1).length()) - && (document()->getLine(pEndPos.line-1)[pEndPos.ch] == '(')) { + && (pEndPos.ch < lineText(pEndPos.line).length()) + && (lineText(pEndPos.line)[pEndPos.ch] == '(')) { kind = StatementKind::Function; } else { kind = StatementKind::Variable; @@ -4783,13 +4784,13 @@ QString getWordAtPosition(QSynedit::QSynEdit *editor, const QSynedit::BufferCoor { QString result = ""; QString s; - if ((p.line<1) || (p.line>editor->document()->count())) { + if ((p.line<1) || (p.line>editor->lineCount())) { pWordBegin = p; pWordEnd = p; return ""; } - s = editor->document()->getLine(p.line - 1); + s = editor->lineText(p.line); int len = s.length(); int wordBegin = p.ch - 1 - 1; //BufferCoord::Char starts with 1 @@ -4972,7 +4973,7 @@ QString getWordAtPosition(QSynedit::QSynEdit *editor, const QSynedit::BufferCoor if (i<0) { line--; if (line>=1) { - s=editor->document()->getLine(line-1); + s=editor->lineText(line); i=s.length(); continue; } else @@ -5023,12 +5024,12 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo { hasTypeQualifier = false; QString result; - if ((p.line<1) || (p.line>document()->count())) { + if ((p.line<1) || (p.line>lineCount())) { return ""; } bool inFunc = testInFunc(p); - QString s = document()->getLine(p.line - 1); + QString s = lineText(p.line); int wordBegin; int wordEnd = p.ch-2; if (wordEnd >= s.length()) @@ -5092,11 +5093,11 @@ QString Editor::getPreviousWordAtPositionForSuggestion(const QSynedit::BufferCoo QString Editor::getPreviousWordAtPositionForCompleteFunctionDefinition(const QSynedit::BufferCoord &p) { QString result; - if ((p.line<1) || (p.line>document()->count())) { + if ((p.line<1) || (p.line>lineCount())) { return ""; } - QString s = document()->getLine(p.line - 1); + QString s = lineText(p.line); int wordBegin; int wordEnd = p.ch-2; if (wordEnd >= s.length()) @@ -5158,7 +5159,7 @@ void Editor::reformat(bool doReparse) } #endif //we must remove all breakpoints and syntax issues -// onLinesDeleted(1,document()->count()); +// onLinesDeleted(1,lineCount()); QByteArray content = text().toUtf8(); QStringList args = pSettings->codeFormatter().getArguments(); //qDebug()<. */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include "mainwindow.h" #include "ui_mainwindow.h" #include "editorlist.h" @@ -62,42 +94,10 @@ #include "widgets/projectalreadyopendialog.h" #include "widgets/searchdialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "mainwindow.h" -#include -#include #include "settingsdialog/settingsdialog.h" #include "compiler/compilermanager.h" -#include -#include -#include -#include +#include #include "cpprefacter.h" #include "widgets/newprojectunitdialog.h" @@ -689,7 +689,7 @@ void MainWindow::updateEditorActions(const Editor *e) } else { ui->actionCopy->setEnabled(true); ui->actionCut->setEnabled(true); - ui->actionFoldAll->setEnabled(e->document()->count()>0); + ui->actionFoldAll->setEnabled(e->lineCount()>0); ui->actionIndent->setEnabled(!e->readOnly()); ui->actionPaste->setEnabled(!e->readOnly()); ui->actionRedo->setEnabled(e->canRedo()); @@ -699,17 +699,17 @@ void MainWindow::updateEditorActions(const Editor *e) ui->actionExport_As_HTML->setEnabled(true); ui->actionExport_As_RTF->setEnabled(true); ui->actionPrint->setEnabled(true); - ui->actionToggleComment->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionToggleComment->setEnabled(!e->readOnly() && e->lineCount()>0); ui->actionToggle_Block_Comment->setEnabled(!e->readOnly() && e->selAvail()); - ui->actionUnIndent->setEnabled(!e->readOnly() && e->document()->count()>0); - ui->actionUnfoldAll->setEnabled(e->document()->count()>0); - ui->actionDelete_Line->setEnabled(!e->readOnly() && e->document()->count()>0); - ui->actionDelete_Word->setEnabled(!e->readOnly() && e->document()->count()>0); - ui->actionDuplicate_Line->setEnabled(!e->readOnly() && e->document()->count()>0); - ui->actionDelete_to_BOL->setEnabled(!e->readOnly() && e->document()->count()>0); - ui->actionDelete_to_EOL->setEnabled(!e->readOnly() && e->document()->count()>0); - ui->actionDelete_to_Word_End->setEnabled(!e->readOnly() && e->document()->count()>0); - ui->actionDelete_Last_Word->setEnabled(!e->readOnly() && e->document()->count()>0); + ui->actionUnIndent->setEnabled(!e->readOnly() && e->lineCount()>0); + ui->actionUnfoldAll->setEnabled(e->lineCount()>0); + ui->actionDelete_Line->setEnabled(!e->readOnly() && e->lineCount()>0); + ui->actionDelete_Word->setEnabled(!e->readOnly() && e->lineCount()>0); + ui->actionDuplicate_Line->setEnabled(!e->readOnly() && e->lineCount()>0); + ui->actionDelete_to_BOL->setEnabled(!e->readOnly() && e->lineCount()>0); + ui->actionDelete_to_EOL->setEnabled(!e->readOnly() && e->lineCount()>0); + ui->actionDelete_to_Word_End->setEnabled(!e->readOnly() && e->lineCount()>0); + ui->actionDelete_Last_Word->setEnabled(!e->readOnly() && e->lineCount()>0); ui->menuMove_Caret->setEnabled(true); ui->actionPage_Up->setEnabled(true); @@ -721,7 +721,7 @@ void MainWindow::updateEditorActions(const Editor *e) ui->actionGoto_Page_Start->setEnabled(true); ui->actionGoto_Page_End->setEnabled(true); - ui->actionSelectAll->setEnabled(e->document()->count()>0); + ui->actionSelectAll->setEnabled(e->lineCount()>0); ui->actionSelect_Word->setEnabled(true); ui->actionMove_Selection_Up->setEnabled(true); ui->actionMove_Selection_Down->setEnabled(true); @@ -747,7 +747,7 @@ void MainWindow::updateEditorActions(const Editor *e) ui->actionClose_Others->setEnabled(mEditorList->pageCount()>1); int line = e->caretY(); - ui->actionAdd_bookmark->setEnabled(e->document()->count()>0 && !e->hasBookmark(line)); + ui->actionAdd_bookmark->setEnabled(e->lineCount()>0 && !e->hasBookmark(line)); ui->actionRemove_Bookmark->setEnabled(e->hasBookmark(line)); ui->actionModify_Bookmark_Description->setEnabled(e->hasBookmark(line)); @@ -1598,27 +1598,27 @@ void MainWindow::updateStatusbarForLineCol(const Editor* e, bool clear) if (e->selAvail()) { msg = tr("Line: %1/%2 Col: %3 Sel: %4") .arg(e->caretY()) - .arg(e->document()->count()) + .arg(e->lineCount()) .arg(col) .arg(e->selCount()); } else { msg = tr("Line: %1/%2 Col: %3") .arg(e->caretY()) - .arg(e->document()->count()) + .arg(e->lineCount()) .arg(col); } } else { if (e->selAvail()) { msg = tr("Line: %1/%2 Char: %3/%4 Sel: %5") .arg(e->caretY()) - .arg(e->document()->count()) + .arg(e->lineCount()) .arg(e->caretX()) .arg(e->lineText().length()) .arg(e->selCount()); } else { msg = tr("Line: %1/%2 Char: %3/%4") .arg(e->caretY()) - .arg(e->document()->count()) + .arg(e->lineCount()) .arg(e->caretX()) .arg(e->lineText().length()); } @@ -5215,7 +5215,7 @@ void MainWindow::onEditorContextMenu(const QPoint& pos) ui->actionLocate_in_Files_View->setEnabled(!editor->isNew()); ui->actionBreakpoint_property->setEnabled(editor->hasBreakpoint(line)); ui->actionAdd_bookmark->setEnabled( - line>=0 && editor->document()->count()>0 + line>=0 && editor->lineCount()>0 && !editor->hasBookmark(line) ); ui->actionRemove_Bookmark->setEnabled(editor->hasBookmark(line)); @@ -5949,11 +5949,11 @@ void MainWindow::onCompileIssue(PCompileIssue issue) Editor* e = mEditorList->getOpenedEditorByFilename(issue->filename); if (e!=nullptr && (issue->line>0)) { int line = issue->line; - if (line > e->document()->count()) + if (line > e->lineCount()) return; - int col = std::min(issue->column,e->document()->getLine(line-1).length()+1); + int col = std::min(issue->column,e->lineText(line).length()+1); if (col < 1) - col = e->document()->getLine(line-1).length()+1; + col = e->lineText(line).length()+1; e->addSyntaxIssues(line,col,issue->endColumn,issue->type,issue->description); } } @@ -6075,8 +6075,8 @@ void MainWindow::onCompileFinished(QString filename, bool isCheckSyntax) int line = e->caretY(); int startLine = 1; QString s = "# "+e->filename()+":"; - for(int i=0;idocument()->count();i++) { - QString t=editor->document()->getLine(i).trimmed(); + for(int i=1;i<=editor->lineCount();i++) { + QString t=editor->lineText(i).trimmed(); if (t.startsWith(s,PATH_SENSITIVITY)) { t=t.mid(s.length()); int pos = t.indexOf(":"); @@ -6086,7 +6086,7 @@ void MainWindow::onCompileFinished(QString filename, bool isCheckSyntax) int l=numstring.toInt(&isOk); if (isOk) { if (l<=line) - startLine=i+1; + startLine=i; if (l>=line) break; } @@ -8380,7 +8380,7 @@ void MainWindow::on_btnReplace_clicked() while (!selections.isEmpty()) { const PSearchResultTreeItem& item = selections.back(); selections.pop_back(); - QString line = editor->document()->getLine(item->line-1); + QString line = editor->lineText(item->line); if (line.mid(item->start-1,results->keyword.length())!=results->keyword) { QMessageBox::critical(editor, tr("Replace Error"), @@ -8534,11 +8534,11 @@ void MainWindow::on_actionAdd_bookmark_triggered() Editor* editor = mEditorList->getEditor(); int line; if (editor && editor->pointToLine(mEditorContextMenuPos,line)) { - if (editor->document()->count()<=0) + if (editor->lineCount()<=0) return; QString desc = QInputDialog::getText(editor,tr("Bookmark Description"), tr("Description:"),QLineEdit::Normal, - editor->document()->getLine(line-1).trimmed()); + editor->lineText(line).trimmed()); desc = desc.trimmed(); editor->addBookmark(line); mBookmarkModel->addBookmark(editor->filename(),line,desc,editor->inProject()); @@ -9836,7 +9836,7 @@ void MainWindow::on_actionGo_to_Line_triggered() return; bool ok; int lineNo=QInputDialog::getInt(e,tr("Go to Line"),tr("Line"), - e->caretY(),1,e->document()->count(), + e->caretY(),1,e->lineCount(), 1,&ok); if (ok && lineNo!=e->caretY()) { e->setCaretPosition(lineNo,1); diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index ce40088c..e2e19af9 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -25,6 +25,7 @@ #include #include #include +#include EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QString& group, QWidget *parent) : SettingsWidget(name,group,parent), diff --git a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp index bc8bdf9a..9eb2f3ab 100644 --- a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "editorsnippetwidget.h" #include "ui_editorsnippetwidget.h" #include "../mainwindow.h" diff --git a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp index 0bb42b0b..c30604be 100644 --- a/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/formattergeneralwidget.cpp @@ -14,6 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ +#include #include "formattergeneralwidget.h" #include "ui_formattergeneralwidget.h" #include "../settings.h" diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp index 039cb2ff..42ada22c 100644 --- a/RedPandaIDE/widgets/cpudialog.cpp +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -15,6 +15,7 @@ * along with this program. If not, see . */ #include +#include #include "cpudialog.h" #include "ui_cpudialog.h" #include "../syntaxermanager.h" diff --git a/RedPandaIDE/widgets/filepropertiesdialog.cpp b/RedPandaIDE/widgets/filepropertiesdialog.cpp index 5849fd62..e38bb0e5 100644 --- a/RedPandaIDE/widgets/filepropertiesdialog.cpp +++ b/RedPandaIDE/widgets/filepropertiesdialog.cpp @@ -46,7 +46,7 @@ void FilePropertiesDialog::calcFile(Editor *editor, int &includeLines, int &charCounts) { - totalLines = editor->document()->count(); + totalLines = editor->lineCount(); codeLines = 0; commentLines = 0; emptyLines = 0; @@ -54,14 +54,14 @@ void FilePropertiesDialog::calcFile(Editor *editor, charCounts = 0; int lineBreakerLen = QString(LINE_BREAKER).length(); // iterate through all lines of file - for (int i=0;idocument()->count();i++) { - QString line = editor->document()->getLine(i); + for (int i=1;i<=editor->lineCount();i++) { + QString line = editor->lineText(i); charCounts+=line.length()+lineBreakerLen; // while (jgetTokenAttriAtRowCol(QSynedit::BufferCoord{1,i+1}, + if (editor->getTokenAttriAtRowCol(QSynedit::BufferCoord{1,i}, token,attr)) { // if it is preprocessor... if (attr->name() == SYNS_AttrPreprocessor) { @@ -136,7 +136,7 @@ void FilePropertiesDialog::on_cbFiles_currentIndexChanged(int index) ui->txtProject->setText("-"); ui->txtPath->setText(editor->filename()); ui->txtRelativeToProject->setText("_"); - ui->txtLines->setText(QString("%1").arg(editor->document()->count())); + ui->txtLines->setText(QString("%1").arg(editor->lineCount())); int totalLines, codeLines,emptyLines,commentLines,includeLines, charCounts; calcFile(editor,totalLines,commentLines,emptyLines,codeLines,includeLines,charCounts); diff --git a/RedPandaIDE/widgets/searchinfiledialog.cpp b/RedPandaIDE/widgets/searchinfiledialog.cpp index 1b95cb6e..3c0cac9c 100644 --- a/RedPandaIDE/widgets/searchinfiledialog.cpp +++ b/RedPandaIDE/widgets/searchinfiledialog.cpp @@ -17,21 +17,21 @@ #include "searchinfiledialog.h" #include "ui_searchinfiledialog.h" #include -#include "../editor.h" -#include "../mainwindow.h" -#include "../editorlist.h" -#include -#include -#include "../project.h" -#include "../settings.h" -#include "../systemconsts.h" #include #include #include #include #include #include - +#include +#include +#include +#include "../editor.h" +#include "../mainwindow.h" +#include "../editorlist.h" +#include "../project.h" +#include "../settings.h" +#include "../systemconsts.h" SearchInFileDialog::SearchInFileDialog(QWidget *parent) : QDialog(parent), @@ -378,14 +378,14 @@ std::shared_ptr SearchInFileDialog::batchFindInEditor(QSyn parentItem->parent = nullptr; execute(e,keyword,"", [e,&parentItem, filename](const QString&, - const QString&, int Line, int ch, int wordLen){ + const QString&, int line, int ch, int wordLen){ PSearchResultTreeItem item = std::make_shared(); item->filename = filename; - item->line = Line; + item->line = line; item->start = ch; item->len = wordLen; item->parent = parentItem.get(); - item->text = e->document()->getLine(Line-1); + item->text = e->lineText(line); item->text.replace('\t',' '); parentItem->results.append(item); return QSynedit::SearchAction::Skip; diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index 40367ca8..a42ac53a 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -22,7 +22,6 @@ #include #include #include -#include "qsynedit.h" #include #include #include "qt_utils/charsetinfo.h" diff --git a/libs/qsynedit/qsynedit/document.h b/libs/qsynedit/qsynedit/document.h index 13f97ced..8e69e64f 100644 --- a/libs/qsynedit/qsynedit/document.h +++ b/libs/qsynedit/qsynedit/document.h @@ -18,7 +18,6 @@ #define SYNEDITSTRINGLIST_H #include -#include "syntaxer/syntaxer.h" #include #include #include diff --git a/libs/qsynedit/qsynedit/exporter/exporter.cpp b/libs/qsynedit/qsynedit/exporter/exporter.cpp index 63b66b9b..567f541b 100644 --- a/libs/qsynedit/qsynedit/exporter/exporter.cpp +++ b/libs/qsynedit/qsynedit/exporter/exporter.cpp @@ -15,11 +15,12 @@ * along with this program. If not, see . */ #include "exporter.h" - +#include "../document.h" #include #include #include #include +#include #include namespace QSynedit { diff --git a/libs/qsynedit/qsynedit/exporter/exporter.h b/libs/qsynedit/qsynedit/exporter/exporter.h index e9808493..69281ca2 100644 --- a/libs/qsynedit/qsynedit/exporter/exporter.h +++ b/libs/qsynedit/qsynedit/exporter/exporter.h @@ -18,9 +18,24 @@ #define EXPORTER_H #include -#include "../qsynedit.h" +#include +#include +#include +#include +#include +#include +#include "qt_utils/utils.h" +#include "../types.h" + namespace QSynedit { +class Document; +using PDocument = std::shared_ptr; +class Syntaxer; +using PSyntaxer = std::shared_ptr; +class TokenAttribute; +using PTokenAttribute = std::shared_ptr; + using FormatTokenHandler = std::function; class Exporter diff --git a/libs/qsynedit/qsynedit/exporter/rtfexporter.cpp b/libs/qsynedit/qsynedit/exporter/rtfexporter.cpp index 0ef0daa4..763bcd9b 100644 --- a/libs/qsynedit/qsynedit/exporter/rtfexporter.cpp +++ b/libs/qsynedit/qsynedit/exporter/rtfexporter.cpp @@ -15,6 +15,8 @@ * along with this program. If not, see . */ #include "rtfexporter.h" + +#include namespace QSynedit { RTFExporter::RTFExporter(int tabSize, const QByteArray charset):Exporter(tabSize,charset) diff --git a/libs/qsynedit/qsynedit/formatter/cppformatter.cpp b/libs/qsynedit/qsynedit/formatter/cppformatter.cpp index a9cad608..435ba5c3 100644 --- a/libs/qsynedit/qsynedit/formatter/cppformatter.cpp +++ b/libs/qsynedit/qsynedit/formatter/cppformatter.cpp @@ -1,5 +1,6 @@ #include "cppformatter.h" #include "../qsynedit.h" +#include "../document.h" #include "../syntaxer/cpp.h" #include @@ -18,14 +19,14 @@ namespace QSynedit { QSynEdit *editor) { Q_ASSERT(editor!=nullptr); - line = std::min(line, editor->document()->count()+1); + line = std::min(line, editor->lineCount()+1); if (line<=1) return 0; // find the first non-empty preceeding line int startLine = line-1; QString startLineText; while (startLine>=1) { - startLineText = editor->document()->getLine(startLine-1); + startLineText = editor->lineText(startLine); if (!startLineText.startsWith('#') && !startLineText.trimmed().isEmpty()) { break; } @@ -87,31 +88,31 @@ namespace QSynedit { // the line the comment beginning , and add 1 additional space int commentStartLine = findCommentStartLine(startLine-1,editor); SyntaxState range; - indentSpaces = editor->leftSpaces(editor->document()->getLine(commentStartLine-1))+1; + indentSpaces = editor->leftSpaces(editor->lineText(commentStartLine))+1; range = editor->document()->getSyntaxState(commentStartLine-1); } else { //indents according to the beginning of the comment and 2 additional space int commentStartLine = findCommentStartLine(startLine-1,editor); SyntaxState range; - indentSpaces = editor->leftSpaces(editor->document()->getLine(commentStartLine-1))+2; + indentSpaces = editor->leftSpaces(editor->lineText(commentStartLine))+2; range = editor->document()->getSyntaxState(commentStartLine-1); } } else if (rangeAfterFirstToken.lastUnindent.type!=IndentType::None && firstToken=="}") { IndentInfo matchingIndents = rangeAfterFirstToken.lastUnindent; - indentSpaces = editor->leftSpaces(editor->document()->getLine(matchingIndents.line)); + indentSpaces = editor->leftSpaces(editor->lineText(matchingIndents.line+1)); } else if (firstToken=="{") { IndentInfo matchingIndents = rangeAfterFirstToken.getLastIndent(); if (matchingIndents.line!=line-1) { - indentSpaces = editor->leftSpaces(editor->document()->getLine(matchingIndents.line)); + indentSpaces = editor->leftSpaces(editor->lineText(matchingIndents.line+1)); } else if (rangeAfterFirstToken.indents.count()>=2){ IndentInfo info = rangeAfterFirstToken.indents[rangeAfterFirstToken.indents.count()-2]; - indentSpaces = editor->leftSpaces(editor->document()->getLine(info.line))+editor->tabSize(); + indentSpaces = editor->leftSpaces(editor->lineText(info.line+1))+editor->tabSize(); } else indentSpaces = 0; } else if (rangePreceeding.getLastIndentType()!=IndentType::None) { IndentInfo matchingIndents = rangePreceeding.getLastIndent(); - indentSpaces = editor->leftSpaces(editor->document()->getLine(matchingIndents.line))+editor->tabSize(); + indentSpaces = editor->leftSpaces(editor->lineText(matchingIndents.line+1))+editor->tabSize(); } else { indentSpaces = 0; } diff --git a/libs/qsynedit/qsynedit/painter.cpp b/libs/qsynedit/qsynedit/painter.cpp index 3c675c95..5ace509d 100644 --- a/libs/qsynedit/qsynedit/painter.cpp +++ b/libs/qsynedit/qsynedit/painter.cpp @@ -16,7 +16,9 @@ */ #include "painter.h" #include "qsynedit.h" +#include "document.h" #include "constants.h" +#include "syntaxer/syntaxer.h" #include #include @@ -847,7 +849,7 @@ void QSynEditPainter::paintFoldAttributes() lastNonBlank = vLine - 1; while (lastNonBlank + 1 < mEdit->mDocument->count() && mEdit->mDocument->getLine(lastNonBlank).isEmpty()) lastNonBlank++; - if (lastNonBlank>=mEdit->document()->count()) + if (lastNonBlank>=mEdit->lineCount()) continue; lineIndent = mEdit->getLineIndent(mEdit->mDocument->getLine(lastNonBlank)); int braceLevel = mEdit->mDocument->getSyntaxState(lastNonBlank).braceLevel; @@ -1158,9 +1160,7 @@ void QSynEditPainter::paintLines() tokenLeft+=tokenWidth; //We don't need to calculate line width, //So we just quit if already out of the right edge of the editor - if ( - (!calculateGlyphPositions || lineTextChanged) - && (tokenLeft>mRight)) + if (lineWidthValid && (tokenLeft>mRight)) break; // Let the highlighter scan the next token. mEdit->mSyntaxer->next(); diff --git a/libs/qsynedit/qsynedit/painter.h b/libs/qsynedit/qsynedit/painter.h index 8ac502db..919d55a5 100644 --- a/libs/qsynedit/qsynedit/painter.h +++ b/libs/qsynedit/qsynedit/painter.h @@ -21,8 +21,6 @@ #include #include #include "types.h" -#include "syntaxer/syntaxer.h" -#include "gutter.h" namespace QSynedit { struct TokenTextInfo { @@ -39,6 +37,10 @@ struct TokenBackgroundInfo { }; +class Syntaxer; +using PSyntaxer = std::shared_ptr; +class TokenAttribute; +using PTokenAttribute = std::shared_ptr; class QSynEdit; class QSynEditPainter { diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 567f4bfd..855715c4 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -15,7 +15,8 @@ * along with this program. If not, see . */ #include "qsynedit.h" -#include "syntaxer/cpp.h" +#include "document.h" +#include "syntaxer/syntaxer.h"" #include #include #include @@ -173,6 +174,11 @@ QSynEdit::QSynEdit(QWidget *parent) : QAbstractScrollArea(parent), setScrollBars(ScrollStyle::Both); } +int QSynEdit::lineCount() const +{ + return mDocument->count(); +} + int QSynEdit::displayLineCount() const { if (mDocument->empty()) { @@ -4019,12 +4025,16 @@ void QSynEdit::setTabSize(int newTabSize) } } +int QSynEdit::tabWidth() const +{ + return mDocument->tabWidth(); +} + EditorOptions QSynEdit::getOptions() const { return mOptions; } - static bool sameEditorOption(const EditorOptions& value1, const EditorOptions& value2, EditorOption flag) { return value1.testFlag(flag)==value2.testFlag(flag); } @@ -4061,6 +4071,11 @@ void QSynEdit::setOptions(const EditorOptions &value) } } +int QSynEdit::tabSize() const +{ + return mDocument->tabSize(); +} + void QSynEdit::doAddStr(const QString &s) { if (mInserting == false && !selAvail()) { @@ -4656,6 +4671,11 @@ QString QSynEdit::lineText() const return QString(); } +QString QSynEdit::lineText(int line) const +{ + return mDocument->getLine(line-1); +} + void QSynEdit::setLineText(const QString s) { if (mCaretY >= 1 && mCaretY <= mDocument->count()) @@ -4890,7 +4910,7 @@ void QSynEdit::moveCaretToLineEnd(bool isSelection, bool ensureCaretVisible) void QSynEdit::doGotoBlockStart(bool isSelection) { - if (mCaretY<0 || mCaretY>document()->count()) + if (mCaretY<0 || mCaretY>lineCount()) return; SyntaxState state = document()->getSyntaxState(mCaretY-1); //todo: handle block other than {} @@ -4913,7 +4933,7 @@ void QSynEdit::doGotoBlockStart(bool isSelection) void QSynEdit::doGotoBlockEnd(bool isSelection) { - if (mCaretY<0 || mCaretY>document()->count()) + if (mCaretY<0 || mCaretY>lineCount()) return; SyntaxState state = document()->getSyntaxState(mCaretY-1); //todo: handle block other than {} @@ -4921,7 +4941,7 @@ void QSynEdit::doGotoBlockEnd(bool isSelection) doGotoEditorEnd(isSelection); } else if (document()->blockEnded(mCaretY-1)==0){ int line=mCaretY+1; - while (line<=document()->count()) { + while (line<=lineCount()) { if (document()->blockEnded(line-1)>document()->blockStarted(line-1)) { moveCaretVert(line-1-mCaretY, isSelection); moveCaretToLineStart(isSelection); diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 9c589cdc..91077935 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -27,7 +27,6 @@ #include "gutter.h" #include "codefolding.h" #include "types.h" -#include "document.h" #include "keystrokes.h" #include "searcher/baseseacher.h" #include "formatter/formatter.h" @@ -85,11 +84,11 @@ enum class EditorOption { AutoHideScrollbars = 0x00000200, //if enabled, then the scrollbars will only show when necessary. If you have ScrollPastEOL, then it the horizontal bar will always be there (it uses MaxLength instead) KeepCaretX = 0x00000400 , //When moving through lines w/o Cursor Past EOL, keeps the X position of the cursor RightMouseMovesCursor= 0x00000800, //When clicking with the right mouse for a popup menu, move the cursor to that location -// eoScrollByOneLess = 0x00001000, //Forces scrolling to be one less +// ScrollByOneLess = 0x00001000, //Forces scrolling to be one less ScrollPastEof = 0x00002000, //Allows the cursor to go past the end of file marker ScrollPastEol = 0x00004000, //Allows the cursor to go past the last character into the white space at the end of a line InvertMouseScroll = 0x00008000, //Shows the special Characters -// eoSpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event +// SpecialLineDefaultFg = 0x00010000, //disables the foreground text color override when using the OnSpecialLineColor event TabIndent = 0x00020000, //When active and act as block indent, unindent when text is selected TabsToSpaces = 0x00040000, //Converts a tab character to a specified number of space characters ShowRainbowColor = 0x00080000, @@ -135,6 +134,18 @@ struct GlyphPostionsListCache { class QSynEdit; using PSynEdit = std::shared_ptr; +class TokenAttribute; +using PTokenAttribute = std::shared_ptr; +class Document; +using PDocument = std::shared_ptr; +class SyntaxState; +class Syntaxer; +using PSyntaxer = std::shared_ptr; +class UndoList; +class RedoList; +using PUndoList = std::shared_ptr; +using PRedoList = std::shared_ptr; + class QSynEdit : public QAbstractScrollArea { Q_OBJECT @@ -143,6 +154,8 @@ public: QSynEdit(const QSynEdit&)=delete; QSynEdit& operator=(const QSynEdit&)=delete; + + int lineCount() const; /** * Returns how many rows are there in the editor * @return @@ -361,9 +374,7 @@ public: QString displayLineText(); QString lineText() const; - QString lineText(int line) const { - return mDocument->getLine(line-1); - } + QString lineText(int line) const; void setLineText(const QString s); const PDocument& document() const; @@ -380,9 +391,9 @@ public: EditorOptions getOptions() const; void setOptions(const EditorOptions &Value); - int tabSize() const { return mDocument->tabSize(); } + int tabSize() const; void setTabSize(int tabSize); - int tabWidth() const { return mDocument->tabWidth(); } + int tabWidth() const; QColor caretColor() const; void setCaretColor(const QColor &caretColor); diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h index dcb7e8f0..3ce0ed7f 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h @@ -114,7 +114,7 @@ private: TokenType mTokenType; }; -typedef std::shared_ptr PTokenAttribute; +using PTokenAttribute = std::shared_ptr ; class Syntaxer { public: