38#include <QTableWidgetItem>
40#include "moc_qgsattributetypeloaddialog.cpp"
42using namespace Qt::StringLiterals;
51 layerComboBox->setCurrentIndex( -1 );
55 connect( keyComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) { createPreview( index ); } );
56 connect( valueComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) { createPreview( index ); } );
57 connect( previewButton, &QAbstractButton::pressed,
this, &QgsAttributeTypeLoadDialog::previewButtonPushed );
58 connect( buttonBox, &QDialogButtonBox::helpRequested,
this, [] {
59 QgsHelp::openHelp( u
"working_with_vector/vector_properties.html#edit-widgets"_s );
68void QgsAttributeTypeLoadDialog::previewButtonPushed()
70 createPreview( valueComboBox->currentIndex(),
true );
73void QgsAttributeTypeLoadDialog::createPreview(
int fieldIndex,
bool full )
75 previewTableWidget->clearContents();
77 for (
int i = previewTableWidget->rowCount() - 1; i > 0; i-- )
79 previewTableWidget->removeRow( i );
81 if ( layerComboBox->currentIndex() < 0 || fieldIndex < 0 )
86 const int idx = keyComboBox->currentIndex();
87 const int idx2 = valueComboBox->currentIndex();
88 QgsMapLayer *dataLayer = layerComboBox->currentLayer();
89 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
94 attributeList.append( idx );
95 attributeList.append( idx2 );
103 const QVariant val1 = f.
attribute( idx );
104 const QVariant val2 = f.
attribute( idx2 );
108 valueMap.insert( val1.toString(), val2.toString() );
114 for ( QMap<QString, QVariant>::iterator mit =
valueMap.begin(); mit !=
valueMap.end(); ++mit, row++ )
116 previewTableWidget->insertRow( row );
117 previewTableWidget->setItem( row, 0,
new QTableWidgetItem( mit.value().toString() ) );
118 previewTableWidget->setItem( row, 1,
new QTableWidgetItem( mit.key() ) );
129 return nullCheckBox->isChecked();
132void QgsAttributeTypeLoadDialog::loadDataToValueMap()
135 const int idx = keyComboBox->currentIndex();
136 const int idx2 = valueComboBox->currentIndex();
137 QgsMapLayer *dataLayer = layerComboBox->currentLayer();
138 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
143 attributeList.append( idx );
144 attributeList.append( idx2 );
154 mValueMap.insert( f.
attribute( idx2 ).toString(), val );
162 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