-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3532 from pvalsecc/discover_relations
Add auto-discovery of relations for PostgresQL and SpatiaLite
- Loading branch information
Showing
22 changed files
with
613 additions
and
9 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
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,61 @@ | ||
/*************************************************************************** | ||
qgsdiscoverrelationsdlg.cpp | ||
--------------------- | ||
begin : September 2016 | ||
copyright : (C) 2016 by Patrick Valsecchi | ||
email : patrick dot valsecchi at camptocamp dot com | ||
*************************************************************************** | ||
* * | ||
* 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 "qgsdiscoverrelationsdlg.h" | ||
#include "qgsvectorlayer.h" | ||
#include "qgsrelationmanager.h" | ||
|
||
#include <QPushButton> | ||
|
||
QgsDiscoverRelationsDlg::QgsDiscoverRelationsDlg( const QList<QgsRelation>& existingRelations, const QList<QgsVectorLayer*>& layers, QWidget *parent ) | ||
: QDialog( parent ) | ||
, mLayers( layers ) | ||
{ | ||
setupUi( this ); | ||
|
||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( false ); | ||
connect( mRelationsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this, &QgsDiscoverRelationsDlg::onSelectionChanged ); | ||
|
||
mFoundRelations = QgsRelationManager::discoverRelations( existingRelations, layers ); | ||
Q_FOREACH ( const QgsRelation& relation, mFoundRelations ) addRelation( relation ); | ||
|
||
mRelationsTable->resizeColumnsToContents(); | ||
|
||
} | ||
|
||
void QgsDiscoverRelationsDlg::addRelation( const QgsRelation &rel ) | ||
{ | ||
const int row = mRelationsTable->rowCount(); | ||
mRelationsTable->insertRow( row ); | ||
mRelationsTable->setItem( row, 0, new QTableWidgetItem( rel.name() ) ); | ||
mRelationsTable->setItem( row, 1, new QTableWidgetItem( rel.referencingLayer()->name() ) ); | ||
mRelationsTable->setItem( row, 2, new QTableWidgetItem( rel.fieldPairs().at( 0 ).referencingField() ) ); | ||
mRelationsTable->setItem( row, 3, new QTableWidgetItem( rel.referencedLayer()->name() ) ); | ||
mRelationsTable->setItem( row, 4, new QTableWidgetItem( rel.fieldPairs().at( 0 ).referencedField() ) ); | ||
} | ||
|
||
QList<QgsRelation> QgsDiscoverRelationsDlg::relations() const | ||
{ | ||
QList<QgsRelation> result; | ||
Q_FOREACH ( const QModelIndex& row, mRelationsTable->selectionModel()->selectedRows() ) | ||
{ | ||
result.append( mFoundRelations.at( row.row() ) ); | ||
} | ||
return result; | ||
} | ||
|
||
void QgsDiscoverRelationsDlg::onSelectionChanged() | ||
{ | ||
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( mRelationsTable->selectionModel()->hasSelection() ); | ||
} |
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,53 @@ | ||
/*************************************************************************** | ||
qgsdiscoverrelationsdlg.h | ||
--------------------- | ||
begin : September 2016 | ||
copyright : (C) 2016 by Patrick Valsecchi | ||
email : patrick dot valsecchi at camptocamp dot com | ||
*************************************************************************** | ||
* * | ||
* 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 QGSDISCOVERRELATIONSDLG_H | ||
#define QGSDISCOVERRELATIONSDLG_H | ||
|
||
#include <QDialog> | ||
#include "ui_qgsdiscoverrelationsdlgbase.h" | ||
#include "qgsrelation.h" | ||
|
||
class QgsRelationManager; | ||
class QgsVectorLayer; | ||
|
||
/** | ||
* Shows the list of relations discovered from the providers. | ||
* | ||
* The user can select some of them to add them to his project. | ||
*/ | ||
class APP_EXPORT QgsDiscoverRelationsDlg : public QDialog, private Ui::QgsDiscoverRelationsDlgBase | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
explicit QgsDiscoverRelationsDlg( const QList<QgsRelation>& existingRelations, const QList<QgsVectorLayer*>& layers, QWidget *parent = nullptr ); | ||
|
||
/** | ||
* Get the selected relations. | ||
*/ | ||
QList<QgsRelation> relations() const; | ||
|
||
private slots: | ||
void onSelectionChanged(); | ||
|
||
private: | ||
QList<QgsVectorLayer*> mLayers; | ||
QList<QgsRelation> mFoundRelations; | ||
|
||
void addRelation( const QgsRelation &rel ); | ||
|
||
}; | ||
|
||
#endif // QGSDISCOVERRELATIONSDLG_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
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.