Show units in tab position widget

This commit is contained in:
Nyall Dawson 2024-10-31 10:04:06 +10:00
parent 22fbd8b87a
commit cf9007658e
6 changed files with 49 additions and 2 deletions

View File

@ -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
};

View File

@ -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
};

View File

@ -14,8 +14,10 @@
***************************************************************************/
#include "qgstabpositionwidget.h"
#include "moc_qgstabpositionwidget.cpp"
#include "qgsapplication.h"
#include "qgsdoublevalidator.h"
#include "qgsunittypes.h"
#include <QDialogButtonBox>
@ -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<QgsTextFormat::Tab> 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<QgsTextFormat::Tab> QgsTabPositionDialog::positions() const
{
return mWidget->positions();
}
void QgsTabPositionDialog::setUnit( Qgis::RenderUnit unit )
{
mWidget->setUnit( unit );
}

View File

@ -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;

View File

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

View File

@ -29,14 +29,14 @@
<item row="0" column="0">
<widget class="QTreeWidget" name="mTabPositionTreeWidget">
<property name="headerHidden">
<bool>true</bool>
<bool>false</bool>
</property>
<property name="columnCount">
<number>1</number>
</property>
<column>
<property name="text">
<string>Dash</string>
<string>Position</string>
</property>
</column>
</widget>