Skip to content
Permalink
Browse files

Synchronize project title field and project metadata title

field in project properties dialog

Since these two are equivalent, we automatically keep them
in sync.
  • Loading branch information
nyalldawson committed Mar 22, 2018
1 parent 6ce184d commit 681cd411855e880fc5c5f14af9a06d9d22cbb50a
@@ -139,6 +139,43 @@ Returns a list of types available by default in the wizard.
void setMapCanvas( QgsMapCanvas *canvas );
%Docstring
Sets a map ``canvas`` associated with the widget.
%End

QString title() const;
%Docstring
Returns the current title field for the metadata.

.. seealso:: :py:func:`setTitle`

.. seealso:: :py:func:`titleChanged`

.. versionadded:: 3.2
%End

public slots:

void setTitle( const QString &title );
%Docstring
Sets the ``title`` field for the metadata.

.. seealso:: :py:func:`title`

.. seealso:: :py:func:`titleChanged`

.. versionadded:: 3.2
%End

signals:

void titleChanged( const QString &title );
%Docstring
Emitted when the ``title`` field is changed.

.. seealso:: :py:func:`title`

.. seealso:: :py:func:`setTitle`

.. versionadded:: 3.2
%End

};
@@ -826,6 +826,10 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mMetadataWidget->setMode( QgsMetadataWidget::ProjectMetadata );
mMetadataWidget->setMetadata( &QgsProject::instance()->metadata() );

// sync metadata title and project title fields
connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText );
connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle );

projectionSelectorInitialized();
restoreOptionsBaseUi();
restoreState();
@@ -121,6 +121,8 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
setMode( LayerMetadata );
setUiFromMetadata();
}

connect( lineEditTitle, &QLineEdit::textChanged, this, &QgsMetadataWidget::titleChanged );
}

void QgsMetadataWidget::setMode( QgsMetadataWidget::Mode mode )
@@ -462,7 +464,7 @@ void QgsMetadataWidget::setUiFromMetadata()
// Title
if ( ! mMetadata->title().isEmpty() )
{
lineEditTitle->setText( mMetadata->title() );
whileBlocking( lineEditTitle )->setText( mMetadata->title() );
}

// Type
@@ -949,6 +951,20 @@ void QgsMetadataWidget::setMapCanvas( QgsMapCanvas *canvas )
spatialExtentSelector->setCurrentExtent( canvas->extent(), canvas->mapSettings().destinationCrs() );
}

QString QgsMetadataWidget::title() const
{
return lineEditTitle->text();
}

void QgsMetadataWidget::setTitle( const QString &title )
{
if ( title != lineEditTitle->text() )
{
whileBlocking( lineEditTitle )->setText( title );
emit titleChanged( title );
}
}

void QgsMetadataWidget::acceptMetadata()
{
saveMetadata( mMetadata.get() );
@@ -38,6 +38,7 @@
class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidgetBase
{
Q_OBJECT
Q_PROPERTY( QString title READ title WRITE setTitle NOTIFY titleChanged )

public:

@@ -153,6 +154,40 @@ class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidg
*/
void setMapCanvas( QgsMapCanvas *canvas );

/**
* Returns the current title field for the metadata.
*
* \see setTitle()
* \see titleChanged()
*
* \since QGIS 3.2
*/
QString title() const;

public slots:

/**
* Sets the \a title field for the metadata.
*
* \see title()
* \see titleChanged()
*
* \since QGIS 3.2
*/
void setTitle( const QString &title );

signals:

/**
* Emitted when the \a title field is changed.
*
* \see title()
* \see setTitle()
*
* \since QGIS 3.2
*/
void titleChanged( const QString &title );

private slots:
void removeSelectedCategories();
void updatePanel();

0 comments on commit 681cd41

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