1 /* 2 * CoreAttributes.h - TaskJuggler 3 * 4 * Copyright (c) 2001, 2002, 2003, 2004, 2005 by Chris Schlaeger <cs@kde.org> 5 * Copyright (c) 2011 by Dag Andersen <danders@get2net.dk> 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 <cs@kde.org> 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 getType()46 virtual CAType getType() const { return CA_Undefined; } 47 getId()48 const QString& getId() const { return id; } 49 QString getFullId() const; 50 getDefinitionFile()51 const QString& getDefinitionFile() const { return definitionFile; } getDefinitionLine()52 uint getDefinitionLine() const { return definitionLine; } 53 setIndex(int idx)54 void setIndex(int idx) { index = idx; } getIndex()55 int getIndex() const { return index; } 56 setSequenceNo(uint no)57 void setSequenceNo(uint no) { sequenceNo = no; } getSequenceNo()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 getProject()67 Project* getProject() const { return project; } 68 setName(const QString & n)69 void setName(const QString& n) { name = n; } getName()70 const QString& getName() const { return name; } 71 void getFullName(QString& fullName) const; 72 getParent()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; addFlag(QString flag)81 void addFlag(QString flag) { flags.addFlag(flag); } purgeFlags()82 void purgeFlags() { flags.clear(); } clearFlag(const QString & flag)83 void clearFlag(const QString& flag) { flags.clearFlag(flag); } hasFlag(const QString & flag)84 bool hasFlag(const QString& flag) { return flags.hasFlag(flag); } getFlagList()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 isRoot()91 bool isRoot() const { return parent == 0; } 92 bool isLeaf() const; 93 94 void addCustomAttribute(const QString& id, CustomAttribute* ca); 95 const CustomAttribute* getCustomAttribute(const QString& id) const; getCustomAttributeDict()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 164