Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Initial table join prototype
git-svn-id: http://svn.osgeo.org/qgis/branches/table_join_branch@13934 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
mhugent
committed
Jul 19, 2010
1 parent
2db428e
commit 9d188a5
Showing
20 changed files
with
1,080 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/*************************************************************************** | ||
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" | ||
|
||
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->getLayerID() ) ); | ||
} | ||
} | ||
} | ||
mJoinLayerComboBox->blockSignals( false ); | ||
on_mJoinLayerComboBox_currentIndexChanged( mJoinLayerComboBox->currentIndex() ); | ||
|
||
//insert possible target fields | ||
const QgsFieldMap& layerFieldMap = mLayer->pendingFields(); | ||
QgsFieldMap::const_iterator fieldIt = layerFieldMap.constBegin(); | ||
for(; fieldIt != layerFieldMap.constEnd(); ++fieldIt ) | ||
{ | ||
mTargetFieldComboBox->addItem(fieldIt.value().name(), fieldIt.key() ); | ||
} | ||
} | ||
|
||
QgsAddJoinDialog::~QgsAddJoinDialog() | ||
{ | ||
} | ||
|
||
QString QgsAddJoinDialog::joinedLayerId() const | ||
{ | ||
return mJoinLayerComboBox->itemData( mJoinLayerComboBox->currentIndex() ).toString(); | ||
} | ||
|
||
int QgsAddJoinDialog::joinField() const | ||
{ | ||
return mJoinFieldComboBox->itemData( mJoinFieldComboBox->currentIndex() ).toInt(); | ||
} | ||
|
||
QString QgsAddJoinDialog::joinFieldName() const | ||
{ | ||
return mJoinFieldComboBox->itemText( mJoinFieldComboBox->currentIndex() ); | ||
} | ||
|
||
int QgsAddJoinDialog::targetField() const | ||
{ | ||
return mTargetFieldComboBox->itemData( mTargetFieldComboBox->currentIndex() ).toInt(); | ||
} | ||
|
||
QString QgsAddJoinDialog::targetFieldName() const | ||
{ | ||
return mTargetFieldComboBox->itemText( mTargetFieldComboBox->currentIndex() ); | ||
} | ||
|
||
bool QgsAddJoinDialog::createAttributeIndex() const | ||
{ | ||
return mCreateIndexCheckBox->isChecked(); | ||
} | ||
|
||
void QgsAddJoinDialog::on_mJoinLayerComboBox_currentIndexChanged ( int index ) | ||
{ | ||
mJoinFieldComboBox->clear(); | ||
QString layerId = mJoinLayerComboBox->itemData( index ).toString(); | ||
QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); | ||
if( !layer ) | ||
{ | ||
return; | ||
} | ||
QgsVectorLayer* vLayer = dynamic_cast<QgsVectorLayer*>( layer ); | ||
if( !vLayer ) | ||
{ | ||
return; | ||
} | ||
|
||
const QgsFieldMap& layerFieldMap = vLayer->pendingFields(); | ||
QgsFieldMap::const_iterator fieldIt = layerFieldMap.constBegin(); | ||
for(; fieldIt != layerFieldMap.constEnd(); ++fieldIt ) | ||
{ | ||
mJoinFieldComboBox->addItem( fieldIt.value().name(), fieldIt.key() ); | ||
} | ||
|
||
//does provider support creation of attribute indices? | ||
QgsVectorDataProvider* dp = vLayer->dataProvider(); | ||
if( dp && (dp->capabilities() & QgsVectorDataProvider::CreateAttributeIndex) ) | ||
{ | ||
mCreateIndexCheckBox->setEnabled( true ); | ||
mCreateIndexCheckBox->setChecked( true ); | ||
} | ||
else | ||
{ | ||
mCreateIndexCheckBox->setEnabled( false ); | ||
mCreateIndexCheckBox->setChecked( false ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/*************************************************************************** | ||
qgsaddjoindialog.h | ||
------------------ | ||
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. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSADDJOINDIALOG_H | ||
#define QGSADDJOINDIALOG_H | ||
|
||
#include "ui_qgsaddjoindialogbase.h" | ||
class QgsVectorLayer; | ||
|
||
class QgsAddJoinDialog: public QDialog, private Ui::QgsAddJoinDialogBase | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsAddJoinDialog( QgsVectorLayer* layer, QWidget * parent = 0, Qt::WindowFlags f = 0 ); | ||
~QgsAddJoinDialog(); | ||
|
||
//retrieve results | ||
|
||
/**Get the id of the layer to join*/ | ||
QString joinedLayerId() const; | ||
/**Returns the index of the join field*/ | ||
int joinField() const; | ||
/**Returns the name of the join field*/ | ||
QString joinFieldName() const; | ||
/**Returns the index of the target field (join-to field)*/ | ||
int targetField() const; | ||
/**Returns the name of the target field (join-to field)*/ | ||
QString targetFieldName() const; | ||
/**Returns true if user wants to create an attribute index on the join field*/ | ||
bool createAttributeIndex() const; | ||
|
||
private slots: | ||
void on_mJoinLayerComboBox_currentIndexChanged ( int index ); | ||
|
||
private: | ||
/**Target layer*/ | ||
QgsVectorLayer* mLayer; | ||
}; | ||
|
||
|
||
#endif // QGSADDJOINDIALOG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.