diff --git a/NEWS.md b/NEWS.md index e6c971ab..879867b6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,8 +4,12 @@ Red Panda C++ Version 1.5 - enhancement: add/new/remove/rename project files won't rebuild project tree - fix: gliches in UI's left panel in some OS - fix: correctly restore project layout when reopen it + - change: new syntax for project layout files - change: clear tools output panel when start to compile - - change: don't show syntax check messages in the tools output panel + - change: don't show syntax check messages in the tools output panel (to reduce longtime memory usage) + - fix: minor memory leaks when set itemmodels + - fix: thread for parsing doesn't correctly released when parsing finished ( so and the parser) + Red Panda C++ Version 1.4 diff --git a/RedPandaIDE/HighlighterManager.cpp b/RedPandaIDE/HighlighterManager.cpp index 73ab5e5d..0e146a78 100644 --- a/RedPandaIDE/HighlighterManager.cpp +++ b/RedPandaIDE/HighlighterManager.cpp @@ -62,7 +62,7 @@ QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighte QSynedit::PHighlighter HighlighterManager::getCppHighlighter() { - QSynedit::CppHighlighter* highlighter = new QSynedit::CppHighlighter(); + std::shared_ptr highlighter = std::make_shared(); highlighter->asmAttribute()->setForeground(Qt::blue); highlighter->charAttribute()->setForeground(Qt::black); highlighter->commentAttribute()->setForeground(0x8C8C8C); @@ -84,14 +84,12 @@ QSynedit::PHighlighter HighlighterManager::getCppHighlighter() highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red); highlighter->symbolAttribute()->setForeground(0xc10000); highlighter->variableAttribute()->setForeground(0x400080); - QSynedit::PHighlighter pHighlighter=std::make_shared(); - return pHighlighter; + return highlighter; } QSynedit::PHighlighter HighlighterManager::getAsmHighlighter() { - QSynedit::ASMHighlighter* highlighter = new QSynedit::ASMHighlighter(); - QSynedit::PHighlighter pHighlighter(highlighter); + std::shared_ptr highlighter=std::make_shared(); highlighter->commentAttribute()->setForeground(0x8C8C8C); highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic); highlighter->identifierAttribute()->setForeground(0x080808); @@ -100,13 +98,12 @@ QSynedit::PHighlighter HighlighterManager::getAsmHighlighter() highlighter->whitespaceAttribute()->setForeground(Qt::lightGray); highlighter->stringAttribute()->setForeground(0x007d17); highlighter->symbolAttribute()->setForeground(0xc10000); - return pHighlighter; + return highlighter; } QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter() { - QSynedit::GLSLHighlighter* highlighter = new QSynedit::GLSLHighlighter(); - QSynedit::PHighlighter pHighlighter(highlighter); + std::shared_ptr highlighter=std::make_shared(); highlighter->asmAttribute()->setForeground(Qt::blue); highlighter->charAttribute()->setForeground(Qt::black); highlighter->commentAttribute()->setForeground(0x8C8C8C); @@ -128,7 +125,7 @@ QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter() highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red); highlighter->symbolAttribute()->setForeground(0xc10000); highlighter->variableAttribute()->setForeground(0x400080); - return pHighlighter; + return highlighter; } void HighlighterManager::applyColorScheme(QSynedit::PHighlighter highlighter, const QString &schemeName) diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 6f02c465..85c191ea 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -42,7 +42,6 @@ Compiler::Compiler(const QString &filename, bool silent, bool onlyCheckSyntax): mFilename(filename), mRebuild(false) { - } void Compiler::run() diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 7d522513..64c78f54 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -81,6 +81,7 @@ void CompilerManager::compile(const QString& filename, const QByteArray& encodin } mCompileErrorCount = 0; mCompileIssueCount = 0; + //deleted when thread finished mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax); mCompiler->setRebuild(rebuild); connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater); @@ -111,6 +112,7 @@ void CompilerManager::compileProject(std::shared_ptr project, bool rebu } mCompileErrorCount = 0; mCompileIssueCount = 0; + //deleted when thread finished mCompiler = new ProjectCompiler(project,silent,onlyCheckSyntax); mCompiler->setRebuild(rebuild); connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater); @@ -142,6 +144,7 @@ void CompilerManager::cleanProject(std::shared_ptr project) } mCompileErrorCount = 0; mCompileIssueCount = 0; + //deleted when thread finished ProjectCompiler* compiler = new ProjectCompiler(project,false,false); compiler->setOnlyClean(true); mCompiler = compiler; @@ -195,6 +198,8 @@ void CompilerManager::checkSyntax(const QString &filename, const QByteArray& enc mSyntaxCheckErrorCount = 0; mSyntaxCheckIssueCount = 0; + + //deleted when thread finished StdinCompiler *pStdinCompiler = new StdinCompiler(filename,encoding, content,true,true); mBackgroundSyntaxChecker = pStdinCompiler; mBackgroundSyntaxChecker->setProject(project); @@ -239,9 +244,12 @@ void CompilerManager::run( QString newArguments = QString(" %1 %2 \"%3\" %4") .arg(consoleFlag) .arg(sharedMemoryId,localizePath(filename)).arg(arguments); + + //delete when thread finished execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().appDir())+"ConsolePauser.exe",newArguments,workDir); execRunner->setShareMemoryId(sharedMemoryId); } else { + //delete when thread finished execRunner = new ExecutableRunner(filename,arguments,workDir); } #else @@ -280,6 +288,7 @@ void CompilerManager::run( #endif execRunner->setStartConsole(true); } else { + //delete when thread finished execRunner = new ExecutableRunner(filename,arguments,workDir); } if (redirectInput) { diff --git a/RedPandaIDE/customfileiconprovider.cpp b/RedPandaIDE/customfileiconprovider.cpp index c45f5c82..4a401ce7 100644 --- a/RedPandaIDE/customfileiconprovider.cpp +++ b/RedPandaIDE/customfileiconprovider.cpp @@ -20,6 +20,7 @@ CustomFileIconProvider::CustomFileIconProvider() { + //provider delete it in the destructor mVCSRepository = new GitRepository(""); } diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 34e86ec0..ac29bd30 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -36,11 +36,13 @@ Debugger::Debugger(QObject *parent) : QObject(parent), mForceUTF8(false) { + //models deleted in the destructor mBreakpointModel=new BreakpointModel(this); mBacktraceModel=new BacktraceModel(this); mWatchModel = new WatchModel(this); mRegisterModel = new RegisterModel(this); mMemoryModel = new MemoryModel(8,this); + connect(mMemoryModel,&MemoryModel::setMemoryData, this, &Debugger::setMemoryData); connect(mWatchModel, &WatchModel::setWatchVarValue, @@ -55,6 +57,15 @@ Debugger::Debugger(QObject *parent) : QObject(parent), this, &Debugger::fetchVarChildren); } +Debugger::~Debugger() +{ + delete mBreakpointModel; + delete mBacktraceModel; + delete mWatchModel; + delete mRegisterModel; + delete mMemoryModel; +} + bool Debugger::start(int compilerSetIndex, const QString& inferior, const QStringList& binDirs) { @@ -112,6 +123,7 @@ bool Debugger::start(int compilerSetIndex, const QString& inferior, const QStrin mMemoryModel->reset(); mWatchModel->resetAllVarInfos(); if (pSettings->debugger().useGDBServer()) { + //deleted when thread finished mTarget = new DebugTarget(inferior,compilerSet->debugServer(),pSettings->debugger().GDBServerPort()); if (pSettings->executor().redirectInput()) mTarget->setInputFile(pSettings->executor().inputFilename()); @@ -127,6 +139,7 @@ bool Debugger::start(int compilerSetIndex, const QString& inferior, const QStrin mTarget->start(); mTarget->waitStart(); } + //delete when thread finished mReader = new DebugReader(this); mReader->addBinDirs(binDirs); mReader->addBinDir(pSettings->dirs().appDir()); diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 86a5212c..dd40d4f2 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -258,6 +258,7 @@ class Debugger : public QObject Q_OBJECT public: explicit Debugger(QObject *parent = nullptr); + ~Debugger(); // Play/pause bool start(int compilerSetIndex, const QString& inferior, const QStringList& binDirs); void sendCommand(const QString& command, const QString& params, diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index e5464920..bea4ccf8 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -191,6 +191,7 @@ Editor::Editor(QWidget *parent, const QString& filename, } Editor::~Editor() { + //qDebug()<<"editor "<fileSystemWatcher()->removePath(mFilename); pMainWindow->caretList().removeEditor(this); @@ -221,7 +222,7 @@ void Editor::loadFile(QString filename) { default: mUseCppSyntax = pSettings->editor().defaultFileCpp(); } - if (highlighter() && mParser) { + if (highlighter()) { reparse(); if (pSettings->editor().syntaxCheckWhenLineChanged()) { checkSyntaxInBack(); @@ -1177,6 +1178,7 @@ bool Editor::event(QEvent *event) QKeyEvent* keyEvent = dynamic_cast(event); if (keyEvent->key() == Qt::Key_Control) { QApplication* app = dynamic_cast(QApplication::instance()); + //postEvent takes the owner ship QHoverEvent* hoverEvent=new QHoverEvent(QEvent::HoverMove, mapFromGlobal(QCursor::pos()), mapFromGlobal(QCursor::pos()), @@ -1392,6 +1394,7 @@ void Editor::copyAsHTML() exporter.ExportRange(document(),blockBegin(),blockEnd()); + //clipboard takes the owner ship QMimeData * mimeData = new QMimeData; //sethtml will convert buffer to QString , which will cause encoding trouble @@ -2686,7 +2689,9 @@ void Editor::reparse() if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp && highlighter()->language() != QSynedit::HighlighterLanguage::GLSL) return; - if (mParser) + if (!mParser) + return; + if (!mParser->enabled()) return; //mParser->setEnabled(pSettings->codeCompletion().enabled()); ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C; @@ -4297,7 +4302,7 @@ void Editor::reformat() onLinesDeleted(1,document()->count()); QByteArray content = text().toUtf8(); QStringList args = pSettings->codeFormatter().getArguments(); - qDebug()<dirs().appDir(), diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index e3d8f625..e335c596 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -52,6 +52,8 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin if (fileExists(filename)) { pMainWindow->fileSystemWatcher()->addPath(filename); } + + // parentPageControl takes the owner ship Editor * e = new Editor(parentPageControl,filename,encoding,pProject,newFile,parentPageControl); connect(e, &Editor::renamed, this, &EditorList::onEditorRenamed); updateLayout(); diff --git a/RedPandaIDE/iconsmanager.cpp b/RedPandaIDE/iconsmanager.cpp index 181ca9c5..82173d20 100644 --- a/RedPandaIDE/iconsmanager.cpp +++ b/RedPandaIDE/iconsmanager.cpp @@ -228,7 +228,8 @@ QIcon IconsManager:: getIcon(IconName iconName) const if (pixmap == mDefaultIconPixmap) return QIcon(); if (mMakeDisabledIconDarker) { - QIcon icon(new CustomDisabledIconEngine()); + //QIcon takes the owner ship + QIcon icon(new CustomDisabledIconEngine); icon.addPixmap(*pixmap); return icon; } else diff --git a/RedPandaIDE/iconsmanager.h b/RedPandaIDE/iconsmanager.h index 2d9c634d..429e7ebb 100644 --- a/RedPandaIDE/iconsmanager.h +++ b/RedPandaIDE/iconsmanager.h @@ -226,6 +226,7 @@ private: QSize mActionIconSize; QString mIconSetTemplate; QString mIconSetsFolder; + bool mMakeDisabledIconDarker; }; diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 6cea2437..e2845931 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -131,6 +131,7 @@ bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/ case WM_DPICHANGED:{ if (pMsg->hwnd == (HWND)pMainWindow->winId()) { int oldDPI = screenDPI(); + //postEvent takes the owner ship QEvent * dpiEvent = new QEvent(DPI_CHANGED_EVENT); qApp->postEvent(pMainWindow,dpiEvent); setScreenDPI(HIWORD(pMsg->wParam)); @@ -318,10 +319,14 @@ int main(int argc, char *argv[]) SystemConsts systemConsts; pSystemConsts = &systemConsts; - pCharsetInfoManager = new CharsetInfoManager(language); - auto charsetInfoManager = std::unique_ptr(pCharsetInfoManager); + CharsetInfoManager charsetInfoManager(language); + pCharsetInfoManager=&charsetInfoManager; + + //We must use smarter point here, to manually control it's lifetime: + // when restore default settings, it must be destoyed before we remove all setting files. + auto settings = std::make_unique(settingFilename); //load settings - pSettings = new Settings(settingFilename); + pSettings = settings.get(); if (firstRun) { pSettings->compilerSets().findSets(); pSettings->compilerSets().saveSets(); @@ -345,11 +350,13 @@ int main(int argc, char *argv[]) //auto detect git in path pSettings->vcs().detectGitInPath(); } - auto settings = std::unique_ptr(pSettings); //Color scheme settings must be loaded after translation - pColorManager = new ColorManager(); - pIconsManager = new IconsManager(); - pAutolinkManager = new AutolinkManager(); + ColorManager colorManager; + pColorManager = &colorManager; + IconsManager iconsManager; + pIconsManager = &iconsManager; + AutolinkManager autolinkManager; + pAutolinkManager = &autolinkManager; try { pAutolinkManager->load(); } catch (FileError e) { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index c5377158..cde797c8 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -117,9 +117,12 @@ MainWindow::MainWindow(QWidget *parent) ui->setupUi(this); addActions( this->findChildren(QString(), Qt::FindChildrenRecursively)); // status bar + + //statusBar takes the owner ships mFileInfoStatus=new QLabel(); mFileEncodingStatus = new LabelWithMenu(); mFileModeStatus = new QLabel(); + mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px"); mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px"); mFileModeStatus->setStyleSheet("margin-left:10px; margin-right:10px"); @@ -128,6 +131,7 @@ MainWindow::MainWindow(QWidget *parent) ui->statusbar->insertPermanentWidget(0,mFileModeStatus); ui->statusbar->insertPermanentWidget(0,mFileEncodingStatus); ui->statusbar->insertPermanentWidget(0,mFileInfoStatus); + //delete in the destructor mEditorList = new EditorList(ui->EditorTabsLeft, ui->EditorTabsRight, ui->splitterEditorPanel, @@ -137,11 +141,15 @@ MainWindow::MainWindow(QWidget *parent) connect(mEditorList, &EditorList::editorClosed, this, &MainWindow::onEditorClosed); mProject = nullptr; - mProjectProxyModel = new ProjectModelSortFilterProxy(this); + //delete in the destructor + mProjectProxyModel = new ProjectModelSortFilterProxy(); + QItemSelectionModel *m=ui->projectView->selectionModel(); ui->projectView->setModel(mProjectProxyModel); + delete m; mProjectProxyModel->setDynamicSortFilter(false); ui->EditorTabsRight->setVisible(false); + //toolbar takes the owner mCompilerSet = new QComboBox(); mCompilerSet->setMinimumWidth(200); mCompilerSet->setSizeAdjustPolicy(QComboBox::AdjustToContents); @@ -151,17 +159,27 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::onCompilerSetChanged); //updateCompilerSet(); - mCompilerManager = new CompilerManager(this); - mDebugger = new Debugger(this); + mCompilerManager = std::make_shared(); + mDebugger = std::make_shared(); + m=ui->tblBreakpoints->selectionModel(); ui->tblBreakpoints->setModel(mDebugger->breakpointModel()); + delete m; + + m=ui->tblStackTrace->selectionModel(); ui->tblStackTrace->setModel(mDebugger->backtraceModel()); + delete m; + + m=ui->watchView->selectionModel(); ui->watchView->setModel(mDebugger->watchModel()); + delete m; + + m=ui->tblMemoryView->selectionModel(); ui->tblMemoryView->setModel(mDebugger->memoryModel()); + delete m; ui->tblMemoryView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); - try { mDebugger->breakpointModel()->load(includeTrailingPathDelimiter(pSettings->dirs().config()) +DEV_BREAKPOINTS_FILE); @@ -183,6 +201,7 @@ MainWindow::MainWindow(QWidget *parent) // ui->actionIndent->setShortcut(Qt::Key_Tab); // ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier); + //mainmenu takes the owner mMenuNew = new QMenu(); mMenuNew->setTitle(tr("New")); mMenuNew->addAction(ui->actionNew); @@ -269,14 +288,24 @@ MainWindow::MainWindow(QWidget *parent) tr("Error"), e.reason()); } + + m=ui->tableBookmark->selectionModel(); ui->tableBookmark->setModel(mBookmarkModel.get()); + delete m; + mSearchResultTreeModel = std::make_shared(&mSearchResultModel); mSearchResultListModel = std::make_shared(&mSearchResultModel); mSearchViewDelegate = std::make_shared(mSearchResultTreeModel); + ui->cbSearchHistory->setModel(mSearchResultListModel.get()); + + m=ui->searchView->selectionModel(); ui->searchView->setModel(mSearchResultTreeModel.get()); + delete m; ui->searchView->setItemDelegate(mSearchViewDelegate.get()); + m=ui->tableTODO->selectionModel(); ui->tableTODO->setModel(&mTodoModel); + delete m; connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset, ui->searchView,&QTreeView::expandAll); ui->replacePanel->setVisible(false); @@ -287,8 +316,12 @@ MainWindow::MainWindow(QWidget *parent) //problem set mOJProblemSetNameCounter=1; mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter)); + m=ui->lstProblemSet->selectionModel(); ui->lstProblemSet->setModel(&mOJProblemSetModel); + delete m; + m=ui->tblProblemCases->selectionModel(); ui->tblProblemCases->setModel(&mOJProblemModel); + delete m; connect(ui->lstProblemSet->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &MainWindow::onProblemSetIndexChanged); @@ -305,7 +338,9 @@ MainWindow::MainWindow(QWidget *parent) this, &MainWindow::updateProblemTitle); //files view + m=ui->treeFiles->selectionModel(); ui->treeFiles->setModel(&mFileSystemModel); + delete m; connect(&mFileSystemModel, &QFileSystemModel::layoutChanged, this, &MainWindow::onFileSystemModelLayoutChanged, Qt::QueuedConnection); mFileSystemModel.setReadOnly(false); @@ -324,7 +359,9 @@ MainWindow::MainWindow(QWidget *parent) //class browser ui->classBrowser->setUniformRowHeights(true); + m=ui->classBrowser->selectionModel(); ui->classBrowser->setModel(&mClassBrowserModel); + delete m; connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged, this, &MainWindow::onFileChanged); @@ -374,6 +411,7 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { + delete mProjectProxyModel; delete mEditorList; delete ui; } @@ -685,9 +723,9 @@ void MainWindow::applySettings() try { PAppTheme appTheme = themeManager.theme(pSettings->environment().theme()); if (appTheme->isDark()) - QApplication::setStyle(new DarkFusionStyle()); + QApplication::setStyle(new DarkFusionStyle());//app takes the onwership else - QApplication::setStyle(new LightFusionStyle()); + QApplication::setStyle(new LightFusionStyle());//app takes the onwership qApp->setPalette(appTheme->palette()); //fix for qstatusbar bug mFileEncodingStatus->setPalette(appTheme->palette()); @@ -1012,6 +1050,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu() } else { mMenuRecentFiles->setEnabled(true); for (const QString& filename: pSettings->history().opennedFiles()) { + //menu takes the ownership QAction* action = new QAction(filename,mMenuRecentFiles); connect(action, &QAction::triggered, [&filename,this](bool){ openFile(filename); @@ -1019,6 +1058,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu() mMenuRecentFiles->addAction(action); } mMenuRecentFiles->addSeparator(); + //menu takes the ownership QAction *action = new QAction(tr("Clear History"),mMenuRecentFiles); connect(action, &QAction::triggered, [](bool){ pSettings->history().clearOpennedFiles(); @@ -1031,6 +1071,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu() } else { mMenuRecentProjects->setEnabled(true); for (const QString& filename: pSettings->history().opennedProjects()) { + //menu takes the ownership QAction* action = new QAction(filename,mMenuRecentProjects); connect(action, &QAction::triggered, [&filename,this](bool){ this->openProject(filename); @@ -1038,6 +1079,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu() mMenuRecentProjects->addAction(action); } mMenuRecentProjects->addSeparator(); + //menu takes the ownership QAction *action = new QAction(tr("Clear History"),mMenuRecentProjects); connect(action, &QAction::triggered, [](bool){ pSettings->history().clearOpennedProjects(); @@ -1974,7 +2016,8 @@ void MainWindow::showSearchPanel(bool showReplace) void MainWindow::showCPUInfoDialog() { if (mCPUDialog==nullptr) { - mCPUDialog = new CPUDialog(); + //main window takes the owner + mCPUDialog = new CPUDialog(this); connect(mCPUDialog, &CPUDialog::closed, this, &MainWindow::cleanUpCPUDialog); updateCompileActions(); } @@ -4404,7 +4447,7 @@ EditorList *MainWindow::editorList() const Debugger *MainWindow::debugger() const { - return mDebugger; + return mDebugger.get(); } CPUDialog *MainWindow::cpuDialog() const @@ -5262,7 +5305,7 @@ void MainWindow::onDebugEvaluateInput() { QString s=ui->cbEvaluate->currentText().trimmed(); if (!s.isEmpty()) { - connect(mDebugger, &Debugger::evalValueReady, + connect(mDebugger.get(), &Debugger::evalValueReady, this, &MainWindow::onEvalValueReady); mDebugger->sendCommand("-data-evaluate-expression",s); pMainWindow->debugger()->refreshAll(); @@ -5330,7 +5373,7 @@ void MainWindow::onEndParsing(int total, int) void MainWindow::onEvalValueReady(const QString& value) { updateDebugEval(value); - disconnect(mDebugger, &Debugger::evalValueReady, + disconnect(mDebugger.get(), &Debugger::evalValueReady, this, &MainWindow::onEvalValueReady); } @@ -6950,8 +6993,8 @@ void MainWindow::on_actionLocate_in_Files_View_triggered() Editor * editor = mEditorList->getEditor(); if (editor) { QFileInfo fileInfo(editor->filename()); - qDebug()<model()->beginUpdate(); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index c1bce69a..273c3d22 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -721,8 +721,8 @@ private: QMenu *mMenuNew; QMenu *mMenuInsertCodeSnippet; QComboBox *mCompilerSet; - CompilerManager *mCompilerManager; - Debugger *mDebugger; + std::shared_ptr mCompilerManager; + std::shared_ptr mDebugger; CPUDialog *mCPUDialog; SearchDialog *mSearchDialog; bool mQuitting; @@ -839,7 +839,7 @@ private: QAction * mToolsOutput_SelectAll; QAction * mToolsOutput_Copy; - QSortFilterProxyModel* mProjectProxyModel; + QSortFilterProxyModel *mProjectProxyModel; // QWidget interface protected: diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 22977ddb..0bd76663 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -75,6 +75,7 @@ CppParser::~CppParser() QCoreApplication* app = QApplication::instance(); app->processEvents(); } + //qDebug()<<"-------- parser deleted ------------"; } void CppParser::addHardDefineByLine(const QString &line) @@ -4750,7 +4751,8 @@ CppFileParserThread::CppFileParserThread( mOnlyIfNotParsed(onlyIfNotParsed), mUpdateView(updateView) { - + connect(this,&QThread::finished, + this,&QObject::deleteLater); } void CppFileParserThread::run() @@ -4766,7 +4768,8 @@ CppFileListParserThread::CppFileListParserThread(PCppParser parser, mParser(parser), mUpdateView(updateView) { - + connect(this,&QThread::finished, + this,&QObject::deleteLater); } void CppFileListParserThread::run() @@ -4782,6 +4785,7 @@ void parseFile(PCppParser parser, const QString& fileName, bool inProject, bool return; if (!parser->enabled()) return; + //delete when finished CppFileParserThread* thread = new CppFileParserThread(parser,fileName,inProject,onlyIfNotParsed,updateView); thread->connect(thread, &QThread::finished, @@ -4796,6 +4800,7 @@ void parseFileList(PCppParser parser, bool updateView) return; if (!parser->enabled()) return; + //delete when finished CppFileListParserThread *thread = new CppFileListParserThread(parser,updateView); thread->connect(thread, &QThread::finished, diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index ff73fc96..c8c7ad05 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -1570,7 +1570,6 @@ void Project::closeUnit(PProjectUnit& unit) saveLayout(); Editor * editor = unitEditor(unit); if (editor) { - editor->setProject(nullptr); mEditorList->forceCloseEditor(editor); } } @@ -2454,6 +2453,7 @@ ProjectModel::ProjectModel(Project *project, QObject *parent): mProject(project) { mUpdateCount = 0; + //delete in the destructor mIconProvider = new CustomFileIconProvider(); } diff --git a/RedPandaIDE/settingsdialog/compilerautolinkwidget.cpp b/RedPandaIDE/settingsdialog/compilerautolinkwidget.cpp index b11fc96f..ebc1315f 100644 --- a/RedPandaIDE/settingsdialog/compilerautolinkwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilerautolinkwidget.cpp @@ -28,7 +28,9 @@ CompilerAutolinkWidget::CompilerAutolinkWidget(const QString& name, const QStrin ui(new Ui::CompilerAutolinkWidget) { ui->setupUi(this); + QItemSelectionModel* m=ui->tblAutolinks->selectionModel(); ui->tblAutolinks->setModel(&mModel); + delete m; } CompilerAutolinkWidget::~CompilerAutolinkWidget() diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp index 077ccae6..51058d13 100644 --- a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.cpp @@ -28,8 +28,9 @@ CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) : { ui->setupUi(this); - mModel = new CompilerSetDirectoriesWidget::ListModel(); - ui->listView->setModel(mModel); + QItemSelectionModel *m=ui->listView->selectionModel(); + ui->listView->setModel(&mModel); + delete m; connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CompilerSetDirectoriesWidget::selectionChanged); ui->listView->setSelectionMode(QAbstractItemView::SingleSelection); @@ -41,20 +42,26 @@ CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) : CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget() { delete ui; + //qDebug()<<"compiler set directory widget deleted"; } void CompilerSetDirectoriesWidget::setDirList(const QStringList &list) { - mModel->setStringList(list); + mModel.setStringList(list); QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes(); ui->btnDelete->setEnabled(lst.count()>0); } QStringList CompilerSetDirectoriesWidget::dirList() const { - return mModel->stringList(); + return mModel.stringList(); } +//CompilerSetDirectoriesWidget::ListModel::~ListModel() +//{ +// qDebug()<<"compiler set directory widget list model deleted"; +//} + Qt::ItemFlags CompilerSetDirectoriesWidget::ListModel::flags(const QModelIndex &index) const { Qt::ItemFlags flags = Qt::NoItemFlags; @@ -71,10 +78,10 @@ void CompilerSetDirectoriesWidget::on_btnAdd_pressed() { QString folder = QFileDialog::getExistingDirectory(this,tr("Choose Folder")); if (!folder.isEmpty()) { - int row = mModel->rowCount(); - mModel->insertRow(row); - QModelIndex index= mModel->index(row,0); - mModel->setData(index,folder,Qt::DisplayRole); + int row = mModel.rowCount(); + mModel.insertRow(row); + QModelIndex index= mModel.index(row,0); + mModel.setData(index,folder,Qt::DisplayRole); } } @@ -87,7 +94,7 @@ void CompilerSetDirectoriesWidget::on_btnDelete_pressed() { QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes(); if (lst.count()>0) { - mModel->removeRow(lst[0].row()); + mModel.removeRow(lst[0].row()); } } diff --git a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h index 58988178..3c5e6378 100644 --- a/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h +++ b/RedPandaIDE/settingsdialog/compilersetdirectorieswidget.h @@ -31,6 +31,7 @@ class CompilerSetDirectoriesWidget : public QWidget Q_OBJECT class ListModel: public QStringListModel { public: + //~ListModel(); Qt::ItemFlags flags(const QModelIndex &index) const; }; @@ -54,7 +55,7 @@ private slots: private: Ui::CompilerSetDirectoriesWidget *ui; - ListModel* mModel; + ListModel mModel; }; #endif // COMPILERSETDIRECTORIESWIDGET_H diff --git a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp index 02ecce09..b6bf5459 100644 --- a/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp +++ b/RedPandaIDE/settingsdialog/editorcolorschemewidget.cpp @@ -46,7 +46,9 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole); schemeCount++; } + QItemSelectionModel *m = ui->treeItems->selectionModel(); ui->treeItems->setModel(&mDefinesModel); + delete m; mDefinesModel.setHorizontalHeaderLabels(QStringList()); for (QString defineName : pColorManager->getDefines()) { addDefine(defineName, pColorManager->getDefine(defineName)); @@ -93,12 +95,14 @@ void EditorColorSchemeWidget::addDefine(const QString& name, PColorSchemeItemDef QList items = mDefinesModel.findItems(define->group()); QStandardItem* pGroupItem; if (items.count() == 0 ) { + //delete in the destructor pGroupItem = new QStandardItem(define->group()); pGroupItem->setData("", NameRole); mDefinesModel.appendRow(pGroupItem); } else { pGroupItem = items[0]; } + //delete in the destructor QStandardItem* pWidgetItem = new QStandardItem(define->displayName()); pWidgetItem->setData(name, NameRole); pGroupItem->appendRow(pWidgetItem); @@ -178,6 +182,7 @@ void EditorColorSchemeWidget::setCurrentSchemeModified() EditorColorSchemeWidget::~EditorColorSchemeWidget() { delete ui; + mDefinesModel.clear(); } static void setColorProp(ColorEdit* ce, QCheckBox* cb, const QColor& color) { diff --git a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp index dd303220..dff3d3d3 100644 --- a/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp +++ b/RedPandaIDE/settingsdialog/editorsnippetwidget.cpp @@ -29,7 +29,9 @@ EditorSnippetWidget::EditorSnippetWidget(const QString& name, const QString& gro { mUpdatingCode = false; ui->setupUi(this); + QItemSelectionModel* m=ui->tblSnippets->selectionModel(); ui->tblSnippets->setModel(&mModel); + delete m; connect(ui->editCode, &Editor::changed, [this] { if (mUpdatingCode) diff --git a/RedPandaIDE/settingsdialog/environmentfileassociationwidget.cpp b/RedPandaIDE/settingsdialog/environmentfileassociationwidget.cpp index a7f84182..6eb9d065 100644 --- a/RedPandaIDE/settingsdialog/environmentfileassociationwidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentfileassociationwidget.cpp @@ -35,7 +35,9 @@ EnvironmentFileAssociationWidget::EnvironmentFileAssociationWidget(const QString mModel.addItem("C++ Header File","hpp",4); mModel.addItem("C++ Header File","hxx",4); mModel.addItem("Red Panda C++ Project File","dev",5); + QItemSelectionModel* m = ui->lstFileTypes->selectionModel(); ui->lstFileTypes->setModel(&mModel); + delete m; connect(&mModel, &FileAssociationModel::associationChanged, [this](){ setSettingsChanged(); diff --git a/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp b/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp index 5f6f1001..1c7ad797 100644 --- a/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp +++ b/RedPandaIDE/settingsdialog/environmentshortcutwidget.cpp @@ -28,7 +28,9 @@ EnvironmentShortcutWidget::EnvironmentShortcutWidget(const QString& name, const { ui->setupUi(this); mDelegate =new EnvironmentShortcutDelegate(this); + QItemSelectionModel* m=ui->tblShortcut->selectionModel(); ui->tblShortcut->setModel(&mModel); + delete m; ui->tblShortcut->setItemDelegate(mDelegate); connect(&mModel, &EnvironmentShortcutModel::shortcutChanged, this, &SettingsWidget::setSettingsChanged); diff --git a/RedPandaIDE/settingsdialog/projectfileswidget.cpp b/RedPandaIDE/settingsdialog/projectfileswidget.cpp index cd96a9eb..b3e47e95 100644 --- a/RedPandaIDE/settingsdialog/projectfileswidget.cpp +++ b/RedPandaIDE/settingsdialog/projectfileswidget.cpp @@ -38,7 +38,9 @@ void ProjectFilesWidget::doLoad() if (!project) return; copyUnits(); + QItemSelectionModel *m=ui->treeProject->selectionModel(); ui->treeProject->setModel(project->model()); + delete m; ui->treeProject->expandAll(); ui->grpFileOptions->setEnabled(false); } diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp index 9401dd8e..e5043fe8 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp @@ -104,7 +104,6 @@ void ProjectGeneralWidget::doSave() project->options().isCpp = ui->cbDefaultCpp->isChecked(); project->options().supportXPThemes = ui->cbSupportXPTheme->isChecked(); - qDebug()<<"iconpath"<= QT_VERSION_CHECK(5,15,0) || ui->lbIcon->pixmap(Qt::ReturnByValue).isNull()) { diff --git a/RedPandaIDE/settingsdialog/settingsdialog.cpp b/RedPandaIDE/settingsdialog/settingsdialog.cpp index 5e2d69c4..c88204f5 100644 --- a/RedPandaIDE/settingsdialog/settingsdialog.cpp +++ b/RedPandaIDE/settingsdialog/settingsdialog.cpp @@ -69,7 +69,9 @@ SettingsDialog::SettingsDialog(QWidget *parent) : setWindowFlag(Qt::WindowContextHelpButtonHint,false); ui->setupUi(this); + QItemSelectionModel *m=ui->widgetsView->selectionModel(); ui->widgetsView->setModel(&model); + delete m; model.setHorizontalHeaderLabels(QStringList()); diff --git a/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp b/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp index 856e86c6..11c63f0b 100644 --- a/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/toolsgeneralwidget.cpp @@ -29,7 +29,9 @@ ToolsGeneralWidget::ToolsGeneralWidget(const QString &name, const QString &group { ui->setupUi(this); ui->cbMacros->setModel(&mMacroInfoModel); + QItemSelectionModel *m=ui->lstTools->selectionModel(); ui->lstTools->setModel(&mToolsModel); + delete m; mEditType = EditType::None; finishEditing(false); connect(ui->lstTools->selectionModel(), &QItemSelectionModel::currentRowChanged, diff --git a/RedPandaIDE/vcs/gitlogdialog.cpp b/RedPandaIDE/vcs/gitlogdialog.cpp index fe8ad0e5..14bac078 100644 --- a/RedPandaIDE/vcs/gitlogdialog.cpp +++ b/RedPandaIDE/vcs/gitlogdialog.cpp @@ -15,7 +15,9 @@ GitLogDialog::GitLogDialog(const QString& folder, QWidget *parent) : mModel(folder) { ui->setupUi(this); + QItemSelectionModel* m=ui->tblLogs->selectionModel(); ui->tblLogs->setModel(&mModel); + delete m; ui->tblLogs->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); connect(ui->tblLogs,&QTableView::customContextMenuRequested, this, &GitLogDialog::onLogsContextMenu); diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index e6340ccf..246c20b2 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -37,7 +37,9 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) : mListView = new CodeCompletionListView(this); mModel=new CodeCompletionListModel(&mCompletionStatementList); mDelegate = new CodeCompletionListItemDelegate(mModel,this); + QItemSelectionModel *m=mListView->selectionModel(); mListView->setModel(mModel); + delete m; mListView->setItemDelegate(mDelegate); setLayout(new QVBoxLayout()); layout()->addWidget(mListView); diff --git a/RedPandaIDE/widgets/cpudialog.cpp b/RedPandaIDE/widgets/cpudialog.cpp index 7e45d2d8..7fa90904 100644 --- a/RedPandaIDE/widgets/cpudialog.cpp +++ b/RedPandaIDE/widgets/cpudialog.cpp @@ -55,7 +55,9 @@ CPUDialog::CPUDialog(QWidget *parent) : ui->txtCode->setBackgroundColor(palette().color(QPalette::Base)); } resetEditorFont(screenDPI()); + QItemSelectionModel *m=ui->lstRegister->selectionModel(); ui->lstRegister->setModel(pMainWindow->debugger()->registerModel()); + delete m; ui->rdIntel->setChecked(pSettings->debugger().useIntelStyle()); ui->chkBlendMode->setChecked(pSettings->debugger().blendMode()); diff --git a/RedPandaIDE/widgets/headercompletionpopup.cpp b/RedPandaIDE/widgets/headercompletionpopup.cpp index 1799b04f..a970a696 100644 --- a/RedPandaIDE/widgets/headercompletionpopup.cpp +++ b/RedPandaIDE/widgets/headercompletionpopup.cpp @@ -26,7 +26,9 @@ HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent) setWindowFlags(Qt::Popup); mListView = new CodeCompletionListView(this); mModel=new HeaderCompletionListModel(&mCompletionList); + QItemSelectionModel *m=mListView->selectionModel(); mListView->setModel(mModel); + delete m; setLayout(new QVBoxLayout()); layout()->addWidget(mListView); layout()->setMargin(0); diff --git a/RedPandaIDE/widgets/issuestable.cpp b/RedPandaIDE/widgets/issuestable.cpp index dd2a7270..8c3f5865 100644 --- a/RedPandaIDE/widgets/issuestable.cpp +++ b/RedPandaIDE/widgets/issuestable.cpp @@ -27,7 +27,9 @@ IssuesTable::IssuesTable(QWidget *parent): QTableView(parent) { mModel = new IssuesModel(this); + QItemSelectionModel *m=this->selectionModel(); this->setModel(mModel); + delete m; this->setColumnWidth(0,200); this->setColumnWidth(1,45); this->setColumnWidth(2,45); diff --git a/RedPandaIDE/widgets/qconsole.cpp b/RedPandaIDE/widgets/qconsole.cpp index 0113e314..94f04991 100644 --- a/RedPandaIDE/widgets/qconsole.cpp +++ b/RedPandaIDE/widgets/qconsole.cpp @@ -488,8 +488,6 @@ void QConsole::scrollTimerHandler() RowColumn mousePosRC = pixelsToNearestRowColumn(iMousePos.x(),iMousePos.y()); if (mScrollDeltaY != 0) { - qDebug()<<"scroll timer"< 0) // scrolling down? row+=mRowsInWindow - 1; mousePosRC.row = row - 1; - qDebug()< acts = actions(); - foreach (const QAction* action, acts) { - qDebug()<shortcut()[0]; - } +// foreach (const QAction* action, acts) { +// qDebug()<shortcut()[0]; +// } } void ShortcutInputEdit::keyPressEvent(QKeyEvent *event)