@@ -111,7 +111,7 @@ QtCodeArea::~QtCodeArea()
|
||||
if (m_setIDECursorPositionAction != nullptr)
|
||||
{
|
||||
m_setIDECursorPositionAction->disconnect();
|
||||
delete m_setIDECursorPositionAction;
|
||||
m_setIDECursorPositionAction->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ QtCodeFileList::~QtCodeFileList()
|
||||
|
||||
void QtCodeFileList::clear()
|
||||
{
|
||||
for (QtCodeFile* file : m_files)
|
||||
{
|
||||
file->deleteLater();
|
||||
}
|
||||
|
||||
m_files.clear();
|
||||
verticalScrollBar()->setValue(0);
|
||||
}
|
||||
@@ -47,23 +52,21 @@ QtCodeFile* QtCodeFileList::getFile(const FilePath filePath)
|
||||
{
|
||||
QtCodeFile* file = nullptr;
|
||||
|
||||
for (const std::shared_ptr<QtCodeFile>& filePtr : m_files)
|
||||
for (QtCodeFile* filePtr : m_files)
|
||||
{
|
||||
if (filePtr->getFilePath() == filePath)
|
||||
{
|
||||
file = filePtr.get();
|
||||
file = filePtr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!file)
|
||||
{
|
||||
std::shared_ptr<QtCodeFile> filePtr = std::make_shared<QtCodeFile>(filePath, m_navigator);
|
||||
m_files.push_back(filePtr);
|
||||
file = new QtCodeFile(filePath, m_navigator);
|
||||
m_files.push_back(file);
|
||||
|
||||
file = filePtr.get();
|
||||
m_filesArea->layout()->addWidget(file);
|
||||
|
||||
file->hide();
|
||||
}
|
||||
|
||||
@@ -177,7 +180,7 @@ bool QtCodeFileList::requestScroll(const FilePath& filePath, uint lineNumber, Id
|
||||
|
||||
void QtCodeFileList::updateFiles()
|
||||
{
|
||||
for (const std::shared_ptr<QtCodeFile>& file : m_files)
|
||||
for (QtCodeFile* file : m_files)
|
||||
{
|
||||
file->updateContent();
|
||||
}
|
||||
@@ -185,25 +188,25 @@ void QtCodeFileList::updateFiles()
|
||||
|
||||
void QtCodeFileList::showContents()
|
||||
{
|
||||
for (const std::shared_ptr<QtCodeFile>& filePtr : m_files)
|
||||
for (QtCodeFile* file : m_files)
|
||||
{
|
||||
filePtr->show();
|
||||
file->show();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFileList::onWindowFocus()
|
||||
{
|
||||
for (const std::shared_ptr<QtCodeFile>& filePtr : m_files)
|
||||
for (QtCodeFile* file : m_files)
|
||||
{
|
||||
filePtr->updateTitleBar();
|
||||
file->updateTitleBar();
|
||||
}
|
||||
}
|
||||
|
||||
void QtCodeFileList::findScreenMatches(const std::string& query, std::vector<std::pair<QtCodeArea*, Id>>* screenMatches)
|
||||
{
|
||||
for (const std::shared_ptr<QtCodeFile>& filePtr : m_files)
|
||||
for (QtCodeFile* file : m_files)
|
||||
{
|
||||
filePtr->findScreenMatches(query, screenMatches);
|
||||
file->findScreenMatches(query, screenMatches);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,14 +229,14 @@ std::pair<QtCodeSnippet*, Id> QtCodeFileList::getFirstSnippetWithActiveLocationI
|
||||
{
|
||||
std::pair<QtCodeSnippet*, Id> result(nullptr, 0);
|
||||
|
||||
for (const std::shared_ptr<QtCodeFile>& filePtr : m_files)
|
||||
for (QtCodeFile* file : m_files)
|
||||
{
|
||||
if (filePtr->isCollapsed())
|
||||
if (file->isCollapsed())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
result = filePtr->getFirstSnippetWithActiveLocationId(tokenId);
|
||||
result = file->getFirstSnippetWithActiveLocationId(tokenId);
|
||||
if (result.first != nullptr)
|
||||
{
|
||||
break;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#ifndef QT_CODE_FILE_LIST
|
||||
#define QT_CODE_FILE_LIST
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <QFrame>
|
||||
@@ -55,7 +54,7 @@ private:
|
||||
QtCodeNavigator* m_navigator;
|
||||
QFrame* m_filesArea;
|
||||
|
||||
std::vector<std::shared_ptr<QtCodeFile>> m_files;
|
||||
std::vector<QtCodeFile*> m_files;
|
||||
|
||||
QtScrollSpeedChangeListener m_scrollSpeedChangeListener;
|
||||
};
|
||||
|
||||
@@ -85,6 +85,11 @@ void QtCodeFileSingle::clearCache()
|
||||
{
|
||||
clearFile();
|
||||
|
||||
for (auto& p : m_fileDatas)
|
||||
{
|
||||
p.second.area->deleteLater();
|
||||
}
|
||||
|
||||
m_fileDatas.clear();
|
||||
m_filePaths.clear();
|
||||
}
|
||||
@@ -113,7 +118,7 @@ void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params)
|
||||
file.title = params.title;
|
||||
}
|
||||
|
||||
file.area = std::make_shared<QtCodeArea>(1, params.code, params.locationFile, m_navigator, !params.reduced, this);
|
||||
file.area = new QtCodeArea(1, params.code, params.locationFile, m_navigator, !params.reduced, this);
|
||||
connect(file.area->verticalScrollBar(), &QScrollBar::valueChanged, m_navigator, &QtCodeNavigator::scrolled);
|
||||
|
||||
m_fileDatas.emplace(file.filePath, file);
|
||||
@@ -128,7 +133,12 @@ void QtCodeFileSingle::addCodeSnippet(const CodeSnippetParams& params)
|
||||
FilePath toDelete = m_filePaths.front();
|
||||
m_filePaths.pop_front();
|
||||
|
||||
m_fileDatas.erase(m_fileDatas.find(toDelete));
|
||||
auto it = m_fileDatas.find(toDelete);
|
||||
if (it != m_fileDatas.end())
|
||||
{
|
||||
it->second.area->deleteLater();
|
||||
m_fileDatas.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +282,7 @@ QtCodeFileSingle::FileData QtCodeFileSingle::getFileData(const FilePath& filePat
|
||||
|
||||
void QtCodeFileSingle::setFileData(const FileData& file)
|
||||
{
|
||||
if (file.area.get() == m_area)
|
||||
if (file.area == m_area)
|
||||
{
|
||||
if (m_area)
|
||||
{
|
||||
@@ -293,7 +303,7 @@ void QtCodeFileSingle::setFileData(const FileData& file)
|
||||
|
||||
if (file.area)
|
||||
{
|
||||
m_area = file.area.get();
|
||||
m_area = file.area;
|
||||
m_area->setSizePolicy(m_area->sizePolicy().horizontalPolicy(), QSizePolicy::Expanding);
|
||||
m_areaWrapper->layout()->addWidget(m_area);
|
||||
m_area->updateContent();
|
||||
|
||||
@@ -55,10 +55,10 @@ private:
|
||||
{
|
||||
FilePath filePath;
|
||||
TimeStamp modificationTime;
|
||||
bool isComplete;
|
||||
bool isComplete = false;
|
||||
std::string title;
|
||||
|
||||
std::shared_ptr<QtCodeArea> area;
|
||||
QtCodeArea* area = nullptr;
|
||||
};
|
||||
|
||||
FileData getFileData(const FilePath& filePath) const;
|
||||
|
||||
@@ -68,8 +68,7 @@ QtCodeSnippet::QtCodeSnippet(const CodeSnippetParams& params, QtCodeNavigator* n
|
||||
, m_footerString(params.footer)
|
||||
, m_title(nullptr)
|
||||
, m_footer(nullptr)
|
||||
, m_codeArea(std::make_shared<QtCodeArea>(
|
||||
params.startLineNumber, params.code, params.locationFile, navigator, !params.reduced, this))
|
||||
, m_codeArea(nullptr)
|
||||
{
|
||||
setObjectName("code_snippet");
|
||||
|
||||
@@ -93,7 +92,8 @@ QtCodeSnippet::QtCodeSnippet(const CodeSnippetParams& params, QtCodeNavigator* n
|
||||
connect(m_title, &QPushButton::clicked, this, &QtCodeSnippet::clickedTitle);
|
||||
}
|
||||
|
||||
layout->addWidget(m_codeArea.get());
|
||||
m_codeArea = new QtCodeArea(params.startLineNumber, params.code, params.locationFile, navigator, !params.reduced, this);
|
||||
layout->addWidget(m_codeArea);
|
||||
|
||||
if (m_footerString.size())
|
||||
{
|
||||
@@ -121,7 +121,7 @@ QtCodeFile* QtCodeSnippet::getFile() const
|
||||
|
||||
QtCodeArea* QtCodeSnippet::getArea() const
|
||||
{
|
||||
return m_codeArea.get();
|
||||
return m_codeArea;
|
||||
}
|
||||
|
||||
uint QtCodeSnippet::getStartLineNumber() const
|
||||
|
||||
@@ -74,7 +74,7 @@ private:
|
||||
|
||||
QPushButton* m_title;
|
||||
QPushButton* m_footer;
|
||||
std::shared_ptr<QtCodeArea> m_codeArea;
|
||||
QtCodeArea* m_codeArea;
|
||||
};
|
||||
|
||||
#endif // QT_CODE_SNIPPET_H
|
||||
|
||||
Reference in New Issue
Block a user