22#include <QInputDialog>
23#include <QStringListModel>
27#include "moc_qgsmetadatawidget.cpp"
40 tabWidget->setCurrentIndex( 0 );
43 encodingFrame->setHidden(
true );
45 spinBoxZMinimum->setClearValue( 0 );
46 spinBoxZMaximum->setClearValue( 0 );
49 mDefaultCategories << tr(
"Farming" ) << tr(
"Climatology Meteorology Atmosphere" ) << tr(
"Location" ) << tr(
"Intelligence Military" ) << tr(
"Transportation" ) << tr(
"Structure" ) << tr(
"Boundaries" );
50 mDefaultCategories << tr(
"Inland Waters" ) << tr(
"Planning Cadastre" ) << tr(
"Geoscientific Information" ) << tr(
"Elevation" ) << tr(
"Health" ) << tr(
"Biota" ) << tr(
"Oceans" ) << tr(
"Environment" );
51 mDefaultCategories << tr(
"Utilities Communication" ) << tr(
"Economy" ) << tr(
"Society" ) << tr(
"Imagery Base Maps Earth Cover" );
52 mDefaultCategoriesModel =
new QStringListModel( mDefaultCategories,
this );
53 mDefaultCategoriesModel->sort( 0 );
54 listDefaultCategories->setModel( mDefaultCategoriesModel );
57 mCategoriesModel =
new QStringListModel( listCategories );
58 listCategories->setModel( mCategoriesModel );
61 mRightsModel =
new QStringListModel( listRights );
62 listRights->setModel( mRightsModel );
65 mConstraintsModel =
new QStandardItemModel( tabConstraints );
66 mConstraintsModel->setColumnCount( 2 );
67 QStringList constraintheaders;
68 constraintheaders << tr(
"Type" ) << tr(
"Constraint" );
69 mConstraintsModel->setHorizontalHeaderLabels( constraintheaders );
70 tabConstraints->setModel( mConstraintsModel );
71 tabConstraints->setItemDelegate(
new ConstraintItemDelegate(
this ) );
74 dateTimeFrom->setAllowNull(
true );
75 dateTimeTo->setAllowNull(
true );
78 mLinksModel =
new QStandardItemModel( tabLinks );
79 mLinksModel->setColumnCount( 7 );
80 QStringList headers = QStringList();
81 headers << tr(
"Name" ) << tr(
"Type" ) << tr(
"URL" ) << tr(
"Description" ) << tr(
"Format" ) << tr(
"MIME" ) << tr(
"Size" );
82 mLinksModel->setHorizontalHeaderLabels( headers );
83 tabLinks->setModel( mLinksModel );
84 tabLinks->setItemDelegate(
new LinkItemDelegate(
this ) );
87 mHistoryModel =
new QStringListModel( listHistory );
88 listHistory->setModel( mHistoryModel );
92 mCreationDateTimeEdit,
93 mCreationDateTimeEdit2,
94 mPublishedDateTimeEdit,
96 mSupersededDateTimeEdit
99 w->setAllowNull(
true );
100 w->setNullRepresentation( tr(
"Not set" ) );
104 connect( tabWidget, &QTabWidget::currentChanged,
this, &QgsMetadataWidget::updatePanel );
105 connect( btnAutoSource, &QPushButton::clicked,
this, &QgsMetadataWidget::fillSourceFromLayer );
106 connect( btnAddVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::addVocabulary );
107 connect( btnRemoveVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedVocabulary );
108 connect( btnAddRight, &QPushButton::clicked,
this, &QgsMetadataWidget::addRight );
109 connect( btnRemoveRight, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedRight );
110 connect( btnAddLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::addLicence );
111 connect( btnRemoveLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLicence );
112 connect( btnAddConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::addConstraint );
113 connect( btnRemoveConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedConstraint );
114 connect( btnSetCrsFromLayer, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromLayer );
115 connect( btnSetCrsFromProvider, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromProvider );
116 connect( btnAddAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::addAddress );
117 connect( btnRemoveAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedAddress );
118 connect( btnAddLink, &QPushButton::clicked,
this, &QgsMetadataWidget::addLink );
119 connect( btnRemoveLink, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLink );
120 connect( btnAddHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::addHistory );
121 connect( btnRemoveHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedHistory );
122 connect( btnNewCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addNewCategory );
123 connect( btnAddDefaultCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addDefaultCategories );
124 connect( btnRemoveCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedCategories );
129 btnAutoSource->setEnabled(
false );
130 btnAutoEncoding->setEnabled(
false );
131 btnSetCrsFromLayer->setEnabled(
false );
152 type = tr(
"dataset" );
153 typeUpper = tr(
"Dataset" );
154 mEncodingFrame->show();
155 mAuthorFrame->hide();
156 btnAutoSource->setEnabled( mLayer );
160 type = tr(
"project" );
161 typeUpper = tr(
"Project" );
162 mEncodingFrame->hide();
163 mAuthorFrame->show();
164 tabWidget->removeTab( 4 );
165 tabWidget->removeTab( 3 );
166 btnAutoSource->setEnabled(
true );
169 connect( mCreationDateTimeEdit, &QDateTimeEdit::dateTimeChanged,
this, [ = ](
const QDateTime & value )
171 if ( value.isValid() )
172 mCreationDateTimeEdit2->setDateTime( value );
173 else if ( mCreationDateTimeEdit2->dateTime().isValid() )
174 mCreationDateTimeEdit2->clear();
176 connect( mCreationDateTimeEdit2, &QDateTimeEdit::dateTimeChanged,
this, [ = ](
const QDateTime & value )
178 if ( value.isValid() )
179 mCreationDateTimeEdit->setDateTime( value );
180 else if ( mCreationDateTimeEdit->dateTime().isValid() )
181 mCreationDateTimeEdit->clear();
187 mIdLabel->setText( tr(
"This page describes the basic attribution of the %1. Please use the tooltips for more information." ).arg( type ) );
188 mLabelCategories->setText( tr(
"%1 categories." ).arg( typeUpper ) );
189 mLabelContact->setText( tr(
"Contacts related to the %1." ).arg( type ) );
190 mLabelLinks->setText( tr(
"Links describe ancillary resources and information related to this %1." ).arg( type ) );
191 mLabelHistory->setText( tr(
"History about the %1." ).arg( type ) );
192 labelKeywords->setText( tr(
"<html><head/><body><p>Keywords are optional, and provide a way to provide additional descriptive information about "
193 "the %1. Edits made in the categories tab will update the category entry below. For the concept, we suggest "
194 "to use a standard based vocabulary such as <a href=\"https://www.eionet.europa.eu/gemet/en/inspire-themes/\">"
195 "<span style=\" text-decoration: underline; color:#0000ff;\">GEMET.</span></a></p></body></html>" ).arg( type ) );
196 btnAutoSource->setText( tr(
"Set from %1" ).arg( mMode ==
LayerMetadata ? tr(
"layer" ) : tr(
"project" ) ) );
215 std::unique_ptr< QgsAbstractMetadataBase > md;
219 md = std::make_unique< QgsLayerMetadata >();
223 md = std::make_unique< QgsProjectMetadata >();
231void QgsMetadataWidget::fillSourceFromLayer()
249void QgsMetadataWidget::addVocabulary()
251 const int row = tabKeywords->rowCount();
252 tabKeywords->setRowCount( row + 1 );
253 QTableWidgetItem *pCell =
nullptr;
256 pCell =
new QTableWidgetItem( tr(
"undefined %1" ).arg( row + 1 ) );
257 tabKeywords->setItem( row, 0, pCell );
260 pCell =
new QTableWidgetItem();
261 tabKeywords->setItem( row, 1, pCell );
264void QgsMetadataWidget::removeSelectedVocabulary()
266 QItemSelectionModel *selectionModel = tabKeywords->selectionModel();
267 const QModelIndexList selectedRows = selectionModel->selectedRows();
268 for (
int i = 0; i < selectedRows.size() ; i++ )
270 tabKeywords->model()->removeRow( selectedRows[i].row() );
274void QgsMetadataWidget::addLicence()
276 QString newLicence = QInputDialog::getItem(
this, tr(
"New Licence" ), tr(
"New Licence" ),
parseLicenses(), 0,
true );
277 if ( tabLicenses->findItems( newLicence, Qt::MatchExactly ).isEmpty() )
279 const int row = tabLicenses->rowCount();
280 tabLicenses->setRowCount( row + 1 );
281 QTableWidgetItem *pCell =
new QTableWidgetItem( newLicence );
282 tabLicenses->setItem( row, 0, pCell );
286void QgsMetadataWidget::removeSelectedLicence()
288 QItemSelectionModel *selectionModel = tabLicenses->selectionModel();
289 const QModelIndexList selectedRows = selectionModel->selectedRows();
290 for (
int i = 0; i < selectedRows.size() ; i++ )
292 tabLicenses->model()->removeRow( selectedRows[i].row() );
296void QgsMetadataWidget::addRight()
298 QString newRight = QInputDialog::getText(
this, tr(
"New Right" ), tr(
"New Right" ) );
299 QStringList existingRights = mRightsModel->stringList();
300 if ( ! existingRights.contains( newRight ) )
302 existingRights.append( newRight );
303 mRightsModel->setStringList( existingRights );
307void QgsMetadataWidget::removeSelectedRight()
309 QItemSelectionModel *selection = listRights->selectionModel();
310 if ( selection->hasSelection() )
312 QModelIndex indexElementSelectionne = selection->currentIndex();
314 QVariant item = mRightsModel->data( indexElementSelectionne, Qt::DisplayRole );
315 QStringList list = mRightsModel->stringList();
316 list.removeOne( item.toString() );
317 mRightsModel->setStringList( list );
321void QgsMetadataWidget::addConstraint()
323 const int row = mConstraintsModel->rowCount();
324 mConstraintsModel->setItem( row, 0,
new QStandardItem( tr(
"undefined %1" ).arg( row + 1 ) ) );
325 mConstraintsModel->setItem( row, 1,
new QStandardItem( tr(
"undefined %1" ).arg( row + 1 ) ) );
328void QgsMetadataWidget::removeSelectedConstraint()
330 const QModelIndexList selectedRows = tabConstraints->selectionModel()->selectedRows();
331 if ( selectedRows.empty() )
333 mConstraintsModel->removeRow( selectedRows[0].row() );
338 if ( ( mCrs.
isValid() ) && ( mLayer ) )
341 spatialExtentSelector->setEnabled(
true );
342 spatialExtentSelector->setOutputCrs( mCrs );
346 lblCurrentCrsStatus->setText( tr(
"Same as layer properties and provider." ) );
350 lblCurrentCrsStatus->setText( tr(
"Same as layer properties but different than the provider." ) );
354 lblCurrentCrsStatus->setText( tr(
"Same as the provider but different than the layer properties." ) );
358 lblCurrentCrsStatus->setText( tr(
"Does not match either layer properties or the provider." ) );
363 lblCurrentCrs->setText( tr(
"CRS: Not set." ) );
364 lblCurrentCrsStatus->setText( QString() );
365 spatialExtentSelector->setEnabled(
false );
369void QgsMetadataWidget::addAddress()
371 const int row = tabAddresses->rowCount();
372 tabAddresses->setRowCount( row + 1 );
373 QTableWidgetItem *pCell =
nullptr;
376 pCell =
new QTableWidgetItem( tr(
"postal" ) );
377 tabAddresses->setItem( row, 0, pCell );
380 tabAddresses->setItem( row, 1,
new QTableWidgetItem() );
383 tabAddresses->setItem( row, 2,
new QTableWidgetItem() );
386 tabAddresses->setItem( row, 3,
new QTableWidgetItem() );
389 tabAddresses->setItem( row, 4,
new QTableWidgetItem() );
392 tabAddresses->setItem( row, 5,
new QTableWidgetItem() );
395void QgsMetadataWidget::removeSelectedAddress()
397 QItemSelectionModel *selectionModel = tabAddresses->selectionModel();
398 const QModelIndexList selectedRows = selectionModel->selectedRows();
399 for (
int i = 0; i < selectedRows.size() ; i++ )
401 tabAddresses->model()->removeRow( selectedRows[i].row() );
405void QgsMetadataWidget::fillCrsFromLayer()
407 mCrs = mLayer->
crs();
411void QgsMetadataWidget::fillCrsFromProvider()
417void QgsMetadataWidget::addLink()
419 const int row = mLinksModel->rowCount();
420 mLinksModel->setItem( row, 0,
new QStandardItem( tr(
"undefined %1" ).arg( row + 1 ) ) );
421 mLinksModel->setItem( row, 1,
new QStandardItem() );
422 mLinksModel->setItem( row, 2,
new QStandardItem() );
423 mLinksModel->setItem( row, 3,
new QStandardItem() );
424 mLinksModel->setItem( row, 4,
new QStandardItem() );
425 mLinksModel->setItem( row, 5,
new QStandardItem() );
426 mLinksModel->setItem( row, 6,
new QStandardItem() );
429void QgsMetadataWidget::removeSelectedLink()
431 const QModelIndexList selectedRows = tabLinks->selectionModel()->selectedRows();
432 if ( selectedRows.empty() )
435 mLinksModel->removeRow( selectedRows[0].row() );
438void QgsMetadataWidget::addHistory()
440 QString newHistory = QInputDialog::getText(
this, tr(
"New History" ), tr(
"New History" ) );
441 QStringList existingHistory = mHistoryModel->stringList();
442 if ( ! existingHistory.contains( newHistory ) )
444 existingHistory.append( newHistory );
445 mHistoryModel->setStringList( existingHistory );
449void QgsMetadataWidget::removeSelectedHistory()
451 QItemSelectionModel *selection = listHistory->selectionModel();
452 if ( selection->hasSelection() )
454 QModelIndex indexElementSelectionne = selection->currentIndex();
456 QVariant item = mHistoryModel->data( indexElementSelectionne, Qt::DisplayRole );
457 QStringList list = mHistoryModel->stringList();
458 list.removeOne( item.toString() );
459 mHistoryModel->setStringList( list );
463void QgsMetadataWidget::fillComboBox()
468 comboType->setEditable(
true );
471 const QStringList &keys = types.keys();
473 for (
const QString &type : keys )
475 comboType->insertItem( i, type );
476 comboType->setItemData( i, types.value( type ), Qt::ToolTipRole );
482 comboLanguage->setEditable(
true );
483 comboLanguage->clear();
485 const QStringList &k = countries.keys();
487 for (
const QString &countryCode : k )
489 comboLanguage->insertItem( i, countryCode );
490 comboLanguage->setItemData( i, countries.value( countryCode ), Qt::ToolTipRole );
495void QgsMetadataWidget::setUiFromMetadata()
498 lineEditParentId->setText( mMetadata->parentIdentifier() );
501 if ( ! mMetadata->identifier().isEmpty() )
503 lineEditIdentifier->setText( mMetadata->identifier() );
507 if ( ! mMetadata->title().isEmpty() )
509 whileBlocking( lineEditTitle )->setText( mMetadata->title() );
513 if ( ! mMetadata->type().isEmpty() )
515 if ( comboType->findText( mMetadata->type() ) == -1 )
517 comboType->addItem( mMetadata->type() );
519 comboType->setCurrentIndex( comboType->findText( mMetadata->type() ) );
523 if ( ! mMetadata->language().isEmpty() )
525 if ( comboLanguage->findText( mMetadata->language() ) == -1 )
527 comboLanguage->addItem( mMetadata->language() );
529 comboLanguage->setCurrentIndex( comboLanguage->findText( mMetadata->language() ) );
533 textEditAbstract->setPlainText( mMetadata->abstract() );
536 mCategoriesModel->setStringList( mMetadata->categories() );
539 tabKeywords->setRowCount( 0 );
540 QMapIterator<QString, QStringList> i( mMetadata->keywords() );
541 while ( i.hasNext() )
545 int currentRow = tabKeywords->rowCount() - 1;
546 tabKeywords->item( currentRow, 0 )->setText( i.key() );
547 tabKeywords->item( currentRow, 1 )->setText( i.value().join( QLatin1Char(
',' ) ) );
553 comboEncoding->setCurrentText( layerMetadata->encoding() );
556 lineEditFees->setText( layerMetadata->fees() );
559 tabLicenses->setRowCount( 0 );
560 const QStringList &licenses = layerMetadata->licenses();
561 for (
const QString &licence : licenses )
563 int currentRow = tabLicenses->rowCount();
564 tabLicenses->setRowCount( currentRow + 1 );
565 QTableWidgetItem *pCell = tabLicenses->item( currentRow, 0 );
568 pCell =
new QTableWidgetItem;
569 tabLicenses->setItem( currentRow, 0, pCell );
571 pCell->setText( licence );
575 mRightsModel->setStringList( layerMetadata->rights() );
578 mConstraintsModel->clear();
579 const QList<QgsLayerMetadata::Constraint> &constraints = layerMetadata->constraints();
582 const int row = mConstraintsModel->rowCount();
583 mConstraintsModel->setItem( row, 0,
new QStandardItem( constraint.type ) );
584 mConstraintsModel->setItem( row, 1,
new QStandardItem( constraint.constraint ) );
588 mCrs = layerMetadata->crs();
592 const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = layerMetadata->extent().spatialExtents();
593 if ( ! spatialExtents.isEmpty() )
596 spatialExtentSelector->setOutputCrs( spatialExtents.at( 0 ).extentCrs );
597 spatialExtentSelector->setOriginalExtent( spatialExtents.at( 0 ).bounds.toRectangle(), spatialExtents.at( 0 ).extentCrs );
598 spatialExtentSelector->setOutputExtentFromOriginal();
599 spinBoxZMaximum->setValue( spatialExtents.at( 0 ).bounds.zMaximum() );
600 spinBoxZMinimum->setValue( spatialExtents.at( 0 ).bounds.zMinimum() );
604 const QList<QgsDateTimeRange> &temporalExtents = layerMetadata->extent().temporalExtents();
605 if ( ! temporalExtents.isEmpty() )
608 dateTimeFrom->setDateTime( temporalExtents.at( 0 ).begin() );
609 dateTimeTo->setDateTime( temporalExtents.at( 0 ).end() );
613 dateTimeFrom->clear();
619 mLineEditAuthor->setText( projectMetadata->author() );
623 const QList<QgsAbstractMetadataBase::Contact> &contacts = mMetadata->contacts();
624 if ( ! contacts.isEmpty() )
628 lineEditContactName->setText( contact.
name );
629 lineEditContactEmail->setText( contact.
email );
630 lineEditContactFax->setText( contact.
fax );
631 lineEditContactOrganization->setText( contact.
organization );
632 lineEditContactPosition->setText( contact.
position );
633 lineEditContactVoice->setText( contact.
voice );
634 if ( comboContactRole->findText( contact.
role ) == -1 )
636 comboContactRole->addItem( contact.
role );
638 comboContactRole->setCurrentIndex( comboContactRole->findText( contact.
role ) );
639 tabAddresses->setRowCount( 0 );
640 const QList<QgsAbstractMetadataBase::Address> &addresses = contact.
addresses;
643 int currentRow = tabAddresses->rowCount();
644 tabAddresses->setRowCount( currentRow + 1 );
645 tabAddresses->setItem( currentRow, 0,
new QTableWidgetItem( address.type ) );
646 tabAddresses->setItem( currentRow, 1,
new QTableWidgetItem( address.address ) );
647 tabAddresses->setItem( currentRow, 2,
new QTableWidgetItem( address.postalCode ) );
648 tabAddresses->setItem( currentRow, 3,
new QTableWidgetItem( address.city ) );
649 tabAddresses->setItem( currentRow, 4,
new QTableWidgetItem( address.administrativeArea ) );
650 tabAddresses->setItem( currentRow, 5,
new QTableWidgetItem( address.country ) );
655 const QList<QgsAbstractMetadataBase::Link> &links = mMetadata->links();
656 mLinksModel->setRowCount( 0 );
659 const int row = mLinksModel->rowCount();
660 mLinksModel->setItem( row, 0,
new QStandardItem( link.name ) );
661 mLinksModel->setItem( row, 1,
new QStandardItem( link.type ) );
662 mLinksModel->setItem( row, 2,
new QStandardItem( link.url ) );
663 mLinksModel->setItem( row, 3,
new QStandardItem( link.description ) );
664 mLinksModel->setItem( row, 4,
new QStandardItem( link.format ) );
665 mLinksModel->setItem( row, 5,
new QStandardItem( link.mimeType ) );
666 mLinksModel->setItem( row, 6,
new QStandardItem( link.size ) );
670 mHistoryModel->setStringList( mMetadata->history() );
676 mCreationDateTimeEdit2->clear();
681 mPublishedDateTimeEdit->clear();
686 mRevisedDateTimeEdit->clear();
691 mSupersededDateTimeEdit->clear();
707 syncFromCategoriesTabToKeywordsTab();
708 QMap<QString, QStringList> keywords;
709 for (
int i = 0; i < tabKeywords->rowCount() ; i++ )
711 keywords.insert( tabKeywords->item( i, 0 )->text(), tabKeywords->item( i, 1 )->text().split(
',' ) );
721 layerMetadata->
setFees( lineEditFees->text() );
724 QStringList licenses;
725 for (
int i = 0; i < tabLicenses->rowCount() ; i++ )
727 licenses.append( tabLicenses->item( i, 0 )->text() );
732 layerMetadata->
setRights( mRightsModel->stringList() );
735 layerMetadata->
setEncoding( comboEncoding->currentText() );
738 QList<QgsLayerMetadata::Constraint> constraints;
739 for (
int row = 0; row < mConstraintsModel->rowCount() ; row++ )
742 constraint.
type = mConstraintsModel->item( row, 0 )->text();
743 constraint.
constraint = mConstraintsModel->item( row, 1 )->text();
744 constraints.append( constraint );
751 layerMetadata->
setCrs( mCrs );
756 spatialExtent.
bounds =
QgsBox3D( spatialExtentSelector->outputExtent() );
759 spatialExtent.
extentCrs = spatialExtentSelector->outputCrs();
760 QList<QgsLayerMetadata::SpatialExtent> spatialExtents;
761 spatialExtents.append( spatialExtent );
762 QList<QgsDateTimeRange> temporalExtents;
763 temporalExtents.append(
QgsDateTimeRange( dateTimeFrom->dateTime(), dateTimeTo->dateTime() ) );
774 projectMetadata->
setAuthor( mLineEditAuthor->text() );
781 QList<QgsAbstractMetadataBase::Contact> contacts = mMetadata->contacts();
782 if ( contacts.size() > 0 )
783 contacts.removeFirst();
785 contact.
email = lineEditContactEmail->text();
786 contact.
position = lineEditContactPosition->text();
787 contact.
fax = lineEditContactFax->text();
788 contact.
voice = lineEditContactVoice->text();
789 contact.
name = lineEditContactName->text();
790 contact.
organization = lineEditContactOrganization->text();
791 contact.
role = comboContactRole->currentText();
792 QList<QgsAbstractMetadataBase::Address> addresses;
793 for (
int i = 0; i < tabAddresses->rowCount() ; i++ )
796 address.
type = tabAddresses->item( i, 0 )->text();
797 address.
address = tabAddresses->item( i, 1 )->text();
798 address.
postalCode = tabAddresses->item( i, 2 )->text();
799 address.
city = tabAddresses->item( i, 3 )->text();
801 address.
country = tabAddresses->item( i, 5 )->text();
802 addresses.append( address );
805 contacts.insert( 0, contact );
809 QList<QgsAbstractMetadataBase::Link> links;
810 for (
int row = 0; row < mLinksModel->rowCount() ; row++ )
813 link.
name = mLinksModel->item( row, 0 )->text();
814 link.
type = mLinksModel->item( row, 1 )->text();
815 link.
url = mLinksModel->item( row, 2 )->text();
816 link.
description = mLinksModel->item( row, 3 )->text();
817 link.
format = mLinksModel->item( row, 4 )->text();
818 link.
mimeType = mLinksModel->item( row, 5 )->text();
819 link.
size = mLinksModel->item( row, 6 )->text();
820 links.append( link );
836 std::unique_ptr< QgsAbstractMetadataBase > md(
metadata() );
838 std::unique_ptr< QgsNativeMetadataBaseValidator > validator;
842 validator = std::make_unique< QgsNativeMetadataValidator>();
846 validator = std::make_unique< QgsNativeProjectMetadataValidator>();
850 QList<QgsAbstractMetadataBaseValidator::ValidationResult> validationResults;
851 bool results = validator->validate( md.get(), validationResults );
858 errors += QLatin1String(
"<b>" ) % result.section;
861 errors += QLatin1Char(
' ' ) % QVariant( result.identifier().toInt() + 1 ).toString();
863 errors += QLatin1String(
"</b>: " ) % result.note % QLatin1String(
"<br />" );
868 errors = tr(
"Ok, it seems valid according to the QGIS Schema." );
872 myStyle.append( QStringLiteral(
"body { margin: 10px; }\n " ) );
873 resultsCheckMetadata->clear();
874 resultsCheckMetadata->document()->setDefaultStyleSheet( myStyle );
875 resultsCheckMetadata->setHtml( errors );
882 QMap<QString, QString> countries;
883 countries.insert( QString(), QString() );
887 if ( !file.open( QIODevice::ReadOnly ) )
889 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
895 while ( !file.atEnd() )
897 QByteArray line = file.readLine();
898 QList<QByteArray> items = line.split(
',' );
899 countries.insert( QString( items.at( 0 ).constData() ).trimmed(), QString( items.at( 1 ).constData() ).trimmed() );
904 QFile secondFile( path );
905 if ( !secondFile.open( QIODevice::ReadOnly ) )
907 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
912 secondFile.readLine();
913 while ( !secondFile.atEnd() )
915 QByteArray line = secondFile.readLine();
916 QList<QByteArray> items = line.split(
',' );
917 countries.insert( QString( items.at( 2 ).constData() ).trimmed(), QString( items.at( 0 ).constData() ).trimmed() );
925 QStringList wordList;
926 wordList.append( QString() );
930 if ( !file.open( QIODevice::ReadOnly ) )
932 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
938 while ( !file.atEnd() )
940 QByteArray line = file.readLine();
941 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
949 QStringList wordList;
950 wordList.append( QString() );
954 if ( !file.open( QIODevice::ReadOnly ) )
956 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
962 while ( !file.atEnd() )
964 QByteArray line = file.readLine();
965 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
973 QStringList wordList;
974 wordList.append( QString() );
978 if ( !file.open( QIODevice::ReadOnly ) )
980 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
984 while ( !file.atEnd() )
986 QByteArray line = file.readLine();
987 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
995 QMap<QString, QString> types;
996 types.insert( QString(), QString() );
999 if ( !file.open( QIODevice::ReadOnly ) )
1001 QgsDebugError( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
1005 types.insert( QString(), QString() );
1006 while ( !file.atEnd() )
1008 QByteArray line = file.readLine();
1009 QList<QByteArray> items = line.split(
';' );
1010 types.insert( items.at( 0 ).constData(), items.at( 1 ).constData() );
1024 return lineEditTitle->text();
1029 if (
title != lineEditTitle->text() )
1055void QgsMetadataWidget::syncFromCategoriesTabToKeywordsTab()
1057 if ( mCategoriesModel->rowCount() > 0 )
1059 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
1061 if ( !categories.isEmpty() )
1063 row = categories.at( 0 )->row();
1069 row = tabKeywords->rowCount() - 1;
1070 tabKeywords->item( row, 0 )->setText( QStringLiteral(
"gmd:topicCategory" ) );
1072 tabKeywords->item( row, 1 )->setText( mCategoriesModel->stringList().join( QLatin1Char(
',' ) ) );
1076void QgsMetadataWidget::updatePanel()
1078 int index = tabWidget->currentIndex();
1079 QString currentTabText = tabWidget->widget( index )->objectName();
1080 if ( currentTabText == QLatin1String(
"tabCategoriesDialog" ) )
1084 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
1085 if ( !categories.isEmpty() )
1087 const int row = categories.at( 0 )->row();
1088 mCategoriesModel->setStringList( tabKeywords->item( row, 1 )->text().split(
',' ) );
1092 mCategoriesModel->setStringList( QStringList() );
1095 else if ( currentTabText == QLatin1String(
"tabKeywordsDialog" ) )
1099 syncFromCategoriesTabToKeywordsTab();
1101 else if ( currentTabText == QLatin1String(
"tabValidationDialog" ) )
1107void QgsMetadataWidget::addNewCategory()
1110 QString text = QInputDialog::getText(
this, tr(
"New Category" ),
1111 tr(
"New Category:" ), QLineEdit::Normal,
1113 if ( ok && !text.isEmpty() )
1115 QStringList list = mCategoriesModel->stringList();
1116 if ( ! list.contains( text ) )
1118 list.append( text );
1119 mCategoriesModel->setStringList( list );
1120 mCategoriesModel->sort( 0 );
1125void QgsMetadataWidget::addDefaultCategories()
1127 const QModelIndexList selectedIndexes = listDefaultCategories->selectionModel()->selectedIndexes();
1128 QStringList defaultCategoriesList = mDefaultCategoriesModel->stringList();
1129 QStringList selectedCategories = mCategoriesModel->stringList();
1131 for (
const QModelIndex &selection : selectedIndexes )
1133 QVariant item = mDefaultCategoriesModel->data( selection, Qt::DisplayRole );
1134 defaultCategoriesList.removeOne( item.toString() );
1136 selectedCategories.append( item.toString() );
1139 mDefaultCategoriesModel->setStringList( defaultCategoriesList );
1140 mCategoriesModel->setStringList( selectedCategories );
1141 mCategoriesModel->sort( 0 );
1144void QgsMetadataWidget::removeSelectedCategories()
1146 const QModelIndexList selectedIndexes = listCategories->selectionModel()->selectedIndexes();
1147 QStringList categories = mCategoriesModel->stringList();
1148 QStringList defaultList = mDefaultCategoriesModel->stringList();
1150 for (
const QModelIndex &selection : selectedIndexes )
1152 QVariant item = mCategoriesModel->data( selection, Qt::DisplayRole );
1153 categories.removeOne( item.toString() );
1155 if ( mDefaultCategories.contains( item.toString() ) )
1157 defaultList.append( item.toString() );
1160 mCategoriesModel->setStringList( categories );
1162 mDefaultCategoriesModel->setStringList( defaultList );
1163 mDefaultCategoriesModel->sort( 0 );
1167LinkItemDelegate::LinkItemDelegate( QObject *parent )
1168 : QStyledItemDelegate( parent )
1173QWidget *LinkItemDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
1175 if ( index.column() == 1 )
1178 QComboBox *typeEditor =
new QComboBox( parent );
1179 typeEditor->setEditable(
true );
1180 QStringListModel *model =
new QStringListModel( parent );
1182 typeEditor->setModel( model );
1185 else if ( index.column() == 5 )
1188 QComboBox *mimeEditor =
new QComboBox( parent );
1189 mimeEditor->setEditable(
true );
1190 QStringListModel *model =
new QStringListModel( parent );
1192 mimeEditor->setModel( model );
1196 return QStyledItemDelegate::createEditor( parent, option, index );
1199ConstraintItemDelegate::ConstraintItemDelegate( QObject *parent )
1200 : QStyledItemDelegate( parent )
1205QWidget *ConstraintItemDelegate::createEditor( QWidget *parent,
const QStyleOptionViewItem &option,
const QModelIndex &index )
const
1207 if ( index.column() == 0 )
1210 QComboBox *typeEditor =
new QComboBox( parent );
1211 typeEditor->setEditable(
true );
1213 types << QStringLiteral(
"access" ) << QStringLiteral(
"use" ) << QStringLiteral(
"other" );
1214 QStringListModel *model =
new QStringListModel( parent );
1215 model->setStringList( types );
1216 typeEditor->setModel( model );
1220 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.