Skip to content
Permalink
Browse files

add missing metadata fields about contacts and extent (#5878)

  • Loading branch information
Gustry authored and timlinux committed Dec 15, 2017
1 parent 0c7cf21 commit 9eb938c61c69e822e0d486085d1e1832f370dd6f
Showing with 385 additions and 182 deletions.
  1. +131 −40 src/gui/qgsmetadatawidget.cpp
  2. +3 −3 src/gui/qgsmetadatawidget.h
  3. +251 −139 src/ui/qgsmetadatawidget.ui
@@ -23,6 +23,7 @@
#include <QInputDialog>
#include <QStringListModel>

#include "qgsbox3d.h"
#include "qgsmetadatawidget.h"
#include "qgslogger.h"
#include "qgslayermetadatavalidator.h"
@@ -36,9 +37,8 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
mMetadata = layer->metadata();
tabWidget->setCurrentIndex( 0 );

// Disable the encoding and contacts
// Disable the encoding
encodingFrame->setHidden( true );
tabWidget->removeTab( 5 );

// Default categories, we want them translated, so we are not using a CSV.
mDefaultCategories << tr( "Farming" ) << tr( "Climatology Meteorology Atmosphere" ) << tr( "Location" ) << tr( "Intelligence Military" ) << tr( "Transportation" ) << tr( "Structure" ) << tr( "Boundaries" );
@@ -65,6 +65,11 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
tabConstraints->setModel( mConstraintsModel );
tabConstraints->setItemDelegate( new ConstraintItemDelegate( this ) );

// Extent
selectionCrs->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
dateTimeFrom->setAllowNull( true );
dateTimeTo->setAllowNull( true );

// Setup the link view
mLinksModel = new QStandardItemModel( tabLinks );
mLinksModel->setColumnCount( 7 );
@@ -90,9 +95,9 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
connect( btnAddConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::addConstraint );
connect( btnRemoveConstraint, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedConstraint );
connect( btnAutoCrs, &QPushButton::clicked, this, &QgsMetadataWidget::fillCrsFromLayer );
connect( btnAddContact, &QPushButton::clicked, this, &QgsMetadataWidget::addContact );
connect( btnRemoveContact, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedContact );
connect( tabContacts, &QTableWidget::itemSelectionChanged, this, &QgsMetadataWidget::updateContactDetails );
connect( selectionCrs, &QgsProjectionSelectionWidget::crsChanged, this, &QgsMetadataWidget::toggleExtentSelector );
connect( btnAddAddress, &QPushButton::clicked, this, &QgsMetadataWidget::addAddress );
connect( btnRemoveAddress, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedAddress );
connect( btnAddLink, &QPushButton::clicked, this, &QgsMetadataWidget::addLink );
connect( btnRemoveLink, &QPushButton::clicked, this, &QgsMetadataWidget::removeSelectedLink );
connect( btnAddHistory, &QPushButton::clicked, this, &QgsMetadataWidget::addHistory );
@@ -103,7 +108,6 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )

fillComboBox();
setPropertiesFromLayer();
updateContactDetails();
}

void QgsMetadataWidget::fillSourceFromLayer() const
@@ -196,56 +200,51 @@ void QgsMetadataWidget::removeSelectedConstraint() const
mConstraintsModel->removeRow( selectedRows[0].row() );
}

void QgsMetadataWidget::fillCrsFromLayer() const
void QgsMetadataWidget::toggleExtentSelector() const
{
selectionCrs->setCrs( mLayer->crs() );
spatialExtentSelector->setEnabled( selectionCrs->crs().isValid() );
spatialExtentSelector->setOutputCrs( selectionCrs->crs() );
}

void QgsMetadataWidget::addContact() const
void QgsMetadataWidget::addAddress() const
{
int row = tabContacts->rowCount();
tabContacts->setRowCount( row + 1 );
int row = tabAddresses->rowCount();
tabAddresses->setRowCount( row + 1 );
QTableWidgetItem *pCell = nullptr;

// Name
pCell = new QTableWidgetItem( QString( tr( "unnamed %1" ) ).arg( row + 1 ) );
tabContacts->setItem( row, 0, pCell );
// Type
pCell = new QTableWidgetItem( QString( tr( "postal" ) ) );
tabAddresses->setItem( row, 0, pCell );

// Address
tabAddresses->setItem( row, 1, new QTableWidgetItem() );

// Organization
pCell = new QTableWidgetItem();
tabContacts->setItem( row, 1, pCell );
// postal code
tabAddresses->setItem( row, 2, new QTableWidgetItem() );

// City
tabAddresses->setItem( row, 3, new QTableWidgetItem() );

// Admin area
tabAddresses->setItem( row, 4, new QTableWidgetItem() );

// Set last item selected
tabContacts->selectRow( row );
// Country
tabAddresses->setItem( row, 5, new QTableWidgetItem() );
}

void QgsMetadataWidget::removeSelectedContact() const
void QgsMetadataWidget::removeSelectedAddress() const
{
QItemSelectionModel *selectionModel = tabContacts->selectionModel();
QItemSelectionModel *selectionModel = tabAddresses->selectionModel();
const QModelIndexList selectedRows = selectionModel->selectedRows();
for ( int i = 0; i < selectedRows.size() ; i++ )
{
tabContacts->model()->removeRow( selectedRows[i].row() );
tabAddresses->model()->removeRow( selectedRows[i].row() );
}
}

void QgsMetadataWidget::updateContactDetails() const
void QgsMetadataWidget::fillCrsFromLayer() const
{
QItemSelectionModel *selectionModel = tabContacts->selectionModel();
const QModelIndexList selectedRows = selectionModel->selectedRows();

if ( ! selectedRows.isEmpty() )
{
panelDetails->setDisabled( false );
lineEditContactName->setText( tabContacts->item( selectedRows[0].row(), 0 )->text() );
lineEditContactOrganization->setText( tabContacts->item( selectedRows[0].row(), 1 )->text() );
}
else
{
panelDetails->setDisabled( true );
lineEditContactName->clear();
lineEditContactOrganization->clear();
}
selectionCrs->setCrs( mLayer->crs() );
}

void QgsMetadataWidget::addLink() const
@@ -414,9 +413,57 @@ void QgsMetadataWidget::setPropertiesFromLayer() const
{
selectionCrs->setCrs( mMetadata.crs() );
}
else
toggleExtentSelector();

// Spatial extent
const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = mMetadata.extent().spatialExtents();
if ( ! spatialExtents.isEmpty() )
{
selectionCrs->setOptionVisible( QgsProjectionSelectionWidget::CrsNotSet, true );
// Even if it's a list, it's supposed to store the same extent in different CRS.
spatialExtentSelector->setCurrentExtent( spatialExtents.at( 0 ).bounds.toRectangle(), spatialExtents.at( 0 ).extentCrs );
spatialExtentSelector->setOutputCrs( spatialExtents.at( 0 ).extentCrs );
spinBoxZMaximum->setValue( spatialExtents.at( 0 ).bounds.zMaximum() );
spinBoxZMinimum->setValue( spatialExtents.at( 0 ).bounds.zMinimum() );
}

// Temporal extent
const QList<QgsDateTimeRange> &temporalExtents = mMetadata.extent().temporalExtents();
if ( ! temporalExtents.isEmpty() )
{
// Even if it's a list, it seems we use only one for now (cf discussion with Tom)
dateTimeFrom->setDateTime( temporalExtents.at( 0 ).begin() );
dateTimeFrom->setDateTime( temporalExtents.at( 0 ).end() );
}

// Contacts
const QList<QgsLayerMetadata::Contact> &contacts = mMetadata.contacts();
if ( ! contacts.isEmpty() )
{
// Only one contact supported in the UI for now
const QgsLayerMetadata::Contact &contact = contacts.at( 0 );
lineEditContactName->setText( contact.name );
lineEditContactEmail->setText( contact.email );
lineEditContactFax->setText( contact.fax );
lineEditContactOrganization->setText( contact.organization );
lineEditContactPosition->setText( contact.position );
lineEditContactVoice->setText( contact.voice );
if ( comboContactRole->findText( contact.role ) == -1 )
{
comboContactRole->addItem( contact.role );
}
comboContactRole->setCurrentIndex( comboContactRole->findText( contact.role ) );
tabAddresses->setRowCount( 0 );
const QList<QgsLayerMetadata::Address> &addresses = contact.addresses;
for ( const QgsLayerMetadata::Address &address : addresses )
{
int currentRow = tabKeywords->rowCount() - 1;
tabAddresses->item( currentRow, 0 )->setText( address.type );
tabAddresses->item( currentRow, 1 )->setText( address.address );
tabAddresses->item( currentRow, 2 )->setText( address.postalCode );
tabAddresses->item( currentRow, 3 )->setText( address.city );
tabAddresses->item( currentRow, 4 )->setText( address.administrativeArea );
tabAddresses->item( currentRow, 5 )->setText( address.country );
}
}

// Links
@@ -483,6 +530,50 @@ void QgsMetadataWidget::saveMetadata( QgsLayerMetadata &layerMetadata ) const
// CRS
layerMetadata.setCrs( selectionCrs->crs() );

// Extent
struct QgsLayerMetadata::SpatialExtent spatialExtent = QgsLayerMetadata::SpatialExtent();
spatialExtent.bounds = QgsBox3d( spatialExtentSelector->outputExtent() );
spatialExtent.bounds.setZMinimum( spinBoxZMinimum->value() );
spatialExtent.bounds.setZMaximum( spinBoxZMaximum->value() );
spatialExtent.extentCrs = spatialExtentSelector->outputCrs();
QList<QgsLayerMetadata::SpatialExtent> spatialExtents;
spatialExtents.append( spatialExtent );
QList<QgsDateTimeRange> temporalExtents;
temporalExtents.append( QgsDateTimeRange( dateTimeFrom->dateTime(), dateTimeTo->dateTime() ) );
struct QgsLayerMetadata::Extent extent = QgsLayerMetadata::Extent();
extent.setSpatialExtents( spatialExtents );
extent.setTemporalExtents( temporalExtents );
layerMetadata.setExtent( extent );

// Contacts, only one contact supported in the UI for now.
// We don't want to lost data if more than one contact, so we update only the first one.
QList<QgsLayerMetadata::Contact> contacts = mMetadata.contacts();
if ( contacts.size() > 0 )
contacts.removeFirst();
struct QgsLayerMetadata::Contact contact = QgsLayerMetadata::Contact();
contact.email = lineEditContactEmail->text();
contact.position = lineEditContactPosition->text();
contact.fax = lineEditContactFax->text();
contact.voice = lineEditContactVoice->text();
contact.name = lineEditContactName->text();
contact.organization = lineEditContactOrganization->text();
contact.role = comboContactRole->currentText();
QList<QgsLayerMetadata::Address> addresses;
for ( int i = 0; i < tabAddresses->rowCount() ; i++ )
{
struct QgsLayerMetadata::Address address = QgsLayerMetadata::Address();
address.type = tabAddresses->item( i, 0 )->text();
address.address = tabAddresses->item( i, 1 )->text();
address.postalCode = tabAddresses->item( i, 2 )->text();
address.city = tabAddresses->item( i, 3 )->text();
address.administrativeArea = tabAddresses->item( i, 4 )->text();
address.country = tabAddresses->item( i, 5 )->text();
addresses.append( address );
}
contact.addresses = addresses;
contacts.insert( 0, contact );
layerMetadata.setContacts( contacts );

// Links
QList<QgsLayerMetadata::Link> links;
for ( int row = 0; row < mLinksModel->rowCount() ; row++ )
@@ -101,13 +101,13 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
void removeSelectedRight() const;
void addConstraint() const;
void removeSelectedConstraint() const;
void addContact() const;
void removeSelectedContact() const;
void toggleExtentSelector() const;
void addAddress() const;
void removeSelectedAddress() const;
void addLink() const;
void removeSelectedLink() const;
void addHistory();
void removeSelectedHistory() const;
void updateContactDetails() const;
void fillComboBox() const;
void setPropertiesFromLayer() const;
void syncFromCategoriesTabToKeywordsTab() const;

0 comments on commit 9eb938c

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