|
| 1 | +/*************************************************************************** |
| 2 | + qgsattributeeditorelement.sip - QgsAttributeEditorElement |
| 3 | + |
| 4 | + --------------------- |
| 5 | + begin : 18.8.2016 |
| 6 | + copyright : (C) 2016 by Matthias Kuhn |
| 7 | + email : matthias@opengis.ch |
| 8 | + *************************************************************************** |
| 9 | + * * |
| 10 | + * This program is free software; you can redistribute it and/or modify * |
| 11 | + * it under the terms of the GNU General Public License as published by * |
| 12 | + * the Free Software Foundation; either version 2 of the License, or * |
| 13 | + * (at your option) any later version. * |
| 14 | + * * |
| 15 | + ***************************************************************************/ |
| 16 | + |
| 17 | +/** \ingroup core |
| 18 | + * This is an abstract base class for any elements of a drag and drop form. |
| 19 | + * |
| 20 | + * This can either be a container which will be represented on the screen |
| 21 | + * as a tab widget or ca collapsible group box. Or it can be a field which will |
| 22 | + * then be represented based on the QgsEditorWidget type and configuration. |
| 23 | + * Or it can be a relation and embed the form of several children of another |
| 24 | + * layer. |
| 25 | + */ |
| 26 | + |
| 27 | +class QgsAttributeEditorElement |
| 28 | +{ |
| 29 | +%TypeHeaderCode |
| 30 | +#include <qgsattributeeditorelement.h> |
| 31 | +%End |
| 32 | + |
| 33 | +%ConvertToSubClassCode |
| 34 | +switch( sipCpp->type() ) |
| 35 | +{ |
| 36 | + case QgsAttributeEditorElement::AeTypeContainer: |
| 37 | + sipType = sipType_QgsAttributeEditorContainer; |
| 38 | + break; |
| 39 | + case QgsAttributeEditorElement::AeTypeField: |
| 40 | + sipType = sipType_QgsAttributeEditorField; |
| 41 | + break; |
| 42 | + case QgsAttributeEditorElement::AeTypeRelation: |
| 43 | + sipType = sipType_QgsAttributeEditorRelation; |
| 44 | + break; |
| 45 | + default: |
| 46 | + sipType = nullptr; |
| 47 | + break; |
| 48 | +} |
| 49 | +%End |
| 50 | + public: |
| 51 | + enum AttributeEditorType |
| 52 | + { |
| 53 | + AeTypeContainer, //!< A container |
| 54 | + AeTypeField, //!< A field |
| 55 | + AeTypeRelation, //!< A relation |
| 56 | + AeTypeInvalid //!< Invalid |
| 57 | + }; |
| 58 | + |
| 59 | + /** |
| 60 | + * Constructor |
| 61 | + * |
| 62 | + * @param type The type of the new element. Should never |
| 63 | + * @param name |
| 64 | + * @param parent |
| 65 | + */ |
| 66 | + QgsAttributeEditorElement( AttributeEditorType type, const QString& name, QgsAttributeEditorElement* parent = nullptr ); |
| 67 | + |
| 68 | + /** |
| 69 | + * Return the name of this element |
| 70 | + * |
| 71 | + * @return The name for this element |
| 72 | + */ |
| 73 | + QString name() const; |
| 74 | + |
| 75 | + /** |
| 76 | + * The type of this element |
| 77 | + * |
| 78 | + * @return The type |
| 79 | + */ |
| 80 | + AttributeEditorType type(); |
| 81 | + |
| 82 | + /** |
| 83 | + * Get the parent of this element. |
| 84 | + * |
| 85 | + * @note Added in QGIS 3.0 |
| 86 | + */ |
| 87 | + QgsAttributeEditorElement* parent() const; |
| 88 | + |
| 89 | + /** |
| 90 | + * Is reimplemented in classes inheriting from this to serialize it. |
| 91 | + * |
| 92 | + * @param doc The QDomDocument which is used to create new XML elements |
| 93 | + * |
| 94 | + * @return An DOM element which represents this element |
| 95 | + */ |
| 96 | + virtual QDomElement toDomElement( QDomDocument& doc ) const = 0; |
| 97 | + |
| 98 | + /** |
| 99 | + * Returns a clone of this element. To be implemented by subclasses. |
| 100 | + * |
| 101 | + * @note Added in QGIS 3.0 |
| 102 | + */ |
| 103 | + virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const = 0 /Factory/; |
| 104 | +}; |
| 105 | + |
| 106 | + |
| 107 | +/** \ingroup core |
| 108 | + * This is a container for attribute editors, used to group them visually in the |
| 109 | + * attribute form if it is set to the drag and drop designer. |
| 110 | + */ |
| 111 | +class QgsAttributeEditorContainer : QgsAttributeEditorElement |
| 112 | +{ |
| 113 | +%TypeHeaderCode |
| 114 | +#include <qgsattributeeditorelement.h> |
| 115 | +%End |
| 116 | +%ConvertToSubClassCode |
| 117 | + switch ( sipCpp->type() ) |
| 118 | + { |
| 119 | + case QgsAttributeEditorElement::AeTypeContainer: sipType = sipType_QgsAttributeEditorContainer; break; |
| 120 | + case QgsAttributeEditorElement::AeTypeField: sipType = sipType_QgsAttributeEditorField; break; |
| 121 | + case QgsAttributeEditorElement::AeTypeRelation: sipType = sipType_QgsAttributeEditorRelation; break; |
| 122 | + } |
| 123 | +%End |
| 124 | + public: |
| 125 | + /** |
| 126 | + * Creates a new attribute editor container |
| 127 | + * |
| 128 | + * @param name The name to show as title |
| 129 | + * @param parent The parent. May be another container. |
| 130 | + */ |
| 131 | + QgsAttributeEditorContainer( const QString& name, QgsAttributeEditorElement* parent ); |
| 132 | + |
| 133 | + /** |
| 134 | + * Will serialize this containers information into a QDomElement for saving it in an XML file. |
| 135 | + * |
| 136 | + * @param doc The QDomDocument used to generate the QDomElement |
| 137 | + * |
| 138 | + * @return The XML element |
| 139 | + */ |
| 140 | + virtual QDomElement toDomElement( QDomDocument& doc ) const; |
| 141 | + |
| 142 | + /** |
| 143 | + * Add a child element to this container. This may be another container, a field or a relation. |
| 144 | + * |
| 145 | + * @param element The element to add as child |
| 146 | + */ |
| 147 | + virtual void addChildElement( QgsAttributeEditorElement* element /Transfer/ ); |
| 148 | + |
| 149 | + /** |
| 150 | + * Determines if this container is rendered as collapsible group box or tab in a tabwidget |
| 151 | + * |
| 152 | + * @param isGroupBox If true, this will be a group box |
| 153 | + */ |
| 154 | + virtual void setIsGroupBox( bool isGroupBox ); |
| 155 | + |
| 156 | + /** |
| 157 | + * Returns if this container is going to be rendered as a group box |
| 158 | + * |
| 159 | + * @return True if it will be a group box, false if it will be a tab |
| 160 | + */ |
| 161 | + virtual bool isGroupBox() const; |
| 162 | + |
| 163 | + /** |
| 164 | + * Get a list of the children elements of this container |
| 165 | + * |
| 166 | + * @return A list of elements |
| 167 | + */ |
| 168 | + QList<QgsAttributeEditorElement*> children() const; |
| 169 | + |
| 170 | + /** |
| 171 | + * Traverses the element tree to find any element of the specified type |
| 172 | + * |
| 173 | + * @param type The type which should be searched |
| 174 | + * |
| 175 | + * @return A list of elements of the type which has been searched for |
| 176 | + */ |
| 177 | + virtual QList<QgsAttributeEditorElement*> findElements( AttributeEditorType type ) const; |
| 178 | + |
| 179 | + /** |
| 180 | + * Clear all children from this container. |
| 181 | + */ |
| 182 | + void clear(); |
| 183 | + |
| 184 | + /** |
| 185 | + * Change the name of this container |
| 186 | + */ |
| 187 | + void setName( const QString& name ); |
| 188 | + |
| 189 | + /** |
| 190 | + * Get the number of columns in this group |
| 191 | + */ |
| 192 | + int columnCount() const; |
| 193 | + |
| 194 | + /** |
| 195 | + * Set the number of columns in this group |
| 196 | + */ |
| 197 | + void setColumnCount( int columnCount ); |
| 198 | + |
| 199 | + /** |
| 200 | + * Creates a deep copy of this element. To be implemented by subclasses. |
| 201 | + * |
| 202 | + * @note Added in QGIS 3.0 |
| 203 | + */ |
| 204 | + virtual QgsAttributeEditorElement* clone(QgsAttributeEditorElement* parent) const /Factory/; |
| 205 | +}; |
| 206 | + |
| 207 | +/** \ingroup core |
| 208 | + * This element will load a field's widget onto the form. |
| 209 | + */ |
| 210 | +class QgsAttributeEditorField : public QgsAttributeEditorElement |
| 211 | +{ |
| 212 | +%TypeHeaderCode |
| 213 | +#include <qgsattributeeditorelement.h> |
| 214 | +%End |
| 215 | + public: |
| 216 | + /** |
| 217 | + * Creates a new attribute editor element which represents a field |
| 218 | + * |
| 219 | + * @param name The name of the element |
| 220 | + * @param idx The index of the field which should be embedded |
| 221 | + * @param parent The parent of this widget (used as container) |
| 222 | + */ |
| 223 | + QgsAttributeEditorField( const QString& name, int idx, QgsAttributeEditorElement *parent ); |
| 224 | + |
| 225 | + /** |
| 226 | + * Will serialize this elements information into a QDomElement for saving it in an XML file. |
| 227 | + * |
| 228 | + * @param doc The QDomDocument used to generate the QDomElement |
| 229 | + * |
| 230 | + * @return The XML element |
| 231 | + */ |
| 232 | + virtual QDomElement toDomElement( QDomDocument& doc ) const; |
| 233 | + |
| 234 | + /** |
| 235 | + * Return the index of the field |
| 236 | + * @return |
| 237 | + */ |
| 238 | + int idx() const; |
| 239 | + |
| 240 | + virtual QgsAttributeEditorElement* clone( QgsAttributeEditorElement* parent ) const /Factory/; |
| 241 | +}; |
| 242 | + |
| 243 | +/** \ingroup core |
| 244 | + * This element will load a relation editor onto the form. |
| 245 | + */ |
| 246 | +class QgsAttributeEditorRelation : QgsAttributeEditorElement |
| 247 | +{ |
| 248 | +%TypeHeaderCode |
| 249 | +#include <qgsattributeeditorelement.h> |
| 250 | +%End |
| 251 | + public: |
| 252 | + /** |
| 253 | + * Creates a new element which embeds a relation. |
| 254 | + * |
| 255 | + * @param name The name of this element |
| 256 | + * @param relationId The id of the relation to embed |
| 257 | + * @param parent The parent (used as container) |
| 258 | + */ |
| 259 | + QgsAttributeEditorRelation( const QString& name, const QString &relationId, QgsAttributeEditorElement* parent ); |
| 260 | + |
| 261 | + /** |
| 262 | + * Creates a new element which embeds a relation. |
| 263 | + * |
| 264 | + * @param name The name of this element |
| 265 | + * @param relation The relation to embed |
| 266 | + * @param parent The parent (used as container) |
| 267 | + */ |
| 268 | + QgsAttributeEditorRelation( const QString& name, const QgsRelation& relation, QgsAttributeEditorElement* parent ); |
| 269 | + |
| 270 | + /** |
| 271 | + * Will serialize this elements information into a QDomElement for saving it in an XML file. |
| 272 | + * |
| 273 | + * @param doc The QDomDocument used to generate the QDomElement |
| 274 | + * |
| 275 | + * @return The XML element |
| 276 | + */ |
| 277 | + virtual QDomElement toDomElement( QDomDocument& doc ) const; |
| 278 | + |
| 279 | + /** |
| 280 | + * Get the id of the relation which shall be embedded |
| 281 | + * |
| 282 | + * @return the id |
| 283 | + */ |
| 284 | + const QgsRelation& relation() const; |
| 285 | + |
| 286 | + /** |
| 287 | + * Initializes the relation from the id |
| 288 | + * |
| 289 | + * @param relManager The relation manager to use for the initialization |
| 290 | + * @return true if the relation was found in the relationmanager |
| 291 | + */ |
| 292 | + bool init( QgsRelationManager* relManager ); |
| 293 | + |
| 294 | + virtual QgsAttributeEditorElement* clone(QgsAttributeEditorElement* parent) const /Factory/; |
| 295 | +}; |
0 commit comments