Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [project] Project information could not be obtained correctly #1042

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 57 additions & 29 deletions src/services/project/directorygenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,46 @@
#include "directoryasynparse.h"
#include "projectservice.h"

#include <QtConcurrent>

Check warning on line 9 in src/services/project/directorygenerator.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QtConcurrent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in src/services/project/directorygenerator.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QtConcurrent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

using namespace dpfservice;

struct GeneratorInfo
{
DirectoryAsynParse *parser { nullptr };
dpfservice::ProjectInfo projectInfo;
QStandardItem *item { nullptr };
};

class DirectoryGeneratorPrivate
{
friend class dpfservice::DirectoryGenerator;
QStandardItem *configureRootItem { nullptr };
QHash<QStandardItem *, DirectoryAsynParse *> projectParses {};
public:
GeneratorInfo findGeneratorInfo(DirectoryAsynParse *parser);

QHash<QStandardItem *, GeneratorInfo> projectParses {};
dpfservice::ProjectInfo prjInfo;
};

GeneratorInfo DirectoryGeneratorPrivate::findGeneratorInfo(DirectoryAsynParse *parser)
{
auto iter = std::find_if(projectParses.cbegin(), projectParses.cend(),
[parser](const GeneratorInfo &info) {
return info.parser == parser;
});

return iter == projectParses.cend() ? GeneratorInfo() : *iter;
}

DirectoryGenerator::DirectoryGenerator()
: d(new DirectoryGeneratorPrivate())
{
}

DirectoryGenerator::~DirectoryGenerator()
{
for (auto parser : d->projectParses.values())
if (parser)
delete parser;
for (auto info : d->projectParses.values())
if (info.parser)
delete info.parser;

if (d)
delete d;
Expand Down Expand Up @@ -68,18 +87,20 @@
using namespace dpfservice;

QStandardItem *rootItem = ProjectGenerator::createRootItem(info);
d->configureRootItem = rootItem;
auto parser = new DirectoryAsynParse();
d->projectParses[rootItem] = parser;
QObject::connect(d->projectParses[rootItem],
GeneratorInfo ginfo;
ginfo.parser = new DirectoryAsynParse();
ginfo.projectInfo = info;
ginfo.item = rootItem;
d->projectParses.insert(rootItem, ginfo);
QObject::connect(ginfo.parser,
&DirectoryAsynParse::itemsCreated,
this, &DirectoryGenerator::projectItemsCreated,
Qt::UniqueConnection);
QObject::connect(d->projectParses[rootItem],
QObject::connect(ginfo.parser,
&DirectoryAsynParse::reqUpdateItem,
this, &DirectoryGenerator::handleItemUpdated,
Qt::UniqueConnection);
QtConcurrent::run(parser, &DirectoryAsynParse::parseProject, info);
QtConcurrent::run(ginfo.parser, &DirectoryAsynParse::parseProject, info);

return rootItem;
}
Expand All @@ -88,7 +109,7 @@
{
if (!root)
return;
auto parser = d->projectParses[root];
auto info = d->projectParses[root];

while (root->hasChildren()) {
root->takeRow(0);
Expand All @@ -97,41 +118,48 @@

delete root;

if (parser)
delete parser;
if (info.parser)
delete info.parser;
}

void DirectoryGenerator::projectItemsCreated(QList<QStandardItem *> itemList)
{
auto sourceFiles = d->projectParses[d->configureRootItem]->getFilelist();
ProjectInfo tempInfo = prjInfo;
auto parser = qobject_cast<DirectoryAsynParse *>(sender());
auto info = d->findGeneratorInfo(parser);
if (!info.item)
return;

auto sourceFiles = parser->getFilelist();
ProjectInfo tempInfo = info.projectInfo;
tempInfo.setSourceFiles(sourceFiles);
ProjectInfo::set(d->configureRootItem, tempInfo);
ProjectInfo::set(info.item, tempInfo);
project.activeProject(tempInfo.kitName(), tempInfo.language(), tempInfo.workspaceFolder());

auto rootItem = d->projectParses.key(qobject_cast<DirectoryAsynParse *>(sender()));
if (rootItem) {
while (rootItem->hasChildren()) {
rootItem->removeRow(0);
if (info.item) {
while (info.item->hasChildren()) {
info.item->removeRow(0);
}
rootItem->appendRows(itemList);
info.item->appendRows(itemList);
}

rootItem->setData(Project::Done, Project::ParsingStateRole);
info.item->setData(Project::Done, Project::ParsingStateRole);
}

void DirectoryGenerator::handleItemUpdated(const QString &path)
{
auto parser = qobject_cast<DirectoryAsynParse *>(sender());
auto info = d->findGeneratorInfo(parser);
if (!info.item)
return;

ProjectService *prjSrv = dpfGetService(ProjectService);
Q_ASSERT(prjSrv);

auto parser = qobject_cast<DirectoryAsynParse *>(sender());
auto rootItem = d->projectParses.key(parser);
auto item = parser->findItem(path, rootItem);
auto item = parser->findItem(path, info.item);
if (!item)
item = rootItem;
item = info.item;
parser->updateItem(item);
if (auto model = rootItem->model())
if (auto model = info.item->model())
Q_EMIT model->layoutChanged();
prjSrv->restoreExpandState(item);
}
Loading