Skip to content

Commit 681cd41

Browse files
committed
Synchronize project title field and project metadata title
field in project properties dialog Since these two are equivalent, we automatically keep them in sync.
1 parent 6ce184d commit 681cd41

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

python/gui/qgsmetadatawidget.sip.in

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,43 @@ Returns a list of types available by default in the wizard.
139139
void setMapCanvas( QgsMapCanvas *canvas );
140140
%Docstring
141141
Sets a map ``canvas`` associated with the widget.
142+
%End
143+
144+
QString title() const;
145+
%Docstring
146+
Returns the current title field for the metadata.
147+
148+
.. seealso:: :py:func:`setTitle`
149+
150+
.. seealso:: :py:func:`titleChanged`
151+
152+
.. versionadded:: 3.2
153+
%End
154+
155+
public slots:
156+
157+
void setTitle( const QString &title );
158+
%Docstring
159+
Sets the ``title`` field for the metadata.
160+
161+
.. seealso:: :py:func:`title`
162+
163+
.. seealso:: :py:func:`titleChanged`
164+
165+
.. versionadded:: 3.2
166+
%End
167+
168+
signals:
169+
170+
void titleChanged( const QString &title );
171+
%Docstring
172+
Emitted when the ``title`` field is changed.
173+
174+
.. seealso:: :py:func:`title`
175+
176+
.. seealso:: :py:func:`setTitle`
177+
178+
.. versionadded:: 3.2
142179
%End
143180

144181
};

src/app/qgsprojectproperties.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,10 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
826826
mMetadataWidget->setMode( QgsMetadataWidget::ProjectMetadata );
827827
mMetadataWidget->setMetadata( &QgsProject::instance()->metadata() );
828828

829+
// sync metadata title and project title fields
830+
connect( mMetadataWidget, &QgsMetadataWidget::titleChanged, titleEdit, &QLineEdit::setText );
831+
connect( titleEdit, &QLineEdit::textChanged, mMetadataWidget, &QgsMetadataWidget::setTitle );
832+
829833
projectionSelectorInitialized();
830834
restoreOptionsBaseUi();
831835
restoreState();

src/gui/qgsmetadatawidget.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ QgsMetadataWidget::QgsMetadataWidget( QWidget *parent, QgsMapLayer *layer )
121121
setMode( LayerMetadata );
122122
setUiFromMetadata();
123123
}
124+
125+
connect( lineEditTitle, &QLineEdit::textChanged, this, &QgsMetadataWidget::titleChanged );
124126
}
125127

126128
void QgsMetadataWidget::setMode( QgsMetadataWidget::Mode mode )
@@ -462,7 +464,7 @@ void QgsMetadataWidget::setUiFromMetadata()
462464
// Title
463465
if ( ! mMetadata->title().isEmpty() )
464466
{
465-
lineEditTitle->setText( mMetadata->title() );
467+
whileBlocking( lineEditTitle )->setText( mMetadata->title() );
466468
}
467469

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

954+
QString QgsMetadataWidget::title() const
955+
{
956+
return lineEditTitle->text();
957+
}
958+
959+
void QgsMetadataWidget::setTitle( const QString &title )
960+
{
961+
if ( title != lineEditTitle->text() )
962+
{
963+
whileBlocking( lineEditTitle )->setText( title );
964+
emit titleChanged( title );
965+
}
966+
}
967+
952968
void QgsMetadataWidget::acceptMetadata()
953969
{
954970
saveMetadata( mMetadata.get() );

src/gui/qgsmetadatawidget.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
class GUI_EXPORT QgsMetadataWidget : public QWidget, private Ui::QgsMetadataWidgetBase
3939
{
4040
Q_OBJECT
41+
Q_PROPERTY( QString title READ title WRITE setTitle NOTIFY titleChanged )
4142

4243
public:
4344

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

157+
/**
158+
* Returns the current title field for the metadata.
159+
*
160+
* \see setTitle()
161+
* \see titleChanged()
162+
*
163+
* \since QGIS 3.2
164+
*/
165+
QString title() const;
166+
167+
public slots:
168+
169+
/**
170+
* Sets the \a title field for the metadata.
171+
*
172+
* \see title()
173+
* \see titleChanged()
174+
*
175+
* \since QGIS 3.2
176+
*/
177+
void setTitle( const QString &title );
178+
179+
signals:
180+
181+
/**
182+
* Emitted when the \a title field is changed.
183+
*
184+
* \see title()
185+
* \see setTitle()
186+
*
187+
* \since QGIS 3.2
188+
*/
189+
void titleChanged( const QString &title );
190+
156191
private slots:
157192
void removeSelectedCategories();
158193
void updatePanel();

0 commit comments

Comments
 (0)