QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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.h"
16 #include "qgsproject.h"
17 
19  : QObject( parent )
20  , mEditorLayout( GeneratedLayout )
21  , mInitCodeSource( CodeSourceNone )
22  , mSuppressForm( SuppressDefault )
23 {
24  connect( QgsProject::instance()->relationManager(), SIGNAL( relationsLoaded() ), this, SLOT( onRelationsLoaded() ) );
25 }
26 
28 {
29  if ( fieldIdx < 0 || fieldIdx >= mFields.count() )
30  return "TextEdit";
31 
32  return mEditorWidgetV2Types.value( mFields.at( fieldIdx ).name(), "TextEdit" );
33 }
34 
36 {
37  return mEditorWidgetV2Types.value( fieldName, "TextEdit" );
38 }
39 
41 {
42  if ( fieldIdx < 0 || fieldIdx >= mFields.count() )
43  return QgsEditorWidgetConfig();
44 
45  return mWidgetConfigs.value( mFields.at( fieldIdx ).name() );
46 }
47 
49 {
50  return mWidgetConfigs.value( widgetName );
51 }
52 
53 void QgsEditFormConfig::setFields( const QgsFields& fields )
54 {
55  mFields = fields;
56 }
57 
59 {
60  if ( attrIdx >= 0 && attrIdx < mFields.count() )
61  mEditorWidgetV2Types[ mFields.at( attrIdx ).name()] = widgetType;
62 }
63 
65 {
66  if ( attrIdx >= 0 && attrIdx < mFields.count() )
67  mWidgetConfigs[ mFields.at( attrIdx ).name()] = config;
68 }
69 
70 void QgsEditFormConfig::setWidgetConfig( const QString& widgetName, const QgsEditorWidgetConfig& config )
71 {
72  mWidgetConfigs[widgetName] = config;
73 }
74 
76 {
77  return mWidgetConfigs.remove( widgetName ) != 0;
78 }
79 
81 {
82  if ( fieldIdx < 0 || fieldIdx >= mFields.count() )
83  return false;
84 
85  return mWidgetConfigs.remove( mFields.at( fieldIdx ).name() );
86 }
87 
89 {
90  if ( ui.isEmpty() || ui.isNull() )
91  {
93  }
94  else
95  {
97  }
98  mUiFormPath = ui;
99 }
100 
101 bool QgsEditFormConfig::readOnly( int idx ) const
102 {
103  if ( idx >= 0 && idx < mFields.count() )
104  {
105  if ( mFields.fieldOrigin( idx ) == QgsFields::OriginJoin
106  || mFields.fieldOrigin( idx ) == QgsFields::OriginExpression )
107  return true;
108  return !mFieldEditables.value( mFields.at( idx ).name(), true );
109  }
110  else
111  return false;
112 }
113 
114 bool QgsEditFormConfig::labelOnTop( int idx ) const
115 {
116  if ( idx >= 0 && idx < mFields.count() )
117  return mLabelOnTop.value( mFields.at( idx ).name(), false );
118  else
119  return false;
120 }
121 
123 {
124  QString expr;
125 
126  if ( idx >= 0 && idx < mFields.count() )
127  expr = mConstraints.value( mFields.at( idx ).name(), QString() );
128 
129  return expr;
130 }
131 
132 void QgsEditFormConfig::setExpression( int idx, const QString& str )
133 {
134  if ( idx >= 0 && idx < mFields.count() )
135  mConstraints[ mFields.at( idx ).name()] = str;
136 }
137 
139 {
140  QString description;
141 
142  if ( idx >= 0 && idx < mFields.count() )
143  description = mConstraintsDescription[ mFields.at( idx ).name()];
144 
145  return description;
146 }
147 
149 {
150  if ( idx >= 0 && idx < mFields.count() )
151  mConstraintsDescription[ mFields.at( idx ).name()] = descr;
152 }
153 
154 bool QgsEditFormConfig::notNull( int idx ) const
155 {
156  if ( idx >= 0 && idx < mFields.count() )
157  return mNotNull.value( mFields.at( idx ).name(), false );
158  else
159  return false;
160 }
161 
163 {
164  if ( idx >= 0 && idx < mFields.count() )
165  mFieldEditables[ mFields.at( idx ).name()] = !readOnly;
166 }
167 
168 void QgsEditFormConfig::setLabelOnTop( int idx, bool onTop )
169 {
170  if ( idx >= 0 && idx < mFields.count() )
171  mLabelOnTop[ mFields.at( idx ).name()] = onTop;
172 }
173 
174 void QgsEditFormConfig::setNotNull( int idx, bool notnull )
175 {
176  if ( idx >= 0 && idx < mFields.count() )
177  mNotNull[ mFields.at( idx ).name()] = notnull;
178 }
179 
181 {
182  QDomNode editFormNode = node.namedItem( "editform" );
183  if ( !editFormNode.isNull() )
184  {
185  QDomElement e = editFormNode.toElement();
186  mUiFormPath = QgsProject::instance()->readPath( e.text() );
187  }
188 
189  QDomNode editFormInitNode = node.namedItem( "editforminit" );
190  if ( !editFormInitNode.isNull() )
191  {
192  mInitFunction = editFormInitNode.toElement().text();
193  }
194 
195  QDomNode editFormInitCodeSourceNode = node.namedItem( "editforminitcodesource" );
196  if ( !editFormInitCodeSourceNode.isNull() || ( !editFormInitCodeSourceNode.isNull() && !editFormInitCodeSourceNode.toElement().text().isEmpty() ) )
197  {
198  setInitCodeSource( static_cast< QgsEditFormConfig::PythonInitCodeSource >( editFormInitCodeSourceNode.toElement().text().toInt() ) );
199  }
200 
201  QDomNode editFormInitCodeNode = node.namedItem( "editforminitcode" );
202  if ( !editFormInitCodeNode.isNull() )
203  {
204  setInitCode( editFormInitCodeNode.toElement().text() );
205  }
206 
207  // Temporary < 2.12 b/w compatibility "dot" support patch
208  // @see: https://github.com/qgis/QGIS/pull/2498
209  // For b/w compatibility, check if there's a dot in the function name
210  // and if yes, transform it in an import statement for the module
211  // and set the PythonInitCodeSource to CodeSourceDialog
212  int dotPos = mInitFunction.lastIndexOf( '.' );
213  if ( dotPos >= 0 ) // It's a module
214  {
216  setInitCode( QString( "from %1 import %2\n" ).arg( mInitFunction.left( dotPos ), mInitFunction.mid( dotPos + 1 ) ) );
217  setInitFunction( mInitFunction.mid( dotPos + 1 ) );
218  }
219 
220  QDomNode editFormInitFilePathNode = node.namedItem( "editforminitfilepath" );
221  if ( !editFormInitFilePathNode.isNull() || ( !editFormInitFilePathNode.isNull() && !editFormInitFilePathNode.toElement().text().isEmpty() ) )
222  {
223  setInitFilePath( QgsProject::instance()->readPath( editFormInitFilePathNode.toElement().text() ) );
224  }
225 
226  QDomNode fFSuppNode = node.namedItem( "featformsuppress" );
227  if ( fFSuppNode.isNull() )
228  {
229  mSuppressForm = QgsEditFormConfig::SuppressDefault;
230  }
231  else
232  {
233  QDomElement e = fFSuppNode.toElement();
234  mSuppressForm = static_cast< QgsEditFormConfig::FeatureFormSuppress >( e.text().toInt() );
235  }
236 
237  // tab display
238  QDomNode editorLayoutNode = node.namedItem( "editorlayout" );
239  if ( editorLayoutNode.isNull() )
240  {
241  mEditorLayout = QgsEditFormConfig::GeneratedLayout;
242  }
243  else
244  {
245  if ( editorLayoutNode.toElement().text() == "uifilelayout" )
246  {
247  mEditorLayout = QgsEditFormConfig::UiFileLayout;
248  }
249  else if ( editorLayoutNode.toElement().text() == "tablayout" )
250  {
251  mEditorLayout = QgsEditFormConfig::TabLayout;
252  }
253  else
254  {
255  mEditorLayout = QgsEditFormConfig::GeneratedLayout;
256  }
257  }
258 
259  // tabs and groups display info
260  clearTabs();
261  QDomNode attributeEditorFormNode = node.namedItem( "attributeEditorForm" );
262  QDomNodeList attributeEditorFormNodeList = attributeEditorFormNode.toElement().childNodes();
263 
264  for ( int i = 0; i < attributeEditorFormNodeList.size(); i++ )
265  {
266  QDomElement elem = attributeEditorFormNodeList.at( i ).toElement();
267 
268  QgsAttributeEditorElement *attributeEditorWidget = attributeEditorElementFromDomElement( elem, this );
269  addTab( attributeEditorWidget );
270  }
271 
272  onRelationsLoaded();
273 
274 
277 
278  QDomElement widgetsElem = node.namedItem( "widgets" ).toElement();
279 
280  QDomNodeList widgetConfigsElems = widgetsElem.childNodes();
281 
282  for ( int i = 0; i < widgetConfigsElems.size(); ++i )
283  {
285 
286  QDomElement wdgElem = widgetConfigsElems.at( i ).toElement();
287 
288  QDomElement cfgElem = wdgElem.namedItem( "config" ).toElement();
289 
290  for ( int j = 0; j < cfgElem.attributes().size(); ++j )
291  {
292  QDomAttr attr = cfgElem.attributes().item( j ).toAttr();
293  cfg.insert( attr.name(), attr.value() );
294  }
295 
296  QDomNodeList optionElements = cfgElem.elementsByTagName( "option" );
297  for ( int j = 0; j < optionElements.size(); ++j )
298  {
299  QString key = optionElements.at( j ).toElement().attribute( "key" );
300  QString value = optionElements.at( j ).toElement().attribute( "value" );
301  cfg.insert( key, value );
302  }
303 
304  setWidgetConfig( wdgElem.attribute( "name" ), cfg );
305  }
307 }
308 
310 {
311  QDomDocument doc( node.ownerDocument() );
312 
313  QDomElement efField = doc.createElement( "editform" );
314  QDomText efText = doc.createTextNode( QgsProject::instance()->writePath( uiForm() ) );
315  efField.appendChild( efText );
316  node.appendChild( efField );
317 
318  QDomElement efiField = doc.createElement( "editforminit" );
319  if ( !initFunction().isEmpty() )
320  efiField.appendChild( doc.createTextNode( initFunction() ) );
321  node.appendChild( efiField );
322 
323  QDomElement eficsField = doc.createElement( "editforminitcodesource" );
324  eficsField.appendChild( doc.createTextNode( QString::number( initCodeSource() ) ) );
325  node.appendChild( eficsField );
326 
327  QDomElement efifpField = doc.createElement( "editforminitfilepath" );
328  efifpField.appendChild( doc.createTextNode( QgsProject::instance()->writePath( initFilePath() ) ) );
329  node.appendChild( efifpField );
330 
331  QDomElement eficField = doc.createElement( "editforminitcode" );
332  eficField.appendChild( doc.createCDATASection( initCode() ) );
333  node.appendChild( eficField );
334 
335  QDomElement fFSuppElem = doc.createElement( "featformsuppress" );
336  QDomText fFSuppText = doc.createTextNode( QString::number( suppress() ) );
337  fFSuppElem.appendChild( fFSuppText );
338  node.appendChild( fFSuppElem );
339 
340  // tab display
341  QDomElement editorLayoutElem = doc.createElement( "editorlayout" );
342  switch ( layout() )
343  {
345  editorLayoutElem.appendChild( doc.createTextNode( "uifilelayout" ) );
346  break;
347 
349  editorLayoutElem.appendChild( doc.createTextNode( "tablayout" ) );
350  break;
351 
353  default:
354  editorLayoutElem.appendChild( doc.createTextNode( "generatedlayout" ) );
355  break;
356  }
357 
358  node.appendChild( editorLayoutElem );
359 
360  // tabs and groups of edit form
361  if ( tabs().size() > 0 )
362  {
363  QDomElement tabsElem = doc.createElement( "attributeEditorForm" );
364 
365  for ( QList< QgsAttributeEditorElement* >::const_iterator it = mAttributeEditorElements.constBegin(); it != mAttributeEditorElements.constEnd(); ++it )
366  {
367  QDomElement attributeEditorWidgetElem = ( *it )->toDomElement( doc );
368  tabsElem.appendChild( attributeEditorWidgetElem );
369  }
370 
371  node.appendChild( tabsElem );
372  }
373 
376 
377  QDomElement widgetsElem = doc.createElement( "widgets" );
378 
380 
381  while ( configIt != mWidgetConfigs.constEnd() )
382  {
383  if ( mFields.indexFromName( configIt.key() ) == -1 )
384  {
385  QDomElement widgetElem = doc.createElement( "widget" );
386  widgetElem.setAttribute( "name", configIt.key() );
387  // widgetElem.setAttribute( "notNull", );
388 
389  QDomElement configElem = doc.createElement( "config" );
390  widgetElem.appendChild( configElem );
391 
392  QgsEditorWidgetConfig::ConstIterator cfgIt( configIt.value().constBegin() );
393 
394  while ( cfgIt != configIt.value().constEnd() )
395  {
396  QDomElement optionElem = doc.createElement( "option" );
397  optionElem.setAttribute( "key", cfgIt.key() );
398  optionElem.setAttribute( "value", cfgIt.value().toString() );
399  configElem.appendChild( optionElem );
400  ++cfgIt;
401  }
402 
403  widgetsElem.appendChild( widgetElem );
404  }
405  ++configIt;
406  }
407 
408  node.appendChild( widgetsElem );
409 
411 }
412 
414 {
415  QgsAttributeEditorElement* newElement = nullptr;
416 
417  if ( elem.tagName() == "attributeEditorContainer" )
418  {
419  QgsAttributeEditorContainer* container = new QgsAttributeEditorContainer( elem.attribute( "name" ), parent );
420  bool ok;
421  int cc = elem.attribute( "columnCount" ).toInt( &ok );
422  if ( !ok )
423  cc = 0;
424  container->setColumnCount( cc );
425 
426  bool isGroupBox = elem.attribute( "groupBox" ).toInt( &ok );
427  if ( ok )
428  container->setIsGroupBox( isGroupBox );
429  else
430  container->setIsGroupBox( qobject_cast<QgsAttributeEditorContainer*>( parent ) );
431 
432  bool visibilityExpressionEnabled = elem.attribute( "visibilityExpressionEnabled" ).toInt( &ok );
433  QgsOptionalExpression visibilityExpression;
434  if ( ok )
435  {
436  visibilityExpression.setEnabled( visibilityExpressionEnabled );
437  visibilityExpression.setData( QgsExpression( elem.attribute( "visibilityExpression" ) ) );
438  }
439  container->setVisibilityExpression( visibilityExpression );
440 
441  QDomNodeList childNodeList = elem.childNodes();
442 
443  for ( int i = 0; i < childNodeList.size(); i++ )
444  {
445  QDomElement childElem = childNodeList.at( i ).toElement();
446  QgsAttributeEditorElement *myElem = attributeEditorElementFromDomElement( childElem, container );
447  if ( myElem )
448  container->addChildElement( myElem );
449  }
450 
451  newElement = container;
452  }
453  else if ( elem.tagName() == "attributeEditorField" )
454  {
455  QString name = elem.attribute( "name" );
456  int idx = mFields.fieldNameIndex( name );
457  newElement = new QgsAttributeEditorField( name, idx, parent );
458  }
459  else if ( elem.tagName() == "attributeEditorRelation" )
460  {
461  // At this time, the relations are not loaded
462  // So we only grab the id and delegate the rest to onRelationsLoaded()
463  QString name = elem.attribute( "name" );
464  QgsAttributeEditorRelation* relElement = new QgsAttributeEditorRelation( name, elem.attribute( "relation", "[None]" ), parent );
465  relElement->setShowLinkButton( elem.attribute( "showLinkButton", "1" ).toInt() );
466  relElement->setShowUnlinkButton( elem.attribute( "showUnlinkButton", "1" ).toInt() );
467  newElement = relElement;
468  }
469 
470  if ( elem.hasAttribute( "showLabel" ) )
471  newElement->setShowLabel( elem.attribute( "showLabel" ).toInt() );
472  else
473  newElement->setShowLabel( true );
474 
475  return newElement;
476 }
477 
478 void QgsEditFormConfig::onRelationsLoaded()
479 {
480  Q_FOREACH ( QgsAttributeEditorElement* elem, mAttributeEditorElements )
481  {
483  {
484  QgsAttributeEditorContainer* cont = dynamic_cast< QgsAttributeEditorContainer* >( elem );
485  if ( !cont )
486  continue;
487 
489  Q_FOREACH ( QgsAttributeEditorElement* relElem, relations )
490  {
491  QgsAttributeEditorRelation* rel = dynamic_cast< QgsAttributeEditorRelation* >( relElem );
492  if ( !rel )
493  continue;
494 
495  rel->init( QgsProject::instance()->relationManager() );
496  }
497  }
498  }
499 }
500 
502 {
503  return mColumnCount;
504 }
505 
507 {
508  mColumnCount = columnCount;
509 }
510 
511 void QgsAttributeEditorContainer::saveConfiguration( QDomElement& elem ) const
512 {
513  elem.setAttribute( "columnCount", mColumnCount );
514  elem.setAttribute( "groupBox", mIsGroupBox ? 1 : 0 );
515  elem.setAttribute( "visibilityExpressionEnabled", mVisibilityExpression.enabled() ? 1 : 0 );
516  elem.setAttribute( "visibilityExpression", mVisibilityExpression->expression() );
517 
518  Q_FOREACH ( QgsAttributeEditorElement* child, mChildren )
519  {
520  QDomDocument doc = elem.ownerDocument();
521  elem.appendChild( child->toDomElement( doc ) );
522  }
523 }
524 
526 {
527  return mVisibilityExpression;
528 }
529 
531 {
532  mVisibilityExpression = visibilityExpression;
533 }
534 
535 QString QgsAttributeEditorContainer::typeIdentifier() const
536 {
537  return "attributeEditorContainer";
538 }
539 
541 {
542  mChildren.append( widget );
543 }
544 
546 {
547  mName = name;
548 }
549 
551 {
553 
554  Q_FOREACH ( QgsAttributeEditorElement* elem, mChildren )
555  {
556  if ( elem->type() == type )
557  {
558  results.append( elem );
559  }
560 
561  if ( elem->type() == AeTypeContainer )
562  {
563  QgsAttributeEditorContainer* cont = dynamic_cast<QgsAttributeEditorContainer*>( elem );
564  if ( cont )
565  results += cont->findElements( type );
566  }
567  }
568 
569  return results;
570 }
571 
572 void QgsAttributeEditorField::saveConfiguration( QDomElement &elem ) const
573 {
574  elem.setAttribute( "index", mIdx );
575 }
576 
577 QString QgsAttributeEditorField::typeIdentifier() const
578 {
579  return "attributeEditorField";
580 }
581 
583 {
584  QDomElement elem = doc.createElement( typeIdentifier() );
585  elem.setAttribute( "name", mName );
586  elem.setAttribute( "showLabel", mShowLabel );
587 
588  saveConfiguration( elem );
589  return elem;
590 }
591 
593 {
594  return mShowLabel;
595 }
596 
598 {
599  mShowLabel = showLabel;
600 }
601 
602 void QgsAttributeEditorRelation::saveConfiguration( QDomElement& elem ) const
603 {
604  elem.setAttribute( "relation", mRelation.id() );
605  elem.setAttribute( "showLinkButton", mShowLinkButton );
606  elem.setAttribute( "showUnlinkButton", mShowUnlinkButton );
607 }
608 
609 QString QgsAttributeEditorRelation::typeIdentifier() const
610 {
611  return "attributeEditorRelation";
612 }
613 
615 {
616  return mShowUnlinkButton;
617 }
618 
620 {
621  mShowUnlinkButton = showUnlinkButton;
622 }
623 
625 {
626  mRelation = relationManager->relation( mRelationId );
627  return mRelation.isValid();
628 }
629 
631 {
632  return mShowLinkButton;
633 }
634 
636 {
637  mShowLinkButton = showLinkButton;
638 }
QObject * child(const char *objName, const char *inheritsClass, bool recursiveSearch) const
Class for parsing and evaluation of expressions (formerly called "search strings").
QDomNodeList elementsByTagName(const QString &tagname) const
bool isValid() const
Returns the validity of this relation.
bool notNull(int fieldidx) const
Returns if the field at fieldidx should be treated as NOT NULL value.
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: qgsfield.h:260
void setName(const QString &name)
Change the name of this container.
This is an abstract base class for any elements of a drag and drop form.
FieldOrigin fieldOrigin(int fieldIdx) const
Get field&#39;s origin (value from an enumeration)
Definition: qgsfield.cpp:448
void setWidgetConfig(int attrIdx, const QgsEditorWidgetConfig &config)
Set the editor widget config for a field.
QString name
Definition: qgsfield.h:52
QString name() const
QDomNode appendChild(const QDomNode &newChild)
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.
bool removeWidgetConfig(int fieldIdx)
Remove the configuration for the editor widget used to represent the field at the given index...
void setVisibilityExpression(const QgsOptionalExpression &visibilityExpression)
An expression that controls the visibility of this container.
QString attribute(const QString &name, const QString &defValue) const
void setExpressionDescription(int idx, const QString &descr)
Set the constraint expression description for a specific field.
QList< QgsAttributeEditorElement *> tabs() const
Returns a list of tabs for EditorLayout::TabLayout.
const_iterator constBegin() const
Use a layout with tabs and group boxes. Needs to be configured.
virtual QList< QgsAttributeEditorElement * > findElements(AttributeEditorType type) const
Traverses the element tree to find any element of the specified type.
QgsEditFormConfig(QObject *parent=nullptr)
Create a new edit form config.
Container of fields for a vector layer.
Definition: qgsfield.h:252
This element will load a field&#39;s widget onto the form.
QDomElement toDomElement(QDomDocument &doc) const
Get the XML Dom element to save this element.
QString expression(int idx) const
Returns the constraint expression of a specific field.
This element will load a relation editor onto the form.
void setInitFunction(const QString &function)
Set python function for edit form initialization.
void setWidgetType(int fieldIdx, const QString &widgetType)
Set the editor widget type for a field.
void setColumnCount(int columnCount)
Set the number of columns in this group.
QDomNodeList childNodes() const
int count() const
Return number of items.
Definition: qgsfield.cpp:402
AttributeEditorType type() const
The type of this element.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.cpp:422
int lastIndexOf(QChar ch, int from, Qt::CaseSensitivity cs) const
bool isNull() const
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...
QDomElement toElement() const
const char * name() const
void setData(const T &data)
Set the payload data.
Definition: qgsoptional.h:127
QString number(int n, int base)
QVariantMap QgsEditorWidgetConfig
Holds a set of configuration parameters for a editor widget wrapper.
An expression with an additional enabled flag.
void append(const T &value)
void setShowLabel(bool showLabel)
Controls if this element should be labeled with a title (field, relation or groupname).
bool showUnlinkButton() const
Determines if the "unlink feature" button should be shown.
QString & insert(int position, QChar ch)
void writeXml(QDomNode &node) const
Write XML information Serialize on project save.
QDomDocument ownerDocument() const
QString text() const
bool hasAttribute(const QString &name) const
void setLayout(EditorLayout editorLayout)
Set the active layout style for the attribute editor for this layer.
void setAttribute(const QString &name, const QString &value)
void addTab(QgsAttributeEditorElement *data)
This is only useful in combination with EditorLayout::TabLayout.
int toInt(bool *ok, int base) const
FeatureFormSuppress
Types of feature form suppression after feature creation.
bool isEmpty() const
const_iterator constEnd() const
bool showLabel() const
Controls if this element should be labeled with a title (field, relation or groupname).
QString expressionDescription(int idx) const
Returns the constraint expression description of a specific filed.
void setNotNull(int idx, bool notnull=true)
Set if the field at fieldidx should be treated as NOT NULL value.
QgsOptionalExpression visibilityExpression() const
An expression that controls the visibility of this container.
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.
QgsAttributeEditorElement * attributeEditorElementFromDomElement(QDomElement &elem, QObject *parent)
Deserialize drag and drop designer elements.
QDomNode namedItem(const QString &name) const
int fieldNameIndex(const QString &fieldName) const
Look up field&#39;s index from name also looks up case-insensitive if there is no match otherwise...
Definition: qgsfield.cpp:571
void setShowLinkButton(bool showLinkButton)
Determines if the "link feature" button should be shown.
QString value() const
void setExpression(int idx, const QString &str)
Set the constraint expression for a specific field.
void setShowUnlinkButton(bool showUnlinkButton)
Determines if the "unlink feature" button should be shown.
bool isNull() const
QString initCode() const
Get python code for edit form initialization.
int indexFromName(const QString &name) const
Look up field&#39;s index from name. Returns -1 on error.
Definition: qgsfield.cpp:461
void setUiForm(const QString &ui)
Set path to the .ui form.
QgsEditorWidgetConfig widgetConfig(int fieldIdx) const
Get the configuration for the editor widget used to represent the field at the given index...
QString mid(int position, int n) const
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.
This class manages a set of relations between layers.
int columnCount() const
Get the number of columns in this group.
QString readPath(QString filename, const QString &relativeBasePath=QString()) const
Turn filename read from the project file to an absolute path.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:382
QDomAttr toAttr() const
This is a container for attribute editors, used to group them visually in the attribute form if it is...
QString left(int n) const
void readXml(const QDomNode &node)
Read XML information Deserialize on project load.
virtual void addChildElement(QgsAttributeEditorElement *element)
Add a child element to this container.
QString tagName() const
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 ...
int size() const
bool showLinkButton() const
Determines if the "link feature" button should be shown.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
bool labelOnTop(int idx) const
If this returns true, the widget at the given index will receive its label on the previous line while...
QDomNode item(int index) const
QString widgetType(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
void setEnabled(bool enabled)
Set if this optional is enabled.
Definition: qgsoptional.h:97
QgsRelation relation(const QString &id) const
Get access to a relation by its id.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const
field is calculated from an expression
Definition: qgsfield.h:262
EditorLayout layout() const
Get the active layout style for the attribute editor for this layer.
QString initFunction() const
Get python function for edit form initialization.
int size() const
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.
QDomNode at(int index) const
const T value(const Key &key) const
PythonInitCodeSource initCodeSource() const
Return python code source for edit form initialization (if it shall be loaded from a file...
QDomNamedNodeMap attributes() const
int remove(const Key &key)
QString writePath(const QString &filename, const QString &relativeBasePath=QString()) const
Prepare a filename to save it to the project file.
QString initFilePath() const
Get python external file path for edit form initialization.