QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 #include <QPushButton>
24 
26  : QDialog( parent )
27  , mLayer( layer )
28 {
29  setupUi( this );
30 
31  const QgsFields fields = mLayer->fields();
32  for ( const QgsField &field : fields )
33  comboBox->addItem( field.name() );
34 
35  if ( fields.isEmpty() )
36  {
37  buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
38  }
39 }
40 
42 {
43  const int idx = mLayer->fields().lookupField( comboBox->currentText() );
44 
45  if ( idx >= 0 )
46  {
47  const QgsField field = mLayer->fields().field( idx );
49 
50  if ( alayer )
51  {
52  mLayer->setAuxiliaryLayer( alayer );
53  }
54  }
55 
56  QDialog::accept();
57 }
int lookupField(const QString &fieldName) const
Looks up field&#39;s index from the field name.
Definition: qgsfields.cpp:324
const QgsAuxiliaryStorage * auxiliaryStorage() const
Returns the current const auxiliary storage.
Class allowing to manage the auxiliary storage for a vector layer.
Container of fields for a vector layer.
Definition: qgsfields.h:42
void setAuxiliaryLayer(QgsAuxiliaryLayer *layer=nullptr)
Sets the current auxiliary layer.
QgsFields fields() const FINAL
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:438
Represents a vector layer which manages a vector based data sets.
QgsField field(int fieldIdx) const
Gets field at particular index (must be in range 0..N-1)
Definition: qgsfields.cpp:168
QgsAuxiliaryLayer * createAuxiliaryLayer(const QgsField &field, QgsVectorLayer *layer) const
Creates an auxiliary layer for a vector layer.