-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
as title Log: unit test plugin
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
cmake_minimum_required(VERSION 3.0.2) | ||
|
||
project(smartut) | ||
|
||
FILE(GLOB_RECURSE PROJECT_SOURCES | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*/*.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*/*.cpp" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*.json" | ||
) | ||
|
||
add_library(${PROJECT_NAME} | ||
SHARED | ||
${PROJECT_SOURCES} | ||
smartut.qrc | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} | ||
duc-framework | ||
duc-base | ||
duc-services | ||
duc-common | ||
${QtUseModules} | ||
${PkgUserModules} | ||
${DtkWidget_LIBRARIES} | ||
) | ||
|
||
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PLUGIN_INSTALL_PATH}) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "itemnode.h" | ||
#include "utils/utils.h" | ||
Check warning on line 6 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
|
||
#include "common/util/qtcassert.h" | ||
Check warning on line 8 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
#include "services/project/projectservice.h" | ||
Check warning on line 9 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
|
||
#include <DFileIconProvider> | ||
Check warning on line 11 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
|
||
#include <QFileInfo> | ||
Check warning on line 13 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
|
||
DWIDGET_USE_NAMESPACE | ||
using namespace dpfservice; | ||
|
||
ProjectNode *Node::parentProjectNode() const | ||
{ | ||
if (!nodeParentFolderNode) | ||
return nullptr; | ||
auto pn = nodeParentFolderNode->asProjectNode(); | ||
if (pn) | ||
return pn; | ||
return nodeParentFolderNode->parentProjectNode(); | ||
} | ||
|
||
FolderNode *Node::parentFolderNode() const | ||
{ | ||
return nodeParentFolderNode; | ||
} | ||
|
||
dpfservice::ProjectInfo Node::projectInfo() const | ||
Check warning on line 33 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
{ | ||
auto prjSrv = dpfGetService(ProjectService); | ||
Q_ASSERT(prjSrv); | ||
|
||
const auto &allInfos = prjSrv->getAllProjectInfo(); | ||
auto iter = std::find_if(allInfos.cbegin(), allInfos.cend(), | ||
[this](const ProjectInfo &info) { | ||
return nodeFilePath.startsWith(info.workspaceFolder()); | ||
}); | ||
|
||
return iter == allInfos.cend() ? ProjectInfo() : *iter; | ||
} | ||
|
||
QString Node::filePath() const | ||
{ | ||
return nodeFilePath; | ||
} | ||
|
||
QString Node::displayName() const | ||
{ | ||
return QFileInfo(nodeFilePath).fileName(); | ||
} | ||
|
||
QString Node::tooltip() const | ||
{ | ||
return nodeFilePath; | ||
} | ||
|
||
QIcon Node::icon() const | ||
{ | ||
return DFileIconProvider::globalProvider()->icon(QFileInfo(nodeFilePath)); | ||
} | ||
|
||
bool Node::sortByPath(const Node *a, const Node *b) | ||
Check warning on line 67 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
{ | ||
return a->filePath() < b->filePath(); | ||
} | ||
|
||
void Node::setParentFolderNode(FolderNode *parentFolder) | ||
{ | ||
nodeParentFolderNode = parentFolder; | ||
} | ||
|
||
void Node::setFilePath(const QString &filePath) | ||
{ | ||
nodeFilePath = filePath; | ||
} | ||
|
||
FileNode::FileNode(const QString &filePath) | ||
{ | ||
setFilePath(filePath); | ||
} | ||
|
||
void FileNode::setSourceFiles(const QStringList &files) | ||
Check warning on line 87 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
{ | ||
sourceList = files; | ||
} | ||
|
||
QStringList FileNode::sourceFiles() const | ||
{ | ||
return sourceList; | ||
} | ||
|
||
FolderNode::FolderNode(const QString &folderPath) | ||
{ | ||
setFilePath(folderPath); | ||
nodeDisplayName = Node::displayName(); | ||
} | ||
|
||
void FolderNode::setDisplayName(const QString &name) | ||
{ | ||
nodeDisplayName = name; | ||
} | ||
|
||
QString FolderNode::displayName() const | ||
{ | ||
return nodeDisplayName; | ||
} | ||
|
||
void FolderNode::addNode(std::unique_ptr<Node> &&node) | ||
{ | ||
QTC_ASSERT(node, return ); | ||
QTC_ASSERT(!node->parentFolderNode(), qDebug("Node has already a parent folder")); | ||
node->setParentFolderNode(this); | ||
children.emplace_back(std::move(node)); | ||
} | ||
|
||
const QList<Node *> FolderNode::nodes() const | ||
Check warning on line 121 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
{ | ||
QList<Node *> nodeList; | ||
std::transform(children.begin(), children.end(), std::back_inserter(nodeList), | ||
[](const auto &pointer) { | ||
return pointer.get(); | ||
}); | ||
return nodeList; | ||
} | ||
|
||
FolderNode *FolderNode::folderNode(const QString &directory) const | ||
{ | ||
auto iter = std::find_if(children.cbegin(), children.cend(), | ||
[directory](const std::unique_ptr<Node> &n) { | ||
FolderNode *fn = n->asFolderNode(); | ||
Check warning on line 135 in src/plugins/smartut/common/itemnode.cpp GitHub Actions / cppcheck
|
||
return fn && fn->filePath() == directory; | ||
}); | ||
|
||
return iter == children.cend() ? nullptr : static_cast<FolderNode *>(iter->get()); | ||
} | ||
|
||
FolderNode *FolderNode::findChildFolderNode(const std::function<bool(FolderNode *)> &predicate) const | ||
{ | ||
for (const std::unique_ptr<Node> &n : children) { | ||
if (FolderNode *fn = n->asFolderNode()) | ||
if (predicate(fn)) | ||
return fn; | ||
} | ||
return nullptr; | ||
} | ||
|
||
void FolderNode::addNestedNodes(std::vector<std::unique_ptr<FileNode>> &&files, | ||
const QString &overrideBaseDir, | ||
const FolderNodeFactory &factory) | ||
{ | ||
using DirWithNodes = std::pair<QString, std::vector<std::unique_ptr<FileNode>>>; | ||
std::vector<DirWithNodes> fileNodesPerDir; | ||
for (auto &f : files) { | ||
QFileInfo fileInfo(f->filePath()); | ||
const QString parentDir = fileInfo.absolutePath(); | ||
const auto it = std::lower_bound(fileNodesPerDir.begin(), fileNodesPerDir.end(), parentDir, | ||
[](const DirWithNodes &nad, const QString &dir) { return nad.first < dir; }); | ||
if (it != fileNodesPerDir.end() && it->first == parentDir) { | ||
it->second.emplace_back(std::move(f)); | ||
} else { | ||
DirWithNodes dirWithNodes; | ||
dirWithNodes.first = parentDir; | ||
dirWithNodes.second.emplace_back(std::move(f)); | ||
fileNodesPerDir.insert(it, std::move(dirWithNodes)); | ||
} | ||
} | ||
|
||
for (DirWithNodes &dirWithNodes : fileNodesPerDir) { | ||
FolderNode *const folderNode = Utils::recursiveFindOrCreateFolderNode(this, dirWithNodes.first, | ||
overrideBaseDir, factory); | ||
for (auto &f : dirWithNodes.second) | ||
folderNode->addNode(std::move(f)); | ||
} | ||
} | ||
|
||
QIcon FolderNode::icon() const | ||
{ | ||
if (!QFile::exists(filePath())) | ||
return QIcon::fromTheme("folder"); | ||
|
||
return Node::icon(); | ||
} | ||
|
||
VirtualFolderNode::VirtualFolderNode(const QString &folderPath) | ||
: FolderNode(folderPath) | ||
{ | ||
setFilePath(folderPath); | ||
} | ||
|
||
ProjectNode::ProjectNode(const QString &projectFilePath) | ||
: FolderNode(projectFilePath) | ||
{ | ||
setFilePath(projectFilePath); | ||
} |