Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7674bd7
commit 2ec31d8
Showing
7 changed files
with
427 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/*************************************************************************** | ||
qgslayoutshapewidget.cpp | ||
-------------------------- | ||
begin : November 2009 | ||
copyright : (C) 2009 by Marco Hugentobler | ||
email : marco@hugis.net | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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 "qgslayoutshapewidget.h" | ||
#include "qgsstyle.h" | ||
#include "qgslayoutitemshape.h" | ||
#include "qgslayout.h" | ||
#include "qgslayoutundostack.h" | ||
|
||
QgsLayoutShapeWidget::QgsLayoutShapeWidget( QgsLayoutItemShape *shape ) | ||
: QgsLayoutItemBaseWidget( nullptr, shape ) | ||
, mShape( shape ) | ||
{ | ||
setupUi( this ); | ||
connect( mShapeComboBox, static_cast<void ( QComboBox::* )( const QString & )>( &QComboBox::currentIndexChanged ), this, &QgsLayoutShapeWidget::mShapeComboBox_currentIndexChanged ); | ||
connect( mCornerRadiusSpinBox, static_cast < void ( QDoubleSpinBox::* )( double ) > ( &QDoubleSpinBox::valueChanged ), this, &QgsLayoutShapeWidget::mCornerRadiusSpinBox_valueChanged ); | ||
setPanelTitle( tr( "Shape properties" ) ); | ||
|
||
//add widget for general composer item properties | ||
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, shape ); | ||
//shapes don't use background or frame, since the symbol style is set through a QgsSymbolSelectorWidget | ||
mItemPropertiesWidget->showBackgroundGroup( false ); | ||
mItemPropertiesWidget->showFrameGroup( false ); | ||
mainLayout->addWidget( mItemPropertiesWidget ); | ||
|
||
blockAllSignals( true ); | ||
|
||
//shape types | ||
mShapeComboBox->addItem( tr( "Rectangle" ), QgsLayoutItemShape::Rectangle ); | ||
mShapeComboBox->addItem( tr( "Ellipse" ), QgsLayoutItemShape::Ellipse ); | ||
mShapeComboBox->addItem( tr( "Triangle" ), QgsLayoutItemShape::Triangle ); | ||
|
||
mShapeStyleButton->setSymbolType( QgsSymbol::Fill ); | ||
mRadiusUnitsComboBox->linkToWidget( mCornerRadiusSpinBox ); | ||
mRadiusUnitsComboBox->setConverter( &mShape->layout()->context().measurementConverter() ); | ||
|
||
setGuiElementValues(); | ||
|
||
blockAllSignals( false ); | ||
|
||
if ( mShape ) | ||
{ | ||
connect( mShape, &QgsLayoutObject::changed, this, &QgsLayoutShapeWidget::setGuiElementValues ); | ||
mShapeStyleButton->registerExpressionContextGenerator( mShape ); | ||
} | ||
connect( mShapeStyleButton, &QgsSymbolButton::changed, this, &QgsLayoutShapeWidget::symbolChanged ); | ||
connect( mRadiusUnitsComboBox, &QgsLayoutUnitsComboBox::changed, this, &QgsLayoutShapeWidget::radiusUnitsChanged ); | ||
|
||
#if 0 //TODO | ||
mShapeStyleButton->setLayer( atlasCoverageLayer() ); | ||
#endif | ||
} | ||
|
||
bool QgsLayoutShapeWidget::setNewItem( QgsLayoutItem *item ) | ||
{ | ||
if ( item->type() != QgsLayoutItemRegistry::LayoutShape ) | ||
return false; | ||
|
||
mShape = qobject_cast< QgsLayoutItemShape * >( item ); | ||
mItemPropertiesWidget->setItem( mShape ); | ||
|
||
setGuiElementValues(); | ||
|
||
return true; | ||
} | ||
|
||
void QgsLayoutShapeWidget::blockAllSignals( bool block ) | ||
{ | ||
mShapeComboBox->blockSignals( block ); | ||
mCornerRadiusSpinBox->blockSignals( block ); | ||
mRadiusUnitsComboBox->blockSignals( block ); | ||
mShapeStyleButton->blockSignals( block ); | ||
} | ||
|
||
void QgsLayoutShapeWidget::setGuiElementValues() | ||
{ | ||
if ( !mShape ) | ||
{ | ||
return; | ||
} | ||
|
||
blockAllSignals( true ); | ||
|
||
mShapeStyleButton->setSymbol( mShape->symbol()->clone() ); | ||
|
||
mCornerRadiusSpinBox->setValue( mShape->cornerRadius().length() ); | ||
mRadiusUnitsComboBox->setUnit( mShape->cornerRadius().units() ); | ||
|
||
mShapeComboBox->setCurrentIndex( mShapeComboBox->findData( mShape->shapeType() ) ); | ||
toggleRadiusSpin( mShape->shapeType() ); | ||
|
||
blockAllSignals( false ); | ||
} | ||
|
||
void QgsLayoutShapeWidget::symbolChanged() | ||
{ | ||
if ( !mShape ) | ||
return; | ||
|
||
mShape->layout()->undoStack()->beginCommand( mShape, tr( "Change Shape Style" ), QgsLayoutItem::UndoShapeStyle ); | ||
mShape->setSymbol( mShapeStyleButton->clonedSymbol<QgsFillSymbol>() ); | ||
mShape->layout()->undoStack()->endCommand(); | ||
} | ||
|
||
void QgsLayoutShapeWidget::mCornerRadiusSpinBox_valueChanged( double val ) | ||
{ | ||
if ( !mShape ) | ||
return; | ||
|
||
mShape->layout()->undoStack()->beginCommand( mShape, tr( "Change Shape Radius" ), QgsLayoutItem::UndoShapeCornerRadius ); | ||
mShape->setCornerRadius( QgsLayoutMeasurement( val, mRadiusUnitsComboBox->unit() ) ); | ||
mShape->layout()->undoStack()->endCommand(); | ||
mShape->update(); | ||
} | ||
|
||
void QgsLayoutShapeWidget::radiusUnitsChanged() | ||
{ | ||
if ( !mShape ) | ||
return; | ||
|
||
mShape->layout()->undoStack()->beginCommand( mShape, tr( "Change Shape Radius" ), QgsLayoutItem::UndoShapeCornerRadius ); | ||
mShape->setCornerRadius( QgsLayoutMeasurement( mCornerRadiusSpinBox->value(), mRadiusUnitsComboBox->unit() ) ); | ||
mShape->layout()->undoStack()->endCommand(); | ||
mShape->update(); | ||
} | ||
|
||
void QgsLayoutShapeWidget::mShapeComboBox_currentIndexChanged( const QString & ) | ||
{ | ||
if ( !mShape ) | ||
{ | ||
return; | ||
} | ||
|
||
mShape->layout()->undoStack()->beginCommand( mShape, tr( "Change Shape Type" ) ); | ||
QgsLayoutItemShape::Shape shape = static_cast< QgsLayoutItemShape::Shape >( mShapeComboBox->currentData().toInt() ); | ||
mShape->setShapeType( shape ); | ||
toggleRadiusSpin( shape ); | ||
mShape->update(); | ||
mShape->layout()->undoStack()->endCommand(); | ||
} | ||
|
||
void QgsLayoutShapeWidget::toggleRadiusSpin( QgsLayoutItemShape::Shape shape ) | ||
{ | ||
switch ( shape ) | ||
{ | ||
case QgsLayoutItemShape::Ellipse: | ||
case QgsLayoutItemShape::Triangle: | ||
{ | ||
mCornerRadiusSpinBox->setEnabled( false ); | ||
break; | ||
} | ||
case QgsLayoutItemShape::Rectangle: | ||
{ | ||
mCornerRadiusSpinBox->setEnabled( true ); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/*************************************************************************** | ||
qgslayoutshapewidget.h | ||
------------------------ | ||
begin : November 2009 | ||
copyright : (C) 2009 by Marco Hugentobler | ||
email : marco@hugis.net | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* 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 QGSLAYOUTSHAPEWIDGET_H | ||
#define QGSLAYOUTSHAPEWIDGET_H | ||
|
||
#include "ui_qgslayoutshapewidgetbase.h" | ||
#include "qgslayoutitemwidget.h" | ||
#include "qgslayoutitemshape.h" | ||
|
||
/** | ||
* \ingroup app | ||
* Input widget for the configuration of QgsLayoutItemShape | ||
*/ | ||
class QgsLayoutShapeWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutShapeWidgetBase | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit QgsLayoutShapeWidget( QgsLayoutItemShape *shape ); | ||
|
||
protected: | ||
|
||
bool setNewItem( QgsLayoutItem *item ) override; | ||
|
||
|
||
private: | ||
QgsLayoutItemShape *mShape = nullptr; | ||
QgsLayoutItemPropertiesWidget *mItemPropertiesWidget = nullptr; | ||
|
||
//! Blocks / unblocks the signal of all GUI elements | ||
void blockAllSignals( bool block ); | ||
|
||
private slots: | ||
void mShapeComboBox_currentIndexChanged( const QString &text ); | ||
void mCornerRadiusSpinBox_valueChanged( double val ); | ||
void radiusUnitsChanged(); | ||
void symbolChanged(); | ||
|
||
//! Sets the GUI elements to the currentValues of mComposerShape | ||
void setGuiElementValues(); | ||
|
||
//! Enables or disables the rounded radius spin box based on shape type | ||
void toggleRadiusSpin( QgsLayoutItemShape::Shape shape ); | ||
}; | ||
|
||
#endif // QGSLAYOUTSHAPEWIDGET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.