19#include "moc_qgsattributetypeloaddialog.cpp"
29#include <QTableWidgetItem>
47 layerComboBox->setCurrentIndex( -1 );
51 connect( keyComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index ) { createPreview( index ); } );
52 connect( valueComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index ) { createPreview( index ); } );
53 connect( previewButton, &QAbstractButton::pressed,
this, &QgsAttributeTypeLoadDialog::previewButtonPushed );
54 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, [ = ]
56 QgsHelp::openHelp( QStringLiteral(
"working_with_vector/vector_properties.html#edit-widgets" ) );
67void QgsAttributeTypeLoadDialog::previewButtonPushed()
69 createPreview( valueComboBox->currentIndex(),
true );
72void QgsAttributeTypeLoadDialog::createPreview(
int fieldIndex,
bool full )
74 previewTableWidget->clearContents();
76 for (
int i = previewTableWidget->rowCount() - 1; i > 0; i-- )
78 previewTableWidget->removeRow( i );
80 if ( layerComboBox->currentIndex() < 0 || fieldIndex < 0 )
85 const int idx = keyComboBox->currentIndex();
86 const int idx2 = valueComboBox->currentIndex();
87 QgsMapLayer *dataLayer = layerComboBox->currentLayer();
88 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
93 attributeList.append( idx );
94 attributeList.append( idx2 );
102 const QVariant val1 = f.
attribute( idx );
103 const QVariant val2 = f.
attribute( idx2 );
107 valueMap.insert( val1.toString(), val2.toString() );
113 for ( QMap<QString, QVariant>::iterator mit =
valueMap.begin(); mit !=
valueMap.end(); ++mit, row++ )
115 previewTableWidget->insertRow( row );
116 previewTableWidget->setItem( row, 0,
new QTableWidgetItem( mit.value().toString() ) );
117 previewTableWidget->setItem( row, 1,
new QTableWidgetItem( mit.key() ) );
128 return nullCheckBox->isChecked();
131void QgsAttributeTypeLoadDialog::loadDataToValueMap()
134 const int idx = keyComboBox->currentIndex();
135 const int idx2 = valueComboBox->currentIndex();
136 QgsMapLayer *dataLayer = layerComboBox->currentLayer();
137 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
142 attributeList.append( idx );
143 attributeList.append( idx2 );
153 mValueMap.insert( f.
attribute( idx2 ).toString(), val );
161 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.
This class 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 data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const FINAL
Queries the layer for features specified in request.
QList< int > QgsAttributeList