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 if ( selectedRows.empty() )
300 mConstraintsModel->removeRow( selectedRows[0].row() );
305 if ( ( mCrs.
isValid() ) && ( mLayer ) )
307 lblCurrentCrs->setText( tr(
"CRS: %1 - %2" ).arg( mCrs.
authid(), mCrs.
description() ) );
308 spatialExtentSelector->setEnabled(
true );
309 spatialExtentSelector->setOutputCrs( mCrs );
313 lblCurrentCrsStatus->setText( tr(
"Same as layer properties and provider." ) );
317 lblCurrentCrsStatus->setText( tr(
"Same as layer properties but different than the provider." ) );
321 lblCurrentCrsStatus->setText( tr(
"Same as the provider but different than the layer properties." ) );
325 lblCurrentCrsStatus->setText( tr(
"Does not match either layer properties or the provider." ) );
330 lblCurrentCrs->setText( tr(
"CRS: Not set." ) );
331 lblCurrentCrsStatus->setText( QString() );
332 spatialExtentSelector->setEnabled(
false );
336 void QgsMetadataWidget::addAddress()
338 int row = tabAddresses->rowCount();
339 tabAddresses->setRowCount( row + 1 );
340 QTableWidgetItem *pCell =
nullptr;
343 pCell =
new QTableWidgetItem( QString( tr(
"postal" ) ) );
344 tabAddresses->setItem( row, 0, pCell );
347 tabAddresses->setItem( row, 1,
new QTableWidgetItem() );
350 tabAddresses->setItem( row, 2,
new QTableWidgetItem() );
353 tabAddresses->setItem( row, 3,
new QTableWidgetItem() );
356 tabAddresses->setItem( row, 4,
new QTableWidgetItem() );
359 tabAddresses->setItem( row, 5,
new QTableWidgetItem() );
362 void QgsMetadataWidget::removeSelectedAddress()
364 QItemSelectionModel *selectionModel = tabAddresses->selectionModel();
365 const QModelIndexList selectedRows = selectionModel->selectedRows();
366 for (
int i = 0; i < selectedRows.size() ; i++ )
368 tabAddresses->model()->removeRow( selectedRows[i].row() );
372 void QgsMetadataWidget::fillCrsFromLayer()
374 mCrs = mLayer->
crs();
378 void QgsMetadataWidget::fillCrsFromProvider()
384 void QgsMetadataWidget::addLink()
386 int row = mLinksModel->rowCount();
387 mLinksModel->setItem( row, 0,
new QStandardItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) ) );
388 mLinksModel->setItem( row, 1,
new QStandardItem() );
389 mLinksModel->setItem( row, 2,
new QStandardItem() );
390 mLinksModel->setItem( row, 3,
new QStandardItem() );
391 mLinksModel->setItem( row, 4,
new QStandardItem() );
392 mLinksModel->setItem( row, 5,
new QStandardItem() );
393 mLinksModel->setItem( row, 6,
new QStandardItem() );
396 void QgsMetadataWidget::removeSelectedLink()
398 const QModelIndexList selectedRows = tabLinks->selectionModel()->selectedRows();
399 if ( selectedRows.empty() )
402 mLinksModel->removeRow( selectedRows[0].row() );
405 void QgsMetadataWidget::addHistory()
407 QString newHistory = QInputDialog::getText(
this, tr(
"New History" ), tr(
"New History" ) );
408 QStringList existingHistory = mHistoryModel->stringList();
409 if ( ! existingHistory.contains( newHistory ) )
411 existingHistory.append( newHistory );
412 mHistoryModel->setStringList( existingHistory );
416 void QgsMetadataWidget::removeSelectedHistory()
418 QItemSelectionModel *selection = listHistory->selectionModel();
419 if ( selection->hasSelection() )
421 QModelIndex indexElementSelectionne = selection->currentIndex();
423 QVariant item = mHistoryModel->data( indexElementSelectionne, Qt::DisplayRole );
424 QStringList list = mHistoryModel->stringList();
425 list.removeOne( item.toString() );
426 mHistoryModel->setStringList( list );
430 void QgsMetadataWidget::fillComboBox()
435 comboType->setEditable(
true );
438 const QStringList &keys = types.keys();
440 for (
const QString &type : keys )
442 comboType->insertItem( i, type );
443 comboType->setItemData( i, types.value( type ), Qt::ToolTipRole );
449 comboLanguage->setEditable(
true );
450 comboLanguage->clear();
452 const QStringList &k = countries.keys();
454 for (
const QString &countryCode : k )
456 comboLanguage->insertItem( i, countryCode );
457 comboLanguage->setItemData( i, countries.value( countryCode ), Qt::ToolTipRole );
462 void QgsMetadataWidget::setUiFromMetadata()
465 lineEditParentId->setText( mMetadata->parentIdentifier() );
468 if ( ! mMetadata->identifier().isEmpty() )
470 lineEditIdentifier->setText( mMetadata->identifier() );
474 if ( ! mMetadata->title().isEmpty() )
476 whileBlocking( lineEditTitle )->setText( mMetadata->title() );
480 if ( ! mMetadata->type().isEmpty() )
482 if ( comboType->findText( mMetadata->type() ) == -1 )
484 comboType->addItem( mMetadata->type() );
486 comboType->setCurrentIndex( comboType->findText( mMetadata->type() ) );
490 if ( ! mMetadata->language().isEmpty() )
492 if ( comboLanguage->findText( mMetadata->language() ) == -1 )
494 comboLanguage->addItem( mMetadata->language() );
496 comboLanguage->setCurrentIndex( comboLanguage->findText( mMetadata->language() ) );
500 textEditAbstract->setPlainText( mMetadata->abstract() );
503 mCategoriesModel->setStringList( mMetadata->categories() );
506 tabKeywords->setRowCount( 0 );
507 QMapIterator<QString, QStringList> i( mMetadata->keywords() );
508 while ( i.hasNext() )
512 int currentRow = tabKeywords->rowCount() - 1;
513 tabKeywords->item( currentRow, 0 )->setText( i.key() );
514 tabKeywords->item( currentRow, 1 )->setText( i.value().join( QStringLiteral(
"," ) ) );
517 if (
QgsLayerMetadata *layerMetadata = dynamic_cast< QgsLayerMetadata * >( mMetadata.get() ) )
520 comboEncoding->setCurrentText( layerMetadata->encoding() );
523 lineEditFees->setText( layerMetadata->fees() );
526 tabLicenses->setRowCount( 0 );
527 const QStringList &licenses = layerMetadata->licenses();
528 for (
const QString &licence : licenses )
530 int currentRow = tabLicenses->rowCount();
531 tabLicenses->setRowCount( currentRow + 1 );
532 QTableWidgetItem *pCell = tabLicenses->item( currentRow, 0 );
535 pCell =
new QTableWidgetItem;
536 tabLicenses->setItem( currentRow, 0, pCell );
538 pCell->setText( licence );
542 mRightsModel->setStringList( layerMetadata->rights() );
545 const QList<QgsLayerMetadata::Constraint> &constraints = layerMetadata->constraints();
548 int row = mConstraintsModel->rowCount();
549 mConstraintsModel->setItem( row, 0,
new QStandardItem( constraint.type ) );
550 mConstraintsModel->setItem( row, 1,
new QStandardItem( constraint.constraint ) );
554 mCrs = layerMetadata->crs();
558 const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = layerMetadata->extent().spatialExtents();
559 if ( ! spatialExtents.isEmpty() )
562 spatialExtentSelector->setOutputCrs( spatialExtents.at( 0 ).extentCrs );
563 spatialExtentSelector->setOriginalExtent( spatialExtents.at( 0 ).bounds.toRectangle(), spatialExtents.at( 0 ).extentCrs );
564 spatialExtentSelector->setOutputExtentFromOriginal();
565 spinBoxZMaximum->setValue( spatialExtents.at( 0 ).bounds.zMaximum() );
566 spinBoxZMinimum->setValue( spatialExtents.at( 0 ).bounds.zMinimum() );
570 const QList<QgsDateTimeRange> &temporalExtents = layerMetadata->extent().temporalExtents();
571 if ( ! temporalExtents.isEmpty() )
574 dateTimeFrom->setDateTime( temporalExtents.at( 0 ).begin() );
575 dateTimeTo->setDateTime( temporalExtents.at( 0 ).end() );
579 dateTimeFrom->clear();
583 else if (
QgsProjectMetadata *projectMetadata = dynamic_cast< QgsProjectMetadata * >( mMetadata.get() ) )
585 mLineEditAuthor->setText( projectMetadata->author() );
586 mCreationDateTimeEdit->setDateTime( projectMetadata->creationDateTime() );
590 const QList<QgsAbstractMetadataBase::Contact> &contacts = mMetadata->contacts();
591 if ( ! contacts.isEmpty() )
595 lineEditContactName->setText( contact.
name );
596 lineEditContactEmail->setText( contact.
email );
597 lineEditContactFax->setText( contact.
fax );
598 lineEditContactOrganization->setText( contact.
organization );
599 lineEditContactPosition->setText( contact.
position );
600 lineEditContactVoice->setText( contact.
voice );
601 if ( comboContactRole->findText( contact.
role ) == -1 )
603 comboContactRole->addItem( contact.
role );
605 comboContactRole->setCurrentIndex( comboContactRole->findText( contact.
role ) );
606 tabAddresses->setRowCount( 0 );
607 const QList<QgsAbstractMetadataBase::Address> &addresses = contact.
addresses;
610 int currentRow = tabAddresses->rowCount();
611 tabAddresses->setRowCount( currentRow + 1 );
612 tabAddresses->setItem( currentRow, 0,
new QTableWidgetItem( address.type ) );
613 tabAddresses->setItem( currentRow, 1,
new QTableWidgetItem( address.address ) );
614 tabAddresses->setItem( currentRow, 2,
new QTableWidgetItem( address.postalCode ) );
615 tabAddresses->setItem( currentRow, 3,
new QTableWidgetItem( address.city ) );
616 tabAddresses->setItem( currentRow, 4,
new QTableWidgetItem( address.administrativeArea ) );
617 tabAddresses->setItem( currentRow, 5,
new QTableWidgetItem( address.country ) );
622 const QList<QgsAbstractMetadataBase::Link> &links = mMetadata->links();
623 mLinksModel->setRowCount( 0 );
626 int row = mLinksModel->rowCount();
627 mLinksModel->setItem( row, 0,
new QStandardItem( link.name ) );
628 mLinksModel->setItem( row, 1,
new QStandardItem( link.type ) );
629 mLinksModel->setItem( row, 2,
new QStandardItem( link.url ) );
630 mLinksModel->setItem( row, 3,
new QStandardItem( link.description ) );
631 mLinksModel->setItem( row, 4,
new QStandardItem( link.format ) );
632 mLinksModel->setItem( row, 5,
new QStandardItem( link.mimeType ) );
633 mLinksModel->setItem( row, 6,
new QStandardItem( link.size ) );
637 mHistoryModel->setStringList( mMetadata->history() );
647 metadata->
setTitle( lineEditTitle->text() );
648 metadata->
setType( comboType->currentText() );
649 metadata->
setLanguage( comboLanguage->currentText() );
650 metadata->
setAbstract( textEditAbstract->toPlainText() );
653 syncFromCategoriesTabToKeywordsTab();
654 QMap<QString, QStringList> keywords;
655 for (
int i = 0; i < tabKeywords->rowCount() ; i++ )
657 keywords.insert( tabKeywords->item( i, 0 )->text(), tabKeywords->item( i, 1 )->text().split(
',' ) );
667 layerMetadata->
setFees( lineEditFees->text() );
670 QStringList licenses;
671 for (
int i = 0; i < tabLicenses->rowCount() ; i++ )
673 licenses.append( tabLicenses->item( i, 0 )->text() );
678 layerMetadata->
setRights( mRightsModel->stringList() );
681 layerMetadata->
setEncoding( comboEncoding->currentText() );
684 QList<QgsLayerMetadata::Constraint> constraints;
685 for (
int row = 0; row < mConstraintsModel->rowCount() ; row++ )
688 constraint.
type = mConstraintsModel->item( row, 0 )->text();
689 constraint.
constraint = mConstraintsModel->item( row, 1 )->text();
690 constraints.append( constraint );
697 layerMetadata->
setCrs( mCrs );
702 spatialExtent.
bounds =
QgsBox3d( spatialExtentSelector->outputExtent() );
705 spatialExtent.
extentCrs = spatialExtentSelector->outputCrs();
706 QList<QgsLayerMetadata::SpatialExtent> spatialExtents;
707 spatialExtents.append( spatialExtent );
708 QList<QgsDateTimeRange> temporalExtents;
709 temporalExtents.append( QgsDateTimeRange( dateTimeFrom->dateTime(), dateTimeTo->dateTime() ) );
720 projectMetadata->
setAuthor( mLineEditAuthor->text() );
728 QList<QgsAbstractMetadataBase::Contact> contacts = mMetadata->contacts();
729 if ( contacts.size() > 0 )
730 contacts.removeFirst();
732 contact.
email = lineEditContactEmail->text();
733 contact.
position = lineEditContactPosition->text();
734 contact.
fax = lineEditContactFax->text();
735 contact.
voice = lineEditContactVoice->text();
736 contact.
name = lineEditContactName->text();
737 contact.
organization = lineEditContactOrganization->text();
738 contact.
role = comboContactRole->currentText();
739 QList<QgsAbstractMetadataBase::Address> addresses;
740 for (
int i = 0; i < tabAddresses->rowCount() ; i++ )
743 address.
type = tabAddresses->item( i, 0 )->text();
744 address.
address = tabAddresses->item( i, 1 )->text();
745 address.
postalCode = tabAddresses->item( i, 2 )->text();
746 address.
city = tabAddresses->item( i, 3 )->text();
748 address.
country = tabAddresses->item( i, 5 )->text();
749 addresses.append( address );
752 contacts.insert( 0, contact );
756 QList<QgsAbstractMetadataBase::Link> links;
757 for (
int row = 0; row < mLinksModel->rowCount() ; row++ )
760 link.
name = mLinksModel->item( row, 0 )->text();
761 link.
type = mLinksModel->item( row, 1 )->text();
762 link.
url = mLinksModel->item( row, 2 )->text();
763 link.
description = mLinksModel->item( row, 3 )->text();
764 link.
format = mLinksModel->item( row, 4 )->text();
765 link.
mimeType = mLinksModel->item( row, 5 )->text();
766 link.
size = mLinksModel->item( row, 6 )->text();
767 links.append( link );
772 metadata->
setHistory( mHistoryModel->stringList() );
777 std::unique_ptr< QgsAbstractMetadataBase > md(
metadata() );
779 std::unique_ptr< QgsNativeMetadataBaseValidator > validator;
783 validator = qgis::make_unique< QgsNativeMetadataValidator>();
787 validator = qgis::make_unique< QgsNativeProjectMetadataValidator>();
791 QList<QgsAbstractMetadataBaseValidator::ValidationResult> validationResults;
792 bool results = validator->validate( md.get(), validationResults );
799 errors += QLatin1String(
"<b>" ) % result.section;
800 if ( ! result.identifier.isNull() )
802 errors += QLatin1String(
" " ) % QVariant( result.identifier.toInt() + 1 ).toString();
804 errors += QLatin1String(
"</b>: " ) % result.note % QLatin1String(
"<br />" );
809 errors = QString( tr(
"Ok, it seems valid according to the QGIS Schema." ) );
813 myStyle.append( QStringLiteral(
"body { margin: 10px; }\n " ) );
814 resultsCheckMetadata->clear();
815 resultsCheckMetadata->document()->setDefaultStyleSheet( myStyle );
816 resultsCheckMetadata->setHtml( errors );
823 QMap<QString, QString> countries;
824 countries.insert( QString(), QString() );
828 if ( !file.open( QIODevice::ReadOnly ) )
830 QgsDebugMsg( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
836 while ( !file.atEnd() )
838 QByteArray line = file.readLine();
839 QList<QByteArray> items = line.split(
',' );
840 countries.insert( QString( items.at( 0 ).constData() ).trimmed(), QString( items.at( 1 ).constData() ).trimmed() );
845 QFile secondFile( path );
846 if ( !secondFile.open( QIODevice::ReadOnly ) )
848 QgsDebugMsg( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
853 secondFile.readLine();
854 while ( !secondFile.atEnd() )
856 QByteArray line = secondFile.readLine();
857 QList<QByteArray> items = line.split(
',' );
858 countries.insert( QString( items.at( 2 ).constData() ).trimmed(), QString( items.at( 0 ).constData() ).trimmed() );
866 QStringList wordList;
867 wordList.append( QString() );
871 if ( !file.open( QIODevice::ReadOnly ) )
873 QgsDebugMsg( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
879 while ( !file.atEnd() )
881 QByteArray line = file.readLine();
882 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
890 QStringList wordList;
891 wordList.append( QString() );
895 if ( !file.open( QIODevice::ReadOnly ) )
897 QgsDebugMsg( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
903 while ( !file.atEnd() )
905 QByteArray line = file.readLine();
906 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
914 QStringList wordList;
915 wordList.append( QString() );
919 if ( !file.open( QIODevice::ReadOnly ) )
921 QgsDebugMsg( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
925 while ( !file.atEnd() )
927 QByteArray line = file.readLine();
928 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
936 QMap<QString, QString> types;
937 types.insert( QString(), QString() );
940 if ( !file.open( QIODevice::ReadOnly ) )
942 QgsDebugMsg( QStringLiteral(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
946 types.insert( QString(), QString() );
947 while ( !file.atEnd() )
949 QByteArray line = file.readLine();
950 QList<QByteArray> items = line.split(
';' );
951 types.insert( items.at( 0 ).constData(), items.at( 1 ).constData() );
965 return lineEditTitle->text();
970 if ( title != lineEditTitle->text() )
986 mLayer->
setMetadata( *static_cast< QgsLayerMetadata * >( mMetadata.get() ) );
996 void QgsMetadataWidget::syncFromCategoriesTabToKeywordsTab()
998 if ( mCategoriesModel->rowCount() > 0 )
1000 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
1002 if ( !categories.isEmpty() )
1004 row = categories.at( 0 )->row();
1010 row = tabKeywords->rowCount() - 1;
1011 tabKeywords->item( row, 0 )->setText( QStringLiteral(
"gmd:topicCategory" ) );
1013 tabKeywords->item( row, 1 )->setText( mCategoriesModel->stringList().join( QStringLiteral(
"," ) ) );
1017 void QgsMetadataWidget::updatePanel()
1019 int index = tabWidget->currentIndex();
1020 QString currentTabText = tabWidget->widget( index )->objectName();
1021 if ( currentTabText == QStringLiteral(
"tabCategoriesDialog" ) )
1025 QList<QTableWidgetItem *> categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
1026 if ( !categories.isEmpty() )
1028 int row = categories.at( 0 )->row();
1029 mCategoriesModel->setStringList( tabKeywords->item( row, 1 )->text().split(
',' ) );
1033 mCategoriesModel->setStringList( QStringList() );
1036 else if ( currentTabText == QStringLiteral(
"tabKeywordsDialog" ) )
1040 syncFromCategoriesTabToKeywordsTab();
1042 else if ( currentTabText == QStringLiteral(
"tabValidationDialog" ) )
1048 void QgsMetadataWidget::addNewCategory()
1051 QString text = QInputDialog::getText(
this, tr(
"New Category" ),
1052 tr(
"New Category:" ), QLineEdit::Normal,
1054 if ( ok && !text.isEmpty() )
1056 QStringList list = mCategoriesModel->stringList();
1057 if ( ! list.contains( text ) )
1059 list.append( text );
1060 mCategoriesModel->setStringList( list );
1061 mCategoriesModel->sort( 0 );
1066 void QgsMetadataWidget::addDefaultCategories()
1068 const QModelIndexList selectedIndexes = listDefaultCategories->selectionModel()->selectedIndexes();
1069 QStringList defaultCategoriesList = mDefaultCategoriesModel->stringList();
1070 QStringList selectedCategories = mCategoriesModel->stringList();
1072 for (
const QModelIndex &selection : selectedIndexes )
1074 QVariant item = mDefaultCategoriesModel->data( selection, Qt::DisplayRole );
1075 defaultCategoriesList.removeOne( item.toString() );
1077 selectedCategories.append( item.toString() );
1080 mDefaultCategoriesModel->setStringList( defaultCategoriesList );
1081 mCategoriesModel->setStringList( selectedCategories );
1082 mCategoriesModel->sort( 0 );
1085 void QgsMetadataWidget::removeSelectedCategories()
1087 const QModelIndexList selectedIndexes = listCategories->selectionModel()->selectedIndexes();
1088 QStringList categories = mCategoriesModel->stringList();
1089 QStringList defaultList = mDefaultCategoriesModel->stringList();
1091 for (
const QModelIndex &selection : selectedIndexes )
1093 QVariant item = mCategoriesModel->data( selection, Qt::DisplayRole );
1094 categories.removeOne( item.toString() );
1096 if ( mDefaultCategories.contains( item.toString() ) )
1098 defaultList.append( item.toString() );
1101 mCategoriesModel->setStringList( categories );
1103 mDefaultCategoriesModel->setStringList( defaultList );
1104 mDefaultCategoriesModel->sort( 0 );
1108 : QStyledItemDelegate( parent )
1115 if ( index.column() == 1 )
1118 QComboBox *typeEditor =
new QComboBox( parent );
1119 typeEditor->setEditable(
true );
1120 QStringListModel *model =
new QStringListModel( parent );
1122 typeEditor->setModel( model );
1125 else if ( index.column() == 5 )
1128 QComboBox *mimeEditor =
new QComboBox( parent );
1129 mimeEditor->setEditable(
true );
1130 QStringListModel *model =
new QStringListModel( parent );
1132 mimeEditor->setModel( model );
1136 return QStyledItemDelegate::createEditor( parent, option, index );
1140 : QStyledItemDelegate( parent )
1147 if ( index.column() == 0 )
1150 QComboBox *typeEditor =
new QComboBox( parent );
1151 typeEditor->setEditable(
true );
1153 types << QStringLiteral(
"access" ) << QStringLiteral(
"use" ) << QStringLiteral(
"other" );
1154 QStringListModel *model =
new QStringListModel( parent );
1155 model->setStringList( types );
1156 typeEditor->setModel( model );
1160 return QStyledItemDelegate::createEditor( parent, option, index );
Base class for all map layer types.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider, it may be null.
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.
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.
QgsCoordinateReferenceSystem crs
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setZMaximum(double z)
Sets the maximum z value.