Add non translatable option page identifier - Fixes #50657

This commit is contained in:
Yoann Quenach de Quivillic 2023-03-21 10:59:51 +01:00 committed by Nyall Dawson
parent f11602d9d1
commit 70bf31adbd
17 changed files with 73 additions and 21 deletions

View File

@ -96,7 +96,7 @@ Sets the dialog ``page`` (by object name) to show.
.. versionadded:: 3.14
%End
void addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget /Transfer/, const QStringList &path = QStringList() );
void addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget /Transfer/, const QStringList &path = QStringList(), const QString &key = QString() );
%Docstring
Adds a new page to the dialog pages.
@ -107,12 +107,15 @@ The page content is specified via the ``widget`` argument. Ownership of ``widget
Since QGIS 3.22, the optional ``path`` argument can be used to set the path of the item's entry in the tree view
(for dialogs which show a tree view of options pages only).
Since QGIS 3.32, the optional ``key`` argument can be used to set an untranslated key that ``path`` can refer to
in following calls. Default to ``title``.
.. seealso:: :py:func:`insertPage`
.. versionadded:: 3.14
%End
void insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget /Transfer/, const QString &before, const QStringList &path = QStringList() );
void insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget /Transfer/, const QString &before, const QStringList &path = QStringList(), const QString &key = QString() );
%Docstring
Inserts a new page into the dialog pages.
@ -126,6 +129,9 @@ before the matching page.
Since QGIS 3.22, the optional ``path`` argument can be used to set the path of the item's entry in the tree view
(for dialogs which show a tree view of options pages only).
Since QGIS 3.32, the optional ``key`` argument can be used to set an untranslated key that ``path`` can refer to
in following calls. Default to ``title``.
.. seealso:: :py:func:`addPage`
.. versionadded:: 3.14

View File

@ -82,7 +82,7 @@ class QgsOptionsWidgetFactory : QObject
Constructor
%End
QgsOptionsWidgetFactory( const QString &title, const QIcon &icon );
QgsOptionsWidgetFactory( const QString &title, const QIcon &icon, const QString &key = QString() );
%Docstring
Constructor
%End
@ -115,6 +115,22 @@ The title of the panel.
Set the ``title`` for the interface.
.. seealso:: :py:func:`title`
%End
virtual QString key() const;
%Docstring
The key of the panel (untranslated title).
.. seealso:: :py:func:`setKey`
.. versionadded:: 3.32
%End
void setKey( const QString &key );
%Docstring
Set the ``key`` for the interface.
.. seealso:: :py:func:`key`
%End
virtual QString pagePositionHint() const;

View File

@ -72,7 +72,7 @@ void Qgs3DOptionsWidget::apply()
// Qgs3DOptionsFactory
//
Qgs3DOptionsFactory::Qgs3DOptionsFactory()
: QgsOptionsWidgetFactory( tr( "3D" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "3D" ), QIcon(), QStringLiteral( "3d" ) )
{
}

View File

@ -54,7 +54,7 @@ QgsSettingsTreeWidget *QgsAdvancedSettingsWidget::settingsTree()
// QgsAdvancedSettingsOptionsFactory
//
QgsAdvancedSettingsOptionsFactory::QgsAdvancedSettingsOptionsFactory()
: QgsOptionsWidgetFactory( QCoreApplication::translate( "QgsOptionsBase", "Advanced" ), QIcon() )
: QgsOptionsWidgetFactory( QCoreApplication::translate( "QgsOptionsBase", "Advanced" ), QIcon(), QStringLiteral( "advanced" ) )
{
}

View File

@ -364,7 +364,7 @@ void QgsCodeEditorOptionsWidget::updatePreview()
// QgsCodeEditorOptionsFactory
//
QgsCodeEditorOptionsFactory::QgsCodeEditorOptionsFactory()
: QgsOptionsWidgetFactory( tr( "Code Editor" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "Code Editor" ), QIcon(), QStringLiteral("code_editor") )
{
}

View File

@ -429,7 +429,7 @@ QString QgsCustomProjectionOptionsWidget::helpKey() const
// QgsCustomProjectionOptionsFactory
//
QgsCustomProjectionOptionsFactory::QgsCustomProjectionOptionsFactory()
: QgsOptionsWidgetFactory( tr( "User Defined CRS" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "User Defined CRS" ), QIcon(), QStringLiteral( "user_defined_crs" ) )
{
}

View File

@ -140,7 +140,7 @@ void QgsFontOptionsWidget::apply()
// QgsFontOptionsFactory
//
QgsFontOptionsFactory::QgsFontOptionsFactory()
: QgsOptionsWidgetFactory( tr( "Fonts" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "Fonts" ), QIcon(), QStringLiteral( "fonts" ) )
{
}

View File

@ -231,7 +231,7 @@ void QgsGpsDeviceOptionsWidget::renameCurrentDevice()
// QgsGpsDeviceOptionsFactory
//
QgsGpsDeviceOptionsFactory::QgsGpsDeviceOptionsFactory()
: QgsOptionsWidgetFactory( tr( "GPSBabel" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "GPSBabel" ), QIcon(), QStringLiteral( "gpsbabel" ) )
{
}

View File

@ -438,7 +438,7 @@ void QgsGpsOptionsWidget::updateTimeZones()
// QgsGpsOptionsFactory
//
QgsGpsOptionsFactory::QgsGpsOptionsFactory()
: QgsOptionsWidgetFactory( tr( "GPS" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "GPS" ), QIcon(), QStringLiteral( "gps" ) )
{
}

View File

@ -1157,9 +1157,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
mAdditionalOptionWidgets << page;
const QString beforePage = factory->pagePositionHint();
if ( beforePage.isEmpty() )
addPage( factory->title(), factory->title(), factory->icon(), page, factory->path() );
addPage( factory->title(), factory->title(), factory->icon(), page, factory->path(), factory->key() );
else
insertPage( factory->title(), factory->title(), factory->icon(), page, beforePage, factory->path() );
insertPage( factory->title(), factory->title(), factory->icon(), page, beforePage, factory->path(), factory->key() );
if ( QgsAdvancedSettingsWidget *advancedPage = qobject_cast< QgsAdvancedSettingsWidget * >( page ) )
{

View File

@ -159,7 +159,7 @@ void QgsRasterRenderingOptionsWidget::saveMinMaxLimits( QComboBox *cbox, const Q
// QgsRasterRenderingOptionsFactory
//
QgsRasterRenderingOptionsFactory::QgsRasterRenderingOptionsFactory()
: QgsOptionsWidgetFactory( tr( "Raster" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "Raster" ), QIcon(), QStringLiteral( "raster" ) )
{
}

View File

@ -77,7 +77,7 @@ void QgsRenderingOptionsWidget::apply()
// QgsRenderingOptionsFactory
//
QgsRenderingOptionsFactory::QgsRenderingOptionsFactory()
: QgsOptionsWidgetFactory( tr( "Rendering" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "Rendering" ), QIcon(), QStringLiteral( "rendering" ) )
{
}

View File

@ -102,7 +102,7 @@ void QgsVectorRenderingOptionsWidget::apply()
// QgsVectorRenderingOptionsFactory
//
QgsVectorRenderingOptionsFactory::QgsVectorRenderingOptionsFactory()
: QgsOptionsWidgetFactory( tr( "Vector" ), QIcon() )
: QgsOptionsWidgetFactory( tr( "Vector" ), QIcon(), QStringLiteral( "vector" ) )
{
}

View File

@ -160,7 +160,7 @@ bool QgsProjectElevationSettingsWidget::isValid()
//
QgsProjectElevationSettingsWidgetFactory::QgsProjectElevationSettingsWidgetFactory( QObject *parent )
: QgsOptionsWidgetFactory( tr( "Terrain" ), QgsApplication::getThemeIcon( QStringLiteral( "mLayoutItem3DMap.svg" ) ) )
: QgsOptionsWidgetFactory( tr( "Terrain" ), QgsApplication::getThemeIcon( QStringLiteral( "mLayoutItem3DMap.svg" ) ), QStringLiteral( "terrain" ) )
{
setParent( parent );
}

View File

@ -325,7 +325,7 @@ void QgsOptionsDialogBase::setCurrentPage( const QString &page )
}
}
void QgsOptionsDialogBase::addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QStringList &path )
void QgsOptionsDialogBase::addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QStringList &path, const QString &key )
{
int newPage = -1;
@ -341,6 +341,10 @@ void QgsOptionsDialogBase::addPage( const QString &title, const QString &tooltip
{
QStandardItem *item = new QStandardItem( icon, title );
item->setToolTip( tooltip );
if ( !key.isEmpty() )
{
item->setData( key );
}
QModelIndex parent;
QStandardItem *parentItem = nullptr;
@ -399,7 +403,7 @@ void QgsOptionsDialogBase::addPage( const QString &title, const QString &tooltip
mOptStackedWidget->insertWidget( newPage, widget );
}
void QgsOptionsDialogBase::insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QString &before, const QStringList &path )
void QgsOptionsDialogBase::insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget, const QString &before, const QStringList &path, const QString &key )
{
//find the page with a matching widget name
for ( int page = 0; page < mOptStackedWidget->count(); ++page )
@ -470,6 +474,10 @@ void QgsOptionsDialogBase::insertPage( const QString &title, const QString &tool
QStandardItem *item = new QStandardItem( icon, title );
item->setToolTip( tooltip );
if ( !key.isEmpty() )
{
item->setData( key );
}
if ( parentItem )
{
if ( sourceBeforeIndices.empty() )

View File

@ -152,10 +152,13 @@ class GUI_EXPORT QgsOptionsDialogBase : public QDialog
* Since QGIS 3.22, the optional \a path argument can be used to set the path of the item's entry in the tree view
* (for dialogs which show a tree view of options pages only).
*
* Since QGIS 3.32, the optional \a key argument can be used to set an untranslated key that \a path can refer to
* in following calls. Default to \a title.
*
* \see insertPage()
* \since QGIS 3.14
*/
void addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget SIP_TRANSFER, const QStringList &path = QStringList() );
void addPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget SIP_TRANSFER, const QStringList &path = QStringList(), const QString &key = QString() );
/**
* Inserts a new page into the dialog pages.
@ -170,10 +173,13 @@ class GUI_EXPORT QgsOptionsDialogBase : public QDialog
* Since QGIS 3.22, the optional \a path argument can be used to set the path of the item's entry in the tree view
* (for dialogs which show a tree view of options pages only).
*
* Since QGIS 3.32, the optional \a key argument can be used to set an untranslated key that \a path can refer to
* in following calls. Default to \a title.
*
* \see addPage()
* \since QGIS 3.14
*/
void insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget SIP_TRANSFER, const QString &before, const QStringList &path = QStringList() );
void insertPage( const QString &title, const QString &tooltip, const QIcon &icon, QWidget *widget SIP_TRANSFER, const QString &before, const QStringList &path = QStringList(), const QString &key = QString() );
public slots:

View File

@ -113,9 +113,10 @@ class GUI_EXPORT QgsOptionsWidgetFactory : public QObject
QgsOptionsWidgetFactory() = default;
//! Constructor
QgsOptionsWidgetFactory( const QString &title, const QIcon &icon )
QgsOptionsWidgetFactory( const QString &title, const QIcon &icon, const QString &key = QString() )
: mTitle( title )
, mIcon( icon )
, mKey( key )
{}
/**
@ -143,6 +144,20 @@ class GUI_EXPORT QgsOptionsWidgetFactory : public QObject
*/
void setTitle( const QString &title ) { mTitle = title; }
/**
* The key of the panel (untranslated title).
* \see setKey()
*
* \since QGIS 3.32
*/
virtual QString key() const { return mKey; }
/**
* Set the \a key for the interface.
* \see key()
*/
void setKey( const QString &key ) { mKey = key; }
/**
* Returns a tab name hinting at where this page should be inserted into the
* options properties tab list.
@ -178,6 +193,7 @@ class GUI_EXPORT QgsOptionsWidgetFactory : public QObject
private:
QString mTitle;
QIcon mIcon;
QString mKey;
};