mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-28 00:17:30 -05:00
Restore ui for configuring labels
This commit is contained in:
parent
83f177c1d2
commit
585a8b70ba
@ -80,6 +80,10 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
|
||||
UndoPictureStrokeColor,
|
||||
UndoPictureStrokeWidth,
|
||||
UndoPictureNorthOffset,
|
||||
UndoLabelText,
|
||||
UndoLabelFont,
|
||||
UndoLabelMargin,
|
||||
UndoLabelFontColor,
|
||||
UndoCustomCommand,
|
||||
};
|
||||
|
||||
|
@ -50,6 +50,14 @@ class QgsLayoutItemLabel: QgsLayoutItem
|
||||
void adjustSizeToText();
|
||||
%Docstring
|
||||
Resizes the item so that the label's text fits to the item. Keeps the top left point stationary.
|
||||
.. seealso:: sizeForText()
|
||||
%End
|
||||
|
||||
QSizeF sizeForText() const;
|
||||
%Docstring
|
||||
Returns the required item size (in layout units) for the label's text to fill the item.
|
||||
.. seealso:: adjustSizeToText()
|
||||
:rtype: QSizeF
|
||||
%End
|
||||
|
||||
QString text();
|
||||
|
@ -179,6 +179,7 @@ SET(QGIS_APP_SRCS
|
||||
layout/qgslayoutguidewidget.cpp
|
||||
layout/qgslayoutitemslistview.cpp
|
||||
layout/qgslayoutappmenuprovider.cpp
|
||||
layout/qgslayoutlabelwidget.cpp
|
||||
layout/qgslayoutmapwidget.cpp
|
||||
layout/qgslayoutmapgridwidget.cpp
|
||||
layout/qgslayoutpagepropertieswidget.cpp
|
||||
@ -381,6 +382,7 @@ SET (QGIS_APP_MOC_HDRS
|
||||
layout/qgslayoutdesignerdialog.h
|
||||
layout/qgslayoutguidewidget.h
|
||||
layout/qgslayoutitemslistview.h
|
||||
layout/qgslayoutlabelwidget.h
|
||||
layout/qgslayoutmapwidget.h
|
||||
layout/qgslayoutmapgridwidget.h
|
||||
layout/qgslayoutpagepropertieswidget.h
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include "qgslayoutpolylinewidget.h"
|
||||
#include "qgslayoutpicturewidget.h"
|
||||
#include "qgslayoutitempicture.h"
|
||||
#include "qgslayoutitemlabel.h"
|
||||
#include "qgslayoutlabelwidget.h"
|
||||
#include "qgisapp.h"
|
||||
#include "qgsmapcanvas.h"
|
||||
|
||||
@ -83,6 +85,31 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
|
||||
}, createRubberBand ) );
|
||||
|
||||
|
||||
// label item
|
||||
|
||||
auto labelItemMetadata = qgis::make_unique< QgsLayoutItemGuiMetadata >( QgsLayoutItemRegistry::LayoutLabel, QObject::tr( "Label" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionLabel.svg" ) ),
|
||||
[ = ]( QgsLayoutItem * item )->QgsLayoutItemBaseWidget *
|
||||
{
|
||||
return new QgsLayoutLabelWidget( qobject_cast< QgsLayoutItemLabel * >( item ) );
|
||||
}, createRubberBand );
|
||||
labelItemMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )
|
||||
{
|
||||
QgsLayoutItemLabel *label = qobject_cast< QgsLayoutItemLabel * >( item );
|
||||
Q_ASSERT( label );
|
||||
|
||||
label->setText( QObject::tr( "Lorem ipsum" ) );
|
||||
QSizeF minSize = label->sizeForText();
|
||||
QSizeF currentSize = label->rect().size();
|
||||
|
||||
//make sure label size is sufficient to fit text
|
||||
double labelWidth = std::max( minSize.width(), currentSize.width() );
|
||||
double labelHeight = std::max( minSize.height(), currentSize.height() );
|
||||
label->attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
|
||||
} );
|
||||
|
||||
registry->addLayoutItemGuiMetadata( labelItemMetadata.release() );
|
||||
|
||||
|
||||
// shape items
|
||||
|
||||
auto createShapeWidget =
|
||||
|
324
src/app/layout/qgslayoutlabelwidget.cpp
Normal file
324
src/app/layout/qgslayoutlabelwidget.cpp
Normal file
@ -0,0 +1,324 @@
|
||||
/***************************************************************************
|
||||
qgslayoutlabelwidget.cpp
|
||||
------------------------
|
||||
begin : October 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* 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 "qgslayoutlabelwidget.h"
|
||||
#include "qgslayoutitemlabel.h"
|
||||
#include "qgslayout.h"
|
||||
#include "qgsexpressionbuilderdialog.h"
|
||||
#include "qgsguiutils.h"
|
||||
|
||||
#include <QColorDialog>
|
||||
#include <QFontDialog>
|
||||
#include <QWidget>
|
||||
|
||||
QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
|
||||
: QgsLayoutItemBaseWidget( nullptr, label )
|
||||
, mLabel( label )
|
||||
{
|
||||
setupUi( this );
|
||||
connect( mHtmlCheckBox, &QCheckBox::stateChanged, this, &QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged );
|
||||
connect( mTextEdit, &QPlainTextEdit::textChanged, this, &QgsLayoutLabelWidget::mTextEdit_textChanged );
|
||||
connect( mInsertExpressionButton, &QPushButton::clicked, this, &QgsLayoutLabelWidget::mInsertExpressionButton_clicked );
|
||||
connect( mMarginXDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged );
|
||||
connect( mMarginYDoubleSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutLabelWidget::mMarginYDoubleSpinBox_valueChanged );
|
||||
connect( mFontColorButton, &QgsColorButton::colorChanged, this, &QgsLayoutLabelWidget::mFontColorButton_colorChanged );
|
||||
connect( mCenterRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mCenterRadioButton_clicked );
|
||||
connect( mLeftRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mLeftRadioButton_clicked );
|
||||
connect( mRightRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mRightRadioButton_clicked );
|
||||
connect( mTopRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mTopRadioButton_clicked );
|
||||
connect( mBottomRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mBottomRadioButton_clicked );
|
||||
connect( mMiddleRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::mMiddleRadioButton_clicked );
|
||||
setPanelTitle( tr( "Label properties" ) );
|
||||
|
||||
mFontButton->setMode( QgsFontButton::ModeQFont );
|
||||
|
||||
//add widget for general composer item properties
|
||||
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, label );
|
||||
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget
|
||||
mainLayout->addWidget( mItemPropertiesWidget );
|
||||
|
||||
mFontColorButton->setColorDialogTitle( tr( "Select Font Color" ) );
|
||||
mFontColorButton->setContext( QStringLiteral( "composer" ) );
|
||||
|
||||
mMarginXDoubleSpinBox->setClearValue( 0.0 );
|
||||
mMarginYDoubleSpinBox->setClearValue( 0.0 );
|
||||
|
||||
if ( mLabel )
|
||||
{
|
||||
setGuiElementValues();
|
||||
connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
|
||||
}
|
||||
|
||||
connect( mFontButton, &QgsFontButton::changed, this, &QgsLayoutLabelWidget::fontChanged );
|
||||
connect( mJustifyRadioButton, &QRadioButton::clicked, this, &QgsLayoutLabelWidget::justifyClicked );
|
||||
}
|
||||
|
||||
bool QgsLayoutLabelWidget::setNewItem( QgsLayoutItem *item )
|
||||
{
|
||||
if ( item->type() != QgsLayoutItemRegistry::LayoutLabel )
|
||||
return false;
|
||||
|
||||
if ( mLabel )
|
||||
{
|
||||
disconnect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
|
||||
}
|
||||
|
||||
mLabel = qobject_cast< QgsLayoutItemLabel * >( item );
|
||||
mItemPropertiesWidget->setItem( mLabel );
|
||||
|
||||
if ( mLabel )
|
||||
{
|
||||
connect( mLabel, &QgsLayoutObject::changed, this, &QgsLayoutLabelWidget::setGuiElementValues );
|
||||
}
|
||||
|
||||
setGuiElementValues();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mHtmlCheckBox_stateChanged( int state )
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mVerticalAlignementLabel->setDisabled( state );
|
||||
mTopRadioButton->setDisabled( state );
|
||||
mMiddleRadioButton->setDisabled( state );
|
||||
mBottomRadioButton->setDisabled( state );
|
||||
|
||||
mLabel->beginCommand( tr( "Change Label Mode" ) );
|
||||
mLabel->blockSignals( true );
|
||||
mLabel->setMode( state ? QgsLayoutItemLabel::ModeHtml : QgsLayoutItemLabel::ModeFont );
|
||||
mLabel->setText( mTextEdit->toPlainText() );
|
||||
mLabel->update();
|
||||
mLabel->blockSignals( false );
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mTextEdit_textChanged()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Text" ), QgsLayoutItem::UndoLabelText );
|
||||
mLabel->blockSignals( true );
|
||||
mLabel->setText( mTextEdit->toPlainText() );
|
||||
mLabel->update();
|
||||
mLabel->blockSignals( false );
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::fontChanged()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
QFont newFont = mFontButton->currentFont();
|
||||
mLabel->beginCommand( tr( "Change Label Font" ), QgsLayoutItem::UndoLabelFont );
|
||||
mLabel->setFont( newFont );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::justifyClicked()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Alignment" ) );
|
||||
mLabel->setHAlign( Qt::AlignJustify );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mMarginXDoubleSpinBox_valueChanged( double d )
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Margin" ), QgsLayoutItem::UndoLabelMargin );
|
||||
mLabel->setMarginX( d );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mMarginYDoubleSpinBox_valueChanged( double d )
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Margin" ), QgsLayoutItem::UndoLabelMargin );
|
||||
mLabel->setMarginY( d );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mFontColorButton_colorChanged( const QColor &newLabelColor )
|
||||
{
|
||||
if ( !mLabel )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
mLabel->beginCommand( tr( "Change Label Color" ), QgsLayoutItem::UndoLabelFontColor );
|
||||
mLabel->setFontColor( newLabelColor );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mInsertExpressionButton_clicked()
|
||||
{
|
||||
if ( !mLabel )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString selText = mTextEdit->textCursor().selectedText();
|
||||
|
||||
// edit the selected expression if there's one
|
||||
if ( selText.startsWith( QLatin1String( "[%" ) ) && selText.endsWith( QLatin1String( "%]" ) ) )
|
||||
selText = selText.mid( 2, selText.size() - 4 );
|
||||
|
||||
// use the atlas coverage layer, if any
|
||||
#if 0 //TODO
|
||||
QgsVectorLayer *coverageLayer = atlasCoverageLayer();
|
||||
#endif
|
||||
QgsVectorLayer *coverageLayer = nullptr;
|
||||
|
||||
QgsExpressionContext context = mLabel->createExpressionContext();
|
||||
QgsExpressionBuilderDialog exprDlg( coverageLayer, selText, this, QStringLiteral( "generic" ), context );
|
||||
|
||||
exprDlg.setWindowTitle( tr( "Insert Expression" ) );
|
||||
if ( exprDlg.exec() == QDialog::Accepted )
|
||||
{
|
||||
QString expression = exprDlg.expressionText();
|
||||
if ( !expression.isEmpty() )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Insert expression" ) );
|
||||
mTextEdit->insertPlainText( "[%" + expression + "%]" );
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mCenterRadioButton_clicked()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Alignment" ) );
|
||||
mLabel->setHAlign( Qt::AlignHCenter );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mRightRadioButton_clicked()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Alignment" ) );
|
||||
mLabel->setHAlign( Qt::AlignRight );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mLeftRadioButton_clicked()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Alignment" ) );
|
||||
mLabel->setHAlign( Qt::AlignLeft );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mTopRadioButton_clicked()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Alignment" ) );
|
||||
mLabel->setVAlign( Qt::AlignTop );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mBottomRadioButton_clicked()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Alignment" ) );
|
||||
mLabel->setVAlign( Qt::AlignBottom );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::mMiddleRadioButton_clicked()
|
||||
{
|
||||
if ( mLabel )
|
||||
{
|
||||
mLabel->beginCommand( tr( "Change Label Alignment" ) );
|
||||
mLabel->setVAlign( Qt::AlignVCenter );
|
||||
mLabel->update();
|
||||
mLabel->endCommand();
|
||||
}
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::setGuiElementValues()
|
||||
{
|
||||
blockAllSignals( true );
|
||||
mTextEdit->setPlainText( mLabel->text() );
|
||||
mTextEdit->moveCursor( QTextCursor::End, QTextCursor::MoveAnchor );
|
||||
mMarginXDoubleSpinBox->setValue( mLabel->marginX() );
|
||||
mMarginYDoubleSpinBox->setValue( mLabel->marginY() );
|
||||
mHtmlCheckBox->setChecked( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
|
||||
mTopRadioButton->setChecked( mLabel->vAlign() == Qt::AlignTop );
|
||||
mMiddleRadioButton->setChecked( mLabel->vAlign() == Qt::AlignVCenter );
|
||||
mBottomRadioButton->setChecked( mLabel->vAlign() == Qt::AlignBottom );
|
||||
mLeftRadioButton->setChecked( mLabel->hAlign() == Qt::AlignLeft );
|
||||
mJustifyRadioButton->setChecked( mLabel->hAlign() == Qt::AlignJustify );
|
||||
mCenterRadioButton->setChecked( mLabel->hAlign() == Qt::AlignHCenter );
|
||||
mRightRadioButton->setChecked( mLabel->hAlign() == Qt::AlignRight );
|
||||
mFontColorButton->setColor( mLabel->fontColor() );
|
||||
mFontButton->setCurrentFont( mLabel->font() );
|
||||
mVerticalAlignementLabel->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
|
||||
mTopRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
|
||||
mMiddleRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
|
||||
mBottomRadioButton->setDisabled( mLabel->mode() == QgsLayoutItemLabel::ModeHtml );
|
||||
|
||||
blockAllSignals( false );
|
||||
}
|
||||
|
||||
void QgsLayoutLabelWidget::blockAllSignals( bool block )
|
||||
{
|
||||
mTextEdit->blockSignals( block );
|
||||
mHtmlCheckBox->blockSignals( block );
|
||||
mMarginXDoubleSpinBox->blockSignals( block );
|
||||
mMarginYDoubleSpinBox->blockSignals( block );
|
||||
mTopRadioButton->blockSignals( block );
|
||||
mMiddleRadioButton->blockSignals( block );
|
||||
mBottomRadioButton->blockSignals( block );
|
||||
mLeftRadioButton->blockSignals( block );
|
||||
mCenterRadioButton->blockSignals( block );
|
||||
mRightRadioButton->blockSignals( block );
|
||||
mJustifyRadioButton->blockSignals( block );
|
||||
mFontColorButton->blockSignals( block );
|
||||
mFontButton->blockSignals( block );
|
||||
}
|
65
src/app/layout/qgslayoutlabelwidget.h
Normal file
65
src/app/layout/qgslayoutlabelwidget.h
Normal file
@ -0,0 +1,65 @@
|
||||
/***************************************************************************
|
||||
qgslayoutlabelwidget.h
|
||||
----------------------
|
||||
begin : October 2017
|
||||
copyright : (C) 2017 by Nyall Dawson
|
||||
email : nyall dot dawson at gmail dot com
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* 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. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef QGSLAYOUTLABELWIDGET_H
|
||||
#define QGSLAYOUTLABELWIDGET_H
|
||||
|
||||
#include "ui_qgslayoutlabelwidgetbase.h"
|
||||
#include "qgslayoutitemwidget.h"
|
||||
|
||||
class QgsLayoutItemLabel;
|
||||
|
||||
/**
|
||||
* \ingroup app
|
||||
* A widget for layout item settings.
|
||||
*/
|
||||
class QgsLayoutLabelWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutLabelWidgetBase
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QgsLayoutLabelWidget( QgsLayoutItemLabel *label );
|
||||
|
||||
protected:
|
||||
|
||||
bool setNewItem( QgsLayoutItem *item ) override;
|
||||
|
||||
private slots:
|
||||
void mHtmlCheckBox_stateChanged( int i );
|
||||
void mTextEdit_textChanged();
|
||||
void mInsertExpressionButton_clicked();
|
||||
void mMarginXDoubleSpinBox_valueChanged( double d );
|
||||
void mMarginYDoubleSpinBox_valueChanged( double d );
|
||||
void mFontColorButton_colorChanged( const QColor &newLabelColor );
|
||||
void mCenterRadioButton_clicked();
|
||||
void mLeftRadioButton_clicked();
|
||||
void mRightRadioButton_clicked();
|
||||
void mTopRadioButton_clicked();
|
||||
void mBottomRadioButton_clicked();
|
||||
void mMiddleRadioButton_clicked();
|
||||
void setGuiElementValues();
|
||||
void fontChanged();
|
||||
void justifyClicked();
|
||||
|
||||
private:
|
||||
QgsLayoutItemLabel *mLabel = nullptr;
|
||||
|
||||
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr;
|
||||
|
||||
void blockAllSignals( bool block );
|
||||
};
|
||||
|
||||
#endif //QGSLAYOUTLABELWIDGET_H
|
@ -113,6 +113,10 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt
|
||||
UndoPictureStrokeColor, //!< Picture stroke color
|
||||
UndoPictureStrokeWidth, //!< Picture stroke width
|
||||
UndoPictureNorthOffset, //!< Picture north offset
|
||||
UndoLabelText, //!< Label text
|
||||
UndoLabelFont, //!< Label font
|
||||
UndoLabelMargin, //!< Label margin
|
||||
UndoLabelFontColor, //!< Label color
|
||||
UndoCustomCommand, //!< Base id for plugin based item undo commands
|
||||
};
|
||||
|
||||
|
@ -332,6 +332,20 @@ void QgsLayoutItemLabel::setMarginY( const double margin )
|
||||
}
|
||||
|
||||
void QgsLayoutItemLabel::adjustSizeToText()
|
||||
{
|
||||
QSizeF newSize = sizeForText();
|
||||
|
||||
//keep alignment point constant
|
||||
double xShift = 0;
|
||||
double yShift = 0;
|
||||
|
||||
itemShiftAdjustSize( newSize.width(), newSize.height(), xShift, yShift );
|
||||
|
||||
//update rect for data defined size and position
|
||||
attemptSetSceneRect( QRectF( pos().x() + xShift, pos().y() + yShift, newSize.width(), newSize.height() ) );
|
||||
}
|
||||
|
||||
QSizeF QgsLayoutItemLabel::sizeForText() const
|
||||
{
|
||||
double textWidth = QgsLayoutUtils::textWidthMM( mFont, currentText() );
|
||||
double fontHeight = QgsLayoutUtils::fontHeightMM( mFont );
|
||||
@ -341,15 +355,7 @@ void QgsLayoutItemLabel::adjustSizeToText()
|
||||
double width = textWidth + 2 * mMarginX + 2 * penWidth + 1;
|
||||
double height = fontHeight + 2 * mMarginY + 2 * penWidth;
|
||||
|
||||
//keep alignment point constant
|
||||
double xShift = 0;
|
||||
double yShift = 0;
|
||||
|
||||
QSizeF newSize = mLayout->convertToLayoutUnits( QgsLayoutSize( width, height, QgsUnitTypes::LayoutMillimeters ) );
|
||||
itemShiftAdjustSize( newSize.width(), newSize.height(), xShift, yShift );
|
||||
|
||||
//update rect for data defined size and position
|
||||
attemptSetSceneRect( QRectF( pos().x() + xShift, pos().y() + yShift, width, height ) );
|
||||
return mLayout->convertToLayoutUnits( QgsLayoutSize( width, height, QgsUnitTypes::LayoutMillimeters ) );
|
||||
}
|
||||
|
||||
QFont QgsLayoutItemLabel::font() const
|
||||
|
@ -64,9 +64,16 @@ class CORE_EXPORT QgsLayoutItemLabel: public QgsLayoutItem
|
||||
|
||||
/**
|
||||
* Resizes the item so that the label's text fits to the item. Keeps the top left point stationary.
|
||||
* \see sizeForText()
|
||||
*/
|
||||
void adjustSizeToText();
|
||||
|
||||
/**
|
||||
* Returns the required item size (in layout units) for the label's text to fill the item.
|
||||
* \see adjustSizeToText()
|
||||
*/
|
||||
QSizeF sizeForText() const;
|
||||
|
||||
/**
|
||||
* Returns the label's preset text.
|
||||
* \see currentText()
|
||||
|
@ -53,7 +53,7 @@ bool QgsLayoutItemRegistry::populate()
|
||||
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPage, QStringLiteral( "Page" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionFileNew.svg" ) ), QgsLayoutItemPage::create ) );
|
||||
addLayoutItemType( new QgsLayoutItemMetadata( LayoutMap, QStringLiteral( "Map" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddMap.svg" ) ), QgsLayoutItemMap::create ) );
|
||||
addLayoutItemType( new QgsLayoutItemMetadata( LayoutPicture, QStringLiteral( "Picture" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddImage.svg" ) ), QgsLayoutItemPicture::create ) );
|
||||
addLayoutItemType( new QgsLayoutItemMetadata( LayoutLabel, QStringLiteral( "Label" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddLabel.svg" ) ), QgsLayoutItemLabel::create ) );
|
||||
addLayoutItemType( new QgsLayoutItemMetadata( LayoutLabel, QStringLiteral( "Label" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionLabel.svg" ) ), QgsLayoutItemLabel::create ) );
|
||||
addLayoutItemType( new QgsLayoutItemMetadata( LayoutShape, QStringLiteral( "Shape" ), QgsApplication::getThemeIcon( QStringLiteral( "/mActionAddBasicRectangle.svg" ) ), []( QgsLayout * layout )
|
||||
{
|
||||
QgsLayoutItemShape *shape = new QgsLayoutItemShape( layout );
|
||||
|
391
src/ui/layout/qgslayoutlabelwidgetbase.ui
Normal file
391
src/ui/layout/qgslayoutlabelwidgetbase.ui
Normal file
@ -0,0 +1,391 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>QgsLayoutLabelWidgetBase</class>
|
||||
<widget class="QWidget" name="QgsLayoutLabelWidgetBase">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>304</width>
|
||||
<height>705</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Label Options</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="_2">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">padding: 2px; font-weight: bold; background-color: rgb(200, 200, 200);</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QgsScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>446</width>
|
||||
<height>665</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<item>
|
||||
<widget class="QgsCollapsibleGroupBoxBasic" name="mTextGroupBox">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Main properties</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="syncGroup" stdset="0">
|
||||
<string notr="true">composeritem</string>
|
||||
</property>
|
||||
<property name="collapsed" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPlainTextEdit" name="mTextEdit">
|
||||
<property name="tabStopWidth">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="mHtmlCheckBox">
|
||||
<property name="text">
|
||||
<string>Render as HTML</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QPushButton" name="mInsertExpressionButton">
|
||||
<property name="text">
|
||||
<string>Insert an expression...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QgsCollapsibleGroupBoxBasic" name="mAppearanceGroup">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Appearance</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="syncGroup" stdset="0">
|
||||
<string notr="true">composeritem</string>
|
||||
</property>
|
||||
<property name="collapsed" stdset="0">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0" colspan="2">
|
||||
<widget class="QLabel" name="mHorizontalAlignementLabel">
|
||||
<property name="text">
|
||||
<string>Horizontal alignment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QgsDoubleSpinBox" name="mMarginYDoubleSpinBox">
|
||||
<property name="suffix">
|
||||
<string> mm</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-99.989999999999995</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
<widget class="QRadioButton" name="mTopRadioButton">
|
||||
<property name="text">
|
||||
<string>Top</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="mMiddleRadioButton">
|
||||
<property name="text">
|
||||
<string>Middle</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="mBottomRadioButton">
|
||||
<property name="text">
|
||||
<string>Bottom</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="mMarginYLabel">
|
||||
<property name="text">
|
||||
<string>Vertical margin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="mMarginXLabel">
|
||||
<property name="text">
|
||||
<string>Horizontal margin</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QgsDoubleSpinBox" name="mMarginXDoubleSpinBox">
|
||||
<property name="prefix">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="suffix">
|
||||
<string> mm</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-99.989999999999995</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Font color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<widget class="QRadioButton" name="mLeftRadioButton">
|
||||
<property name="text">
|
||||
<string>Left</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup_2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QRadioButton" name="mJustifyRadioButton">
|
||||
<property name="text">
|
||||
<string>Justify</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup_2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QRadioButton" name="mRightRadioButton">
|
||||
<property name="text">
|
||||
<string>Right</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup_2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QRadioButton" name="mCenterRadioButton">
|
||||
<property name="text">
|
||||
<string>Center</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">buttonGroup_2</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="7" column="0" colspan="2">
|
||||
<widget class="QLabel" name="mVerticalAlignementLabel">
|
||||
<property name="text">
|
||||
<string>Vertical alignment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="QgsFontButton" name="mFontButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Font</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QgsColorButton" name="mFontColorButton">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>120</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QgsScrollArea</class>
|
||||
<extends>QScrollArea</extends>
|
||||
<header>qgsscrollarea.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsColorButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>qgscolorbutton.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsCollapsibleGroupBoxBasic</class>
|
||||
<extends>QGroupBox</extends>
|
||||
<header>qgscollapsiblegroupbox.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsDoubleSpinBox</class>
|
||||
<extends>QDoubleSpinBox</extends>
|
||||
<header>qgsdoublespinbox.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QgsFontButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>qgsfontbutton.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>scrollArea</tabstop>
|
||||
<tabstop>mTextGroupBox</tabstop>
|
||||
<tabstop>mTextEdit</tabstop>
|
||||
<tabstop>mHtmlCheckBox</tabstop>
|
||||
<tabstop>mInsertExpressionButton</tabstop>
|
||||
<tabstop>mAppearanceGroup</tabstop>
|
||||
<tabstop>mFontButton</tabstop>
|
||||
<tabstop>mFontColorButton</tabstop>
|
||||
<tabstop>mMarginXDoubleSpinBox</tabstop>
|
||||
<tabstop>mMarginYDoubleSpinBox</tabstop>
|
||||
<tabstop>mLeftRadioButton</tabstop>
|
||||
<tabstop>mCenterRadioButton</tabstop>
|
||||
<tabstop>mRightRadioButton</tabstop>
|
||||
<tabstop>mTopRadioButton</tabstop>
|
||||
<tabstop>mMiddleRadioButton</tabstop>
|
||||
<tabstop>mBottomRadioButton</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
<buttongroups>
|
||||
<buttongroup name="buttonGroup"/>
|
||||
<buttongroup name="buttonGroup_2"/>
|
||||
</buttongroups>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user