27 #include <QTableWidgetItem> 
   34 #include <QPushButton> 
   35 #include <QHBoxLayout> 
   36 #include <QFileDialog> 
   43   connect( layerComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsAttributeTypeLoadDialog::fillComboBoxes );
 
   44   connect( keyComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, [ = ]( 
int index ) { createPreview( index ); } );
 
   45   connect( valueComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, [ = ]( 
int index ) { createPreview( index ); } );
 
   46   connect( previewButton, &QAbstractButton::pressed, 
this, &QgsAttributeTypeLoadDialog::previewButtonPushed );
 
   50   keyComboBox->setDisabled( 
true );
 
   51   valueComboBox->setDisabled( 
true );
 
   59 void QgsAttributeTypeLoadDialog::previewButtonPushed()
 
   61   createPreview( valueComboBox->currentIndex(), 
true );
 
   64 void QgsAttributeTypeLoadDialog::fillLayerList()
 
   66   layerComboBox->blockSignals( 
true );
 
   67   layerComboBox->clear();
 
   73       layerComboBox->addItem( vl->
name(), vl->
id() );
 
   75   layerComboBox->setCurrentIndex( -1 );
 
   76   layerComboBox->blockSignals( 
false );
 
   79 void QgsAttributeTypeLoadDialog::fillComboBoxes( 
int layerIndex )
 
   81   keyComboBox->blockSignals( 
true );
 
   82   valueComboBox->blockSignals( 
true );
 
   86   valueComboBox->clear();
 
   88   QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( layerIndex < 0 ? 
nullptr : 
QgsProject::instance()->mapLayer( layerComboBox->itemData( layerIndex ).toString() ) );
 
   92     QMap<QString, int>::iterator it = fieldMap.begin();
 
   93     for ( ; it != fieldMap.end(); ++it )
 
   95       keyComboBox->addItem( it.key(), it.value() );
 
   96       valueComboBox->addItem( it.key(), it.value() );
 
  100   keyComboBox->setEnabled( 
nullptr != vLayer );
 
  101   valueComboBox->setEnabled( 
nullptr != vLayer );
 
  103   keyComboBox->setCurrentIndex( -1 );
 
  104   valueComboBox->setCurrentIndex( -1 );
 
  106   keyComboBox->blockSignals( 
false );
 
  107   valueComboBox->blockSignals( 
false );
 
  110 void QgsAttributeTypeLoadDialog::createPreview( 
int fieldIndex, 
bool full )
 
  112   previewTableWidget->clearContents();
 
  114   for ( 
int i = previewTableWidget->rowCount() - 1; i > 0; i-- )
 
  116     previewTableWidget->removeRow( i );
 
  118   if ( layerComboBox->currentIndex() < 0 || fieldIndex < 0 )
 
  123   const int idx = keyComboBox->currentData().toInt();
 
  124   const int idx2 = valueComboBox->currentData().toInt();
 
  126   QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
 
  131   attributeList.append( idx );
 
  132   attributeList.append( idx2 );
 
  140     const QVariant val1 = f.
attribute( idx );
 
  141     const QVariant val2 = f.
attribute( idx2 );
 
  142     if ( val1.isValid() && !val1.isNull() && !val1.toString().isEmpty()
 
  143          && val2.isValid() && !val2.isNull() && !val2.toString().isEmpty() )
 
  145       valueMap.insert( val1.toString(), val2.toString() );
 
  151   for ( QMap<QString, QVariant>::iterator mit = 
valueMap.begin(); mit != 
valueMap.end(); ++mit, row++ )
 
  153     previewTableWidget->insertRow( row );
 
  154     previewTableWidget->setItem( row, 0, 
new QTableWidgetItem( mit.value().toString() ) );
 
  155     previewTableWidget->setItem( row, 1, 
new QTableWidgetItem( mit.key() ) );
 
  166   return nullCheckBox->isChecked();
 
  169 void QgsAttributeTypeLoadDialog::loadDataToValueMap()
 
  172   const int idx = keyComboBox->currentData().toInt();
 
  173   const int idx2 = valueComboBox->currentData().toInt();
 
  175   QgsVectorLayer *vLayer = qobject_cast<QgsVectorLayer *>( dataLayer );
 
  180   attributeList.append( idx );
 
  181   attributeList.append( idx2 );
 
  189     if ( val.isValid() && !val.isNull() && !val.toString().isEmpty() )
 
  191       mValueMap.insert( f.
attribute( idx2 ).toString(), val );
 
  199   loadDataToValueMap();