Skip to content
Permalink
Browse files

Add a simple dialog for configuring text formatting

  • Loading branch information
nyalldawson committed Oct 24, 2016
1 parent 4282474 commit 8fa8167d7bab0aee262f8b779360a34693732965
@@ -14,7 +14,7 @@
* @note Added in QGIS 3.0
*/

class QgsTextFormatWidget : public QgsPanelWidget
class QgsTextFormatWidget : QWidget
{
%TypeHeaderCode
#include <qgstextformatwidget.h>
@@ -86,3 +86,36 @@ class QgsTextFormatWidget : public QgsPanelWidget
//! Updates label placement options to reflect current state of widget
void updatePlacementWidgets();
};

/** \class QgsTextFormatDialog
* \ingroup gui
* A simple dialog for customising text formatting settings.
*
* QgsTextFormatDialog provides a dialog for controlling the appearance of text rendered
* using QgsTextRenderer. The dialog includes all settings contained within
* a QgsTextFormat, including shadow, background and buffer.
*
* @note Added in QGIS 3.0
*/

class QgsTextFormatDialog : QDialog
{
%TypeHeaderCode
#include <qgstextformatwidget.h>
%End
public:

/** Constructor for QgsTextFormatDialog.
* @param format initial format settings to show in dialog
* @param mapCanvas optional associated map canvas
* @param parent parent widget
* @param fl window flags for dialog
*/
QgsTextFormatDialog( const QgsTextFormat& format, QgsMapCanvas* mapCanvas = nullptr, QWidget* parent /TransferThis/ = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );

virtual ~QgsTextFormatDialog();

/** Returns the current formatting settings defined by the widget.
*/
QgsTextFormat format() const;
};
@@ -1376,3 +1376,40 @@ void QgsTextFormatWidget::enableDataDefinedAlignment( bool enable )
}


//
// QgsTextFormatDialog
//

QgsTextFormatDialog::QgsTextFormatDialog( const QgsTextFormat& format, QgsMapCanvas* mapCanvas, QWidget* parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
setWindowTitle( tr( "Text settings" ) );

mFormatWidget = new QgsTextFormatWidget( format, mapCanvas, this );
mFormatWidget->layout()->setContentsMargins( 0, 0, 0, 0 );

QVBoxLayout *layout = new QVBoxLayout( this );
layout->addWidget( mFormatWidget );

QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this );
layout->addWidget( buttonBox );

setLayout( layout );

QSettings settings;
restoreGeometry( settings.value( "/Windows/TextFormatDialog/geometry" ).toByteArray() );

connect( buttonBox->button( QDialogButtonBox::Ok ), SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( buttonBox->button( QDialogButtonBox::Cancel ), SIGNAL( clicked() ), this, SLOT( reject() ) );
}

QgsTextFormatDialog::~QgsTextFormatDialog()
{
QSettings settings;
settings.setValue( "/Windows/TextFormatDialog/geometry", saveGeometry() );
}

QgsTextFormat QgsTextFormatDialog::format() const
{
return mFormatWidget->format();
}
@@ -20,6 +20,7 @@
#include <ui_qgstextformatwidgetbase.h>
#include "qgstextrenderer.h"
#include "qgsstringutils.h"
#include "qgisgui.h"
#include <QFontDatabase>

class QgsMapCanvas;
@@ -31,7 +32,7 @@ class QgsCharacterSelectorDialog;
* A widget for customising text formatting settings.
*
* QgsTextFormatWidget provides a widget for controlling the appearance of text rendered
* using QgsTextRenderer. The preview includes all settings contained within
* using QgsTextRenderer. The widget includes all settings contained within
* a QgsTextFormat, including shadow, background and buffer.
*
* Additionally, the widget can handle labeling settings due to the large overlap between
@@ -193,6 +194,43 @@ class GUI_EXPORT QgsTextFormatWidget : public QWidget, protected Ui::QgsTextForm
void updateSvgWidgets( const QString& svgPath );
};


/** \class QgsTextFormatDialog
* \ingroup gui
* A simple dialog for customising text formatting settings.
*
* QgsTextFormatDialog provides a dialog for controlling the appearance of text rendered
* using QgsTextRenderer. The dialog includes all settings contained within
* a QgsTextFormat, including shadow, background and buffer.
*
* @note Added in QGIS 3.0
*/

class GUI_EXPORT QgsTextFormatDialog : public QDialog
{
Q_OBJECT

public:

/** Constructor for QgsTextFormatDialog.
* @param format initial format settings to show in dialog
* @param mapCanvas optional associated map canvas
* @param parent parent widget
* @param fl window flags for dialog
*/
QgsTextFormatDialog( const QgsTextFormat& format, QgsMapCanvas* mapCanvas = nullptr, QWidget* parent = nullptr, Qt::WindowFlags fl = QgisGui::ModalDialogFlags );

virtual ~QgsTextFormatDialog();

/** Returns the current formatting settings defined by the widget.
*/
QgsTextFormat format() const;

private:

QgsTextFormatWidget* mFormatWidget;
};

#endif //QGSTEXTFORMATWIDGET_H


@@ -21,7 +21,7 @@
QgsTextFormat,
QgsUnitTypes,
QgsMapUnitScale)
from qgis.gui import (QgsTextFormatWidget)
from qgis.gui import (QgsTextFormatWidget, QgsTextFormatDialog)
from qgis.PyQt.QtGui import (QColor, QPainter, QFont, QImage, QBrush, QPen)
from qgis.PyQt.QtCore import (Qt, QSizeF, QPointF, QRectF, QDir)
from qgis.testing import unittest, start_app
@@ -184,6 +184,11 @@ def testSettings(self):
w = QgsTextFormatWidget(s)
self.checkTextFormat(w.format())

def testDialogSettings(self):
# test that dialog correctly sets and returns matching settings
s = self.createFormatSettings()
d = QgsTextFormatDialog(s)
self.checkTextFormat(d.format())

if __name__ == '__main__':
unittest.main()

0 comments on commit 8fa8167

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