1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/*
SPDX-FileCopyrightText: 2015 Laszlo Kis-Adam
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KDEVPLATFORM_PROBLEMSTORENODE_H
#define KDEVPLATFORM_PROBLEMSTORENODE_H
#include <QString>
#include <interfaces/iproblem.h>
#include <shell/shellexport.h>
namespace KDevelop
{
/**
* @brief Base class for ProblemStoreNode classes, which together make up a tree structure with label or problem leaves.
*
* When adding a child the node is automatically reparented.
*
* Usage:
* @code
* ProblemStoreNode *root = new ProblemStoreNode();
* root->addChild(new ProblemStoreNode());
* root->addChild(new ProblemStoreNode());
* root->addChild(new ProblemStoreNode());
* root->count(); // Returns 3
* @endcode
*
*/
class KDEVPLATFORMSHELL_EXPORT ProblemStoreNode
{
public:
explicit ProblemStoreNode(ProblemStoreNode *parent = nullptr)
{
m_parent = parent;
}
virtual ~ProblemStoreNode()
{
clear();
}
/// Clear the children nodes
void clear()
{
qDeleteAll(m_children);
m_children.clear();
}
/// Tells if the node is a root node.
/// A node is considered a root node (in this context), when it has no parent
bool isRoot() const
{
if(!m_parent)
return true;
else
return false;
}
/// Returns the index of this node in the parent's child list.
int index()
{
if(!m_parent)
return -1;
const QVector<ProblemStoreNode*> &children = m_parent->children();
return children.indexOf(this);
}
/// Returns the parent of this node
ProblemStoreNode* parent() const{
return m_parent;
}
/// Sets the parent of this node
void setParent(ProblemStoreNode *parent)
{
m_parent = parent;
}
/// Returns the number of children nodes
int count() const
{
return m_children.count();
}
/// Returns a particular child node
ProblemStoreNode* child(int row) const
{
return m_children[row];
}
/// Returns the list of children nodes
const QVector<ProblemStoreNode*>& children() const{
return m_children;
}
/// Adds a child node, and reparents the child
void addChild(ProblemStoreNode *child)
{
m_children.push_back(child);
child->setParent(this);
}
/// Returns the label of this node, if there's one
virtual QString label() const{
return QString();
}
/// Returns the node's stored problem, if there's such
virtual IProblem::Ptr problem() const{
return IProblem::Ptr(nullptr);
}
private:
/// The parent node
ProblemStoreNode *m_parent;
/// Children nodes
QVector<ProblemStoreNode*> m_children;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* @brief A ProblemStoreNode that contains a label. For example: Label for severity or path grouping of problem nodes.
*
* Usage:
* @code
* ProblemStoreNode *root = new ProblemStoreNode();
* ...
* root->addChild(new LabelNode(root, QStringLiteral("ERROR")));
* root->children().last()->label(); // "ERROR"
* @endcode
*
*/
class KDEVPLATFORMSHELL_EXPORT LabelNode : public ProblemStoreNode
{
public:
explicit LabelNode(ProblemStoreNode *parent = nullptr, const QString &l = QString())
: ProblemStoreNode(parent)
, m_label(l)
{
}
~LabelNode() override
{
}
QString label() const override { return m_label; }
/// Sets the label
void setLabel(const QString &s){ m_label = s; }
private:
/// The label
QString m_label;
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* @brief A ProblemStoreNode that contains a problem. For example: as part of a problem list in a severity or path group.
*
* Usage:
* @code
* IProblem::Ptr problem1(new DetectedProblem());
* ...
* label->addChild(new ProblemNode(label, problem1));
* label->children().last()->problem(); // Provides problem1
* @endcode
*
*/
class KDEVPLATFORMSHELL_EXPORT ProblemNode : public ProblemStoreNode
{
public:
explicit ProblemNode(ProblemStoreNode *parent = nullptr, const IProblem::Ptr &problem = IProblem::Ptr(nullptr))
: ProblemStoreNode(parent)
, m_problem(problem)
{
}
~ProblemNode() override
{
}
IProblem::Ptr problem() const override {
return m_problem;
}
/// Sets the problem
void setProblem(const IProblem::Ptr &problem){
m_problem = problem;
}
private:
/// The problem
IProblem::Ptr m_problem;
};
}
#endif
|