QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgseditformconfig.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgseditformconfig.h
3  -------------------
4  begin : Nov 18, 2015
5  copyright : (C) 2015 by Matthias Kuhn
6  email : matthias at opengis dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSEDITFORMCONFIG_H
19 #define QGSEDITFORMCONFIG_H
20 
21 #include <QMap>
22 
23 #include "qgseditorwidgetconfig.h"
24 #include "qgsrelationmanager.h"
25 #include "qgsoptionalexpression.h"
26 
36 class CORE_EXPORT QgsAttributeEditorElement : public QObject
37 {
38  Q_OBJECT
39  public:
40 
42  {
46  AeTypeInvalid
47  };
48 
56  QgsAttributeEditorElement( AttributeEditorType type, const QString& name, QObject *parent = nullptr )
57  : QObject( parent )
58  , mType( type )
59  , mName( name )
60  , mShowLabel( true )
61  {}
62 
65 
71  QString name() const { return mName; }
72 
78  AttributeEditorType type() const { return mType; }
79 
87  QDomElement toDomElement( QDomDocument& doc ) const;
88 
94  bool showLabel() const;
95 
101  void setShowLabel( bool showLabel );
102 
103  protected:
107 
108  private:
114  virtual void saveConfiguration( QDomElement& elem ) const = 0;
115 
122  virtual QString typeIdentifier() const = 0;
123 };
124 
125 
131 {
132  Q_OBJECT
133 
134  public:
142  : QgsAttributeEditorElement( AeTypeContainer, name, parent )
143  , mIsGroupBox( true )
144  , mColumnCount( 1 )
145  {}
146 
149 
155  virtual void addChildElement( QgsAttributeEditorElement* element );
156 
162  virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
163 
169  virtual bool isGroupBox() const { return mIsGroupBox; }
170 
176  QList<QgsAttributeEditorElement*> children() const { return mChildren; }
177 
185  virtual QList<QgsAttributeEditorElement*> findElements( AttributeEditorType type ) const;
186 
190  void setName( const QString& name );
191 
195  int columnCount() const;
196 
200  void setColumnCount( int columnCount );
201 
207  QgsOptionalExpression visibilityExpression() const;
208 
214  void setVisibilityExpression( const QgsOptionalExpression& visibilityExpression );
215 
216  private:
217  virtual void saveConfiguration( QDomElement& elem ) const override;
218  virtual QString typeIdentifier() const override;
219 
220  bool mIsGroupBox;
222  int mColumnCount;
223  QgsOptionalExpression mVisibilityExpression;
224 };
225 
230 {
231  Q_OBJECT
232 
233  public:
241  QgsAttributeEditorField( const QString& name, int idx, QObject *parent )
242  : QgsAttributeEditorElement( AeTypeField, name, parent )
243  , mIdx( idx )
244  {}
245 
248 
253  int idx() const { return mIdx; }
254 
255  private:
256  virtual void saveConfiguration( QDomElement& elem ) const override;
257  virtual QString typeIdentifier() const override;
258  int mIdx;
259 };
260 
265 {
266  Q_OBJECT
267 
268  public:
276  QgsAttributeEditorRelation( const QString& name, const QString &relationId, QObject *parent )
277  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
278  , mRelationId( relationId )
279  , mShowLinkButton( true )
280  , mShowUnlinkButton( true )
281  {}
282 
290  QgsAttributeEditorRelation( const QString& name, const QgsRelation& relation, QObject *parent )
291  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
292  , mRelationId( relation.id() )
293  , mRelation( relation )
294  , mShowLinkButton( true )
295  , mShowUnlinkButton( true )
296  {}
297 
300 
306  const QgsRelation& relation() const { return mRelation; }
307 
314  bool init( QgsRelationManager *relManager );
315 
321  bool showLinkButton() const;
327  void setShowLinkButton( bool showLinkButton );
328 
334  bool showUnlinkButton() const;
340  void setShowUnlinkButton( bool showUnlinkButton );
341 
342  private:
343  virtual void saveConfiguration( QDomElement& elem ) const override;
344  virtual QString typeIdentifier() const override;
345  QString mRelationId;
346  QgsRelation mRelation;
347  bool mShowLinkButton;
348  bool mShowUnlinkButton;
349 };
350 
351 
355 class CORE_EXPORT QgsEditFormConfig : public QObject
356 {
357  Q_OBJECT
358 
359  public:
360 
363  {
364  GeneratedLayout = 0,
365  TabLayout = 1,
366  UiFileLayout = 2
367  };
368 
369  struct GroupData
370  {
372  GroupData( const QString& name, const QList<QString>& fields )
373  : mName( name )
374  , mFields( fields )
375  {}
378  };
379 
380  struct TabData
381  {
382  TabData() {}
383  TabData( const QString& name, const QList<QString>& fields, const QList<GroupData>& groups )
384  : mName( name )
385  , mFields( fields )
386  , mGroups( groups )
387  {}
391  };
392 
397  {
398  SuppressDefault = 0,
399  SuppressOn = 1,
400  SuppressOff = 2
401  };
402 
407  {
408  CodeSourceNone = 0,
409  CodeSourceFile = 1,
410  CodeSourceDialog = 2,
411  CodeSourceEnvironment = 3
412  };
413 
419  void addTab( QgsAttributeEditorElement* data ) { mAttributeEditorElements.append( data ); }
420 
424  QList< QgsAttributeEditorElement* > tabs() const { return mAttributeEditorElements; }
425 
429  void clearTabs() { mAttributeEditorElements.clear(); }
430 
432  EditorLayout layout() const { return mEditorLayout; }
433 
435  void setLayout( EditorLayout editorLayout ) { mEditorLayout = editorLayout; }
436 
438  QString uiForm() const { return mUiFormPath; }
439 
446  void setUiForm( const QString& ui );
447 
448 
449  // Widget stuff
450 
479  void setWidgetType( int fieldIdx, const QString& widgetType );
480 
488  QString widgetType( int fieldIdx ) const;
489 
497  QString widgetType( const QString& fieldName ) const;
498 
514  void setWidgetConfig( int attrIdx, const QgsEditorWidgetConfig& config );
515 
531  void setWidgetConfig( const QString& widgetName, const QgsEditorWidgetConfig& config );
532 
540  QgsEditorWidgetConfig widgetConfig( int fieldIdx ) const;
541 
549  QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;
550 
558  bool removeWidgetConfig( int fieldIdx );
559 
567  bool removeWidgetConfig( const QString& widgetName );
568 
573  bool readOnly( int idx ) const;
574 
578  void setReadOnly( int idx, bool readOnly = true );
579 
586  QString expression( int idx ) const;
587 
594  void setExpression( int idx, const QString& str );
595 
602  QString expressionDescription( int idx ) const;
603 
610  void setExpressionDescription( int idx, const QString &descr );
611 
615  bool notNull( int fieldidx ) const;
619  void setNotNull( int idx, bool notnull = true );
620 
626  bool labelOnTop( int idx ) const;
627 
634  void setLabelOnTop( int idx, bool onTop );
635 
636 
637  // Python form init function stuff
638 
645  QString initFunction() const { return mInitFunction; }
646 
653  void setInitFunction( const QString& function ) { mInitFunction = function; }
654 
658  QString initCode() const { return mInitCode; }
659 
665  void setInitCode( const QString& code ) { mInitCode = code; }
666 
670  QString initFilePath() const { return mInitFilePath; }
671 
677  void setInitFilePath( const QString& filePath ) { mInitFilePath = filePath; }
678 
683  PythonInitCodeSource initCodeSource() const { return mInitCodeSource; }
684 
686  void setInitCodeSource( const PythonInitCodeSource initCodeSource ) { mInitCodeSource = initCodeSource; }
687 
689  FeatureFormSuppress suppress() const { return mSuppressForm; }
691  void setSuppress( FeatureFormSuppress s ) { mSuppressForm = s; }
692 
693  // Serialization
694 
699  void readXml( const QDomNode& node );
700 
705  void writeXml( QDomNode& node ) const;
706 
710  QgsAttributeEditorElement* attributeEditorElementFromDomElement( QDomElement &elem, QObject* parent );
711 
712  private slots:
713  void onRelationsLoaded();
714 
715  protected:
716  // Internal stuff
717 
721  explicit QgsEditFormConfig( QObject* parent = nullptr );
722 
723  private:
724 
731  void setFields( const QgsFields& fields );
732 
733  private:
735  QList< QgsAttributeEditorElement* > mAttributeEditorElements;
736 
738  QList< TabData > mTabs;
739 
740  QMap< QString, QString> mConstraints;
741  QMap< QString, QString> mConstraintsDescription;
742  QMap< QString, bool> mFieldEditables;
743  QMap< QString, bool> mLabelOnTop;
744  QMap< QString, bool> mNotNull;
745 
746  QMap<QString, QString> mEditorWidgetV2Types;
748 
750  EditorLayout mEditorLayout;
751 
753  QString mUiFormPath;
755  QString mInitFunction;
757  QString mInitFilePath;
759  PythonInitCodeSource mInitCodeSource;
761  QString mInitCode;
762 
764  FeatureFormSuppress mSuppressForm;
765 
766  QgsFields mFields;
767 
768  friend class QgsVectorLayer;
769 };
770 
771 #endif // QGSEDITFORMCONFIG_H
QgsAttributeEditorRelation(const QString &name, const QString &relationId, QObject *parent)
Creates a new element which embeds a relation.
virtual ~QgsAttributeEditorContainer()
Destructor.
This is an abstract base class for any elements of a drag and drop form.
EditorLayout
The different types to layout the attribute editor.
QgsAttributeEditorRelation(const QString &name, const QgsRelation &relation, QObject *parent)
Creates a new element which embeds a relation.
void setInitFilePath(const QString &filePath)
Set python external file path for edit form initialization.
void setInitCodeSource(const PythonInitCodeSource initCodeSource)
Set if python code shall be used for edit form initialization and its origin.
QList< QgsAttributeEditorElement *> tabs() const
Returns a list of tabs for EditorLayout::TabLayout.
const QgsRelation & relation() const
Get the id of the relation which shall be embedded.
Container of fields for a vector layer.
Definition: qgsfield.h:252
This element will load a field&#39;s widget onto the form.
virtual ~QgsAttributeEditorElement()
Destructor.
This element will load a relation editor onto the form.
void setInitFunction(const QString &function)
Set python function for edit form initialization.
AttributeEditorType type() const
The type of this element.
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
An expression with an additional enabled flag.
void setLayout(EditorLayout editorLayout)
Set the active layout style for the attribute editor for this layer.
void addTab(QgsAttributeEditorElement *data)
This is only useful in combination with EditorLayout::TabLayout.
FeatureFormSuppress
Types of feature form suppression after feature creation.
QgsAttributeEditorField(const QString &name, int idx, QObject *parent)
Creates a new attribute editor element which represents a field.
virtual ~QgsAttributeEditorField()
Destructor.
int idx() const
Return the index of the field.
void setInitCode(const QString &code)
Set python code for edit form initialization.
QgsAttributeEditorContainer(const QString &name, QObject *parent)
Creates a new attribute editor container.
void clearTabs()
Clears all the tabs for the attribute editor form with EditorLayout::TabLayout.
void setName(const char *name)
virtual ~QgsAttributeEditorRelation()
Destructor.
void setSuppress(FeatureFormSuppress s)
Set type of feature form pop-up suppression after feature creation (overrides app setting) ...
GroupData(const QString &name, const QList< QString > &fields)
QString initCode() const
Get python code for edit form initialization.
QgsAttributeEditorElement(AttributeEditorType type, const QString &name, QObject *parent=nullptr)
Constructor.
virtual void setIsGroupBox(bool isGroupBox)
Determines if this container is rendered as collapsible group box or tab in a tabwidget.
This class manages a set of relations between layers.
This is a container for attribute editors, used to group them visually in the attribute form if it is...
TabData(const QString &name, const QList< QString > &fields, const QList< GroupData > &groups)
QList< QgsAttributeEditorElement * > children() const
Get a list of the children elements of this container.
virtual bool isGroupBox() const
Returns if this container is going to be rendered as a group box.
Represents a vector layer which manages a vector based data sets.
QString name() const
Return the name of this element.
EditorLayout layout() const
Get the active layout style for the attribute editor for this layer.
AttributeEditorType mType
QString initFunction() const
Get python function for edit form initialization.
PythonInitCodeSource
The python init code source options.
FeatureFormSuppress suppress() const
Type of feature form pop-up suppression after feature creation (overrides app setting) ...
QString uiForm() const
Get path to the .ui form.
PythonInitCodeSource initCodeSource() const
Return python code source for edit form initialization (if it shall be loaded from a file...
QString initFilePath() const
Get python external file path for edit form initialization.