37#include <QTableWidgetItem>
39#include "moc_qgsattributetypeloaddialog.cpp"
48 layerComboBox->setCurrentIndex( -1 );
52 connect( keyComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) { createPreview( index ); } );
53 connect( valueComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) { createPreview( index ); } );
54 connect( previewButton, &QAbstractButton::pressed,
this, &QgsAttributeTypeLoadDialog::previewButtonPushed );
55 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, [] {
56 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#edit-widgets" ) );
65void QgsAttributeTypeLoadDialog::previewButtonPushed()
67 createPreview( valueComboBox->currentIndex(),
true );
70void QgsAttributeTypeLoadDialog::createPreview(
int fieldIndex,
bool full )
72 previewTableWidget->clearContents();
74 for (
int i = previewTableWidget->rowCount() - 1; i > 0; i-- )
76 previewTableWidget->removeRow( i );
78 if ( layerComboBox->currentIndex() < 0 || fieldIndex < 0 )
83 const int idx = keyComboBox->currentIndex();
84 const int idx2 = valueComboBox->currentIndex();
85 QgsMapLayer *dataLayer = layerComboBox->currentLayer();
86 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
91 attributeList.append( idx );
92 attributeList.append( idx2 );
100 const QVariant val1 = f.
attribute( idx );
101 const QVariant val2 = f.
attribute( idx2 );
105 valueMap.insert( val1.toString(), val2.toString() );
111 for ( QMap<QString, QVariant>::iterator mit =
valueMap.begin(); mit !=
valueMap.end(); ++mit, row++ )
113 previewTableWidget->insertRow( row );
114 previewTableWidget->setItem( row, 0,
new QTableWidgetItem( mit.value().toString() ) );
115 previewTableWidget->setItem( row, 1,
new QTableWidgetItem( mit.key() ) );
126 return nullCheckBox->isChecked();
129void QgsAttributeTypeLoadDialog::loadDataToValueMap()
132 const int idx = keyComboBox->currentIndex();
133 const int idx2 = valueComboBox->currentIndex();
134 QgsMapLayer *dataLayer = layerComboBox->currentLayer();
135 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
140 attributeList.append( idx );
141 attributeList.append( idx2 );
151 mValueMap.insert( f.
attribute( idx2 ).toString(), val );
159 loadDataToValueMap();
@ NoGeometry
Geometry is not required. It may still be returned if e.g. required for a filter condition.
void accept() override
Overloaded accept method which will write the feature field values, then delegate to QDialog::accept(...
QgsAttributeTypeLoadDialog(QgsVectorLayer *vl)
bool insertNull()
Returns true if the "Add NULL value" checkbox has been checked.
QMap< QString, QVariant > & valueMap()
Returns the value map which is currently active.
void setVectorLayer(QgsVectorLayer *layer)
Sets predefined vector layer for selection of data.
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
Wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
void setLayer(QgsMapLayer *layer)
Sets the layer for which fields are listed in the combobox.
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...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
void layerChanged(QgsMapLayer *layer)
Emitted whenever the currently selected layer changes.
Base class for all map layer types.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based dataset.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const final
Queries the layer for features specified in request.
QList< int > QgsAttributeList