Skip to content

Commit

Permalink
Synchronize project title field and project metadata title
Browse files Browse the repository at this point in the history
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 681cd41
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
37 changes: 37 additions & 0 deletions python/gui/qgsmetadatawidget.sip.in
Expand Up @@ -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

};
Expand Down
4 changes: 4 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -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();
Expand Down
18 changes: 17 additions & 1 deletion src/gui/qgsmetadatawidget.cpp
Expand Up @@ -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 )
Expand Down Expand Up @@ -462,7 +464,7 @@ void QgsMetadataWidget::setUiFromMetadata()
// Title
if ( ! mMetadata->title().isEmpty() )
{
lineEditTitle->setText( mMetadata->title() );
whileBlocking( lineEditTitle )->setText( mMetadata->title() );
}

// Type
Expand Down Expand Up @@ -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() );
Expand Down
35 changes: 35 additions & 0 deletions src/gui/qgsmetadatawidget.h
Expand Up @@ -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:

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 681cd41

Please sign in to comment.