|
| 1 | +/*************************************************************************** |
| 2 | + qgsaddjoindialog.cpp |
| 3 | + -------------------- |
| 4 | + begin : July 10, 2010 |
| 5 | + copyright : (C) 2010 by Marco Hugentobler |
| 6 | + email : marco dot hugentobler at sourcepole dot ch |
| 7 | + ***************************************************************************/ |
| 8 | + |
| 9 | +/*************************************************************************** |
| 10 | + * * |
| 11 | + * This program is free software; you can redistribute it and/or modify * |
| 12 | + * it under the terms of the GNU General Public License as published by * |
| 13 | + * the Free Software Foundation; either version 2 of the License, or * |
| 14 | + * (at your option) any later version. * |
| 15 | + * * |
| 16 | + ***************************************************************************/ |
| 17 | + |
| 18 | +#include "qgsaddjoindialog.h" |
| 19 | +#include "qgsmaplayer.h" |
| 20 | +#include "qgsmaplayerregistry.h" |
| 21 | +#include "qgsvectordataprovider.h" |
| 22 | +#include "qgsvectorlayer.h" |
| 23 | + |
| 24 | +QgsAddJoinDialog::QgsAddJoinDialog( QgsVectorLayer* layer, QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mLayer( layer ) |
| 25 | +{ |
| 26 | + setupUi( this ); |
| 27 | + |
| 28 | + if( !mLayer ) |
| 29 | + { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + //insert possible vector layers into mJoinLayerComboBox |
| 34 | + |
| 35 | + mJoinLayerComboBox->blockSignals( true ); |
| 36 | + const QMap<QString, QgsMapLayer*>& layerList = QgsMapLayerRegistry::instance()->mapLayers(); |
| 37 | + QMap<QString, QgsMapLayer*>::const_iterator layerIt = layerList.constBegin(); |
| 38 | + for(; layerIt != layerList.constEnd(); ++layerIt ) |
| 39 | + { |
| 40 | + QgsMapLayer* currentLayer = layerIt.value(); |
| 41 | + if( currentLayer->type() == QgsMapLayer::VectorLayer ) |
| 42 | + { |
| 43 | + QgsVectorLayer* currentVectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer ); |
| 44 | + if( currentVectorLayer && currentVectorLayer != mLayer ) |
| 45 | + { |
| 46 | + if( currentVectorLayer->dataProvider() && currentVectorLayer->dataProvider()->supportsSubsetString() ) |
| 47 | + mJoinLayerComboBox->addItem( currentLayer->name(), QVariant(currentLayer->getLayerID() ) ); |
| 48 | + } |
| 49 | + } |
| 50 | + } |
| 51 | + mJoinLayerComboBox->blockSignals( false ); |
| 52 | + on_mJoinLayerComboBox_currentIndexChanged( mJoinLayerComboBox->currentIndex() ); |
| 53 | + |
| 54 | + //insert possible target fields |
| 55 | + const QgsFieldMap& layerFieldMap = mLayer->pendingFields(); |
| 56 | + QgsFieldMap::const_iterator fieldIt = layerFieldMap.constBegin(); |
| 57 | + for(; fieldIt != layerFieldMap.constEnd(); ++fieldIt ) |
| 58 | + { |
| 59 | + mTargetFieldComboBox->addItem(fieldIt.value().name(), fieldIt.key() ); |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +QgsAddJoinDialog::~QgsAddJoinDialog() |
| 64 | +{ |
| 65 | +} |
| 66 | + |
| 67 | +QString QgsAddJoinDialog::joinedLayerId() const |
| 68 | +{ |
| 69 | + return mJoinLayerComboBox->itemData( mJoinLayerComboBox->currentIndex() ).toString(); |
| 70 | +} |
| 71 | + |
| 72 | +int QgsAddJoinDialog::joinField() const |
| 73 | +{ |
| 74 | + return mJoinFieldComboBox->itemData( mJoinFieldComboBox->currentIndex() ).toInt(); |
| 75 | +} |
| 76 | + |
| 77 | +QString QgsAddJoinDialog::joinFieldName() const |
| 78 | +{ |
| 79 | + return mJoinFieldComboBox->itemText( mJoinFieldComboBox->currentIndex() ); |
| 80 | +} |
| 81 | + |
| 82 | +int QgsAddJoinDialog::targetField() const |
| 83 | +{ |
| 84 | + return mTargetFieldComboBox->itemData( mTargetFieldComboBox->currentIndex() ).toInt(); |
| 85 | +} |
| 86 | + |
| 87 | +QString QgsAddJoinDialog::targetFieldName() const |
| 88 | +{ |
| 89 | + return mTargetFieldComboBox->itemText( mTargetFieldComboBox->currentIndex() ); |
| 90 | +} |
| 91 | + |
| 92 | +bool QgsAddJoinDialog::createAttributeIndex() const |
| 93 | +{ |
| 94 | + return mCreateIndexCheckBox->isChecked(); |
| 95 | +} |
| 96 | + |
| 97 | +void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged ( int index ) |
| 98 | +{ |
| 99 | + mJoinFieldComboBox->clear(); |
| 100 | + QString layerId = mJoinLayerComboBox->itemData( index ).toString(); |
| 101 | + QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); |
| 102 | + if( !layer ) |
| 103 | + { |
| 104 | + return; |
| 105 | + } |
| 106 | + QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( layer ); |
| 107 | + if( !vLayer ) |
| 108 | + { |
| 109 | + return; |
| 110 | + } |
| 111 | + |
| 112 | + const QgsFieldMap& layerFieldMap = vLayer->pendingFields(); |
| 113 | + QgsFieldMap::const_iterator fieldIt = layerFieldMap.constBegin(); |
| 114 | + for(; fieldIt != layerFieldMap.constEnd(); ++fieldIt ) |
| 115 | + { |
| 116 | + mJoinFieldComboBox->addItem( fieldIt.value().name(), fieldIt.key() ); |
| 117 | + } |
| 118 | + |
| 119 | + //does provider support creation of attribute indices? |
| 120 | + QgsVectorDataProvider* dp = vLayer->dataProvider(); |
| 121 | + if( dp && (dp->capabilities() & QgsVectorDataProvider::CreateAttributeIndex) ) |
| 122 | + { |
| 123 | + mCreateIndexCheckBox->setEnabled( true ); |
| 124 | + mCreateIndexCheckBox->setChecked( true ); |
| 125 | + } |
| 126 | + else |
| 127 | + { |
| 128 | + mCreateIndexCheckBox->setEnabled( false ); |
| 129 | + mCreateIndexCheckBox->setChecked( false ); |
| 130 | + } |
| 131 | +} |
0 commit comments