20 #include <QPushButton> 23 #include <QInputDialog> 24 #include <QStringListModel> 40 tabWidget->setCurrentIndex( 0 );
43 encodingFrame->setHidden(
true );
46 mDefaultCategories << tr(
"Farming" ) << tr(
"Climatology Meteorology Atmosphere" ) << tr(
"Location" ) << tr(
"Intelligence Military" ) << tr(
"Transportation" ) << tr(
"Structure" ) << tr(
"Boundaries" );
47 mDefaultCategories << tr(
"Inland Waters" ) << tr(
"Planning Cadastre" ) << tr(
"Geoscientific Information" ) << tr(
"Elevation" ) << tr(
"Health" ) << tr(
"Biota" ) << tr(
"Oceans" ) << tr(
"Environment" );
48 mDefaultCategories << tr(
"Utilities Communication" ) << tr(
"Economy" ) << tr(
"Society" ) << tr(
"Imagery Base Maps Earth Cover" );
49 mDefaultCategoriesModel =
new QStringListModel( mDefaultCategories );
50 mDefaultCategoriesModel->sort( 0 );
51 listDefaultCategories->setModel( mDefaultCategoriesModel );
54 mCategoriesModel =
new QStringListModel( listCategories );
55 listCategories->setModel( mCategoriesModel );
58 mRightsModel =
new QStringListModel( listRights );
59 listRights->setModel( mRightsModel );
62 mConstraintsModel =
new QStandardItemModel( tabConstraints );
63 mConstraintsModel->setColumnCount( 2 );
64 QStringList constraintheaders;
65 constraintheaders << tr(
"Type" ) << tr(
"Constraint" );
66 mConstraintsModel->setHorizontalHeaderLabels( constraintheaders );
67 tabConstraints->setModel( mConstraintsModel );
71 dateTimeFrom->setAllowNull(
true );
72 dateTimeTo->setAllowNull(
true );
75 mLinksModel =
new QStandardItemModel( tabLinks );
76 mLinksModel->setColumnCount( 7 );
77 QStringList headers = QStringList();
78 headers << tr(
"Name" ) << tr(
"Type" ) << tr(
"URL" ) << tr(
"Description" ) << tr(
"Format" ) << tr(
"MIME" ) << tr(
"Size" );
79 mLinksModel->setHorizontalHeaderLabels( headers );
80 tabLinks->setModel( mLinksModel );
84 mHistoryModel =
new QStringListModel( listHistory );
85 listHistory->setModel( mHistoryModel );
88 connect( tabWidget, &QTabWidget::currentChanged,
this, &QgsMetadataWidget::updatePanel );
89 connect( btnAutoSource, &QPushButton::clicked,
this, &QgsMetadataWidget::fillSourceFromLayer );
90 connect( btnAddVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::addVocabulary );
91 connect( btnRemoveVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedVocabulary );
92 connect( btnAddRight, &QPushButton::clicked,
this, &QgsMetadataWidget::addRight );
93 connect( btnRemoveRight, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedRight );
94 connect( btnAddLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::addLicence );
95 connect( btnRemoveLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLicence );
96 connect( btnAddConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::addConstraint );
97 connect( btnRemoveConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedConstraint );
98 connect( btnSetCrsFromLayer, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromLayer );
99 connect( btnSetCrsFromProvider, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromProvider );
100 connect( btnAddAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::addAddress );
101 connect( btnRemoveAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedAddress );
102 connect( btnAddLink, &QPushButton::clicked,
this, &QgsMetadataWidget::addLink );
103 connect( btnRemoveLink, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLink );
104 connect( btnAddHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::addHistory );
105 connect( btnRemoveHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedHistory );
106 connect( btnNewCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addNewCategory );
107 connect( btnAddDefaultCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addDefaultCategories );
108 connect( btnRemoveCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedCategories );
113 btnAutoSource->setEnabled(
false );
114 btnAutoEncoding->setEnabled(
false );
115 btnSetCrsFromLayer->setEnabled(
false );
136 type = tr(
"dataset" );
137 typeUpper = tr(
"Dataset" );
138 mEncodingFrame->show();
139 mAuthorFrame->hide();
140 btnAutoSource->setEnabled( mLayer );
144 type = tr(
"project" );
145 typeUpper = tr(
"Project" );
146 mEncodingFrame->hide();
147 mAuthorFrame->show();
148 tabWidget->removeTab( 4 );
149 tabWidget->removeTab( 3 );
150 btnAutoSource->setEnabled(
true );
154 mIdLabel->setText( tr(
"This page describes the basic attribution of the %1. Please use the tooltips for more information." ).arg( type ) );
155 mLabelCategories->setText( tr(
"%1 categories." ).arg( typeUpper ) );
156 mLabelContact->setText( tr(
"Contacts related to the %1." ).arg( type ) );
157 mLabelLinks->setText( tr(
"Links describe ancillary resources and information related to this %1." ).arg( type ) );
158 mLabelHistory->setText( tr(
"History about the %1." ).arg( type ) );
159 labelKeywords->setText( tr(
"<html><head/><body><p>Keywords are optional, and provide a way to provide additional descriptive information about " 160 "the %1. Edits made in the categories tab will update the category entry below. For the concept, we suggest " 161 "to use a standard based vocabulary such as <a href=\"https://www.eionet.europa.eu/gemet/en/inspire-themes/\">" 162 "<span style=\" text-decoration: underline; color:#0000ff;\">GEMET.</span></a></p></body></html>" ).arg( type ) );
163 btnAutoSource->setText( tr(
"Set from %1" ).arg( mMode ==
LayerMetadata ? tr(
"layer" ) : tr(
"project" ) ) );
171 if ( dynamic_cast< const QgsLayerMetadata * >( metadata ) && mMode !=
LayerMetadata )
173 else if ( dynamic_cast< const QgsProjectMetadata * >( metadata ) && mMode !=
ProjectMetadata )
176 mMetadata.reset( metadata->
clone() );
182 std::unique_ptr< QgsAbstractMetadataBase > md;
186 md = qgis::make_unique< QgsLayerMetadata >();
190 md = qgis::make_unique< QgsProjectMetadata >();
198 void QgsMetadataWidget::fillSourceFromLayer()
216 void QgsMetadataWidget::addVocabulary()
218 int row = tabKeywords->rowCount();
219 tabKeywords->setRowCount( row + 1 );
220 QTableWidgetItem *pCell =
nullptr;
223 pCell =
new QTableWidgetItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) );
224 tabKeywords->setItem( row, 0, pCell );
227 pCell =
new QTableWidgetItem();
228 tabKeywords->setItem( row, 1, pCell );
231 void QgsMetadataWidget::removeSelectedVocabulary()
233 QItemSelectionModel *selectionModel = tabKeywords->selectionModel();
234 const QModelIndexList selectedRows = selectionModel->selectedRows();
235 for (
int i = 0; i < selectedRows.size() ; i++ )
237 tabKeywords->model()->removeRow( selectedRows[i].row() );
241 void QgsMetadataWidget::addLicence()
243 QString newLicence = QInputDialog::getItem(
this, tr(
"New Licence" ), tr(
"New Licence" ),
parseLicenses(), 0,
true );
244 if ( tabLicenses->findItems( newLicence, Qt::MatchExactly ).isEmpty() )
246 int row = tabLicenses->rowCount();
247 tabLicenses->setRowCount( row + 1 );
248 QTableWidgetItem *pCell =
new QTableWidgetItem( newLicence );
249 tabLicenses->setItem( row, 0, pCell );
253 void QgsMetadataWidget::removeSelectedLicence()
255 QItemSelectionModel *selectionModel = tabLicenses->selectionModel();
256 const QModelIndexList selectedRows = selectionModel->selectedRows();
257 for (
int i = 0; i < selectedRows.size() ; i++ )
259 tabLicenses->model()->removeRow( selectedRows[i].row() );
263 void QgsMetadataWidget::addRight()
265 QString newRight = QInputDialog::getText(
this, tr(
"New Right" ), tr(
"New Right" ) );
266 QStringList existingRights = mRightsModel->stringList();
267 if ( ! existingRights.contains( newRight ) )
269 existingRights.append( newRight );
270 mRightsModel->setStringList( existingRights );
274 void QgsMetadataWidget::removeSelectedRight()
276 QItemSelectionModel *selection = listRights->selectionModel();
277 if ( selection->hasSelection() )
279 QModelIndex indexElementSelectionne = selection->currentIndex();
281 QVariant item = mRightsModel->data( indexElementSelectionne, Qt::DisplayRole );
282 QStringList list = mRightsModel->stringList();
283 list.removeOne( item.toString() );
284 mRightsModel->setStringList( list );
288 void QgsMetadataWidget::addConstraint()
290 int row = mConstraintsModel->rowCount();
291 mConstraintsModel->setItem( row, 0,
new QStandardItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) ) );
292 mConstraintsModel->setItem( row, 1,
new QStandardItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) ) );
295 void QgsMetadataWidget::removeSelectedConstraint()
297 const QModelIndexList selectedRows = tabConstraints->selectionModel()->selectedRows();
298 mConstraintsModel->removeRow( selectedRows[0].row() );
303 if ( ( mCrs.
isValid() ) && ( mLayer ) )
305 lblCurrentCrs->setText( tr(
"CRS: %1 - %2" ).arg( mCrs.
authid(), mCrs.
description() ) );
306 spatialExtentSelector->setEnabled(
true );
307 spatialExtentSelector->setOutputCrs( mCrs );
311 lblCurrentCrsStatus->setText( tr(
"Same as layer properties and provider." ) );
315 lblCurrentCrsStatus->setText( tr(
"Same as layer properties but different than the provider." ) );
319 lblCurrentCrsStatus->setText( tr(
"Same as the provider but different than the layer properties." ) );
323 lblCurrentCrsStatus->setText( tr(
"Does not match either layer properties or the provider." ) );
328 lblCurrentCrs->setText( tr(
"CRS: Not set." ) );
329 lblCurrentCrsStatus->setText( QString() );
330 spatialExtentSelector->setEnabled(
false );
334 void QgsMetadataWidget::addAddress()
336 int row = tabAddresses->rowCount();
337 tabAddresses->setRowCount( row + 1 );
338 QTableWidgetItem *pCell =
nullptr;
341 pCell =
new QTableWidgetItem( QString( tr(
"postal" ) ) );
342 tabAddresses->setItem( row, 0, pCell );
345 tabAddresses->setItem( row, 1,
new QTableWidgetItem() );
348 tabAddresses->setItem( row, 2,
new QTableWidgetItem() );
351 tabAddresses->setItem( row, 3,
new QTableWidgetItem() );
354 tabAddresses->setItem( row, 4,
new QTableWidgetItem() );
357 tabAddresses->setItem( row, 5,
new QTableWidgetItem() );
360 void QgsMetadataWidget::removeSelectedAddress()
362 QItemSelectionModel *selectionModel = tabAddresses->selectionModel();
363 const QModelIndexList selectedRows = selectionModel->selectedRows();
364 for (
int i = 0; i < selectedRows.size() ; i++ )
366 tabAddresses->model()->removeRow( selectedRows[i].row() );
370 void QgsMetadataWidget::fillCrsFromLayer()
372 mCrs = mLayer->
crs();
376 void QgsMetadataWidget::fillCrsFromProvider()
382 void QgsMetadataWidget::addLink()
384 int row = mLinksModel->rowCount();
385 mLinksModel->setItem( row, 0,
new QStandardItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) ) );
386 mLinksModel->setItem( row, 1,
new QStandardItem() );
387 mLinksModel->setItem( row, 2,
new QStandardItem() );
388 mLinksModel->setItem( row, 3,
new QStandardItem() );
389 mLinksModel->setItem( row, 4,
new QStandardItem() );
390 mLinksModel->setItem( row, 5,
new QStandardItem() );
391 mLinksModel->setItem( row, 6,
new QStandardItem() );
394 void QgsMetadataWidget::removeSelectedLink()
396 const QModelIndexList selectedRows = tabLinks->selectionModel()->selectedRows();
397 mLinksModel->removeRow( selectedRows[0].row() );
400 void QgsMetadataWidget::addHistory()
402 QString newHistory = QInputDialog::getText(
this, tr(
"New History" ), tr(
"New History" ) );
403 QStringList existingHistory = mHistoryModel->stringList();
404 if ( ! existingHistory.contains( newHistory ) )
406 existingHistory.append( newHistory );
407 mHistoryModel->setStringList( existingHistory );
411 void QgsMetadataWidget::removeSelectedHistory()
413 QItemSelectionModel *selection = listHistory->selectionModel();
414 if ( selection->hasSelection() )
416 QModelIndex indexElementSelectionne = selection->currentIndex();
418 QVariant item = mHistoryModel->data( indexElementSelectionne, Qt::DisplayRole );
419 QStringList list = mHistoryModel->stringList();
420 list.removeOne( item.toString() );
421 mHistoryModel->setStringList( list );
425 void QgsMetadataWidget::fillComboBox()
430 comboType->setEditable(
true );
433 const QStringList &keys = types.keys();
435 for (
const QString &type : keys )
437 comboType->insertItem( i, type );
438 comboType->setItemData( i, types.value( type ), Qt::ToolTipRole );
444 comboLanguage->setEditable(
true );
445 comboLanguage->clear();
447 const QStringList &k = countries.keys();
449 for (
const QString &countryCode : k )
451 comboLanguage->insertItem( i, countryCode );
452 comboLanguage->setItemData( i, countries.value( countryCode ), Qt::ToolTipRole );
457 void QgsMetadataWidget::setUiFromMetadata()
460 lineEditParentId->setText( mMetadata->parentIdentifier() );
463 if ( ! mMetadata->identifier().isEmpty() )
465 lineEditIdentifier->setText( mMetadata->identifier() );
469 if ( ! mMetadata->title().isEmpty() )
471 whileBlocking( lineEditTitle )->setText( mMetadata->title() );
475 if ( ! mMetadata->type().isEmpty() )
477 if ( comboType->findText( mMetadata->type() ) == -1 )
479 comboType->addItem( mMetadata->type() );
481 comboType->setCurrentIndex( comboType->findText( mMetadata->type() ) );
485 if ( ! mMetadata->language().isEmpty() )
487 if ( comboLanguage->findText( mMetadata->language() ) == -1 )
489 comboLanguage->addItem( mMetadata->language() );
491 comboLanguage->setCurrentIndex( comboLanguage->findText( mMetadata->language() ) );
495 textEditAbstract->setPlainText( mMetadata->abstract() );
498 mCategoriesModel->setStringList( mMetadata->categories() );
501 tabKeywords->setRowCount( 0 );
502 QMapIterator<QString, QStringList> i( mMetadata->keywords() );
503 while ( i.hasNext() )
507 int currentRow = tabKeywords->rowCount() - 1;
508 tabKeywords->item( currentRow, 0 )->setText( i.key() );
509 tabKeywords->item( currentRow, 1 )->setText( i.value().join( QStringLiteral(
"," ) ) );
512 if (
QgsLayerMetadata *layerMetadata = dynamic_cast< QgsLayerMetadata * >( mMetadata.get() ) )
515 comboEncoding->setCurrentText( layerMetadata->encoding() );
518 lineEditFees->setText( layerMetadata->fees() );
521 tabLicenses->setRowCount( 0 );
522 const QStringList &licenses = layerMetadata->licenses();
523 for (
const QString &licence : licenses )
525 int currentRow = tabLicenses->rowCount();
526 tabLicenses->setRowCount( currentRow + 1 );
527 QTableWidgetItem *pCell = tabLicenses->item( currentRow, 0 );
530 pCell =
new QTableWidgetItem;
531 tabLicenses->setItem( currentRow, 0, pCell );
533 pCell->setText( licence );
537 mRightsModel->setStringList( layerMetadata->rights() );
540 const QList<QgsLayerMetadata::Constraint> &constraints = layerMetadata->constraints();
543 int row = mConstraintsModel->rowCount();
544 mConstraintsModel->setItem( row, 0,
new QStandardItem( constraint.type ) );
545 mConstraintsModel->setItem( row, 1,
new QStandardItem( constraint.constraint ) );
549 mCrs = layerMetadata->crs();
553 const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = layerMetadata->extent().spatialExtents();
554 if ( ! spatialExtents.isEmpty() )
557 spatialExtentSelector->setOutputCrs( spatialExtents.at( 0 ).extentCrs );
558 spatialExtentSelector->setOriginalExtent( spatialExtents.at( 0 ).bounds.toRectangle(), spatialExtents.at( 0 ).extentCrs );
559 spatialExtentSelector->setOutputExtentFromOriginal();
560 spinBoxZMaximum->setValue( spatialExtents.at( 0 ).bounds.zMaximum() );
561 spinBoxZMinimum->setValue( spatialExtents.at( 0 ).bounds.zMinimum() );
565 const QList<QgsDateTimeRange> &temporalExtents = layerMetadata->extent().temporalExtents();
566 if ( ! temporalExtents.isEmpty() )
569 dateTimeFrom->setDateTime( temporalExtents.at( 0 ).begin() );
570 dateTimeTo->setDateTime( temporalExtents.at( 0 ).end() );
574 dateTimeFrom->clear();
578 else if (
QgsProjectMetadata *projectMetadata = dynamic_cast< QgsProjectMetadata * >( mMetadata.get() ) )
580 mLineEditAuthor->setText( projectMetadata->author() );
581 mCreationDateTimeEdit->setDateTime( projectMetadata->creationDateTime() );
585 const QList<QgsAbstractMetadataBase::Contact> &contacts = mMetadata->contacts();
586 if ( ! contacts.isEmpty() )
590 lineEditContactName->setText( contact.
name );
591 lineEditContactEmail->setText( contact.
email );
592 lineEditContactFax->setText( contact.
fax );
593 lineEditContactOrganization->setText( contact.
organization );
594 lineEditContactPosition->setText( contact.
position );
595 lineEditContactVoice->setText( contact.
voice );
596 if ( comboContactRole->findText( contact.
role ) == -1 )
598 comboContactRole->addItem( contact.
role );
600 comboContactRole->setCurrentIndex( comboContactRole->findText( contact.
role ) );
601 tabAddresses->setRowCount( 0 );
602 const QList<QgsAbstractMetadataBase::Address> &addresses = contact.
addresses;
605 int currentRow = tabAddresses->rowCount();
606 tabAddresses->setRowCount( currentRow + 1 );
607 tabAddresses->setItem( currentRow, 0,
new QTableWidgetItem( address.type ) );
608 tabAddresses->setItem( currentRow, 1,
new QTableWidgetItem( address.address ) );
609 tabAddresses->setItem( currentRow, 2,
new QTableWidgetItem( address.postalCode ) );
610 tabAddresses->setItem( currentRow, 3,
new QTableWidgetItem( address.city ) );
611 tabAddresses->setItem( currentRow, 4,
new QTableWidgetItem( address.administrativeArea ) );
612 tabAddresses->setItem( currentRow, 5,
new QTableWidgetItem( address.country ) );
617 const QList<QgsAbstractMetadataBase::Link> &links = mMetadata->links();
618 mLinksModel->setRowCount( 0 );
621 int row = mLinksModel->rowCount();
622 mLinksModel->setItem( row, 0,
new QStandardItem( link.name ) );
623 mLinksModel->setItem( row, 1,
new QStandardItem( link.type ) );
624 mLinksModel->setItem( row, 2,
new QStandardItem( link.url ) );
625 mLinksModel->setItem( row, 3,
new QStandardItem( link.description ) );
626 mLinksModel->setItem( row, 4,
new QStandardItem( link.format ) );
627 mLinksModel->setItem( row, 5,
new QStandardItem( link.mimeType ) );
628 mLinksModel->setItem( row, 6,
new QStandardItem( link.size ) );
632 mHistoryModel->setStringList( mMetadata->history() );
642 metadata->
setTitle( lineEditTitle->text() );
643 metadata->
setType( comboType->currentText() );
644 metadata->
setLanguage( comboLanguage->currentText() );
645 metadata->
setAbstract( textEditAbstract->toPlainText() );
648 syncFromCategoriesTabToKeywordsTab();
649 QMap<QString, QStringList> keywords;
650 for (
int i = 0; i < tabKeywords->rowCount() ; i++ )
652 keywords.insert( tabKeywords->item( i, 0 )->text(), tabKeywords->item( i, 1 )->text().split(
',' ) );
662 layerMetadata->
setFees( lineEditFees->text() );
665 QStringList licenses;
666 for (
int i = 0; i < tabLicenses->rowCount() ; i++ )
668 licenses.append( tabLicenses->item( i, 0 )->text() );
673 layerMetadata->
setRights( mRightsModel->stringList() );
676 layerMetadata->
setEncoding( comboEncoding->currentText() );
679 QList<QgsLayerMetadata::Constraint> constraints;
680 for (
int row = 0; row < mConstraintsModel->rowCount() ; row++ )
683 constraint.
type = mConstraintsModel->item( row, 0 )->text();
684 constraint.
constraint = mConstraintsModel->item( row, 1 )->text();
685 constraints.append( constraint );
692 layerMetadata->
setCrs( mCrs );
697 spatialExtent.
bounds =
QgsBox3d( spatialExtentSelector->outputExtent() );
700 spatialExtent.
extentCrs = spatialExtentSelector->outputCrs();
701 QList<QgsLayerMetadata::SpatialExtent> spatialExtents;
702 spatialExtents.append( spatialExtent );
703 QList<QgsDateTimeRange> temporalExtents;
704 temporalExtents.append( QgsDateTimeRange( dateTimeFrom->dateTime(), dateTimeTo->dateTime() ) );
715 projectMetadata->
setAuthor( mLineEditAuthor->text() );
723 QList<QgsAbstractMetadataBase::Contact> contacts = mMetadata->contacts();
724 if ( contacts.size() > 0 )
725 contacts.removeFirst();
727 contact.
email = lineEditContactEmail->text();
728 contact.
position = lineEditContactPosition->text();
729 contact.
fax = lineEditContactFax->text();
730 contact.
voice = lineEditContactVoice->text();
731 contact.
name = lineEditContactName->text();
732 contact.
organization = lineEditContactOrganization->text();
733 contact.
role = comboContactRole->currentText();
734 QList<QgsAbstractMetadataBase::Address> addresses;
735 for (
int i = 0; i < tabAddresses->rowCount() ; i++ )
738 address.
type = tabAddresses->item( i, 0 )->text();
739 address.
address = tabAddresses->item( i, 1 )->text();
740 address.
postalCode = tabAddresses->item( i, 2 )->text();
741 address.
city = tabAddresses->item( i, 3 )->text();
743 address.
country = tabAddresses->item( i, 5 )->text();
744 addresses.append( address );
747 contacts.insert( 0, contact );
751 QList<QgsAbstractMetadataBase::Link> links;
752 for (
int row = 0; row < mLinksModel->rowCount() ; row++ )
755 link.
name = mLinksModel->item( row, 0 )->text();
756 link.
type = mLinksModel->item( row, 1 )->text();
757 link.
url = mLinksModel->item( row, 2 )->text();
758 link.
description = mLinksModel->item( row, 3 )->text();
759 link.
format = mLinksModel->item( row, 4 )->text();
760 link.
mimeType = mLinksModel->item( row, 5 )->text();
761 link.
size = mLinksModel->item( row, 6 )->text();
762 links.append( link );
767 metadata->
setHistory( mHistoryModel->stringList() );
772 std::unique_ptr< QgsAbstractMetadataBase > md(
metadata() );
774 std::unique_ptr< QgsNativeMetadataBaseValidator > validator;
778 validator = qgis::make_unique< QgsNativeMetadataValidator>();
782 validator = qgis::make_unique< QgsNativeProjectMetadataValidator>();
786 QList<QgsAbstractMetadataBaseValidator::ValidationResult> validationResults;
787 bool results = validator->validate( md.get(), validationResults );
794 errors += QLatin1String(
"<b>" ) % result.section;
795 if ( ! result.identifier.isNull() )
797 errors += QLatin1String(
" " ) % QVariant( result.identifier.toInt() + 1 ).toString();
799 errors += QLatin1String(
"</b>: " ) % result.note % QLatin1String(
"<br />" );
804 errors = QString( tr(
"Ok, it seems valid according to the QGIS Schema." ) );
808 myStyle.append( QStringLiteral(
"body { margin: 10px; }\n " ) );
809 resultsCheckMetadata->clear();
810 resultsCheckMetadata->document()->setDefaultStyleSheet( myStyle );
811 resultsCheckMetadata->setHtml( errors );
818 QMap<QString, QString> countries;
819 countries.insert( QString(), QString() );
823 if ( !file.open( QIODevice::ReadOnly ) )
825 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
831 while ( !file.atEnd() )
833 QByteArray line = file.readLine();
834 QList<QByteArray> items = line.split(
',' );
835 countries.insert( QString( items.at( 0 ).constData() ).trimmed(), QString( items.at( 1 ).constData() ).trimmed() );
840 QFile secondFile( path );
841 if ( !secondFile.open( QIODevice::ReadOnly ) )
843 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
848 secondFile.readLine();
849 while ( !secondFile.atEnd() )
851 QByteArray line = secondFile.readLine();
852 QList<QByteArray> items = line.split(
',' );
853 countries.insert( QString( items.at( 2 ).constData() ).trimmed(), QString( items.at( 0 ).constData() ).trimmed() );
861 QStringList wordList;
862 wordList.append( QString() );
866 if ( !file.open( QIODevice::ReadOnly ) )
868 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
874 while ( !file.atEnd() )
876 QByteArray line = file.readLine();
877 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
885 QStringList wordList;
886 wordList.append( QString() );
890 if ( !file.open( QIODevice::ReadOnly ) )
892 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
898 while ( !file.atEnd() )
900 QByteArray line = file.readLine();
901 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
909 QStringList wordList;
910 wordList.append( QString() );
914 if ( !file.open( QIODevice::ReadOnly ) )
916 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
920 while ( !file.atEnd() )
922 QByteArray line = file.readLine();
923 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
931 QMap<QString, QString> types;
932 types.insert( QString(), QString() );
935 if ( !file.open( QIODevice::ReadOnly ) )
937 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
941 types.insert( QString(), QString() );
942 while ( !file.atEnd() )
944 QByteArray line = file.readLine();
945 QList<QByteArray> items = line.split(
';' );
946 types.insert( items.at( 0 ).constData(), items.at( 1 ).constData() );
960 return lineEditTitle->text();
965 if ( title != lineEditTitle->text() )
981 mLayer->
setMetadata( *static_cast< QgsLayerMetadata * >( mMetadata.get() ) );
991 void QgsMetadataWidget::syncFromCategoriesTabToKeywordsTab()
993 if ( mCategoriesModel->rowCount() > 0 )
995 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
997 if ( !categories.isEmpty() )
999 row = categories.at( 0 )->row();
1005 row = tabKeywords->rowCount() - 1;
1006 tabKeywords->item( row, 0 )->setText( QStringLiteral(
"gmd:topicCategory" ) );
1008 tabKeywords->item( row, 1 )->setText( mCategoriesModel->stringList().join( QStringLiteral(
"," ) ) );
1012 void QgsMetadataWidget::updatePanel()
1014 int index = tabWidget->currentIndex();
1015 QString currentTabText = tabWidget->widget( index )->objectName();
1016 if ( currentTabText == QStringLiteral(
"tabCategoriesDialog" ) )
1020 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
1021 if ( !categories.isEmpty() )
1023 int row = categories.at( 0 )->row();
1024 mCategoriesModel->setStringList( tabKeywords->item( row, 1 )->text().split(
',' ) );
1028 mCategoriesModel->setStringList( QStringList() );
1031 else if ( currentTabText == QStringLiteral(
"tabKeywordsDialog" ) )
1035 syncFromCategoriesTabToKeywordsTab();
1037 else if ( currentTabText == QStringLiteral(
"tabValidationDialog" ) )
1043 void QgsMetadataWidget::addNewCategory()
1046 QString text = QInputDialog::getText(
this, tr(
"New Category" ),
1047 tr(
"New Category:" ), QLineEdit::Normal,
1049 if ( ok && !text.isEmpty() )
1051 QStringList list = mCategoriesModel->stringList();
1052 if ( ! list.contains( text ) )
1054 list.append( text );
1055 mCategoriesModel->setStringList( list );
1056 mCategoriesModel->sort( 0 );
1061 void QgsMetadataWidget::addDefaultCategories()
1063 const QModelIndexList selectedIndexes = listDefaultCategories->selectionModel()->selectedIndexes();
1064 QStringList defaultCategoriesList = mDefaultCategoriesModel->stringList();
1065 QStringList selectedCategories = mCategoriesModel->stringList();
1067 for (
const QModelIndex &selection : selectedIndexes )
1069 QVariant item = mDefaultCategoriesModel->data( selection, Qt::DisplayRole );
1070 defaultCategoriesList.removeOne( item.toString() );
1072 selectedCategories.append( item.toString() );
1075 mDefaultCategoriesModel->setStringList( defaultCategoriesList );
1076 mCategoriesModel->setStringList( selectedCategories );
1077 mCategoriesModel->sort( 0 );
1080 void QgsMetadataWidget::removeSelectedCategories()
1082 const QModelIndexList selectedIndexes = listCategories->selectionModel()->selectedIndexes();
1083 QStringList categories = mCategoriesModel->stringList();
1084 QStringList defaultList = mDefaultCategoriesModel->stringList();
1086 for (
const QModelIndex &selection : selectedIndexes )
1088 QVariant item = mCategoriesModel->data( selection, Qt::DisplayRole );
1089 categories.removeOne( item.toString() );
1091 if ( mDefaultCategories.contains( item.toString() ) )
1093 defaultList.append( item.toString() );
1096 mCategoriesModel->setStringList( categories );
1098 mDefaultCategoriesModel->setStringList( defaultList );
1099 mDefaultCategoriesModel->sort( 0 );
1103 : QStyledItemDelegate( parent )
1110 if ( index.column() == 1 )
1113 QComboBox *typeEditor =
new QComboBox( parent );
1114 typeEditor->setEditable(
true );
1115 QStringListModel *model =
new QStringListModel( parent );
1117 typeEditor->setModel( model );
1120 else if ( index.column() == 5 )
1123 QComboBox *mimeEditor =
new QComboBox( parent );
1124 mimeEditor->setEditable(
true );
1125 QStringListModel *model =
new QStringListModel( parent );
1127 mimeEditor->setModel( model );
1131 return QStyledItemDelegate::createEditor( parent, option, index );
1135 : QStyledItemDelegate( parent )
1142 if ( index.column() == 0 )
1145 QComboBox *typeEditor =
new QComboBox( parent );
1146 typeEditor->setEditable(
true );
1148 types << QStringLiteral(
"access" ) << QStringLiteral(
"use" ) << QStringLiteral(
"other" );
1149 QStringListModel *model =
new QStringListModel( parent );
1150 model->setStringList( types );
1151 typeEditor->setModel( model );
1155 return QStyledItemDelegate::createEditor( parent, option, index );
Base class for all map layer types.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider.
QgsLayerMetadata metadata
static QString reportStyleSheet()
Returns a standard css style sheet for reports.
A 3-dimensional box composed of x, y, z coordinates.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Create a special editor with a QCombobox in the constraint view.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
LinkItemDelegate(QObject *parent=nullptr)
LinkItemDelegate constructor.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
void setZMinimum(double z)
Sets the minimum z value.
void setMetadata(const QgsProjectMetadata &metadata)
Sets the project's metadata store.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Create a special editor with a QCombobox in the link view.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
static QgsProject * instance()
Returns the QgsProject singleton instance.
Special delegate for the constraint view in the metadata wizard.
static QString metadataPath()
Returns the path to the metadata directory.
ConstraintItemDelegate(QObject *parent=nullptr)
ConstraintItemDelegate constructor.
QString authid() const
Returns the authority identifier for the CRS.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setZMaximum(double z)
Sets the maximum z value.