Skip to content
Permalink
Browse files

Add project metadata mode to QgsMetadataWidget

  • Loading branch information
nyalldawson committed Mar 19, 2018
1 parent b10be8a commit f4ed93e1ca35cd89bbb1c82e5fb9647dea737e0f
@@ -39,6 +39,14 @@ using QgsNativeMetadataValidator.

%TypeHeaderCode
#include "qgsabstractmetadatabase.h"
%End
%ConvertToSubClassCode
if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
sipType = sipType_QgsLayerMetadata;
else if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
sipType = sipType_QgsProjectMetadata;
else
sipType = NULL;
%End
public:

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

virtual ~QgsAbstractMetadataBase();

virtual QgsAbstractMetadataBase *clone() const = 0 /Factory/;
%Docstring
Clones the metadata object.

.. versionadded:: 3.2
%End

QString identifier() const;
%Docstring
A reference, URI, URL or some other mechanism to identify the resource.
@@ -115,6 +115,9 @@ Constructor for Constraint.
Constructor for QgsLayerMetadata.
%End

virtual QgsLayerMetadata *clone() const /Factory/;


QString fees() const;
%Docstring
Returns any fees associated with using the resource.
@@ -46,6 +46,9 @@ using QgsNativeProjectMetadataValidator.
Constructor for QgsProjectMetadata.
%End

virtual QgsProjectMetadata *clone() const /Factory/;


QString author() const;
%Docstring
Returns the project author string.
@@ -10,7 +10,7 @@



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

QgsAbstractMetadataBaseWidget( QWidget *parent, QgsMapLayer *layer = 0 );
enum Mode
{
LayerMetadata,
ProjectMetadata,
};

QgsMetadataWidget( QWidget *parent /TransferThis/ = 0, QgsMapLayer *layer = 0 );
%Docstring
Constructor for the wizard.

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

void setMetadata( const QgsLayerMetadata &metadata );
void setMode( Mode mode );
%Docstring
Sets the widget's current ``mode``.

.. versionadded:: 3.2

.. seealso:: :py:func:`mode`
%End

Mode mode() const;
%Docstring
Returns the widget's current mode.

.. versionadded:: 3.2

.. seealso:: :py:func:`setMode`
%End

void setMetadata( const QgsAbstractMetadataBase *metadata );
%Docstring
Sets the ``metadata`` to display in the widget.

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

Calling this method will automatically setMode() to the correct mode corresponding
to the specified ``metadata`` object.

.. seealso:: :py:func:`metadata`
%End

QgsLayerMetadata metadata();
QgsAbstractMetadataBase *metadata() /Factory/;
%Docstring
Returns a QgsLayerMetadata object representing the current state of the widget.
Returns a QgsAbstractMetadataBase object representing the current state of the widget.

Caller takes ownership of the returned object.

.. seealso:: :py:func:`saveMetadata`
%End

void saveMetadata( QgsLayerMetadata &layerMetadata );
void saveMetadata( QgsAbstractMetadataBase *metadata );
%Docstring
Save all fields in a QgsLayerMetadata object.
Save all fields in a metadata object.

.. seealso:: :py:func:`metadata`

@@ -253,7 +253,7 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv

QVBoxLayout *layout = new QVBoxLayout( metadataFrame );
layout->setMargin( 0 );
mMetadataWidget = new QgsAbstractMetadataBaseWidget( this, mRasterLayer );
mMetadataWidget = new QgsMetadataWidget( this, mRasterLayer );
mMetadataWidget->layout()->setContentsMargins( -1, 0, -1, 0 );
mMetadataWidget->setMapCanvas( mMapCanvas );
layout->addWidget( mMetadataWidget );
@@ -1903,7 +1903,7 @@ void QgsRasterLayerProperties::loadMetadata()
//reset if the default style was loaded OK only
if ( defaultLoadedFlag )
{
mMetadataWidget->setMetadata( mRasterLayer->metadata() );
mMetadataWidget->setMetadata( &mRasterLayer->metadata() );
}
else
{
@@ -1965,7 +1965,7 @@ void QgsRasterLayerProperties::loadDefaultMetadata()
//reset if the default metadata was loaded OK only
if ( defaultLoadedFlag )
{
mMetadataWidget->setMetadata( mRasterLayer->metadata() );
mMetadataWidget->setMetadata( &mRasterLayer->metadata() );
}
else
{
@@ -33,7 +33,7 @@ class QgsPointXY;
class QgsMapLayer;
class QgsMapCanvas;
class QgsRasterLayer;
class QgsAbstractMetadataBaseWidget;
class QgsMetadataWidget;
class QgsRasterRenderer;
class QgsRasterRendererWidget;
class QgsRasterHistogramWidget;
@@ -181,7 +181,7 @@ class APP_EXPORT QgsRasterLayerProperties : public QgsOptionsDialogBase, private
//bool mRasterLayerIsInternal;

QgsRasterRendererWidget *mRendererWidget = nullptr;
QgsAbstractMetadataBaseWidget *mMetadataWidget = nullptr;
QgsMetadataWidget *mMetadataWidget = nullptr;

bool rasterIsMultiBandColor();

@@ -240,7 +240,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
// Metadata tab, before the syncToLayer
QVBoxLayout *metadataLayout = new QVBoxLayout( metadataFrame );
metadataLayout->setMargin( 0 );
mMetadataWidget = new QgsAbstractMetadataBaseWidget( this, mLayer );
mMetadataWidget = new QgsMetadataWidget( this, mLayer );
mMetadataWidget->layout()->setContentsMargins( -1, 0, -1, 0 );
mMetadataWidget->setMapCanvas( QgisApp::instance()->mapCanvas() );
metadataLayout->addWidget( mMetadataWidget );
@@ -560,7 +560,7 @@ void QgsVectorLayerProperties::syncToLayer()
mVector3DWidget->setLayer( mLayer );
#endif

mMetadataWidget->setMetadata( mLayer->metadata() );
mMetadataWidget->setMetadata( &mLayer->metadata() );

} // syncToLayer()

@@ -1017,7 +1017,7 @@ void QgsVectorLayerProperties::loadMetadata()
//reset if the default style was loaded OK only
if ( defaultLoadedFlag )
{
mMetadataWidget->setMetadata( mLayer->metadata() );
mMetadataWidget->setMetadata( &mLayer->metadata() );
}
else
{
@@ -1092,7 +1092,7 @@ void QgsVectorLayerProperties::loadDefaultMetadata()
//reset if the default metadata was loaded OK only
if ( defaultLoadedFlag )
{
mMetadataWidget->setMetadata( mLayer->metadata() );
mMetadataWidget->setMetadata( &mLayer->metadata() );
}
else
{
@@ -43,7 +43,7 @@ class QgsAttributesFormProperties;
class QgsRendererPropertiesDialog;
class QgsMapLayerConfigWidgetFactory;
class QgsMapLayerConfigWidget;
class QgsAbstractMetadataBaseWidget;
class QgsMetadataWidget;
class QgsPanelWidget;
class QgsVectorLayer3DRendererWidget;

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

void showHelp();

QgsAbstractMetadataBaseWidget *mMetadataWidget = nullptr;
QgsMetadataWidget *mMetadataWidget = nullptr;

QAction *mAuxiliaryLayerActionNew = nullptr;
QAction *mAuxiliaryLayerActionClear = nullptr;
@@ -52,6 +52,18 @@ class QDomDocument;
*/
class CORE_EXPORT QgsAbstractMetadataBase
{

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
sipType = sipType_QgsLayerMetadata;
else if ( dynamic_cast< QgsLayerMetadata * >( sipCpp ) != NULL )
sipType = sipType_QgsProjectMetadata;
else
sipType = NULL;
SIP_END
#endif

public:

// 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

virtual ~QgsAbstractMetadataBase() = default;

/**
* Clones the metadata object.
* \since QGIS 3.2
*/
virtual QgsAbstractMetadataBase *clone() const = 0 SIP_FACTORY;

/**
* A reference, URI, URL or some other mechanism to identify the resource.
* \see setIdentifier()
@@ -18,6 +18,11 @@
#include "qgslayermetadata.h"
#include "qgsmaplayer.h"

QgsLayerMetadata *QgsLayerMetadata::clone() const
{
return new QgsLayerMetadata( *this );
}

QString QgsLayerMetadata::fees() const
{
return mFees;
@@ -169,6 +169,8 @@ class CORE_EXPORT QgsLayerMetadata : public QgsAbstractMetadataBase
*/
QgsLayerMetadata() = default;

QgsLayerMetadata *clone() const override SIP_FACTORY;

/**
* Returns any fees associated with using the resource.
* An empty string will be returned if no fees are set.
@@ -62,6 +62,11 @@ bool QgsProjectMetadata::operator==( const QgsProjectMetadata &metadataOther )
mCreationDateTime == metadataOther.mCreationDateTime ;
}

QgsProjectMetadata *QgsProjectMetadata::clone() const
{
return new QgsProjectMetadata( *this );
}

QString QgsProjectMetadata::author() const
{
return mAuthor;
@@ -57,6 +57,8 @@ class CORE_EXPORT QgsProjectMetadata : public QgsAbstractMetadataBase
*/
QgsProjectMetadata() = default;

QgsProjectMetadata *clone() const override SIP_FACTORY;

/**
* Returns the project author string.
* \see setAuthor()
@@ -510,6 +510,7 @@ void QgsProject::clear()
mTrustLayerMetadata = false;
mCustomVariables.clear();
mMetadata = QgsProjectMetadata();
mMetadata.setCreationDateTime( QDateTime::currentDateTime() );
emit metadataChanged();

QgsCoordinateTransformContext context;

0 comments on commit f4ed93e

Please sign in to comment.
You can’t perform that action at this time.