22#include <QInputDialog>
23#include <QStringListModel>
27#include "moc_qgsmetadatawidget.cpp"
36 : QWidget( parent ), mLayer( layer )
39 tabWidget->setCurrentIndex( 0 );
42 encodingFrame->setHidden(
true );
44 spinBoxZMinimum->setClearValue( 0 );
45 spinBoxZMaximum->setClearValue( 0 );
48 mDefaultCategories << tr(
"Farming" ) << tr(
"Climatology Meteorology Atmosphere" ) << tr(
"Location" ) << tr(
"Intelligence Military" ) << tr(
"Transportation" ) << tr(
"Structure" ) << tr(
"Boundaries" );
49 mDefaultCategories << tr(
"Inland Waters" ) << tr(
"Planning Cadastre" ) << tr(
"Geoscientific Information" ) << tr(
"Elevation" ) << tr(
"Health" ) << tr(
"Biota" ) << tr(
"Oceans" ) << tr(
"Environment" );
50 mDefaultCategories << tr(
"Utilities Communication" ) << tr(
"Economy" ) << tr(
"Society" ) << tr(
"Imagery Base Maps Earth Cover" );
51 mDefaultCategoriesModel =
new QStringListModel( mDefaultCategories,
this );
52 mDefaultCategoriesModel->sort( 0 );
53 listDefaultCategories->setModel( mDefaultCategoriesModel );
56 mCategoriesModel =
new QStringListModel( listCategories );
57 listCategories->setModel( mCategoriesModel );
60 mRightsModel =
new QStringListModel( listRights );
61 listRights->setModel( mRightsModel );
64 mConstraintsModel =
new QStandardItemModel( tabConstraints );
65 mConstraintsModel->setColumnCount( 2 );
66 QStringList constraintheaders;
67 constraintheaders << tr(
"Type" ) << tr(
"Constraint" );
68 mConstraintsModel->setHorizontalHeaderLabels( constraintheaders );
69 tabConstraints->setModel( mConstraintsModel );
70 tabConstraints->setItemDelegate(
new ConstraintItemDelegate(
this ) );
73 dateTimeFrom->setAllowNull(
true );
74 dateTimeTo->setAllowNull(
true );
77 mLinksModel =
new QStandardItemModel( tabLinks );
78 mLinksModel->setColumnCount( 7 );
79 QStringList headers = QStringList();
80 headers << tr(
"Name" ) << tr(
"Type" ) << tr(
"URL" ) << tr(
"Description" ) << tr(
"Format" ) << tr(
"MIME" ) << tr(
"Size" );
81 mLinksModel->setHorizontalHeaderLabels( headers );
82 tabLinks->setModel( mLinksModel );
83 tabLinks->setItemDelegate(
new LinkItemDelegate(
this ) );
86 mHistoryModel =
new QStringListModel( listHistory );
87 listHistory->setModel( mHistoryModel );
91 mCreationDateTimeEdit,
92 mCreationDateTimeEdit2,
93 mPublishedDateTimeEdit,
95 mSupersededDateTimeEdit
98 w->setAllowNull(
true );
99 w->setNullRepresentation( tr(
"Not set" ) );
103 connect( tabWidget, &QTabWidget::currentChanged,
this, &QgsMetadataWidget::updatePanel );
104 connect( btnAutoSource, &QPushButton::clicked,
this, &QgsMetadataWidget::fillSourceFromLayer );
105 connect( btnAddVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::addVocabulary );
106 connect( btnRemoveVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedVocabulary );
107 connect( btnAddRight, &QPushButton::clicked,
this, &QgsMetadataWidget::addRight );
108 connect( btnRemoveRight, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedRight );
109 connect( btnAddLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::addLicence );
110 connect( btnRemoveLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLicence );
111 connect( btnAddConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::addConstraint );
112 connect( btnRemoveConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedConstraint );
113 connect( btnSetCrsFromLayer, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromLayer );
114 connect( btnSetCrsFromProvider, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromProvider );
115 connect( btnAddAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::addAddress );
116 connect( btnRemoveAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedAddress );
117 connect( btnAddLink, &QPushButton::clicked,
this, &QgsMetadataWidget::addLink );
118 connect( btnRemoveLink, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLink );
119 connect( btnAddHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::addHistory );
120 connect( btnRemoveHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedHistory );
121 connect( btnNewCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addNewCategory );
122 connect( btnAddDefaultCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addDefaultCategories );
123 connect( btnRemoveCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedCategories );
128 btnAutoSource->setEnabled(
false );
129 btnAutoEncoding->setEnabled(
false );
130 btnSetCrsFromLayer->setEnabled(
false );
151 type = tr(
"dataset" );
152 typeUpper = tr(
"Dataset" );
153 mEncodingFrame->show();
154 mAuthorFrame->hide();
155 btnAutoSource->setEnabled( mLayer );
159 type = tr(
"project" );
160 typeUpper = tr(
"Project" );
161 mEncodingFrame->hide();
162 mAuthorFrame->show();
163 tabWidget->removeTab( 4 );
164 tabWidget->removeTab( 3 );
165 btnAutoSource->setEnabled(
true );
168 connect( mCreationDateTimeEdit, &QDateTimeEdit::dateTimeChanged,
this, [=](
const QDateTime &value ) {
169 if ( value.isValid() )
170 mCreationDateTimeEdit2->setDateTime( value );
171 else if ( mCreationDateTimeEdit2->dateTime().isValid() )
172 mCreationDateTimeEdit2->clear();
174 connect( mCreationDateTimeEdit2, &QDateTimeEdit::dateTimeChanged,
this, [=](
const QDateTime &value ) {
175 if ( value.isValid() )
176 mCreationDateTimeEdit->setDateTime( value );
177 else if ( mCreationDateTimeEdit->dateTime().isValid() )
178 mCreationDateTimeEdit->clear();
184 mIdLabel->setText( tr(
"This page describes the basic attribution of the %1. Please use the tooltips for more information." ).arg( type ) );
185 mLabelCategories->setText( tr(
"%1 categories." ).arg( typeUpper ) );
186 mLabelContact->setText( tr(
"Contacts related to the %1." ).arg( type ) );
187 mLabelLinks->setText( tr(
"Links describe ancillary resources and information related to this %1." ).arg( type ) );
188 mLabelHistory->setText( tr(
"History about the %1." ).arg( type ) );
189 labelKeywords->setText( tr(
"<html><head/><body><p>Keywords are optional, and provide a way to provide additional descriptive information about "
190 "the %1. Edits made in the categories tab will update the category entry below. For the concept, we suggest "
191 "to use a standard based vocabulary such as <a href=\"https://www.eionet.europa.eu/gemet/en/inspire-themes/\">"
192 "<span style=\" text-decoration: underline; color:#0000ff;\">GEMET.</span></a></p></body></html>" )
194 btnAutoSource->setText( tr(
"Set from %1" ).arg( mMode ==
LayerMetadata ? tr(
"layer" ) : tr(
"project" ) ) );
213 std::unique_ptr<QgsAbstractMetadataBase> md;
217 md = std::make_unique<QgsLayerMetadata>();
221 md = std::make_unique<QgsProjectMetadata>();
228void QgsMetadataWidget::fillSourceFromLayer()
245void QgsMetadataWidget::addVocabulary()
247 const int row = tabKeywords->rowCount();
248 tabKeywords->setRowCount( row + 1 );
249 QTableWidgetItem *pCell =
nullptr;
252 pCell =
new QTableWidgetItem( tr(
"undefined %1" ).arg( row + 1 ) );
253 tabKeywords->setItem( row, 0, pCell );
256 pCell =
new QTableWidgetItem();
257 tabKeywords->setItem( row, 1, pCell );
260void QgsMetadataWidget::removeSelectedVocabulary()
262 QItemSelectionModel *selectionModel = tabKeywords->selectionModel();
263 const QModelIndexList selectedRows = selectionModel->selectedRows();
264 for (
int i = 0; i < selectedRows.size(); i++ )
266 tabKeywords->model()->removeRow( selectedRows[i].row() );
270void QgsMetadataWidget::addLicence()
272 QString newLicence = QInputDialog::getItem(
this, tr(
"New Licence" ), tr(
"New Licence" ),
parseLicenses(), 0,
true );
273 if ( tabLicenses->findItems( newLicence, Qt::MatchExactly ).isEmpty() )
275 const int row = tabLicenses->rowCount();
276 tabLicenses->setRowCount( row + 1 );
277 QTableWidgetItem *pCell =
new QTableWidgetItem( newLicence );
278 tabLicenses->setItem( row, 0, pCell );
282void QgsMetadataWidget::removeSelectedLicence()
284 QItemSelectionModel *selectionModel = tabLicenses->selectionModel();
285 const QModelIndexList selectedRows = selectionModel->selectedRows();
286 for (
int i = 0; i < selectedRows.size(); i++ )
288 tabLicenses->model()->removeRow( selectedRows[i].row() );
292void QgsMetadataWidget::addRight()
294 QString newRight = QInputDialog::getText(
this, tr(
"New Right" ), tr(
"New Right" ) );
295 QStringList existingRights = mRightsModel->stringList();
296 if ( !existingRights.contains( newRight ) )
298 existingRights.append( newRight );
299 mRightsModel->setStringList( existingRights );
303void QgsMetadataWidget::removeSelectedRight()
305 QItemSelectionModel *selection = listRights->selectionModel();
306 if ( selection->hasSelection() )
308 QModelIndex indexElementSelectionne = selection->currentIndex();
310 QVariant item = mRightsModel->data( indexElementSelectionne, Qt::DisplayRole );
311 QStringList list = mRightsModel->stringList();
312 list.removeOne( item.toString() );
313 mRightsModel->setStringList( list );
317void QgsMetadataWidget::addConstraint()
319 const int row = mConstraintsModel->rowCount();
320 mConstraintsModel->setItem( row, 0,
new QStandardItem( tr(
"undefined %1" ).arg( row + 1 ) ) );
321 mConstraintsModel->setItem( row, 1,
new QStandardItem( tr(
"undefined %1" ).arg( row + 1 ) ) );
324void QgsMetadataWidget::removeSelectedConstraint()
326 const QModelIndexList selectedRows = tabConstraints->selectionModel()->selectedRows();
327 if ( selectedRows.empty() )
329 mConstraintsModel->removeRow( selectedRows[0].row() );
334 if ( ( mCrs.
isValid() ) && ( mLayer ) )
337 spatialExtentSelector->setEnabled(
true );
338 spatialExtentSelector->setOutputCrs( mCrs );
342 lblCurrentCrsStatus->setText( tr(
"Same as layer properties and provider." ) );
346 lblCurrentCrsStatus->setText( tr(
"Same as layer properties but different than the provider." ) );
350 lblCurrentCrsStatus->setText( tr(
"Same as the provider but different than the layer properties." ) );
354 lblCurrentCrsStatus->setText( tr(
"Does not match either layer properties or the provider." ) );
359 lblCurrentCrs->setText( tr(
"CRS: Not set." ) );
360 lblCurrentCrsStatus->setText( QString() );
361 spatialExtentSelector->setEnabled(
false );
365void QgsMetadataWidget::addAddress()
367 const int row = tabAddresses->rowCount();
368 tabAddresses->setRowCount( row + 1 );
369 QTableWidgetItem *pCell =
nullptr;
372 pCell =
new QTableWidgetItem( tr(
"postal" ) );
373 tabAddresses->setItem( row, 0, pCell );
376 tabAddresses->setItem( row, 1,
new QTableWidgetItem() );
379 tabAddresses->setItem( row, 2,
new QTableWidgetItem() );
382 tabAddresses->setItem( row, 3,
new QTableWidgetItem() );
385 tabAddresses->setItem( row, 4,
new QTableWidgetItem() );
388 tabAddresses->setItem( row, 5,
new QTableWidgetItem() );
391void QgsMetadataWidget::removeSelectedAddress()
393 QItemSelectionModel *selectionModel = tabAddresses->selectionModel();
394 const QModelIndexList selectedRows = selectionModel->selectedRows();
395 for (
int i = 0; i < selectedRows.size(); i++ )
397 tabAddresses->model()->removeRow( selectedRows[i].row() );
401void QgsMetadataWidget::fillCrsFromLayer()
403 mCrs = mLayer->
crs();
407void QgsMetadataWidget::fillCrsFromProvider()
413void QgsMetadataWidget::addLink()
415 const int row = mLinksModel->rowCount();
416 mLinksModel->setItem( row, 0,
new QStandardItem( tr(
"undefined %1" ).arg( row + 1 ) ) );
417 mLinksModel->setItem( row, 1,
new QStandardItem() );
418 mLinksModel->setItem( row, 2,
new QStandardItem() );
419 mLinksModel->setItem( row, 3,
new QStandardItem() );
420 mLinksModel->setItem( row, 4,
new QStandardItem() );
421 mLinksModel->setItem( row, 5,
new QStandardItem() );
422 mLinksModel->setItem( row, 6,
new QStandardItem() );
425void QgsMetadataWidget::removeSelectedLink()
427 const QModelIndexList selectedRows = tabLinks->selectionModel()->selectedRows();
428 if ( selectedRows.empty() )
431 mLinksModel->removeRow( selectedRows[0].row() );
434void QgsMetadataWidget::addHistory()
436 QString newHistory = QInputDialog::getText(
this, tr(
"New History" ), tr(
"New History" ) );
437 QStringList existingHistory = mHistoryModel->stringList();
438 if ( !existingHistory.contains( newHistory ) )
440 existingHistory.append( newHistory );
441 mHistoryModel->setStringList( existingHistory );
445void QgsMetadataWidget::removeSelectedHistory()
447 QItemSelectionModel *selection = listHistory->selectionModel();
448 if ( selection->hasSelection() )
450 QModelIndex indexElementSelectionne = selection->currentIndex();
452 QVariant item = mHistoryModel->data( indexElementSelectionne, Qt::DisplayRole );
453 QStringList list = mHistoryModel->stringList();
454 list.removeOne( item.toString() );
455 mHistoryModel->setStringList( list );
459void QgsMetadataWidget::fillComboBox()
464 comboType->setEditable(
true );
467 const QStringList &keys = types.keys();
469 for (
const QString &type : keys )
471 comboType->insertItem( i, type );
472 comboType->setItemData( i, types.value( type ), Qt::ToolTipRole );
478 comboLanguage->setEditable(
true );
479 comboLanguage->clear();
481 const QStringList &k = countries.keys();
483 for (
const QString &countryCode : k )
485 comboLanguage->insertItem( i, countryCode );
486 comboLanguage->setItemData( i, countries.value( countryCode ), Qt::ToolTipRole );
491void QgsMetadataWidget::setUiFromMetadata()
494 lineEditParentId->setText( mMetadata->parentIdentifier() );
497 if ( !mMetadata->identifier().isEmpty() )
499 lineEditIdentifier->setText( mMetadata->identifier() );
503 if ( !mMetadata->title().isEmpty() )
505 whileBlocking( lineEditTitle )->setText( mMetadata->title() );
509 if ( !mMetadata->type().isEmpty() )
511 if ( comboType->findText( mMetadata->type() ) == -1 )
513 comboType->addItem( mMetadata->type() );
515 comboType->setCurrentIndex( comboType->findText( mMetadata->type() ) );
519 if ( !mMetadata->language().isEmpty() )
521 if ( comboLanguage->findText( mMetadata->language() ) == -1 )
523 comboLanguage->addItem( mMetadata->language() );
525 comboLanguage->setCurrentIndex( comboLanguage->findText( mMetadata->language() ) );
529 textEditAbstract->setPlainText( mMetadata->abstract() );
532 mCategoriesModel->setStringList( mMetadata->categories() );
535 tabKeywords->setRowCount( 0 );
536 QMapIterator<QString, QStringList> i( mMetadata->keywords() );
537 while ( i.hasNext() )
541 int currentRow = tabKeywords->rowCount() - 1;
542 tabKeywords->item( currentRow, 0 )->setText( i.key() );
543 tabKeywords->item( currentRow, 1 )->setText( i.value().join( QLatin1Char(
',' ) ) );
549 comboEncoding->setCurrentText( layerMetadata->encoding() );
552 lineEditFees->setText( layerMetadata->fees() );
555 tabLicenses->setRowCount( 0 );
556 const QStringList &licenses = layerMetadata->licenses();
557 for (
const QString &licence : licenses )
559 int currentRow = tabLicenses->rowCount();
560 tabLicenses->setRowCount( currentRow + 1 );
561 QTableWidgetItem *pCell = tabLicenses->item( currentRow, 0 );
564 pCell =
new QTableWidgetItem;
565 tabLicenses->setItem( currentRow, 0, pCell );
567 pCell->setText( licence );
571 mRightsModel->setStringList( layerMetadata->rights() );
574 mConstraintsModel->clear();
575 const QList<QgsLayerMetadata::Constraint> &constraints = layerMetadata->constraints();
578 const int row = mConstraintsModel->rowCount();
579 mConstraintsModel->setItem( row, 0,
new QStandardItem( constraint.type ) );
580 mConstraintsModel->setItem( row, 1,
new QStandardItem( constraint.constraint ) );
584 mCrs = layerMetadata->crs();
588 const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = layerMetadata->extent().spatialExtents();
589 if ( !spatialExtents.isEmpty() )
592 spatialExtentSelector->setOutputCrs( spatialExtents.at( 0 ).extentCrs );
593 spatialExtentSelector->setOriginalExtent( spatialExtents.at( 0 ).bounds.toRectangle(), spatialExtents.at( 0 ).extentCrs );
594 spatialExtentSelector->setOutputExtentFromOriginal();
595 spinBoxZMaximum->setValue( spatialExtents.at( 0 ).bounds.zMaximum() );
596 spinBoxZMinimum->setValue( spatialExtents.at( 0 ).bounds.zMinimum() );
600 const QList<QgsDateTimeRange> &temporalExtents = layerMetadata->extent().temporalExtents();
601 if ( !temporalExtents.isEmpty() )
604 dateTimeFrom->setDateTime( temporalExtents.at( 0 ).begin() );
605 dateTimeTo->setDateTime( temporalExtents.at( 0 ).end() );
609 dateTimeFrom->clear();
615 mLineEditAuthor->setText( projectMetadata->author() );
619 const QList<QgsAbstractMetadataBase::Contact> &contacts = mMetadata->contacts();
620 if ( !contacts.isEmpty() )
624 lineEditContactName->setText( contact.
name );
625 lineEditContactEmail->setText( contact.
email );
626 lineEditContactFax->setText( contact.
fax );
627 lineEditContactOrganization->setText( contact.
organization );
628 lineEditContactPosition->setText( contact.
position );
629 lineEditContactVoice->setText( contact.
voice );
630 if ( comboContactRole->findText( contact.
role ) == -1 )
632 comboContactRole->addItem( contact.
role );
634 comboContactRole->setCurrentIndex( comboContactRole->findText( contact.
role ) );
635 tabAddresses->setRowCount( 0 );
636 const QList<QgsAbstractMetadataBase::Address> &addresses = contact.
addresses;
639 int currentRow = tabAddresses->rowCount();
640 tabAddresses->setRowCount( currentRow + 1 );
641 tabAddresses->setItem( currentRow, 0,
new QTableWidgetItem( address.type ) );
642 tabAddresses->setItem( currentRow, 1,
new QTableWidgetItem( address.address ) );
643 tabAddresses->setItem( currentRow, 2,
new QTableWidgetItem( address.postalCode ) );
644 tabAddresses->setItem( currentRow, 3,
new QTableWidgetItem( address.city ) );
645 tabAddresses->setItem( currentRow, 4,
new QTableWidgetItem( address.administrativeArea ) );
646 tabAddresses->setItem( currentRow, 5,
new QTableWidgetItem( address.country ) );
651 const QList<QgsAbstractMetadataBase::Link> &links = mMetadata->links();
652 mLinksModel->setRowCount( 0 );
655 const int row = mLinksModel->rowCount();
656 mLinksModel->setItem( row, 0,
new QStandardItem( link.name ) );
657 mLinksModel->setItem( row, 1,
new QStandardItem( link.type ) );
658 mLinksModel->setItem( row, 2,
new QStandardItem( link.url ) );
659 mLinksModel->setItem( row, 3,
new QStandardItem( link.description ) );
660 mLinksModel->setItem( row, 4,
new QStandardItem( link.format ) );
661 mLinksModel->setItem( row, 5,
new QStandardItem( link.mimeType ) );
662 mLinksModel->setItem( row, 6,
new QStandardItem( link.size ) );
666 mHistoryModel->setStringList( mMetadata->history() );
672 mCreationDateTimeEdit2->clear();
677 mPublishedDateTimeEdit->clear();
682 mRevisedDateTimeEdit->clear();
687 mSupersededDateTimeEdit->clear();
703 syncFromCategoriesTabToKeywordsTab();
704 QMap<QString, QStringList> keywords;
705 for (
int i = 0; i < tabKeywords->rowCount(); i++ )
707 keywords.insert( tabKeywords->item( i, 0 )->text(), tabKeywords->item( i, 1 )->text().split(
',' ) );
717 layerMetadata->
setFees( lineEditFees->text() );
720 QStringList licenses;
721 for (
int i = 0; i < tabLicenses->rowCount(); i++ )
723 licenses.append( tabLicenses->item( i, 0 )->text() );
728 layerMetadata->
setRights( mRightsModel->stringList() );
731 layerMetadata->
setEncoding( comboEncoding->currentText() );
734 QList<QgsLayerMetadata::Constraint> constraints;
735 for (
int row = 0; row < mConstraintsModel->rowCount(); row++ )
738 constraint.
type = mConstraintsModel->item( row, 0 )->text();
739 constraint.
constraint = mConstraintsModel->item( row, 1 )->text();
740 constraints.append( constraint );
747 layerMetadata->
setCrs( mCrs );
752 spatialExtent.
bounds =
QgsBox3D( spatialExtentSelector->outputExtent() );
755 spatialExtent.
extentCrs = spatialExtentSelector->outputCrs();
756 QList<QgsLayerMetadata::SpatialExtent> spatialExtents;
757 spatialExtents.append( spatialExtent );
758 QList<QgsDateTimeRange> temporalExtents;
759 temporalExtents.append(
QgsDateTimeRange( dateTimeFrom->dateTime(), dateTimeTo->dateTime() ) );
770 projectMetadata->
setAuthor( mLineEditAuthor->text() );
777 QList<QgsAbstractMetadataBase::Contact> contacts = mMetadata->contacts();
778 if ( contacts.size() > 0 )
779 contacts.removeFirst();
781 contact.
email = lineEditContactEmail->text();
782 contact.
position = lineEditContactPosition->text();
783 contact.
fax = lineEditContactFax->text();
784 contact.
voice = lineEditContactVoice->text();
785 contact.
name = lineEditContactName->text();
786 contact.
organization = lineEditContactOrganization->text();
787 contact.
role = comboContactRole->currentText();
788 QList<QgsAbstractMetadataBase::Address> addresses;
789 for (
int i = 0; i < tabAddresses->rowCount(); i++ )
792 address.
type = tabAddresses->item( i, 0 )->text();
793 address.
address = tabAddresses->item( i, 1 )->text();
794 address.
postalCode = tabAddresses->item( i, 2 )->text();
795 address.
city = tabAddresses->item( i, 3 )->text();
797 address.
country = tabAddresses->item( i, 5 )->text();
798 addresses.append( address );
801 contacts.insert( 0, contact );
805 QList<QgsAbstractMetadataBase::Link> links;
806 for (
int row = 0; row < mLinksModel->rowCount(); row++ )
809 link.
name = mLinksModel->item( row, 0 )->text();
810 link.
type = mLinksModel->item( row, 1 )->text();
811 link.
url = mLinksModel->item( row, 2 )->text();
812 link.
description = mLinksModel->item( row, 3 )->text();
813 link.
format = mLinksModel->item( row, 4 )->text();
814 link.
mimeType = mLinksModel->item( row, 5 )->text();
815 link.
size = mLinksModel->item( row, 6 )->text();
816 links.append( link );
832 std::unique_ptr<QgsAbstractMetadataBase> md(
metadata() );
834 std::unique_ptr<QgsNativeMetadataBaseValidator> validator;
838 validator = std::make_unique<QgsNativeMetadataValidator>();
842 validator = std::make_unique<QgsNativeProjectMetadataValidator>();
846 QList<QgsAbstractMetadataBaseValidator::ValidationResult> validationResults;
847 bool results = validator->validate( md.get(), validationResults );
854 errors += QLatin1String(
"<b>" ) % result.section;
857 errors += QLatin1Char(
' ' ) % QVariant( result.identifier().toInt() + 1 ).toString();
859 errors += QLatin1String(
"</b>: " ) % result.note % QLatin1String(
"<br />" );
864 errors = tr(
"Ok, it seems valid according to the QGIS Schema." );
868 myStyle.append( QStringLiteral(
"body { margin: 10px; }\n " ) );
869 resultsCheckMetadata->clear();
870 resultsCheckMetadata->document()->setDefaultStyleSheet( myStyle );
871 resultsCheckMetadata->setHtml( errors );
878 QMap<QString, QString> countries;
879 countries.insert( QString(), QString() );
883 if ( !file.open( QIODevice::ReadOnly ) )
885 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
891 while ( !file.atEnd() )
893 QByteArray line = file.readLine();
894 QList<QByteArray> items = line.split(
',' );
895 countries.insert( QString( items.at( 0 ).constData() ).trimmed(), QString( items.at( 1 ).constData() ).trimmed() );
900 QFile secondFile( path );
901 if ( !secondFile.open( QIODevice::ReadOnly ) )
903 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
908 secondFile.readLine();
909 while ( !secondFile.atEnd() )
911 QByteArray line = secondFile.readLine();
912 QList<QByteArray> items = line.split(
',' );
913 countries.insert( QString( items.at( 2 ).constData() ).trimmed(), QString( items.at( 0 ).constData() ).trimmed() );
921 QStringList wordList;
922 wordList.append( QString() );
926 if ( !file.open( QIODevice::ReadOnly ) )
928 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
934 while ( !file.atEnd() )
936 QByteArray line = file.readLine();
937 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
945 QStringList wordList;
946 wordList.append( QString() );
950 if ( !file.open( QIODevice::ReadOnly ) )
952 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
958 while ( !file.atEnd() )
960 QByteArray line = file.readLine();
961 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
969 QStringList wordList;
970 wordList.append( QString() );
974 if ( !file.open( QIODevice::ReadOnly ) )
976 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
980 while ( !file.atEnd() )
982 QByteArray line = file.readLine();
983 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
991 QMap<QString, QString> types;
992 types.insert( QString(), QString() );
995 if ( !file.open( QIODevice::ReadOnly ) )
997 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
1001 types.insert( QString(), QString() );
1002 while ( !file.atEnd() )
1004 QByteArray line = file.readLine();
1005 QList<QByteArray> items = line.split(
';' );
1006 types.insert( items.at( 0 ).constData(), items.at( 1 ).constData() );
1020 return lineEditTitle->text();
1025 if (
title != lineEditTitle->text() )
1051void QgsMetadataWidget::syncFromCategoriesTabToKeywordsTab()
1053 if ( mCategoriesModel->rowCount() > 0 )
1055 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
1057 if ( !categories.isEmpty() )
1059 row = categories.at( 0 )->row();
1065 row = tabKeywords->rowCount() - 1;
1066 tabKeywords->item( row, 0 )->setText( QStringLiteral(
"gmd:topicCategory" ) );
1068 tabKeywords->item( row, 1 )->setText( mCategoriesModel->stringList().join( QLatin1Char(
',' ) ) );
1072void QgsMetadataWidget::updatePanel()
1074 int index = tabWidget->currentIndex();
1075 QString currentTabText = tabWidget->widget( index )->objectName();
1076 if ( currentTabText == QLatin1String(
"tabCategoriesDialog" ) )
1080 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
1081 if ( !categories.isEmpty() )
1083 const int row = categories.at( 0 )->row();
1084 mCategoriesModel->setStringList( tabKeywords->item( row, 1 )->text().split(
',' ) );
1088 mCategoriesModel->setStringList( QStringList() );
1091 else if ( currentTabText == QLatin1String(
"tabKeywordsDialog" ) )
1095 syncFromCategoriesTabToKeywordsTab();
1097 else if ( currentTabText == QLatin1String(
"tabValidationDialog" ) )
1103void QgsMetadataWidget::addNewCategory()
1106 QString text = QInputDialog::getText(
this, tr(
"New Category" ), tr(
"New Category:" ), QLineEdit::Normal, QString(), &ok );
1107 if ( ok && !text.isEmpty() )
1109 QStringList list = mCategoriesModel->stringList();
1110 if ( !list.contains( text ) )
1112 list.append( text );
1113 mCategoriesModel->setStringList( list );
1114 mCategoriesModel->sort( 0 );
1119void QgsMetadataWidget::addDefaultCategories()
1121 const QModelIndexList selectedIndexes = listDefaultCategories->selectionModel()->selectedIndexes();
1122 QStringList defaultCategoriesList = mDefaultCategoriesModel->stringList();
1123 QStringList selectedCategories = mCategoriesModel->stringList();
1125 for (
const QModelIndex &selection : selectedIndexes )
1127 QVariant item = mDefaultCategoriesModel->data( selection, Qt::DisplayRole );
1128 defaultCategoriesList.removeOne( item.toString() );
1130 selectedCategories.append( item.toString() );
1133 mDefaultCategoriesModel->setStringList( defaultCategoriesList );
1134 mCategoriesModel->setStringList( selectedCategories );
1135 mCategoriesModel->sort( 0 );
1138void QgsMetadataWidget::removeSelectedCategories()
1140 const QModelIndexList selectedIndexes = listCategories->selectionModel()->selectedIndexes();
1141 QStringList categories = mCategoriesModel->stringList();
1142 QStringList defaultList = mDefaultCategoriesModel->stringList();
1144 for (
const QModelIndex &selection : selectedIndexes )
1146 QVariant item = mCategoriesModel->data( selection, Qt::DisplayRole );
1147 categories.removeOne( item.toString() );
1149 if ( mDefaultCategories.contains( item.toString() ) )
1151 defaultList.append( item.toString() );
1154 mCategoriesModel->setStringList( categories );
1156 mDefaultCategoriesModel->setStringList( defaultList );
1157 mDefaultCategoriesModel->sort( 0 );
1161LinkItemDelegate::LinkItemDelegate( QObject *parent )
1162 : QStyledItemDelegate( parent )
1166QWidget *LinkItemDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
1168 if ( index.column() == 1 )
1171 QComboBox *typeEditor =
new QComboBox( parent );
1172 typeEditor->setEditable(
true );
1173 QStringListModel *model =
new QStringListModel( parent );
1175 typeEditor->setModel( model );
1178 else if ( index.column() == 5 )
1181 QComboBox *mimeEditor =
new QComboBox( parent );
1182 mimeEditor->setEditable(
true );
1183 QStringListModel *model =
new QStringListModel( parent );
1185 mimeEditor->setModel( model );
1189 return QStyledItemDelegate::createEditor( parent, option, index );
1192ConstraintItemDelegate::ConstraintItemDelegate( QObject *parent )
1193 : QStyledItemDelegate( parent )
1197QWidget *ConstraintItemDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
1199 if ( index.column() == 0 )
1202 QComboBox *typeEditor =
new QComboBox( parent );
1203 typeEditor->setEditable(
true );
1205 types << QStringLiteral(
"access" ) << QStringLiteral(
"use" ) << QStringLiteral(
"other" );
1206 QStringListModel *model =
new QStringListModel( parent );
1207 model->setStringList( types );
1208 typeEditor->setModel( model );
1212 return QStyledItemDelegate::createEditor( parent, option, index );
@ Published
Date published.
@ Superseded
Date superseded.
static QString reportStyleSheet(QgsApplication::StyleSheetType styleSheetType=QgsApplication::StyleSheetType::Qt)
Returns a css style sheet for reports, the styleSheetType argument determines what type of stylesheet...
static QString metadataPath()
Returns the path to the metadata directory.
A 3-dimensional box composed of x, y, z coordinates.
void setZMinimum(double z)
Sets the minimum z value.
void setZMaximum(double z)
Sets the maximum z value.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
QString userFriendlyIdentifier(Qgis::CrsIdentifierType type=Qgis::CrsIdentifierType::MediumString) const
Returns a user friendly identifier for the CRS.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
The QgsDateTimeEdit class is a QDateTimeEdit with the capability of setting/reading null date/times.
Map canvas is a class for displaying all GIS data types on a canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
Base class for all map layer types.
QgsCoordinateReferenceSystem crs
QgsLayerMetadata metadata
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
virtual Q_INVOKABLE QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be nullptr.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void setMetadata(const QgsProjectMetadata &metadata)
Sets the project's metadata store.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
#define QgsDebugError(str)
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.