Skip to content

Commit

Permalink
[needs-docs] Add labeling engine version setting in project labeling …
Browse files Browse the repository at this point in the history
…settings dialog

This allows users to upgrade existing projects to the newer labeling engine version.
A warning will show advising users that change the version will alter the placement
of labels within the project.
  • Loading branch information
nyalldawson committed Nov 27, 2019
1 parent ff3b4d5 commit bdb1c76
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 25 deletions.
22 changes: 22 additions & 0 deletions src/app/qgslabelengineconfigdialog.cpp
Expand Up @@ -18,14 +18,20 @@
#include "qgsproject.h"
#include "pal/pal.h"
#include "qgshelp.h"
#include "qgsmessagebar.h"

#include <QPushButton>
#include <QMessageBox>

QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
: QDialog( parent )
{
setupUi( this );

mMessageBar = new QgsMessageBar();
mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
verticalLayout->insertWidget( 0, mMessageBar );

connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsLabelEngineConfigDialog::onOK );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLabelEngineConfigDialog::showHelp );
connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), &QAbstractButton::clicked,
Expand All @@ -36,6 +42,19 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
mTextRenderFormatComboBox->addItem( tr( "Always Render Labels as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
mTextRenderFormatComboBox->addItem( tr( "Always Render Labels as Text" ), QgsRenderContext::TextFormatAlwaysText );

mPlacementVersionComboBox->addItem( tr( "Version 1" ), QgsLabelingEngineSettings::PlacementEngineVersion1 );
mPlacementVersionComboBox->addItem( tr( "Version 2 (Recommended)" ), QgsLabelingEngineSettings::PlacementEngineVersion2 );

mPreviousEngineVersion = engineSettings.placementVersion();
mPlacementVersionComboBox->setCurrentIndex( mPlacementVersionComboBox->findData( mPreviousEngineVersion ) );
connect( mPlacementVersionComboBox, &QComboBox::currentTextChanged, this, [ = ]()
{
if ( static_cast< QgsLabelingEngineSettings::PlacementEngineVersion >( mPlacementVersionComboBox->currentData().toInt() ) != mPreviousEngineVersion )
{
mMessageBar->pushMessage( QString(), tr( "Version changes will alter label placement in the project." ), Qgis::Warning, 0 );
}
} );

// candidate numbers
int candPoint, candLine, candPolygon;
engineSettings.numCandidatePositions( candPoint, candLine, candPolygon );
Expand Down Expand Up @@ -72,6 +91,8 @@ void QgsLabelEngineConfigDialog::onOK()

engineSettings.setUnplacedLabelColor( mUnplacedColorButton->color() );

engineSettings.setPlacementVersion( static_cast< QgsLabelingEngineSettings::PlacementEngineVersion >( mPlacementVersionComboBox->currentData().toInt() ) );

QgsProject::instance()->setLabelingEngineSettings( engineSettings );

accept();
Expand All @@ -87,6 +108,7 @@ void QgsLabelEngineConfigDialog::setDefaults()
chkShowAllLabels->setChecked( false );
chkShowPartialsLabels->setChecked( p.getShowPartial() );
mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( QgsRenderContext::TextFormatAlwaysOutlines ) );
mPlacementVersionComboBox->setCurrentIndex( mPlacementVersionComboBox->findData( QgsLabelingEngineSettings::PlacementEngineVersion2 ) );
}

void QgsLabelEngineConfigDialog::showHelp()
Expand Down
7 changes: 6 additions & 1 deletion src/app/qgslabelengineconfigdialog.h
Expand Up @@ -19,7 +19,9 @@

#include "ui_qgslabelengineconfigdialog.h"
#include "qgis_app.h"
#include "qgslabelingenginesettings.h"

class QgsMessageBar;

class APP_EXPORT QgsLabelEngineConfigDialog : public QDialog, private Ui::QgsLabelEngineConfigDialog
{
Expand All @@ -35,7 +37,10 @@ class APP_EXPORT QgsLabelEngineConfigDialog : public QDialog, private Ui::QgsLab
private slots:
void showHelp();

protected:
private:
QgsMessageBar *mMessageBar = nullptr;

QgsLabelingEngineSettings::PlacementEngineVersion mPreviousEngineVersion = QgsLabelingEngineSettings::PlacementEngineVersion2;
};

#endif // QGSLABELENGINECONFIGDIALOG_H
58 changes: 34 additions & 24 deletions src/ui/qgslabelengineconfigdialog.ui
Expand Up @@ -160,19 +160,13 @@
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0,0">
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowAllLabels">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="inputMethodHints">
<set>Qt::ImhNone</set>
</property>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mTextRenderFormatComboBox"/>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowCandidates">
<property name="text">
<string>Show all labels for all layers (i.e. including colliding objects)</string>
<string>Show candidates (for debugging)</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -215,20 +209,19 @@
</item>
</layout>
</item>
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="mTextRenderFormatComboBox"/>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowCandidates">
<property name="text">
<string>Show candidates (for debugging)</string>
<item row="2" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowAllLabels">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="inputMethodHints">
<set>Qt::ImhNone</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowPartialsLabels">
<property name="text">
<string>Allow truncated labels on edges of map</string>
<string>Show all labels for all layers (i.e. including colliding objects)</string>
</property>
</widget>
</item>
Expand All @@ -246,6 +239,23 @@
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QCheckBox" name="chkShowPartialsLabels">
<property name="text">
<string>Allow truncated labels on edges of map</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Project labeling version</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<widget class="QComboBox" name="mPlacementVersionComboBox"/>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit bdb1c76

Please sign in to comment.