Skip to content

Commit 4bfbcb2

Browse files
committed
[joins] allow edition of joins in layer properties
1 parent cafc722 commit 4bfbcb2

14 files changed

+332
-254
lines changed

python/gui/qgsmaplayercombobox.sip

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class QgsMapLayerComboBox : QComboBox
2121

2222
//! currently used filter on list layers
2323
QgsMapLayerProxyModel::Filters filters() const;
24+
25+
//! except a list of layers not to be listed
26+
void setExceptedLayerList( QList<QgsMapLayer*> layerList );
27+
28+
//! returns the list of excepted layers
29+
QList<QgsMapLayer*> exceptedLayerList() const;
2430

2531
//! currentLayer returns the current layer selected in the combo box
2632
QgsMapLayer* currentLayer() const;

python/gui/qgsmaplayerproxymodel.sip

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class QgsMapLayerProxyModel : QSortFilterProxyModel
4242
*/
4343
QgsMapLayerProxyModel* setFilters( Filters filters );
4444
const Filters& filters() const;
45+
46+
//! offer the possibility to except some layers to be listed
47+
void setExceptedLayerList( QList<QgsMapLayer*> exceptList );
48+
QList<QgsMapLayer*> exceptedLayerList();
4549

4650
// QSortFilterProxyModel interface
4751
public:

src/app/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SET(QGIS_APP_SRCS
77
qgssponsors.cpp
88
qgsaddattrdialog.cpp
99
qgsaddtaborgroup.cpp
10-
qgsaddjoindialog.cpp
10+
qgsjoindialog.cpp
1111
qgsannotationwidget.cpp
1212
qgsattributeactiondialog.cpp
1313
qgsattributetypedialog.cpp
@@ -163,7 +163,7 @@ SET (QGIS_APP_MOC_HDRS
163163
qgisappstylesheet.h
164164
qgsabout.h
165165
qgsaddattrdialog.h
166-
qgsaddjoindialog.h
166+
qgsjoindialog.h
167167
qgsaddtaborgroup.h
168168
qgsannotationwidget.h
169169
qgsattributeactiondialog.h

src/app/qgsaddjoindialog.cpp

-171
This file was deleted.

src/app/qgsjoindialog.cpp

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/***************************************************************************
2+
qgsjoindialog.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 "qgsjoindialog.h"
19+
#include "qgsmaplayer.h"
20+
#include "qgsmaplayerregistry.h"
21+
#include "qgsvectordataprovider.h"
22+
#include "qgsvectorlayer.h"
23+
#include "qgsmaplayercombobox.h"
24+
#include "qgsfieldcombobox.h"
25+
26+
#include <QStandardItemModel>
27+
28+
QgsJoinDialog::QgsJoinDialog( QgsVectorLayer* layer, QWidget * parent, Qt::WindowFlags f )
29+
: QDialog( parent, f )
30+
, mLayer( layer )
31+
{
32+
setupUi( this );
33+
34+
if ( !mLayer )
35+
{
36+
return;
37+
}
38+
39+
mTargetFieldComboBox->setLayer( mLayer );
40+
mJoinLayerComboBox->setExceptedLayerList( QList<QgsMapLayer*>() << mLayer );
41+
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), mJoinFieldComboBox, SLOT( setLayer( QgsMapLayer* ) ) );
42+
connect( mJoinLayerComboBox, SIGNAL( layerChanged( QgsMapLayer* ) ), this, SLOT( joinedLayerChanged( QgsMapLayer* ) ) );
43+
connect( mJoinFieldComboBox, SIGNAL( fieldChanged( QString ) ), this, SLOT( allowAttrIndexCreation() ) );
44+
45+
mCacheInMemoryCheckBox->setChecked( true );
46+
}
47+
48+
QgsJoinDialog::~QgsJoinDialog()
49+
{
50+
}
51+
52+
void QgsJoinDialog::setJoinInfo( const QgsVectorJoinInfo& joinInfo )
53+
{
54+
mJoinLayerComboBox->setLayer( QgsMapLayerRegistry::instance()->mapLayer( joinInfo.joinLayerId ) );
55+
mJoinFieldComboBox->setField( joinInfo.joinFieldName );
56+
mTargetFieldComboBox->setField( joinInfo.targetFieldName );
57+
mCacheInMemoryCheckBox->setChecked( joinInfo.memoryCache );
58+
if ( joinInfo.prefix.isNull() )
59+
{
60+
mUseCustomPrefix->setChecked( false );
61+
}
62+
else
63+
{
64+
mUseCustomPrefix->setChecked( true );
65+
mCustomPrefix->setText( joinInfo.prefix );
66+
}
67+
68+
QStringList* lst = joinInfo.joinFieldNamesSubset();
69+
mUseJoinFieldsSubset->setChecked( lst->count() > 0 );
70+
QAbstractItemModel* model = mJoinFieldsSubsetView->model();
71+
if ( model )
72+
{
73+
for ( int i = 0; i < model->rowCount(); ++i )
74+
{
75+
QModelIndex index = model->index( i, 0 );
76+
if ( lst->contains( model->data( index, Qt::DisplayRole ).toString() ) )
77+
{
78+
model->setData( index, Qt::Checked, Qt::CheckStateRole );
79+
}
80+
else
81+
{
82+
model->setData( index, Qt::Unchecked, Qt::CheckStateRole );
83+
}
84+
}
85+
}
86+
}
87+
88+
QgsVectorJoinInfo QgsJoinDialog::joinInfo() const
89+
{
90+
QgsVectorJoinInfo info;
91+
info.joinLayerId = mJoinLayerComboBox->currentLayer()->id();
92+
info.joinFieldName = mJoinFieldComboBox->currentField();
93+
info.targetFieldName = mTargetFieldComboBox->currentField();
94+
info.memoryCache = mCacheInMemoryCheckBox->isChecked();
95+
96+
if ( mUseCustomPrefix->isChecked() )
97+
info.prefix = mCustomPrefix->text();
98+
else
99+
info.prefix = QString::null;
100+
101+
if ( mUseJoinFieldsSubset->isChecked() )
102+
{
103+
QStringList lst;
104+
QAbstractItemModel* model = mJoinFieldsSubsetView->model();
105+
if ( model )
106+
{
107+
for ( int i = 0; i < model->rowCount(); ++i )
108+
{
109+
QModelIndex index = model->index( i, 0 );
110+
if ( model->data( index, Qt::CheckStateRole ).toInt() == Qt::Checked )
111+
lst << model->data( index ).toString();
112+
}
113+
}
114+
info.setJoinFieldNamesSubset( new QStringList( lst ) );
115+
}
116+
117+
return info;
118+
}
119+
120+
bool QgsJoinDialog::createAttributeIndex() const
121+
{
122+
return mCreateIndexCheckBox->isChecked();
123+
}
124+
125+
void QgsJoinDialog::joinedLayerChanged( QgsMapLayer* layer )
126+
{
127+
128+
mJoinFieldComboBox->clear();
129+
130+
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( layer );
131+
if ( !vLayer )
132+
{
133+
return;
134+
}
135+
136+
mUseJoinFieldsSubset->setChecked( false );
137+
QStandardItemModel* subsetModel = new QStandardItemModel( this );
138+
const QgsFields& layerFields = vLayer->pendingFields();
139+
for ( int idx = 0; idx < layerFields.count(); ++idx )
140+
{
141+
QStandardItem* subsetItem = new QStandardItem( layerFields[idx].name() );
142+
subsetItem->setCheckable( true );
143+
//subsetItem->setFlags( subsetItem->flags() | Qt::ItemIsUserCheckable );
144+
subsetModel->appendRow( subsetItem );
145+
}
146+
mJoinFieldsSubsetView->setModel( subsetModel );
147+
148+
QgsVectorDataProvider* dp = vLayer->dataProvider();
149+
bool canCreateAttrIndex = dp && ( dp->capabilities() & QgsVectorDataProvider::CreateAttributeIndex );
150+
if ( canCreateAttrIndex )
151+
{
152+
mCreateIndexCheckBox->setEnabled( true );
153+
}
154+
else
155+
{
156+
mCreateIndexCheckBox->setEnabled( false );
157+
mCreateIndexCheckBox->setChecked( false );
158+
}
159+
160+
if ( !mUseCustomPrefix->isChecked() )
161+
{
162+
mCustomPrefix->setText( layer->name() + "_" );
163+
}
164+
}

0 commit comments

Comments
 (0)