Skip to content
Permalink
Browse files

When setting a new text format for a QgsFontButton, automatically

update any open configuration panel to reflect the new format
(or dismiss it automatically if the new format is invalid)

Avoids UI going out of sync with text formats when a panel is already
open
  • Loading branch information
nyalldawson committed Jul 27, 2020
1 parent 7cfa476 commit 466a01ca6d6faa846f95e0e4bd193f27650d15ec
@@ -9,6 +9,7 @@




class QgsFontButton : QToolButton
{
%Docstring
@@ -277,6 +277,13 @@ Constructor for QgsTextFormatPanelWidget.
QgsTextFormat format() const;
%Docstring
Returns the current formatting settings defined by the widget.
%End

void setFormat( const QgsTextFormat &format );
%Docstring
Sets the ``format`` to show in the widget.

.. versionadded:: 3.16
%End

void setContext( const QgsSymbolWidgetContext &context );
@@ -94,12 +94,12 @@ void QgsFontButton::showSettingsDialog()
QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
if ( panel && panel->dockMode() )
{
QgsTextFormatPanelWidget *formatWidget = new QgsTextFormatPanelWidget( mFormat, mMapCanvas, this, mLayer.data() );
formatWidget->setPanelTitle( mDialogTitle );
formatWidget->setContext( symbolContext );
mActivePanel = new QgsTextFormatPanelWidget( mFormat, mMapCanvas, this, mLayer.data() );
mActivePanel->setPanelTitle( mDialogTitle );
mActivePanel->setContext( symbolContext );

connect( formatWidget, &QgsTextFormatPanelWidget::widgetChanged, this, [ this, formatWidget ] { this->setTextFormat( formatWidget->format() ); } );
panel->openPanel( formatWidget );
connect( mActivePanel, &QgsTextFormatPanelWidget::widgetChanged, this, [ this ] { setTextFormat( mActivePanel->format() ); } );
panel->openPanel( mActivePanel );
return;
}

@@ -154,8 +154,14 @@ QgsMessageBar *QgsFontButton::messageBar() const

void QgsFontButton::setTextFormat( const QgsTextFormat &format )
{
if ( mActivePanel && !format.isValid() )
mActivePanel->acceptPanel();

mFormat = format;
updatePreview();

if ( mActivePanel && format.isValid() )
mActivePanel->setFormat( format );
emit changed();
}

@@ -24,6 +24,8 @@
class QgsExpressionContextGenerator;
class QgsMapCanvas;
class QgsMessageBar;
class QgsTextFormatPanelWidget;


/**
* \ingroup gui
@@ -329,6 +331,7 @@ class GUI_EXPORT QgsFontButton : public QToolButton
bool mShowNoFormat = false;
QString mNullFormatString;
QPointer< QAction > mNullFormatAction;
QPointer< QgsTextFormatPanelWidget > mActivePanel;

/**
* Attempts to parse \a mimeData as a text format.
@@ -2036,14 +2036,25 @@ QgsTextFormatPanelWidget::QgsTextFormatPanelWidget( const QgsTextFormat &format,
: QgsPanelWidgetWrapper( new QgsTextFormatWidget( format, mapCanvas, nullptr, layer ), parent )
{
mFormatWidget = qobject_cast< QgsTextFormatWidget * >( widget() );
connect( mFormatWidget, &QgsTextFormatWidget::widgetChanged, this, &QgsPanelWidget::widgetChanged );
connect( mFormatWidget, &QgsTextFormatWidget::widgetChanged, this, [ = ]
{
if ( !mBlockSignals )
emit widgetChanged();
} );
}

QgsTextFormat QgsTextFormatPanelWidget::format() const
{
return mFormatWidget->format();
}

void QgsTextFormatPanelWidget::setFormat( const QgsTextFormat &format )
{
mBlockSignals = true;
mFormatWidget->setFormat( format );
mBlockSignals = false;
}

void QgsTextFormatPanelWidget::setContext( const QgsSymbolWidgetContext &context )
{
mFormatWidget->setContext( context );
@@ -395,6 +395,13 @@ class GUI_EXPORT QgsTextFormatPanelWidget : public QgsPanelWidgetWrapper
*/
QgsTextFormat format() const;

/**
* Sets the \a format to show in the widget.
*
* \since QGIS 3.16
*/
void setFormat( const QgsTextFormat &format );

/**
* Sets the \a context in which the widget is shown, e.g., the associated map canvas and expression contexts.
* \since QGIS 3.10
@@ -406,6 +413,7 @@ class GUI_EXPORT QgsTextFormatPanelWidget : public QgsPanelWidgetWrapper
private:

QgsTextFormatWidget *mFormatWidget = nullptr;
bool mBlockSignals = false;
};

#endif //QGSTEXTFORMATWIDGET_H

0 comments on commit 466a01c

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