Skip to content

Commit

Permalink
ticket:3841
Browse files Browse the repository at this point in the history
Get a proper bounding rectangle for exporting image.
  • Loading branch information
adeas31 committed Apr 12, 2016
1 parent efb215b commit a9c53de
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
20 changes: 20 additions & 0 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -601,6 +601,26 @@ QRectF Component::boundingRect() const
return QRectF(left, bottom, fabs(left - right), fabs(bottom - top));
}

/*!
* \brief Component::itemsBoundingRect
* Gets the bounding rectangle of all the items added to the component.
* \return
*/
QRectF Component::itemsBoundingRect()
{
QRectF rect;
foreach (Component *pComponent, mInheritedComponentsList) {
rect |= pComponent->itemsBoundingRect();
}
foreach (Component *pComponent, mComponentsList) {
rect |= pComponent->itemsBoundingRect();
}
foreach (QGraphicsItem *item, mShapesList) {
rect |= item->sceneBoundingRect();
}
return rect;
}

void Component::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(painter);
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -169,6 +169,7 @@ class Component : public QObject, public QGraphicsItem
bool hasShapeAnnotation(Component *pComponent);
bool hasNonExistingClass();
QRectF boundingRect() const;
QRectF itemsBoundingRect();
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
LibraryTreeItem* getLibraryTreeItem() {return mpLibraryTreeItem;}
QString getName() {return mpComponentInfo->getName();}
Expand Down
3 changes: 1 addition & 2 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -1697,7 +1697,6 @@ void MainWindow::exportModelAsImage(bool copyToClipboard)
return;
}
}
bool oldSkipDrawBackground;
// show the progressbar and set the message in status bar
mpProgressBar->setRange(0, 0);
showProgressBar();
Expand Down Expand Up @@ -1730,7 +1729,7 @@ void MainWindow::exportModelAsImage(bool copyToClipboard)
}
painter.setWindow(destinationRect);
// paint all the items
oldSkipDrawBackground = pGraphicsView->mSkipBackground;
bool oldSkipDrawBackground = pGraphicsView->mSkipBackground;
pGraphicsView->mSkipBackground = true;
pGraphicsView->render(&painter, destinationRect, destinationRect);
painter.end();
Expand Down
17 changes: 12 additions & 5 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -840,19 +840,26 @@ void GraphicsView::createBitmapShape(QPointF point)
}
}

//! Gets the bounding rectangle of all the items added to the view, excluding background and so on
/*!
* \brief GraphicsView::itemsBoundingRect
* Gets the bounding rectangle of all the items added to the view, excluding background and so on
* \return
*/
QRectF GraphicsView::itemsBoundingRect()
{
QRectF rect;
foreach(QGraphicsItem *item, mComponentsList){
rect |= item->sceneBoundingRect();
foreach (Component *pComponent, mComponentsList) {
rect |= pComponent->itemsBoundingRect();
}
foreach(QGraphicsItem *item, mShapesList){
foreach (QGraphicsItem *item, mShapesList) {
rect |= item->sceneBoundingRect();
}
foreach(QGraphicsItem *item, mConnectionsList){
foreach (QGraphicsItem *item, mConnectionsList) {
rect |= item->sceneBoundingRect();
}
qreal x1, y1, x2, y2;
rect.getCoords(&x1, &y1, &x2, &y2);
rect.setCoords(x1 -5, y1 -5, x2 + 5, y2 + 5);
return mapFromScene(rect).boundingRect();
}

Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/TLM/TLMCoSimulationDialog.cpp
Expand Up @@ -457,7 +457,7 @@ void MetaModelSimulationParamsDialog::saveSimulationParams()
{
if (validateSimulationParams()) {
// If user has changed the simulation parameters then push the change on the stack.
if(!mOldStartTime.compare(mpStartTimeTextBox->text())== 0 || !mOldStopTime.compare(mpStopTimeTextBox->text())== 0) {
if (!mOldStartTime.compare(mpStartTimeTextBox->text())== 0 || !mOldStopTime.compare(mpStopTimeTextBox->text())== 0) {
UpdateSimulationParamsCommand *pUpdateSimulationParamsCommand;
pUpdateSimulationParamsCommand = new UpdateSimulationParamsCommand(mpLibraryTreeItem, mOldStartTime, mpStartTimeTextBox->text(),
mOldStopTime, mpStopTimeTextBox->text());
Expand Down

0 comments on commit a9c53de

Please sign in to comment.