Skip to content
Permalink
Browse files

[FEATURE] Joins: optionally use just a subset of fields from the join…

…ed layer
  • Loading branch information
wonder-sk committed Sep 13, 2014
1 parent ffcd07b commit 9945a6d14545a8fe4dda9c7455e0761fcdb662f1
Showing with 83 additions and 16 deletions.
  1. +36 −0 src/app/qgsaddjoindialog.cpp
  2. +5 −0 src/app/qgsaddjoindialog.h
  3. +2 −0 src/app/qgsvectorlayerproperties.cpp
  4. +40 −16 src/ui/qgsaddjoindialogbase.ui
@@ -21,6 +21,8 @@
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"

#include <QStandardItemModel>

QgsAddJoinDialog::QgsAddJoinDialog( QgsVectorLayer* layer, QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mLayer( layer )
{
setupUi( this );
@@ -94,6 +96,27 @@ bool QgsAddJoinDialog::createAttributeIndex() const
return mCreateIndexCheckBox->isChecked();
}

bool QgsAddJoinDialog::hasJoinFieldsSubset() const
{
return mUseJoinFieldsSubset->isChecked();
}

QStringList QgsAddJoinDialog::joinFieldsSubset() const
{
QStringList lst;
QAbstractItemModel* model = mJoinFieldsSubsetView->model();
if ( !model )
return lst;

for ( int i = 0; i < model->rowCount(); ++i )
{
QModelIndex index = model->index( i, 0 );
if ( model->data( index, Qt::CheckStateRole ).toInt() == Qt::Checked )
lst << model->data( index ).toString();
}
return lst;
}

void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged( int index )
{
mJoinFieldComboBox->clear();
@@ -109,10 +132,16 @@ void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged( int index )
return;
}

QStandardItemModel* subsetModel = new QStandardItemModel( this );

const QgsFields& layerFields = vLayer->pendingFields();
for ( int idx = 0; idx < layerFields.count(); ++idx )
{
mJoinFieldComboBox->addItem( layerFields[idx].name(), idx );
QStandardItem* subsetItem = new QStandardItem( layerFields[idx].name() );
subsetItem->setCheckable( true );
//subsetItem->setFlags( subsetItem->flags() | Qt::ItemIsUserCheckable );
subsetModel->appendRow( subsetItem );
}

//does provider support creation of attribute indices?
@@ -126,4 +155,11 @@ void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged( int index )
mCreateIndexCheckBox->setEnabled( false );
mCreateIndexCheckBox->setChecked( false );
}

mJoinFieldsSubsetView->setModel( subsetModel );
}

void QgsAddJoinDialog::on_mUseJoinFieldsSubset_clicked()
{
mJoinFieldsSubsetView->setEnabled( mUseJoinFieldsSubset->isChecked() );
}
@@ -40,9 +40,14 @@ class APP_EXPORT QgsAddJoinDialog: public QDialog, private Ui::QgsAddJoinDialogB
bool cacheInMemory() const;
/**Returns true if user wants to create an attribute index on the join field*/
bool createAttributeIndex() const;
/**True if onle a subset of fields of joined layer should be used*/
bool hasJoinFieldsSubset() const;
/**Return list of checked fields from joined layer to be used in join*/
QStringList joinFieldsSubset() const;

private slots:
void on_mJoinLayerComboBox_currentIndexChanged( int index );
void on_mUseJoinFieldsSubset_clicked();

private:
/**Target layer*/
@@ -980,6 +980,8 @@ void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
info.joinLayerId = d.joinedLayerId();
info.joinFieldName = d.joinFieldName();
info.memoryCache = d.cacheInMemory();
if ( d.hasJoinFieldsSubset() )
info.setJoinFieldNamesSubset( new QStringList( d.joinFieldsSubset() ) );
if ( layer )
{
//create attribute index if possible
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>281</width>
<height>160</height>
<width>301</width>
<height>327</height>
</rect>
</property>
<property name="windowTitle">
@@ -44,13 +44,10 @@
<item row="2" column="1">
<widget class="QComboBox" name="mTargetFieldComboBox"/>
</item>
<item row="5" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mCacheInMemoryCheckBox">
<property name="text">
<string>Cache join layer in virtual memory</string>
</property>
</widget>
</item>
@@ -61,15 +58,42 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="mCacheInMemoryCheckBox">
<item row="5" column="0" colspan="2">
<widget class="QCheckBox" name="mUseJoinFieldsSubset">
<property name="text">
<string>Cache join layer in virtual memory</string>
<string>Choose which fields are joined</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QListView" name="mJoinFieldsSubsetView">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>mJoinLayerComboBox</tabstop>
<tabstop>mJoinFieldComboBox</tabstop>
<tabstop>mTargetFieldComboBox</tabstop>
<tabstop>mCacheInMemoryCheckBox</tabstop>
<tabstop>mCreateIndexCheckBox</tabstop>
<tabstop>mUseJoinFieldsSubset</tabstop>
<tabstop>mJoinFieldsSubsetView</tabstop>
<tabstop>buttonBox</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
@@ -79,8 +103,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
<x>252</x>
<y>322</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
@@ -95,8 +119,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
<x>296</x>
<y>322</y>
</hint>
<hint type="destinationlabel">
<x>286</x>

0 comments on commit 9945a6d

Please sign in to comment.
You can’t perform that action at this time.