QGIS API Documentation  3.0.2-Girona (307d082)
qgsnewauxiliarylayerdialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsnewauxiliarylayerdialog.cpp - description
3  -------------------
4  begin : Aug 28, 2017
5  copyright : (C) 2017 by Paul Blottiere
6  email : [email protected]
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 
19 #include "qgsproject.h"
20 #include "qgsauxiliarystorage.h"
21 
22 #include <QMessageBox>
23 
25  : QDialog( parent )
26  , mLayer( layer )
27 {
28  setupUi( this );
29 
30  for ( const QgsField &field : mLayer->fields() )
31  comboBox->addItem( field.name() );
32 }
33 
35 {
36  const int idx = mLayer->fields().lookupField( comboBox->currentText() );
37 
38  if ( idx >= 0 )
39  {
40  const QgsField field = mLayer->fields().field( idx );
42 
43  if ( alayer )
44  {
45  mLayer->setAuxiliaryLayer( alayer );
46  }
47  }
48 
49  QDialog::accept();
50 }
int lookupField(const QString &fieldName) const
Look up field&#39;s index from the field name.
Definition: qgsfields.cpp:299
const QgsAuxiliaryStorage * auxiliaryStorage() const
Returns the current const auxiliary storage.
Class allowing to manage the auxiliary storage for a vector layer.
void setAuxiliaryLayer(QgsAuxiliaryLayer *layer=nullptr)
Sets the current auxiliary layer.
QgsFields fields() const override
Returns the list of fields of this layer.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
QgsNewAuxiliaryLayerDialog(QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:383
Represents a vector layer which manages a vector based data sets.
QgsField field(int fieldIdx) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:150
QgsAuxiliaryLayer * createAuxiliaryLayer(const QgsField &field, QgsVectorLayer *layer) const
Creates an auxiliary layer for a vector layer.