QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgsauxiliarystorage.h"
20 #include "qgsproject.h"
21 #include "qgsgui.h"
22 
23 #include <QMessageBox>
24 #include <QPushButton>
25 
27  : QDialog( parent )
28  , mLayer( layer )
29 {
30  setupUi( this );
32 
33  const QgsFields fields = mLayer->fields();
34  for ( const QgsField &field : fields )
35  comboBox->addItem( field.name() );
36 
37  if ( fields.isEmpty() )
38  {
39  buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
40  }
41 }
42 
44 {
45  const int idx = mLayer->fields().lookupField( comboBox->currentText() );
46 
47  if ( idx >= 0 )
48  {
49  const QgsField field = mLayer->fields().field( idx );
51 
52  if ( alayer )
53  {
54  mLayer->setAuxiliaryLayer( alayer );
55  }
56  else
57  {
58  QDialog::close();
59  const QString errMsg = QgsProject::instance()->auxiliaryStorage()->errorString();
60  QMessageBox::critical( this, tr( "New Auxiliary Layer" ), errMsg );
61  return;
62  }
63  }
64 
65  QDialog::accept();
66 }
QgsProject::auxiliaryStorage
const QgsAuxiliaryStorage * auxiliaryStorage() const
Returns the current const auxiliary storage.
Definition: qgsproject.cpp:4045
QgsAuxiliaryLayer
Class allowing to manage the auxiliary storage for a vector layer.
Definition: qgsauxiliarystorage.h:61
qgsgui.h
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:480
field
const QgsField & field
Definition: qgsfield.h:463
QgsVectorLayer::setAuxiliaryLayer
void setAuxiliaryLayer(QgsAuxiliaryLayer *layer=nullptr)
Sets the current auxiliary layer.
Definition: qgsvectorlayer.cpp:5497
QgsField::name
QString name
Definition: qgsfield.h:60
qgsauxiliarystorage.h
QgsAuxiliaryStorage::createAuxiliaryLayer
QgsAuxiliaryLayer * createAuxiliaryLayer(const QgsField &field, QgsVectorLayer *layer) const
Creates an auxiliary layer for a vector layer.
Definition: qgsauxiliarystorage.cpp:652
qgsnewauxiliarylayerdialog.h
QgsGui::enableAutoGeometryRestore
static void enableAutoGeometryRestore(QWidget *widget, const QString &key=QString())
Register the widget to allow its position to be automatically saved and restored when open and closed...
Definition: qgsgui.cpp:180
QgsVectorLayer::fields
QgsFields fields() const FINAL
Returns the list of fields of this layer.
Definition: qgsvectorlayer.cpp:3436
QgsNewAuxiliaryLayerDialog::accept
void accept() override
Definition: qgsnewauxiliarylayerdialog.cpp:43
QgsNewAuxiliaryLayerDialog::QgsNewAuxiliaryLayerDialog
QgsNewAuxiliaryLayerDialog(QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor.
Definition: qgsnewauxiliarylayerdialog.cpp:26
QgsFields::field
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
Definition: qgsfields.cpp:168
QgsNewAuxiliaryLayerDialog::mLayer
QgsVectorLayer * mLayer
Definition: qgsnewauxiliarylayerdialog.h:51
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsAuxiliaryStorage::errorString
QString errorString() const
Returns the underlying error string describing potential errors happening in saveAs().
Definition: qgsauxiliarystorage.cpp:720
QgsFields::lookupField
int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
Definition: qgsfields.cpp:349
qgsproject.h
QgsField
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:50