20 #include <QPushButton> 23 #include <QInputDialog> 24 #include <QStringListModel> 42 tabWidget->setCurrentIndex( 0 );
45 encodingFrame->setHidden(
true );
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 );
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 );
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 );
86 mHistoryModel =
new QStringListModel( listHistory );
87 listHistory->setModel( mHistoryModel );
90 connect( tabWidget, &QTabWidget::currentChanged,
this, &QgsMetadataWidget::updatePanel );
91 connect( btnAutoSource, &QPushButton::clicked,
this, &QgsMetadataWidget::fillSourceFromLayer );
92 connect( btnAddVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::addVocabulary );
93 connect( btnRemoveVocabulary, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedVocabulary );
94 connect( btnAddRight, &QPushButton::clicked,
this, &QgsMetadataWidget::addRight );
95 connect( btnRemoveRight, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedRight );
96 connect( btnAddLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::addLicence );
97 connect( btnRemoveLicence, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLicence );
98 connect( btnAddConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::addConstraint );
99 connect( btnRemoveConstraint, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedConstraint );
100 connect( btnSetCrsFromLayer, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromLayer );
101 connect( btnSetCrsFromProvider, &QPushButton::clicked,
this, &QgsMetadataWidget::fillCrsFromProvider );
102 connect( btnAddAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::addAddress );
103 connect( btnRemoveAddress, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedAddress );
104 connect( btnAddLink, &QPushButton::clicked,
this, &QgsMetadataWidget::addLink );
105 connect( btnRemoveLink, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedLink );
106 connect( btnAddHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::addHistory );
107 connect( btnRemoveHistory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedHistory );
108 connect( btnNewCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addNewCategory );
109 connect( btnAddDefaultCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::addDefaultCategories );
110 connect( btnRemoveCategory, &QPushButton::clicked,
this, &QgsMetadataWidget::removeSelectedCategories );
115 btnAutoSource->setEnabled(
false );
116 btnAutoEncoding->setEnabled(
false );
117 btnSetCrsFromLayer->setEnabled(
false );
124 mMetadata = layerMetadata;
125 setPropertiesFromLayer();
135 void QgsMetadataWidget::fillSourceFromLayer()
143 void QgsMetadataWidget::addVocabulary()
145 int row = tabKeywords->rowCount();
146 tabKeywords->setRowCount( row + 1 );
147 QTableWidgetItem *pCell =
nullptr;
150 pCell =
new QTableWidgetItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) );
151 tabKeywords->setItem( row, 0, pCell );
154 pCell =
new QTableWidgetItem();
155 tabKeywords->setItem( row, 1, pCell );
158 void QgsMetadataWidget::removeSelectedVocabulary()
160 QItemSelectionModel *selectionModel = tabKeywords->selectionModel();
161 const QModelIndexList selectedRows = selectionModel->selectedRows();
162 for (
int i = 0; i < selectedRows.size() ; i++ )
164 tabKeywords->model()->removeRow( selectedRows[i].row() );
168 void QgsMetadataWidget::addLicence()
170 QString newLicence = QInputDialog::getItem(
this, tr(
"New Licence" ), tr(
"New Licence" ),
parseLicenses(), 0,
true );
171 if ( tabLicenses->findItems( newLicence, Qt::MatchExactly ).isEmpty() )
173 int row = tabLicenses->rowCount();
174 tabLicenses->setRowCount( row + 1 );
175 QTableWidgetItem *pCell =
new QTableWidgetItem( newLicence );
176 tabLicenses->setItem( row, 0, pCell );
180 void QgsMetadataWidget::removeSelectedLicence()
182 QItemSelectionModel *selectionModel = tabLicenses->selectionModel();
183 const QModelIndexList selectedRows = selectionModel->selectedRows();
184 for (
int i = 0; i < selectedRows.size() ; i++ )
186 tabLicenses->model()->removeRow( selectedRows[i].row() );
190 void QgsMetadataWidget::addRight()
192 QString newRight = QInputDialog::getText(
this, tr(
"New Right" ), tr(
"New Right" ) );
193 QStringList existingRights = mRightsModel->stringList();
194 if ( ! existingRights.contains( newRight ) )
196 existingRights.append( newRight );
197 mRightsModel->setStringList( existingRights );
201 void QgsMetadataWidget::removeSelectedRight()
203 QItemSelectionModel *selection = listRights->selectionModel();
204 if ( selection->hasSelection() )
206 QModelIndex indexElementSelectionne = selection->currentIndex();
208 QVariant item = mRightsModel->data( indexElementSelectionne, Qt::DisplayRole );
209 QStringList list = mRightsModel->stringList();
210 list.removeOne( item.toString() );
211 mRightsModel->setStringList( list );
215 void QgsMetadataWidget::addConstraint()
217 int row = mConstraintsModel->rowCount();
218 mConstraintsModel->setItem( row, 0,
new QStandardItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) ) );
219 mConstraintsModel->setItem( row, 1,
new QStandardItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) ) );
222 void QgsMetadataWidget::removeSelectedConstraint()
224 const QModelIndexList selectedRows = tabConstraints->selectionModel()->selectedRows();
225 mConstraintsModel->removeRow( selectedRows[0].row() );
230 if ( ( mCrs.
isValid() ) && ( mLayer ) )
232 lblCurrentCrs->setText( tr(
"CRS: %1 - %2" ).arg( mCrs.
authid(), mCrs.
description() ) );
233 spatialExtentSelector->setEnabled(
true );
234 spatialExtentSelector->setOutputCrs( mCrs );
238 lblCurrentCrsStatus->setText( tr(
"Same as layer properties and provider." ) );
242 lblCurrentCrsStatus->setText( tr(
"Same as layer properties but different than the provider." ) );
246 lblCurrentCrsStatus->setText( tr(
"Same as the provider but different than the layer properties." ) );
250 lblCurrentCrsStatus->setText( tr(
"Does not match either layer properties or the provider." ) );
255 lblCurrentCrs->setText( tr(
"CRS: Not set." ) );
256 lblCurrentCrsStatus->setText( QString() );
257 spatialExtentSelector->setEnabled(
false );
261 void QgsMetadataWidget::addAddress()
263 int row = tabAddresses->rowCount();
264 tabAddresses->setRowCount( row + 1 );
265 QTableWidgetItem *pCell =
nullptr;
268 pCell =
new QTableWidgetItem( QString( tr(
"postal" ) ) );
269 tabAddresses->setItem( row, 0, pCell );
272 tabAddresses->setItem( row, 1,
new QTableWidgetItem() );
275 tabAddresses->setItem( row, 2,
new QTableWidgetItem() );
278 tabAddresses->setItem( row, 3,
new QTableWidgetItem() );
281 tabAddresses->setItem( row, 4,
new QTableWidgetItem() );
284 tabAddresses->setItem( row, 5,
new QTableWidgetItem() );
287 void QgsMetadataWidget::removeSelectedAddress()
289 QItemSelectionModel *selectionModel = tabAddresses->selectionModel();
290 const QModelIndexList selectedRows = selectionModel->selectedRows();
291 for (
int i = 0; i < selectedRows.size() ; i++ )
293 tabAddresses->model()->removeRow( selectedRows[i].row() );
297 void QgsMetadataWidget::fillCrsFromLayer()
299 mCrs = mLayer->
crs();
303 void QgsMetadataWidget::fillCrsFromProvider()
309 void QgsMetadataWidget::addLink()
311 int row = mLinksModel->rowCount();
312 mLinksModel->setItem( row, 0,
new QStandardItem( QString( tr(
"undefined %1" ) ).arg( row + 1 ) ) );
313 mLinksModel->setItem( row, 1,
new QStandardItem() );
314 mLinksModel->setItem( row, 2,
new QStandardItem() );
315 mLinksModel->setItem( row, 3,
new QStandardItem() );
316 mLinksModel->setItem( row, 4,
new QStandardItem() );
317 mLinksModel->setItem( row, 5,
new QStandardItem() );
318 mLinksModel->setItem( row, 6,
new QStandardItem() );
321 void QgsMetadataWidget::removeSelectedLink()
323 const QModelIndexList selectedRows = tabLinks->selectionModel()->selectedRows();
324 mLinksModel->removeRow( selectedRows[0].row() );
327 void QgsMetadataWidget::addHistory()
329 QString newHistory = QInputDialog::getText(
this, tr(
"New History" ), tr(
"New History" ) );
330 QStringList existingHistory = mHistoryModel->stringList();
331 if ( ! existingHistory.contains( newHistory ) )
333 existingHistory.append( newHistory );
334 mHistoryModel->setStringList( existingHistory );
338 void QgsMetadataWidget::removeSelectedHistory()
340 QItemSelectionModel *selection = listHistory->selectionModel();
341 if ( selection->hasSelection() )
343 QModelIndex indexElementSelectionne = selection->currentIndex();
345 QVariant item = mHistoryModel->data( indexElementSelectionne, Qt::DisplayRole );
346 QStringList list = mHistoryModel->stringList();
347 list.removeOne( item.toString() );
348 mHistoryModel->setStringList( list );
352 void QgsMetadataWidget::fillComboBox()
357 comboType->setEditable(
true );
360 const QStringList &keys = types.keys();
362 for (
const QString &type : keys )
364 comboType->insertItem( i, type );
365 comboType->setItemData( i, types.value( type ), Qt::ToolTipRole );
371 comboLanguage->setEditable(
true );
372 comboLanguage->clear();
374 const QStringList &k = countries.keys();
376 for (
const QString &countryCode : k )
378 comboLanguage->insertItem( i, countryCode );
379 comboLanguage->setItemData( i, countries.value( countryCode ), Qt::ToolTipRole );
384 void QgsMetadataWidget::setPropertiesFromLayer()
392 lineEditIdentifier->setText( mMetadata.
identifier() );
396 if ( ! mMetadata.
title().isEmpty() )
398 lineEditTitle->setText( mMetadata.
title() );
402 if ( ! mMetadata.
type().isEmpty() )
404 if ( comboType->findText( mMetadata.
type() ) == -1 )
406 comboType->addItem( mMetadata.
type() );
408 comboType->setCurrentIndex( comboType->findText( mMetadata.
type() ) );
412 if ( ! mMetadata.
language().isEmpty() )
414 if ( comboLanguage->findText( mMetadata.
language() ) == -1 )
416 comboLanguage->addItem( mMetadata.
language() );
418 comboLanguage->setCurrentIndex( comboLanguage->findText( mMetadata.
language() ) );
422 textEditAbstract->setPlainText( mMetadata.
abstract() );
425 mCategoriesModel->setStringList( mMetadata.
categories() );
428 tabKeywords->setRowCount( 0 );
429 QMapIterator<QString, QStringList> i( mMetadata.
keywords() );
430 while ( i.hasNext() )
434 int currentRow = tabKeywords->rowCount() - 1;
435 tabKeywords->item( currentRow, 0 )->setText( i.key() );
436 tabKeywords->item( currentRow, 1 )->setText( i.value().join( QStringLiteral(
"," ) ) );
440 lineEditFees->setText( mMetadata.
fees() );
443 tabLicenses->setRowCount( 0 );
444 const QStringList &licenses = mMetadata.
licenses();
445 for (
const QString &licence : licenses )
447 int currentRow = tabLicenses->rowCount();
448 tabLicenses->setRowCount( currentRow + 1 );
449 QTableWidgetItem *pCell = tabLicenses->item( currentRow, 0 );
452 pCell =
new QTableWidgetItem;
453 tabLicenses->setItem( currentRow, 0, pCell );
455 pCell->setText( licence );
459 mRightsModel->setStringList( mMetadata.
rights() );
462 const QList<QgsLayerMetadata::Constraint> &constraints = mMetadata.
constraints();
465 int row = mConstraintsModel->rowCount();
466 mConstraintsModel->setItem( row, 0,
new QStandardItem( constraint.type ) );
467 mConstraintsModel->setItem( row, 1,
new QStandardItem( constraint.constraint ) );
471 mCrs = mMetadata.
crs();
475 const QList<QgsLayerMetadata::SpatialExtent> &spatialExtents = mMetadata.
extent().
spatialExtents();
476 if ( ! spatialExtents.isEmpty() )
479 spatialExtentSelector->setOutputCrs( spatialExtents.at( 0 ).extentCrs );
480 spatialExtentSelector->setOriginalExtent( spatialExtents.at( 0 ).bounds.toRectangle(), spatialExtents.at( 0 ).extentCrs );
481 spatialExtentSelector->setOutputExtentFromOriginal();
482 spinBoxZMaximum->setValue( spatialExtents.at( 0 ).bounds.zMaximum() );
483 spinBoxZMinimum->setValue( spatialExtents.at( 0 ).bounds.zMinimum() );
488 if ( ! temporalExtents.isEmpty() )
491 dateTimeFrom->setDateTime( temporalExtents.at( 0 ).begin() );
492 dateTimeTo->setDateTime( temporalExtents.at( 0 ).end() );
496 dateTimeFrom->clear();
501 const QList<QgsLayerMetadata::Contact> &contacts = mMetadata.
contacts();
502 if ( ! contacts.isEmpty() )
506 lineEditContactName->setText( contact.
name );
507 lineEditContactEmail->setText( contact.
email );
508 lineEditContactFax->setText( contact.
fax );
509 lineEditContactOrganization->setText( contact.
organization );
510 lineEditContactPosition->setText( contact.
position );
511 lineEditContactVoice->setText( contact.
voice );
512 if ( comboContactRole->findText( contact.
role ) == -1 )
514 comboContactRole->addItem( contact.
role );
516 comboContactRole->setCurrentIndex( comboContactRole->findText( contact.
role ) );
517 tabAddresses->setRowCount( 0 );
518 const QList<QgsLayerMetadata::Address> &addresses = contact.
addresses;
521 int currentRow = tabAddresses->rowCount();
522 tabAddresses->setRowCount( currentRow + 1 );
523 tabAddresses->setItem( currentRow, 0,
new QTableWidgetItem( address.type ) );
524 tabAddresses->setItem( currentRow, 1,
new QTableWidgetItem( address.address ) );
525 tabAddresses->setItem( currentRow, 2,
new QTableWidgetItem( address.postalCode ) );
526 tabAddresses->setItem( currentRow, 3,
new QTableWidgetItem( address.city ) );
527 tabAddresses->setItem( currentRow, 4,
new QTableWidgetItem( address.administrativeArea ) );
528 tabAddresses->setItem( currentRow, 5,
new QTableWidgetItem( address.country ) );
533 const QList<QgsLayerMetadata::Link> &links = mMetadata.
links();
534 mLinksModel->setRowCount( 0 );
537 int row = mLinksModel->rowCount();
538 mLinksModel->setItem( row, 0,
new QStandardItem( link.name ) );
539 mLinksModel->setItem( row, 1,
new QStandardItem( link.type ) );
540 mLinksModel->setItem( row, 2,
new QStandardItem( link.url ) );
541 mLinksModel->setItem( row, 3,
new QStandardItem( link.description ) );
542 mLinksModel->setItem( row, 4,
new QStandardItem( link.format ) );
543 mLinksModel->setItem( row, 5,
new QStandardItem( link.mimeType ) );
544 mLinksModel->setItem( row, 6,
new QStandardItem( link.size ) );
548 mHistoryModel->setStringList( mMetadata.
history() );
555 layerMetadata.
setTitle( lineEditTitle->text() );
556 layerMetadata.
setType( comboType->currentText() );
557 layerMetadata.
setLanguage( comboLanguage->currentText() );
558 layerMetadata.
setAbstract( textEditAbstract->toPlainText() );
561 syncFromCategoriesTabToKeywordsTab();
562 QMap<QString, QStringList> keywords;
563 for (
int i = 0; i < tabKeywords->rowCount() ; i++ )
565 keywords.insert( tabKeywords->item( i, 0 )->text(), tabKeywords->item( i, 1 )->text().split(
',' ) );
570 layerMetadata.
setFees( lineEditFees->text() );
573 QStringList licenses;
574 for (
int i = 0; i < tabLicenses->rowCount() ; i++ )
576 licenses.append( tabLicenses->item( i, 0 )->text() );
581 layerMetadata.
setRights( mRightsModel->stringList() );
584 QList<QgsLayerMetadata::Constraint> constraints;
585 for (
int row = 0; row < mConstraintsModel->rowCount() ; row++ )
588 constraint.
type = mConstraintsModel->item( row, 0 )->text();
589 constraint.
constraint = mConstraintsModel->item( row, 1 )->text();
590 constraints.append( constraint );
597 layerMetadata.
setCrs( mCrs );
602 spatialExtent.
bounds =
QgsBox3d( spatialExtentSelector->outputExtent() );
605 spatialExtent.
extentCrs = spatialExtentSelector->outputCrs();
606 QList<QgsLayerMetadata::SpatialExtent> spatialExtents;
607 spatialExtents.append( spatialExtent );
608 QList<QgsDateTimeRange> temporalExtents;
609 temporalExtents.append( QgsDateTimeRange( dateTimeFrom->dateTime(), dateTimeTo->dateTime() ) );
618 if ( contacts.size() > 0 )
619 contacts.removeFirst();
621 contact.
email = lineEditContactEmail->text();
622 contact.
position = lineEditContactPosition->text();
623 contact.
fax = lineEditContactFax->text();
624 contact.
voice = lineEditContactVoice->text();
625 contact.
name = lineEditContactName->text();
626 contact.
organization = lineEditContactOrganization->text();
627 contact.
role = comboContactRole->currentText();
628 QList<QgsLayerMetadata::Address>
addresses;
629 for (
int i = 0; i < tabAddresses->rowCount() ; i++ )
632 address.
type = tabAddresses->item( i, 0 )->text();
633 address.
address = tabAddresses->item( i, 1 )->text();
634 address.
postalCode = tabAddresses->item( i, 2 )->text();
635 address.
city = tabAddresses->item( i, 3 )->text();
637 address.
country = tabAddresses->item( i, 5 )->text();
638 addresses.append( address );
641 contacts.insert( 0, contact );
645 QList<QgsLayerMetadata::Link>
links;
646 for (
int row = 0; row < mLinksModel->rowCount() ; row++ )
649 link.
name = mLinksModel->item( row, 0 )->text();
650 link.
type = mLinksModel->item( row, 1 )->text();
651 link.
url = mLinksModel->item( row, 2 )->text();
652 link.
description = mLinksModel->item( row, 3 )->text();
653 link.
format = mLinksModel->item( row, 4 )->text();
654 link.
mimeType = mLinksModel->item( row, 5 )->text();
655 link.
size = mLinksModel->item( row, 6 )->text();
656 links.append( link );
661 layerMetadata.
setHistory( mHistoryModel->stringList() );
669 QList<QgsMetadataValidator::ValidationResult> validationResults;
670 bool results = validator.
validate( metadata, validationResults );
677 errors += QLatin1String(
"<b>" ) % result.section;
678 if ( ! result.identifier.isNull() )
680 errors += QLatin1String(
" " ) % QVariant( result.identifier.toInt() + 1 ).toString();
682 errors += QLatin1String(
"</b>: " ) % result.note % QLatin1String(
"<br />" );
687 errors = QString( tr(
"Ok, it seems valid according to the QGIS Schema." ) );
691 myStyle.append( QStringLiteral(
"body { margin: 10px; }\n " ) );
692 resultsCheckMetadata->clear();
693 resultsCheckMetadata->document()->setDefaultStyleSheet( myStyle );
694 resultsCheckMetadata->setHtml( errors );
701 QMap<QString, QString> countries;
702 countries.insert( QString(), QString() );
706 if ( !file.open( QIODevice::ReadOnly ) )
708 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
714 while ( !file.atEnd() )
716 QByteArray line = file.readLine();
717 QList<QByteArray> items = line.split(
',' );
718 countries.insert( QString( items.at( 0 ).constData() ).trimmed(), QString( items.at( 1 ).constData() ).trimmed() );
723 QFile secondFile( path );
724 if ( !secondFile.open( QIODevice::ReadOnly ) )
726 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
731 secondFile.readLine();
732 while ( !secondFile.atEnd() )
734 QByteArray line = secondFile.readLine();
735 QList<QByteArray> items = line.split(
',' );
736 countries.insert( QString( items.at( 2 ).constData() ).trimmed(), QString( items.at( 0 ).constData() ).trimmed() );
744 QStringList wordList;
745 wordList.append( QString() );
749 if ( !file.open( QIODevice::ReadOnly ) )
751 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
757 while ( !file.atEnd() )
759 QByteArray line = file.readLine();
760 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
768 QStringList wordList;
769 wordList.append( QString() );
773 if ( !file.open( QIODevice::ReadOnly ) )
775 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
781 while ( !file.atEnd() )
783 QByteArray line = file.readLine();
784 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
792 QStringList wordList;
793 wordList.append( QString() );
797 if ( !file.open( QIODevice::ReadOnly ) )
799 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
803 while ( !file.atEnd() )
805 QByteArray line = file.readLine();
806 wordList.append( line.split(
',' ).at( 0 ).trimmed() );
814 QMap<QString, QString> types;
815 types.insert( QString(), QString() );
818 if ( !file.open( QIODevice::ReadOnly ) )
820 QgsDebugMsg( QString(
"Error while opening the CSV file: %1, %2 " ).arg( path, file.errorString() ) );
824 types.insert( QString(), QString() );
825 while ( !file.atEnd() )
827 QByteArray line = file.readLine();
828 QList<QByteArray> items = line.split(
';' );
829 types.insert( items.at( 0 ).constData(), items.at( 1 ).constData() );
851 void QgsMetadataWidget::syncFromCategoriesTabToKeywordsTab()
853 if ( mCategoriesModel->rowCount() > 0 )
855 QList<QTableWidgetItem *>
categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
857 if ( !categories.isEmpty() )
859 row = categories.at( 0 )->row();
865 row = tabKeywords->rowCount() - 1;
866 tabKeywords->item( row, 0 )->setText( QStringLiteral(
"gmd:topicCategory" ) );
868 tabKeywords->item( row, 1 )->setText( mCategoriesModel->stringList().join( QStringLiteral(
"," ) ) );
872 void QgsMetadataWidget::updatePanel()
874 int index = tabWidget->currentIndex();
875 QString currentTabText = tabWidget->widget( index )->objectName();
876 if ( currentTabText == QStringLiteral(
"tabCategoriesDialog" ) )
880 QList<QTableWidgetItem *>
categories = tabKeywords->findItems( QStringLiteral(
"gmd:topicCategory" ), Qt::MatchExactly );
881 if ( !categories.isEmpty() )
883 int row = categories.at( 0 )->row();
884 mCategoriesModel->setStringList( tabKeywords->item( row, 1 )->text().split(
',' ) );
888 mCategoriesModel->setStringList( QStringList() );
891 else if ( currentTabText == QStringLiteral(
"tabKeywordsDialog" ) )
895 syncFromCategoriesTabToKeywordsTab();
897 else if ( currentTabText == QStringLiteral(
"tabValidationDialog" ) )
903 void QgsMetadataWidget::addNewCategory()
906 QString text = QInputDialog::getText(
this, tr(
"New Category" ),
907 tr(
"New Category:" ), QLineEdit::Normal,
909 if ( ok && !text.isEmpty() )
911 QStringList list = mCategoriesModel->stringList();
912 if ( ! list.contains( text ) )
915 mCategoriesModel->setStringList( list );
916 mCategoriesModel->sort( 0 );
921 void QgsMetadataWidget::addDefaultCategories()
923 const QModelIndexList selectedIndexes = listDefaultCategories->selectionModel()->selectedIndexes();
924 QStringList defaultCategoriesList = mDefaultCategoriesModel->stringList();
925 QStringList selectedCategories = mCategoriesModel->stringList();
927 for (
const QModelIndex &selection : selectedIndexes )
929 QVariant item = mDefaultCategoriesModel->data( selection, Qt::DisplayRole );
930 defaultCategoriesList.removeOne( item.toString() );
932 selectedCategories.append( item.toString() );
935 mDefaultCategoriesModel->setStringList( defaultCategoriesList );
936 mCategoriesModel->setStringList( selectedCategories );
937 mCategoriesModel->sort( 0 );
940 void QgsMetadataWidget::removeSelectedCategories()
942 const QModelIndexList selectedIndexes = listCategories->selectionModel()->selectedIndexes();
943 QStringList
categories = mCategoriesModel->stringList();
944 QStringList defaultList = mDefaultCategoriesModel->stringList();
946 for (
const QModelIndex &selection : selectedIndexes )
948 QVariant item = mCategoriesModel->data( selection, Qt::DisplayRole );
949 categories.removeOne( item.toString() );
951 if ( mDefaultCategories.contains( item.toString() ) )
953 defaultList.append( item.toString() );
956 mCategoriesModel->setStringList( categories );
958 mDefaultCategoriesModel->setStringList( defaultList );
959 mDefaultCategoriesModel->sort( 0 );
963 : QStyledItemDelegate( parent )
970 if ( index.column() == 1 )
973 QComboBox *typeEditor =
new QComboBox( parent );
974 typeEditor->setEditable(
true );
975 QStringListModel *model =
new QStringListModel( parent );
977 typeEditor->setModel( model );
980 else if ( index.column() == 5 )
983 QComboBox *mimeEditor =
new QComboBox( parent );
984 mimeEditor->setEditable(
true );
985 QStringListModel *model =
new QStringListModel( parent );
987 mimeEditor->setModel( model );
991 return QStyledItemDelegate::createEditor( parent, option, index );
995 : QStyledItemDelegate( parent )
1002 if ( index.column() == 0 )
1005 QComboBox *typeEditor =
new QComboBox( parent );
1006 typeEditor->setEditable(
true );
1008 types << QStringLiteral(
"access" ) << QStringLiteral(
"use" ) << QStringLiteral(
"other" );
1009 QStringListModel *model =
new QStringListModel( parent );
1010 model->setStringList( types );
1011 typeEditor->setModel( model );
1015 return QStyledItemDelegate::createEditor( parent, option, index );
Base class for all map layer types.
virtual QgsDataProvider * dataProvider()
Returns the layer's data provider.
QgsLayerMetadata metadata
static QString reportStyleSheet()
get a standard css style sheet for reports.
A 3-dimensional box composed of x, y, z coordinates.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
virtual void setMetadata(const QgsLayerMetadata &metadata)
Sets the layer's metadata store.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QgsRectangle extent() const
Returns the current zoom extent of the map canvas.
QString description() const
Returns the descriptive name of the CRS, e.g., "WGS 84" or "GDA 94 / Vicgrid94".
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Create a special editor with a QCombobox in the constraint view.
QgsCoordinateReferenceSystem crs() const
Returns the layer's spatial reference system.
LinkItemDelegate(QObject *parent=nullptr)
LinkItemDelegate constructor.
QString publicSource() const
Gets a version of the internal layer definition that has sensitive bits removed (for example...
void setZMinimum(double z)
Sets the minimum z value.
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
Get access to properties used for map rendering.
Special delegate for the constraint view in the metadata wizard.
static QString metadataPath()
Returns the path to the metadata directory.
ConstraintItemDelegate(QObject *parent=nullptr)
ConstraintItemDelegate constructor.
QString authid() const
Returns the authority identifier for the CRS.
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
void setZMaximum(double z)
Sets the maximum z value.