Remove a lot of hardcoded tab indexes

This commit is contained in:
Nyall Dawson 2024-12-18 15:00:35 +10:00
parent 6408267d95
commit e5379a7b5c
6 changed files with 186 additions and 178 deletions

View File

@ -171,6 +171,7 @@ Toggles whether data defined buttons should be shown in the widget.
protected slots:
void updateLinePlacementOptions();

View File

@ -171,6 +171,7 @@ Toggles whether data defined buttons should be shown in the widget.
protected slots:
void updateLinePlacementOptions();

View File

@ -79,6 +79,99 @@ void QgsTextFormatWidget::initWidget()
mGeometryGeneratorGroupBox->setCollapsed( true );
mTextItem = new QListWidgetItem( tr( "Text" ), mLabelingOptionsListWidget );
mTextItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labeltext.svg" ) ) );
mTextItem->setToolTip( tr( "Text style" ) );
mFormattingItem = new QListWidgetItem( tr( "Formatting" ), mLabelingOptionsListWidget );
mFormattingItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labelformatting.svg" ) ) );
mFormattingItem->setToolTip( tr( "Formatting" ) );
mBufferItem = new QListWidgetItem( tr( "Buffer" ), mLabelingOptionsListWidget );
mBufferItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labelbuffer.svg" ) ) );
mBufferItem->setToolTip( tr( "Buffer" ) );
mMaskItem = new QListWidgetItem( tr( "Mask" ), mLabelingOptionsListWidget );
mMaskItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labelmask.svg" ) ) );
mMaskItem->setToolTip( tr( "Mask" ) );
mBackgroundItem = new QListWidgetItem( tr( "Background" ), mLabelingOptionsListWidget );
mBackgroundItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labelbackground.svg" ) ) );
mBackgroundItem->setToolTip( tr( "Background" ) );
mShadowItem = new QListWidgetItem( tr( "Shadow" ), mLabelingOptionsListWidget );
mShadowItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labelshadow.svg" ) ) );
mShadowItem->setToolTip( tr( "Shadow" ) );
mCalloutItem = new QListWidgetItem( tr( "Callouts" ), mLabelingOptionsListWidget );
mCalloutItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labelcallout.svg" ) ) );
mCalloutItem->setToolTip( tr( "Callouts" ) );
mPlacementItem = new QListWidgetItem( tr( "Placement" ), mLabelingOptionsListWidget );
mPlacementItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/labelplacement.svg" ) ) );
mPlacementItem->setToolTip( tr( "Placement" ) );
mRenderingItem = new QListWidgetItem( tr( "Rendering" ), mLabelingOptionsListWidget );
mRenderingItem->setIcon( QgsApplication::getThemeIcon( QStringLiteral( "propertyicons/render.svg" ) ) );
mRenderingItem->setToolTip( tr( "Rendering" ) );
mLabelingOptionsListWidget->addItem( mTextItem );
mLabelingOptionsListWidget->addItem( mFormattingItem );
mLabelingOptionsListWidget->addItem( mBufferItem );
mLabelingOptionsListWidget->addItem( mMaskItem );
mLabelingOptionsListWidget->addItem( mBackgroundItem );
mLabelingOptionsListWidget->addItem( mShadowItem );
mLabelingOptionsListWidget->addItem( mCalloutItem );
mLabelingOptionsListWidget->addItem( mPlacementItem );
mLabelingOptionsListWidget->addItem( mRenderingItem );
QObject::connect( mOptionsTab, &QTabWidget::currentChanged, this, [this]( int index ) {
if ( index == mOptionsTab->indexOf( textTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Text );
else if ( index == mOptionsTab->indexOf( formattingTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Formatting );
else if ( index == mOptionsTab->indexOf( maskTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Mask );
else if ( index == mOptionsTab->indexOf( bufferTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Buffer );
else if ( index == mOptionsTab->indexOf( backgroundTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Background );
else if ( index == mOptionsTab->indexOf( shadowTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Shadow );
else if ( index == mOptionsTab->indexOf( calloutsTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Callouts );
else if ( index == mOptionsTab->indexOf( placementTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Placement );
else if ( index == mOptionsTab->indexOf( renderingTab ) )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Rendering );
} );
QObject::connect( mLabelingOptionsListWidget, &QListWidget::currentRowChanged, this, [this]( int ) {
QListWidgetItem *currentItem = mLabelingOptionsListWidget->currentItem();
if ( !currentItem )
return;
if ( currentItem == mTextItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Text );
else if ( currentItem == mFormattingItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Formatting );
else if ( currentItem == mMaskItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Mask );
else if ( currentItem == mBufferItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Buffer );
else if ( currentItem == mBackgroundItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Background );
else if ( currentItem == mShadowItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Shadow );
else if ( currentItem == mCalloutItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Callouts );
else if ( currentItem == mPlacementItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Placement );
else if ( currentItem == mRenderingItem )
mLabelStackedWidget->setCurrentWidget( mLabelPage_Rendering );
} );
QObject::connect( mLabelingOptionsListWidget, &QListWidget::currentRowChanged, mLabelStackedWidget, &QStackedWidget::setCurrentIndex );
connect( mShapeSVGPathLineEdit, &QLineEdit::textChanged, this, &QgsTextFormatWidget::mShapeSVGPathLineEdit_textChanged );
connect( mFontSizeSpinBox, static_cast<void ( QDoubleSpinBox::* )( double )>( &QDoubleSpinBox::valueChanged ), this, &QgsTextFormatWidget::mFontSizeSpinBox_valueChanged );
connect( mFontFamilyCmbBx, &QFontComboBox::currentFontChanged, this, &QgsTextFormatWidget::mFontFamilyCmbBx_currentFontChanged );
@ -553,14 +646,18 @@ void QgsTextFormatWidget::setWidgetMode( QgsTextFormatWidget::Mode mode )
{
const int prevIndex = mOptionsTab->currentIndex();
setPropertyOverrideButtonsVisible( true );
delete mLabelingOptionsListWidget->takeItem( 8 ); // rendering
delete mLabelingOptionsListWidget->takeItem( 7 ); // placement
delete mLabelingOptionsListWidget->takeItem( 6 ); // callouts
delete mLabelingOptionsListWidget->takeItem( 3 ); // mask
mOptionsTab->removeTab( 8 );
mOptionsTab->removeTab( 7 );
mOptionsTab->removeTab( 6 );
mOptionsTab->removeTab( 3 );
delete mRenderingItem;
mRenderingItem = nullptr;
delete mPlacementItem;
mPlacementItem = nullptr;
delete mCalloutItem;
mCalloutItem = nullptr;
delete mMaskItem;
mMaskItem = nullptr;
mOptionsTab->removeTab( mOptionsTab->indexOf( renderingTab ) );
mOptionsTab->removeTab( mOptionsTab->indexOf( placementTab ) );
mOptionsTab->removeTab( mOptionsTab->indexOf( calloutsTab ) );
mOptionsTab->removeTab( mOptionsTab->indexOf( maskTab ) );
mLabelStackedWidget->removeWidget( mLabelPage_Rendering );
mLabelStackedWidget->removeWidget( mLabelPage_Callouts );
mLabelStackedWidget->removeWidget( mLabelPage_Mask );
@ -629,15 +726,24 @@ void QgsTextFormatWidget::setPropertyOverrideButtonsVisible( bool visible )
void QgsTextFormatWidget::setDockMode( bool enabled )
{
mOptionsTab->setVisible( enabled );
mOptionsTab->setTabToolTip( 0, tr( "Text" ) );
mOptionsTab->setTabToolTip( 1, tr( "Formatting" ) );
mOptionsTab->setTabToolTip( 2, tr( "Buffer" ) );
mOptionsTab->setTabToolTip( 3, tr( "Mask" ) );
mOptionsTab->setTabToolTip( 4, tr( "Background" ) );
mOptionsTab->setTabToolTip( 5, tr( "Shadow" ) );
mOptionsTab->setTabToolTip( 6, tr( "Callouts" ) );
mOptionsTab->setTabToolTip( 7, tr( "Placement" ) );
mOptionsTab->setTabToolTip( 8, tr( "Rendering" ) );
if ( int tabIndex = mOptionsTab->indexOf( textTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Text" ) );
if ( int tabIndex = mOptionsTab->indexOf( formattingTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Formatting" ) );
if ( int tabIndex = mOptionsTab->indexOf( bufferTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Buffer" ) );
if ( int tabIndex = mOptionsTab->indexOf( maskTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Mask" ) );
if ( int tabIndex = mOptionsTab->indexOf( backgroundTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Background" ) );
if ( int tabIndex = mOptionsTab->indexOf( shadowTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Shadow" ) );
if ( int tabIndex = mOptionsTab->indexOf( calloutsTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Callouts" ) );
if ( int tabIndex = mOptionsTab->indexOf( placementTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Placement" ) );
if ( int tabIndex = mOptionsTab->indexOf( renderingTab ); tabIndex >= 0 )
mOptionsTab->setTabToolTip( tabIndex, tr( "Rendering" ) );
mLabelingOptionsListFrame->setVisible( !enabled );
groupBox_mPreview->setVisible( !enabled );
@ -985,8 +1091,8 @@ void QgsTextFormatWidget::updateWidgetForFormat( const QgsTextFormat &format )
mFontMissingLabel->setText( missingTxt.arg( txtPrepend ) );
// ensure user is sent to 'Text style' section to see notice
mLabelingOptionsListWidget->setCurrentRow( 0 );
whileBlocking( mOptionsTab )->setCurrentIndex( 0 );
mLabelingOptionsListWidget->setCurrentItem( mTextItem );
whileBlocking( mOptionsTab )->setCurrentIndex( mOptionsTab->indexOf( textTab ) );
}
mFontLineHeightSpinBox->setValue( format.lineHeightUnit() == Qgis::RenderUnit::Percentage ? ( format.lineHeight() * 100 ) : format.lineHeight() );
mLineHeightUnitWidget->setUnit( format.lineHeightUnit() );
@ -1237,10 +1343,28 @@ void QgsTextFormatWidget::deactivateField( QgsPalLayerSettings::Property key )
}
}
void QgsTextFormatWidget::optionsStackedWidget_CurrentChanged( int indx )
void QgsTextFormatWidget::optionsStackedWidget_CurrentChanged( int )
{
mLabelingOptionsListWidget->blockSignals( true );
mLabelingOptionsListWidget->setCurrentRow( indx );
QWidget *currentPage = mLabelStackedWidget->currentWidget();
if ( currentPage == mLabelPage_Text )
mLabelingOptionsListWidget->setCurrentItem( mTextItem );
else if ( currentPage == mLabelPage_Formatting )
mLabelingOptionsListWidget->setCurrentItem( mFormattingItem );
else if ( currentPage == mLabelPage_Mask )
mLabelingOptionsListWidget->setCurrentItem( mMaskItem );
if ( currentPage == mLabelPage_Buffer )
mLabelingOptionsListWidget->setCurrentItem( mBufferItem );
if ( currentPage == mLabelPage_Background )
mLabelingOptionsListWidget->setCurrentItem( mBackgroundItem );
if ( currentPage == mLabelPage_Shadow )
mLabelingOptionsListWidget->setCurrentItem( mShadowItem );
if ( currentPage == mLabelPage_Callouts )
mLabelingOptionsListWidget->setCurrentItem( mCalloutItem );
if ( currentPage == mLabelPage_Rendering )
mLabelingOptionsListWidget->setCurrentItem( mRenderingItem );
if ( currentPage == mLabelPage_Placement )
mLabelingOptionsListWidget->setCurrentItem( mPlacementItem );
mLabelingOptionsListWidget->blockSignals( false );
}

View File

@ -203,6 +203,25 @@ class GUI_EXPORT QgsTextFormatWidget : public QWidget, public QgsExpressionConte
//! Geometry type for layer, if known
Qgis::GeometryType mGeomType = Qgis::GeometryType::Unknown;
//! Text widget item
QListWidgetItem *mTextItem = nullptr;
//! Formatting widget item
QListWidgetItem *mFormattingItem = nullptr;
//! Buffer widget item
QListWidgetItem *mBufferItem = nullptr;
//! Mask widget item
QListWidgetItem *mMaskItem = nullptr;
//! Background widget item
QListWidgetItem *mBackgroundItem = nullptr;
//! Shadow widget item
QListWidgetItem *mShadowItem = nullptr;
//! Callout widget item
QListWidgetItem *mCalloutItem = nullptr;
//! Placement widget item
QListWidgetItem *mPlacementItem = nullptr;
//! Rendering widget item
QListWidgetItem *mRenderingItem = nullptr;
protected slots:
//! Updates line placement options to reflect current state of widget

View File

@ -82,11 +82,13 @@ QgsRasterLabelSettingsWidget::QgsRasterLabelSettingsWidget( QgsRasterLayer *laye
setPropertyOverrideButtonsVisible( true );
mTextFormatsListWidget->setEntityTypes( QList<QgsStyle::StyleEntity>() << QgsStyle::TextFormatEntity );
delete mLabelingOptionsListWidget->takeItem( 6 ); // callouts
delete mLabelingOptionsListWidget->takeItem( 3 ); // mask
delete mCalloutItem;
mCalloutItem = nullptr;
delete mMaskItem;
mMaskItem = nullptr;
mOptionsTab->removeTab( 6 );
mOptionsTab->removeTab( 3 );
mOptionsTab->removeTab( mOptionsTab->indexOf( calloutsTab ) );
mOptionsTab->removeTab( mOptionsTab->indexOf( maskTab ) );
mLabelStackedWidget->removeWidget( mLabelPage_Callouts );
mLabelStackedWidget->removeWidget( mLabelPage_Mask );

View File

@ -352,7 +352,7 @@
<string/>
</attribute>
</widget>
<widget class="QWidget" name="tab_2">
<widget class="QWidget" name="formattingTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelformatting.svg</normaloff>:/images/themes/default/propertyicons/labelformatting.svg</iconset>
@ -361,7 +361,7 @@
<string/>
</attribute>
</widget>
<widget class="QWidget" name="tab">
<widget class="QWidget" name="bufferTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelbuffer.svg</normaloff>:/images/themes/default/propertyicons/labelbuffer.svg</iconset>
@ -379,7 +379,7 @@
<string/>
</attribute>
</widget>
<widget class="QWidget" name="tab_3">
<widget class="QWidget" name="backgroundTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelbackground.svg</normaloff>:/images/themes/default/propertyicons/labelbackground.svg</iconset>
@ -388,7 +388,7 @@
<string/>
</attribute>
</widget>
<widget class="QWidget" name="tab_4">
<widget class="QWidget" name="shadowTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelshadow.svg</normaloff>:/images/themes/default/propertyicons/labelshadow.svg</iconset>
@ -397,7 +397,7 @@
<string/>
</attribute>
</widget>
<widget class="QWidget" name="callouts">
<widget class="QWidget" name="calloutsTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelcallout.svg</normaloff>:/images/themes/default/propertyicons/labelcallout.svg</iconset>
@ -409,7 +409,7 @@
<string>Callouts</string>
</attribute>
</widget>
<widget class="QWidget" name="widget">
<widget class="QWidget" name="placementTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelplacement.svg</normaloff>:/images/themes/default/propertyicons/labelplacement.svg</iconset>
@ -418,7 +418,7 @@
<string/>
</attribute>
</widget>
<widget class="QWidget" name="tab_6">
<widget class="QWidget" name="renderingTab">
<attribute name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/render.svg</normaloff>:/images/themes/default/propertyicons/render.svg</iconset>
@ -486,112 +486,6 @@
<height>20</height>
</size>
</property>
<item>
<property name="text">
<string>Text</string>
</property>
<property name="toolTip">
<string>Text style</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labeltext.svg</normaloff>:/images/themes/default/propertyicons/labeltext.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Formatting</string>
</property>
<property name="toolTip">
<string>Formatting</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelformatting.svg</normaloff>:/images/themes/default/propertyicons/labelformatting.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Buffer</string>
</property>
<property name="toolTip">
<string>Buffer</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelbuffer.svg</normaloff>:/images/themes/default/propertyicons/labelbuffer.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Mask</string>
</property>
<property name="icon">
<iconset>
<normalon>:/images/themes/default/propertyicons/labelmask.svg</normalon>
</iconset>
</property>
</item>
<item>
<property name="text">
<string>Background</string>
</property>
<property name="toolTip">
<string>Background</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelbackground.svg</normaloff>:/images/themes/default/propertyicons/labelbackground.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Shadow</string>
</property>
<property name="toolTip">
<string>Shadow</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelshadow.svg</normaloff>:/images/themes/default/propertyicons/labelshadow.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Callouts</string>
</property>
<property name="toolTip">
<string>Callouts</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelcallout.svg</normaloff>:/images/themes/default/propertyicons/labelcallout.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Placement</string>
</property>
<property name="toolTip">
<string>Placement</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/labelplacement.svg</normaloff>:/images/themes/default/propertyicons/labelplacement.svg</iconset>
</property>
</item>
<item>
<property name="text">
<string>Rendering</string>
</property>
<property name="toolTip">
<string>Rendering</string>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/propertyicons/render.svg</normaloff>:/images/themes/default/propertyicons/render.svg</iconset>
</property>
</item>
</widget>
</item>
</layout>
@ -1217,7 +1111,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>347</width>
<width>350</width>
<height>755</height>
</rect>
</property>
@ -2214,7 +2108,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>273</width>
<width>276</width>
<height>299</height>
</rect>
</property>
@ -2560,7 +2454,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>273</width>
<width>276</width>
<height>284</height>
</rect>
</property>
@ -2838,7 +2732,7 @@ font-style: italic;</string>
<rect>
<x>0</x>
<y>0</y>
<width>418</width>
<width>471</width>
<height>731</height>
</rect>
</property>
@ -5973,9 +5867,9 @@ font-style: italic;</string>
<property name="geometry">
<rect>
<x>0</x>
<y>-463</y>
<y>0</y>
<width>471</width>
<height>849</height>
<height>865</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
@ -7266,38 +7160,5 @@ This limit is inclusive, that means the label will be displayed on this scale.</
<resources>
<include location="../../images/images.qrc"/>
</resources>
<connections>
<connection>
<sender>mOptionsTab</sender>
<signal>currentChanged(int)</signal>
<receiver>mLabelStackedWidget</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>164</x>
<y>205</y>
</hint>
<hint type="destinationlabel">
<x>689</x>
<y>277</y>
</hint>
</hints>
</connection>
<connection>
<sender>mLabelingOptionsListWidget</sender>
<signal>currentRowChanged(int)</signal>
<receiver>mLabelStackedWidget</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>34</x>
<y>599</y>
</hint>
<hint type="destinationlabel">
<x>633</x>
<y>411</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>