Skip to content
Permalink
Browse files

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
  • Loading branch information
nyalldawson committed Dec 22, 2019
1 parent 59c777f commit 16b981c28735bfeaf5b10ce7d12181439c103158
@@ -19,24 +19,23 @@
#include "pal/pal.h"
#include "qgshelp.h"
#include "qgsmessagebar.h"

#include "qgisapp.h"
#include "qgsmapcanvas.h"
#include "qgsgui.h"
#include <QPushButton>
#include <QMessageBox>

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

setPanelTitle( tr( "Placement Engine Settings" ) );

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 );
@@ -73,9 +72,20 @@ QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
mUnplacedColorButton->setWindowTitle( tr( "Unplaced Label Color" ) );

mTextRenderFormatComboBox->setCurrentIndex( mTextRenderFormatComboBox->findData( engineSettings.defaultTextRenderFormat() ) );

connect( spinCandPoint, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( spinCandLine, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( spinCandPolygon, qgis::overload<int>::of( &QSpinBox::valueChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( chkShowCandidates, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( chkShowAllLabels, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( chkShowUnplaced, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( chkShowPartialsLabels, &QCheckBox::toggled, this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( mTextRenderFormatComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( mUnplacedColorButton, &QgsColorButton::colorChanged, this, &QgsLabelEngineConfigWidget::widgetChanged );
connect( mPlacementVersionComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), this, &QgsLabelEngineConfigWidget::widgetChanged );
}

void QgsLabelEngineConfigDialog::onOK()
void QgsLabelEngineConfigWidget::apply()
{
QgsLabelingEngineSettings engineSettings;

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

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

accept();
QgisApp::instance()->mapCanvas()->refreshAllLayers();
}

void QgsLabelEngineConfigDialog::setDefaults()
void QgsLabelEngineConfigWidget::setDefaults()
{
pal::Pal p;
spinCandPoint->setValue( p.maximumNumberOfPointCandidates() );
@@ -111,7 +120,37 @@ void QgsLabelEngineConfigDialog::setDefaults()
mPlacementVersionComboBox->setCurrentIndex( mPlacementVersionComboBox->findData( QgsLabelingEngineSettings::PlacementEngineVersion2 ) );
}

void QgsLabelEngineConfigDialog::showHelp()
void QgsLabelEngineConfigWidget::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "working_with_vector/vector_properties.html#setting-the-automated-placement-engine" ) );
}

//
// QgsLabelEngineConfigDialog
//

QgsLabelEngineConfigDialog::QgsLabelEngineConfigDialog( QWidget *parent )
: QDialog( parent )
{
mWidget = new QgsLabelEngineConfigWidget();
setWindowTitle( mWidget->windowTitle() );
QVBoxLayout *vLayout = new QVBoxLayout();
vLayout->addWidget( mWidget );
QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::RestoreDefaults, Qt::Horizontal );
connect( bbox, &QDialogButtonBox::accepted, this, &QDialog::accept );
connect( bbox, &QDialogButtonBox::rejected, this, &QDialog::reject );
connect( bbox, &QDialogButtonBox::helpRequested, mWidget, &QgsLabelEngineConfigWidget::showHelp );
connect( bbox->button( QDialogButtonBox::RestoreDefaults ), &QAbstractButton::clicked,
mWidget, &QgsLabelEngineConfigWidget::setDefaults );
vLayout->addWidget( bbox );
setLayout( vLayout );

setObjectName( QStringLiteral( "QgsLabelSettingsWidgetDialog" ) );
QgsGui::instance()->enableAutoGeometryRestore( this );
}

void QgsLabelEngineConfigDialog::accept()
{
mWidget->apply();
QDialog::accept();
}
@@ -23,18 +23,15 @@

class QgsMessageBar;

class APP_EXPORT QgsLabelEngineConfigDialog : public QDialog, private Ui::QgsLabelEngineConfigDialog
class APP_EXPORT QgsLabelEngineConfigWidget : public QgsPanelWidget, private Ui::QgsLabelEngineConfigDialog
{
Q_OBJECT
public:
QgsLabelEngineConfigDialog( QWidget *parent = nullptr );
QgsLabelEngineConfigWidget( QWidget *parent = nullptr );

public slots:
void onOK();
void apply();
void setDefaults();


private slots:
void showHelp();

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

class APP_EXPORT QgsLabelEngineConfigDialog : public QDialog
{
Q_OBJECT

public:

QgsLabelEngineConfigDialog( QWidget *parent = nullptr );

void accept() override;
private:
QgsLabelEngineConfigWidget *mWidget = nullptr;

};

#endif // QGSLABELENGINECONFIGDIALOG_H
@@ -280,7 +280,18 @@ void QgsLabelingWidget::labelModeChanged( int index )

void QgsLabelingWidget::showEngineConfigDialog()
{
QgsLabelEngineConfigDialog dlg( this );
dlg.exec();
emit widgetChanged();
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsLabelEngineConfigWidget *widget = new QgsLabelEngineConfigWidget();
connect( widget, &QgsLabelEngineConfigWidget::widgetChanged, widget, &QgsLabelEngineConfigWidget::apply );
panel->openPanel( widget );
}
else
{
QgsLabelEngineConfigDialog dialog( this );
dialog.exec();
// reactivate button's window
activateWindow();
}
}
@@ -752,8 +752,20 @@ void QgsDiagramProperties::mDiagramAttributesTreeWidget_itemDoubleClicked( QTree

void QgsDiagramProperties::mEngineSettingsButton_clicked()
{
QgsLabelEngineConfigDialog dlg( this );
dlg.exec();
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsLabelEngineConfigWidget *widget = new QgsLabelEngineConfigWidget();
connect( widget, &QgsLabelEngineConfigWidget::widgetChanged, widget, &QgsLabelEngineConfigWidget::apply );
panel->openPanel( widget );
}
else
{
QgsLabelEngineConfigDialog dialog( this );
dialog.exec();
// reactivate button's window
activateWindow();
}
}

void QgsDiagramProperties::apply()
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QgsLabelEngineConfigDialog</class>
<widget class="QDialog" name="QgsLabelEngineConfigDialog">
<widget class="QgsPanelWidget" name="QgsLabelEngineConfigDialog">
<property name="geometry">
<rect>
<x>0</x>
@@ -47,7 +47,7 @@
</size>
</property>
<property name="title">
<string>Number of candidates</string>
<string>Number of Candidates</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
@@ -271,16 +271,6 @@
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@@ -290,6 +280,12 @@
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsPanelWidget</class>
<extends>QWidget</extends>
<header>qgspanelwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>spinCandPoint</tabstop>
@@ -303,22 +299,5 @@
<tabstop>chkShowCandidates</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>QgsLabelEngineConfigDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>

0 comments on commit 16b981c

Please sign in to comment.
You can’t perform that action at this time.