26#include <QTableWidgetItem>
42 connect( layerComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsAttributeTypeLoadDialog::fillComboBoxes );
43 connect( keyComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index ) { createPreview( index ); } );
44 connect( valueComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index ) { createPreview( index ); } );
45 connect( previewButton, &QAbstractButton::pressed,
this, &QgsAttributeTypeLoadDialog::previewButtonPushed );
49 keyComboBox->setDisabled(
true );
50 valueComboBox->setDisabled(
true );
58void QgsAttributeTypeLoadDialog::previewButtonPushed()
60 createPreview( valueComboBox->currentIndex(),
true );
63void QgsAttributeTypeLoadDialog::fillLayerList()
65 layerComboBox->blockSignals(
true );
66 layerComboBox->clear();
72 layerComboBox->addItem( vl->
name(), vl->
id() );
74 layerComboBox->setCurrentIndex( -1 );
75 layerComboBox->blockSignals(
false );
78void QgsAttributeTypeLoadDialog::fillComboBoxes(
int layerIndex )
80 keyComboBox->blockSignals(
true );
81 valueComboBox->blockSignals(
true );
85 valueComboBox->clear();
87 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layerIndex < 0 ?
nullptr :
QgsProject::instance()->mapLayer( layerComboBox->itemData( layerIndex ).toString() ) );
91 QMap<QString, int>::iterator it = fieldMap.begin();
92 for ( ; it != fieldMap.end(); ++it )
94 keyComboBox->addItem( it.key(), it.value() );
95 valueComboBox->addItem( it.key(), it.value() );
99 keyComboBox->setEnabled(
nullptr != vLayer );
100 valueComboBox->setEnabled(
nullptr != vLayer );
102 keyComboBox->setCurrentIndex( -1 );
103 valueComboBox->setCurrentIndex( -1 );
105 keyComboBox->blockSignals(
false );
106 valueComboBox->blockSignals(
false );
109void QgsAttributeTypeLoadDialog::createPreview(
int fieldIndex,
bool full )
111 previewTableWidget->clearContents();
113 for (
int i = previewTableWidget->rowCount() - 1; i > 0; i-- )
115 previewTableWidget->removeRow( i );
117 if ( layerComboBox->currentIndex() < 0 || fieldIndex < 0 )
122 const int idx = keyComboBox->currentData().toInt();
123 const int idx2 = valueComboBox->currentData().toInt();
125 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
130 attributeList.append( idx );
131 attributeList.append( idx2 );
139 const QVariant val1 = f.
attribute( idx );
140 const QVariant val2 = f.
attribute( idx2 );
144 valueMap.insert( val1.toString(), val2.toString() );
150 for ( QMap<QString, QVariant>::iterator mit =
valueMap.begin(); mit !=
valueMap.end(); ++mit, row++ )
152 previewTableWidget->insertRow( row );
153 previewTableWidget->setItem( row, 0,
new QTableWidgetItem( mit.value().toString() ) );
154 previewTableWidget->setItem( row, 1,
new QTableWidgetItem( mit.key() ) );
165 return nullCheckBox->isChecked();
168void QgsAttributeTypeLoadDialog::loadDataToValueMap()
171 const int idx = keyComboBox->currentData().toInt();
172 const int idx2 = valueComboBox->currentData().toInt();
174 QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
179 attributeList.append( idx );
180 attributeList.append( idx2 );
190 mValueMap.insert( f.
attribute( idx2 ).toString(), val );
198 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...
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
Base class for all map layer types.
QString id() const
Returns the layer's unique ID, which is used to access this layer from QgsProject.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
static QgsProject * instance()
Returns the QgsProject singleton instance.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
QMap< QString, int > fieldNameMap() const
Returns a map where the key is the name of the field and the value is its index.
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.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
QList< int > QgsAttributeList