From e1f060f3036ac0a99d6fb85aea20e176440b129c Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 31 Oct 2024 10:04:06 +1000 Subject: [PATCH] Show units in tab position widget --- .../labeling/qgstabpositionwidget.sip.in | 10 ++++++++++ .../labeling/qgstabpositionwidget.sip.in | 10 ++++++++++ src/gui/labeling/qgstabpositionwidget.cpp | 15 +++++++++++++++ src/gui/labeling/qgstabpositionwidget.h | 10 ++++++++++ src/gui/qgstextformatwidget.cpp | 2 ++ src/ui/qgstabpositionwidgetbase.ui | 4 ++-- 6 files changed, 49 insertions(+), 2 deletions(-) diff --git a/python/PyQt6/gui/auto_generated/labeling/qgstabpositionwidget.sip.in b/python/PyQt6/gui/auto_generated/labeling/qgstabpositionwidget.sip.in index d44fdbd15fe2..028b6dc4d762 100644 --- a/python/PyQt6/gui/auto_generated/labeling/qgstabpositionwidget.sip.in +++ b/python/PyQt6/gui/auto_generated/labeling/qgstabpositionwidget.sip.in @@ -40,6 +40,11 @@ Sets the tab ``positions`` to show in the widget. Returns the tab positions defined in the widget. .. seealso:: :py:func:`setPositions` +%End + + void setUnit( Qgis::RenderUnit unit ); +%Docstring +Sets the unit type used for the tab positions (used to update interface labels). %End signals: @@ -81,6 +86,11 @@ Sets the tab ``positions`` to show in the dialog. Returns the tab positions defined in the dialog. .. seealso:: :py:func:`setPositions` +%End + + void setUnit( Qgis::RenderUnit unit ); +%Docstring +Sets the unit type used for the tab positions (used to update interface labels). %End }; diff --git a/python/gui/auto_generated/labeling/qgstabpositionwidget.sip.in b/python/gui/auto_generated/labeling/qgstabpositionwidget.sip.in index d44fdbd15fe2..028b6dc4d762 100644 --- a/python/gui/auto_generated/labeling/qgstabpositionwidget.sip.in +++ b/python/gui/auto_generated/labeling/qgstabpositionwidget.sip.in @@ -40,6 +40,11 @@ Sets the tab ``positions`` to show in the widget. Returns the tab positions defined in the widget. .. seealso:: :py:func:`setPositions` +%End + + void setUnit( Qgis::RenderUnit unit ); +%Docstring +Sets the unit type used for the tab positions (used to update interface labels). %End signals: @@ -81,6 +86,11 @@ Sets the tab ``positions`` to show in the dialog. Returns the tab positions defined in the dialog. .. seealso:: :py:func:`setPositions` +%End + + void setUnit( Qgis::RenderUnit unit ); +%Docstring +Sets the unit type used for the tab positions (used to update interface labels). %End }; diff --git a/src/gui/labeling/qgstabpositionwidget.cpp b/src/gui/labeling/qgstabpositionwidget.cpp index ef3ef14592ad..647113eea403 100644 --- a/src/gui/labeling/qgstabpositionwidget.cpp +++ b/src/gui/labeling/qgstabpositionwidget.cpp @@ -14,8 +14,10 @@ ***************************************************************************/ #include "qgstabpositionwidget.h" +#include "moc_qgstabpositionwidget.cpp" #include "qgsapplication.h" #include "qgsdoublevalidator.h" +#include "qgsunittypes.h" #include @@ -27,6 +29,8 @@ QgsTabPositionWidget::QgsTabPositionWidget( QWidget *parent ) mAddButton->setIcon( QgsApplication::getThemeIcon( "symbologyAdd.svg" ) ); mRemoveButton->setIcon( QgsApplication::getThemeIcon( "symbologyRemove.svg" ) ); + setUnit( Qgis::RenderUnit::Millimeters ); + connect( mAddButton, &QPushButton::clicked, this, &QgsTabPositionWidget::mAddButton_clicked ); connect( mRemoveButton, &QPushButton::clicked, this, &QgsTabPositionWidget::mRemoveButton_clicked ); connect( mTabPositionTreeWidget, &QTreeWidget::itemChanged, this, &QgsTabPositionWidget::emitPositionsChanged ); @@ -66,6 +70,12 @@ QList QgsTabPositionWidget::positions() const return result; } +void QgsTabPositionWidget::setUnit( Qgis::RenderUnit unit ) +{ + QTreeWidgetItem *headerItem = mTabPositionTreeWidget->headerItem(); + headerItem->setText( 0, QStringLiteral( "%1 (%2)" ).arg( tr( "Position" ), QgsUnitTypes::toAbbreviatedString( unit ) ) ); +} + void QgsTabPositionWidget::mAddButton_clicked() { const QList< QgsTextFormat::Tab > currentPositions = positions(); @@ -121,3 +131,8 @@ QList QgsTabPositionDialog::positions() const { return mWidget->positions(); } + +void QgsTabPositionDialog::setUnit( Qgis::RenderUnit unit ) +{ + mWidget->setUnit( unit ); +} diff --git a/src/gui/labeling/qgstabpositionwidget.h b/src/gui/labeling/qgstabpositionwidget.h index c09a3683ce57..b26ec299eb6e 100644 --- a/src/gui/labeling/qgstabpositionwidget.h +++ b/src/gui/labeling/qgstabpositionwidget.h @@ -52,6 +52,11 @@ class GUI_EXPORT QgsTabPositionWidget: public QgsPanelWidget, private Ui::QgsTab */ QList< QgsTextFormat::Tab > positions() const; + /** + * Sets the unit type used for the tab positions (used to update interface labels). + */ + void setUnit( Qgis::RenderUnit unit ); + signals: /** @@ -94,6 +99,11 @@ class GUI_EXPORT QgsTabPositionDialog : public QDialog */ QList< QgsTextFormat::Tab > positions() const; + /** + * Sets the unit type used for the tab positions (used to update interface labels). + */ + void setUnit( Qgis::RenderUnit unit ); + private: QgsTabPositionWidget *mWidget = nullptr; diff --git a/src/gui/qgstextformatwidget.cpp b/src/gui/qgstextformatwidget.cpp index bf14c1b0bcc8..8796e86354c5 100644 --- a/src/gui/qgstextformatwidget.cpp +++ b/src/gui/qgstextformatwidget.cpp @@ -2176,6 +2176,7 @@ void QgsTextFormatWidget::configureTabStops() QgsTabPositionWidget *widget = new QgsTabPositionWidget( panel ); widget->setPanelTitle( tr( "Tab Positions" ) ); widget->setPositions( mTabPositions ); + widget->setUnit( mTabDistanceUnitWidget->unit() ); connect( widget, &QgsTabPositionWidget::positionsChanged, this, [ = ]( const QList< QgsTextFormat::Tab > &positions ) { mTabPositions = positions; @@ -2188,6 +2189,7 @@ void QgsTextFormatWidget::configureTabStops() { QgsTabPositionDialog dlg( this ); dlg.setPositions( mTabPositions ); + dlg.setUnit( mTabDistanceUnitWidget->unit() ); if ( dlg.exec() == QDialog::Accepted ) { mTabPositions = dlg.positions(); diff --git a/src/ui/qgstabpositionwidgetbase.ui b/src/ui/qgstabpositionwidgetbase.ui index e158f3749c20..601ecaff642f 100644 --- a/src/ui/qgstabpositionwidgetbase.ui +++ b/src/ui/qgstabpositionwidgetbase.ui @@ -29,14 +29,14 @@ - true + false 1 - Dash + Position