Skip to content

Commit

Permalink
[composer] Fix new frames not inheriting outline color, clean up item…
Browse files Browse the repository at this point in the history
… api a bit
  • Loading branch information
nyalldawson committed Oct 9, 2014
1 parent 7a389f6 commit a5b5bd4
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 21 deletions.
29 changes: 26 additions & 3 deletions python/core/composer/qgscomposeritem.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -298,6 +319,7 @@ class QgsComposerItem : QgsComposerObject, QGraphicsRectItem
* @see hasFrame
* @see setFrameOutlineWidth
* @see frameJoinStyle
* @see frameOutlineColor
*/
double frameOutlineWidth() const;

Expand All @@ -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 );

Expand Down
16 changes: 3 additions & 13 deletions src/app/composer/qgscomposeritemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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();
}
Expand Down Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion src/app/composer/qgscomposeritemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
13 changes: 13 additions & 0 deletions src/core/composer/qgscomposeritem.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
29 changes: 26 additions & 3 deletions src/core/composer/qgscomposeritem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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(); }

Expand All @@ -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 );

Expand Down
3 changes: 2 additions & 1 deletion src/core/composer/qgscomposermultiframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
44 changes: 44 additions & 0 deletions tests/src/core/testqgscomposermultiframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit a5b5bd4

Please sign in to comment.