QGIS API Documentation 3.41.0-Master (d5b93354e9c)
Loading...
Searching...
No Matches
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
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 "moc_qgsnewauxiliarylayerdialog.cpp"
20#include "qgsauxiliarystorage.h"
21#include "qgsproject.h"
22#include "qgsgui.h"
23
24#include <QMessageBox>
25#include <QPushButton>
26
28 : QDialog( parent )
29 , mLayer( layer )
30{
31 setupUi( this );
33
34 const QgsFields fields = mLayer->fields();
35 for ( const QgsField &field : fields )
36 comboBox->addItem( field.name() );
37
38 if ( fields.isEmpty() )
39 {
40 buttonBox->button( QDialogButtonBox::Ok )->setDisabled( true );
41 }
42}
43
45{
46 const int idx = mLayer->fields().lookupField( comboBox->currentText() );
47
48 if ( idx >= 0 )
49 {
50 const QgsField field = mLayer->fields().field( idx );
52
53 if ( alayer )
54 {
55 mLayer->setAuxiliaryLayer( alayer );
56 }
57 else
58 {
59 QDialog::close();
60 const QString errMsg = QgsProject::instance()->auxiliaryStorage()->errorString();
61 QMessageBox::critical( this, tr( "New Auxiliary Layer" ), errMsg );
62 return;
63 }
64 }
65
66 QDialog::accept();
67}
Class allowing to manage the auxiliary storage for a vector layer.
QString errorString() const
Returns the underlying error string describing potential errors happening in saveAs().
QgsAuxiliaryLayer * createAuxiliaryLayer(const QgsField &field, QgsVectorLayer *layer) const
Creates an auxiliary layer for a vector layer.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:53
Container of fields for a vector layer.
Definition qgsfields.h:46
bool isEmpty
Definition qgsfields.h:49
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
Q_INVOKABLE int lookupField(const QString &fieldName) const
Looks up field's index from the field name.
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:210
QgsNewAuxiliaryLayerDialog(QgsVectorLayer *layer, QWidget *parent=nullptr)
Constructor.
static QgsProject * instance()
Returns the QgsProject singleton instance.
const QgsAuxiliaryStorage * auxiliaryStorage() const
Returns the current const auxiliary storage.
Represents a vector layer which manages a vector based data sets.
void setAuxiliaryLayer(QgsAuxiliaryLayer *layer=nullptr)
Sets the current auxiliary layer.