- 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 - enhancement: add/new/remove/rename project files won't rebuild project tree
- fix: gliches in UI's left panel in some OS - fix: gliches in UI's left panel in some OS
- fix: correctly restore project layout when reopen it - 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: 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 Red Panda C++ Version 1.4

View File

@ -62,7 +62,7 @@ QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighte
QSynedit::PHighlighter HighlighterManager::getCppHighlighter() 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->asmAttribute()->setForeground(Qt::blue);
highlighter->charAttribute()->setForeground(Qt::black); highlighter->charAttribute()->setForeground(Qt::black);
highlighter->commentAttribute()->setForeground(0x8C8C8C); highlighter->commentAttribute()->setForeground(0x8C8C8C);
@ -84,14 +84,12 @@ QSynedit::PHighlighter HighlighterManager::getCppHighlighter()
highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red); highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red);
highlighter->symbolAttribute()->setForeground(0xc10000); highlighter->symbolAttribute()->setForeground(0xc10000);
highlighter->variableAttribute()->setForeground(0x400080); highlighter->variableAttribute()->setForeground(0x400080);
QSynedit::PHighlighter pHighlighter=std::make_shared<QSynedit::CppHighlighter>(); return highlighter;
return pHighlighter;
} }
QSynedit::PHighlighter HighlighterManager::getAsmHighlighter() QSynedit::PHighlighter HighlighterManager::getAsmHighlighter()
{ {
QSynedit::ASMHighlighter* highlighter = new QSynedit::ASMHighlighter(); std::shared_ptr<QSynedit::ASMHighlighter> highlighter=std::make_shared<QSynedit::ASMHighlighter>();
QSynedit::PHighlighter pHighlighter(highlighter);
highlighter->commentAttribute()->setForeground(0x8C8C8C); highlighter->commentAttribute()->setForeground(0x8C8C8C);
highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic); highlighter->commentAttribute()->setStyles(QSynedit::FontStyle::fsItalic);
highlighter->identifierAttribute()->setForeground(0x080808); highlighter->identifierAttribute()->setForeground(0x080808);
@ -100,13 +98,12 @@ QSynedit::PHighlighter HighlighterManager::getAsmHighlighter()
highlighter->whitespaceAttribute()->setForeground(Qt::lightGray); highlighter->whitespaceAttribute()->setForeground(Qt::lightGray);
highlighter->stringAttribute()->setForeground(0x007d17); highlighter->stringAttribute()->setForeground(0x007d17);
highlighter->symbolAttribute()->setForeground(0xc10000); highlighter->symbolAttribute()->setForeground(0xc10000);
return pHighlighter; return highlighter;
} }
QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter() QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter()
{ {
QSynedit::GLSLHighlighter* highlighter = new QSynedit::GLSLHighlighter(); std::shared_ptr<QSynedit::GLSLHighlighter> highlighter=std::make_shared<QSynedit::GLSLHighlighter>();
QSynedit::PHighlighter pHighlighter(highlighter);
highlighter->asmAttribute()->setForeground(Qt::blue); highlighter->asmAttribute()->setForeground(Qt::blue);
highlighter->charAttribute()->setForeground(Qt::black); highlighter->charAttribute()->setForeground(Qt::black);
highlighter->commentAttribute()->setForeground(0x8C8C8C); highlighter->commentAttribute()->setForeground(0x8C8C8C);
@ -128,7 +125,7 @@ QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter()
highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red); highlighter->stringEscapeSequenceAttribute()->setForeground(Qt::red);
highlighter->symbolAttribute()->setForeground(0xc10000); highlighter->symbolAttribute()->setForeground(0xc10000);
highlighter->variableAttribute()->setForeground(0x400080); highlighter->variableAttribute()->setForeground(0x400080);
return pHighlighter; return highlighter;
} }
void HighlighterManager::applyColorScheme(QSynedit::PHighlighter highlighter, const QString &schemeName) 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), mFilename(filename),
mRebuild(false) mRebuild(false)
{ {
} }
void Compiler::run() void Compiler::run()

View File

@ -81,6 +81,7 @@ void CompilerManager::compile(const QString& filename, const QByteArray& encodin
} }
mCompileErrorCount = 0; mCompileErrorCount = 0;
mCompileIssueCount = 0; mCompileIssueCount = 0;
//deleted when thread finished
mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax); mCompiler = new FileCompiler(filename,encoding,silent,onlyCheckSyntax);
mCompiler->setRebuild(rebuild); mCompiler->setRebuild(rebuild);
connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater); connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater);
@ -111,6 +112,7 @@ void CompilerManager::compileProject(std::shared_ptr<Project> project, bool rebu
} }
mCompileErrorCount = 0; mCompileErrorCount = 0;
mCompileIssueCount = 0; mCompileIssueCount = 0;
//deleted when thread finished
mCompiler = new ProjectCompiler(project,silent,onlyCheckSyntax); mCompiler = new ProjectCompiler(project,silent,onlyCheckSyntax);
mCompiler->setRebuild(rebuild); mCompiler->setRebuild(rebuild);
connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater); connect(mCompiler, &Compiler::finished, mCompiler, &QObject::deleteLater);
@ -142,6 +144,7 @@ void CompilerManager::cleanProject(std::shared_ptr<Project> project)
} }
mCompileErrorCount = 0; mCompileErrorCount = 0;
mCompileIssueCount = 0; mCompileIssueCount = 0;
//deleted when thread finished
ProjectCompiler* compiler = new ProjectCompiler(project,false,false); ProjectCompiler* compiler = new ProjectCompiler(project,false,false);
compiler->setOnlyClean(true); compiler->setOnlyClean(true);
mCompiler = compiler; mCompiler = compiler;
@ -195,6 +198,8 @@ void CompilerManager::checkSyntax(const QString &filename, const QByteArray& enc
mSyntaxCheckErrorCount = 0; mSyntaxCheckErrorCount = 0;
mSyntaxCheckIssueCount = 0; mSyntaxCheckIssueCount = 0;
//deleted when thread finished
StdinCompiler *pStdinCompiler = new StdinCompiler(filename,encoding, content,true,true); StdinCompiler *pStdinCompiler = new StdinCompiler(filename,encoding, content,true,true);
mBackgroundSyntaxChecker = pStdinCompiler; mBackgroundSyntaxChecker = pStdinCompiler;
mBackgroundSyntaxChecker->setProject(project); mBackgroundSyntaxChecker->setProject(project);
@ -239,9 +244,12 @@ void CompilerManager::run(
QString newArguments = QString(" %1 %2 \"%3\" %4") QString newArguments = QString(" %1 %2 \"%3\" %4")
.arg(consoleFlag) .arg(consoleFlag)
.arg(sharedMemoryId,localizePath(filename)).arg(arguments); .arg(sharedMemoryId,localizePath(filename)).arg(arguments);
//delete when thread finished
execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().appDir())+"ConsolePauser.exe",newArguments,workDir); execRunner = new ExecutableRunner(includeTrailingPathDelimiter(pSettings->dirs().appDir())+"ConsolePauser.exe",newArguments,workDir);
execRunner->setShareMemoryId(sharedMemoryId); execRunner->setShareMemoryId(sharedMemoryId);
} else { } else {
//delete when thread finished
execRunner = new ExecutableRunner(filename,arguments,workDir); execRunner = new ExecutableRunner(filename,arguments,workDir);
} }
#else #else
@ -280,6 +288,7 @@ void CompilerManager::run(
#endif #endif
execRunner->setStartConsole(true); execRunner->setStartConsole(true);
} else { } else {
//delete when thread finished
execRunner = new ExecutableRunner(filename,arguments,workDir); execRunner = new ExecutableRunner(filename,arguments,workDir);
} }
if (redirectInput) { if (redirectInput) {

View File

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

View File

@ -36,11 +36,13 @@
Debugger::Debugger(QObject *parent) : QObject(parent), Debugger::Debugger(QObject *parent) : QObject(parent),
mForceUTF8(false) mForceUTF8(false)
{ {
//models deleted in the destructor
mBreakpointModel=new BreakpointModel(this); mBreakpointModel=new BreakpointModel(this);
mBacktraceModel=new BacktraceModel(this); mBacktraceModel=new BacktraceModel(this);
mWatchModel = new WatchModel(this); mWatchModel = new WatchModel(this);
mRegisterModel = new RegisterModel(this); mRegisterModel = new RegisterModel(this);
mMemoryModel = new MemoryModel(8,this); mMemoryModel = new MemoryModel(8,this);
connect(mMemoryModel,&MemoryModel::setMemoryData, connect(mMemoryModel,&MemoryModel::setMemoryData,
this, &Debugger::setMemoryData); this, &Debugger::setMemoryData);
connect(mWatchModel, &WatchModel::setWatchVarValue, connect(mWatchModel, &WatchModel::setWatchVarValue,
@ -55,6 +57,15 @@ Debugger::Debugger(QObject *parent) : QObject(parent),
this, &Debugger::fetchVarChildren); 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) 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(); mMemoryModel->reset();
mWatchModel->resetAllVarInfos(); mWatchModel->resetAllVarInfos();
if (pSettings->debugger().useGDBServer()) { if (pSettings->debugger().useGDBServer()) {
//deleted when thread finished
mTarget = new DebugTarget(inferior,compilerSet->debugServer(),pSettings->debugger().GDBServerPort()); mTarget = new DebugTarget(inferior,compilerSet->debugServer(),pSettings->debugger().GDBServerPort());
if (pSettings->executor().redirectInput()) if (pSettings->executor().redirectInput())
mTarget->setInputFile(pSettings->executor().inputFilename()); mTarget->setInputFile(pSettings->executor().inputFilename());
@ -127,6 +139,7 @@ bool Debugger::start(int compilerSetIndex, const QString& inferior, const QStrin
mTarget->start(); mTarget->start();
mTarget->waitStart(); mTarget->waitStart();
} }
//delete when thread finished
mReader = new DebugReader(this); mReader = new DebugReader(this);
mReader->addBinDirs(binDirs); mReader->addBinDirs(binDirs);
mReader->addBinDir(pSettings->dirs().appDir()); mReader->addBinDir(pSettings->dirs().appDir());

View File

@ -258,6 +258,7 @@ class Debugger : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit Debugger(QObject *parent = nullptr); explicit Debugger(QObject *parent = nullptr);
~Debugger();
// Play/pause // Play/pause
bool start(int compilerSetIndex, const QString& inferior, const QStringList& binDirs); bool start(int compilerSetIndex, const QString& inferior, const QStringList& binDirs);
void sendCommand(const QString& command, const QString& params, void sendCommand(const QString& command, const QString& params,

View File

@ -191,6 +191,7 @@ Editor::Editor(QWidget *parent, const QString& filename,
} }
Editor::~Editor() { Editor::~Editor() {
//qDebug()<<"editor "<<mFilename<<" deleted";
if (mParentPageControl) { if (mParentPageControl) {
pMainWindow->fileSystemWatcher()->removePath(mFilename); pMainWindow->fileSystemWatcher()->removePath(mFilename);
pMainWindow->caretList().removeEditor(this); pMainWindow->caretList().removeEditor(this);
@ -221,7 +222,7 @@ void Editor::loadFile(QString filename) {
default: default:
mUseCppSyntax = pSettings->editor().defaultFileCpp(); mUseCppSyntax = pSettings->editor().defaultFileCpp();
} }
if (highlighter() && mParser) { if (highlighter()) {
reparse(); reparse();
if (pSettings->editor().syntaxCheckWhenLineChanged()) { if (pSettings->editor().syntaxCheckWhenLineChanged()) {
checkSyntaxInBack(); checkSyntaxInBack();
@ -1177,6 +1178,7 @@ bool Editor::event(QEvent *event)
QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event); QKeyEvent* keyEvent = dynamic_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Control) { if (keyEvent->key() == Qt::Key_Control) {
QApplication* app = dynamic_cast<QApplication *>(QApplication::instance()); QApplication* app = dynamic_cast<QApplication *>(QApplication::instance());
//postEvent takes the owner ship
QHoverEvent* hoverEvent=new QHoverEvent(QEvent::HoverMove, QHoverEvent* hoverEvent=new QHoverEvent(QEvent::HoverMove,
mapFromGlobal(QCursor::pos()), mapFromGlobal(QCursor::pos()),
mapFromGlobal(QCursor::pos()), mapFromGlobal(QCursor::pos()),
@ -1392,6 +1394,7 @@ void Editor::copyAsHTML()
exporter.ExportRange(document(),blockBegin(),blockEnd()); exporter.ExportRange(document(),blockBegin(),blockEnd());
//clipboard takes the owner ship
QMimeData * mimeData = new QMimeData; QMimeData * mimeData = new QMimeData;
//sethtml will convert buffer to QString , which will cause encoding trouble //sethtml will convert buffer to QString , which will cause encoding trouble
@ -2686,7 +2689,9 @@ void Editor::reparse()
if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp if (highlighter()->language() != QSynedit::HighlighterLanguage::Cpp
&& highlighter()->language() != QSynedit::HighlighterLanguage::GLSL) && highlighter()->language() != QSynedit::HighlighterLanguage::GLSL)
return; return;
if (mParser) if (!mParser)
return;
if (!mParser->enabled())
return; return;
//mParser->setEnabled(pSettings->codeCompletion().enabled()); //mParser->setEnabled(pSettings->codeCompletion().enabled());
ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C; ParserLanguage language = mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C;
@ -4297,7 +4302,7 @@ void Editor::reformat()
onLinesDeleted(1,document()->count()); onLinesDeleted(1,document()->count());
QByteArray content = text().toUtf8(); QByteArray content = text().toUtf8();
QStringList args = pSettings->codeFormatter().getArguments(); QStringList args = pSettings->codeFormatter().getArguments();
qDebug()<<args; //qDebug()<<args;
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QByteArray newContent = runAndGetOutput("astyle.exe", QByteArray newContent = runAndGetOutput("astyle.exe",
pSettings->dirs().appDir(), pSettings->dirs().appDir(),

View File

@ -52,6 +52,8 @@ Editor* EditorList::newEditor(const QString& filename, const QByteArray& encodin
if (fileExists(filename)) { if (fileExists(filename)) {
pMainWindow->fileSystemWatcher()->addPath(filename); pMainWindow->fileSystemWatcher()->addPath(filename);
} }
// parentPageControl takes the owner ship
Editor * e = new Editor(parentPageControl,filename,encoding,pProject,newFile,parentPageControl); Editor * e = new Editor(parentPageControl,filename,encoding,pProject,newFile,parentPageControl);
connect(e, &Editor::renamed, this, &EditorList::onEditorRenamed); connect(e, &Editor::renamed, this, &EditorList::onEditorRenamed);
updateLayout(); updateLayout();

View File

@ -228,7 +228,8 @@ QIcon IconsManager:: getIcon(IconName iconName) const
if (pixmap == mDefaultIconPixmap) if (pixmap == mDefaultIconPixmap)
return QIcon(); return QIcon();
if (mMakeDisabledIconDarker) { if (mMakeDisabledIconDarker) {
QIcon icon(new CustomDisabledIconEngine()); //QIcon takes the owner ship
QIcon icon(new CustomDisabledIconEngine);
icon.addPixmap(*pixmap); icon.addPixmap(*pixmap);
return icon; return icon;
} else } else

View File

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

View File

@ -131,6 +131,7 @@ bool WindowLogoutEventFilter::nativeEventFilter(const QByteArray & /*eventType*/
case WM_DPICHANGED:{ case WM_DPICHANGED:{
if (pMsg->hwnd == (HWND)pMainWindow->winId()) { if (pMsg->hwnd == (HWND)pMainWindow->winId()) {
int oldDPI = screenDPI(); int oldDPI = screenDPI();
//postEvent takes the owner ship
QEvent * dpiEvent = new QEvent(DPI_CHANGED_EVENT); QEvent * dpiEvent = new QEvent(DPI_CHANGED_EVENT);
qApp->postEvent(pMainWindow,dpiEvent); qApp->postEvent(pMainWindow,dpiEvent);
setScreenDPI(HIWORD(pMsg->wParam)); setScreenDPI(HIWORD(pMsg->wParam));
@ -318,10 +319,14 @@ int main(int argc, char *argv[])
SystemConsts systemConsts; SystemConsts systemConsts;
pSystemConsts = &systemConsts; pSystemConsts = &systemConsts;
pCharsetInfoManager = new CharsetInfoManager(language); CharsetInfoManager charsetInfoManager(language);
auto charsetInfoManager = std::unique_ptr<CharsetInfoManager>(pCharsetInfoManager); 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 //load settings
pSettings = new Settings(settingFilename); pSettings = settings.get();
if (firstRun) { if (firstRun) {
pSettings->compilerSets().findSets(); pSettings->compilerSets().findSets();
pSettings->compilerSets().saveSets(); pSettings->compilerSets().saveSets();
@ -345,11 +350,13 @@ int main(int argc, char *argv[])
//auto detect git in path //auto detect git in path
pSettings->vcs().detectGitInPath(); pSettings->vcs().detectGitInPath();
} }
auto settings = std::unique_ptr<Settings>(pSettings);
//Color scheme settings must be loaded after translation //Color scheme settings must be loaded after translation
pColorManager = new ColorManager(); ColorManager colorManager;
pIconsManager = new IconsManager(); pColorManager = &colorManager;
pAutolinkManager = new AutolinkManager(); IconsManager iconsManager;
pIconsManager = &iconsManager;
AutolinkManager autolinkManager;
pAutolinkManager = &autolinkManager;
try { try {
pAutolinkManager->load(); pAutolinkManager->load();
} catch (FileError e) { } catch (FileError e) {

View File

@ -117,9 +117,12 @@ MainWindow::MainWindow(QWidget *parent)
ui->setupUi(this); ui->setupUi(this);
addActions( this->findChildren<QAction *>(QString(), Qt::FindChildrenRecursively)); addActions( this->findChildren<QAction *>(QString(), Qt::FindChildrenRecursively));
// status bar // status bar
//statusBar takes the owner ships
mFileInfoStatus=new QLabel(); mFileInfoStatus=new QLabel();
mFileEncodingStatus = new LabelWithMenu(); mFileEncodingStatus = new LabelWithMenu();
mFileModeStatus = new QLabel(); mFileModeStatus = new QLabel();
mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px"); mFileInfoStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px"); mFileEncodingStatus->setStyleSheet("margin-left:10px; margin-right:10px");
mFileModeStatus->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,mFileModeStatus);
ui->statusbar->insertPermanentWidget(0,mFileEncodingStatus); ui->statusbar->insertPermanentWidget(0,mFileEncodingStatus);
ui->statusbar->insertPermanentWidget(0,mFileInfoStatus); ui->statusbar->insertPermanentWidget(0,mFileInfoStatus);
//delete in the destructor
mEditorList = new EditorList(ui->EditorTabsLeft, mEditorList = new EditorList(ui->EditorTabsLeft,
ui->EditorTabsRight, ui->EditorTabsRight,
ui->splitterEditorPanel, ui->splitterEditorPanel,
@ -137,11 +141,15 @@ MainWindow::MainWindow(QWidget *parent)
connect(mEditorList, &EditorList::editorClosed, connect(mEditorList, &EditorList::editorClosed,
this, &MainWindow::onEditorClosed); this, &MainWindow::onEditorClosed);
mProject = nullptr; mProject = nullptr;
mProjectProxyModel = new ProjectModelSortFilterProxy(this); //delete in the destructor
mProjectProxyModel = new ProjectModelSortFilterProxy();
QItemSelectionModel *m=ui->projectView->selectionModel();
ui->projectView->setModel(mProjectProxyModel); ui->projectView->setModel(mProjectProxyModel);
delete m;
mProjectProxyModel->setDynamicSortFilter(false); mProjectProxyModel->setDynamicSortFilter(false);
ui->EditorTabsRight->setVisible(false); ui->EditorTabsRight->setVisible(false);
//toolbar takes the owner
mCompilerSet = new QComboBox(); mCompilerSet = new QComboBox();
mCompilerSet->setMinimumWidth(200); mCompilerSet->setMinimumWidth(200);
mCompilerSet->setSizeAdjustPolicy(QComboBox::AdjustToContents); mCompilerSet->setSizeAdjustPolicy(QComboBox::AdjustToContents);
@ -151,17 +159,27 @@ MainWindow::MainWindow(QWidget *parent)
this, &MainWindow::onCompilerSetChanged); this, &MainWindow::onCompilerSetChanged);
//updateCompilerSet(); //updateCompilerSet();
mCompilerManager = new CompilerManager(this); mCompilerManager = std::make_shared<CompilerManager>();
mDebugger = new Debugger(this); mDebugger = std::make_shared<Debugger>();
m=ui->tblBreakpoints->selectionModel();
ui->tblBreakpoints->setModel(mDebugger->breakpointModel()); ui->tblBreakpoints->setModel(mDebugger->breakpointModel());
delete m;
m=ui->tblStackTrace->selectionModel();
ui->tblStackTrace->setModel(mDebugger->backtraceModel()); ui->tblStackTrace->setModel(mDebugger->backtraceModel());
delete m;
m=ui->watchView->selectionModel();
ui->watchView->setModel(mDebugger->watchModel()); ui->watchView->setModel(mDebugger->watchModel());
delete m;
m=ui->tblMemoryView->selectionModel();
ui->tblMemoryView->setModel(mDebugger->memoryModel()); ui->tblMemoryView->setModel(mDebugger->memoryModel());
delete m;
ui->tblMemoryView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); ui->tblMemoryView->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
try { try {
mDebugger->breakpointModel()->load(includeTrailingPathDelimiter(pSettings->dirs().config()) mDebugger->breakpointModel()->load(includeTrailingPathDelimiter(pSettings->dirs().config())
+DEV_BREAKPOINTS_FILE); +DEV_BREAKPOINTS_FILE);
@ -183,6 +201,7 @@ MainWindow::MainWindow(QWidget *parent)
// ui->actionIndent->setShortcut(Qt::Key_Tab); // ui->actionIndent->setShortcut(Qt::Key_Tab);
// ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier); // ui->actionUnIndent->setShortcut(Qt::Key_Tab | Qt::ShiftModifier);
//mainmenu takes the owner
mMenuNew = new QMenu(); mMenuNew = new QMenu();
mMenuNew->setTitle(tr("New")); mMenuNew->setTitle(tr("New"));
mMenuNew->addAction(ui->actionNew); mMenuNew->addAction(ui->actionNew);
@ -269,14 +288,24 @@ MainWindow::MainWindow(QWidget *parent)
tr("Error"), tr("Error"),
e.reason()); e.reason());
} }
m=ui->tableBookmark->selectionModel();
ui->tableBookmark->setModel(mBookmarkModel.get()); ui->tableBookmark->setModel(mBookmarkModel.get());
delete m;
mSearchResultTreeModel = std::make_shared<SearchResultTreeModel>(&mSearchResultModel); mSearchResultTreeModel = std::make_shared<SearchResultTreeModel>(&mSearchResultModel);
mSearchResultListModel = std::make_shared<SearchResultListModel>(&mSearchResultModel); mSearchResultListModel = std::make_shared<SearchResultListModel>(&mSearchResultModel);
mSearchViewDelegate = std::make_shared<SearchResultTreeViewDelegate>(mSearchResultTreeModel); mSearchViewDelegate = std::make_shared<SearchResultTreeViewDelegate>(mSearchResultTreeModel);
ui->cbSearchHistory->setModel(mSearchResultListModel.get()); ui->cbSearchHistory->setModel(mSearchResultListModel.get());
m=ui->searchView->selectionModel();
ui->searchView->setModel(mSearchResultTreeModel.get()); ui->searchView->setModel(mSearchResultTreeModel.get());
delete m;
ui->searchView->setItemDelegate(mSearchViewDelegate.get()); ui->searchView->setItemDelegate(mSearchViewDelegate.get());
m=ui->tableTODO->selectionModel();
ui->tableTODO->setModel(&mTodoModel); ui->tableTODO->setModel(&mTodoModel);
delete m;
connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset, connect(mSearchResultTreeModel.get() , &QAbstractItemModel::modelReset,
ui->searchView,&QTreeView::expandAll); ui->searchView,&QTreeView::expandAll);
ui->replacePanel->setVisible(false); ui->replacePanel->setVisible(false);
@ -287,8 +316,12 @@ MainWindow::MainWindow(QWidget *parent)
//problem set //problem set
mOJProblemSetNameCounter=1; mOJProblemSetNameCounter=1;
mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter)); mOJProblemSetModel.rename(tr("Problem Set %1").arg(mOJProblemSetNameCounter));
m=ui->lstProblemSet->selectionModel();
ui->lstProblemSet->setModel(&mOJProblemSetModel); ui->lstProblemSet->setModel(&mOJProblemSetModel);
delete m;
m=ui->tblProblemCases->selectionModel();
ui->tblProblemCases->setModel(&mOJProblemModel); ui->tblProblemCases->setModel(&mOJProblemModel);
delete m;
connect(ui->lstProblemSet->selectionModel(), connect(ui->lstProblemSet->selectionModel(),
&QItemSelectionModel::currentRowChanged, &QItemSelectionModel::currentRowChanged,
this, &MainWindow::onProblemSetIndexChanged); this, &MainWindow::onProblemSetIndexChanged);
@ -305,7 +338,9 @@ MainWindow::MainWindow(QWidget *parent)
this, &MainWindow::updateProblemTitle); this, &MainWindow::updateProblemTitle);
//files view //files view
m=ui->treeFiles->selectionModel();
ui->treeFiles->setModel(&mFileSystemModel); ui->treeFiles->setModel(&mFileSystemModel);
delete m;
connect(&mFileSystemModel, &QFileSystemModel::layoutChanged, connect(&mFileSystemModel, &QFileSystemModel::layoutChanged,
this, &MainWindow::onFileSystemModelLayoutChanged, Qt::QueuedConnection); this, &MainWindow::onFileSystemModelLayoutChanged, Qt::QueuedConnection);
mFileSystemModel.setReadOnly(false); mFileSystemModel.setReadOnly(false);
@ -324,7 +359,9 @@ MainWindow::MainWindow(QWidget *parent)
//class browser //class browser
ui->classBrowser->setUniformRowHeights(true); ui->classBrowser->setUniformRowHeights(true);
m=ui->classBrowser->selectionModel();
ui->classBrowser->setModel(&mClassBrowserModel); ui->classBrowser->setModel(&mClassBrowserModel);
delete m;
connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged, connect(&mFileSystemWatcher,&QFileSystemWatcher::fileChanged,
this, &MainWindow::onFileChanged); this, &MainWindow::onFileChanged);
@ -374,6 +411,7 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete mProjectProxyModel;
delete mEditorList; delete mEditorList;
delete ui; delete ui;
} }
@ -685,9 +723,9 @@ void MainWindow::applySettings()
try { try {
PAppTheme appTheme = themeManager.theme(pSettings->environment().theme()); PAppTheme appTheme = themeManager.theme(pSettings->environment().theme());
if (appTheme->isDark()) if (appTheme->isDark())
QApplication::setStyle(new DarkFusionStyle()); QApplication::setStyle(new DarkFusionStyle());//app takes the onwership
else else
QApplication::setStyle(new LightFusionStyle()); QApplication::setStyle(new LightFusionStyle());//app takes the onwership
qApp->setPalette(appTheme->palette()); qApp->setPalette(appTheme->palette());
//fix for qstatusbar bug //fix for qstatusbar bug
mFileEncodingStatus->setPalette(appTheme->palette()); mFileEncodingStatus->setPalette(appTheme->palette());
@ -1012,6 +1050,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu()
} else { } else {
mMenuRecentFiles->setEnabled(true); mMenuRecentFiles->setEnabled(true);
for (const QString& filename: pSettings->history().opennedFiles()) { for (const QString& filename: pSettings->history().opennedFiles()) {
//menu takes the ownership
QAction* action = new QAction(filename,mMenuRecentFiles); QAction* action = new QAction(filename,mMenuRecentFiles);
connect(action, &QAction::triggered, [&filename,this](bool){ connect(action, &QAction::triggered, [&filename,this](bool){
openFile(filename); openFile(filename);
@ -1019,6 +1058,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu()
mMenuRecentFiles->addAction(action); mMenuRecentFiles->addAction(action);
} }
mMenuRecentFiles->addSeparator(); mMenuRecentFiles->addSeparator();
//menu takes the ownership
QAction *action = new QAction(tr("Clear History"),mMenuRecentFiles); QAction *action = new QAction(tr("Clear History"),mMenuRecentFiles);
connect(action, &QAction::triggered, [](bool){ connect(action, &QAction::triggered, [](bool){
pSettings->history().clearOpennedFiles(); pSettings->history().clearOpennedFiles();
@ -1031,6 +1071,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu()
} else { } else {
mMenuRecentProjects->setEnabled(true); mMenuRecentProjects->setEnabled(true);
for (const QString& filename: pSettings->history().opennedProjects()) { for (const QString& filename: pSettings->history().opennedProjects()) {
//menu takes the ownership
QAction* action = new QAction(filename,mMenuRecentProjects); QAction* action = new QAction(filename,mMenuRecentProjects);
connect(action, &QAction::triggered, [&filename,this](bool){ connect(action, &QAction::triggered, [&filename,this](bool){
this->openProject(filename); this->openProject(filename);
@ -1038,6 +1079,7 @@ void MainWindow::rebuildOpenedFileHisotryMenu()
mMenuRecentProjects->addAction(action); mMenuRecentProjects->addAction(action);
} }
mMenuRecentProjects->addSeparator(); mMenuRecentProjects->addSeparator();
//menu takes the ownership
QAction *action = new QAction(tr("Clear History"),mMenuRecentProjects); QAction *action = new QAction(tr("Clear History"),mMenuRecentProjects);
connect(action, &QAction::triggered, [](bool){ connect(action, &QAction::triggered, [](bool){
pSettings->history().clearOpennedProjects(); pSettings->history().clearOpennedProjects();
@ -1974,7 +2016,8 @@ void MainWindow::showSearchPanel(bool showReplace)
void MainWindow::showCPUInfoDialog() void MainWindow::showCPUInfoDialog()
{ {
if (mCPUDialog==nullptr) { if (mCPUDialog==nullptr) {
mCPUDialog = new CPUDialog(); //main window takes the owner
mCPUDialog = new CPUDialog(this);
connect(mCPUDialog, &CPUDialog::closed, this, &MainWindow::cleanUpCPUDialog); connect(mCPUDialog, &CPUDialog::closed, this, &MainWindow::cleanUpCPUDialog);
updateCompileActions(); updateCompileActions();
} }
@ -4404,7 +4447,7 @@ EditorList *MainWindow::editorList() const
Debugger *MainWindow::debugger() const Debugger *MainWindow::debugger() const
{ {
return mDebugger; return mDebugger.get();
} }
CPUDialog *MainWindow::cpuDialog() const CPUDialog *MainWindow::cpuDialog() const
@ -5262,7 +5305,7 @@ void MainWindow::onDebugEvaluateInput()
{ {
QString s=ui->cbEvaluate->currentText().trimmed(); QString s=ui->cbEvaluate->currentText().trimmed();
if (!s.isEmpty()) { if (!s.isEmpty()) {
connect(mDebugger, &Debugger::evalValueReady, connect(mDebugger.get(), &Debugger::evalValueReady,
this, &MainWindow::onEvalValueReady); this, &MainWindow::onEvalValueReady);
mDebugger->sendCommand("-data-evaluate-expression",s); mDebugger->sendCommand("-data-evaluate-expression",s);
pMainWindow->debugger()->refreshAll(); pMainWindow->debugger()->refreshAll();
@ -5330,7 +5373,7 @@ void MainWindow::onEndParsing(int total, int)
void MainWindow::onEvalValueReady(const QString& value) void MainWindow::onEvalValueReady(const QString& value)
{ {
updateDebugEval(value); updateDebugEval(value);
disconnect(mDebugger, &Debugger::evalValueReady, disconnect(mDebugger.get(), &Debugger::evalValueReady,
this, &MainWindow::onEvalValueReady); this, &MainWindow::onEvalValueReady);
} }
@ -6950,8 +6993,8 @@ void MainWindow::on_actionLocate_in_Files_View_triggered()
Editor * editor = mEditorList->getEditor(); Editor * editor = mEditorList->getEditor();
if (editor) { if (editor) {
QFileInfo fileInfo(editor->filename()); QFileInfo fileInfo(editor->filename());
qDebug()<<fileInfo.absoluteFilePath(); //qDebug()<<fileInfo.absoluteFilePath();
qDebug()<<includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath()); //qDebug()<<includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath());
if (!fileInfo.absoluteFilePath().startsWith( if (!fileInfo.absoluteFilePath().startsWith(
includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath()), includeTrailingPathDelimiter(mFileSystemModel.rootDirectory().absolutePath()),
PATH_SENSITIVITY PATH_SENSITIVITY
@ -7761,7 +7804,6 @@ void MainWindow::on_actionGit_Log_triggered()
return; return;
GitLogDialog dialog(folder); GitLogDialog dialog(folder);
if (dialog.exec()==QDialog::Accepted) { if (dialog.exec()==QDialog::Accepted) {
qDebug()<<"yes";
//update project view //update project view
if (mProject) { if (mProject) {
mProject->model()->beginUpdate(); mProject->model()->beginUpdate();

View File

@ -721,8 +721,8 @@ private:
QMenu *mMenuNew; QMenu *mMenuNew;
QMenu *mMenuInsertCodeSnippet; QMenu *mMenuInsertCodeSnippet;
QComboBox *mCompilerSet; QComboBox *mCompilerSet;
CompilerManager *mCompilerManager; std::shared_ptr<CompilerManager> mCompilerManager;
Debugger *mDebugger; std::shared_ptr<Debugger> mDebugger;
CPUDialog *mCPUDialog; CPUDialog *mCPUDialog;
SearchDialog *mSearchDialog; SearchDialog *mSearchDialog;
bool mQuitting; bool mQuitting;
@ -839,7 +839,7 @@ private:
QAction * mToolsOutput_SelectAll; QAction * mToolsOutput_SelectAll;
QAction * mToolsOutput_Copy; QAction * mToolsOutput_Copy;
QSortFilterProxyModel* mProjectProxyModel; QSortFilterProxyModel *mProjectProxyModel;
// QWidget interface // QWidget interface
protected: protected:

View File

@ -75,6 +75,7 @@ CppParser::~CppParser()
QCoreApplication* app = QApplication::instance(); QCoreApplication* app = QApplication::instance();
app->processEvents(); app->processEvents();
} }
//qDebug()<<"-------- parser deleted ------------";
} }
void CppParser::addHardDefineByLine(const QString &line) void CppParser::addHardDefineByLine(const QString &line)
@ -4750,7 +4751,8 @@ CppFileParserThread::CppFileParserThread(
mOnlyIfNotParsed(onlyIfNotParsed), mOnlyIfNotParsed(onlyIfNotParsed),
mUpdateView(updateView) mUpdateView(updateView)
{ {
connect(this,&QThread::finished,
this,&QObject::deleteLater);
} }
void CppFileParserThread::run() void CppFileParserThread::run()
@ -4766,7 +4768,8 @@ CppFileListParserThread::CppFileListParserThread(PCppParser parser,
mParser(parser), mParser(parser),
mUpdateView(updateView) mUpdateView(updateView)
{ {
connect(this,&QThread::finished,
this,&QObject::deleteLater);
} }
void CppFileListParserThread::run() void CppFileListParserThread::run()
@ -4782,6 +4785,7 @@ void parseFile(PCppParser parser, const QString& fileName, bool inProject, bool
return; return;
if (!parser->enabled()) if (!parser->enabled())
return; return;
//delete when finished
CppFileParserThread* thread = new CppFileParserThread(parser,fileName,inProject,onlyIfNotParsed,updateView); CppFileParserThread* thread = new CppFileParserThread(parser,fileName,inProject,onlyIfNotParsed,updateView);
thread->connect(thread, thread->connect(thread,
&QThread::finished, &QThread::finished,
@ -4796,6 +4800,7 @@ void parseFileList(PCppParser parser, bool updateView)
return; return;
if (!parser->enabled()) if (!parser->enabled())
return; return;
//delete when finished
CppFileListParserThread *thread = new CppFileListParserThread(parser,updateView); CppFileListParserThread *thread = new CppFileListParserThread(parser,updateView);
thread->connect(thread, thread->connect(thread,
&QThread::finished, &QThread::finished,

View File

@ -1570,7 +1570,6 @@ void Project::closeUnit(PProjectUnit& unit)
saveLayout(); saveLayout();
Editor * editor = unitEditor(unit); Editor * editor = unitEditor(unit);
if (editor) { if (editor) {
editor->setProject(nullptr);
mEditorList->forceCloseEditor(editor); mEditorList->forceCloseEditor(editor);
} }
} }
@ -2454,6 +2453,7 @@ ProjectModel::ProjectModel(Project *project, QObject *parent):
mProject(project) mProject(project)
{ {
mUpdateCount = 0; mUpdateCount = 0;
//delete in the destructor
mIconProvider = new CustomFileIconProvider(); mIconProvider = new CustomFileIconProvider();
} }

View File

@ -28,7 +28,9 @@ CompilerAutolinkWidget::CompilerAutolinkWidget(const QString& name, const QStrin
ui(new Ui::CompilerAutolinkWidget) ui(new Ui::CompilerAutolinkWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
QItemSelectionModel* m=ui->tblAutolinks->selectionModel();
ui->tblAutolinks->setModel(&mModel); ui->tblAutolinks->setModel(&mModel);
delete m;
} }
CompilerAutolinkWidget::~CompilerAutolinkWidget() CompilerAutolinkWidget::~CompilerAutolinkWidget()

View File

@ -28,8 +28,9 @@ CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
mModel = new CompilerSetDirectoriesWidget::ListModel(); QItemSelectionModel *m=ui->listView->selectionModel();
ui->listView->setModel(mModel); ui->listView->setModel(&mModel);
delete m;
connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged, connect(ui->listView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &CompilerSetDirectoriesWidget::selectionChanged); this, &CompilerSetDirectoriesWidget::selectionChanged);
ui->listView->setSelectionMode(QAbstractItemView::SingleSelection); ui->listView->setSelectionMode(QAbstractItemView::SingleSelection);
@ -41,20 +42,26 @@ CompilerSetDirectoriesWidget::CompilerSetDirectoriesWidget(QWidget *parent) :
CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget() CompilerSetDirectoriesWidget::~CompilerSetDirectoriesWidget()
{ {
delete ui; delete ui;
//qDebug()<<"compiler set directory widget deleted";
} }
void CompilerSetDirectoriesWidget::setDirList(const QStringList &list) void CompilerSetDirectoriesWidget::setDirList(const QStringList &list)
{ {
mModel->setStringList(list); mModel.setStringList(list);
QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes(); QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes();
ui->btnDelete->setEnabled(lst.count()>0); ui->btnDelete->setEnabled(lst.count()>0);
} }
QStringList CompilerSetDirectoriesWidget::dirList() const 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 CompilerSetDirectoriesWidget::ListModel::flags(const QModelIndex &index) const
{ {
Qt::ItemFlags flags = Qt::NoItemFlags; Qt::ItemFlags flags = Qt::NoItemFlags;
@ -71,10 +78,10 @@ void CompilerSetDirectoriesWidget::on_btnAdd_pressed()
{ {
QString folder = QFileDialog::getExistingDirectory(this,tr("Choose Folder")); QString folder = QFileDialog::getExistingDirectory(this,tr("Choose Folder"));
if (!folder.isEmpty()) { if (!folder.isEmpty()) {
int row = mModel->rowCount(); int row = mModel.rowCount();
mModel->insertRow(row); mModel.insertRow(row);
QModelIndex index= mModel->index(row,0); QModelIndex index= mModel.index(row,0);
mModel->setData(index,folder,Qt::DisplayRole); mModel.setData(index,folder,Qt::DisplayRole);
} }
} }
@ -87,7 +94,7 @@ void CompilerSetDirectoriesWidget::on_btnDelete_pressed()
{ {
QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes(); QModelIndexList lst =ui->listView->selectionModel()->selectedIndexes();
if (lst.count()>0) { 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 Q_OBJECT
class ListModel: public QStringListModel { class ListModel: public QStringListModel {
public: public:
//~ListModel();
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;
}; };
@ -54,7 +55,7 @@ private slots:
private: private:
Ui::CompilerSetDirectoriesWidget *ui; Ui::CompilerSetDirectoriesWidget *ui;
ListModel* mModel; ListModel mModel;
}; };
#endif // COMPILERSETDIRECTORIESWIDGET_H #endif // COMPILERSETDIRECTORIESWIDGET_H

View File

@ -46,7 +46,9 @@ EditorColorSchemeWidget::EditorColorSchemeWidget(const QString& name, const QStr
ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole); ui->cbScheme->setItemData(schemeCount,mModifiedSchemeComboFont,Qt::FontRole);
schemeCount++; schemeCount++;
} }
QItemSelectionModel *m = ui->treeItems->selectionModel();
ui->treeItems->setModel(&mDefinesModel); ui->treeItems->setModel(&mDefinesModel);
delete m;
mDefinesModel.setHorizontalHeaderLabels(QStringList()); mDefinesModel.setHorizontalHeaderLabels(QStringList());
for (QString defineName : pColorManager->getDefines()) { for (QString defineName : pColorManager->getDefines()) {
addDefine(defineName, pColorManager->getDefine(defineName)); addDefine(defineName, pColorManager->getDefine(defineName));
@ -93,12 +95,14 @@ void EditorColorSchemeWidget::addDefine(const QString& name, PColorSchemeItemDef
QList<QStandardItem*> items = mDefinesModel.findItems(define->group()); QList<QStandardItem*> items = mDefinesModel.findItems(define->group());
QStandardItem* pGroupItem; QStandardItem* pGroupItem;
if (items.count() == 0 ) { if (items.count() == 0 ) {
//delete in the destructor
pGroupItem = new QStandardItem(define->group()); pGroupItem = new QStandardItem(define->group());
pGroupItem->setData("", NameRole); pGroupItem->setData("", NameRole);
mDefinesModel.appendRow(pGroupItem); mDefinesModel.appendRow(pGroupItem);
} else { } else {
pGroupItem = items[0]; pGroupItem = items[0];
} }
//delete in the destructor
QStandardItem* pWidgetItem = new QStandardItem(define->displayName()); QStandardItem* pWidgetItem = new QStandardItem(define->displayName());
pWidgetItem->setData(name, NameRole); pWidgetItem->setData(name, NameRole);
pGroupItem->appendRow(pWidgetItem); pGroupItem->appendRow(pWidgetItem);
@ -178,6 +182,7 @@ void EditorColorSchemeWidget::setCurrentSchemeModified()
EditorColorSchemeWidget::~EditorColorSchemeWidget() EditorColorSchemeWidget::~EditorColorSchemeWidget()
{ {
delete ui; delete ui;
mDefinesModel.clear();
} }
static void setColorProp(ColorEdit* ce, QCheckBox* cb, const QColor& color) { 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; mUpdatingCode = false;
ui->setupUi(this); ui->setupUi(this);
QItemSelectionModel* m=ui->tblSnippets->selectionModel();
ui->tblSnippets->setModel(&mModel); ui->tblSnippets->setModel(&mModel);
delete m;
connect(ui->editCode, &Editor::changed, connect(ui->editCode, &Editor::changed,
[this] { [this] {
if (mUpdatingCode) if (mUpdatingCode)

View File

@ -35,7 +35,9 @@ EnvironmentFileAssociationWidget::EnvironmentFileAssociationWidget(const QString
mModel.addItem("C++ Header File","hpp",4); mModel.addItem("C++ Header File","hpp",4);
mModel.addItem("C++ Header File","hxx",4); mModel.addItem("C++ Header File","hxx",4);
mModel.addItem("Red Panda C++ Project File","dev",5); mModel.addItem("Red Panda C++ Project File","dev",5);
QItemSelectionModel* m = ui->lstFileTypes->selectionModel();
ui->lstFileTypes->setModel(&mModel); ui->lstFileTypes->setModel(&mModel);
delete m;
connect(&mModel, &FileAssociationModel::associationChanged, connect(&mModel, &FileAssociationModel::associationChanged,
[this](){ [this](){
setSettingsChanged(); setSettingsChanged();

View File

@ -28,7 +28,9 @@ EnvironmentShortcutWidget::EnvironmentShortcutWidget(const QString& name, const
{ {
ui->setupUi(this); ui->setupUi(this);
mDelegate =new EnvironmentShortcutDelegate(this); mDelegate =new EnvironmentShortcutDelegate(this);
QItemSelectionModel* m=ui->tblShortcut->selectionModel();
ui->tblShortcut->setModel(&mModel); ui->tblShortcut->setModel(&mModel);
delete m;
ui->tblShortcut->setItemDelegate(mDelegate); ui->tblShortcut->setItemDelegate(mDelegate);
connect(&mModel, &EnvironmentShortcutModel::shortcutChanged, connect(&mModel, &EnvironmentShortcutModel::shortcutChanged,
this, &SettingsWidget::setSettingsChanged); this, &SettingsWidget::setSettingsChanged);

View File

@ -38,7 +38,9 @@ void ProjectFilesWidget::doLoad()
if (!project) if (!project)
return; return;
copyUnits(); copyUnits();
QItemSelectionModel *m=ui->treeProject->selectionModel();
ui->treeProject->setModel(project->model()); ui->treeProject->setModel(project->model());
delete m;
ui->treeProject->expandAll(); ui->treeProject->expandAll();
ui->grpFileOptions->setEnabled(false); ui->grpFileOptions->setEnabled(false);
} }

View File

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

View File

@ -69,7 +69,9 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
setWindowFlag(Qt::WindowContextHelpButtonHint,false); setWindowFlag(Qt::WindowContextHelpButtonHint,false);
ui->setupUi(this); ui->setupUi(this);
QItemSelectionModel *m=ui->widgetsView->selectionModel();
ui->widgetsView->setModel(&model); ui->widgetsView->setModel(&model);
delete m;
model.setHorizontalHeaderLabels(QStringList()); model.setHorizontalHeaderLabels(QStringList());

View File

@ -29,7 +29,9 @@ ToolsGeneralWidget::ToolsGeneralWidget(const QString &name, const QString &group
{ {
ui->setupUi(this); ui->setupUi(this);
ui->cbMacros->setModel(&mMacroInfoModel); ui->cbMacros->setModel(&mMacroInfoModel);
QItemSelectionModel *m=ui->lstTools->selectionModel();
ui->lstTools->setModel(&mToolsModel); ui->lstTools->setModel(&mToolsModel);
delete m;
mEditType = EditType::None; mEditType = EditType::None;
finishEditing(false); finishEditing(false);
connect(ui->lstTools->selectionModel(), &QItemSelectionModel::currentRowChanged, connect(ui->lstTools->selectionModel(), &QItemSelectionModel::currentRowChanged,

View File

@ -15,7 +15,9 @@ GitLogDialog::GitLogDialog(const QString& folder, QWidget *parent) :
mModel(folder) mModel(folder)
{ {
ui->setupUi(this); ui->setupUi(this);
QItemSelectionModel* m=ui->tblLogs->selectionModel();
ui->tblLogs->setModel(&mModel); ui->tblLogs->setModel(&mModel);
delete m;
ui->tblLogs->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu); ui->tblLogs->setContextMenuPolicy(Qt::ContextMenuPolicy::CustomContextMenu);
connect(ui->tblLogs,&QTableView::customContextMenuRequested, connect(ui->tblLogs,&QTableView::customContextMenuRequested,
this, &GitLogDialog::onLogsContextMenu); this, &GitLogDialog::onLogsContextMenu);

View File

@ -37,7 +37,9 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) :
mListView = new CodeCompletionListView(this); mListView = new CodeCompletionListView(this);
mModel=new CodeCompletionListModel(&mCompletionStatementList); mModel=new CodeCompletionListModel(&mCompletionStatementList);
mDelegate = new CodeCompletionListItemDelegate(mModel,this); mDelegate = new CodeCompletionListItemDelegate(mModel,this);
QItemSelectionModel *m=mListView->selectionModel();
mListView->setModel(mModel); mListView->setModel(mModel);
delete m;
mListView->setItemDelegate(mDelegate); mListView->setItemDelegate(mDelegate);
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
layout()->addWidget(mListView); layout()->addWidget(mListView);

View File

@ -55,7 +55,9 @@ CPUDialog::CPUDialog(QWidget *parent) :
ui->txtCode->setBackgroundColor(palette().color(QPalette::Base)); ui->txtCode->setBackgroundColor(palette().color(QPalette::Base));
} }
resetEditorFont(screenDPI()); resetEditorFont(screenDPI());
QItemSelectionModel *m=ui->lstRegister->selectionModel();
ui->lstRegister->setModel(pMainWindow->debugger()->registerModel()); ui->lstRegister->setModel(pMainWindow->debugger()->registerModel());
delete m;
ui->rdIntel->setChecked(pSettings->debugger().useIntelStyle()); ui->rdIntel->setChecked(pSettings->debugger().useIntelStyle());
ui->chkBlendMode->setChecked(pSettings->debugger().blendMode()); ui->chkBlendMode->setChecked(pSettings->debugger().blendMode());

View File

@ -26,7 +26,9 @@ HeaderCompletionPopup::HeaderCompletionPopup(QWidget* parent):QWidget(parent)
setWindowFlags(Qt::Popup); setWindowFlags(Qt::Popup);
mListView = new CodeCompletionListView(this); mListView = new CodeCompletionListView(this);
mModel=new HeaderCompletionListModel(&mCompletionList); mModel=new HeaderCompletionListModel(&mCompletionList);
QItemSelectionModel *m=mListView->selectionModel();
mListView->setModel(mModel); mListView->setModel(mModel);
delete m;
setLayout(new QVBoxLayout()); setLayout(new QVBoxLayout());
layout()->addWidget(mListView); layout()->addWidget(mListView);
layout()->setMargin(0); layout()->setMargin(0);

View File

@ -27,7 +27,9 @@ IssuesTable::IssuesTable(QWidget *parent):
QTableView(parent) QTableView(parent)
{ {
mModel = new IssuesModel(this); mModel = new IssuesModel(this);
QItemSelectionModel *m=this->selectionModel();
this->setModel(mModel); this->setModel(mModel);
delete m;
this->setColumnWidth(0,200); this->setColumnWidth(0,200);
this->setColumnWidth(1,45); this->setColumnWidth(1,45);
this->setColumnWidth(2,45); this->setColumnWidth(2,45);

View File

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

View File

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