Skip to content
Permalink
Browse files

[joins] allow edition of joins in layer properties

  • Loading branch information
3nids committed Mar 10, 2015
1 parent cafc722 commit 4bfbcb2629ed1fdce66007274f11c39528edf405
@@ -21,6 +21,12 @@ class QgsMapLayerComboBox : QComboBox

//! currently used filter on list layers
QgsMapLayerProxyModel::Filters filters() const;

//! except a list of layers not to be listed
void setExceptedLayerList( QList<QgsMapLayer*> layerList );

//! returns the list of excepted layers
QList<QgsMapLayer*> exceptedLayerList() const;

//! currentLayer returns the current layer selected in the combo box
QgsMapLayer* currentLayer() const;
@@ -42,6 +42,10 @@ class QgsMapLayerProxyModel : QSortFilterProxyModel
*/
QgsMapLayerProxyModel* setFilters( Filters filters );
const Filters& filters() const;

//! offer the possibility to except some layers to be listed
void setExceptedLayerList( QList<QgsMapLayer*> exceptList );
QList<QgsMapLayer*> exceptedLayerList();

// QSortFilterProxyModel interface
public:
@@ -7,7 +7,7 @@ SET(QGIS_APP_SRCS
qgssponsors.cpp
qgsaddattrdialog.cpp
qgsaddtaborgroup.cpp
qgsaddjoindialog.cpp
qgsjoindialog.cpp
qgsannotationwidget.cpp
qgsattributeactiondialog.cpp
qgsattributetypedialog.cpp
@@ -163,7 +163,7 @@ SET (QGIS_APP_MOC_HDRS
qgisappstylesheet.h
qgsabout.h
qgsaddattrdialog.h
qgsaddjoindialog.h
qgsjoindialog.h
qgsaddtaborgroup.h
qgsannotationwidget.h
qgsattributeactiondialog.h

This file was deleted.

@@ -0,0 +1,164 @@
/***************************************************************************
qgsjoindialog.cpp
--------------------
begin : July 10, 2010
copyright : (C) 2010 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsjoindialog.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectordataprovider.h"
#include "qgsvectorlayer.h"
#include "qgsmaplayercombobox.h"
#include "qgsfieldcombobox.h"

#include <QStandardItemModel>

QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QWidget * parent, Qt::WindowFlags f )
: QDialog( parent, f )
, mLayer( layer )
{
setupUi( this );

if ( !mLayer )
{
return;
}

mTargetFieldComboBox->setLayer( mLayer );
mJoinLayerComboBox->setExceptedLayerList( QList<QgsMapLayer*>() << mLayer );
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), mJoinFieldComboBox, SLOT( setLayer( QgsMapLayer* ) ) );
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( joinedLayerChanged( QgsMapLayer* ) ) );
connect( mJoinFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( allowAttrIndexCreation() ) );

mCacheInMemoryCheckBox->setChecked( true );
}

QgsJoinDialog::~QgsJoinDialog()
{
}

void QgsJoinDialog::setJoinInfo( const QgsVectorJoinInfo& joinInfo )
{
mJoinLayerComboBox->setLayer( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) );
mJoinFieldComboBox->setField( joinInfo.joinFieldName );
mTargetFieldComboBox->setField( joinInfo.targetFieldName );
mCacheInMemoryCheckBox->setChecked( joinInfo.memoryCache );
if ( joinInfo.prefix.isNull() )
{
mUseCustomPrefix->setChecked( false );
}
else
{
mUseCustomPrefix->setChecked( true );
mCustomPrefix->setText( joinInfo.prefix );
}

QStringList* lst = joinInfo.joinFieldNamesSubset();
mUseJoinFieldsSubset->setChecked( lst->count() > 0 );
QAbstractItemModel* model = mJoinFieldsSubsetView->model();
if ( model )
{
for ( int i = 0; i < model->rowCount(); ++i )
{
QModelIndex index = model->index( i, 0 );
if ( lst->contains( model->data( index, Qt::DisplayRole ).toString() ) )
{
model->setData( index, Qt::Checked, Qt::CheckStateRole );
}
else
{
model->setData( index, Qt::Unchecked, Qt::CheckStateRole );
}
}
}
}

QgsVectorJoinInfo QgsJoinDialog::joinInfo() const
{
QgsVectorJoinInfo info;
info.joinLayerId = mJoinLayerComboBox->currentLayer()->id();
info.joinFieldName = mJoinFieldComboBox->currentField();
info.targetFieldName = mTargetFieldComboBox->currentField();
info.memoryCache = mCacheInMemoryCheckBox->isChecked();

if ( mUseCustomPrefix->isChecked() )
info.prefix = mCustomPrefix->text();
else
info.prefix = QString::null;

if ( mUseJoinFieldsSubset->isChecked() )
{
QStringList lst;
QAbstractItemModel* model = mJoinFieldsSubsetView->model();
if ( model )
{
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();
}
}
info.setJoinFieldNamesSubset( new QStringList( lst ) );
}

return info;
}

bool QgsJoinDialog::createAttributeIndex() const
{
return mCreateIndexCheckBox->isChecked();
}

void QgsJoinDialog::joinedLayerChanged( QgsMapLayer* layer )
{

mJoinFieldComboBox->clear();

QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( layer );
if ( !vLayer )
{
return;
}

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

QgsVectorDataProvider* dp = vLayer->dataProvider();
bool canCreateAttrIndex = dp && ( dp->capabilities() & QgsVectorDataProvider::CreateAttributeIndex );
if ( canCreateAttrIndex )
{
mCreateIndexCheckBox->setEnabled( true );
}
else
{
mCreateIndexCheckBox->setEnabled( false );
mCreateIndexCheckBox->setChecked( false );
}

if ( !mUseCustomPrefix->isChecked() )
{
mCustomPrefix->setText( layer->name() + "_" );
}
}

0 comments on commit 4bfbcb2

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