- fix: minor memory leaks when set itemmodels

- fix: thread for parsing doesn't correctly released when parsing finished ( so and the parser)
This commit is contained in:
Roy Qu 2022-10-10 18:05:18 +08:00
parent 39c56aeff2
commit f67628863f
34 changed files with 178 additions and 58 deletions

View File

@ -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

View File

@ -62,7 +62,7 @@ QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighte
QSynedit::PHighlighter HighlighterManager::getCppHighlighter()
{
QSynedit::CppHighlighter* highlighter = new QSynedit::CppHighlighter();
std::shared_ptr<QSynedit::CppHighlighter> highlighter = std::make_shared<QSynedit::CppHighlighter>();
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<QSynedit::CppHighlighter>();
return pHighlighter;
return highlighter;
}
QSynedit::PHighlighter HighlighterManager::getAsmHighlighter()
{
QSynedit::ASMHighlighter* highlighter = new QSynedit::ASMHighlighter();
QSynedit::PHighlighter pHighlighter(highlighter);
std::shared_ptr<QSynedit::ASMHighlighter> highlighter=std::make_shared<QSynedit::ASMHighlighter>();
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<QSynedit::GLSLHighlighter> highlighter=std::make_shared<QSynedit::GLSLHighlighter>();
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)

View File

@ -42,7 +42,6 @@ Compiler::Compiler(const QString &filename, bool silent, bool onlyCheckSyntax):
mFilename(filename),
mRebuild(false)
{
}
void Compiler::run()

View File

@ -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> 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> 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) {

View File

@ -20,6 +20,7 @@
CustomFileIconProvider::CustomFileIconProvider()
{
//provider delete it in the destructor
mVCSRepository = new GitRepository("");
}

View File

@ -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());

View File

@ -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,

View File

@ -191,6 +191,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
}
Editor::~Editor() {
//qDebug()<<"editor "<<mFilename<<" deleted";
if (mParentPageControl) {
pMainWindow->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<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Control) {
QApplication* app = dynamic_cast<QApplication *>(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()<<args;
//qDebug()<<args;
#ifdef Q_OS_WIN
QByteArray newContent = runAndGetOutput("astyle.exe",
pSettings->dirs().appDir(),

View File

@ -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();

View File

@ -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

View File

@ -226,6 +226,7 @@ private:
QSize mActionIconSize;
QString mIconSetTemplate;
QString mIconSetsFolder;
bool mMakeDisabledIconDarker;
};

View File

@ -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<CharsetInfoManager>(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<Settings>(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<Settings>(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) {

View File

@ -117,9 +117,12 @@ MainWindow::MainWindow(QWidget *parent)
ui->setupUi(this);
addActions( this->findChildren<QAction *>(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<CompilerManager>();
mDebugger = std::make_shared<Debugger>();
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<SearchResultTreeModel>(&mSearchResultModel);
mSearchResultListModel = std::make_shared<SearchResultListModel>(&mSearchResultModel);
mSearchViewDelegate = std::make_shared<SearchResultTreeViewDelegate>(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()<<fileInfo.absoluteFilePath();
qDebug()<<includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath());
//qDebug()<<fileInfo.absoluteFilePath();
//qDebug()<<includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath());
if (!fileInfo.absoluteFilePath().startsWith(
includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath()),
PATH_SENSITIVITY
@ -7761,7 +7804,6 @@ void MainWindow::on_actionGit_Log_triggered()
return;
GitLogDialog dialog(folder);
if (dialog.exec()==QDialog::Accepted) {
qDebug()<<"yes";
//update project view
if (mProject) {
mProject->model()->beginUpdate();

View File

@ -721,8 +721,8 @@ private:
QMenu *mMenuNew;
QMenu *mMenuInsertCodeSnippet;
QComboBox *mCompilerSet;
CompilerManager *mCompilerManager;
Debugger *mDebugger;
std::shared_ptr<CompilerManager> mCompilerManager;
std::shared_ptr<Debugger> 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:

View File

@ -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,

View File

@ -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();
}

View File

@ -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()

View File

@ -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());
}
}

View File

@ -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

View File

@ -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<QStandardItem*> 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) {

View File

@ -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)

View File

@ -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();

View File

@ -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);

View File

@ -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);
}

View File

@ -104,7 +104,6 @@ void ProjectGeneralWidget::doSave()
project->options().isCpp = ui->cbDefaultCpp->isChecked();
project->options().supportXPThemes = ui->cbSupportXPTheme->isChecked();
qDebug()<<"iconpath"<<mIconPath;
if (mIconPath.isEmpty()
#if QT_VERSION >= QT_VERSION_CHECK(5,15,0)
|| ui->lbIcon->pixmap(Qt::ReturnByValue).isNull()) {

View File

@ -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());

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -488,8 +488,6 @@ void QConsole::scrollTimerHandler()
RowColumn mousePosRC = pixelsToNearestRowColumn(iMousePos.x(),iMousePos.y());
if (mScrollDeltaY != 0) {
qDebug()<<"scroll timer"<<mScrollDeltaY;
qDebug()<<mousePosRC.row<<mousePosRC.column;
if (QApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier))
setTopRow(mTopRow + mScrollDeltaY * mRowsInWindow);
else
@ -498,7 +496,6 @@ void QConsole::scrollTimerHandler()
if (mScrollDeltaY > 0) // scrolling down?
row+=mRowsInWindow - 1;
mousePosRC.row = row - 1;
qDebug()<<row;
int oldStartRow = mContents.lineCharToRowColumn(selectionBegin()).row+1;
int oldEndRow = mContents.lineCharToRowColumn(selectionEnd()).row+1;
invalidateRows(oldStartRow,oldEndRow);

View File

@ -24,9 +24,9 @@
ShortcutInputEdit::ShortcutInputEdit(QWidget* parent):QLineEdit(parent)
{
QList<QAction *> acts = actions();
foreach (const QAction* action, acts) {
qDebug()<<action->shortcut()[0];
}
// foreach (const QAction* action, acts) {
// qDebug()<<action->shortcut()[0];
// }
}
void ShortcutInputEdit::keyPressEvent(QKeyEvent *event)