Skip to content

Commit 16b981c

Browse files
committedDec 22, 2019
Make label engine project settings dialog open as an inline panel
in the styling dock Means that you can get instant feedback on changes without having to close the dialog and refresh the map
1 parent 59c777f commit 16b981c

File tree

5 files changed

+106
-54
lines changed

5 files changed

+106
-54
lines changed
 

‎src/app/labeling/qgslabelengineconfigdialog.cpp

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,23 @@
1919
#include "pal/pal.h"
2020
#include "qgshelp.h"
2121
#include "qgsmessagebar.h"
22-
22+
#include "qgisapp.h"
23+
#include "qgsmapcanvas.h"
24+
#include "qgsgui.h"
2325
#include <QPushButton>
2426
#include <QMessageBox>
2527

26-
QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
27-
: QDialog( parent )
28+
QgsLabelEngineConfigWidget::QgsLabelEngineConfigWidget( QWidget *parent )
29+
: QgsPanelWidget( parent )
2830
{
2931
setupUi( this );
3032

33+
setPanelTitle( tr( "Placement Engine Settings" ) );
34+
3135
mMessageBar = new QgsMessageBar();
3236
mMessageBar->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
3337
verticalLayout->insertWidget( 0, mMessageBar );
3438

35-
connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsLabelEngineConfigDialog::onOK );
36-
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsLabelEngineConfigDialog::showHelp );
37-
connect( buttonBox->button( QDialogButtonBox::RestoreDefaults ), &QAbstractButton::clicked,
38-
this, &QgsLabelEngineConfigDialog::setDefaults );
39-
4039
QgsLabelingEngineSettings engineSettings = QgsProject::instance()->labelingEngineSettings();
4140

4241
mTextRenderFormatComboBox->addItem( tr( "Always Render Labels as Paths (Recommended)" ), QgsRenderContext::TextFormatAlwaysOutlines );
@@ -73,9 +72,20 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
7372
mUnplacedColorButton->setWindowTitle( tr( "Unplaced Label Color" ) );
7473

7574
mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( engineSettings.defaultTextRenderFormat() ) );
75+
76+
connect( spinCandPoint, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
77+
connect( spinCandLine, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
78+
connect( spinCandPolygon, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
79+
connect( chkShowCandidates, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
80+
connect( chkShowAllLabels, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
81+
connect( chkShowUnplaced, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
82+
connect( chkShowPartialsLabels, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
83+
connect( mTextRenderFormatComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
84+
connect( mUnplacedColorButton, &QgsColorButton::colorChanged, this, &QgsLabelEngineConfigWidget::widgetChanged );
85+
connect( mPlacementVersionComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
7686
}
7787

78-
void QgsLabelEngineConfigDialog::onOK()
88+
void QgsLabelEngineConfigWidget::apply()
7989
{
8090
QgsLabelingEngineSettings engineSettings;
8191

@@ -94,11 +104,10 @@ void QgsLabelEngineConfigDialog::onOK()
94104
engineSettings.setPlacementVersion( static_cast< QgsLabelingEngineSettings::PlacementEngineVersion >( mPlacementVersionComboBox->currentData().toInt() ) );
95105

96106
QgsProject::instance()->setLabelingEngineSettings( engineSettings );
97-
98-
accept();
107+
QgisApp::instance()->mapCanvas()->refreshAllLayers();
99108
}
100109

101-
void QgsLabelEngineConfigDialog::setDefaults()
110+
void QgsLabelEngineConfigWidget::setDefaults()
102111
{
103112
pal::Pal p;
104113
spinCandPoint->setValue( p.maximumNumberOfPointCandidates() );
@@ -111,7 +120,37 @@ void QgsLabelEngineConfigDialog::setDefaults()
111120
mPlacementVersionComboBox->setCurrentIndex( mPlacementVersionComboBox->findData( QgsLabelingEngineSettings::PlacementEngineVersion2 ) );
112121
}
113122

114-
void QgsLabelEngineConfigDialog::showHelp()
123+
void QgsLabelEngineConfigWidget::showHelp()
115124
{
116125
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#setting-the-automated-placement-engine" ) );
117126
}
127+
128+
//
129+
// QgsLabelEngineConfigDialog
130+
//
131+
132+
QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
133+
: QDialog( parent )
134+
{
135+
mWidget = new QgsLabelEngineConfigWidget();
136+
setWindowTitle( mWidget->windowTitle() );
137+
QVBoxLayout *vLayout = new QVBoxLayout();
138+
vLayout->addWidget( mWidget );
139+
QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::RestoreDefaults, Qt::Horizontal );
140+
connect( bbox, &QDialogButtonBox::accepted, this, &QDialog::accept );
141+
connect( bbox, &QDialogButtonBox::rejected, this, &QDialog::reject );
142+
connect( bbox, &QDialogButtonBox::helpRequested, mWidget, &QgsLabelEngineConfigWidget::showHelp );
143+
connect( bbox->button( QDialogButtonBox::RestoreDefaults ), &QAbstractButton::clicked,
144+
mWidget, &QgsLabelEngineConfigWidget::setDefaults );
145+
vLayout->addWidget( bbox );
146+
setLayout( vLayout );
147+
148+
setObjectName( QStringLiteral( "QgsLabelSettingsWidgetDialog" ) );
149+
QgsGui::instance()->enableAutoGeometryRestore( this );
150+
}
151+
152+
void QgsLabelEngineConfigDialog::accept()
153+
{
154+
mWidget->apply();
155+
QDialog::accept();
156+
}

‎src/app/labeling/qgslabelengineconfigdialog.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@
2323

2424
class QgsMessageBar;
2525

26-
class APP_EXPORT QgsLabelEngineConfigDialog : public QDialog, private Ui::QgsLabelEngineConfigDialog
26+
class APP_EXPORT QgsLabelEngineConfigWidget : public QgsPanelWidget, private Ui::QgsLabelEngineConfigDialog
2727
{
2828
Q_OBJECT
2929
public:
30-
QgsLabelEngineConfigDialog( QWidget *parent = nullptr );
30+
QgsLabelEngineConfigWidget( QWidget *parent = nullptr );
3131

3232
public slots:
33-
void onOK();
33+
void apply();
3434
void setDefaults();
35-
36-
37-
private slots:
3835
void showHelp();
3936

4037
private:
@@ -43,4 +40,18 @@ class APP_EXPORT QgsLabelEngineConfigDialog : public QDialog, private Ui::QgsLab
4340
QgsLabelingEngineSettings::PlacementEngineVersion mPreviousEngineVersion = QgsLabelingEngineSettings::PlacementEngineVersion2;
4441
};
4542

43+
class APP_EXPORT QgsLabelEngineConfigDialog : public QDialog
44+
{
45+
Q_OBJECT
46+
47+
public:
48+
49+
QgsLabelEngineConfigDialog( QWidget *parent = nullptr );
50+
51+
void accept() override;
52+
private:
53+
QgsLabelEngineConfigWidget *mWidget = nullptr;
54+
55+
};
56+
4657
#endif // QGSLABELENGINECONFIGDIALOG_H

‎src/app/labeling/qgslabelingwidget.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,18 @@ void QgsLabelingWidget::labelModeChanged( int index )
280280

281281
void QgsLabelingWidget::showEngineConfigDialog()
282282
{
283-
QgsLabelEngineConfigDialog dlg( this );
284-
dlg.exec();
285-
emit widgetChanged();
283+
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
284+
if ( panel && panel->dockMode() )
285+
{
286+
QgsLabelEngineConfigWidget *widget = new QgsLabelEngineConfigWidget();
287+
connect( widget, &QgsLabelEngineConfigWidget::widgetChanged, widget, &QgsLabelEngineConfigWidget::apply );
288+
panel->openPanel( widget );
289+
}
290+
else
291+
{
292+
QgsLabelEngineConfigDialog dialog( this );
293+
dialog.exec();
294+
// reactivate button's window
295+
activateWindow();
296+
}
286297
}

‎src/app/qgsdiagramproperties.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,20 @@ void QgsDiagramProperties::mDiagramAttributesTreeWidget_itemDoubleClicked( QTree
752752

753753
void QgsDiagramProperties::mEngineSettingsButton_clicked()
754754
{
755-
QgsLabelEngineConfigDialog dlg( this );
756-
dlg.exec();
755+
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
756+
if ( panel && panel->dockMode() )
757+
{
758+
QgsLabelEngineConfigWidget *widget = new QgsLabelEngineConfigWidget();
759+
connect( widget, &QgsLabelEngineConfigWidget::widgetChanged, widget, &QgsLabelEngineConfigWidget::apply );
760+
panel->openPanel( widget );
761+
}
762+
else
763+
{
764+
QgsLabelEngineConfigDialog dialog( this );
765+
dialog.exec();
766+
// reactivate button's window
767+
activateWindow();
768+
}
757769
}
758770

759771
void QgsDiagramProperties::apply()

‎src/ui/labeling/qgslabelengineconfigdialog.ui

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ui version="4.0">
33
<class>QgsLabelEngineConfigDialog</class>
4-
<widget class="QDialog" name="QgsLabelEngineConfigDialog">
4+
<widget class="QgsPanelWidget" name="QgsLabelEngineConfigDialog">
55
<property name="geometry">
66
<rect>
77
<x>0</x>
@@ -47,7 +47,7 @@
4747
</size>
4848
</property>
4949
<property name="title">
50-
<string>Number of candidates</string>
50+
<string>Number of Candidates</string>
5151
</property>
5252
<layout class="QGridLayout" name="gridLayout">
5353
<item row="0" column="0">
@@ -271,16 +271,6 @@
271271
</property>
272272
</spacer>
273273
</item>
274-
<item>
275-
<widget class="QDialogButtonBox" name="buttonBox">
276-
<property name="orientation">
277-
<enum>Qt::Horizontal</enum>
278-
</property>
279-
<property name="standardButtons">
280-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
281-
</property>
282-
</widget>
283-
</item>
284274
</layout>
285275
</widget>
286276
<customwidgets>
@@ -290,6 +280,12 @@
290280
<header>qgscolorbutton.h</header>
291281
<container>1</container>
292282
</customwidget>
283+
<customwidget>
284+
<class>QgsPanelWidget</class>
285+
<extends>QWidget</extends>
286+
<header>qgspanelwidget.h</header>
287+
<container>1</container>
288+
</customwidget>
293289
</customwidgets>
294290
<tabstops>
295291
<tabstop>spinCandPoint</tabstop>
@@ -303,22 +299,5 @@
303299
<tabstop>chkShowCandidates</tabstop>
304300
</tabstops>
305301
<resources/>
306-
<connections>
307-
<connection>
308-
<sender>buttonBox</sender>
309-
<signal>rejected()</signal>
310-
<receiver>QgsLabelEngineConfigDialog</receiver>
311-
<slot>reject()</slot>
312-
<hints>
313-
<hint type="sourcelabel">
314-
<x>316</x>
315-
<y>260</y>
316-
</hint>
317-
<hint type="destinationlabel">
318-
<x>286</x>
319-
<y>274</y>
320-
</hint>
321-
</hints>
322-
</connection>
323-
</connections>
302+
<connections/>
324303
</ui>

0 commit comments

Comments
 (0)
Please sign in to comment.