/
qgslabelengineconfigdialog.cpp
117 lines (94 loc) · 5.83 KB
/
qgslabelengineconfigdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/***************************************************************************
qgslabelengineconfigdialog.cpp
---------------------
begin : May 2010
copyright : (C) 2010 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgslabelengineconfigdialog.h"
#include "qgslabelingenginesettings.h"
#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,
this, &QgsLabelEngineConfigDialog::setDefaults );
QgsLabelingEngineSettings engineSettings = QgsProject::instance()->labelingEngineSettings();
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 );
spinCandPoint->setValue( candPoint );
spinCandLine->setValue( candLine );
spinCandPolygon->setValue( candPolygon );
chkShowCandidates->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::DrawCandidates ) );
chkShowAllLabels->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::UseAllLabels ) );
chkShowUnplaced->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::DrawUnplacedLabels ) );
chkShowPartialsLabels->setChecked( engineSettings.testFlag( QgsLabelingEngineSettings::UsePartialCandidates ) );
mUnplacedColorButton->setColor( engineSettings.unplacedLabelColor() );
mUnplacedColorButton->setAllowOpacity( false );
mUnplacedColorButton->setDefaultColor( QColor( 255, 0, 0 ) );
mUnplacedColorButton->setWindowTitle( tr( "Unplaced Label Color" ) );
mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( engineSettings.defaultTextRenderFormat() ) );
}
void QgsLabelEngineConfigDialog::onOK()
{
QgsLabelingEngineSettings engineSettings;
// save
engineSettings.setNumCandidatePositions( spinCandPoint->value(), spinCandLine->value(), spinCandPolygon->value() );
engineSettings.setFlag( QgsLabelingEngineSettings::DrawCandidates, chkShowCandidates->isChecked() );
engineSettings.setFlag( QgsLabelingEngineSettings::UseAllLabels, chkShowAllLabels->isChecked() );
engineSettings.setFlag( QgsLabelingEngineSettings::DrawUnplacedLabels, chkShowUnplaced->isChecked() );
engineSettings.setFlag( QgsLabelingEngineSettings::UsePartialCandidates, chkShowPartialsLabels->isChecked() );
engineSettings.setDefaultTextRenderFormat( static_cast< QgsRenderContext::TextRenderFormat >( mTextRenderFormatComboBox->currentData().toInt() ) );
engineSettings.setUnplacedLabelColor( mUnplacedColorButton->color() );
engineSettings.setPlacementVersion( static_cast< QgsLabelingEngineSettings::PlacementEngineVersion >( mPlacementVersionComboBox->currentData().toInt() ) );
QgsProject::instance()->setLabelingEngineSettings( engineSettings );
accept();
}
void QgsLabelEngineConfigDialog::setDefaults()
{
pal::Pal p;
spinCandPoint->setValue( p.maximumNumberOfPointCandidates() );
spinCandLine->setValue( p.maximumNumberOfLineCandidates() );
spinCandPolygon->setValue( p.maximumNumberOfPolygonCandidates() );
chkShowCandidates->setChecked( false );
chkShowAllLabels->setChecked( false );
chkShowPartialsLabels->setChecked( p.showPartialLabels() );
mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( QgsRenderContext::TextFormatAlwaysOutlines ) );
mPlacementVersionComboBox->setCurrentIndex( mPlacementVersionComboBox->findData( QgsLabelingEngineSettings::PlacementEngineVersion2 ) );
}
void QgsLabelEngineConfigDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#setting-the-automated-placement-engine" ) );
}