QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgsrelationreferencewidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrelationreferencewidget.cpp
3  --------------------------------------
4  Date : 20.4.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias dot kuhn at gmx 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 
17 
18 #include <QPushButton>
19 #include <QDialog>
20 #include <QHBoxLayout>
21 #include <QTimer>
22 
23 #include "qgsattributeform.h"
24 #include "qgsattributedialog.h"
25 #include "qgsapplication.h"
26 #include "qgscollapsiblegroupbox.h"
27 #include "qgseditorwidgetfactory.h"
28 #include "qgsexpression.h"
29 #include "qgsfield.h"
30 #include "qgsgeometry.h"
31 #include "qgsmapcanvas.h"
32 #include "qgsmessagebar.h"
34 #include "qgsvectorlayer.h"
35 
36 
38  : QWidget( parent )
39  , mEditorContext( QgsAttributeEditorContext() )
40  , mCanvas( NULL )
41  , mMessageBar( NULL )
42  , mForeignKey( QVariant() )
43  , mFeatureId( QgsFeatureId() )
44  , mFkeyFieldIdx( -1 )
45  , mAllowNull( true )
46  , mHighlight( NULL )
47  , mMapTool( NULL )
48  , mMessageBarItem( NULL )
49  , mRelationName( "" )
50  , mReferencedAttributeForm( NULL )
51  , mReferencedLayer( NULL )
52  , mReferencingLayer( NULL )
53  , mWindowWidget( NULL )
54  , mShown( false )
55  , mIsEditable( true )
56  , mEmbedForm( false )
57  , mReadOnlySelector( false )
58  , mAllowMapIdentification( false )
59  , mOpenFormButtonVisible( true )
60 {
61  mTopLayout = new QVBoxLayout( this );
62  mTopLayout->setContentsMargins( 0, 0, 0, 0 );
63  mTopLayout->setAlignment( Qt::AlignTop );
64  setLayout( mTopLayout );
65 
66  QHBoxLayout* editLayout = new QHBoxLayout();
67  editLayout->setContentsMargins( 0, 0, 0, 0 );
68  editLayout->setSpacing( 2 );
69 
70  // combobox (for non-geometric relation)
71  mComboBox = new QComboBox( this );
72  editLayout->addWidget( mComboBox );
73 
74  // read-only line edit
75  mLineEdit = new QLineEdit( this );
76  mLineEdit->setReadOnly( true );
77  editLayout->addWidget( mLineEdit );
78 
79  // open form button
80  mOpenFormButton = new QToolButton( this );
81  mOpenFormButton->setIcon( QgsApplication::getThemeIcon( "/mActionPropertyItem.png" ) );
82  mOpenFormButton->setText( tr( "Open related feature form" ) );
83  editLayout->addWidget( mOpenFormButton );
84 
85  // highlight button
86  mHighlightFeatureButton = new QToolButton( this );
87  mHighlightFeatureButton->setPopupMode( QToolButton::MenuButtonPopup );
88  mHighlightFeatureAction = new QAction( QgsApplication::getThemeIcon( "/mActionHighlightFeature.svg" ), tr( "Highlight feature" ), this );
89  mScaleHighlightFeatureAction = new QAction( QgsApplication::getThemeIcon( "/mActionScaleHighlightFeature.svg" ), tr( "Scale and highlight feature" ), this );
90  mPanHighlightFeatureAction = new QAction( QgsApplication::getThemeIcon( "/mActionPanHighlightFeature.svg" ), tr( "Pan and highlight feature" ), this );
91  mHighlightFeatureButton->addAction( mHighlightFeatureAction );
92  mHighlightFeatureButton->addAction( mScaleHighlightFeatureAction );
93  mHighlightFeatureButton->addAction( mPanHighlightFeatureAction );
94  mHighlightFeatureButton->setDefaultAction( mHighlightFeatureAction );
95  editLayout->addWidget( mHighlightFeatureButton );
96 
97  // map identification button
98  mMapIdentificationButton = new QToolButton( this );
99  mMapIdentificationButton->setIcon( QgsApplication::getThemeIcon( "/mActionMapIdentification.svg" ) );
100  mMapIdentificationButton->setText( tr( "Select on map" ) );
101  mMapIdentificationButton->setCheckable( true );
102  editLayout->addWidget( mMapIdentificationButton );
103 
104  // remove foreign key button
105  mRemoveFKButton = new QToolButton( this );
106  mRemoveFKButton->setIcon( QgsApplication::getThemeIcon( "/mActionRemove.svg" ) );
107  mRemoveFKButton->setText( tr( "No selection" ) );
108  editLayout->addWidget( mRemoveFKButton );
109 
110  // spacer
111  editLayout->addItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding ) );
112 
113  // add line to top layout
114  mTopLayout->addLayout( editLayout );
115 
116  // embed form
117  mAttributeEditorFrame = new QgsCollapsibleGroupBox( this );
118  mAttributeEditorLayout = new QVBoxLayout( mAttributeEditorFrame );
119  mAttributeEditorFrame->setLayout( mAttributeEditorLayout );
120  mAttributeEditorFrame->setSizePolicy( mAttributeEditorFrame->sizePolicy().horizontalPolicy(), QSizePolicy::Expanding );
121  mTopLayout->addWidget( mAttributeEditorFrame );
122 
123  // invalid label
124  mInvalidLabel = new QLabel( tr( "The relation is not valid. Please make sure your relation definitions are ok." ) );
125  mInvalidLabel->setWordWrap( true );
126  QFont font = mInvalidLabel->font();
127  font.setItalic( true );
128  mInvalidLabel->setStyleSheet( "QLabel { color: red; } " );
129  mInvalidLabel->setFont( font );
130  mTopLayout->addWidget( mInvalidLabel );
131 
132  // default mode is combobox, no geometric relation and no embed form
133  mLineEdit->hide();
134  mMapIdentificationButton->hide();
135  mHighlightFeatureButton->hide();
136  mAttributeEditorFrame->hide();
137  mInvalidLabel->hide();
138 
139  // connect buttons
140  connect( mOpenFormButton, SIGNAL( clicked() ), this, SLOT( openForm() ) );
141  connect( mHighlightFeatureButton, SIGNAL( triggered( QAction* ) ), this, SLOT( highlightActionTriggered( QAction* ) ) );
142  connect( mMapIdentificationButton, SIGNAL( clicked() ), this, SLOT( mapIdentification() ) );
143  connect( mRemoveFKButton, SIGNAL( clicked() ), this, SLOT( deleteForeignKey() ) );
144 }
145 
147 {
148  deleteHighlight();
149  unsetMapTool();
150  if ( mMapTool )
151  delete mMapTool;
152 }
153 
154 void QgsRelationReferenceWidget::setRelation( QgsRelation relation, bool allowNullValue )
155 {
156  mAllowNull = allowNullValue;
157  mRemoveFKButton->setVisible( allowNullValue && mReadOnlySelector );
158 
159  if ( relation.isValid() )
160  {
161  mInvalidLabel->hide();
162 
163  mRelation = relation;
164  mReferencingLayer = relation.referencingLayer();
165  mRelationName = relation.name();
166  mReferencedLayer = relation.referencedLayer();
167  mFkeyFieldIdx = mReferencedLayer->fieldNameIndex( relation.fieldPairs().first().second );
168 
170 
171  if ( mEmbedForm )
172  {
173  mAttributeEditorFrame->setTitle( mReferencedLayer->name() );
174  mReferencedAttributeForm = new QgsAttributeForm( relation.referencedLayer(), QgsFeature(), context, this );
175  mReferencedAttributeForm->hideButtonBox();
176  mAttributeEditorLayout->addWidget( mReferencedAttributeForm );
177  }
178  }
179  else
180  {
181  mInvalidLabel->show();
182  }
183 
184  if ( mShown && isVisible() )
185  {
186  init();
187  }
188 }
189 
191 {
192  if ( !editable )
193  unsetMapTool();
194 
195  mComboBox->setEnabled( editable );
196  mMapIdentificationButton->setEnabled( editable );
197  mRemoveFKButton->setEnabled( editable );
198  mIsEditable = editable;
199 }
200 
201 void QgsRelationReferenceWidget::setForeignKey( const QVariant& value )
202 {
203  if ( !value.isValid() || value.isNull() )
204  {
206  return;
207  }
208 
209  QgsFeature f;
210  if ( !mReferencedLayer )
211  return;
212 
213  // TODO: Rewrite using expression
214  QgsFeatureIterator fit = mReferencedLayer->getFeatures( QgsFeatureRequest() );
215  while ( fit.nextFeature( f ) )
216  {
217  if ( f.attribute( mFkeyFieldIdx ) == value )
218  {
219  break;
220  }
221  }
222 
223  if ( !f.isValid() )
224  {
226  return;
227  }
228 
229  mForeignKey = f.attribute( mFkeyFieldIdx );
230 
231  if ( mReadOnlySelector )
232  {
233  QgsExpression expr( mReferencedLayer->displayExpression() );
234  QString title = expr.evaluate( &f ).toString();
235  if ( expr.hasEvalError() )
236  {
237  title = f.attribute( mFkeyFieldIdx ).toString();
238  }
239  mLineEdit->setText( title );
240  mFeatureId = f.id();
241  }
242  else
243  {
244  int i = mComboBox->findData( value );
245  if ( i == -1 && mAllowNull )
246  {
247  mComboBox->setCurrentIndex( 0 );
248  }
249  else
250  {
251  mComboBox->setCurrentIndex( i );
252  }
253  }
254 
255  mRemoveFKButton->setEnabled( mIsEditable );
256  highlightFeature( f );
257  updateAttributeEditorFrame( f );
258  emit foreignKeyChanged( foreignKey() );
259 }
260 
262 {
263  QVariant nullValue = QSettings().value( "qgis/nullValue", "NULL" );
264  if ( mReadOnlySelector )
265  {
266  QString nullText = "";
267  if ( mAllowNull )
268  {
269  nullText = tr( "%1 (no selection)" ).arg( nullValue.toString() );
270  }
271  mLineEdit->setText( nullText );
272  mForeignKey = QVariant();
273  mFeatureId = QgsFeatureId();
274  }
275  else
276  {
277  if ( mAllowNull )
278  {
279  mComboBox->setCurrentIndex( 0 );
280  }
281  else
282  {
283  mComboBox->setCurrentIndex( -1 );
284  }
285  }
286  mRemoveFKButton->setEnabled( false );
287  updateAttributeEditorFrame( QgsFeature() );
288  emit foreignKeyChanged( QVariant( QVariant::Int ) );
289 }
290 
292 {
293  QgsFeature f;
294  if ( mReferencedLayer )
295  {
296  QgsFeatureId fid;
297  if ( mReadOnlySelector )
298  {
299  fid = mFeatureId;
300  }
301  else
302  {
303  fid = mComboBox->itemData( mComboBox->currentIndex() ).value<QgsFeatureId>();
304  }
305  mReferencedLayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( f );
306  }
307  return f;
308 }
309 
311 {
312  if ( mReadOnlySelector )
313  {
314  return mForeignKey;
315  }
316  else
317  {
318  QVariant varFid = mComboBox->itemData( mComboBox->currentIndex() );
319  if ( varFid.isNull() )
320  {
321  return QVariant();
322  }
323  else
324  {
325  return mFidFkMap.value( varFid.value<QgsFeatureId>() );
326  }
327  }
328 }
329 
331 {
332  mEditorContext = context;
333  mCanvas = canvas;
334  mMessageBar = messageBar;
335 
336  if ( mMapTool )
337  delete mMapTool;
338  mMapTool = new QgsMapToolIdentifyFeature( mCanvas );
339  mMapTool->setAction( mMapIdentificationButton->defaultAction() );
340 }
341 
343 {
344  mAttributeEditorFrame->setVisible( display );
345  mEmbedForm = display;
346 }
347 
349 {
350  mComboBox->setHidden( readOnly );
351  mLineEdit->setVisible( readOnly );
352  mRemoveFKButton->setVisible( mAllowNull && readOnly );
353  mReadOnlySelector = readOnly;
354 }
355 
356 void QgsRelationReferenceWidget::setAllowMapIdentification( bool allowMapIdentification )
357 {
358  mHighlightFeatureButton->setVisible( allowMapIdentification );
359  mMapIdentificationButton->setVisible( allowMapIdentification );
360  mAllowMapIdentification = allowMapIdentification;
361 }
362 
364 {
365  mOpenFormButton->setVisible( openFormButtonVisible );
366  mOpenFormButtonVisible = openFormButtonVisible;
367 }
368 
370 {
371  Q_UNUSED( e )
372 
373  mShown = true;
374 
375  init();
376 }
377 
379 {
380  if ( !mReadOnlySelector && mComboBox->count() == 0 && mReferencedLayer )
381  {
382  QApplication::setOverrideCursor( Qt::WaitCursor );
383  if ( mAllowNull )
384  {
385  const QString nullValue = QSettings().value( "qgis/nullValue", "NULL" ).toString();
386 
387  mComboBox->addItem( tr( "%1 (no selection)" ).arg( nullValue ), QVariant( QVariant::Int ) );
388  mComboBox->setItemData( 0, QColor( Qt::gray ), Qt::ForegroundRole );
389  }
390 
391  QgsExpression exp( mReferencedLayer->displayExpression() );
392 
393  QStringList attrs = exp.referencedColumns();
394  attrs << mRelation.fieldPairs().first().second;
395 
396  QgsFeatureIterator fit = mReferencedLayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( attrs, mReferencedLayer->pendingFields() ) );
397 
398  exp.prepare( mReferencedLayer->pendingFields() );
399 
400  QgsFeature f;
401  while ( fit.nextFeature( f ) )
402  {
403  QString txt = exp.evaluate( &f ).toString();
404  mComboBox->addItem( txt, f.id() );
405 
406  if ( f.attribute( mFkeyFieldIdx ) == mForeignKey )
407  mComboBox->setCurrentIndex( mComboBox->count() - 1 );
408 
409  mFidFkMap.insert( f.id(), f.attribute( mFkeyFieldIdx ) );
410  }
411 
412  // Only connect after iterating, to have only one iterator on the referenced table at once
413  connect( mComboBox, SIGNAL( activated( int ) ), this, SLOT( comboReferenceChanged( int ) ) );
414  QApplication::restoreOverrideCursor();
415  }
416 }
417 
418 void QgsRelationReferenceWidget::highlightActionTriggered( QAction* action )
419 {
420  if ( action == mHighlightFeatureAction )
421  {
422  highlightFeature();
423  }
424  else if ( action == mScaleHighlightFeatureAction )
425  {
426  highlightFeature( QgsFeature(), Scale );
427  }
428  else if ( action == mPanHighlightFeatureAction )
429  {
430  highlightFeature( QgsFeature(), Pan );
431  }
432 }
433 
435 {
436  QgsFeature feat = referencedFeature();
437 
438  if ( !feat.isValid() )
439  return;
440 
442  QgsAttributeDialog attributeDialog( mReferencedLayer, new QgsFeature( feat ), true, this, true, context );
443  attributeDialog.exec();
444 }
445 
446 void QgsRelationReferenceWidget::highlightFeature( QgsFeature f, CanvasExtent canvasExtent )
447 {
448  if ( !mCanvas )
449  return;
450 
451  if ( !f.isValid() )
452  {
453  f = referencedFeature();
454  if ( !f.isValid() )
455  return;
456  }
457 
458  QgsGeometry* geom = f.geometry();
459  if ( !geom )
460  {
461  return;
462  }
463 
464  // scale or pan
465  if ( canvasExtent == Scale )
466  {
467  QgsRectangle featBBox = geom->boundingBox();
468  featBBox = mCanvas->mapSettings().layerToMapCoordinates( mReferencedLayer, featBBox );
469  QgsRectangle extent = mCanvas->extent();
470  if ( !extent.contains( featBBox ) )
471  {
472  extent.combineExtentWith( &featBBox );
473  extent.scale( 1.1 );
474  mCanvas->setExtent( extent );
475  mCanvas->refresh();
476  }
477  }
478  else if ( canvasExtent == Pan )
479  {
480  QgsPoint center = geom->centroid()->asPoint();
481  center = mCanvas->mapSettings().layerToMapCoordinates( mReferencedLayer, center );
482  mCanvas->zoomByFactor( 1.0, &center ); // refresh is done in this method
483  }
484 
485  // highlight
486  deleteHighlight();
487  mHighlight = new QgsHighlight( mCanvas, f, mReferencedLayer );
488  QSettings settings;
489  QColor color = QColor( settings.value( "/Map/highlight/color", QGis::DEFAULT_HIGHLIGHT_COLOR.name() ).toString() );
490  int alpha = settings.value( "/Map/highlight/colorAlpha", QGis::DEFAULT_HIGHLIGHT_COLOR.alpha() ).toInt();
491  double buffer = settings.value( "/Map/highlight/buffer", QGis::DEFAULT_HIGHLIGHT_BUFFER_MM ).toDouble();
492  double minWidth = settings.value( "/Map/highlight/minWidth", QGis::DEFAULT_HIGHLIGHT_MIN_WIDTH_MM ).toDouble();
493 
494  mHighlight->setColor( color ); // sets also fill with default alpha
495  color.setAlpha( alpha );
496  mHighlight->setFillColor( color ); // sets fill with alpha
497  mHighlight->setBuffer( buffer );
498  mHighlight->setMinWidth( minWidth );
499  mHighlight->show();
500 
501  QTimer* timer = new QTimer( this );
502  timer->setSingleShot( true );
503  connect( timer, SIGNAL( timeout() ), this, SLOT( deleteHighlight() ) );
504  timer->start( 3000 );
505 }
506 
507 void QgsRelationReferenceWidget::deleteHighlight()
508 {
509  if ( mHighlight )
510  {
511  mHighlight->hide();
512  delete mHighlight;
513  }
514  mHighlight = NULL;
515 }
516 
518 {
519  if ( !mAllowMapIdentification || !mReferencedLayer )
520  return;
521 
522  const QgsVectorLayerTools* tools = mEditorContext.vectorLayerTools();
523  if ( !tools )
524  return;
525  if ( !mCanvas )
526  return;
527 
528  mMapTool->setLayer( mReferencedLayer );
529  mCanvas->setMapTool( mMapTool );
530 
531  mWindowWidget = window();
532 
533  mCanvas->window()->raise();
534  mCanvas->activateWindow();
535 
536  connect( mMapTool, SIGNAL( featureIdentified( QgsFeature ) ), this, SLOT( featureIdentified( const QgsFeature ) ) );
537  connect( mMapTool, SIGNAL( deactivated() ), this, SLOT( mapToolDeactivated() ) );
538 
539  if ( mMessageBar )
540  {
541  QString title = QString( "Relation %1 for %2." ).arg( mRelationName ).arg( mReferencingLayer->name() );
542  QString msg = tr( "Identify a feature of %1 to be associated. Press <ESC> to cancel." ).arg( mReferencedLayer->name() );
543  mMessageBarItem = QgsMessageBar::createMessage( title, msg, this );
544  mMessageBar->pushItem( mMessageBarItem );
545  }
546 }
547 
548 void QgsRelationReferenceWidget::comboReferenceChanged( int index )
549 {
550  QgsFeatureId fid = mComboBox->itemData( index ).value<QgsFeatureId>();
551  QgsFeature feat;
552  mReferencedLayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( feat );
553  highlightFeature( feat );
554  updateAttributeEditorFrame( feat );
555  emit foreignKeyChanged( mFidFkMap.value( fid ) );
556 }
557 
558 void QgsRelationReferenceWidget::updateAttributeEditorFrame( const QgsFeature feature )
559 {
560  // Check if we're running with an embedded frame we need to update
561  if ( mAttributeEditorFrame )
562  {
563  if ( feature.isValid() && mReferencedAttributeForm )
564  {
565  mReferencedAttributeForm->setFeature( feature );
566  }
567  }
568 }
569 
570 void QgsRelationReferenceWidget::featureIdentified( const QgsFeature& feature )
571 {
572  if ( mReadOnlySelector )
573  {
574  QgsExpression expr( mReferencedLayer->displayExpression() );
575  QString title = expr.evaluate( &feature ).toString();
576  if ( expr.hasEvalError() )
577  {
578  title = feature.attribute( mFkeyFieldIdx ).toString();
579  }
580  mLineEdit->setText( title );
581  mForeignKey = feature.attribute( mFkeyFieldIdx );
582  mFeatureId = feature.id();
583  }
584  else
585  {
586  mComboBox->setCurrentIndex( mComboBox->findData( feature.attribute( mFkeyFieldIdx ) ) );
587  }
588 
589  mRemoveFKButton->setEnabled( mIsEditable );
590  highlightFeature( feature );
591  updateAttributeEditorFrame( feature );
592  emit foreignKeyChanged( foreignKey() );
593 
594  unsetMapTool();
595 }
596 
597 void QgsRelationReferenceWidget::unsetMapTool()
598 {
599  // deactivate map tool if activated
600  if ( mCanvas && mMapTool )
601  {
602  /* this will call mapToolDeactivated */
603  mCanvas->unsetMapTool( mMapTool );
604  }
605 }
606 
607 void QgsRelationReferenceWidget::mapToolDeactivated()
608 {
609  if ( mWindowWidget )
610  {
611  mWindowWidget->raise();
612  mWindowWidget->activateWindow();
613  }
614 
615  if ( mMessageBar && mMessageBarItem )
616  {
617  mMessageBar->popWidget( mMessageBarItem );
618  }
619  mMessageBarItem = NULL;
620 }
621 
void unsetMapTool(QgsMapTool *mapTool)
Unset the current map tool or last non zoom tool.
QgsFeatureId id() const
Get the feature id for this feature.
Definition: qgsfeature.cpp:100
Methods in this class are used to handle basic operations on vector layers.
When showing a single feature (e.g. district information when looking at the form of a house) ...
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:87
Wrapper for iterator of features from vector data provider or vector layer.
bool isValid() const
Returns the validity of this relation.
static unsigned index
static double DEFAULT_HIGHLIGHT_BUFFER_MM
Default highlight buffer in mm.
Definition: qgis.h:282
const QString name() const
A rectangle specified with double values.
Definition: qgsrectangle.h:35
static const QColor DEFAULT_HIGHLIGHT_COLOR
Default highlight color.
Definition: qgis.h:278
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer's CRS to output CRS
void zoomByFactor(double scaleFactor, const QgsPoint *center=0)
Zoom with the factor supplied.
void setLayer(QgsVectorLayer *vl)
change the layer used by the map tool to identify
bool isValid() const
Return the validity of this feature.
Definition: qgsfeature.cpp:171
void foreignKeyChanged(QVariant)
void hideButtonBox()
Hides the button box (Ok/Cancel) and enables auto-commit.
QVariant evaluate(const QgsFeature *f=NULL)
Evaluate the feature and return the result.
A groupbox that collapses/expands when toggled and can save its collapsed and checked states...
void deleteForeignKey()
unset the currently related feature
This class contains context information for attribute editor widgets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
void setOpenFormButtonVisible(bool openFormButtonVisible)
void setExtent(const QgsRectangle &r)
Set the extent of the map canvas.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
Definition: qgsfeature.cpp:112
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
void setFillColor(const QColor &fillColor)
Set polygons fill color.
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:42
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
QgsVectorLayer * referencedLayer() const
Access the referenced (parent) layer.
void refresh()
Repaints the canvas map.
QVariant foreignKey()
returns the related feature foreign key
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
const QString displayExpression()
Get the preview expression, used to create a human readable preview string.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
void setAllowMapIdentification(bool allowMapIdentification)
bool allowMapIdentification()
determines if the widge offers the possibility to select the related feature on the map (using a dedi...
QgsGeometry * centroid()
Returns the center of mass of a geometry.
void setForeignKey(const QVariant &value)
this sets the related feature using from the foreign key
void setMapTool(QgsMapTool *mapTool)
Sets the map tool currently being used on the canvas.
void setBuffer(double buffer)
Set line / outline buffer in millimeters.
Definition: qgshighlight.h:63
const QString & name() const
Get the display name of the layer.
void combineExtentWith(QgsRectangle *rect)
expand the rectangle so that covers both the original rectangle and the given rectangle ...
static QgsMessageBarItem * createMessage(const QString &text, QWidget *parent=0)
make out a widget containing a message to be displayed on the bar
void setFeature(const QgsFeature &feature)
Update all editors to correspond to a different feature.
bool popWidget(QgsMessageBarItem *item)
void setAction(QAction *action)
Use this to associate a QAction to this maptool.
Definition: qgsmaptool.cpp:103
QgsVectorLayer * referencingLayer() const
Access the referencing (child) layer This is the layer which has the field(s) which point to another ...
void setEditorContext(QgsAttributeEditorContext context, QgsMapCanvas *canvas, QgsMessageBar *messageBar)
QStringList referencedColumns()
Get list of columns referenced by the expression.
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)...
void setRelation(QgsRelation relation, bool allowNullValue)
A class to represent a point.
Definition: qgspoint.h:63
The QgsMapToolIdentifyFeature class is a map tool to identify a feature on a chosen layer...
QgsRectangle boundingBox()
Returns the bounding box of this feature.
virtual void showEvent(QShowEvent *e)
void pushItem(QgsMessageBarItem *item)
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:230
void setColor(const QColor &color)
Set line/outline to color, polygon fill to color with alpha = 63.
QgsFeature referencedFeature()
return the related feature (from the referenced layer) if no feature is related, it returns an invali...
const QgsVectorLayerTools * vectorLayerTools() const
QList< FieldPair > fieldPairs() const
Returns the field pairs which form this relation The first element of each pair are the field names f...
qint64 QgsFeatureId
Definition: qgsfeature.h:30
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QgsPoint asPoint() const
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
void mapIdentification()
activate the map tool to select a new related feature on the map
static double DEFAULT_HIGHLIGHT_MIN_WIDTH_MM
Default highlight line/outline minimum width in mm.
Definition: qgis.h:286
bool openFormButtonVisible()
determines the open form button is visible in the widget
void openForm()
open the form of the related feature in a new dialog
A form was embedded as a widget on another form.
void setMinWidth(double width)
Set minimum line / outline width in millimeters.
Definition: qgshighlight.h:67
#define tr(sourceText)
void scale(double scaleFactor, const QgsPoint *c=0)
Scale the rectangle around its center point.