From a5b5bd4c45b2de5ab0a1e144ca7ed46b57432a3f Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 9 Oct 2014 19:56:59 +1100 Subject: [PATCH] [composer] Fix new frames not inheriting outline color, clean up item api a bit --- python/core/composer/qgscomposeritem.sip | 29 +++++++++++-- src/app/composer/qgscomposeritemwidget.cpp | 16 ++----- src/app/composer/qgscomposeritemwidget.h | 2 +- src/core/composer/qgscomposeritem.cpp | 13 ++++++ src/core/composer/qgscomposeritem.h | 29 +++++++++++-- src/core/composer/qgscomposermultiframe.cpp | 3 +- tests/src/core/testqgscomposermultiframe.cpp | 44 ++++++++++++++++++++ 7 files changed, 115 insertions(+), 21 deletions(-) mode change 100755 => 100644 src/core/composer/qgscomposeritem.cpp diff --git a/python/core/composer/qgscomposeritem.sip b/python/core/composer/qgscomposeritem.sip index 179c0858275..6ccd4e92198 100644 --- a/python/core/composer/qgscomposeritem.sip +++ b/python/core/composer/qgscomposeritem.sip @@ -269,26 +269,47 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem * @see setFrameEnabled * @see frameOutlineWidth * @see frameJoinStyle + * @see frameOutlineColor */ bool hasFrame() const; /**Set whether this item has a frame drawn around it or not. * @param drawFrame draw frame - * @returns nothing * @note introduced in 1.8 * @see hasFrame * @see setFrameOutlineWidth * @see setFrameJoinStyle + * @see setFrameOutlineColor */ void setFrameEnabled( const bool drawFrame ); + + /**Sets frame outline color + * @param color new color for outline frame + * @note introduced in 2.6 + * @see frameOutlineColor + * @see setFrameEnabled + * @see setFrameJoinStyle + * @see setFrameOutlineWidth + */ + virtual void setFrameOutlineColor( const QColor& color ); + + /**Returns the frame's outline color. Only used if hasFrame is true. + * @returns frame outline color + * @note introduced in 2.6 + * @see hasFrame + * @see setFrameOutlineColor + * @see frameJoinStyle + * @see setFrameOutlineColor + */ + QColor frameOutlineColor() const; /**Sets frame outline width * @param outlineWidth new width for outline frame - * @returns nothing * @note introduced in 2.2 * @see frameOutlineWidth * @see setFrameEnabled * @see setFrameJoinStyle + * @see setFrameOutlineColor */ virtual void setFrameOutlineWidth( const double outlineWidth ); @@ -298,6 +319,7 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem * @see hasFrame * @see setFrameOutlineWidth * @see frameJoinStyle + * @see frameOutlineColor */ double frameOutlineWidth() const; @@ -307,16 +329,17 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem * @see hasFrame * @see setFrameJoinStyle * @see frameOutlineWidth + * @see frameOutlineColor */ Qt::PenJoinStyle frameJoinStyle() const; /**Sets join style used when drawing the item's frame * @param style Join style for outline frame - * @returns nothing * @note introduced in 2.3 * @see setFrameEnabled * @see frameJoinStyle * @see setFrameOutlineWidth + * @see setFrameOutlineColor */ void setFrameJoinStyle( const Qt::PenJoinStyle style ); diff --git a/src/app/composer/qgscomposeritemwidget.cpp b/src/app/composer/qgscomposeritemwidget.cpp index b1961bea16c..78c911b6d3b 100644 --- a/src/app/composer/qgscomposeritemwidget.cpp +++ b/src/app/composer/qgscomposeritemwidget.cpp @@ -191,13 +191,6 @@ void QgsComposerItemWidget::showFrameGroup( bool showGroup ) } //slots -void QgsComposerItemWidget::on_mFrameColorButton_clicked() -{ - if ( !mItem ) - { - return; - } -} void QgsComposerItemWidget::on_mFrameColorButton_colorChanged( const QColor& newFrameColor ) { @@ -206,10 +199,7 @@ void QgsComposerItemWidget::on_mFrameColorButton_colorChanged( const QColor& new return; } mItem->beginCommand( tr( "Frame color changed" ) ); - QPen thePen = mItem->pen(); - thePen.setColor( newFrameColor ); - - mItem->setPen( thePen ); + mItem->setFrameOutlineColor( newFrameColor ); mItem->update(); mItem->endCommand(); } @@ -486,8 +476,8 @@ void QgsComposerItemWidget::setValuesForGuiNonPositionElements() mItemRotationSpinBox->blockSignals( true ); mExcludeFromPrintsCheckBox->blockSignals( true ); - mBackgroundColorButton->setColor( mItem->brush().color() ); - mFrameColorButton->setColor( mItem->pen().color() ); + mBackgroundColorButton->setColor( mItem->backgroundColor() ); + mFrameColorButton->setColor( mItem->frameOutlineColor() ); mOutlineWidthSpinBox->setValue( mItem->frameOutlineWidth() ); mFrameJoinStyleCombo->setPenJoinStyle( mItem->frameJoinStyle() ); mItemIdLineEdit->setText( mItem->id() ); diff --git a/src/app/composer/qgscomposeritemwidget.h b/src/app/composer/qgscomposeritemwidget.h index a2713f297e4..4993772a860 100644 --- a/src/app/composer/qgscomposeritemwidget.h +++ b/src/app/composer/qgscomposeritemwidget.h @@ -73,7 +73,7 @@ class QgsComposerItemWidget: public QgsComposerItemBaseWidget, private Ui::QgsCo void showFrameGroup( bool showGroup ); public slots: - void on_mFrameColorButton_clicked(); + /** Set the frame color * @note added in 1.9 */ diff --git a/src/core/composer/qgscomposeritem.cpp b/src/core/composer/qgscomposeritem.cpp old mode 100755 new mode 100644 index ab283cd3bdc..a8158e425cd --- a/src/core/composer/qgscomposeritem.cpp +++ b/src/core/composer/qgscomposeritem.cpp @@ -422,6 +422,19 @@ void QgsComposerItem::setFrameEnabled( const bool drawFrame ) emit frameChanged(); } +void QgsComposerItem::setFrameOutlineColor( const QColor &color ) +{ + QPen itemPen = pen(); + if ( itemPen.color() == color ) + { + //no change + return; + } + itemPen.setColor( color ); + setPen( itemPen ); + emit frameChanged(); +} + void QgsComposerItem::setFrameOutlineWidth( const double outlineWidth ) { QPen itemPen = pen(); diff --git a/src/core/composer/qgscomposeritem.h b/src/core/composer/qgscomposeritem.h index 30112f753d5..11874478433 100755 --- a/src/core/composer/qgscomposeritem.h +++ b/src/core/composer/qgscomposeritem.h @@ -227,26 +227,47 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec * @see setFrameEnabled * @see frameOutlineWidth * @see frameJoinStyle + * @see frameOutlineColor */ bool hasFrame() const {return mFrame;} /**Set whether this item has a frame drawn around it or not. * @param drawFrame draw frame - * @returns nothing * @note introduced in 1.8 * @see hasFrame * @see setFrameOutlineWidth * @see setFrameJoinStyle + * @see setFrameOutlineColor */ void setFrameEnabled( const bool drawFrame ); + /**Sets frame outline color + * @param color new color for outline frame + * @note introduced in 2.6 + * @see frameOutlineColor + * @see setFrameEnabled + * @see setFrameJoinStyle + * @see setFrameOutlineWidth + */ + virtual void setFrameOutlineColor( const QColor& color ); + + /**Returns the frame's outline color. Only used if hasFrame is true. + * @returns frame outline color + * @note introduced in 2.6 + * @see hasFrame + * @see setFrameOutlineColor + * @see frameJoinStyle + * @see setFrameOutlineColor + */ + QColor frameOutlineColor() const { return pen().color(); } + /**Sets frame outline width * @param outlineWidth new width for outline frame - * @returns nothing * @note introduced in 2.2 * @see frameOutlineWidth * @see setFrameEnabled * @see setFrameJoinStyle + * @see setFrameOutlineColor */ virtual void setFrameOutlineWidth( const double outlineWidth ); @@ -256,6 +277,7 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec * @see hasFrame * @see setFrameOutlineWidth * @see frameJoinStyle + * @see frameOutlineColor */ double frameOutlineWidth() const { return pen().widthF(); } @@ -265,16 +287,17 @@ class CORE_EXPORT QgsComposerItem: public QgsComposerObject, public QGraphicsRec * @see hasFrame * @see setFrameJoinStyle * @see frameOutlineWidth + * @see frameOutlineColor */ Qt::PenJoinStyle frameJoinStyle() const { return mFrameJoinStyle; } /**Sets join style used when drawing the item's frame * @param style Join style for outline frame - * @returns nothing * @note introduced in 2.3 * @see setFrameEnabled * @see frameJoinStyle * @see setFrameOutlineWidth + * @see setFrameOutlineColor */ void setFrameJoinStyle( const Qt::PenJoinStyle style ); diff --git a/src/core/composer/qgscomposermultiframe.cpp b/src/core/composer/qgscomposermultiframe.cpp index 80addf15310..6dafee476a4 100644 --- a/src/core/composer/qgscomposermultiframe.cpp +++ b/src/core/composer/qgscomposermultiframe.cpp @@ -211,9 +211,10 @@ QgsComposerFrame* QgsComposerMultiFrame::createNewFrame( QgsComposerFrame* curre newFrame->setBackgroundEnabled( currentFrame->hasBackground() ); newFrame->setBlendMode( currentFrame->blendMode() ); newFrame->setFrameEnabled( currentFrame->hasFrame() ); + newFrame->setFrameOutlineColor( currentFrame->frameOutlineColor() ); newFrame->setFrameJoinStyle( currentFrame->frameJoinStyle() ); newFrame->setFrameOutlineWidth( currentFrame->frameOutlineWidth() ); - newFrame->setOpacity( currentFrame->opacity() ); + newFrame->setTransparency( currentFrame->transparency() ); newFrame->setHideBackgroundIfEmpty( currentFrame->hideBackgroundIfEmpty() ); addFrame( newFrame, false ); diff --git a/tests/src/core/testqgscomposermultiframe.cpp b/tests/src/core/testqgscomposermultiframe.cpp index f33c16f498e..498f2f8e0d3 100644 --- a/tests/src/core/testqgscomposermultiframe.cpp +++ b/tests/src/core/testqgscomposermultiframe.cpp @@ -31,6 +31,7 @@ class TestQgsComposerMultiFrame: public QObject void cleanupTestCase();// will be called after the last testfunction was executed. void init();// will be called before each testfunction is executed. void cleanup();// will be called after every testfunction. + void addFrame(); //test creating new frame inherits all properties of existing frame void frameIsEmpty(); //test if frame is empty works void addRemovePage(); //test if page is added and removed for RepeatUntilFinished mode @@ -72,6 +73,49 @@ void TestQgsComposerMultiFrame::cleanup() } +void TestQgsComposerMultiFrame::addFrame() +{ + QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, false ); + QgsComposerFrame* frame1 = new QgsComposerFrame( mComposition, htmlItem, 0, 0, 100, 200 ); + + //should not be inherited + frame1->setHidePageIfEmpty( true ); + + //should be inherited + frame1->setHideBackgroundIfEmpty( true ); + frame1->setFrameOutlineWidth( 5.0 ); + frame1->setFrameJoinStyle( Qt::RoundJoin ); + frame1->setFrameEnabled( true ); + frame1->setFrameOutlineColor( QColor( Qt::red ) ); + frame1->setBackgroundEnabled( true ); + frame1->setBackgroundColor( QColor( Qt::green ) ); + frame1->setBlendMode( QPainter::CompositionMode_ColorBurn ); + frame1->setTransparency( 50 ); + + QgsComposerFrame* frame2 = htmlItem->createNewFrame( frame1, QPointF( 50, 55 ), QSizeF( 70, 120 ) ); + + //check frame created in correct place + QCOMPARE( frame2->rect().height(), 120.0 ); + QCOMPARE( frame2->rect().width(), 70.0 ); + QCOMPARE( frame2->scenePos().x(), 50.0 ); + QCOMPARE( frame2->scenePos().y(), 55.0 ); + + //check frame properties + QCOMPARE( frame2->frameOutlineWidth(), frame1->frameOutlineWidth() ); + QCOMPARE( frame2->frameOutlineColor(), frame1->frameOutlineColor() ); + QCOMPARE( frame2->frameJoinStyle(), frame1->frameJoinStyle() ); + QCOMPARE( frame2->hasBackground(), frame1->hasBackground() ); + QCOMPARE( frame2->backgroundColor(), frame1->backgroundColor() ); + QCOMPARE( frame2->blendMode(), frame1->blendMode() ); + QCOMPARE( frame2->transparency(), frame1->transparency() ); + + //check non-inherited properties + QVERIFY( !frame2->hidePageIfEmpty() ); + + mComposition->removeMultiFrame( htmlItem ); + delete htmlItem; +} + void TestQgsComposerMultiFrame::frameIsEmpty() { QgsComposerHtml* htmlItem = new QgsComposerHtml( mComposition, false );