Skip to content

Commit f4ed93e

Browse files
committed
Add project metadata mode to QgsMetadataWidget
1 parent b10be8a commit f4ed93e

17 files changed

+586
-260
lines changed

python/core/metadata/qgsabstractmetadatabase.sip.in

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ using QgsNativeMetadataValidator.
3939

4040
%TypeHeaderCode
4141
#include "qgsabstractmetadatabase.h"
42+
%End
43+
%ConvertToSubClassCode
44+
if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
45+
sipType = sipType_QgsLayerMetadata;
46+
else if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
47+
sipType = sipType_QgsProjectMetadata;
48+
else
49+
sipType = NULL;
4250
%End
4351
public:
4452

@@ -127,6 +135,13 @@ Constructor for Link.
127135

128136
virtual ~QgsAbstractMetadataBase();
129137

138+
virtual QgsAbstractMetadataBase *clone() const = 0 /Factory/;
139+
%Docstring
140+
Clones the metadata object.
141+
142+
.. versionadded:: 3.2
143+
%End
144+
130145
QString identifier() const;
131146
%Docstring
132147
A reference, URI, URL or some other mechanism to identify the resource.

python/core/metadata/qgslayermetadata.sip.in

+3
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ Constructor for Constraint.
115115
Constructor for QgsLayerMetadata.
116116
%End
117117

118+
virtual QgsLayerMetadata *clone() const /Factory/;
119+
120+
118121
QString fees() const;
119122
%Docstring
120123
Returns any fees associated with using the resource.

python/core/metadata/qgsprojectmetadata.sip.in

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ using QgsNativeProjectMetadataValidator.
4646
Constructor for QgsProjectMetadata.
4747
%End
4848

49+
virtual QgsProjectMetadata *clone() const /Factory/;
50+
51+
4952
QString author() const;
5053
%Docstring
5154
Returns the project author string.

python/gui/qgsmetadatawidget.sip.in

+36-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212

13-
class QgsAbstractMetadataBaseWidget : QWidget
13+
class QgsMetadataWidget : QWidget
1414
{
1515
%Docstring
1616
A wizard to edit metadata on a map layer.
@@ -23,7 +23,13 @@ class QgsAbstractMetadataBaseWidget : QWidget
2323
%End
2424
public:
2525

26-
QgsAbstractMetadataBaseWidget( QWidget *parent, QgsMapLayer *layer = 0 );
26+
enum Mode
27+
{
28+
LayerMetadata,
29+
ProjectMetadata,
30+
};
31+
32+
QgsMetadataWidget( QWidget *parent /TransferThis/ = 0, QgsMapLayer *layer = 0 );
2733
%Docstring
2834
Constructor for the wizard.
2935

@@ -33,26 +39,49 @@ the layer's metadata..
3339
.. seealso:: :py:func:`setMetadata`
3440
%End
3541

36-
void setMetadata( const QgsLayerMetadata &metadata );
42+
void setMode( Mode mode );
43+
%Docstring
44+
Sets the widget's current ``mode``.
45+
46+
.. versionadded:: 3.2
47+
48+
.. seealso:: :py:func:`mode`
49+
%End
50+
51+
Mode mode() const;
52+
%Docstring
53+
Returns the widget's current mode.
54+
55+
.. versionadded:: 3.2
56+
57+
.. seealso:: :py:func:`setMode`
58+
%End
59+
60+
void setMetadata( const QgsAbstractMetadataBase *metadata );
3761
%Docstring
3862
Sets the ``metadata`` to display in the widget.
3963

4064
This method can be called after constructing a QgsAbstractMetadataBaseWidget in order
4165
to set the displayed metadata to custom, non-layer based metadata.
4266

67+
Calling this method will automatically setMode() to the correct mode corresponding
68+
to the specified ``metadata`` object.
69+
4370
.. seealso:: :py:func:`metadata`
4471
%End
4572

46-
QgsLayerMetadata metadata();
73+
QgsAbstractMetadataBase *metadata() /Factory/;
4774
%Docstring
48-
Returns a QgsLayerMetadata object representing the current state of the widget.
75+
Returns a QgsAbstractMetadataBase object representing the current state of the widget.
76+
77+
Caller takes ownership of the returned object.
4978

5079
.. seealso:: :py:func:`saveMetadata`
5180
%End
5281

53-
void saveMetadata( QgsLayerMetadata &layerMetadata );
82+
void saveMetadata( QgsAbstractMetadataBase *metadata );
5483
%Docstring
55-
Save all fields in a QgsLayerMetadata object.
84+
Save all fields in a metadata object.
5685

5786
.. seealso:: :py:func:`metadata`
5887

src/app/qgsrasterlayerproperties.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
253253

254254
QVBoxLayout *layout = new QVBoxLayout( metadataFrame );
255255
layout->setMargin( 0 );
256-
mMetadataWidget = new QgsAbstractMetadataBaseWidget( this, mRasterLayer );
256+
mMetadataWidget = new QgsMetadataWidget( this, mRasterLayer );
257257
mMetadataWidget->layout()->setContentsMargins( -1, 0, -1, 0 );
258258
mMetadataWidget->setMapCanvas( mMapCanvas );
259259
layout->addWidget( mMetadataWidget );
@@ -1903,7 +1903,7 @@ void QgsRasterLayerProperties::loadMetadata()
19031903
//reset if the default style was loaded OK only
19041904
if ( defaultLoadedFlag )
19051905
{
1906-
mMetadataWidget->setMetadata( mRasterLayer->metadata() );
1906+
mMetadataWidget->setMetadata( &mRasterLayer->metadata() );
19071907
}
19081908
else
19091909
{
@@ -1965,7 +1965,7 @@ void QgsRasterLayerProperties::loadDefaultMetadata()
19651965
//reset if the default metadata was loaded OK only
19661966
if ( defaultLoadedFlag )
19671967
{
1968-
mMetadataWidget->setMetadata( mRasterLayer->metadata() );
1968+
mMetadataWidget->setMetadata( &mRasterLayer->metadata() );
19691969
}
19701970
else
19711971
{

src/app/qgsrasterlayerproperties.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class QgsPointXY;
3333
class QgsMapLayer;
3434
class QgsMapCanvas;
3535
class QgsRasterLayer;
36-
class QgsAbstractMetadataBaseWidget;
36+
class QgsMetadataWidget;
3737
class QgsRasterRenderer;
3838
class QgsRasterRendererWidget;
3939
class QgsRasterHistogramWidget;
@@ -181,7 +181,7 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
181181
//bool mRasterLayerIsInternal;
182182

183183
QgsRasterRendererWidget *mRendererWidget = nullptr;
184-
QgsAbstractMetadataBaseWidget *mMetadataWidget = nullptr;
184+
QgsMetadataWidget *mMetadataWidget = nullptr;
185185

186186
bool rasterIsMultiBandColor();
187187

src/app/qgsvectorlayerproperties.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
240240
// Metadata tab, before the syncToLayer
241241
QVBoxLayout *metadataLayout = new QVBoxLayout( metadataFrame );
242242
metadataLayout->setMargin( 0 );
243-
mMetadataWidget = new QgsAbstractMetadataBaseWidget( this, mLayer );
243+
mMetadataWidget = new QgsMetadataWidget( this, mLayer );
244244
mMetadataWidget->layout()->setContentsMargins( -1, 0, -1, 0 );
245245
mMetadataWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );
246246
metadataLayout->addWidget( mMetadataWidget );
@@ -560,7 +560,7 @@ void QgsVectorLayerProperties::syncToLayer()
560560
mVector3DWidget->setLayer( mLayer );
561561
#endif
562562

563-
mMetadataWidget->setMetadata( mLayer->metadata() );
563+
mMetadataWidget->setMetadata( &mLayer->metadata() );
564564

565565
} // syncToLayer()
566566

@@ -1017,7 +1017,7 @@ void QgsVectorLayerProperties::loadMetadata()
10171017
//reset if the default style was loaded OK only
10181018
if ( defaultLoadedFlag )
10191019
{
1020-
mMetadataWidget->setMetadata( mLayer->metadata() );
1020+
mMetadataWidget->setMetadata( &mLayer->metadata() );
10211021
}
10221022
else
10231023
{
@@ -1092,7 +1092,7 @@ void QgsVectorLayerProperties::loadDefaultMetadata()
10921092
//reset if the default metadata was loaded OK only
10931093
if ( defaultLoadedFlag )
10941094
{
1095-
mMetadataWidget->setMetadata( mLayer->metadata() );
1095+
mMetadataWidget->setMetadata( &mLayer->metadata() );
10961096
}
10971097
else
10981098
{

src/app/qgsvectorlayerproperties.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class QgsAttributesFormProperties;
4343
class QgsRendererPropertiesDialog;
4444
class QgsMapLayerConfigWidgetFactory;
4545
class QgsMapLayerConfigWidget;
46-
class QgsAbstractMetadataBaseWidget;
46+
class QgsMetadataWidget;
4747
class QgsPanelWidget;
4848
class QgsVectorLayer3DRendererWidget;
4949

@@ -244,7 +244,7 @@ class APP_EXPORT QgsVectorLayerProperties : public QgsOptionsDialogBase, private
244244

245245
void showHelp();
246246

247-
QgsAbstractMetadataBaseWidget *mMetadataWidget = nullptr;
247+
QgsMetadataWidget *mMetadataWidget = nullptr;
248248

249249
QAction *mAuxiliaryLayerActionNew = nullptr;
250250
QAction *mAuxiliaryLayerActionClear = nullptr;

src/core/metadata/qgsabstractmetadatabase.h

+18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ class QDomDocument;
5252
*/
5353
class CORE_EXPORT QgsAbstractMetadataBase
5454
{
55+
56+
#ifdef SIP_RUN
57+
SIP_CONVERT_TO_SUBCLASS_CODE
58+
if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
59+
sipType = sipType_QgsLayerMetadata;
60+
else if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
61+
sipType = sipType_QgsProjectMetadata;
62+
else
63+
sipType = NULL;
64+
SIP_END
65+
#endif
66+
5567
public:
5668

5769
// NOTE - these really belong in a separate namespace, but SIP says no, I want to make you waste more time
@@ -249,6 +261,12 @@ class CORE_EXPORT QgsAbstractMetadataBase
249261

250262
virtual ~QgsAbstractMetadataBase() = default;
251263

264+
/**
265+
* Clones the metadata object.
266+
* \since QGIS 3.2
267+
*/
268+
virtual QgsAbstractMetadataBase *clone() const = 0 SIP_FACTORY;
269+
252270
/**
253271
* A reference, URI, URL or some other mechanism to identify the resource.
254272
* \see setIdentifier()

src/core/metadata/qgslayermetadata.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
#include "qgslayermetadata.h"
1919
#include "qgsmaplayer.h"
2020

21+
QgsLayerMetadata *QgsLayerMetadata::clone() const
22+
{
23+
return new QgsLayerMetadata( *this );
24+
}
25+
2126
QString QgsLayerMetadata::fees() const
2227
{
2328
return mFees;

src/core/metadata/qgslayermetadata.h

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ class CORE_EXPORT QgsLayerMetadata : public QgsAbstractMetadataBase
169169
*/
170170
QgsLayerMetadata() = default;
171171

172+
QgsLayerMetadata *clone() const override SIP_FACTORY;
173+
172174
/**
173175
* Returns any fees associated with using the resource.
174176
* An empty string will be returned if no fees are set.

src/core/metadata/qgsprojectmetadata.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ bool QgsProjectMetadata::operator==( const QgsProjectMetadata &metadataOther )
6262
mCreationDateTime == metadataOther.mCreationDateTime ;
6363
}
6464

65+
QgsProjectMetadata *QgsProjectMetadata::clone() const
66+
{
67+
return new QgsProjectMetadata( *this );
68+
}
69+
6570
QString QgsProjectMetadata::author() const
6671
{
6772
return mAuthor;

src/core/metadata/qgsprojectmetadata.h

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class CORE_EXPORT QgsProjectMetadata : public QgsAbstractMetadataBase
5757
*/
5858
QgsProjectMetadata() = default;
5959

60+
QgsProjectMetadata *clone() const override SIP_FACTORY;
61+
6062
/**
6163
* Returns the project author string.
6264
* \see setAuthor()

src/core/qgsproject.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ void QgsProject::clear()
510510
mTrustLayerMetadata = false;
511511
mCustomVariables.clear();
512512
mMetadata = QgsProjectMetadata();
513+
mMetadata.setCreationDateTime( QDateTime::currentDateTime() );
513514
emit metadataChanged();
514515

515516
QgsCoordinateTransformContext context;

0 commit comments

Comments
 (0)