| 1 |
/* |
| 2 |
* CoreAttributes.h - TaskJuggler |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2001, 2002, 2003, 2004, 2005 Chris Schlaeger <[email protected]> |
| 5 |
* SPDX-FileCopyrightText: 2011 Dag Andersen <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of version 2 of the GNU General Public License as |
| 9 |
* published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* $Id$ |
| 12 |
*/ |
| 13 |
|
| 14 |
#ifndef _CoreAttributes_h_ |
| 15 |
#define _CoreAttributes_h_ |
| 16 |
|
| 17 |
#include "plantj_export.h" |
| 18 |
|
| 19 |
#include <QString> |
| 20 |
#include <QMap> |
| 21 |
|
| 22 |
#include "FlagList.h" |
| 23 |
#include "CustomAttribute.h" |
| 24 |
|
| 25 |
namespace TJ |
| 26 |
{ |
| 27 |
|
| 28 |
class Project; |
| 29 |
class CoreAttributes; |
| 30 |
class CoreAttributesList; |
| 31 |
class CoreAttributesListIterator; |
| 32 |
class CustomAttributeDefinition; |
| 33 |
|
| 34 |
/** |
| 35 |
* @short This class is the base class for all attribute classes. |
| 36 |
* @author Chris Schlaeger <[email protected]> |
| 37 |
*/ |
| 38 |
class PLANTJ_EXPORT CoreAttributes |
| 39 |
{ |
| 40 |
public: |
| 41 |
CoreAttributes(Project* p, const QString& i, const QString& n, |
| 42 |
CoreAttributes* parent_, const QString& df = QString(), |
| 43 |
uint dl = 0); |
| 44 |
virtual ~CoreAttributes(); |
| 45 |
|
| 46 |
virtual CAType getType() const { return CA_Undefined; } |
| 47 |
|
| 48 |
const QString& getId() const { return id; } |
| 49 |
QString getFullId() const; |
| 50 |
|
| 51 |
const QString& getDefinitionFile() const { return definitionFile; } |
| 52 |
uint getDefinitionLine() const { return definitionLine; } |
| 53 |
|
| 54 |
void setIndex(int idx) { index = idx; } |
| 55 |
int getIndex() const { return index; } |
| 56 |
|
| 57 |
void setSequenceNo(uint no) { sequenceNo = no; } |
| 58 |
uint getSequenceNo() const { return sequenceNo; } |
| 59 |
|
| 60 |
void setHierarchNo(uint no); |
| 61 |
QString getHierarchNo() const; |
| 62 |
|
| 63 |
void setHierarchIndex(uint no); |
| 64 |
QString getHierarchIndex() const; |
| 65 |
QString getHierarchLevel() const; |
| 66 |
|
| 67 |
Project* getProject() const { return project; } |
| 68 |
|
| 69 |
void setName(const QString& n) { name = n; } |
| 70 |
const QString& getName() const { return name; } |
| 71 |
void getFullName(QString& fullName) const; |
| 72 |
|
| 73 |
CoreAttributes* getParent() const { return parent; } |
| 74 |
|
| 75 |
uint treeLevel() const; |
| 76 |
|
| 77 |
CoreAttributesList getSubList() const; |
| 78 |
CoreAttributesListIterator getSubListIterator() const; |
| 79 |
|
| 80 |
bool hasSubs() const; |
| 81 |
void addFlag(QString flag) { flags.addFlag(flag); } |
| 82 |
void purgeFlags() { flags.clear(); } |
| 83 |
void clearFlag(const QString& flag) { flags.clearFlag(flag); } |
| 84 |
bool hasFlag(const QString& flag) { return flags.hasFlag(flag); } |
| 85 |
FlagList getFlagList() const { return flags; } |
| 86 |
|
| 87 |
bool hasSameAncestor(const CoreAttributes* c) const; |
| 88 |
bool isDescendantOf(const CoreAttributes* c) const; |
| 89 |
bool isParentOf(const CoreAttributes* c) const; |
| 90 |
|
| 91 |
bool isRoot() const { return parent == nullptr; } |
| 92 |
bool isLeaf() const; |
| 93 |
|
| 94 |
void addCustomAttribute(const QString& id, CustomAttribute* ca); |
| 95 |
const CustomAttribute* getCustomAttribute(const QString& id) const; |
| 96 |
const QMap<QString, CustomAttribute*>& getCustomAttributeDict() const |
| 97 |
{ |
| 98 |
return customAttributes; |
| 99 |
} |
| 100 |
void inheritCustomAttributes |
| 101 |
(const QMap<QString, CustomAttributeDefinition*>& dict); |
| 102 |
|
| 103 |
protected: |
| 104 |
/// A pointer to access information that are global to the project. |
| 105 |
Project* project; |
| 106 |
|
| 107 |
/// An ID that must be unique within the attribute class. |
| 108 |
QString id; |
| 109 |
|
| 110 |
/// A short description of the attribute. |
| 111 |
QString name; |
| 112 |
|
| 113 |
/// Pointer to parent. If there is no parent the pointer is 0. |
| 114 |
CoreAttributes* parent; |
| 115 |
|
| 116 |
/* Name of the tjp file that caused the creation of this CoreAttribute. It |
| 117 |
* may be empty if it was not created from a .tjp file. */ |
| 118 |
const QString definitionFile; |
| 119 |
|
| 120 |
/* Line in the .tjp file that caused the createtion of this Core |
| 121 |
* Attribute. It may be 0 if it was not created from a .tjp file. */ |
| 122 |
uint definitionLine; |
| 123 |
|
| 124 |
/** |
| 125 |
* The index of the attribute declaration within the project files. Each |
| 126 |
* attribute lists has it's own indices. |
| 127 |
*/ |
| 128 |
uint sequenceNo; |
| 129 |
|
| 130 |
/** |
| 131 |
* The index of the attribute declaration within it's parents children. |
| 132 |
*/ |
| 133 |
uint hierarchNo; |
| 134 |
/** |
| 135 |
* The index of the attributes in a logical order that takes the tree |
| 136 |
* structure and the start and end date into account. Each attribute list |
| 137 |
* has it's own indices. |
| 138 |
*/ |
| 139 |
int index; |
| 140 |
|
| 141 |
/** |
| 142 |
* The index of the attributes of the same parent in a logical order that |
| 143 |
* takes the tree structure and the start and end date into account. Each |
| 144 |
* attribute list has it's own indices. |
| 145 |
*/ |
| 146 |
uint hierarchIndex; |
| 147 |
|
| 148 |
/// List of child attributes. |
| 149 |
CoreAttributesList* sub; |
| 150 |
|
| 151 |
/// List of flags set for this attribute. |
| 152 |
FlagList flags; |
| 153 |
|
| 154 |
/// User defined, optional attributes. |
| 155 |
QMap<QString, CustomAttribute*> customAttributes; |
| 156 |
} ; |
| 157 |
|
| 158 |
} // namespace TJ |
| 159 |
|
| 160 |
PLANTJ_EXPORT QDebug operator<<(QDebug dbg, const TJ::CoreAttributes* t); |
| 161 |
PLANTJ_EXPORT QDebug operator<<(QDebug dbg, const TJ::CoreAttributes& t); |
| 162 |
|
| 163 |
#endif |