ProjectExplorer: Use setters in ProjectExplorer::Node

Instead of constructor arguments. This makes it clearer on the
user side which value is actually changed.

Change-Id: I63ae8cd139a49700996c8874098111aad89ace22
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-02-25 13:06:09 +01:00
parent 1ca9b2b16e
commit f844f54cb7
4 changed files with 45 additions and 21 deletions

View File

@@ -107,8 +107,9 @@ void noAutoAdditionNotify(const QStringList &filePaths, const ProjectExplorer::P
}
CMakeInputsNode::CMakeInputsNode(const Utils::FileName &cmakeLists) :
ProjectExplorer::ProjectNode(cmakeLists, generateId(cmakeLists))
ProjectExplorer::ProjectNode(cmakeLists)
{
setNodeId(generateId(cmakeLists));
setPriority(Node::DefaultPriority - 10); // Bottom most!
setDisplayName(QCoreApplication::translate("CMakeFilesProjectNode", "CMake Modules"));
setIcon(QIcon(":/projectexplorer/images/session.png")); // TODO: Use a better icon!
@@ -174,8 +175,9 @@ bool CMakeProjectNode::addFiles(const QStringList &filePaths, QStringList *)
}
CMakeTargetNode::CMakeTargetNode(const Utils::FileName &directory, const QString &target) :
ProjectExplorer::ProjectNode(directory, generateId(directory, target))
ProjectExplorer::ProjectNode(directory)
{
setNodeId(generateId(directory, target));
setPriority(Node::DefaultProjectPriority + 900);
setIcon(QIcon(":/projectexplorer/images/build.png")); // TODO: Use proper icon!
setListInProject(false);

View File

@@ -119,8 +119,8 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
\sa ProjectExplorer::NodesWatcher
*/
Node::Node(NodeType nodeType, const Utils::FileName &filePath, int line, const QByteArray &id) :
m_filePath(filePath), m_nodeId(id), m_line(line), m_nodeType(nodeType)
Node::Node(NodeType nodeType)
: m_nodeType(nodeType)
{ }
void Node::setPriority(int p)
@@ -128,6 +128,21 @@ void Node::setPriority(int p)
m_priority = p;
}
void Node::setNodeId(const QByteArray &nodeId)
{
m_nodeId = nodeId;
}
void Node::setFilePath(const Utils::FileName &filePath)
{
m_filePath = filePath;
}
void Node::setLine(int line)
{
m_line = line;
}
void Node::setListInProject(bool l)
{
if (l)
@@ -315,11 +330,11 @@ FileType Node::fileTypeForFileName(const Utils::FileName &file)
\sa ProjectExplorer::FolderNode, ProjectExplorer::ProjectNode
*/
FileNode::FileNode(const Utils::FileName &filePath, const FileType fileType,
int line, const QByteArray &id) :
Node(NodeType::File, filePath, line, id),
FileNode::FileNode(const Utils::FileName &filePath, const FileType fileType) :
Node(NodeType::File),
m_fileType(fileType)
{
setFilePath(filePath);
setListInProject(true);
if (fileType == FileType::Project)
setPriority(DefaultProjectFilePriority);
@@ -329,7 +344,9 @@ FileNode::FileNode(const Utils::FileName &filePath, const FileType fileType,
FileNode *FileNode::clone() const
{
auto fn = new FileNode(filePath(), fileType(), line(), id());
auto fn = new FileNode(filePath(), fileType());
fn->setLine(line());
fn->setNodeId(id());
fn->setIsGenerated(isGenerated());
fn->setEnabled(isEnabled());
fn->setPriority(priority());
@@ -417,10 +434,11 @@ bool FileNode::supportsAction(ProjectAction action, const Node *node) const
\sa ProjectExplorer::FileNode, ProjectExplorer::ProjectNode
*/
FolderNode::FolderNode(const Utils::FileName &folderPath, NodeType nodeType,
const QString &displayName, const QByteArray &id) :
Node(nodeType, folderPath, -1, id),
const QString &displayName) :
Node(nodeType),
m_displayName(displayName)
{
setFilePath(folderPath);
setPriority(DefaultFolderPriority);
setListInProject(false);
setIsGenerated(false);
@@ -778,9 +796,10 @@ bool FolderNode::showWhenEmpty() const
*/
VirtualFolderNode::VirtualFolderNode(const Utils::FileName &folderPath, int priority,
const QByteArray &id) :
FolderNode(folderPath, NodeType::VirtualFolder, QString(), id)
FolderNode(folderPath, NodeType::VirtualFolder, QString())
{
setPriority(priority);
setNodeId(id);
}
QString VirtualFolderNode::addFileFilter() const
@@ -803,8 +822,8 @@ QString VirtualFolderNode::addFileFilter() const
/*!
Creates an uninitialized project node object.
*/
ProjectNode::ProjectNode(const Utils::FileName &projectFilePath, const QByteArray &id) :
FolderNode(projectFilePath, NodeType::Project, projectFilePath.fileName(), id)
ProjectNode::ProjectNode(const Utils::FileName &projectFilePath) :
FolderNode(projectFilePath, NodeType::Project, projectFilePath.fileName())
{
setPriority(DefaultProjectPriority);
setListInProject(true);

View File

@@ -160,10 +160,12 @@ public:
static FileType fileTypeForFileName(const Utils::FileName &file);
protected:
Node(NodeType nodeType, const Utils::FileName &filePath, int line = -1,
const QByteArray &id = {});
explicit Node(NodeType nodeType);
void setPriority(int priority);
void setLine(int line);
void setNodeId(const QByteArray &nodeId);
void setFilePath(const Utils::FileName &filePath);
private:
FolderNode *m_parentFolderNode = nullptr;
@@ -184,8 +186,7 @@ private:
class PROJECTEXPLORER_EXPORT FileNode : public Node
{
public:
FileNode(const Utils::FileName &filePath, const FileType fileType, int line = -1,
const QByteArray &id = {});
FileNode(const Utils::FileName &filePath, const FileType fileType);
FileNode *clone() const;
@@ -209,7 +210,7 @@ class PROJECTEXPLORER_EXPORT FolderNode : public Node
{
public:
explicit FolderNode(const Utils::FileName &folderPath, NodeType nodeType = NodeType::Folder,
const QString &displayName = QString(), const QByteArray &id = {});
const QString &displayName = QString());
QString displayName() const override;
QIcon icon() const;
@@ -354,7 +355,7 @@ public:
virtual bool setData(Core::Id role, const QVariant &value) const;
protected:
explicit ProjectNode(const Utils::FileName &projectFilePath, const QByteArray &id = {});
explicit ProjectNode(const Utils::FileName &projectFilePath);
};
class PROJECTEXPLORER_EXPORT ContainerNode : public FolderNode

View File

@@ -237,8 +237,10 @@ static bool supportsNodeAction(ProjectAction action, const Node *node)
QbsFileNode::QbsFileNode(const Utils::FileName &filePath,
const ProjectExplorer::FileType fileType,
int line) :
ProjectExplorer::FileNode(filePath, fileType, line, QByteArray{})
{}
ProjectExplorer::FileNode(filePath, fileType)
{
setLine(line);
}
QString QbsFileNode::displayName() const
{