QGIS API Documentation  2.3.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsattributedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributedialog.cpp - description
3  -------------------
4  begin : October 2004
5  copyright : (C) 2004 by Marco Hugentobler
6  email : marco.hugentobler@autoform.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 #include "qgsattributedialog.h"
18 #include "qgseditorwidgetwrapper.h"
19 #include "qgsfield.h"
20 #include "qgslogger.h"
21 #include "qgsmapcanvas.h"
22 #include "qgsproject.h"
23 #include "qgsrelationeditor.h"
24 #include "qgsvectordataprovider.h"
25 #include "qgsvectorlayer.h"
26 #include "qgsattributeeditor.h"
27 #include "qgshighlight.h"
28 #include "qgsexpression.h"
29 #include "qgspythonrunner.h"
30 
31 #include <QTableWidgetItem>
32 #include <QSettings>
33 #include <QLabel>
34 #include <QFrame>
35 #include <QScrollArea>
36 #include <QFile>
37 #include <QFileInfo>
38 #include <QDir>
39 #include <QDialogButtonBox>
40 #include <QUiLoader>
41 #include <QDialog>
42 #include <QVBoxLayout>
43 #include <QLineEdit>
44 #include <QWebView>
45 #include <QPushButton>
46 
48 QString QgsAttributeDialog::sSettingsPath = "/Windows/AttributeDialog/";
49 
50 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QWidget* parent, bool showDialogButtons, QgsAttributeEditorContext context )
51  : QObject( parent )
52  , mDialog( 0 )
53  , mContext( context )
54  , mLayer( vl )
55  , mFeature( thepFeature )
56  , mFeatureOwner( featureOwner )
57  , mHighlight( 0 )
58  , mFormNr( sFormCounter++ )
59  , mShowDialogButtons( showDialogButtons )
60 {
62  init();
63 }
64 
65 QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer* vl, QgsFeature* thepFeature, bool featureOwner, QgsDistanceArea myDa, QWidget* parent, bool showDialogButtons )
66  : QObject( parent )
67  , mDialog( 0 )
68  , mContext( )
69  , mLayer( vl )
70  , mFeature( thepFeature )
71  , mFeatureOwner( featureOwner )
72  , mHighlight( 0 )
73  , mFormNr( sFormCounter++ )
74  , mShowDialogButtons( showDialogButtons )
75 {
76  mContext.setDistanceArea( myDa );
78  init();
79 }
80 
82 {
83  if ( !mFeature || !mLayer->dataProvider() )
84  return;
85 
86  const QgsFields &theFields = mLayer->pendingFields();
87  if ( theFields.isEmpty() )
88  return;
89 
90  QDialogButtonBox *buttonBox = NULL;
91 
92  if ( mLayer->editorLayout() == QgsVectorLayer::UiFileLayout && !mLayer->editForm().isEmpty() )
93  {
94  // UI-File defined layout
95  QFile file( mLayer->editForm() );
96 
97  if ( file.open( QFile::ReadOnly ) )
98  {
99  QUiLoader loader;
100 
101  QFileInfo fi( mLayer->editForm() );
102  loader.setWorkingDirectory( fi.dir() );
103  QWidget *myWidget = loader.load( &file, qobject_cast<QWidget*>( parent() ) );
104  file.close();
105 
106  mDialog = qobject_cast<QDialog*>( myWidget );
107  buttonBox = myWidget->findChild<QDialogButtonBox*>();
108  }
109  }
111  {
112  // Tab display
113  mDialog = new QDialog( qobject_cast<QWidget*>( parent() ) );
114 
115  QGridLayout *gridLayout;
116  QTabWidget *tabWidget;
117 
118  mDialog->resize( 447, 343 );
119  gridLayout = new QGridLayout( mDialog );
120  gridLayout->setObjectName( QString::fromUtf8( "gridLayout" ) );
121 
122  tabWidget = new QTabWidget( mDialog );
123  gridLayout->addWidget( tabWidget );
124 
125  foreach ( const QgsAttributeEditorElement *widgDef, mLayer->attributeEditorElements() )
126  {
127  QWidget* tabPage = new QWidget( tabWidget );
128 
129  tabWidget->addTab( tabPage, widgDef->name() );
130  QGridLayout *tabPageLayout = new QGridLayout( tabPage );
131 
133  {
134  QString dummy1;
135  bool dummy2;
136  tabPageLayout->addWidget( QgsAttributeEditor::createWidgetFromDef( widgDef, tabPage, mLayer, *mFeature, mContext, dummy1, dummy2 ) );
137  }
138  else
139  {
140  QgsDebugMsg( "No support for fields in attribute editor on top level" );
141  }
142  }
143 
144  buttonBox = new QDialogButtonBox( mDialog );
145  buttonBox->setObjectName( QString::fromUtf8( "buttonBox" ) );
146  gridLayout->addWidget( buttonBox );
147  }
148 
149  // Still no dialog: create the default generated dialog
150  if ( !mDialog )
151  {
152  mDialog = new QDialog( qobject_cast<QWidget*>( parent() ) );
153 
154  QGridLayout *gridLayout;
155  QFrame *mFrame;
156 
157  mDialog->resize( 447, 343 );
158  gridLayout = new QGridLayout( mDialog );
159  gridLayout->setSpacing( 6 );
160  gridLayout->setMargin( 2 );
161  gridLayout->setObjectName( QString::fromUtf8( "gridLayout" ) );
162  mFrame = new QFrame( mDialog );
163  mFrame->setObjectName( QString::fromUtf8( "mFrame" ) );
164  mFrame->setFrameShape( QFrame::NoFrame );
165  mFrame->setFrameShadow( QFrame::Plain );
166 
167  gridLayout->addWidget( mFrame, 0, 0, 1, 1 );
168 
169  buttonBox = new QDialogButtonBox( mDialog );
170  buttonBox->setObjectName( QString::fromUtf8( "buttonBox" ) );
171  gridLayout->addWidget( buttonBox, 2, 0, 1, 1 );
172 
173  //
174  //Set up dynamic inside a scroll box
175  //
176  QVBoxLayout *mypOuterLayout = new QVBoxLayout();
177  mypOuterLayout->setContentsMargins( 0, 0, 0, 0 );
178 
179  //transfers layout ownership so no need to call delete
180  mFrame->setLayout( mypOuterLayout );
181 
182  QScrollArea *mypScrollArea = new QScrollArea();
183  mypScrollArea->setFrameShape( QFrame::NoFrame );
184  mypScrollArea->setFrameShadow( QFrame::Plain );
185 
186  //transfers scroll area ownership so no need to call delete
187  mypOuterLayout->addWidget( mypScrollArea );
188 
189  QFrame *mypInnerFrame = new QFrame();
190  mypInnerFrame->setFrameShape( QFrame::NoFrame );
191  mypInnerFrame->setFrameShadow( QFrame::Plain );
192 
193  //transfers frame ownership so no need to call delete
194  mypScrollArea->setWidget( mypInnerFrame );
195 
196  mypScrollArea->setWidgetResizable( true );
197  QGridLayout *mypInnerLayout = new QGridLayout( mypInnerFrame );
198 
199  int index = 0;
200  for ( int fldIdx = 0; fldIdx < theFields.count(); ++fldIdx )
201  {
202  //show attribute alias if available
203  QString myFieldName = mLayer->attributeDisplayName( fldIdx );
204  // by default (until user defined alias) append date format
205  // (validator does not allow to enter a value in wrong format)
206  const QgsField &myField = theFields[fldIdx];
207  if ( myField.type() == QVariant::Date && mLayer->attributeAlias( fldIdx ).isEmpty() )
208  {
209  myFieldName += " (" + mLayer->dateFormat( fldIdx ) + ")";
210  }
211 
212  QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( mDialog, 0, mLayer, fldIdx, mFeature->attribute( fldIdx ), mContext );
213  if ( !myWidget )
214  continue;
215 
216  QLabel *mypLabel = new QLabel( myFieldName, mypInnerFrame );
217 
218  if ( mLayer->editType( fldIdx ) != QgsVectorLayer::Immutable )
219  {
220  if ( mLayer->isEditable() && mLayer->fieldEditable( fldIdx ) )
221  {
222  myWidget->setEnabled( true );
223  }
224  else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::Photo )
225  {
226  foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
227  {
228  w->setEnabled( qobject_cast<QLabel *>( w ) ? true : false );
229  }
230  }
231  else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::WebView )
232  {
233  foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
234  {
235  if ( qobject_cast<QWebView *>( w ) )
236  w->setEnabled( true );
237  else if ( qobject_cast<QPushButton *>( w ) && w->objectName() == "openUrl" )
238  w->setEnabled( true );
239  else
240  w->setEnabled( false );
241  }
242  }
243  else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::EditorWidgetV2 )
244  {
245  QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget( myWidget );
246  if ( ww )
247  {
248  ww->setEnabled( false );
249  }
250  }
251  else
252  {
253  myWidget->setEnabled( false );
254  }
255  }
256 
257  if ( mLayer->labelOnTop( fldIdx ) )
258  {
259  mypInnerLayout->addWidget( mypLabel, index++, 0, 1, 2 );
260  mypInnerLayout->addWidget( myWidget, index++, 0, 1, 2 );
261  }
262  else
263  {
264  mypInnerLayout->addWidget( mypLabel, index, 0 );
265  mypInnerLayout->addWidget( myWidget, index, 1 );
266  ++index;
267  }
268  }
269 
270  QList<QgsRelation> relations = QgsProject::instance()->relationManager()->referencedRelations( mLayer );
271 
272  foreach ( const QgsRelation& relation, relations )
273  {
275  if ( !myWidget )
276  continue;
277 
278  myWidget->setProperty( "qgisRelation", relation.id() );
279  myWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
280  mypInnerLayout->addWidget( myWidget, index, 0, 1, 2 );
281  mypInnerLayout->setRowStretch( index, 2 );
282  ++index;
283  }
284 
285  // Set focus to first widget in list, to help entering data without moving the mouse.
286  if ( mypInnerLayout->rowCount() > 0 )
287  {
288  QWidget* widget = mypInnerLayout->itemAtPosition( 0, 1 )->widget();
289  if ( widget )
290  widget->setFocus( Qt::OtherFocusReason );
291  }
292 
293  QSpacerItem *mypSpacer = new QSpacerItem( 0, 0, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding );
294  mypInnerLayout->addItem( mypSpacer, mypInnerLayout->rowCount() + 1, 0 );
295  }
296  else
297  {
298 #if 0
299  QgsDistanceArea myDa;
300 
301  myDa.setSourceCrs( vl->crs().srsid() );
302  myDa.setEllipsoidalMode( QgisApp::instance()->mapCanvas()->mapRenderer()->hasCrsTransformEnabled() );
303  myDa.setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
304 #endif
305 
306  // Get all widgets on the dialog
307  QList<QWidget *> myWidgets = mDialog->findChildren<QWidget*>();
308  Q_FOREACH( QWidget* myWidget, myWidgets )
309  {
310  // Check the widget's properties for a relation definition
311  QVariant vRel = myWidget->property( "qgisRelation" );
312  if ( vRel.isValid() )
313  {
315  QgsRelation relation = relMgr->relation( vRel.toString() );
316  if ( relation.isValid() )
317  {
319  if ( !myWidget->layout() )
320  {
321  myWidget->setLayout( new QHBoxLayout() );
322  }
323  myWidget->layout()->addWidget( relWdg );
324  }
325  }
326  else
327  {
328  // No widget definition properties defined, check if the widget's
329  // objectName matches a field name
330  for ( int fldIdx = 0; fldIdx < theFields.count(); ++fldIdx )
331  {
332  if ( myWidget->objectName() == theFields[fldIdx].name() )
333  {
335 
336  if ( mLayer->editType( fldIdx ) != QgsVectorLayer::Immutable )
337  {
338  if ( mLayer->isEditable() && mLayer->fieldEditable( fldIdx ) )
339  {
340  myWidget->setEnabled( true );
341  }
342  else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::Photo )
343  {
344  foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
345  {
346  w->setEnabled( qobject_cast<QLabel *>( w ) ? true : false );
347  }
348  }
349  else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::WebView )
350  {
351  foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
352  {
353  w->setEnabled( qobject_cast<QWebView *>( w ) ? true : false );
354  }
355  }
356  else if ( mLayer->editType( fldIdx ) == QgsVectorLayer::EditorWidgetV2 )
357  {
358  QgsEditorWidgetWrapper* ww = QgsEditorWidgetWrapper::fromWidget( myWidget );
359  if ( ww )
360  {
361  ww->setEnabled( false );
362  }
363  }
364  else
365  {
366  myWidget->setEnabled( false );
367  }
368  }
369  }
370  }
371  }
372  }
373 
374  foreach ( QLineEdit *le, mDialog->findChildren<QLineEdit*>() )
375  {
376  if ( !le->objectName().startsWith( "expr_" ) )
377  continue;
378 
379  le->setReadOnly( true );
380  QString expr = le->text();
381  le->setText( tr( "Error" ) );
382 
383  QgsExpression exp( expr );
384  if ( exp.hasParserError() )
385  continue;
386 
387 
388  if ( !mFeature->geometry() && exp.needsGeometry() )
389  {
390  QgsFeature f;
391  if ( mLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeature->id() ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) && f.geometry() )
392  {
393  mFeature->setGeometry( *f.geometry() );
394  }
395  }
396 
398 
399  QVariant value = exp.evaluate( mFeature, mLayer->pendingFields() );
400 
401  if ( !exp.hasEvalError() )
402  {
403  QString text;
404  switch ( value.type() )
405  {
406  case QVariant::Invalid: text = "NULL"; break;
407  case QVariant::Int: text = QString::number( value.toInt() ); break;
408  case QVariant::LongLong: text = QString::number( value.toLongLong() ); break;
409  case QVariant::Double: text = QString::number( value.toDouble() ); break;
410  case QVariant::String:
411  default: text = value.toString();
412  }
413  le->setText( text );
414  }
415  else
416  {
417  le->setText( tr( "Error: %1" ).arg( exp.evalErrorString() ) );
418  }
419  }
420  }
421 
423 
424  if ( mDialog )
425  {
426  if ( mDialog->objectName().isEmpty() )
427  mDialog->setObjectName( "QgsAttributeDialogBase" );
428 
429  if ( mDialog->windowTitle().isEmpty() )
430  mDialog->setWindowTitle( tr( "Attributes - %1" ).arg( mLayer->name() ) );
431  }
432 
433  if ( mShowDialogButtons )
434  {
435  if ( buttonBox )
436  {
437  buttonBox->clear();
438 
439  if ( mLayer->isEditable() )
440  {
441  buttonBox->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
442  connect( buttonBox, SIGNAL( accepted() ), mDialog, SLOT( accept() ) );
443  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
444  }
445  else
446  {
447  buttonBox->setStandardButtons( QDialogButtonBox::Cancel );
448  }
449 
450  connect( buttonBox, SIGNAL( rejected() ), mDialog, SLOT( reject() ) );
451  }
452  }
453  else
454  {
455  if ( buttonBox )
456  {
457  // Add dummy buttons
458  if ( mLayer->isEditable() )
459  {
460  buttonBox->clear();
461 
462  buttonBox->setStandardButtons( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
463  connect( buttonBox, SIGNAL( accepted() ), mDialog, SLOT( accept() ) );
464  connect( buttonBox, SIGNAL( accepted() ), this, SLOT( accept() ) );
465  }
466 
467  buttonBox->setVisible( false );
468  }
469  }
470 
471  QMetaObject::connectSlotsByName( mDialog );
472 
473  connect( mDialog, SIGNAL( destroyed() ), this, SLOT( dialogDestroyed() ) );
474 
475  if ( !mLayer->editFormInit().isEmpty() )
476  {
477 #if 0
478  // would be nice if only PyQt's QVariant.toPyObject() wouldn't take ownership
479  vl->setProperty( "featureForm.dialog", QVariant::fromValue( qobject_cast<QObject*>( mDialog ) ) );
480  vl->setProperty( "featureForm.id", QVariant( mpFeature->id() ) );
481 #endif
482 
483  QString module = mLayer->editFormInit();
484  int pos = module.lastIndexOf( "." );
485  if ( pos >= 0 )
486  {
487  QgsPythonRunner::run( QString( "import %1" ).arg( module.left( pos ) ) );
488  }
489 
490  /* Reload the module if the DEBUGMODE switch has been set in the module.
491  If set to False you have to reload QGIS to reset it to True due to Python
492  module caching */
493  QString reload = QString( "if hasattr(%1,'DEBUGMODE') and %1.DEBUGMODE:"
494  " reload(%1)" ).arg( module.left( pos ) );
495 
496  QgsPythonRunner::run( reload );
497 
498  QString form = QString( "_qgis_featureform_%1 = sip.wrapinstance( %2, QtGui.QDialog )" )
499  .arg( mFormNr )
500  .arg(( unsigned long ) mDialog );
501 
502  QString layer = QString( "_qgis_layer_%1 = sip.wrapinstance( %2, qgis.core.QgsVectorLayer )" )
503  .arg( mLayer->id() )
504  .arg(( unsigned long ) mLayer );
505 
506  // Generate the unique ID of this feature. We used to use feature ID but some providers
507  // return a ID that is an invalid python variable when we have new unsaved features.
508  QDateTime dt = QDateTime::currentDateTime();
509  QString featurevarname = QString( "_qgis_feature_%1" ).arg( dt.toString( "yyyyMMddhhmmsszzz" ) );
510  QString feature = QString( "%1 = sip.wrapinstance( %2, qgis.core.QgsFeature )" )
511  .arg( featurevarname )
512  .arg(( unsigned long ) mFeature );
513 
514  QgsPythonRunner::run( form );
515  QgsPythonRunner::run( feature );
516  QgsPythonRunner::run( layer );
517 
518  mReturnvarname = QString( "_qgis_feature_form_%1" ).arg( dt.toString( "yyyyMMddhhmmsszzz" ) );
519  QString expr = QString( "%5 = %1(_qgis_featureform_%2, _qgis_layer_%3, %4)" )
520  .arg( mLayer->editFormInit() )
521  .arg( mFormNr )
522  .arg( mLayer->id() )
523  .arg( featurevarname )
524  .arg( mReturnvarname );
525 
526  QgsDebugMsg( QString( "running featureForm init: %1" ).arg( expr ) );
527  QgsPythonRunner::run( expr );
528  }
529 
530  // Only restore the geometry of the dialog if it's not a custom one.
532  {
533  restoreGeometry();
534  }
535 }
536 
537 
539 {
540  if ( mHighlight )
541  {
542  mHighlight->hide();
543  delete mHighlight;
544  }
545 
546  if ( mFeatureOwner )
547  {
548  delete mFeature;
549  }
550 
551  // Only save the geometry of the dialog if it's not a custom one.
553  {
554  saveGeometry();
555  }
556 
557  if ( mDialog )
558  {
559  delete mDialog;
560  }
561 }
562 
564 {
565  if ( !mLayer->isEditable() || !mFeature )
566  return;
567 
568  //write the new values back to the feature
569  const QgsFields& fields = mLayer->pendingFields();
570  for ( int idx = 0; idx < fields.count(); ++idx )
571  {
572  QVariant value;
573 
575  mFeature->setAttribute( idx, value );
576  }
577 }
578 
580 {
581  if ( mDialog )
582  {
583  return mDialog->exec();
584  }
585  else
586  {
587  QgsDebugMsg( "No dialog" );
588  return QDialog::Accepted;
589  }
590 }
591 
593 {
594  if ( mDialog )
595  {
596  mDialog->setAttribute( Qt::WA_DeleteOnClose );
597  mDialog->show();
598  mDialog->raise();
599  mDialog->activateWindow();
600  mDialog->installEventFilter( this );
601  }
602 }
603 
605 {
606  if ( mDialog )
607  {
608  QSettings settings;
609  settings.setValue( mSettingsPath + "geometry", mDialog->saveGeometry() );
610  }
611 }
612 
614 {
615  if ( mDialog )
616  {
617  QSettings settings;
618  mDialog->restoreGeometry( settings.value( mSettingsPath + "geometry" ).toByteArray() );
619  }
620 }
621 
623 {
624  if ( mHighlight )
625  {
626  delete mHighlight;
627  }
628 
629  mHighlight = h;
630 }
631 
632 
634 {
635 #if 0
636  mLayer->setProperty( "featureForm.dialog", QVariant() );
637  mLayer->setProperty( "featureForm.id", QVariant() );
638 #endif
639  if ( -1 < mFormNr )
640  {
641  QString expr = QString( "if locals().has_key('_qgis_featureform_%1'): del _qgis_featureform_%1\n" ).arg( mFormNr );
642  QgsPythonRunner::run( expr );
643  }
644 
645  if ( !mReturnvarname.isEmpty() )
646  {
647  QString expr = QString( "if locals().has_key('%1'): del %1\n" ).arg( mReturnvarname );
648  QgsPythonRunner::run( expr );
649  }
650 
651  mDialog = NULL;
652  deleteLater();
653 }
654 
655 bool QgsAttributeDialog::eventFilter( QObject *obj, QEvent *e )
656 {
657  if ( mHighlight && obj == mDialog )
658  {
659  switch ( e->type() )
660  {
661  case QEvent::WindowActivate:
662  mHighlight->show();
663  break;
664  case QEvent::WindowDeactivate:
665  mHighlight->hide();
666  break;
667  default:
668  break;
669  }
670  }
671 
672  return false;
673 }
QgsFeatureId id() const
Get the feature id for this feature.
Definition: qgsfeature.cpp:100
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
QgsFeature * feature()
bool hasEvalError() const
Returns true if an error occurred when evaluating last input.
bool isValid() const
Returns the validity of this relation.
static unsigned index
bool fieldEditable(int idx)
is edit widget editable
bool hasParserError() const
Returns true if an error occurred when parsing the input expression.
Definition: qgsexpression.h:96
QWidget * proxyWidget(QgsVectorLayer *vl, int fieldIdx)
EditorLayout editorLayout()
get the active layout for the attribute editor for this layer (added in 1.9)
void restoreGeometry()
Restores the size and position from the last time this dialog box was used.
static bool retrieveValue(QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value)
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
The attribute value should not be changed in the attribute form.
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
This class contains context information for attribute editor widgets.
void saveGeometry()
Saves the size and position for the next time this dialog box will be used.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
Definition: qgsfeature.cpp:112
QgsHighlight * mHighlight
Container of fields for a vector layer.
Definition: qgsfield.h:164
QgsVectorLayer * mLayer
bool setAttribute(int field, const QVariant &attr)
Set an attribute by id.
Definition: qgsfeature.cpp:190
void setHighlight(QgsHighlight *h)
QgsAttributeDialog(QgsVectorLayer *vl, QgsFeature *thepFeature, bool featureOwner, QgsDistanceArea myDa, QWidget *parent=0, bool showDialogButtons=true)
Create an attribute dialog for a given layer and feature.
bool setEllipsoid(const QString &ellipsoid)
sets ellipsoid by its acronym
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:114
static QWidget * createWidgetFromDef(const QgsAttributeEditorElement *widgetDef, QWidget *parent, QgsVectorLayer *vl, const QgsFeature &feat, QgsAttributeEditorContext &context, QString &labelText, bool &labelOnTop)
Creates a widget form a QgsAttributeEditorElement definition.
QString editForm()
get edit form (added in 1.4)
const QString & name() const
Get the display name of the layer.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object (deep copy)
Definition: qgsfeature.cpp:134
QList< QgsRelation > referencedRelations(QgsVectorLayer *layer=0) const
static QgsRelationEditorWidget * createRelationEditor(const QgsRelation &relation, const QgsFeature &feature, QgsAttributeEditorContext context, QWidget *parent=NULL)
QString attributeDisplayName(int attributeIndex) const
Convenience function that returns the attribute alias if defined or the field name else...
static bool run(QString command, QString messageOnError=QString())
execute a python statement
QgsRelation relation(const QString &id) const
EditType editType(int idx)
get edit type
const QString & id() const
The id.
void adjustForLayer(QgsVectorLayer *layer)
When copying the context for another layer, call this.
bool eventFilter(QObject *obj, QEvent *event)
A class for highlight features on the map.
Definition: qgshighlight.h:36
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
AttributeEditorType type() const
QString & dateFormat(int idx)
access date format
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Definition: qgsmaplayer.cpp:92
int count() const
Return number of items.
Definition: qgsfield.h:198
static QString sSettingsPath
void setDistanceArea(const QgsDistanceArea &distanceArea)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:31
QString attributeAlias(int attributeIndex) const
Returns the alias of an attribute name or an empty string if there is no alias.
bool labelOnTop(int idx)
label widget on top
bool needsGeometry()
Returns true if the expression uses feature geometry for some computation.
QString file
Definition: qgssvgcache.cpp:76
General purpose distance and area calculator.
static QWidget * createAttributeEditor(QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap< int, QWidget * > &proxyWidgets)
Creates or prepares a attribute editor widget.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:230
This class manages a set of relations between layers.
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:362
const CORE_EXPORT QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
Definition: qgis.cpp:73
QList< QgsAttributeEditorElement * > & attributeEditorElements()
Returns a list of tabs holding groups and fields.
void setGeomCalculator(const QgsDistanceArea &calc)
Sets the geometry calculator used in evaluation of expressions,.
QgsAttributeEditorContext mContext
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
QgsVectorDataProvider * dataProvider()
Returns the data provider.
QString editFormInit()
get python function for edit form initialization (added in 1.4)
bool nextFeature(QgsFeature &f)
virtual bool isEditable() const
Returns true if the provider is in editing mode.
Represents a vector layer which manages a vector based data sets.
bool isEmpty() const
Check whether the container is empty.
Definition: qgsfield.h:196
QgsRelationManager * relationManager() const
modularized edit widgets
QString evalErrorString() const
Returns evaluation error.
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
Definition: qgsfield.cpp:60
const QgsDistanceArea & distanceArea()
#define tr(sourceText)