25 #include <QTableWidgetItem>
30 #include <QScrollArea>
33 #include <QPushButton>
34 #include <QHBoxLayout>
35 #include <QFileDialog>
43 connect( layerComboBox, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( fillComboBoxes(
int ) ) );
44 connect( keyComboBox, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( createPreview(
int ) ) );
45 connect( valueComboBox, SIGNAL( currentIndexChanged(
int ) ),
this, SLOT( createPreview(
int ) ) );
46 connect( previewButton, SIGNAL( pressed() ),
this, SLOT( previewButtonPushed() ) );
50 keyComboBox->setDisabled(
true );
51 valueComboBox->setDisabled(
true );
64 void QgsAttributeTypeLoadDialog::previewButtonPushed()
66 createPreview( valueComboBox->currentIndex(), true );
69 void QgsAttributeTypeLoadDialog::fillLayerList()
71 layerComboBox->blockSignals(
true );
72 layerComboBox->clear();
77 layerComboBox->addItem( vl->
name(), vl->
id() );
79 layerComboBox->setCurrentIndex( -1 );
80 layerComboBox->blockSignals(
false );
83 void QgsAttributeTypeLoadDialog::fillComboBoxes(
int layerIndex )
85 keyComboBox->blockSignals(
true );
86 valueComboBox->blockSignals(
true );
90 valueComboBox->clear();
96 QMap<QString, int>::iterator it = fieldMap.begin();
97 for ( ; it != fieldMap.end(); ++it )
99 keyComboBox->addItem( it.key(), it.value() );
100 valueComboBox->addItem( it.key(), it.value() );
104 keyComboBox->setEnabled( vLayer != 0 );
105 valueComboBox->setEnabled( vLayer != 0 );
107 keyComboBox->setCurrentIndex( -1 );
108 valueComboBox->setCurrentIndex( -1 );
110 keyComboBox->blockSignals(
false );
111 valueComboBox->blockSignals(
false );
114 void QgsAttributeTypeLoadDialog::createPreview(
int fieldIndex,
bool full )
116 previewTableWidget->clearContents();
118 for (
int i = previewTableWidget->rowCount() - 1; i > 0; i-- )
120 previewTableWidget->removeRow( i );
122 if ( layerComboBox->currentIndex() < 0 || fieldIndex < 0 )
127 int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
128 int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
135 attributeList.append( idx );
136 attributeList.append( idx2 );
146 if ( val1.isValid() && !val1.isNull() && !val1.toString().isEmpty()
147 && val2.isValid() && !val2.isNull() && !val2.toString().isEmpty() )
149 valueMap.insert( val1.toString(), val2.toString() );
151 if ( !full && valueMap.size() > 8 )
155 for ( QMap<QString, QVariant>::iterator mit = valueMap.begin(); mit != valueMap.end(); ++mit, row++ )
157 previewTableWidget->insertRow( row );
158 previewTableWidget->setItem( row, 0,
new QTableWidgetItem( mit.value().toString() ) );
159 previewTableWidget->setItem( row, 1,
new QTableWidgetItem( mit.key() ) );
170 return nullCheckBox->isChecked();
173 void QgsAttributeTypeLoadDialog::loadDataToValueMap()
176 int idx = keyComboBox->itemData( keyComboBox->currentIndex() ).toInt();
177 int idx2 = valueComboBox->itemData( valueComboBox->currentIndex() ).toInt();
184 attributeList.append( idx );
185 attributeList.append( idx2 );
193 if ( val.isValid() && !val.isNull() && !val.toString().isEmpty() )
195 mValueMap.insert( f.
attribute( idx2 ).toString(), val );
203 loadDataToValueMap();