Skip to content

Commit

Permalink
Show units in tab position widget
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 9, 2024
1 parent 22fbd8b commit cf90076
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

};
Expand Down
10 changes: 10 additions & 0 deletions python/gui/auto_generated/labeling/qgstabpositionwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

};
Expand Down
15 changes: 15 additions & 0 deletions src/gui/labeling/qgstabpositionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
***************************************************************************/

#include "qgstabpositionwidget.h"
#include "moc_qgstabpositionwidget.cpp"
#include "qgsapplication.h"
#include "qgsdoublevalidator.h"
#include "qgsunittypes.h"

#include <QDialogButtonBox>

Expand All @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -121,3 +131,8 @@ QList<QgsTextFormat::Tab> QgsTabPositionDialog::positions() const
{
return mWidget->positions();
}

void QgsTabPositionDialog::setUnit( Qgis::RenderUnit unit )
{
mWidget->setUnit( unit );
}
10 changes: 10 additions & 0 deletions src/gui/labeling/qgstabpositionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

/**
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgstextformatwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/ui/qgstabpositionwidgetbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit cf90076

Please sign in to comment.