1 /* 2 SPDX-License-Identifier: GPL-2.0-or-later 3 SPDX-FileCopyrightText: 2002-2021 Umbrello UML Modeller Authors <umbrello-devel@kde.org> 4 */ 5 6 #ifndef UMLLISTVIEWITEM_H 7 #define UMLLISTVIEWITEM_H 8 9 #include "basictypes.h" 10 #include "icon_utils.h" 11 12 #include <QDomDocument> 13 #include <QDomElement> 14 #include <QMap> 15 #include <QPointer> 16 #include <QTreeWidget> 17 #include <QXmlStreamWriter> 18 19 // forward declarations 20 class UMLListView; 21 class UMLObject; 22 class UMLClassifierListItem; 23 24 typedef QTreeWidgetItemIterator UMLListViewItemIterator; 25 26 /** 27 * Items used by the class @ref UMLListView. This is needed as the type 28 * and object information is required to be stored. 29 * 30 * @short Items used by @ref UMLListView. 31 * @author Paul Hensgen <phensgen@techie.com> 32 * @see UMLListView 33 * Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org 34 */ 35 class UMLListViewItem : public QTreeWidgetItem 36 { 37 public: 38 enum ListViewType 39 { 40 //the values in this enum are saved out to the file 41 //for file compatibility, only add new values to the end 42 lvt_Min = 799, 43 lvt_View = 800, 44 lvt_Logical_View, 45 lvt_UseCase_View, 46 lvt_Logical_Folder, 47 lvt_UseCase_Folder, 48 lvt_UseCase_Diagram, 49 lvt_Collaboration_Diagram, 50 lvt_Class_Diagram, 51 lvt_State_Diagram, 52 lvt_Activity_Diagram, 53 lvt_Sequence_Diagram, 54 lvt_Actor, 55 lvt_UseCase, 56 lvt_Class, 57 lvt_Attribute, 58 lvt_Operation, 59 lvt_Template, 60 lvt_Interface, 61 lvt_Package, 62 lvt_Component_Diagram, 63 lvt_Component_Folder, 64 lvt_Component_View, 65 lvt_Component, 66 lvt_Diagrams, // currently unused 67 lvt_Artifact, 68 lvt_Deployment_Diagram, 69 lvt_Deployment_Folder, 70 lvt_Deployment_View, 71 lvt_Node, 72 lvt_Datatype, 73 lvt_Datatype_Folder, 74 lvt_Enum, 75 lvt_Entity, 76 lvt_EntityAttribute, 77 lvt_EntityRelationship_Diagram, 78 lvt_EntityRelationship_Folder, 79 lvt_EntityRelationship_Model, 80 lvt_Subsystem, 81 lvt_Model, 82 lvt_EnumLiteral, 83 lvt_UniqueConstraint, 84 lvt_PrimaryKeyConstraint, 85 lvt_ForeignKeyConstraint, 86 lvt_CheckConstraint, 87 lvt_Category, 88 lvt_Port, 89 lvt_Properties, 90 lvt_Properties_AutoLayout, 91 lvt_Properties_Class, 92 lvt_Properties_CodeGeneration, 93 lvt_Properties_CodeImport, 94 lvt_Properties_CodeViewer, 95 lvt_Properties_Font, 96 lvt_Properties_General, 97 lvt_Properties_UserInterface, 98 lvt_Association, 99 lvt_Object_Diagram, 100 lvt_Instance, 101 lvt_InstanceAttribute, 102 // enter new values above 103 lvt_Max, 104 lvt_Unknown = -1 105 }; 106 107 static QString toString(ListViewType type); 108 109 UMLListViewItem(UMLListView * parent, const QString &name, ListViewType t, UMLObject* o = 0); 110 explicit UMLListViewItem(UMLListView * parent); 111 explicit UMLListViewItem(UMLListViewItem * parent); 112 UMLListViewItem(UMLListViewItem * parent, const QString &name, ListViewType t, UMLObject* o = 0); 113 UMLListViewItem(UMLListViewItem * parent, const QString &name, ListViewType t, Uml::ID::Type id); 114 ~UMLListViewItem(); 115 116 ListViewType type() const; 117 118 void setID(Uml::ID::Type id); 119 Uml::ID::Type ID() const; 120 121 void setUMLObject(UMLObject * obj); 122 UMLObject * umlObject() const; 123 124 bool isOwnParent(Uml::ID::Type listViewItemID); 125 126 void updateObject(); 127 void updateFolder(); 128 129 void setText(int column, const QString &text); 130 void setText(const QString &text); 131 QString getSavedText() const; 132 void setVisible(bool state); 133 134 QString toolTip() const; 135 136 void setIcon(Icon_Utils::IconType iconType); 137 138 void addChildItem(UMLObject *child, UMLListViewItem *childItem); 139 140 void deleteChildItem(UMLObject *child); 141 142 //virtual int compare(UMLListViewItem *other, int col, bool ascending) const; 143 144 UMLListViewItem* deepCopy(UMLListViewItem *newParent); 145 146 UMLListViewItem* findUMLObject(const UMLObject *o); 147 UMLListViewItem* findChildObject(UMLObject *child); 148 UMLListViewItem* findItem(Uml::ID::Type id); 149 150 UMLListViewItem* childItem(int i); 151 152 void saveToXMI1(QXmlStreamWriter& writer); 153 bool loadFromXMI1(QDomElement& qElement); 154 isOpen()155 bool isOpen() const { return isExpanded(); } 156 void setOpen(bool state); 157 158 public slots: 159 void slotEditFinished(const QString &newText); 160 161 protected: 162 void init(); 163 164 void cancelRenameWithMsg(); 165 166 /** 167 * Auxiliary map of child UMLListViewItems keyed by UMLObject. 168 * Used by findChildObject() for efficiency instead of looping using 169 * firstChild()/nextSibling() because the latter incur enforceItemVisible() 170 * and thus expensive sorting. 171 */ 172 typedef QMap<UMLObject*, UMLListViewItem*> ChildObjectMap; 173 174 ListViewType m_type; 175 Uml::ID::Type m_id; 176 QPointer<UMLObject> m_object; 177 QString m_label; 178 ChildObjectMap m_comap; 179 180 }; 181 182 QDebug operator<<(QDebug dbg, const UMLListViewItem& item); 183 184 #endif 185