mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
[joins] allow edition of joins in layer properties
This commit is contained in:
parent
cafc722d92
commit
4bfbcb2629
@ -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
|
||||
|
@ -1,171 +0,0 @@
|
||||
/***************************************************************************
|
||||
qgsaddjoindialog.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 "qgsaddjoindialog.h"
|
||||
#include "qgsmaplayer.h"
|
||||
#include "qgsmaplayerregistry.h"
|
||||
#include "qgsvectordataprovider.h"
|
||||
#include "qgsvectorlayer.h"
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
QgsAddJoinDialog::QgsAddJoinDialog( QgsVectorLayer* layer, QWidget * parent, Qt::WindowFlags f ): QDialog( parent, f ), mLayer( layer )
|
||||
{
|
||||
setupUi( this );
|
||||
|
||||
if ( !mLayer )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//insert possible vector layers into mJoinLayerComboBox
|
||||
|
||||
mJoinLayerComboBox->blockSignals( true );
|
||||
const QMap<QString, QgsMapLayer*>& layerList = QgsMapLayerRegistry::instance()->mapLayers();
|
||||
QMap<QString, QgsMapLayer*>::const_iterator layerIt = layerList.constBegin();
|
||||
for ( ; layerIt != layerList.constEnd(); ++layerIt )
|
||||
{
|
||||
QgsMapLayer* currentLayer = layerIt.value();
|
||||
if ( currentLayer->type() == QgsMapLayer::VectorLayer )
|
||||
{
|
||||
QgsVectorLayer* currentVectorLayer = dynamic_cast<QgsVectorLayer*>( currentLayer );
|
||||
if ( currentVectorLayer && currentVectorLayer != mLayer )
|
||||
{
|
||||
if ( currentVectorLayer->dataProvider() && currentVectorLayer->dataProvider()->supportsSubsetString() )
|
||||
mJoinLayerComboBox->addItem( currentLayer->name(), QVariant( currentLayer->id() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
mJoinLayerComboBox->blockSignals( false );
|
||||
on_mJoinLayerComboBox_currentIndexChanged( mJoinLayerComboBox->currentIndex() );
|
||||
|
||||
//insert possible target fields
|
||||
QgsVectorDataProvider* provider = mLayer->dataProvider();
|
||||
if ( provider )
|
||||
{
|
||||
const QgsFields& layerFields = provider->fields();
|
||||
for ( int idx = 0; idx < layerFields.count(); ++idx )
|
||||
{
|
||||
mTargetFieldComboBox->addItem( layerFields[idx].name(), idx );
|
||||
}
|
||||
}
|
||||
|
||||
mCacheInMemoryCheckBox->setChecked( true );
|
||||
}
|
||||
|
||||
QgsAddJoinDialog::~QgsAddJoinDialog()
|
||||
{
|
||||
}
|
||||
|
||||
QString QgsAddJoinDialog::joinedLayerId() const
|
||||
{
|
||||
return mJoinLayerComboBox->itemData( mJoinLayerComboBox->currentIndex() ).toString();
|
||||
}
|
||||
|
||||
QString QgsAddJoinDialog::joinFieldName() const
|
||||
{
|
||||
return mJoinFieldComboBox->itemText( mJoinFieldComboBox->currentIndex() );
|
||||
}
|
||||
|
||||
QString QgsAddJoinDialog::targetFieldName() const
|
||||
{
|
||||
return mTargetFieldComboBox->itemText( mTargetFieldComboBox->currentIndex() );
|
||||
}
|
||||
|
||||
bool QgsAddJoinDialog::cacheInMemory() const
|
||||
{
|
||||
return mCacheInMemoryCheckBox->isChecked();
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool QgsAddJoinDialog::hasCustomPrefix() const
|
||||
{
|
||||
return mUseCustomPrefix;
|
||||
}
|
||||
|
||||
const QString QgsAddJoinDialog::customPrefix() const
|
||||
{
|
||||
return mCustomPrefix->text();
|
||||
}
|
||||
|
||||
void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged( int index )
|
||||
{
|
||||
mJoinFieldComboBox->clear();
|
||||
QString layerId = mJoinLayerComboBox->itemData( index ).toString();
|
||||
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId );
|
||||
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( layer );
|
||||
if ( !vLayer )
|
||||
{
|
||||
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?
|
||||
QgsVectorDataProvider* dp = vLayer->dataProvider();
|
||||
if ( dp && ( dp->capabilities() & QgsVectorDataProvider::CreateAttributeIndex ) )
|
||||
{
|
||||
mCreateIndexCheckBox->setEnabled( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
mCreateIndexCheckBox->setEnabled( false );
|
||||
mCreateIndexCheckBox->setChecked( false );
|
||||
}
|
||||
|
||||
mJoinFieldsSubsetView->setModel( subsetModel );
|
||||
|
||||
if ( !mUseCustomPrefix->isChecked() )
|
||||
{
|
||||
mCustomPrefix->setText( layer->name() + "_" );
|
||||
}
|
||||
}
|
164
src/app/qgsjoindialog.cpp
Normal file
164
src/app/qgsjoindialog.cpp
Normal file
@ -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() + "_" );
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/***************************************************************************
|
||||
qgsaddjoindialog.h
|
||||
qgsjoindialog.h
|
||||
------------------
|
||||
begin : July 10, 2010
|
||||
copyright : (C) 2010 by Marco Hugentobler
|
||||
@ -15,42 +15,32 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSADDJOINDIALOG_H
|
||||
#define QGSADDJOINDIALOG_H
|
||||
#ifndef QgsJoinDIALOG_H
|
||||
#define QgsJoinDIALOG_H
|
||||
|
||||
#include "ui_qgsjoindialogbase.h"
|
||||
|
||||
#include "ui_qgsaddjoindialogbase.h"
|
||||
class QgsVectorLayer;
|
||||
class QgsVectorJoinInfo;
|
||||
|
||||
class APP_EXPORT QgsAddJoinDialog: public QDialog, private Ui::QgsAddJoinDialogBase
|
||||
class APP_EXPORT QgsJoinDialog: public QDialog, private Ui::QgsJoinDialogBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QgsAddJoinDialog( QgsVectorLayer* layer, QWidget * parent = 0, Qt::WindowFlags f = 0 );
|
||||
~QgsAddJoinDialog();
|
||||
QgsJoinDialog( QgsVectorLayer* layer, QWidget * parent = 0, Qt::WindowFlags f = 0 );
|
||||
~QgsJoinDialog();
|
||||
|
||||
//retrieve results
|
||||
/** Configure the dialog for an existing join */
|
||||
void setJoinInfo( const QgsVectorJoinInfo& joinInfo );
|
||||
|
||||
/** Returns the join info */
|
||||
QgsVectorJoinInfo joinInfo() const;
|
||||
|
||||
/** Get the id of the layer to join*/
|
||||
QString joinedLayerId() const;
|
||||
/** Returns the name of the join field*/
|
||||
QString joinFieldName() const;
|
||||
/** Returns the name of the target field (join-to field)*/
|
||||
QString targetFieldName() const;
|
||||
/** True if joined layer should be cached in virtual memory*/
|
||||
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;
|
||||
/** Return if the user selected a custom prefix*/
|
||||
bool hasCustomPrefix() const;
|
||||
/** The custom prefix the user defined*/
|
||||
const QString customPrefix() const;
|
||||
|
||||
private slots:
|
||||
void on_mJoinLayerComboBox_currentIndexChanged( int index );
|
||||
void joinedLayerChanged( QgsMapLayer* layer );
|
||||
|
||||
private:
|
||||
/**Target layer*/
|
||||
@ -58,4 +48,4 @@ class APP_EXPORT QgsAddJoinDialog: public QDialog, private Ui::QgsAddJoinDialogB
|
||||
};
|
||||
|
||||
|
||||
#endif // QGSADDJOINDIALOG_H
|
||||
#endif // QgsJoinDIALOG_H
|
@ -20,7 +20,7 @@
|
||||
#include <limits>
|
||||
|
||||
#include "qgisapp.h"
|
||||
#include "qgsaddjoindialog.h"
|
||||
#include "qgsjoindialog.h"
|
||||
#include "qgsapplication.h"
|
||||
#include "qgsattributeactiondialog.h"
|
||||
#include "qgsapplydialog.h"
|
||||
@ -1031,17 +1031,10 @@ void QgsVectorLayerProperties::showListOfStylesFromDatabase()
|
||||
|
||||
void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
|
||||
{
|
||||
QgsAddJoinDialog d( layer );
|
||||
QgsJoinDialog d( layer );
|
||||
if ( d.exec() == QDialog::Accepted )
|
||||
{
|
||||
QgsVectorJoinInfo info;
|
||||
info.targetFieldName = d.targetFieldName();
|
||||
info.joinLayerId = d.joinedLayerId();
|
||||
info.joinFieldName = d.joinFieldName();
|
||||
info.memoryCache = d.cacheInMemory();
|
||||
|
||||
if ( d.hasJoinFieldsSubset() )
|
||||
info.setJoinFieldNamesSubset( new QStringList( d.joinFieldsSubset() ) );
|
||||
QgsVectorJoinInfo info = d.joinInfo();
|
||||
if ( layer )
|
||||
{
|
||||
//create attribute index if possible
|
||||
@ -1053,11 +1046,6 @@ void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
|
||||
joinLayer->dataProvider()->createAttributeIndex( joinLayer->pendingFields().indexFromName( info.joinFieldName ) );
|
||||
}
|
||||
}
|
||||
if ( d.hasCustomPrefix() )
|
||||
info.prefix = d.customPrefix();
|
||||
else
|
||||
info.prefix = QString::null;
|
||||
|
||||
layer->addJoin( info );
|
||||
addJoinToTreeWidget( info );
|
||||
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
|
||||
@ -1067,6 +1055,62 @@ void QgsVectorLayerProperties::on_mButtonAddJoin_clicked()
|
||||
}
|
||||
}
|
||||
|
||||
void QgsVectorLayerProperties::on_mButtonEditJoin_clicked()
|
||||
{
|
||||
QTreeWidgetItem* currentJoinItem = mJoinTreeWidget->currentItem();
|
||||
if ( !layer || !currentJoinItem )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString joinLayerId = currentJoinItem->data( 0, Qt::UserRole ).toString();
|
||||
const QList< QgsVectorJoinInfo >& joins = layer->vectorJoins();
|
||||
int j = -1;
|
||||
for ( int i = 0; i < joins.size(); ++i )
|
||||
{
|
||||
if ( joins[i].joinLayerId == joinLayerId )
|
||||
{
|
||||
j = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( j == -1 )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QgsJoinDialog d( layer );
|
||||
d.setJoinInfo( joins[j] );
|
||||
|
||||
if ( d.exec() == QDialog::Accepted )
|
||||
{
|
||||
// remove old join
|
||||
layer->removeJoin( currentJoinItem->data( 0, Qt::UserRole ).toString() );
|
||||
mJoinTreeWidget->takeTopLevelItem( mJoinTreeWidget->indexOfTopLevelItem( currentJoinItem ) );
|
||||
|
||||
// add the new edited
|
||||
QgsVectorJoinInfo info = d.joinInfo();
|
||||
if ( layer )
|
||||
{
|
||||
//create attribute index if possible
|
||||
if ( d.createAttributeIndex() )
|
||||
{
|
||||
QgsVectorLayer* joinLayer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance()->mapLayer( info.joinLayerId ) );
|
||||
if ( joinLayer )
|
||||
{
|
||||
joinLayer->dataProvider()->createAttributeIndex( joinLayer->pendingFields().indexFromName( info.joinFieldName ) );
|
||||
}
|
||||
}
|
||||
layer->addJoin( info );
|
||||
addJoinToTreeWidget( info );
|
||||
|
||||
pbnQueryBuilder->setEnabled( layer && layer->dataProvider() && layer->dataProvider()->supportsSubsetString() &&
|
||||
!layer->isEditable() && layer->vectorJoins().size() < 1 );
|
||||
mFieldsPropertiesDialog->init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsVectorLayerProperties::addJoinToTreeWidget( const QgsVectorJoinInfo& join )
|
||||
{
|
||||
QTreeWidgetItem* joinItem = new QTreeWidgetItem();
|
||||
|
@ -115,6 +115,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
|
||||
void enableLabelOptions( bool theFlag );
|
||||
|
||||
void on_mButtonAddJoin_clicked();
|
||||
void on_mButtonEditJoin_clicked();
|
||||
void on_mButtonRemoveJoin_clicked();
|
||||
|
||||
void on_mSimplifyDrawingGroupBox_toggled( bool checked );
|
||||
|
@ -26,11 +26,6 @@ QgsMapLayerComboBox::QgsMapLayerComboBox( QWidget *parent ) :
|
||||
connect( this, SIGNAL( activated( int ) ), this, SLOT( indexChanged( int ) ) );
|
||||
}
|
||||
|
||||
void QgsMapLayerComboBox::setFilters( QgsMapLayerProxyModel::Filters filters )
|
||||
{
|
||||
mProxyModel->setFilters( filters );
|
||||
}
|
||||
|
||||
void QgsMapLayerComboBox::setLayer( QgsMapLayer *layer )
|
||||
{
|
||||
QModelIndex idx = mProxyModel->sourceLayerModel()->indexFromLayer( layer );
|
||||
@ -78,3 +73,4 @@ void QgsMapLayerComboBox::indexChanged( int i )
|
||||
QgsMapLayer* layer = currentLayer();
|
||||
emit layerChanged( layer );
|
||||
}
|
||||
|
||||
|
@ -41,11 +41,17 @@ class GUI_EXPORT QgsMapLayerComboBox : public QComboBox
|
||||
explicit QgsMapLayerComboBox( QWidget *parent = 0 );
|
||||
|
||||
//! setFilters allows fitering according to layer type and/or geometry type.
|
||||
void setFilters( QgsMapLayerProxyModel::Filters filters );
|
||||
void setFilters( QgsMapLayerProxyModel::Filters filters ) { mProxyModel->setFilters( filters ); }
|
||||
|
||||
//! currently used filter on list layers
|
||||
QgsMapLayerProxyModel::Filters filters() const { return mProxyModel->filters(); }
|
||||
|
||||
//! except a list of layers not to be listed
|
||||
void setExceptedLayerList( QList<QgsMapLayer*> layerList ) { mProxyModel->setExceptedLayerList( layerList ); }
|
||||
|
||||
//! returns the list of excepted layers
|
||||
QList<QgsMapLayer*> exceptedLayerList() const {return mProxyModel->exceptedLayerList();}
|
||||
|
||||
//! currentLayer returns the current layer selected in the combo box
|
||||
QgsMapLayer* currentLayer() const;
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
QgsMapLayerProxyModel::QgsMapLayerProxyModel( QObject *parent )
|
||||
: QSortFilterProxyModel( parent )
|
||||
, mFilters( All )
|
||||
, mExceptList( QList<QgsMapLayer*>() )
|
||||
, mModel( new QgsMapLayerModel( parent ) )
|
||||
{
|
||||
setSourceModel( mModel );
|
||||
@ -37,6 +38,12 @@ QgsMapLayerProxyModel *QgsMapLayerProxyModel::setFilters( Filters filters )
|
||||
return this;
|
||||
}
|
||||
|
||||
void QgsMapLayerProxyModel::setExceptedLayerList(QList<QgsMapLayer*> exceptList)
|
||||
{
|
||||
mExceptList = exceptList;
|
||||
invalidateFilter();
|
||||
}
|
||||
|
||||
bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex &source_parent ) const
|
||||
{
|
||||
if ( mFilters.testFlag( All ) )
|
||||
@ -47,6 +54,9 @@ bool QgsMapLayerProxyModel::filterAcceptsRow( int source_row, const QModelIndex
|
||||
if ( !layer )
|
||||
return false;
|
||||
|
||||
if ( mExceptList.contains( layer ) )
|
||||
return false;
|
||||
|
||||
// layer type
|
||||
if (( mFilters.testFlag( RasterLayer ) && layer->type() == QgsMapLayer::RasterLayer ) ||
|
||||
( mFilters.testFlag( VectorLayer ) && layer->type() == QgsMapLayer::VectorLayer ) ||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <QSortFilterProxyModel>
|
||||
|
||||
class QgsMapLayerModel;
|
||||
class QgsMapLayer;
|
||||
|
||||
/**
|
||||
* @brief The QgsMapLayerProxyModel class provides an easy to use model to display the list of layers in widgets.
|
||||
@ -62,8 +63,13 @@ class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
|
||||
QgsMapLayerProxyModel* setFilters( Filters filters );
|
||||
const Filters& filters() const { return mFilters; }
|
||||
|
||||
//! offer the possibility to except some layers to be listed
|
||||
void setExceptedLayerList( QList<QgsMapLayer*> exceptList );
|
||||
QList<QgsMapLayer*> exceptedLayerList() {return mExceptList;}
|
||||
|
||||
private:
|
||||
Filters mFilters;
|
||||
QList<QgsMapLayer*> mExceptList;
|
||||
QgsMapLayerModel* mModel;
|
||||
|
||||
// QSortFilterProxyModel interface
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QgsAddJoinDialogBase</class>
|
||||
<widget class="QDialog" name="QgsAddJoinDialogBase">
|
||||
<class>QgsJoinDialogBase</class>
|
||||
<widget class="QDialog" name="QgsJoinDialogBase">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
@ -14,51 +14,42 @@
|
||||
<string>Add vector join</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="mJoinLayerLabel">
|
||||
<property name="text">
|
||||
<string>Join layer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="mJoinLayerComboBox"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="mJoinFieldLabel">
|
||||
<property name="text">
|
||||
<string>Join field</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QComboBox" name="mJoinFieldComboBox"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="mTargetFieldLabel">
|
||||
<property name="text">
|
||||
<string>Target field</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QComboBox" name="mTargetFieldComboBox"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QCheckBox" name="mCacheInMemoryCheckBox">
|
||||
<property name="text">
|
||||
<string>Cache join layer in virtual memory</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="0" colspan="2">
|
||||
<item row="5" column="0" colspan="2">
|
||||
<widget class="QCheckBox" name="mCreateIndexCheckBox">
|
||||
<property name="text">
|
||||
<string>Create attribute index on join field</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="2">
|
||||
<item row="6" column="0" colspan="2">
|
||||
<widget class="QgsCollapsibleGroupBox" name="mUseJoinFieldsSubset">
|
||||
<property name="title">
|
||||
<string>Choose which fields are joined</string>
|
||||
@ -69,7 +60,7 @@
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="collapsed" stdset="0">
|
||||
<property name="collapsed">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
@ -79,7 +70,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="0" colspan="2">
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QgsCollapsibleGroupBox" name="mUseCustomPrefix">
|
||||
<property name="title">
|
||||
<string>Custom field name prefix</string>
|
||||
@ -90,7 +81,7 @@
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="collapsed" stdset="0">
|
||||
<property name="collapsed">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
@ -100,7 +91,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<item row="9" column="0" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
@ -110,7 +101,7 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<item row="8" column="0">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
@ -123,6 +114,19 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QgsMapLayerComboBox" name="mJoinLayerComboBox">
|
||||
<property name="filters">
|
||||
<set>QgsMapLayerProxyModel::VectorLayer</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QgsFieldComboBox" name="mJoinFieldComboBox"/>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QgsFieldComboBox" name="mTargetFieldComboBox"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
@ -132,11 +136,18 @@
|
||||
<header>qgscollapsiblegroupbox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsFieldComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>qgsfieldcombobox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsMapLayerComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>qgsmaplayercombobox.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>mJoinLayerComboBox</tabstop>
|
||||
<tabstop>mJoinFieldComboBox</tabstop>
|
||||
<tabstop>mTargetFieldComboBox</tabstop>
|
||||
<tabstop>mCacheInMemoryCheckBox</tabstop>
|
||||
<tabstop>mCreateIndexCheckBox</tabstop>
|
||||
<tabstop>mUseJoinFieldsSubset</tabstop>
|
||||
@ -150,7 +161,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>QgsAddJoinDialogBase</receiver>
|
||||
<receiver>QgsJoinDialogBase</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
@ -166,7 +177,7 @@
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>QgsAddJoinDialogBase</receiver>
|
||||
<receiver>QgsJoinDialogBase</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
@ -293,8 +293,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>730</width>
|
||||
<height>537</height>
|
||||
<width>331</width>
|
||||
<height>431</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_13">
|
||||
@ -1316,6 +1316,17 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mButtonEditJoin">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../images/images.qrc">
|
||||
<normaloff>:/images/themes/default/mActionToggleEditing.png</normaloff>:/images/themes/default/mActionToggleEditing.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
@ -1364,8 +1375,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>730</width>
|
||||
<height>537</height>
|
||||
<width>100</width>
|
||||
<height>30</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_24">
|
||||
@ -1424,7 +1435,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>714</width>
|
||||
<width>392</width>
|
||||
<height>608</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
Loading…
x
Reference in New Issue
Block a user