work save: header completion suggestion done

This commit is contained in:
royqh1979@gmail.com 2021-08-29 10:14:07 +08:00
parent f1ae5bfdfd
commit 7207994d57
21 changed files with 357 additions and 164 deletions

View File

@ -3,6 +3,7 @@ QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++17 CONFIG += c++17
CONFIG += nokey
QMAKE_CXXFLAGS_RELEASE += -Werror=return-type QMAKE_CXXFLAGS_RELEASE += -Werror=return-type
QMAKE_CXXFLAGS_DEBUG += -Werror=return-type QMAKE_CXXFLAGS_DEBUG += -Werror=return-type

View File

@ -91,7 +91,7 @@ int Compiler::getLineNumberFromOutputLine(QString &line)
pos = line.indexOf(','); pos = line.indexOf(',');
} }
if (pos>=0) { if (pos>=0) {
result = line.mid(0,pos).toInt(); result = line.midRef(0,pos).toInt();
if (result > 0) if (result > 0)
line.remove(0,pos+1); line.remove(0,pos+1);
} }
@ -107,7 +107,7 @@ int Compiler::getColunmnFromOutputLine(QString &line)
pos = line.indexOf(','); pos = line.indexOf(',');
} }
if (pos>=0) { if (pos>=0) {
result = line.mid(0,pos).toInt(); result = line.midRef(0,pos).toInt();
if (result > 0) if (result > 0)
line.remove(0,pos+1); line.remove(0,pos+1);
} }
@ -154,7 +154,6 @@ void Compiler::processOutput(QString &line)
QString inFilePrefix = QString("In file included from "); QString inFilePrefix = QString("In file included from ");
QString fromPrefix = QString("from "); QString fromPrefix = QString("from ");
PCompileIssue issue = std::make_shared<CompileIssue>(); PCompileIssue issue = std::make_shared<CompileIssue>();
QString description;
issue->type = CompileIssueType::Other; issue->type = CompileIssueType::Other;
issue->endColumn = -1; issue->endColumn = -1;
if (line.startsWith(inFilePrefix)) { if (line.startsWith(inFilePrefix)) {
@ -252,8 +251,7 @@ QString Compiler::getCharsetArgument(const QByteArray& encoding)
encodingName = encoding; encodingName = encoding;
} }
result += QString(" -finput-charset=%1 -fexec-charset=%2") result += QString(" -finput-charset=%1 -fexec-charset=%2")
.arg(encodingName) .arg(encodingName,systemEncodingName);
.arg(systemEncodingName);
} }
return result; return result;
} }
@ -265,7 +263,7 @@ QString Compiler::getCCompileArguments(bool checkSyntax)
result += " -fsyntax-only"; result += " -fsyntax-only";
} }
for (PCompilerOption pOption: compilerSet()->options()) { foreach (const PCompilerOption& pOption, compilerSet()->options()) {
if (pOption->value > 0 && pOption->isC) { if (pOption->value > 0 && pOption->isC) {
if (pOption->choices.isEmpty()) { if (pOption->choices.isEmpty()) {
result += " " + pOption->setting; result += " " + pOption->setting;
@ -291,7 +289,7 @@ QString Compiler::getCppCompileArguments(bool checkSyntax)
result += " -fsyntax-only"; result += " -fsyntax-only";
} }
for (PCompilerOption pOption: compilerSet()->options()) { foreach (const PCompilerOption& pOption, compilerSet()->options()) {
if (pOption->value > 0 && pOption->isCpp) { if (pOption->value > 0 && pOption->isCpp) {
if (pOption->choices.isEmpty()) { if (pOption->choices.isEmpty()) {
result += " "+pOption->setting; result += " "+pOption->setting;
@ -314,7 +312,7 @@ QString Compiler::getCppCompileArguments(bool checkSyntax)
QString Compiler::getCIncludeArguments() QString Compiler::getCIncludeArguments()
{ {
QString result; QString result;
for (const QString& folder:compilerSet()->CIncludeDirs()) { foreach (const QString& folder,compilerSet()->CIncludeDirs()) {
result += QString(" -I\"%1\"").arg(folder); result += QString(" -I\"%1\"").arg(folder);
} }
return result; return result;
@ -323,7 +321,7 @@ QString Compiler::getCIncludeArguments()
QString Compiler::getCppIncludeArguments() QString Compiler::getCppIncludeArguments()
{ {
QString result; QString result;
for (const QString& folder:compilerSet()->CppIncludeDirs()) { foreach (const QString& folder,compilerSet()->CppIncludeDirs()) {
result += QString(" -I\"%1\"").arg(folder); result += QString(" -I\"%1\"").arg(folder);
} }
return result; return result;
@ -333,7 +331,7 @@ QString Compiler::getLibraryArguments()
{ {
QString result; QString result;
for (const QString& folder:compilerSet()->libDirs()) { foreach (const QString& folder, compilerSet()->libDirs()) {
result += QString(" -L\"%1\"").arg(folder); result += QString(" -L\"%1\"").arg(folder);
} }
@ -343,7 +341,7 @@ QString Compiler::getLibraryArguments()
} }
//options like "-static" must be added after "-lxxx" //options like "-static" must be added after "-lxxx"
for (PCompilerOption pOption: compilerSet()->options()) { foreach (const PCompilerOption& pOption, compilerSet()->options()) {
if (pOption->value > 0 && pOption->isLinker) { if (pOption->value > 0 && pOption->isLinker) {
if (pOption->choices.isEmpty()) { if (pOption->choices.isEmpty()) {
result += " " + pOption->setting; result += " " + pOption->setting;
@ -377,7 +375,7 @@ void Compiler::runCommand(const QString &cmd, const QString &arguments, const Q
process.connect(&process, &QProcess::readyReadStandardOutput,[&process,this](){ process.connect(&process, &QProcess::readyReadStandardOutput,[&process,this](){
this->log(QString::fromLocal8Bit( process.readAllStandardOutput())); this->log(QString::fromLocal8Bit( process.readAllStandardOutput()));
}); });
process.connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),[&process,this](){ process.connect(&process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),[this](){
this->error(COMPILE_PROCESS_END); this->error(COMPILE_PROCESS_END);
}); });
process.start(); process.start();

View File

@ -29,15 +29,17 @@ using namespace std;
SaveException::SaveException(const QString& reason) { SaveException::SaveException(const QString& reason) {
mReason = reason; mReason = reason;
mReasonBuffer = mReason.toLocal8Bit();
} }
SaveException::SaveException(const QString&& reason) { SaveException::SaveException(const QString&& reason) {
mReason = reason; mReason = reason;
mReasonBuffer = mReason.toLocal8Bit();
} }
const QString& SaveException::reason() const noexcept{ const QString& SaveException::reason() const noexcept{
return mReason; return mReason;
} }
const char *SaveException::what() const noexcept { const char* SaveException::what() const noexcept {
return mReason.toLocal8Bit(); return mReasonBuffer;
} }
int Editor::newfileCount=0; int Editor::newfileCount=0;
@ -98,6 +100,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
initParser(); initParser();
} }
mCompletionPopup = std::make_shared<CodeCompletionPopup>(); mCompletionPopup = std::make_shared<CodeCompletionPopup>();
mHeaderCompletionPopup = std::make_shared<HeaderCompletionPopup>();
applySettings(); applySettings();
applyColorScheme(pSettings->editor().colorScheme()); applyColorScheme(pSettings->editor().colorScheme());
@ -255,8 +258,8 @@ void Editor::undoSymbolCompletion(int pos)
if (pos<0 || pos+1>=lineText().length()) if (pos<0 || pos+1>=lineText().length())
return; return;
QChar DeletedChar = lineText()[pos]; QChar DeletedChar = lineText().at(pos);
QChar NextChar = lineText()[pos+1]; QChar NextChar = lineText().at(pos+1);
if ((tokenType == SynHighlighterTokenType::Character) && (DeletedChar != '\'')) if ((tokenType == SynHighlighterTokenType::Character) && (DeletedChar != '\''))
return; return;
if (tokenType == SynHighlighterTokenType::StringEscapeSequence) if (tokenType == SynHighlighterTokenType::StringEscapeSequence)
@ -454,7 +457,7 @@ void Editor::onGutterPaint(QPainter &painter, int aLine, int X, int Y)
PSyntaxIssueList lst = getSyntaxIssuesAtLine(aLine); PSyntaxIssueList lst = getSyntaxIssuesAtLine(aLine);
if (lst) { if (lst) {
bool hasError=false; bool hasError=false;
for (PSyntaxIssue issue : *lst) { for (const PSyntaxIssue& issue : *lst) {
if (issue->issueType == CompileIssueType::Error) { if (issue->issueType == CompileIssueType::Error) {
hasError = true; hasError = true;
break;; break;;
@ -488,7 +491,7 @@ void Editor::onGetEditingAreas(int Line, SynEditingAreaList &areaList)
// StrToThemeColor(tc,devEditor.Syntax.Values[cWN]); // StrToThemeColor(tc,devEditor.Syntax.Values[cWN]);
PSyntaxIssueList lst = getSyntaxIssuesAtLine(Line); PSyntaxIssueList lst = getSyntaxIssuesAtLine(Line);
if (lst) { if (lst) {
for (PSyntaxIssue issue: *lst) { for (const PSyntaxIssue& issue: *lst) {
PSynEditingArea p=std::make_shared<SynEditingArea>(); PSynEditingArea p=std::make_shared<SynEditingArea>();
p->beginX = issue->col; p->beginX = issue->col;
p->endX = issue->endCol; p->endX = issue->endCol;
@ -556,6 +559,7 @@ void Editor::onPreparePaintHighlightToken(int row, int column, const QString &to
StatementKind kind = mParser->getKindOfStatement(statement); StatementKind kind = mParser->getKindOfStatement(statement);
if (kind == StatementKind::skUnknown) { if (kind == StatementKind::skUnknown) {
if ((pEndPos.Line>=1) if ((pEndPos.Line>=1)
&& (pEndPos.Char>=0)
&& (pEndPos.Char < lines()->getString(pEndPos.Line-1).length()) && (pEndPos.Char < lines()->getString(pEndPos.Line-1).length())
&& (lines()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) { && (lines()->getString(pEndPos.Line-1)[pEndPos.Char] == '(')) {
kind = StatementKind::skFunction; kind = StatementKind::skFunction;
@ -760,7 +764,7 @@ Editor::PSyntaxIssueList Editor::getSyntaxIssuesAtLine(int line)
Editor::PSyntaxIssue Editor::getSyntaxIssueAtPosition(const BufferCoord &pos) Editor::PSyntaxIssue Editor::getSyntaxIssueAtPosition(const BufferCoord &pos)
{ {
PSyntaxIssueList lst = getSyntaxIssuesAtLine(pos.Line); PSyntaxIssueList lst = getSyntaxIssuesAtLine(pos.Line);
for (PSyntaxIssue issue: *lst) { foreach (const PSyntaxIssue& issue, *lst) {
if (issue->startChar<=pos.Char && pos.Char<=issue->endChar) if (issue->startChar<=pos.Char && pos.Char<=issue->endChar)
return issue; return issue;
} }
@ -865,7 +869,7 @@ void Editor::onStatusChanged(SynStatusChanges changes)
// mainForm.CaretList.AddCaret(self,fText.CaretY,fText.CaretX); // mainForm.CaretList.AddCaret(self,fText.CaretY,fText.CaretX);
} }
void Editor::onGutterClicked(Qt::MouseButton button, int x, int y, int line) void Editor::onGutterClicked(Qt::MouseButton button, int , int , int line)
{ {
if (button == Qt::LeftButton) { if (button == Qt::LeftButton) {
toggleBreakpoint(line); toggleBreakpoint(line);
@ -878,7 +882,7 @@ QChar Editor::getCurrentChar()
if (lineText().length()<caretX()) if (lineText().length()<caretX())
return QChar(); return QChar();
else else
return lineText()[caretX()-1]; return lineText().at(caretX()-1);
} }
bool Editor::handleSymbolCompletion(QChar key) bool Editor::handleSymbolCompletion(QChar key)
@ -1429,7 +1433,50 @@ void Editor::showCompletion(bool autoComplete)
void Editor::showHeaderCompletion(bool autoComplete) void Editor::showHeaderCompletion(bool autoComplete)
{ {
//todo: // if not devCodeCompletion.Enabled then
// Exit;
if (mHeaderCompletionPopup->isVisible()) // already in search, don't do it again
return;
// Position it at the top of the next line
QPoint p = RowColumnToPixels(displayXY());
p.setY(p.y() + textHeight() + 2);
mHeaderCompletionPopup->move(mapToGlobal(p));
// fHeaderCompletionBox.IgnoreCase := devCodeCompletion.IgnoreCase;
// fHeaderCompletionBox.ShowCount := devCodeCompletion.MaxCount;
//Set Font size;
mHeaderCompletionPopup->setFont(font());
// Redirect key presses to completion box if applicable
mHeaderCompletionPopup->setKeypressedCallback([this](QKeyEvent* event)->bool{
return onHeaderCompletionKeyPressed(event);
});
mHeaderCompletionPopup->setParser(mParser);
BufferCoord pBeginPos,pEndPos;
QString word = getWordAtPosition(caretXY(),pBeginPos,pEndPos,
WordPurpose::wpHeaderCompletionStart);
if (word.isEmpty())
return;
if (!word.startsWith('"') && !word.startsWith('<'))
return;
if (word.lastIndexOf('"')>0 || word.lastIndexOf('>')>0)
return;
mHeaderCompletionPopup->show();
mHeaderCompletionPopup->setSearchLocal(word.startsWith('"'));
word.remove(0,1);
mHeaderCompletionPopup->prepareSearch(word, mFilename);
// Filter the whole statement list
if (mHeaderCompletionPopup->search(word, autoComplete)) //only one suggestion and it's not input while typing
headerCompletionInsert(); // if only have one suggestion, just use it
} }
bool Editor::testInFunc(int x, int y) bool Editor::testInFunc(int x, int y)
@ -1503,7 +1550,7 @@ void Editor::completionInsert(bool appendFunc)
|| statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::skConstructor
|| statement->kind == StatementKind::skDestructor) { || statement->kind == StatementKind::skDestructor) {
if ((p.Char >= lineText().length()) // it's the last char on line if ((p.Char >= lineText().length()) // it's the last char on line
|| (lineText()[p.Char] != '(')) { // it don't have '(' after it || (lineText().at(p.Char) != '(')) { // it don't have '(' after it
if (statement->fullName!="std::endl") if (statement->fullName!="std::endl")
funcAddOn = "()"; funcAddOn = "()";
} }
@ -1546,11 +1593,46 @@ void Editor::completionInsert(bool appendFunc)
mCompletionPopup->hide(); mCompletionPopup->hide();
} }
void Editor::headerCompletionInsert()
{
QString headerName = mHeaderCompletionPopup->selectedFilename();
if (headerName.isEmpty())
return;
// delete the part of the word that's already been typed ...
BufferCoord p = caretXY();
int posBegin = p.Char-1;
int posEnd = p.Char-1;
QString sLine = lineText();
while ((posBegin>0) &&
(isIdentChar(sLine[posBegin-1]) || (sLine[posBegin-1]=='.')))
posBegin--;
while ((posEnd < sLine.length())
&& (isIdentChar(sLine[posEnd]) || (sLine[posEnd]=='.')))
posEnd++;
p.Char = posBegin+1;
setBlockBegin(p);
p.Char = posEnd+1;
setBlockEnd(p);
setSelText(headerName);
mCompletionPopup->hide();
}
bool Editor::onCompletionKeyPressed(QKeyEvent *event) bool Editor::onCompletionKeyPressed(QKeyEvent *event)
{ {
bool processed = false; bool processed = false;
if (!mCompletionPopup->isEnabled()) if (!mCompletionPopup->isEnabled())
return false; return false;
QString oldPhrase = mCompletionPopup->phrase();
WordPurpose purpose = WordPurpose::wpCompletion;
if (oldPhrase.startsWith('#')) {
purpose = WordPurpose::wpDirective;
} else if (oldPhrase.startsWith('@')) {
purpose = WordPurpose::wpJavadoc;
}
QString phrase; QString phrase;
BufferCoord pBeginPos,pEndPos; BufferCoord pBeginPos,pEndPos;
switch (event->key()) { switch (event->key()) {
@ -1560,7 +1642,7 @@ bool Editor::onCompletionKeyPressed(QKeyEvent *event)
QChar(), nullptr); // Simulate backspace in editor QChar(), nullptr); // Simulate backspace in editor
phrase = getWordAtPosition(caretXY(), phrase = getWordAtPosition(caretXY(),
pBeginPos,pEndPos, pBeginPos,pEndPos,
WordPurpose::wpCompletion); purpose);
mLastIdCharPressed = phrase.length(); mLastIdCharPressed = phrase.length();
mCompletionPopup->search(phrase, false); mCompletionPopup->search(phrase, false);
return true; return true;
@ -1583,9 +1665,9 @@ bool Editor::onCompletionKeyPressed(QKeyEvent *event)
QChar ch = event->text().front(); QChar ch = event->text().front();
if (isIdentChar(ch)) { if (isIdentChar(ch)) {
setSelText(ch); setSelText(ch);
phrase = phrase = getWordAtPosition(caretXY(), phrase = getWordAtPosition(caretXY(),
pBeginPos,pEndPos, pBeginPos,pEndPos,
WordPurpose::wpCompletion); purpose);
mLastIdCharPressed = phrase.length(); mLastIdCharPressed = phrase.length();
mCompletionPopup->search(phrase, false); mCompletionPopup->search(phrase, false);
return true; return true;
@ -1598,6 +1680,59 @@ bool Editor::onCompletionKeyPressed(QKeyEvent *event)
return processed; return processed;
} }
bool Editor::onHeaderCompletionKeyPressed(QKeyEvent *event)
{
bool processed = false;
if (!mCompletionPopup->isEnabled())
return false;
QString phrase;
BufferCoord pBeginPos,pEndPos;
switch (event->key()) {
case Qt::Key_Backspace:
ExecuteCommand(
SynEditorCommand::ecDeleteLastChar,
QChar(), nullptr); // Simulate backspace in editor
phrase = getWordAtPosition(caretXY(),
pBeginPos,pEndPos,
WordPurpose::wpHeaderCompletion);
mLastIdCharPressed = phrase.length();
mHeaderCompletionPopup->search(phrase, false);
return true;
case Qt::Key_Escape:
mHeaderCompletionPopup->hide();
return true;
case Qt::Key_Return:
case Qt::Key_Tab:
//CompletionInsert(devCodeCompletion.AppendFunc);
headerCompletionInsert();
mHeaderCompletionPopup->hide();
return true;
default:
if (event->text().isEmpty()) {
//stop completion
mHeaderCompletionPopup->hide();
keyPressEvent(event);
return true;
}
}
QChar ch = event->text().front();
if (isIdentChar(ch)) {
setSelText(ch);
phrase = getWordAtPosition(caretXY(),
pBeginPos,pEndPos,
WordPurpose::wpHeaderCompletion);
mLastIdCharPressed = phrase.length();
mHeaderCompletionPopup->search(phrase, false);
return true;
} else {
//stop completion
mHeaderCompletionPopup->hide();
keyPressEvent(event);
return true;
}
return processed;
}
QString Editor::getWordAtPosition(const BufferCoord &p, BufferCoord &pWordBegin, BufferCoord &pWordEnd, WordPurpose purpose) QString Editor::getWordAtPosition(const BufferCoord &p, BufferCoord &pWordBegin, BufferCoord &pWordEnd, WordPurpose purpose)
{ {
QString result = ""; QString result = "";
@ -2066,6 +2201,7 @@ void Editor::applyColorScheme(const QString& schemeName)
if (item) { if (item) {
mCompletionPopup->colors().insert(StatementKind::skPreprocessor,item->foreground()); mCompletionPopup->colors().insert(StatementKind::skPreprocessor,item->foreground());
mCompletionPopup->colors().insert(StatementKind::skEnum,item->foreground()); mCompletionPopup->colors().insert(StatementKind::skEnum,item->foreground());
mHeaderCompletionPopup->setSuggestionColor(item->foreground());
} }
item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord); item = pColorManager->getItem(schemeName, SYNS_AttrReservedWord);
if (item) { if (item) {

View File

@ -9,6 +9,7 @@
#include "common.h" #include "common.h"
#include "parser/cppparser.h" #include "parser/cppparser.h"
#include "widgets/codecompletionpopup.h" #include "widgets/codecompletionpopup.h"
#include "widgets/headercompletionpopup.h"
class SaveException: public std::exception { class SaveException: public std::exception {
@ -21,6 +22,7 @@ public:
const char *what() const noexcept override; const char *what() const noexcept override;
private: private:
QString mReason; QString mReason;
QByteArray mReasonBuffer;
}; };
class Editor : public SynEdit class Editor : public SynEdit
@ -169,7 +171,10 @@ private:
void completionInsert(bool appendFunc=false); void completionInsert(bool appendFunc=false);
void headerCompletionInsert();
bool onCompletionKeyPressed(QKeyEvent* event); bool onCompletionKeyPressed(QKeyEvent* event);
bool onHeaderCompletionKeyPressed(QKeyEvent* event);
private: private:
static int newfileCount; static int newfileCount;
@ -193,6 +198,7 @@ private:
int mActiveBreakpointLine; int mActiveBreakpointLine;
PCppParser mParser; PCppParser mParser;
std::shared_ptr<CodeCompletionPopup> mCompletionPopup; std::shared_ptr<CodeCompletionPopup> mCompletionPopup;
std::shared_ptr<HeaderCompletionPopup> mHeaderCompletionPopup;
int mLastIdCharPressed; int mLastIdCharPressed;
bool mUseCppSyntax; bool mUseCppSyntax;

View File

@ -32,11 +32,11 @@ MainWindow* pMainWindow;
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), : QMainWindow(parent),
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
mSearchDialog(nullptr),
mQuitting(false),
mMessageControlChanged(false), mMessageControlChanged(false),
mTabMessagesTogglingState(false), mTabMessagesTogglingState(false),
mCheckSyntaxInBack(false), mCheckSyntaxInBack(false)
mSearchDialog(nullptr),
mQuitting(false)
{ {
ui->setupUi(this); ui->setupUi(this);
// status bar // status bar
@ -135,8 +135,8 @@ void MainWindow::updateForEncodingInfo() {
if (editor!=NULL) { if (editor!=NULL) {
mFileEncodingStatus->setText( mFileEncodingStatus->setText(
QString("%1(%2)") QString("%1(%2)")
.arg(QString(editor->encodingOption())) .arg(QString(editor->encodingOption())
.arg(QString(editor->fileEncoding()))); ,QString(editor->fileEncoding())));
ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT); ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT);
ui->actionEncode_in_ANSI->setChecked(editor->encodingOption() == ENCODING_SYSTEM_DEFAULT); ui->actionEncode_in_ANSI->setChecked(editor->encodingOption() == ENCODING_SYSTEM_DEFAULT);
ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8); ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8);
@ -304,23 +304,25 @@ void MainWindow::updateAppTitle()
else else
str = e->filename(); str = e->filename();
if (mDebugger->executing()) { if (mDebugger->executing()) {
setWindowTitle(QString("%1 - [%2] - %3 %4").arg(str).arg(appName) setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(tr("Debugging")).arg(DEVCPP_VERSION)); .arg(str,appName,tr("Debugging"),DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3").arg(str).arg(appName) app->setApplicationName(QString("%1 - [%2] - %3")
.arg(tr("Debugging"))); .arg(str,appName,tr("Debugging")));
} else if (mCompilerManager->running()) { } else if (mCompilerManager->running()) {
setWindowTitle(QString("%1 - [%2] - %3 %4").arg(str).arg(appName) setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(tr("Running")).arg(DEVCPP_VERSION)); .arg(str,appName,tr("Running"),DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3").arg(str).arg(appName) app->setApplicationName(QString("%1 - [%2] - %3")
.arg(tr("Running"))); .arg(str,appName,tr("Running")));
} else if (mCompilerManager->compiling()) { } else if (mCompilerManager->compiling()) {
setWindowTitle(QString("%1 - [%2] - %3 %4").arg(str).arg(appName) setWindowTitle(QString("%1 - [%2] - %3 %4")
.arg(tr("Compiling")).arg(DEVCPP_VERSION)); .arg(str,appName,tr("Compiling"),DEVCPP_VERSION));
app->setApplicationName(QString("%1 - [%2] - %3").arg(str).arg(appName) app->setApplicationName(QString("%1 - [%2] - %3")
.arg(tr("Compiling"))); .arg(str,appName,tr("Compiling")));
} else { } else {
this->setWindowTitle(QString("%1 - %2 %3").arg(str).arg(appName).arg(DEVCPP_VERSION)); this->setWindowTitle(QString("%1 - %2 %3")
app->setApplicationName(QString("%1 - %2").arg(str).arg(appName)); .arg(str,appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1 - %2")
.arg(str,appName));
} }
} }
// else if Assigned(fProject) then begin // else if Assigned(fProject) then begin
@ -342,7 +344,7 @@ void MainWindow::updateAppTitle()
// Application.Title := Format('%s - %s', [fProject.Name, appName]); // Application.Title := Format('%s - %s', [fProject.Name, appName]);
// end; // end;
else { else {
setWindowTitle(QString("%1 %2").arg(appName).arg(DEVCPP_VERSION)); setWindowTitle(QString("%1 %2").arg(appName,DEVCPP_VERSION));
app->setApplicationName(QString("%1").arg(appName)); app->setApplicationName(QString("%1").arg(appName));
} }
} }
@ -370,7 +372,7 @@ void MainWindow::updateDebugEval(const QString &value)
void MainWindow::rebuildOpenedFileHisotryMenu() void MainWindow::rebuildOpenedFileHisotryMenu()
{ {
mMenuRecentFiles->clear(); mMenuRecentFiles->clear();
for (QAction* action:mRecentFileActions) { foreach (QAction* action,mRecentFileActions) {
action->setParent(nullptr); action->setParent(nullptr);
action->deleteLater(); action->deleteLater();
} }
@ -379,10 +381,10 @@ void MainWindow::rebuildOpenedFileHisotryMenu()
mMenuRecentFiles->setEnabled(false); mMenuRecentFiles->setEnabled(false);
} else { } else {
mMenuRecentFiles->setEnabled(true); mMenuRecentFiles->setEnabled(true);
for (QString filename: pSettings->history().openedFiles()) { for (const QString& filename: pSettings->history().openedFiles()) {
QAction* action = new QAction(); QAction* action = new QAction();
action->setText(filename); action->setText(filename);
connect(action, &QAction::triggered, [filename,this](bool checked = false){ connect(action, &QAction::triggered, [&filename,this](bool){
this->openFile(filename); this->openFile(filename);
}); });
mRecentFileActions.append(action); mRecentFileActions.append(action);
@ -471,7 +473,7 @@ void MainWindow::openFiles(const QStringList &files)
auto end = finally([this] { auto end = finally([this] {
this->mEditorList->endUpdate(); this->mEditorList->endUpdate();
}); });
for (QString file:files) { for (const QString& file:files) {
openFile(file); openFile(file);
} }
mEditorList->endUpdate(); mEditorList->endUpdate();
@ -804,16 +806,16 @@ void MainWindow::debug()
updateEditorActions(); updateEditorActions();
// Add library folders // Add library folders
for (QString dir:compilerSet->libDirs()) { foreach (QString dir,compilerSet->libDirs()) {
mDebugger->sendCommand("dir", mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/'))); QString("\"%1\"").arg(dir.replace('\\','/')));
} }
// Add include folders // Add include folders
for (QString dir:compilerSet->CIncludeDirs()) { foreach (QString dir,compilerSet->CIncludeDirs()) {
mDebugger->sendCommand("dir", mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/'))); QString("\"%1\"").arg(dir.replace('\\','/')));
} }
for (QString dir:compilerSet->CppIncludeDirs()) { foreach (QString dir,compilerSet->CppIncludeDirs()) {
mDebugger->sendCommand("dir", mDebugger->sendCommand("dir",
QString("\"%1\"").arg(dir.replace('\\','/'))); QString("\"%1\"").arg(dir.replace('\\','/')));
} }
@ -1123,7 +1125,7 @@ void MainWindow::onCompileFinished()
if (issue->type == CompileIssueType::Error) { if (issue->type == CompileIssueType::Error) {
ui->tableIssues->selectRow(i); ui->tableIssues->selectRow(i);
QModelIndex index =ui->tableIssues->model()->index(i,0); QModelIndex index =ui->tableIssues->model()->index(i,0);
ui->tableIssues->doubleClicked(index); emit ui->tableIssues->doubleClicked(index);
} }
} }
@ -1133,7 +1135,7 @@ void MainWindow::onCompileFinished()
if (issue->type == CompileIssueType::Warning) { if (issue->type == CompileIssueType::Warning) {
ui->tableIssues->selectRow(i); ui->tableIssues->selectRow(i);
QModelIndex index =ui->tableIssues->model()->index(i,0); QModelIndex index =ui->tableIssues->model()->index(i,0);
ui->tableIssues->doubleClicked(index); emit ui->tableIssues->doubleClicked(index);
} }
} }
// Then try to find anything with a line number... // Then try to find anything with a line number...
@ -1452,13 +1454,13 @@ bool MainWindow::debugInferiorhasBreakpoint()
if (e==nullptr) if (e==nullptr)
return false; return false;
if (!e->inProject()) { if (!e->inProject()) {
for (PBreakpoint breakpoint:mDebugger->breakpointModel()->breakpoints()) { for (const PBreakpoint& breakpoint:mDebugger->breakpointModel()->breakpoints()) {
if (e->filename() == breakpoint->filename) { if (e->filename() == breakpoint->filename) {
return true; return true;
} }
} }
} else { } else {
for (PBreakpoint breakpoint:mDebugger->breakpointModel()->breakpoints()) { for (const PBreakpoint& breakpoint:mDebugger->breakpointModel()->breakpoints()) {
Editor* e1 = mEditorList->getOpenedEditorByFilename(breakpoint->filename); Editor* e1 = mEditorList->getOpenedEditorByFilename(breakpoint->filename);
if (e1->inProject()) { if (e1->inProject()) {
return true; return true;

View File

@ -381,7 +381,7 @@ PStatement CppParser::findStatementStartingFrom(const QString &fileName, const Q
return result; return result;
// not found // not found
// search members of all usings (in current scope ) // search members of all usings (in current scope )
for (const QString& namespaceName:scopeStatement->usingList) { foreach (const QString& namespaceName, scopeStatement->usingList) {
result = findStatementInNamespace(phrase,namespaceName); result = findStatementInNamespace(phrase,namespaceName);
if (result) if (result)
return result; return result;
@ -514,7 +514,7 @@ QSet<QString> CppParser::getFileIncludes(const QString &filename)
PFileIncludes fileIncludes = mPreprocessor.includesList().value(filename,PFileIncludes()); PFileIncludes fileIncludes = mPreprocessor.includesList().value(filename,PFileIncludes());
if (fileIncludes) { if (fileIncludes) {
for (const QString& file: fileIncludes->includeFiles.keys()) { foreach (const QString& file, fileIncludes->includeFiles.keys()) {
list.insert(file); list.insert(file);
} }
} }
@ -636,7 +636,7 @@ void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNo
mFilesScannedCount = 0; mFilesScannedCount = 0;
// parse header files in the first parse // parse header files in the first parse
for (const QString& file:files) { foreach (const QString& file,files) {
if (isHfile(file)) { if (isHfile(file)) {
mFilesScannedCount++; mFilesScannedCount++;
emit onProgress(file,mFilesToScanCount,mFilesScannedCount); emit onProgress(file,mFilesToScanCount,mFilesScannedCount);
@ -646,7 +646,7 @@ void CppParser::parseFile(const QString &fileName, bool inProject, bool onlyIfNo
} }
} }
//we only parse CFile in the second parse //we only parse CFile in the second parse
for (const QString& file:files) { foreach (const QString& file,files) {
if (isCfile(file)) { if (isCfile(file)) {
mFilesScannedCount++; mFilesScannedCount++;
emit onProgress(file,mFilesToScanCount,mFilesScannedCount); emit onProgress(file,mFilesToScanCount,mFilesScannedCount);
@ -684,7 +684,7 @@ void CppParser::parseFileList(bool updateView)
mFilesScannedCount = 0; mFilesScannedCount = 0;
mFilesToScanCount = mFilesToScan.count(); mFilesToScanCount = mFilesToScan.count();
// parse header files in the first parse // parse header files in the first parse
for (const QString& file:mFilesToScan) { foreach (const QString& file, mFilesToScan) {
if (isHfile(file)) { if (isHfile(file)) {
mFilesScannedCount++; mFilesScannedCount++;
emit onProgress(mCurrentFile,mFilesToScanCount,mFilesScannedCount); emit onProgress(mCurrentFile,mFilesToScanCount,mFilesScannedCount);
@ -694,7 +694,7 @@ void CppParser::parseFileList(bool updateView)
} }
} }
//we only parse CFile in the second parse //we only parse CFile in the second parse
for (const QString& file:mFilesToScan) { foreach (const QString& file,mFilesToScan) {
if (isCfile(file)) { if (isCfile(file)) {
mFilesScannedCount++; mFilesScannedCount++;
emit onProgress(mCurrentFile,mFilesToScanCount,mFilesScannedCount); emit onProgress(mCurrentFile,mFilesToScanCount,mFilesScannedCount);
@ -2274,7 +2274,7 @@ void CppParser::handlePreprocessor()
// Mention progress to user if we enter a NEW file // Mention progress to user if we enter a NEW file
bool ok; bool ok;
int line = s.mid(delimPos+1).toInt(&ok); int line = s.midRef(delimPos+1).toInt(&ok);
if (line == 1) { if (line == 1) {
mFilesScannedCount++; mFilesScannedCount++;
mFilesToScanCount++; mFilesToScanCount++;
@ -3008,7 +3008,7 @@ void CppParser::inheritClassStatement(const PStatement& derived, bool isStruct,
else else
access = StatementClassScope::scsPrivate; access = StatementClassScope::scsPrivate;
} }
for (const PStatement& statement : base->children) { foreach (const PStatement& statement, base->children) {
if (statement->classScope == StatementClassScope::scsPrivate if (statement->classScope == StatementClassScope::scsPrivate
|| statement->kind == StatementKind::skConstructor || statement->kind == StatementKind::skConstructor
|| statement->kind == StatementKind::skDestructor) || statement->kind == StatementKind::skDestructor)
@ -3085,7 +3085,7 @@ PStatement CppParser::findStatementInScope(const QString &name, const QString &n
PStatementList namespaceStatementsList = findNamespace(scope->command); PStatementList namespaceStatementsList = findNamespace(scope->command);
if (!namespaceStatementsList) if (!namespaceStatementsList)
return PStatement(); return PStatement();
for (const PStatement& namespaceStatement: *namespaceStatementsList) { foreach (const PStatement& namespaceStatement, *namespaceStatementsList) {
PStatement result=doFindStatementInScope(name,noNameArgs,kind,namespaceStatement); PStatement result=doFindStatementInScope(name,noNameArgs,kind,namespaceStatement);
if (result) if (result)
return result; return result;
@ -3112,7 +3112,7 @@ PStatement CppParser::findStatementInNamespace(const QString &name, const QStrin
PStatementList namespaceStatementsList=findNamespace(namespaceName); PStatementList namespaceStatementsList=findNamespace(namespaceName);
if (!namespaceStatementsList) if (!namespaceStatementsList)
return PStatement(); return PStatement();
for (const PStatement& namespaceStatement:*namespaceStatementsList) { foreach (const PStatement& namespaceStatement,*namespaceStatementsList) {
PStatement result = findMemberOfStatement(name,namespaceStatement); PStatement result = findMemberOfStatement(name,namespaceStatement);
if (result) if (result)
return result; return result;
@ -3146,7 +3146,7 @@ PStatement CppParser::doFindStatementInScope(const QString &name,
{ {
const StatementMap& statementMap =mStatementList.childrenStatements(scope); const StatementMap& statementMap =mStatementList.childrenStatements(scope);
for (const PStatement& statement: statementMap.values(name)) { foreach (const PStatement& statement, statementMap.values(name)) {
if (statement->kind == kind && statement->noNameArgs == noNameArgs) { if (statement->kind == kind && statement->noNameArgs == noNameArgs) {
return statement; return statement;
} }
@ -3224,7 +3224,7 @@ QSet<QString> CppParser::calculateFilesToBeReparsed(const QString &fileName)
PFileIncludes p=mPreprocessor.includesList().value(name); PFileIncludes p=mPreprocessor.includesList().value(name);
if (!p) if (!p)
continue; continue;
for (const QString& s:p->dependedFiles) { foreach (const QString& s,p->dependedFiles) {
if (!processed.contains(s)) { if (!processed.contains(s)) {
queue.enqueue(s); queue.enqueue(s);
} }

View File

@ -154,7 +154,7 @@ void CppPreprocessor::invalidDefinesInFile(const QString &fileName)
{ {
PDefineMap defineMap = mFileDefines.value(fileName,PDefineMap()); PDefineMap defineMap = mFileDefines.value(fileName,PDefineMap());
if (defineMap) { if (defineMap) {
for (const PDefine& define:*defineMap) { foreach (const PDefine& define, *defineMap) {
const PDefine& p = mDefines.value(define->name); const PDefine& p = mDefines.value(define->name);
if (p == define) { if (p == define) {
mDefines.remove(define->name); mDefines.remove(define->name);
@ -186,26 +186,26 @@ void CppPreprocessor::dumpIncludesListTo(const QString &fileName) const
for (const PFileIncludes& fileIncludes:mIncludesList) { for (const PFileIncludes& fileIncludes:mIncludesList) {
stream<<fileIncludes->baseFile<<" : "<<Qt::endl; stream<<fileIncludes->baseFile<<" : "<<Qt::endl;
stream<<"\t**includes:**"<<Qt::endl; stream<<"\t**includes:**"<<Qt::endl;
for (const QString& s:fileIncludes->includeFiles.keys()) { foreach (const QString& s,fileIncludes->includeFiles.keys()) {
stream<<"\t--"+s<<Qt::endl; stream<<"\t--"+s<<Qt::endl;
} }
stream<<"\t**depends on:**"<<Qt::endl; stream<<"\t**depends on:**"<<Qt::endl;
for (const QString& s:fileIncludes->dependingFiles) { foreach (const QString& s,fileIncludes->dependingFiles) {
stream<<"\t^^"+s<<Qt::endl; stream<<"\t^^"+s<<Qt::endl;
} }
stream<<"\t**depended by:**"<<Qt::endl; stream<<"\t**depended by:**"<<Qt::endl;
for (const QString& s:fileIncludes->dependedFiles) { foreach (const QString& s,fileIncludes->dependedFiles) {
stream<<"\t&&"+s<<Qt::endl; stream<<"\t&&"+s<<Qt::endl;
} }
stream<<"\t**using:**"<<Qt::endl; stream<<"\t**using:**"<<Qt::endl;
for (const QString& s:fileIncludes->usings) { foreach (const QString& s,fileIncludes->usings) {
stream<<"\t++"+s<<Qt::endl; stream<<"\t++"+s<<Qt::endl;
} }
stream<<"\t**statements:**"<<Qt::endl; stream<<"\t**statements:**"<<Qt::endl;
for (PStatement& statement:fileIncludes->statements) { foreach (const PStatement& statement,fileIncludes->statements) {
if (statement) { if (statement) {
stream<<QString("\t**%1 , %2").arg(statement->command) stream<<QString("\t**%1 , %2")
.arg(statement->fullName)<<Qt::endl; .arg(statement->command,statement->fullName)<<Qt::endl;
} }
} }
} }
@ -709,7 +709,7 @@ void CppPreprocessor::addDefinesInFile(const QString &fileName)
//first add the defines in the files it included //first add the defines in the files it included
PFileIncludes fileIncludes = getFileIncludesEntry(fileName); PFileIncludes fileIncludes = getFileIncludesEntry(fileName);
if (fileIncludes) { if (fileIncludes) {
for (const QString& s:fileIncludes->includeFiles.keys()) { foreach (const QString& s,fileIncludes->includeFiles.keys()) {
addDefinesInFile(s); addDefinesInFile(s);
} }
} }
@ -717,7 +717,7 @@ void CppPreprocessor::addDefinesInFile(const QString &fileName)
// then add the defines defined in it // then add the defines defined in it
PDefineMap defineList = mFileDefines.value(fileName, PDefineMap()); PDefineMap defineList = mFileDefines.value(fileName, PDefineMap());
if (defineList) { if (defineList) {
for (const PDefine& define: defineList->values()) { foreach (const PDefine& define, defineList->values()) {
mDefines.insert(define->name,define); mDefines.insert(define->name,define);
} }
} }
@ -739,7 +739,7 @@ void CppPreprocessor::parseArgs(PDefine define)
QString formatStr = ""; QString formatStr = "";
DefineArgTokenType lastTokenType=DefineArgTokenType::Other; DefineArgTokenType lastTokenType=DefineArgTokenType::Other;
int index; int index;
for (const PDefineArgToken& token: tokens) { foreach (const PDefineArgToken& token, tokens) {
switch(token->type) { switch(token->type) {
case DefineArgTokenType::Identifier: case DefineArgTokenType::Identifier:
index = define->argList.indexOf(token->value); index = define->argList.indexOf(token->value);
@ -872,7 +872,7 @@ QStringList CppPreprocessor::removeComments(const QStringList &text)
currentType=ContentType::Other; currentType=ContentType::Other;
break; break;
case ContentType::RawString: case ContentType::RawString:
if (line.mid(0,pos).endsWith(')'+delimiter)) if (line.midRef(0,pos).endsWith(')'+delimiter))
currentType = ContentType::Other; currentType = ContentType::Other;
break; break;
case ContentType::Other: case ContentType::Other:

View File

@ -50,7 +50,7 @@ void CppTokenizer::dumpTokens(const QString &fileName)
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
QTextStream stream(&file); QTextStream stream(&file);
for (const PToken& token:mTokenList) { foreach (const PToken& token,mTokenList) {
stream<<QString("%1,%2").arg(token->line).arg(token->text)<<Qt::endl; stream<<QString("%1,%2").arg(token->line).arg(token->text)<<Qt::endl;
} }
} }
@ -149,7 +149,7 @@ QString CppTokenizer::getNextToken(bool bSkipParenthesis, bool bSkipArray, bool
int delimPos = result.lastIndexOf(':'); int delimPos = result.lastIndexOf(':');
if (delimPos >= 0) { if (delimPos >= 0) {
bool ok; bool ok;
mCurrentLine = result.mid(delimPos+1).toInt(&ok)-1; // fCurrLine is 0 based mCurrentLine = result.midRef(delimPos+1).toInt(&ok)-1; // fCurrLine is 0 based
} }
} }
done = (result != ""); done = (result != "");
@ -369,7 +369,7 @@ void CppTokenizer::simplifyArgs(QString &output)
QString temp; QString temp;
QString lastSpace = ""; QString lastSpace = "";
bool parentheseStart = true; bool parentheseStart = true;
for (const QChar& ch:output.trimmed()) { foreach (const QChar& ch,output.trimmed()) {
if (isSpaceChar(ch)) { if (isSpaceChar(ch)) {
if (!parentheseStart) if (!parentheseStart)
lastSpace+=ch; lastSpace+=ch;

View File

@ -4,6 +4,7 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QDebug> #include <QDebug>
#include <QGlobalStatic>
QStringList CppDirectives; QStringList CppDirectives;
QStringList JavadocTags; QStringList JavadocTags;
@ -14,25 +15,25 @@ QSet<QString> STLPointers;
QSet<QString> STLContainers; QSet<QString> STLContainers;
QSet<QString> STLElementMethods; QSet<QString> STLElementMethods;
static QSet<QString> CppHeaderExts; Q_GLOBAL_STATIC(QSet<QString>,CppHeaderExts)
static QSet<QString> CppSourceExts; Q_GLOBAL_STATIC(QSet<QString>,CppSourceExts)
void initParser() void initParser()
{ {
CppHeaderExts.insert("h"); CppHeaderExts->insert("h");
CppHeaderExts.insert("hpp"); CppHeaderExts->insert("hpp");
CppHeaderExts.insert("rh"); CppHeaderExts->insert("rh");
CppHeaderExts.insert("hh"); CppHeaderExts->insert("hh");
CppHeaderExts.insert("hxx"); CppHeaderExts->insert("hxx");
CppHeaderExts.insert("inl"); CppHeaderExts->insert("inl");
CppHeaderExts.insert(""); CppHeaderExts->insert("");
CppSourceExts.insert("c"); CppSourceExts->insert("c");
CppSourceExts.insert("cpp"); CppSourceExts->insert("cpp");
CppSourceExts.insert("cc"); CppSourceExts->insert("cc");
CppSourceExts.insert("cxx"); CppSourceExts->insert("cxx");
CppSourceExts.insert("c++"); CppSourceExts->insert("c++");
CppSourceExts.insert("cp"); CppSourceExts->insert("cp");
// skip itself // skip itself
CppKeywords.insert("and",SkipType::skItself); CppKeywords.insert("and",SkipType::skItself);
CppKeywords.insert("and_eq",SkipType::skItself); CppKeywords.insert("and_eq",SkipType::skItself);
@ -393,7 +394,7 @@ bool isHfile(const QString& filename)
return false; return false;
QFileInfo fileInfo(filename); QFileInfo fileInfo(filename);
return CppHeaderExts.contains(fileInfo.suffix().toLower()); return CppHeaderExts->contains(fileInfo.suffix().toLower());
} }
@ -403,7 +404,7 @@ bool isCfile(const QString& filename)
return false; return false;
QFileInfo fileInfo(filename); QFileInfo fileInfo(filename);
return CppSourceExts.contains(fileInfo.suffix().toLower()); return CppSourceExts->contains(fileInfo.suffix().toLower());
} }
PStatement CppScopes::findScopeAtLine(int line) PStatement CppScopes::findScopeAtLine(int line)

View File

@ -120,10 +120,10 @@ int StatementModel::deleteMember(StatementMap &map, const PStatement& statement)
void StatementModel::dumpStatementMap(StatementMap &map, QTextStream &out, int level) void StatementModel::dumpStatementMap(StatementMap &map, QTextStream &out, int level)
{ {
QString indent(level,'\t'); QString indent(level,'\t');
for (PStatement statement:map.values()) { foreach (const PStatement& statement,map) {
out<<indent<<QString("%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12") out<<indent<<QString("%1, %2, %3, %4, %5, %6, %7, %8, %9, %10, %11, %12")
.arg(statement->command).arg(int(statement->kind)) .arg(statement->command).arg(int(statement->kind))
.arg(statement->type).arg(statement->fullName) .arg(statement->type,statement->fullName)
.arg((size_t)(statement->parentScope.lock().get())) .arg((size_t)(statement->parentScope.lock().get()))
.arg((int)statement->classScope) .arg((int)statement->classScope)
.arg(statement->fileName) .arg(statement->fileName)

View File

@ -570,8 +570,6 @@ int StrScanForNonWordChar(const QString &s, int startPos)
int StrRScanForWordChar(const QString &s, int startPos) int StrRScanForWordChar(const QString &s, int startPos)
{ {
int i = startPos-1; int i = startPos-1;
if (i>s.length())
return 0;
while (i>=0) { while (i>=0) {
if (isWordChar(s[i])) if (isWordChar(s[i]))
return i+1; return i+1;
@ -583,8 +581,6 @@ int StrRScanForWordChar(const QString &s, int startPos)
int StrRScanForNonWordChar(const QString &s, int startPos) int StrRScanForNonWordChar(const QString &s, int startPos)
{ {
int i = startPos-1; int i = startPos-1;
if (i>s.length())
return 0;
while (i>=0) { while (i>=0) {
if (!isWordChar(s[i])) if (!isWordChar(s[i]))
return i+1; return i+1;

View File

@ -56,7 +56,7 @@ int SynSearch::findAll(const QString &keyword)
return mResults.size(); return mResults.size();
} }
QString SynSearch::replace(const QString &aOccurrence, const QString &aReplacement) QString SynSearch::replace(const QString &, const QString &aReplacement)
{ {
return aReplacement; return aReplacement;
} }

View File

@ -297,7 +297,7 @@ void SynEdit::setInsertMode(bool value)
if (mInserting != value) { if (mInserting != value) {
mInserting = value; mInserting = value;
updateCaret(); updateCaret();
statusChanged(scInsertMode); emit statusChanged(scInsertMode);
} }
} }
@ -1179,7 +1179,7 @@ BufferCoord SynEdit::WordStartEx(const BufferCoord &XY)
// valid line? // valid line?
if ((CY >= 1) && (CY <= mLines->count())) { if ((CY >= 1) && (CY <= mLines->count())) {
QString Line = mLines->getString(CY - 1); QString Line = mLines->getString(CY - 1);
CX = std::min(CX, Line.length()+1); CX = std::min(CX, Line.length());
if (CX-1 >= 0) { if (CX-1 >= 0) {
if (!(Line[CX - 1].isSpace())) if (!(Line[CX - 1].isSpace()))
CX = StrRScanForNonWordChar(Line, CX - 1) + 1; CX = StrRScanForNonWordChar(Line, CX - 1) + 1;
@ -1539,7 +1539,7 @@ void SynEdit::doDeleteLastChar()
setCaretX(newCaretX); setCaretX(newCaretX);
updateLastCaretX(); updateLastCaretX();
mStateFlags.setFlag(SynStateFlag::sfCaretChanged); mStateFlags.setFlag(SynStateFlag::sfCaretChanged);
statusChanged(SynStatusChange::scCaretX); emit statusChanged(SynStatusChange::scCaretX);
} else { } else {
// delete char // delete char
internalSetCaretX(mCaretX - 1); internalSetCaretX(mCaretX - 1);
@ -2635,7 +2635,7 @@ void SynEdit::recalcCharExtent()
bool hasStyles[] = {false,false,false,false}; bool hasStyles[] = {false,false,false,false};
int size = 4; int size = 4;
if (mHighlighter && mHighlighter->attributes().count()>0) { if (mHighlighter && mHighlighter->attributes().count()>0) {
for (PSynHighlighterAttribute attribute: mHighlighter->attributes().values()) { for (const PSynHighlighterAttribute& attribute: mHighlighter->attributes()) {
for (int i=0;i<size;i++) { for (int i=0;i<size;i++) {
if (attribute->styles().testFlag(styles[i])) if (attribute->styles().testFlag(styles[i]))
hasStyles[i] = true; hasStyles[i] = true;
@ -3003,7 +3003,7 @@ PSynEditFoldRange SynEdit::collapsedFoldStartAtLine(int Line)
return PSynEditFoldRange(); return PSynEditFoldRange();
} }
void SynEdit::doOnPaintTransientEx(SynTransientType TransientType, bool Lock) void SynEdit::doOnPaintTransientEx(SynTransientType , bool )
{ {
//todo: we can't draw to canvas outside paintEvent //todo: we can't draw to canvas outside paintEvent
} }
@ -3243,7 +3243,7 @@ void SynEdit::setReadOnly(bool readOnly)
{ {
if (mReadOnly != readOnly) { if (mReadOnly != readOnly) {
mReadOnly = readOnly; mReadOnly = readOnly;
statusChanged(scReadOnly); emit statusChanged(scReadOnly);
} }
} }
@ -3870,7 +3870,7 @@ QString SynEdit::selText()
result += mLines->getString(i); result += mLines->getString(i);
result+=lineBreak(); result+=lineBreak();
} }
result += mLines->getString(Last).left(ColTo-1); result += mLines->getString(Last).leftRef(ColTo-1);
return result; return result;
} }
case SynSelectionMode::smColumn: case SynSelectionMode::smColumn:
@ -4340,7 +4340,7 @@ int SynEdit::searchReplace(const QString &sSearch, const QString &sReplace, SynS
return result; return result;
} }
void SynEdit::DoLinesDeleted(int FirstLine, int Count) void SynEdit::DoLinesDeleted(int , int )
{ {
// // gutter marks // // gutter marks
// for i := 0 to Marks.Count - 1 do begin // for i := 0 to Marks.Count - 1 do begin
@ -4356,7 +4356,7 @@ void SynEdit::DoLinesDeleted(int FirstLine, int Count)
// end; // end;
} }
void SynEdit::DoLinesInserted(int FirstLine, int Count) void SynEdit::DoLinesInserted(int , int )
{ {
// // gutter marks // // gutter marks
// for i := 0 to Marks.Count - 1 do begin // for i := 0 to Marks.Count - 1 do begin
@ -4606,7 +4606,7 @@ int SynEdit::InsertTextByLineMode(const QString &Value)
QString Str; QString Str;
int Result = 0; int Result = 0;
mCaretX = 1; mCaretX = 1;
statusChanged(SynStatusChange::scCaretX); emit statusChanged(SynStatusChange::scCaretX);
// Insert string before current line // Insert string before current line
Start = 0; Start = 0;
do { do {
@ -4659,12 +4659,12 @@ void SynEdit::onGetEditingAreas(int, SynEditingAreaList &)
} }
void SynEdit::onGutterGetText(int aLine, QString &aText) void SynEdit::onGutterGetText(int , QString &)
{ {
} }
void SynEdit::onGutterPaint(QPainter &painter, int aLine, int X, int Y) void SynEdit::onGutterPaint(QPainter &, int , int , int )
{ {
} }
@ -4674,7 +4674,8 @@ void SynEdit::onPaint(QPainter &)
} }
void SynEdit::onPreparePaintHighlightToken(int row, int column, const QString &token, PSynHighlighterAttribute attr, SynFontStyles &style, QColor &foreground, QColor &background) void SynEdit::onPreparePaintHighlightToken(int , int , const QString &,
PSynHighlighterAttribute , SynFontStyles &, QColor &, QColor &)
{ {
} }
@ -5188,7 +5189,7 @@ void SynEdit::paintEvent(QPaintEvent *event)
paintCaret(painter, rcCaret); paintCaret(painter, rcCaret);
} }
void SynEdit::resizeEvent(QResizeEvent *e) void SynEdit::resizeEvent(QResizeEvent *)
{ {
//resize the cache image //resize the cache image
std::shared_ptr<QImage> image = std::make_shared<QImage>(clientWidth(),clientHeight(), std::shared_ptr<QImage> image = std::make_shared<QImage>(clientWidth(),clientHeight(),
@ -5407,7 +5408,7 @@ void SynEdit::inputMethodEvent(QInputMethodEvent *event)
} }
} }
void SynEdit::leaveEvent(QEvent *event) void SynEdit::leaveEvent(QEvent *)
{ {
setCursor(Qt::ArrowCursor); setCursor(Qt::ArrowCursor);
} }
@ -5458,7 +5459,7 @@ void SynEdit::setModified(bool Value)
if (mOptions.testFlag(SynEditorOption::eoGroupUndo) && (!Value) && mUndoList->CanUndo()) if (mOptions.testFlag(SynEditorOption::eoGroupUndo) && (!Value) && mUndoList->CanUndo())
mUndoList->AddGroupBreak(); mUndoList->AddGroupBreak();
mUndoList->setInitialState(!Value); mUndoList->setInitialState(!Value);
statusChanged(SynStatusChange::scModified); emit statusChanged(SynStatusChange::scModified);
} }
} }

View File

@ -273,7 +273,7 @@ void SynEditStringList::addStrings(const QStringList &Strings)
int SynEditStringList::getTextLength() int SynEditStringList::getTextLength()
{ {
int Result = 0; int Result = 0;
for (const PSynEditStringRec& line: mList ) { foreach (const PSynEditStringRec& line, mList ) {
Result += line->fString.length(); Result += line->fString.length();
if (mFileEndingType == FileEndingType::Windows) { if (mFileEndingType == FileEndingType::Windows) {
Result += 2; Result += 2;
@ -783,7 +783,7 @@ void SynEditUndoList::PushItem(PSynEditUndoItem Item)
mItems.append(Item); mItems.append(Item);
EnsureMaxEntries(); EnsureMaxEntries();
if (Item->changeReason()!= SynChangeReason::crGroupBreak) if (Item->changeReason()!= SynChangeReason::crGroupBreak)
addedUndo(); emit addedUndo();
} }
void SynEditUndoList::Unlock() void SynEditUndoList::Unlock()

View File

@ -22,7 +22,6 @@ void SynEditTextPainter::paintTextLines(const QRect& clip)
bCurrentLine = false; bCurrentLine = false;
// If the right edge is visible and in the invalid area, prepare to paint it. // If the right edge is visible and in the invalid area, prepare to paint it.
// Do this first to realize the pen when getting the dc variable. // Do this first to realize the pen when getting the dc variable.
QString SynTabGlyphString = SynTabGlyph;
bDoRightEdge = false; bDoRightEdge = false;
if (edit->mRightEdge > 0) { // column value if (edit->mRightEdge > 0) { // column value
nRightEdge = edit->textOffset()+ edit->mRightEdge * edit->mCharWidth; // pixel value nRightEdge = edit->textOffset()+ edit->mRightEdge * edit->mCharWidth; // pixel value
@ -75,7 +74,6 @@ void SynEditTextPainter::paintGutter(const QRect& clip)
{ {
int cRow; int cRow;
QRect rcLine, rcFold; QRect rcLine, rcFold;
QList<int> aGutterOffs;
QString s; QString s;
int vLine; int vLine;
int vLineTop; int vLineTop;
@ -392,7 +390,7 @@ void SynEditTextPainter::PaintEditAreas(const SynEditingAreaList &areaList)
rc=rcLine; rc=rcLine;
rc.setBottom(rc.bottom()-1); rc.setBottom(rc.bottom()-1);
setDrawingColors(false); setDrawingColors(false);
for (PSynEditingArea p:areaList) { for (const PSynEditingArea& p:areaList) {
if (p->beginX > LastCol) if (p->beginX > LastCol)
continue; continue;
if (p->endX < FirstCol) if (p->endX < FirstCol)
@ -536,7 +534,6 @@ void SynEditTextPainter::PaintHighlightToken(bool bFillToEOL)
bool SynEditTextPainter::TokenIsSpaces(bool &bSpacesTest, const QString& Token, bool& bIsSpaces) bool SynEditTextPainter::TokenIsSpaces(bool &bSpacesTest, const QString& Token, bool& bIsSpaces)
{ {
QString pTok;
if (!bSpacesTest) { if (!bSpacesTest) {
bSpacesTest = true; bSpacesTest = true;
for (QChar ch:Token) { for (QChar ch:Token) {
@ -622,7 +619,6 @@ void SynEditTextPainter::AddHighlightToken(const QString &Token, int ColumnsBefo
void SynEditTextPainter::PaintFoldAttributes() void SynEditTextPainter::PaintFoldAttributes()
{ {
int TabSteps, LineIndent, LastNonBlank, X, Y, cRow, vLine; int TabSteps, LineIndent, LastNonBlank, X, Y, cRow, vLine;
QBrush DottedPenDesc;
// Paint indent guides. Use folds to determine indent value of these // Paint indent guides. Use folds to determine indent value of these
// Use a separate loop so we can use a custom pen // Use a separate loop so we can use a custom pen
// Paint indent guides using custom pen // Paint indent guides using custom pen
@ -933,7 +929,7 @@ void SynEditTextPainter::PaintLines()
} }
} }
void SynEditTextPainter::drawMark(PSynEditMark aMark, int &aGutterOff, int aMarkRow) void SynEditTextPainter::drawMark(PSynEditMark , int &, int )
{ {
//todo //todo
} }

View File

@ -1259,7 +1259,7 @@ QStringList &Settings::CompilerSet::libDirs()
return mLibDirs; return mLibDirs;
} }
const QString &Settings::CompilerSet::dumpMachine() const QString &Settings::CompilerSet::dumpMachine() const
{ {
return mDumpMachine; return mDumpMachine;
} }
@ -1269,7 +1269,7 @@ void Settings::CompilerSet::setDumpMachine(const QString &value)
mDumpMachine = value; mDumpMachine = value;
} }
const QString &Settings::CompilerSet::version() const QString &Settings::CompilerSet::version() const
{ {
return mVersion; return mVersion;
} }
@ -1279,7 +1279,7 @@ void Settings::CompilerSet::setVersion(const QString &value)
mVersion = value; mVersion = value;
} }
const QString &Settings::CompilerSet::type() const QString &Settings::CompilerSet::type() const
{ {
return mType; return mType;
} }
@ -1289,7 +1289,7 @@ void Settings::CompilerSet::setType(const QString& value)
mType = value; mType = value;
} }
const QString &Settings::CompilerSet::name() const QString &Settings::CompilerSet::name() const
{ {
return mName; return mName;
} }
@ -1299,12 +1299,12 @@ void Settings::CompilerSet::setName(const QString &value)
mName = value; mName = value;
} }
QStringList& Settings::CompilerSet::defines() const QStringList& Settings::CompilerSet::defines() const
{ {
return mDefines; return mDefines;
} }
const QString &Settings::CompilerSet::target() const QString &Settings::CompilerSet::target() const
{ {
return mTarget; return mTarget;
} }
@ -1319,7 +1319,7 @@ void Settings::CompilerSet::setUseCustomCompileParams(bool value)
mUseCustomCompileParams = value; mUseCustomCompileParams = value;
} }
bool Settings::CompilerSet::useCustomLinkParams() bool Settings::CompilerSet::useCustomLinkParams() const
{ {
return mUseCustomLinkParams; return mUseCustomLinkParams;
} }
@ -1329,7 +1329,7 @@ void Settings::CompilerSet::setUseCustomLinkParams(bool value)
mUseCustomLinkParams = value; mUseCustomLinkParams = value;
} }
const QString &Settings::CompilerSet::customCompileParams() const QString &Settings::CompilerSet::customCompileParams() const
{ {
return mCustomCompileParams; return mCustomCompileParams;
} }
@ -1339,7 +1339,7 @@ void Settings::CompilerSet::setCustomCompileParams(const QString &value)
mCustomCompileParams = value; mCustomCompileParams = value;
} }
const QString &Settings::CompilerSet::customLinkParams() const QString &Settings::CompilerSet::customLinkParams() const
{ {
return mCustomLinkParams; return mCustomLinkParams;
} }
@ -1349,7 +1349,7 @@ void Settings::CompilerSet::setCustomLinkParams(const QString &value)
mCustomLinkParams = value; mCustomLinkParams = value;
} }
bool Settings::CompilerSet::autoAddCharsetParams() bool Settings::CompilerSet::autoAddCharsetParams() const
{ {
return mAutoAddCharsetParams; return mAutoAddCharsetParams;
} }
@ -1784,7 +1784,7 @@ QString Settings::CompilerSet::findProgramInBinDirs(const QString name)
QByteArray Settings::CompilerSet::iniOptions() const QByteArray Settings::CompilerSet::iniOptions() const
{ {
QByteArray result; QByteArray result;
for (PCompilerOption p:mOptions) { for (const PCompilerOption& p:mOptions) {
result.append(ValueToChar[p->value]); result.append(ValueToChar[p->value]);
} }
return result; return result;
@ -1808,14 +1808,14 @@ QByteArray Settings::CompilerSet::getCompilerOutput(const QString &binDir, const
return result.trimmed(); return result.trimmed();
} }
bool Settings::CompilerSet::useCustomCompileParams() bool Settings::CompilerSet::useCustomCompileParams() const
{ {
return mUseCustomCompileParams; return mUseCustomCompileParams;
} }
Settings::CompilerSets::CompilerSets(Settings *settings): Settings::CompilerSets::CompilerSets(Settings *settings):
mSettings(settings), mDefaultIndex(-1),
mDefaultIndex(-1) mSettings(settings)
{ {
} }
@ -1914,7 +1914,7 @@ void Settings::CompilerSets::addSets(const QString &folder)
void Settings::CompilerSets::clearSets() void Settings::CompilerSets::clearSets()
{ {
for (int i=0;i<mList.size();i++) { for (size_t i=0;i<mList.size();i++) {
mSettings->mSettings.beginGroup(QString(SETTING_COMPILTER_SET).arg(i)); mSettings->mSettings.beginGroup(QString(SETTING_COMPILTER_SET).arg(i));
mSettings->mSettings.remove(""); mSettings->mSettings.remove("");
mSettings->mSettings.endGroup(); mSettings->mSettings.endGroup();
@ -1932,7 +1932,7 @@ void Settings::CompilerSets::findSets()
void Settings::CompilerSets::saveSets() void Settings::CompilerSets::saveSets()
{ {
for (int i=0;i<mList.size();i++) { for (size_t i=0;i<mList.size();i++) {
saveSet(i); saveSet(i);
} }
if (mDefaultIndex>=mList.size()) { if (mDefaultIndex>=mList.size()) {
@ -2395,12 +2395,12 @@ Settings::History::History(Settings *settings):_Base(settings, SETTING_HISTORY)
} }
QStringList &Settings::History::openedFiles() const QStringList &Settings::History::openedFiles() const
{ {
return mOpenedFiles; return mOpenedFiles;
} }
QStringList &Settings::History::openedProjects() const QStringList &Settings::History::openedProjects() const
{ {
return mOpenedProjects; return mOpenedProjects;
} }

View File

@ -375,8 +375,8 @@ public:
public: public:
explicit History(Settings *settings); explicit History(Settings *settings);
QStringList& openedFiles(); const QStringList& openedFiles() const;
QStringList& openedProjects(); const QStringList& openedProjects() const;
bool addToOpenedFiles(const QString& filename); bool addToOpenedFiles(const QString& filename);
private: private:
QStringList mOpenedFiles; QStringList mOpenedFiles;
@ -488,27 +488,27 @@ public:
QStringList& CppIncludeDirs(); QStringList& CppIncludeDirs();
QStringList& libDirs(); QStringList& libDirs();
const QString& dumpMachine(); const QString& dumpMachine() const;
void setDumpMachine(const QString& value); void setDumpMachine(const QString& value);
const QString& version(); const QString& version() const;
void setVersion(const QString& value); void setVersion(const QString& value);
const QString& type(); const QString& type() const;
void setType(const QString& value); void setType(const QString& value);
const QString& name(); const QString& name() const;
void setName(const QString& value); void setName(const QString& value);
QStringList& defines(); const QStringList& defines() const;
const QString& target(); const QString& target() const;
void setTarget(const QString& value); void setTarget(const QString& value);
bool useCustomCompileParams(); bool useCustomCompileParams() const;
void setUseCustomCompileParams(bool value); void setUseCustomCompileParams(bool value);
bool useCustomLinkParams(); bool useCustomLinkParams() const;
void setUseCustomLinkParams(bool value); void setUseCustomLinkParams(bool value);
const QString& customCompileParams(); const QString& customCompileParams() const;
void setCustomCompileParams(const QString& value); void setCustomCompileParams(const QString& value);
const QString& customLinkParams(); const QString& customLinkParams() const;
void setCustomLinkParams(const QString& value); void setCustomLinkParams(const QString& value);
bool autoAddCharsetParams(); bool autoAddCharsetParams() const;
void setAutoAddCharsetParams(bool value); void setAutoAddCharsetParams(bool value);
CompilerOptionList& options(); CompilerOptionList& options();

View File

@ -708,6 +708,11 @@ bool CodeCompletionPopup::isIncluded(const QString &fileName)
return mIncludedFiles.contains(fileName); return mIncludedFiles.contains(fileName);
} }
const QString &CodeCompletionPopup::phrase() const
{
return mPhrase;
}
void CodeCompletionPopup::showEvent(QShowEvent *) void CodeCompletionPopup::showEvent(QShowEvent *)
{ {
mListView->setFocus(); mListView->setFocus();

View File

@ -107,6 +107,7 @@ protected:
// QObject interface // QObject interface
public: public:
bool event(QEvent *event) override; bool event(QEvent *event) override;
const QString &phrase() const;
}; };
#endif // CODECOMPLETIONPOPUP_H #endif // CODECOMPLETIONPOPUP_H

View File

@ -88,6 +88,17 @@ void HeaderCompletionPopup::setSuggestionColor(const QColor &color)
mModel->setColor(color); mModel->setColor(color);
} }
QString HeaderCompletionPopup::selectedFilename()
{
if (!isEnabled())
return "";
int index = mListView->currentIndex().row();
if (index>=0 && index<mCompletionList.count())
return mCompletionList[index];
else
return "";
}
void HeaderCompletionPopup::filterList(const QString &member) void HeaderCompletionPopup::filterList(const QString &member)
{ {
mCompletionList.clear(); mCompletionList.clear();
@ -149,8 +160,10 @@ void HeaderCompletionPopup::addFilesInPath(const QString &path)
if (!dir.exists()) if (!dir.exists())
return; return;
foreach (const QFileInfo& fileInfo, dir.entryInfoList()) { foreach (const QFileInfo& fileInfo, dir.entryInfoList()) {
if (fileInfo.fileName().startsWith("."))
continue;
QString suffix = fileInfo.suffix().toLower(); QString suffix = fileInfo.suffix().toLower();
if (suffix == ".h" || suffix == ".hpp" || suffix == "") { if (suffix == "h" || suffix == "hpp" || suffix == "") {
addFile(fileInfo.fileName()); addFile(fileInfo.fileName());
} }
} }
@ -172,6 +185,36 @@ void HeaderCompletionPopup::addFilesInSubDir(const QString &baseDirPath, const Q
addFilesInPath(subDirPath); addFilesInPath(subDirPath);
} }
bool HeaderCompletionPopup::searchLocal() const
{
return mSearchLocal;
}
void HeaderCompletionPopup::setSearchLocal(bool newSearchLocal)
{
mSearchLocal = newSearchLocal;
}
bool HeaderCompletionPopup::ignoreCase() const
{
return mIgnoreCase;
}
void HeaderCompletionPopup::setIgnoreCase(bool newIgnoreCase)
{
mIgnoreCase = newIgnoreCase;
}
const QString &HeaderCompletionPopup::phrase() const
{
return mPhrase;
}
void HeaderCompletionPopup::setParser(const PCppParser &newParser)
{
mParser = newParser;
}
void HeaderCompletionPopup::showEvent(QShowEvent *) void HeaderCompletionPopup::showEvent(QShowEvent *)
{ {
mListView->setFocus(); mListView->setFocus();

View File

@ -29,6 +29,7 @@ public:
bool search(const QString& phrase, bool autoHideOnSingleResult); bool search(const QString& phrase, bool autoHideOnSingleResult);
void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback); void setKeypressedCallback(const KeyPressedCallback &newKeypressedCallback);
void setSuggestionColor(const QColor& color); void setSuggestionColor(const QColor& color);
QString selectedFilename();
private: private:
void filterList(const QString& member); void filterList(const QString& member);
@ -59,6 +60,12 @@ protected:
// QObject interface // QObject interface
public: public:
bool event(QEvent *event) override; bool event(QEvent *event) override;
void setParser(const PCppParser &newParser);
const QString &phrase() const;
bool ignoreCase() const;
void setIgnoreCase(bool newIgnoreCase);
bool searchLocal() const;
void setSearchLocal(bool newSearchLocal);
}; };
#endif // HEADERCOMPLETIONPOPUP_H #endif // HEADERCOMPLETIONPOPUP_H