QGIS API Documentation  2.14.0-Essen
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 
35 class CORE_EXPORT QgsAttributeEditorElement : public QObject
36 {
37  Q_OBJECT
38  public:
39 
41  {
45  AeTypeInvalid
46  };
47 
55  QgsAttributeEditorElement( AttributeEditorType type, const QString& name, QObject *parent = nullptr )
56  : QObject( parent ), mType( type ), mName( name ) {}
57 
60 
66  QString name() const { return mName; }
67 
73  AttributeEditorType type() const { return mType; }
74 
82  virtual QDomElement toDomElement( QDomDocument& doc ) const = 0;
83 
84  protected:
87 };
88 
89 
95 {
96  Q_OBJECT
97 
98  public:
106  : QgsAttributeEditorElement( AeTypeContainer, name, parent )
107  , mIsGroupBox( true )
108  {}
109 
112 
120  virtual QDomElement toDomElement( QDomDocument& doc ) const override;
121 
127  virtual void addChildElement( QgsAttributeEditorElement* element );
128 
134  virtual void setIsGroupBox( bool isGroupBox ) { mIsGroupBox = isGroupBox; }
135 
141  virtual bool isGroupBox() const { return mIsGroupBox; }
142 
148  QList<QgsAttributeEditorElement*> children() const { return mChildren; }
149 
157  virtual QList<QgsAttributeEditorElement*> findElements( AttributeEditorType type ) const;
158 
164  void setName( const QString& name );
165 
166  private:
167  bool mIsGroupBox;
169 };
170 
175 {
176  Q_OBJECT
177 
178  public:
186  QgsAttributeEditorField( const QString& name, int idx, QObject *parent )
187  : QgsAttributeEditorElement( AeTypeField, name, parent ), mIdx( idx ) {}
188 
191 
199  virtual QDomElement toDomElement( QDomDocument& doc ) const override;
200 
205  int idx() const { return mIdx; }
206 
207  private:
208  int mIdx;
209 };
210 
215 {
216  Q_OBJECT
217 
218  public:
226  QgsAttributeEditorRelation( const QString& name, const QString &relationId, QObject *parent )
227  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
228  , mRelationId( relationId ) {}
229 
237  QgsAttributeEditorRelation( const QString& name, const QgsRelation& relation, QObject *parent )
238  : QgsAttributeEditorElement( AeTypeRelation, name, parent )
239  , mRelationId( relation.id() )
240  , mRelation( relation ) {}
241 
244 
252  virtual QDomElement toDomElement( QDomDocument& doc ) const override;
253 
259  const QgsRelation& relation() const { return mRelation; }
260 
267  bool init( QgsRelationManager *relManager );
268 
269  private:
270  QString mRelationId;
271  QgsRelation mRelation;
272 };
273 
274 
275 class CORE_EXPORT QgsEditFormConfig : public QObject
276 {
277  Q_OBJECT
278 
279  public:
280 
283  {
284  GeneratedLayout = 0,
285  TabLayout = 1,
286  UiFileLayout = 2
287  };
288 
289  struct GroupData
290  {
292  GroupData( const QString& name, const QList<QString>& fields )
293  : mName( name ), mFields( fields ) {}
296  };
297 
298  struct TabData
299  {
300  TabData() {}
301  TabData( const QString& name, const QList<QString>& fields, const QList<GroupData>& groups )
302  : mName( name ), mFields( fields ), mGroups( groups ) {}
306  };
307 
312  {
313  SuppressDefault = 0,
314  SuppressOn = 1,
315  SuppressOff = 2
316  };
317 
322  {
323  CodeSourceNone = 0,
324  CodeSourceFile = 1,
325  CodeSourceDialog = 2,
326  CodeSourceEnvironment = 3
327  };
328 
334  void addTab( QgsAttributeEditorElement* data ) { mAttributeEditorElements.append( data ); }
335 
339  QList< QgsAttributeEditorElement* > tabs() const { return mAttributeEditorElements; }
340 
344  void clearTabs() { mAttributeEditorElements.clear(); }
345 
347  EditorLayout layout() const { return mEditorLayout; }
348 
350  void setLayout( EditorLayout editorLayout ) { mEditorLayout = editorLayout; }
351 
353  QString uiForm() const { return mUiFormPath; }
354 
361  void setUiForm( const QString& ui );
362 
363 
364  // Widget stuff
365 
394  void setWidgetType( int fieldIdx, const QString& widgetType );
395 
403  QString widgetType( int fieldIdx ) const;
404 
412  QString widgetType( const QString& fieldName ) const;
413 
429  void setWidgetConfig( int attrIdx, const QgsEditorWidgetConfig& config );
430 
446  void setWidgetConfig( const QString& widgetName, const QgsEditorWidgetConfig& config );
447 
455  QgsEditorWidgetConfig widgetConfig( int fieldIdx ) const;
456 
464  QgsEditorWidgetConfig widgetConfig( const QString& widgetName ) const;
465 
473  bool removeWidgetConfig( int fieldIdx );
474 
482  bool removeWidgetConfig( const QString& widgetName );
483 
488  bool readOnly( int idx ) const;
489 
493  void setReadOnly( int idx, bool readOnly = true );
494 
500  bool labelOnTop( int idx ) const;
501 
508  void setLabelOnTop( int idx, bool onTop );
509 
510 
511  // Python form init function stuff
512 
519  QString initFunction() const { return mInitFunction; }
520 
527  void setInitFunction( const QString& function ) { mInitFunction = function; }
528 
532  QString initCode() const { return mInitCode; }
533 
539  void setInitCode( const QString& code ) { mInitCode = code; }
540 
544  QString initFilePath() const { return mInitFilePath; }
545 
551  void setInitFilePath( const QString& filePath ) { mInitFilePath = filePath; }
552 
557  PythonInitCodeSource initCodeSource() const { return mInitCodeSource; }
558 
560  void setInitCodeSource( const PythonInitCodeSource initCodeSource ) { mInitCodeSource = initCodeSource; }
561 
563  FeatureFormSuppress suppress() const { return mSuppressForm; }
565  void setSuppress( FeatureFormSuppress s ) { mSuppressForm = s; }
566 
567  // Serialization
568 
573  void readXml( const QDomNode& node );
574 
579  void writeXml( QDomNode& node ) const;
580 
584  QgsAttributeEditorElement* attributeEditorElementFromDomElement( QDomElement &elem, QObject* parent );
585 
586  private slots:
587  void onRelationsLoaded();
588 
589  protected:
590  // Internal stuff
591 
595  explicit QgsEditFormConfig( QObject* parent = nullptr );
596 
597  private:
598 
605  void setFields( const QgsFields& fields );
606 
607  private:
609  QList< QgsAttributeEditorElement* > mAttributeEditorElements;
610 
612  QList< TabData > mTabs;
613 
614  QMap< QString, bool> mFieldEditables;
615  QMap< QString, bool> mLabelOnTop;
616 
617  QMap<QString, QString> mEditorWidgetV2Types;
619 
621  EditorLayout mEditorLayout;
622 
624  QString mUiFormPath;
626  QString mInitFunction;
628  QString mInitFilePath;
630  PythonInitCodeSource mInitCodeSource;
632  QString mInitCode;
633 
635  FeatureFormSuppress mSuppressForm;
636 
637  QgsFields mFields;
638 
639  friend class QgsVectorLayer;
640 };
641 
642 #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.
virtual bool isGroupBox() const
Returns if this container is going to be rendered as a group box.
PythonInitCodeSource initCodeSource() const
Return python code source for edit form initialization (if it shall be loaded from a file...
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.
FeatureFormSuppress suppress() const
Type of feature form pop-up suppression after feature creation (overrides app setting) ...
Container of fields for a vector layer.
Definition: qgsfield.h:187
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.
const QgsRelation & relation() const
Get the id of the relation which shall be embedded.
int idx() const
Return the index of the field.
QString name() const
Return the name of this element.
EditorLayout layout() const
Get the active layout style for the attribute editor for this layer.
QString uiForm() const
Get path to the .ui form.
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.
AttributeEditorType type() const
The type of this element.
QgsAttributeEditorField(const QString &name, int idx, QObject *parent)
Creates a new attribute editor element which represents a field.
virtual ~QgsAttributeEditorField()
Destructor.
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.
QList< QgsAttributeEditorElement * > children() const
Get a list of the children elements of this container.
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)
QgsAttributeEditorElement(AttributeEditorType type, const QString &name, QObject *parent=nullptr)
Constructor.
virtual QDomElement toDomElement(QDomDocument &doc) const =0
Is reimplemented in classes inheriting from this to serialize it.
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.
QString initFunction() const
Get python function for edit form initialization.
QList< QgsAttributeEditorElement * > tabs() const
Returns a list of tabs for EditorLayout::TabLayout.
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)
QString initCode() const
Get python code for edit form initialization.
Represents a vector layer which manages a vector based data sets.
AttributeEditorType mType
PythonInitCodeSource
The python init code source options.
QString initFilePath() const
Get python external file path for edit form initialization.