Fix redrawing VPGraphicsSheet.

This commit is contained in:
Roman Telezhynskyi 2021-09-11 14:01:29 +03:00
parent 18e52f4a70
commit 54b0ca5ee5
4 changed files with 41 additions and 6 deletions

View File

@ -280,6 +280,15 @@ void VPSheetSceneData::ClearTilesScheme()
RefreshLayout(); RefreshLayout();
} }
//---------------------------------------------------------------------------------------------------------------------
void VPSheetSceneData::RefreshSheetSize()
{
if (m_graphicsSheet != nullptr)
{
m_graphicsSheet->RefreshBoundingRect();
}
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece) void VPSheetSceneData::ConnectPiece(VPGraphicsPiece *piece)
{ {
@ -707,6 +716,11 @@ void VPSheet::SetSheetSize(qreal width, qreal height)
{ {
m_size.setWidth(width); m_size.setWidth(width);
m_size.setHeight(height); m_size.setHeight(height);
if (m_sceneData != nullptr)
{
m_sceneData->RefreshSheetSize();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -715,12 +729,22 @@ void VPSheet::SetSheetSizeConverted(qreal width, qreal height)
Unit unit = SheetUnits(); Unit unit = SheetUnits();
m_size.setWidth(UnitConvertor(width, unit, Unit::Px)); m_size.setWidth(UnitConvertor(width, unit, Unit::Px));
m_size.setHeight(UnitConvertor(height, unit, Unit::Px)); m_size.setHeight(UnitConvertor(height, unit, Unit::Px));
if (m_sceneData != nullptr)
{
m_sceneData->RefreshSheetSize();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPSheet::SetSheetSize(const QSizeF &size) void VPSheet::SetSheetSize(const QSizeF &size)
{ {
m_size = size; m_size = size;
if (m_sceneData != nullptr)
{
m_sceneData->RefreshSheetSize();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -729,6 +753,11 @@ void VPSheet::SetSheetSizeConverted(const QSizeF &size)
Unit unit = SheetUnits(); Unit unit = SheetUnits();
m_size = QSizeF(UnitConvertor(size.width(), unit, Unit::Px), m_size = QSizeF(UnitConvertor(size.width(), unit, Unit::Px),
UnitConvertor(size.height(), unit, Unit::Px)); UnitConvertor(size.height(), unit, Unit::Px));
if (m_sceneData != nullptr)
{
m_sceneData->RefreshSheetSize();
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -87,6 +87,8 @@ public:
void PrepareTilesScheme(); void PrepareTilesScheme();
void ClearTilesScheme(); void ClearTilesScheme();
void RefreshSheetSize();
private: private:
Q_DISABLE_COPY(VPSheetSceneData) Q_DISABLE_COPY(VPSheetSceneData)

View File

@ -35,8 +35,7 @@
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPGraphicsSheet::VPGraphicsSheet(const VPLayoutPtr &layout, QGraphicsItem *parent): VPGraphicsSheet::VPGraphicsSheet(const VPLayoutPtr &layout, QGraphicsItem *parent):
QGraphicsItem(parent), QGraphicsItem(parent),
m_layout(layout), m_layout(layout)
m_boundingRect(GetSheetRect())
{} {}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -98,8 +97,6 @@ void VPGraphicsSheet::paint(QPainter *painter, const QStyleOptionGraphicsItem *o
} }
} }
} }
m_boundingRect = sheetRect;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -148,8 +145,14 @@ void VPGraphicsSheet::SetShowBorder(bool value)
m_showBorder = value; m_showBorder = value;
} }
//---------------------------------------------------------------------------------------------------------------------
void VPGraphicsSheet::RefreshBoundingRect()
{
prepareGeometryChange();
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VPGraphicsSheet::boundingRect() const -> QRectF auto VPGraphicsSheet::boundingRect() const -> QRectF
{ {
return m_boundingRect; return GetSheetRect();
} }

View File

@ -60,11 +60,12 @@ public:
*/ */
void SetShowBorder(bool value); void SetShowBorder(bool value);
void RefreshBoundingRect();
private: private:
Q_DISABLE_COPY(VPGraphicsSheet) Q_DISABLE_COPY(VPGraphicsSheet)
VPLayoutWeakPtr m_layout{}; VPLayoutWeakPtr m_layout{};
QRectF m_boundingRect;
bool m_showMargin{true}; bool m_showMargin{true};
bool m_showBorder{true}; bool m_showBorder{true};