QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsattributeeditorelement.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeeditorelement.h - QgsAttributeEditorElement
3 
4  ---------------------
5  begin : 18.8.2016
6  copyright : (C) 2016 by Matthias Kuhn
7  email : [email protected]
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 #ifndef QGSATTRIBUTEEDITORELEMENT_H
17 #define QGSATTRIBUTEEDITORELEMENT_H
18 
19 #include "qgis_core.h"
20 #include "qgsrelation.h"
21 #include "qgsoptionalexpression.h"
22 #include "qgspropertycollection.h"
23 #include <QColor>
24 
25 
26 class QgsRelationManager;
27 
40 {
41 
42 #ifdef SIP_RUN
44  switch ( sipCpp->type() )
45  {
47  sipType = sipType_QgsAttributeEditorContainer;
48  break;
50  sipType = sipType_QgsAttributeEditorField;
51  break;
53  sipType = sipType_QgsAttributeEditorRelation;
54  break;
55  default:
56  sipType = nullptr;
57  break;
58  }
59  SIP_END
60 #endif
61  public:
63  {
69  AeTypeHtmlElement
70  };
71 
79  QgsAttributeEditorElement( AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent = nullptr )
80  : mType( type )
81  , mName( name )
82  , mParent( parent )
83  , mShowLabel( true )
84  {}
85 
86  virtual ~QgsAttributeEditorElement() = default;
87 
93  QString name() const { return mName; }
94 
100  AttributeEditorType type() const { return mType; }
101 
107  QgsAttributeEditorElement *parent() const { return mParent; }
108 
116  QDomElement toDomElement( QDomDocument &doc ) const;
117 
124 
130  bool showLabel() const;
131 
136  void setShowLabel( bool showLabel );
137 
138  protected:
139 #ifndef SIP_RUN
141  QString mName;
142  QgsAttributeEditorElement *mParent = nullptr;
144 #endif
145 
146  private:
147 
153  virtual void saveConfiguration( QDomElement &elem ) const = 0;
154 
161  virtual QString typeIdentifier() const = 0;
162 
163 };
164 
165 
172 {
173  public:
174 
182  QgsAttributeEditorContainer( const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor = QColor() )
183  : QgsAttributeEditorElement( AeTypeContainer, name, parent )
184  , mIsGroupBox( true )
185  , mColumnCount( 1 )
186  , mBackgroundColor( backgroundColor )
187  {}
188 
189 
190  ~QgsAttributeEditorContainer() override;
191 
197  virtual void addChildElement( QgsAttributeEditorElement *element SIP_TRANSFER );
198 
204  virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
205 
211  virtual bool isGroupBox() const { return mIsGroupBox; }
212 
218  QList<QgsAttributeEditorElement *> children() const { return mChildren; }
219 
227  virtual QList<QgsAttributeEditorElement *> findElements( AttributeEditorType type ) const;
228 
232  void clear();
233 
237  void setName( const QString &name );
238 
242  int columnCount() const;
243 
247  void setColumnCount( int columnCount );
248 
255 
263  QgsOptionalExpression visibilityExpression() const;
264 
272  void setVisibilityExpression( const QgsOptionalExpression &visibilityExpression );
273 
279  QColor backgroundColor() const;
280 
284  void setBackgroundColor( const QColor &backgroundColor );
285 
286  private:
287  void saveConfiguration( QDomElement &elem ) const override;
288  QString typeIdentifier() const override;
289 
290  bool mIsGroupBox;
291  QList<QgsAttributeEditorElement *> mChildren;
292  int mColumnCount;
293  QgsOptionalExpression mVisibilityExpression;
294  QColor mBackgroundColor;
295 };
296 
302 {
303  public:
304 
312  QgsAttributeEditorField( const QString &name, int idx, QgsAttributeEditorElement *parent )
313  : QgsAttributeEditorElement( AeTypeField, name, parent )
314  , mIdx( idx )
315  {}
316 
320  int idx() const { return mIdx; }
321 
323 
324  private:
325  void saveConfiguration( QDomElement &elem ) const override;
326  QString typeIdentifier() const override;
327  int mIdx;
328 };
329 
335 {
336  Q_GADGET
337  public:
338 
343  enum Button
344  {
345  Link = 1 << 1,
346  Unlink = 1 << 2,
347  SaveChildEdits = 1 << 3,
348  AddChildFeature = 1 << 4,
349  DuplicateChildFeature = 1 << 5,
350  DeleteChildFeature = 1 << 6,
351  ZoomToChildFeature = 1 << 7,
352  AllButtons = Link | Unlink | SaveChildEdits | AddChildFeature | DuplicateChildFeature | DeleteChildFeature | ZoomToChildFeature
353  };
354  Q_ENUM( Button )
355  Q_DECLARE_FLAGS( Buttons, Button )
356  Q_FLAG( Buttons )
357 
358 
361  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QString &relationId, QgsAttributeEditorElement *parent )
362  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
363  , mRelationId( relationId )
364  {}
365 
369  Q_DECL_DEPRECATED QgsAttributeEditorRelation( const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent )
370  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
371  , mRelationId( relation.id() )
372  , mRelation( relation )
373  {}
374 
381  QgsAttributeEditorRelation( const QString &relationId, QgsAttributeEditorElement *parent )
382  : QgsAttributeEditorElement( AeTypeRelation, relationId, parent )
383  , mRelationId( relationId )
384  {}
385 
393  : QgsAttributeEditorElement( AeTypeRelation, relation.id(), parent )
394  , mRelationId( relation.id() )
395  , mRelation( relation )
396  {}
397 
398 
404  const QgsRelation &relation() const { return mRelation; }
405 
412  bool init( QgsRelationManager *relManager );
413 
415 
421  Q_DECL_DEPRECATED bool showLinkButton() const SIP_DEPRECATED;
422 
428  Q_DECL_DEPRECATED void setShowLinkButton( bool showLinkButton ) SIP_DEPRECATED;
429 
435  Q_DECL_DEPRECATED bool showUnlinkButton() const SIP_DEPRECATED;
436 
442  Q_DECL_DEPRECATED void setShowUnlinkButton( bool showUnlinkButton ) SIP_DEPRECATED;
443 
449  Q_DECL_DEPRECATED void setShowSaveChildEditsButton( bool showChildEdits ) SIP_DEPRECATED;
450 
456  Q_DECL_DEPRECATED bool showSaveChildEditsButton() const SIP_DEPRECATED;
457 
462  void setVisibleButtons( const QgsAttributeEditorRelation::Buttons &buttons );
463 
468  QgsAttributeEditorRelation::Buttons visibleButtons() const {return mButtons;}
469 
474  bool forceSuppressFormPopup() const;
475 
482  void setForceSuppressFormPopup( bool forceSuppressFormPopup );
483 
488  QVariant nmRelationId() const;
489 
495  void setNmRelationId( const QVariant &nmRelationId = QVariant() );
496 
501  QString label() const;
502 
508  void setLabel( const QString &label = QString() );
509 
510  private:
511  void saveConfiguration( QDomElement &elem ) const override;
512  QString typeIdentifier() const override;
513  QString mRelationId;
514  QgsRelation mRelation;
515  Buttons mButtons = Buttons( Button::AllButtons );
516  bool mForceSuppressFormPopup = false;
517  QVariant mNmRelationId;
518  QString mLabel;
519 };
520 
521 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAttributeEditorRelation::Buttons )
522 
523 
524 
531 {
532  public:
533 
541  : QgsAttributeEditorElement( AeTypeQmlElement, name, parent )
542  {}
543 
544  QgsAttributeEditorElement *clone( QgsAttributeEditorElement *parent ) const override SIP_FACTORY;
545 
551  QString qmlCode() const;
552 
556  void setQmlCode( const QString &qmlCode );
557 
558  private:
559  void saveConfiguration( QDomElement &elem ) const override;
560  QString typeIdentifier() const override;
561  QString mQmlCode;
562 };
563 
564 
572 {
573  public:
574 
582  : QgsAttributeEditorElement( AeTypeHtmlElement, name, parent )
583  {}
584 
586 
592  QString htmlCode() const;
593 
597  void setHtmlCode( const QString &htmlCode );
598 
599  private:
600  void saveConfiguration( QDomElement &elem ) const override;
601  QString typeIdentifier() const override;
602  QString mHtmlCode;
603 };
604 
605 
606 #endif // QGSATTRIBUTEEDITORELEMENT_H
QgsAttributeEditorElement
This is an abstract base class for any elements of a drag and drop form.
Definition: qgsattributeeditorelement.h:40
QgsAttributeEditorRelation::QgsAttributeEditorRelation
QgsAttributeEditorRelation(const QString &relationId, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
Definition: qgsattributeeditorelement.h:381
QgsAttributeEditorContainer::QgsAttributeEditorContainer
QgsAttributeEditorContainer(const QString &name, QgsAttributeEditorElement *parent, const QColor &backgroundColor=QColor())
Creates a new attribute editor container.
Definition: qgsattributeeditorelement.h:182
qgsoptionalexpression.h
QgsRelationManager
This class manages a set of relations between layers.
Definition: qgsrelationmanager.h:35
QgsAttributeEditorElement::QgsAttributeEditorElement
QgsAttributeEditorElement(AttributeEditorType type, const QString &name, QgsAttributeEditorElement *parent=nullptr)
Constructor.
Definition: qgsattributeeditorelement.h:79
QgsAttributeEditorElement::AeTypeRelation
@ AeTypeRelation
A relation.
Definition: qgsattributeeditorelement.h:66
QgsAttributeEditorField
This element will load a field's widget onto the form.
Definition: qgsattributeeditorelement.h:302
QgsAttributeEditorRelation::QgsAttributeEditorRelation
Q_DECL_DEPRECATED QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QgsAttributeEditorElement *parent)
Definition: qgsattributeeditorelement.h:369
QgsAttributeEditorContainer::isGroupBox
virtual bool isGroupBox() const
Returns if this container is going to be rendered as a group box.
Definition: qgsattributeeditorelement.h:211
QgsAttributeEditorElement::mType
AttributeEditorType mType
Definition: qgsattributeeditorelement.h:140
QgsAttributeEditorContainer::children
QList< QgsAttributeEditorElement * > children() const
Gets a list of the children elements of this container.
Definition: qgsattributeeditorelement.h:218
QgsAttributeEditorHtmlElement::QgsAttributeEditorHtmlElement
QgsAttributeEditorHtmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display HTML.
Definition: qgsattributeeditorelement.h:581
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
QgsAttributeEditorField::idx
int idx() const
Returns the index of the field.
Definition: qgsattributeeditorelement.h:320
QgsAttributeEditorElement::AeTypeContainer
@ AeTypeContainer
A container.
Definition: qgsattributeeditorelement.h:64
QgsAttributeEditorQmlElement
An attribute editor widget that will represent arbitrary QML code.
Definition: qgsattributeeditorelement.h:531
QgsAttributeEditorRelation::Button
Button
Possible buttons shown in the relation editor.
Definition: qgsattributeeditorelement.h:344
QgsAttributeEditorField::QgsAttributeEditorField
QgsAttributeEditorField(const QString &name, int idx, QgsAttributeEditorElement *parent)
Creates a new attribute editor element which represents a field.
Definition: qgsattributeeditorelement.h:312
QgsAttributeEditorRelation
This element will load a relation editor onto the form.
Definition: qgsattributeeditorelement.h:335
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsAttributeEditorRelation::relation
const QgsRelation & relation() const
Gets the id of the relation which shall be embedded.
Definition: qgsattributeeditorelement.h:404
qgsrelation.h
QgsOptionalExpression
An expression with an additional enabled flag.
Definition: qgsoptionalexpression.h:40
QgsAttributeEditorContainer::setIsGroupBox
virtual void setIsGroupBox(bool isGroupBox)
Determines if this container is rendered as collapsible group box or tab in a tabwidget.
Definition: qgsattributeeditorelement.h:204
QgsAttributeEditorElement::AeTypeQmlElement
@ AeTypeQmlElement
A QML element.
Definition: qgsattributeeditorelement.h:68
QgsAttributeEditorElement::mName
QString mName
Definition: qgsattributeeditorelement.h:141
QgsAttributeEditorQmlElement::QgsAttributeEditorQmlElement
QgsAttributeEditorQmlElement(const QString &name, QgsAttributeEditorElement *parent)
Creates a new element which can display QML.
Definition: qgsattributeeditorelement.h:540
QgsAttributeEditorElement::mShowLabel
bool mShowLabel
Definition: qgsattributeeditorelement.h:143
QgsAttributeEditorElement::~QgsAttributeEditorElement
virtual ~QgsAttributeEditorElement()=default
QgsAttributeEditorContainer
This is a container for attribute editors, used to group them visually in the attribute form if it is...
Definition: qgsattributeeditorelement.h:172
QgsAttributeEditorElement::type
AttributeEditorType type() const
The type of this element.
Definition: qgsattributeeditorelement.h:100
QgsAttributeEditorElement::clone
virtual QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const =0
Returns a clone of this element.
qgspropertycollection.h
QgsRelation
Definition: qgsrelation.h:42
QgsAttributeEditorElement::AeTypeInvalid
@ AeTypeInvalid
Invalid.
Definition: qgsattributeeditorelement.h:67
QgsAttributeEditorRelation::QgsAttributeEditorRelation
QgsAttributeEditorRelation(const QgsRelation &relation, QgsAttributeEditorElement *parent)
Creates a new element which embeds a relation.
Definition: qgsattributeeditorelement.h:392
QgsAttributeEditorElement::name
QString name() const
Returns the name of this element.
Definition: qgsattributeeditorelement.h:93
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
QgsAttributeEditorElement::AttributeEditorType
AttributeEditorType
Definition: qgsattributeeditorelement.h:63
QgsAttributeEditorElement::AeTypeField
@ AeTypeField
A field.
Definition: qgsattributeeditorelement.h:65
SIP_ABSTRACT
#define SIP_ABSTRACT
Definition: qgis_sip.h:199
QgsAttributeEditorHtmlElement
An attribute editor widget that will represent arbitrary HTML code.
Definition: qgsattributeeditorelement.h:572
QgsAttributeEditorElement::parent
QgsAttributeEditorElement * parent() const
Gets the parent of this element.
Definition: qgsattributeeditorelement.h:107