QGIS API Documentation  3.2.0-Bonn (bc43194)
qgseditformconfig.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgseditformconfig.cpp
3  ---------------------
4  begin : November 2015
5  copyright : (C) 2015 by Matthias Kuhn
6  email : matthias at opengis dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "qgseditformconfig_p.h"
16 #include "qgseditformconfig.h"
18 #include "qgspathresolver.h"
19 #include "qgsproject.h"
20 #include "qgsreadwritecontext.h"
21 #include "qgsrelationmanager.h"
22 #include "qgslogger.h"
23 #include "qgsxmlutils.h"
24 
25 //#include "qgseditorwidgetregistry.h"
26 
28 {
29  qDeleteAll( mChildren );
30 }
31 
33  : d( new QgsEditFormConfigPrivate() )
34 {
35 }
36 
37 QVariantMap QgsEditFormConfig::widgetConfig( const QString &widgetName ) const
38 {
39  int fieldIndex = d->mFields.indexOf( widgetName );
40  if ( fieldIndex != -1 )
41  return d->mFields.at( fieldIndex ).editorWidgetSetup().config();
42  else
43  return d->mWidgetConfigs.value( widgetName );
44 }
45 
46 void QgsEditFormConfig::setFields( const QgsFields &fields )
47 {
48  d.detach();
49  d->mFields = fields;
50 
51  if ( !d->mConfiguredRootContainer )
52  {
53  d->mInvisibleRootContainer->clear();
54  for ( int i = 0; i < d->mFields.size(); ++i )
55  {
56  QgsAttributeEditorField *field = new QgsAttributeEditorField( d->mFields.at( i ).name(), i, d->mInvisibleRootContainer );
57  d->mInvisibleRootContainer->addChildElement( field );
58  }
59  }
60 }
61 
62 void QgsEditFormConfig::onRelationsLoaded()
63 {
64  QList<QgsAttributeEditorElement *> relations = d->mInvisibleRootContainer->findElements( QgsAttributeEditorElement::AeTypeRelation );
65 
66  Q_FOREACH ( QgsAttributeEditorElement *relElem, relations )
67  {
68  QgsAttributeEditorRelation *rel = dynamic_cast< QgsAttributeEditorRelation * >( relElem );
69  if ( !rel )
70  continue;
71 
72  rel->init( QgsProject::instance()->relationManager() );
73  }
74 }
75 
76 bool QgsEditFormConfig::setWidgetConfig( const QString &widgetName, const QVariantMap &config )
77 {
78  if ( d->mFields.indexOf( widgetName ) != -1 )
79  {
80  QgsDebugMsg( "Trying to set a widget config for a field on QgsEditFormConfig. Use layer->setEditorWidgetSetup() instead." );
81  return false;
82  }
83 
84  d.detach();
85  d->mWidgetConfigs[widgetName] = config;
86  return true;
87 }
88 
89 bool QgsEditFormConfig::removeWidgetConfig( const QString &widgetName )
90 {
91  d.detach();
92  return d->mWidgetConfigs.remove( widgetName ) != 0;
93 }
94 
96  : d( o.d )
97 {
98 }
99 
101 {}
102 
104 {
105  d = o.d;
106  return *this;
107 }
108 
110 {
111  return d == o.d;
112 }
113 
115 {
116  d.detach();
117  d->mInvisibleRootContainer->addChildElement( data );
118 }
119 
120 QList<QgsAttributeEditorElement *> QgsEditFormConfig::tabs() const
121 {
122  return d->mInvisibleRootContainer->children();
123 }
124 
126 {
127  d.detach();
128  d->mInvisibleRootContainer->clear();
129 }
130 
132 {
133  return d->mInvisibleRootContainer;
134 }
135 
137 {
138  return d->mEditorLayout;
139 }
140 
142 {
143  d.detach();
144  d->mEditorLayout = editorLayout;
145 
146  if ( editorLayout == TabLayout )
147  d->mConfiguredRootContainer = true;
148 }
149 
151 {
152  return d->mUiFormPath;
153 }
154 
155 void QgsEditFormConfig::setUiForm( const QString &ui )
156 {
157  if ( !ui.isEmpty() && !QUrl::fromUserInput( ui ).isLocalFile() )
158  {
159  // any existing download will not be restarted!
161  }
162 
163  if ( ui.isEmpty() )
164  {
166  }
167  else
168  {
170  }
171  d->mUiFormPath = ui;
172 }
173 
174 bool QgsEditFormConfig::readOnly( int idx ) const
175 {
176  if ( idx >= 0 && idx < d->mFields.count() )
177  {
178  if ( d->mFields.fieldOrigin( idx ) == QgsFields::OriginJoin
179  || d->mFields.fieldOrigin( idx ) == QgsFields::OriginExpression )
180  return true;
181  return !d->mFieldEditables.value( d->mFields.at( idx ).name(), true );
182  }
183  else
184  return false;
185 }
186 
187 bool QgsEditFormConfig::labelOnTop( int idx ) const
188 {
189  if ( idx >= 0 && idx < d->mFields.count() )
190  return d->mLabelOnTop.value( d->mFields.at( idx ).name(), false );
191  else
192  return false;
193 }
194 
196 {
197  if ( idx >= 0 && idx < d->mFields.count() )
198  {
199  d.detach();
200  d->mFieldEditables[ d->mFields.at( idx ).name()] = !readOnly;
201  }
202 }
203 
204 void QgsEditFormConfig::setLabelOnTop( int idx, bool onTop )
205 {
206  if ( idx >= 0 && idx < d->mFields.count() )
207  {
208  d.detach();
209  d->mLabelOnTop[ d->mFields.at( idx ).name()] = onTop;
210  }
211 }
212 
214 {
215  return d->mInitFunction;
216 }
217 
218 void QgsEditFormConfig::setInitFunction( const QString &function )
219 {
220  d.detach();
221  d->mInitFunction = function;
222 }
223 
225 {
226  return d->mInitCode;
227 }
228 
229 void QgsEditFormConfig::setInitCode( const QString &code )
230 {
231  d.detach();
232  d->mInitCode = code;
233 }
234 
236 {
237  return d->mInitFilePath;
238 }
239 
240 void QgsEditFormConfig::setInitFilePath( const QString &filePath )
241 {
242  d.detach();
243  d->mInitFilePath = filePath;
244 }
245 
247 {
248  return d->mInitCodeSource;
249 }
250 
252 {
253  d.detach();
254  d->mInitCodeSource = initCodeSource;
255 }
256 
258 {
259  return d->mSuppressForm;
260 }
261 
263 {
264  d.detach();
265  d->mSuppressForm = s;
266 }
267 
268 void QgsEditFormConfig::readXml( const QDomNode &node, QgsReadWriteContext &context )
269 {
270  QgsReadWriteContextCategoryPopper p = context.enterCategory( QObject::tr( "Edit form config" ) );
271 
272  d.detach();
273 
274  QDomNode editFormNode = node.namedItem( QStringLiteral( "editform" ) );
275  if ( !editFormNode.isNull() )
276  {
277  QDomElement e = editFormNode.toElement();
278  setUiForm( context.pathResolver().readPath( e.text() ) );
279  }
280 
281  QDomNode editFormInitNode = node.namedItem( QStringLiteral( "editforminit" ) );
282  if ( !editFormInitNode.isNull() )
283  {
284  d->mInitFunction = editFormInitNode.toElement().text();
285  }
286 
287  QDomNode editFormInitCodeSourceNode = node.namedItem( QStringLiteral( "editforminitcodesource" ) );
288  if ( !editFormInitCodeSourceNode.isNull() && !editFormInitCodeSourceNode.toElement().text().isEmpty() )
289  {
290  setInitCodeSource( static_cast< QgsEditFormConfig::PythonInitCodeSource >( editFormInitCodeSourceNode.toElement().text().toInt() ) );
291  }
292 
293  QDomNode editFormInitCodeNode = node.namedItem( QStringLiteral( "editforminitcode" ) );
294  if ( !editFormInitCodeNode.isNull() )
295  {
296  setInitCode( editFormInitCodeNode.toElement().text() );
297  }
298 
299  // Temporary < 2.12 b/w compatibility "dot" support patch
300  // \see: https://github.com/qgis/QGIS/pull/2498
301  // For b/w compatibility, check if there's a dot in the function name
302  // and if yes, transform it in an import statement for the module
303  // and set the PythonInitCodeSource to CodeSourceDialog
304  int dotPos = d->mInitFunction.lastIndexOf( '.' );
305  if ( dotPos >= 0 ) // It's a module
306  {
308  setInitCode( QStringLiteral( "from %1 import %2\n" ).arg( d->mInitFunction.left( dotPos ), d->mInitFunction.mid( dotPos + 1 ) ) );
309  setInitFunction( d->mInitFunction.mid( dotPos + 1 ) );
310  }
311 
312  QDomNode editFormInitFilePathNode = node.namedItem( QStringLiteral( "editforminitfilepath" ) );
313  if ( !editFormInitFilePathNode.isNull() && !editFormInitFilePathNode.toElement().text().isEmpty() )
314  {
315  setInitFilePath( context.pathResolver().readPath( editFormInitFilePathNode.toElement().text() ) );
316  }
317 
318  QDomNode fFSuppNode = node.namedItem( QStringLiteral( "featformsuppress" ) );
319  if ( fFSuppNode.isNull() )
320  {
321  d->mSuppressForm = QgsEditFormConfig::SuppressDefault;
322  }
323  else
324  {
325  QDomElement e = fFSuppNode.toElement();
326  d->mSuppressForm = static_cast< QgsEditFormConfig::FeatureFormSuppress >( e.text().toInt() );
327  }
328 
329  // tab display
330  QDomNode editorLayoutNode = node.namedItem( QStringLiteral( "editorlayout" ) );
331  if ( editorLayoutNode.isNull() )
332  {
333  d->mEditorLayout = QgsEditFormConfig::GeneratedLayout;
334  }
335  else
336  {
337  if ( editorLayoutNode.toElement().text() == QLatin1String( "uifilelayout" ) )
338  {
339  d->mEditorLayout = QgsEditFormConfig::UiFileLayout;
340  }
341  else if ( editorLayoutNode.toElement().text() == QLatin1String( "tablayout" ) )
342  {
343  d->mEditorLayout = QgsEditFormConfig::TabLayout;
344  }
345  else
346  {
347  d->mEditorLayout = QgsEditFormConfig::GeneratedLayout;
348  }
349  }
350 
351  d->mFieldEditables.clear();
352  QDomNodeList editableNodeList = node.namedItem( QStringLiteral( "editable" ) ).toElement().childNodes();
353  for ( int i = 0; i < editableNodeList.size(); ++i )
354  {
355  QDomElement editableElement = editableNodeList.at( i ).toElement();
356  d->mFieldEditables.insert( editableElement.attribute( QStringLiteral( "name" ) ), static_cast< bool >( editableElement.attribute( QStringLiteral( "editable" ) ).toInt() ) );
357  }
358 
359  d->mLabelOnTop.clear();
360  QDomNodeList labelOnTopNodeList = node.namedItem( QStringLiteral( "labelOnTop" ) ).toElement().childNodes();
361  for ( int i = 0; i < labelOnTopNodeList.size(); ++i )
362  {
363  QDomElement labelOnTopElement = labelOnTopNodeList.at( i ).toElement();
364  d->mLabelOnTop.insert( labelOnTopElement.attribute( QStringLiteral( "name" ) ), static_cast< bool >( labelOnTopElement.attribute( QStringLiteral( "labelOnTop" ) ).toInt() ) );
365  }
366 
367  QDomNodeList widgetsNodeList = node.namedItem( QStringLiteral( "widgets" ) ).toElement().childNodes();
368 
369  for ( int i = 0; i < widgetsNodeList.size(); ++i )
370  {
371  QDomElement widgetElement = widgetsNodeList.at( i ).toElement();
372  QVariant config = QgsXmlUtils::readVariant( widgetElement.firstChildElement( QStringLiteral( "config" ) ) );
373 
374  d->mWidgetConfigs[widgetElement.attribute( QStringLiteral( "name" ) )] = config.toMap();
375  }
376 
377  // tabs and groups display info
378  QDomNode attributeEditorFormNode = node.namedItem( QStringLiteral( "attributeEditorForm" ) );
379  if ( !attributeEditorFormNode.isNull() )
380  {
381  QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();
382 
383  if ( attributeEditorFormNodeList.size() )
384  {
385  d->mConfiguredRootContainer = true;
386  clearTabs();
387 
388  for ( int i = 0; i < attributeEditorFormNodeList.size(); i++ )
389  {
390  QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();
391 
392  QgsAttributeEditorElement *attributeEditorWidget = attributeEditorElementFromDomElement( elem, nullptr );
393  addTab( attributeEditorWidget );
394  }
395 
396  onRelationsLoaded();
397  }
398  }
399 }
400 
401 void QgsEditFormConfig::writeXml( QDomNode &node, const QgsReadWriteContext &context ) const
402 {
403  QDomDocument doc( node.ownerDocument() );
404 
405  QDomElement efField = doc.createElement( QStringLiteral( "editform" ) );
406  QDomText efText = doc.createTextNode( context.pathResolver().writePath( uiForm() ) );
407  efField.appendChild( efText );
408  node.appendChild( efField );
409 
410  QDomElement efiField = doc.createElement( QStringLiteral( "editforminit" ) );
411  if ( !initFunction().isEmpty() )
412  efiField.appendChild( doc.createTextNode( initFunction() ) );
413  node.appendChild( efiField );
414 
415  QDomElement eficsField = doc.createElement( QStringLiteral( "editforminitcodesource" ) );
416  eficsField.appendChild( doc.createTextNode( QString::number( initCodeSource() ) ) );
417  node.appendChild( eficsField );
418 
419  QDomElement efifpField = doc.createElement( QStringLiteral( "editforminitfilepath" ) );
420  efifpField.appendChild( doc.createTextNode( context.pathResolver().writePath( initFilePath() ) ) );
421  node.appendChild( efifpField );
422 
423  QDomElement eficField = doc.createElement( QStringLiteral( "editforminitcode" ) );
424  eficField.appendChild( doc.createCDATASection( initCode() ) );
425  node.appendChild( eficField );
426 
427  QDomElement fFSuppElem = doc.createElement( QStringLiteral( "featformsuppress" ) );
428  QDomText fFSuppText = doc.createTextNode( QString::number( suppress() ) );
429  fFSuppElem.appendChild( fFSuppText );
430  node.appendChild( fFSuppElem );
431 
432  // tab display
433  QDomElement editorLayoutElem = doc.createElement( QStringLiteral( "editorlayout" ) );
434  switch ( layout() )
435  {
437  editorLayoutElem.appendChild( doc.createTextNode( QStringLiteral( "uifilelayout" ) ) );
438  break;
439 
441  editorLayoutElem.appendChild( doc.createTextNode( QStringLiteral( "tablayout" ) ) );
442  break;
443 
445  default:
446  editorLayoutElem.appendChild( doc.createTextNode( QStringLiteral( "generatedlayout" ) ) );
447  break;
448  }
449 
450  node.appendChild( editorLayoutElem );
451 
452  // tabs and groups of edit form
453  if ( !tabs().empty() && d->mConfiguredRootContainer )
454  {
455  QDomElement tabsElem = doc.createElement( QStringLiteral( "attributeEditorForm" ) );
456 
457  QDomElement rootElem = d->mInvisibleRootContainer->toDomElement( doc );
458  QDomNodeList elemList = rootElem.childNodes();
459 
460  while ( !elemList.isEmpty() )
461  {
462  tabsElem.appendChild( elemList.at( 0 ) );
463  }
464 
465  node.appendChild( tabsElem );
466  }
467 
468  QDomElement editableElem = doc.createElement( QStringLiteral( "editable" ) );
469  for ( auto editIt = d->mFieldEditables.constBegin(); editIt != d->mFieldEditables.constEnd(); ++editIt )
470  {
471  QDomElement fieldElem = doc.createElement( QStringLiteral( "field" ) );
472  fieldElem.setAttribute( QStringLiteral( "name" ), editIt.key() );
473  fieldElem.setAttribute( QStringLiteral( "editable" ), editIt.value() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
474  editableElem.appendChild( fieldElem );
475  }
476  node.appendChild( editableElem );
477 
478  QDomElement labelOnTopElem = doc.createElement( QStringLiteral( "labelOnTop" ) );
479  for ( auto labelOnTopIt = d->mLabelOnTop.constBegin(); labelOnTopIt != d->mLabelOnTop.constEnd(); ++labelOnTopIt )
480  {
481  QDomElement fieldElem = doc.createElement( QStringLiteral( "field" ) );
482  fieldElem.setAttribute( QStringLiteral( "name" ), labelOnTopIt.key() );
483  fieldElem.setAttribute( QStringLiteral( "labelOnTop" ), labelOnTopIt.value() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
484  labelOnTopElem.appendChild( fieldElem );
485  }
486  node.appendChild( labelOnTopElem );
487 
488  QDomElement widgetsElem = doc.createElement( QStringLiteral( "widgets" ) );
489 
490  QMap<QString, QVariantMap >::ConstIterator configIt( d->mWidgetConfigs.constBegin() );
491 
492  while ( configIt != d->mWidgetConfigs.constEnd() )
493  {
494  QDomElement widgetElem = doc.createElement( QStringLiteral( "widget" ) );
495  widgetElem.setAttribute( QStringLiteral( "name" ), configIt.key() );
496  // widgetElem.setAttribute( "notNull", );
497 
498  QDomElement configElem = QgsXmlUtils::writeVariant( configIt.value(), doc );
499  configElem.setTagName( QStringLiteral( "config" ) );
500  widgetElem.appendChild( configElem );
501  widgetsElem.appendChild( widgetElem );
502  ++configIt;
503  }
504 
505  node.appendChild( widgetsElem );
506 
508 }
509 
511 {
512  QgsAttributeEditorElement *newElement = nullptr;
513 
514  if ( elem.tagName() == QLatin1String( "attributeEditorContainer" ) )
515  {
516  QgsAttributeEditorContainer *container = new QgsAttributeEditorContainer( elem.attribute( QStringLiteral( "name" ) ), parent );
517  bool ok;
518  int cc = elem.attribute( QStringLiteral( "columnCount" ) ).toInt( &ok );
519  if ( !ok )
520  cc = 0;
521  container->setColumnCount( cc );
522 
523  bool isGroupBox = elem.attribute( QStringLiteral( "groupBox" ) ).toInt( &ok );
524  if ( ok )
525  container->setIsGroupBox( isGroupBox );
526  else
527  container->setIsGroupBox( parent );
528 
529  bool visibilityExpressionEnabled = elem.attribute( QStringLiteral( "visibilityExpressionEnabled" ) ).toInt( &ok );
530  QgsOptionalExpression visibilityExpression;
531  if ( ok )
532  {
533  visibilityExpression.setEnabled( visibilityExpressionEnabled );
534  visibilityExpression.setData( QgsExpression( elem.attribute( QStringLiteral( "visibilityExpression" ) ) ) );
535  }
536  container->setVisibilityExpression( visibilityExpression );
537 
538  QDomNodeList childNodeList = elem.childNodes();
539 
540  for ( int i = 0; i < childNodeList.size(); i++ )
541  {
542  QDomElement childElem = childNodeList.at( i ).toElement();
543  QgsAttributeEditorElement *myElem = attributeEditorElementFromDomElement( childElem, container );
544  if ( myElem )
545  container->addChildElement( myElem );
546  }
547 
548  newElement = container;
549  }
550  else if ( elem.tagName() == QLatin1String( "attributeEditorField" ) )
551  {
552  QString name = elem.attribute( QStringLiteral( "name" ) );
553  int idx = d->mFields.lookupField( name );
554  newElement = new QgsAttributeEditorField( name, idx, parent );
555  }
556  else if ( elem.tagName() == QLatin1String( "attributeEditorRelation" ) )
557  {
558  // At this time, the relations are not loaded
559  // So we only grab the id and delegate the rest to onRelationsLoaded()
560  QgsAttributeEditorRelation *relElement = new QgsAttributeEditorRelation( elem.attribute( QStringLiteral( "relation" ), QStringLiteral( "[None]" ) ), parent );
561  relElement->setShowLinkButton( elem.attribute( QStringLiteral( "showLinkButton" ), QStringLiteral( "1" ) ).toInt() );
562  relElement->setShowUnlinkButton( elem.attribute( QStringLiteral( "showUnlinkButton" ), QStringLiteral( "1" ) ).toInt() );
563  newElement = relElement;
564  }
565 
566  if ( newElement )
567  {
568  if ( elem.hasAttribute( QStringLiteral( "showLabel" ) ) )
569  newElement->setShowLabel( elem.attribute( QStringLiteral( "showLabel" ) ).toInt() );
570  else
571  newElement->setShowLabel( true );
572  }
573 
574  return newElement;
575 }
576 
578 {
579  return mColumnCount;
580 }
581 
583 {
584  mColumnCount = columnCount;
585 }
586 
588 {
589  QgsAttributeEditorContainer *element = new QgsAttributeEditorContainer( name(), parent );
590 
591  Q_FOREACH ( QgsAttributeEditorElement *child, children() )
592  {
593  element->addChildElement( child->clone( element ) );
594  }
595  element->mIsGroupBox = mIsGroupBox;
596  element->mColumnCount = mColumnCount;
597  element->mVisibilityExpression = mVisibilityExpression;
598 
599  return element;
600 }
601 
602 void QgsAttributeEditorContainer::saveConfiguration( QDomElement &elem ) const
603 {
604  elem.setAttribute( QStringLiteral( "columnCount" ), mColumnCount );
605  elem.setAttribute( QStringLiteral( "groupBox" ), mIsGroupBox ? 1 : 0 );
606  elem.setAttribute( QStringLiteral( "visibilityExpressionEnabled" ), mVisibilityExpression.enabled() ? 1 : 0 );
607  elem.setAttribute( QStringLiteral( "visibilityExpression" ), mVisibilityExpression->expression() );
608 
609  Q_FOREACH ( QgsAttributeEditorElement *child, mChildren )
610  {
611  QDomDocument doc = elem.ownerDocument();
612  elem.appendChild( child->toDomElement( doc ) );
613  }
614 }
615 
616 QString QgsAttributeEditorContainer::typeIdentifier() const
617 {
618  return QStringLiteral( "attributeEditorContainer" );
619 }
Class for parsing and evaluation of expressions (formerly called "search strings").
The class is used as a container of context for various read/write operations on other objects...
Use the Python code provided in the dialog.
bool init(QgsRelationManager *relManager)
Initializes the relation from the id.
Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index w...
Definition: qgsfields.h:50
This is an abstract base class for any elements of a drag and drop form.
EditorLayout
The different types to layout the attribute editor.
void readXml(const QDomNode &node, QgsReadWriteContext &context)
Read XML information Deserialize on project load.
static QgsApplication * instance()
Returns the singleton instance of the QgsApplication.
void setInitFilePath(const QString &filePath)
Set Python external file path for edit form initialization.
MAYBE_UNUSED NODISCARD QgsReadWriteContextCategoryPopper enterCategory(const QString &category, const QString &details=QString())
Push a category to the stack.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
void setVisibilityExpression(const QgsOptionalExpression &visibilityExpression)
The visibility expression is used in the attribute form to show or hide this container based on an ex...
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QList< QgsAttributeEditorElement *> tabs() const
Returns a list of tabs for EditorLayout::TabLayout obtained from the invisible root container...
Use a layout with tabs and group boxes. Needs to be configured.
The download will start immediately, not need to run QgsFecthedContent::download() ...
Container of fields for a vector layer.
Definition: qgsfields.h:42
QVariantMap widgetConfig(const QString &widgetName) const
Gets the configuration for the editor widget with the given name.
This element will load a field&#39;s widget onto the form.
Allows entering a context category and takes care of leaving this category on deletion of the class...
QDomElement toDomElement(QDomDocument &doc) const
Gets the XML Dom element to save this element.
This element will load a relation editor onto the form.
void setInitFunction(const QString &function)
Set Python function for edit form initialization.
PythonInitCodeSource initCodeSource() const
Returns Python code source for edit form initialization (if it shall be loaded from a file...
void setColumnCount(int columnCount)
Set the number of columns in this group.
Use the application-wide setting.
void setLabelOnTop(int idx, bool onTop)
If this is set to true, the widget at the given index will receive its label on the previous line whi...
QgsEditFormConfig()
Create a new edit form config.
void setData(const T &data)
Set the payload data.
Definition: qgsoptional.h:129
An expression with an additional enabled flag.
static QVariant readVariant(const QDomElement &element)
Read a QVariant from a QDomElement.
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
void setLayout(EditorLayout editorLayout)
Sets the active layout style for the attribute editor for this layer.
void addTab(QgsAttributeEditorElement *data)
Adds a new element to the invisible root container in the layout.
FeatureFormSuppress
Types of feature form suppression after feature creation.
void setInitCode(const QString &code)
Set Python code for edit form initialization.
void clearTabs()
Clears all the tabs for the attribute editor form with EditorLayout::TabLayout.
QgsAttributeEditorContainer * invisibleRootContainer()
Gets the invisible root container for the drag and drop designer form (EditorLayout::TabLayout).
EditorLayout layout() const
Gets the active layout style for the attribute editor for this layer.
void setSuppress(FeatureFormSuppress s)
Sets type of feature form pop-up suppression after feature creation (overrides app setting) ...
void setShowLinkButton(bool showLinkButton)
Determines if the "link feature" button should be shown.
void setShowUnlinkButton(bool showUnlinkButton)
Determines if the "unlink feature" button should be shown.
void writeXml(QDomNode &node, const QgsReadWriteContext &context) const
Write XML information Serialize on project save.
QString initCode() const
Gets Python code for edit form initialization.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.
bool operator==(const QgsEditFormConfig &o)
FeatureFormSuppress suppress() const
Type of feature form pop-up suppression after feature creation (overrides app setting) ...
QgsEditFormConfig & operator=(const QgsEditFormConfig &o)
void setUiForm(const QString &ui)
Set path to the .ui form.
void setInitCodeSource(PythonInitCodeSource initCodeSource)
Sets if Python code shall be used for edit form initialization and its origin.
Autogenerate a simple tabular layout for the form.
void setReadOnly(int idx, bool readOnly=true)
If set to false, the widget at the given index will be read-only.
virtual void setIsGroupBox(bool isGroupBox)
Determines if this container is rendered as collapsible group box or tab in a tabwidget.
Load a .ui file for the layout. Needs to be configured.
int columnCount() const
Gets the number of columns in this group.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:391
static QgsNetworkContentFetcherRegistry * networkContentFetcherRegistry()
Returns the application&#39;s network content registry used for fetching temporary files during QGIS sess...
This is a container for attribute editors, used to group them visually in the attribute form if it is...
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
bool setWidgetConfig(const QString &widgetName, const QVariantMap &config)
Set the editor widget config for a widget which is not for a simple field.
const QgsFetchedContent * fetch(const QString &url, FetchingMode fetchingMode=DownloadLater)
Initialize a download for the given URL.
virtual void addChildElement(QgsAttributeEditorElement *element)
Add a child element to this container.
bool readOnly(int idx) const
This returns true if the field is manually set to read only or if the field does not support editing ...
bool removeWidgetConfig(const QString &widgetName)
Remove the configuration for the editor widget with the given name.
bool labelOnTop(int idx) const
If this returns true, the widget at the given index will receive its label on the previous line while...
void setEnabled(bool enabled)
Set if this optional is enabled.
Definition: qgsoptional.h:99
virtual QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const =0
Returns a clone of this element.
Field is calculated from an expression.
Definition: qgsfields.h:52
QgsAttributeEditorElement * attributeEditorElementFromDomElement(QDomElement &elem, QgsAttributeEditorElement *parent)
Deserialize drag and drop designer elements.
static QDomElement writeVariant(const QVariant &value, QDomDocument &doc)
Write a QVariant to a QDomElement.
QString initFunction() const
Gets Python function for edit form initialization.
PythonInitCodeSource
The Python init code source options.
QgsAttributeEditorElement * clone(QgsAttributeEditorElement *parent) const override
Creates a deep copy of this element.
QString uiForm() const
Returns the path or URL to the .ui form.
QString initFilePath() const
Gets Python external file path for edit form initialization.