Refactoring. Join similar parts from methods that update labels. ref #672.
Issue #672 that this part better to refactor to eliminate more issues in future. --HG-- branch : release
This commit is contained in:
parent
795373e74e
commit
f990a5726c
|
@ -524,7 +524,7 @@ void VToolSeamAllowance::UpdateAll()
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
void VToolSeamAllowance::retranslateUi()
|
void VToolSeamAllowance::retranslateUi()
|
||||||
{
|
{
|
||||||
UpdateLabel();
|
UpdateDetailLabel();
|
||||||
UpdatePatternInfo();
|
UpdatePatternInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,7 +538,7 @@ void VToolSeamAllowance::Highlight(quint32 id)
|
||||||
/**
|
/**
|
||||||
* @brief UpdateLabel updates the text label, making it just big enough for the text to fit it
|
* @brief UpdateLabel updates the text label, making it just big enough for the text to fit it
|
||||||
*/
|
*/
|
||||||
void VToolSeamAllowance::UpdateLabel()
|
void VToolSeamAllowance::UpdateDetailLabel()
|
||||||
{
|
{
|
||||||
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
const VPiece detail = VAbstractTool::data.GetPiece(id);
|
||||||
const VPieceLabelData& labelData = detail.GetPatternPieceData();
|
const VPieceLabelData& labelData = detail.GetPatternPieceData();
|
||||||
|
@ -546,44 +546,13 @@ void VToolSeamAllowance::UpdateLabel()
|
||||||
if (labelData.IsVisible() == true)
|
if (labelData.IsVisible() == true)
|
||||||
{
|
{
|
||||||
QPointF pos;
|
QPointF pos;
|
||||||
qreal labelWidth = 0;
|
|
||||||
qreal labelHeight = 0;
|
|
||||||
qreal labelAngle = 0;
|
qreal labelAngle = 0;
|
||||||
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelAngle, labelWidth, labelHeight,
|
|
||||||
pos);
|
|
||||||
if (type & VGrainlineItem::Error)
|
|
||||||
{
|
|
||||||
m_dataLabel->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_dataLabel->SetMoveType(type);
|
|
||||||
|
|
||||||
QFont fnt = QApplication::font();
|
if (PrepareLabelData(labelData, m_dataLabel, pos, labelAngle))
|
||||||
{
|
{
|
||||||
const int iFS = labelData.GetFontSize();
|
m_dataLabel->UpdateData(detail.GetName(), labelData);
|
||||||
iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS);
|
UpdateLabelItem(m_dataLabel, pos, labelAngle);
|
||||||
}
|
}
|
||||||
m_dataLabel->SetFont(fnt);
|
|
||||||
m_dataLabel->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()),
|
|
||||||
ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()));
|
|
||||||
m_dataLabel->UpdateData(detail.GetName(), labelData);
|
|
||||||
|
|
||||||
QRectF rectBB;
|
|
||||||
rectBB.setTopLeft(pos);
|
|
||||||
rectBB.setWidth(m_dataLabel->boundingRect().width());
|
|
||||||
rectBB.setHeight(m_dataLabel->boundingRect().height());
|
|
||||||
qreal dX;
|
|
||||||
qreal dY;
|
|
||||||
if (m_dataLabel->IsContained(rectBB, labelAngle, dX, dY) == false)
|
|
||||||
{
|
|
||||||
pos.setX(pos.x() + dX);
|
|
||||||
pos.setY(pos.y() + dY);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_dataLabel->setPos(pos);
|
|
||||||
m_dataLabel->setRotation(-labelAngle);// expects clockwise direction
|
|
||||||
m_dataLabel->Update();
|
|
||||||
m_dataLabel->show();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -603,45 +572,13 @@ void VToolSeamAllowance::UpdatePatternInfo()
|
||||||
if (geom.IsVisible() == true)
|
if (geom.IsVisible() == true)
|
||||||
{
|
{
|
||||||
QPointF pos;
|
QPointF pos;
|
||||||
qreal labelWidth = 0;
|
|
||||||
qreal labelHeight = 0;
|
|
||||||
qreal labelAngle = 0;
|
qreal labelAngle = 0;
|
||||||
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(geom, labelAngle, labelWidth, labelHeight, pos);
|
|
||||||
if (type & VGrainlineItem::Error)
|
|
||||||
{
|
|
||||||
m_dataLabel->hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_patternInfo->SetMoveType(type);
|
|
||||||
|
|
||||||
QFont fnt = QApplication::font();
|
if (PrepareLabelData(geom, m_patternInfo, pos, labelAngle))
|
||||||
int iFS = geom.GetFontSize();
|
|
||||||
if (iFS < MIN_FONT_SIZE)
|
|
||||||
{
|
{
|
||||||
iFS = MIN_FONT_SIZE;
|
m_patternInfo->UpdateData(doc, VContainer::size(), VContainer::height());
|
||||||
|
UpdateLabelItem(m_patternInfo, pos, labelAngle);
|
||||||
}
|
}
|
||||||
fnt.setPixelSize(iFS);
|
|
||||||
m_patternInfo->SetFont(fnt);
|
|
||||||
m_patternInfo->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()),
|
|
||||||
ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()));
|
|
||||||
m_patternInfo->UpdateData(doc, VContainer::size(), VContainer::height());
|
|
||||||
|
|
||||||
QRectF rectBB;
|
|
||||||
rectBB.setTopLeft(pos);
|
|
||||||
rectBB.setWidth(m_patternInfo->boundingRect().width());
|
|
||||||
rectBB.setHeight(m_patternInfo->boundingRect().height());
|
|
||||||
qreal dX;
|
|
||||||
qreal dY;
|
|
||||||
if (m_patternInfo->IsContained(rectBB, labelAngle, dX, dY) == false)
|
|
||||||
{
|
|
||||||
pos.setX(pos.x() + dX);
|
|
||||||
pos.setY(pos.y() + dY);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_patternInfo->setPos(pos);
|
|
||||||
m_patternInfo->setRotation(-labelAngle);// expects clockwise direction
|
|
||||||
m_patternInfo->Update();
|
|
||||||
m_patternInfo->GetTextLines() > 0 ? m_patternInfo->show() : m_patternInfo->hide();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1190,15 +1127,15 @@ VToolSeamAllowance::VToolSeamAllowance(VAbstractPattern *doc, VContainer *data,
|
||||||
connect(m_grainLine, &VGrainlineItem::SignalRotated, this, &VToolSeamAllowance::SaveRotateGrainline);
|
connect(m_grainLine, &VGrainlineItem::SignalRotated, this, &VToolSeamAllowance::SaveRotateGrainline);
|
||||||
|
|
||||||
connect(doc, &VAbstractPattern::patternChanged, this, &VToolSeamAllowance::UpdatePatternInfo);
|
connect(doc, &VAbstractPattern::patternChanged, this, &VToolSeamAllowance::UpdatePatternInfo);
|
||||||
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateLabel);
|
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateDetailLabel);
|
||||||
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdatePatternInfo);
|
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdatePatternInfo);
|
||||||
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateGrainline);
|
connect(doc, &VAbstractPattern::CheckLayout, this, &VToolSeamAllowance::UpdateGrainline);
|
||||||
|
|
||||||
connect(m_sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolSeamAllowance::UpdateLabel);
|
connect(m_sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolSeamAllowance::UpdateDetailLabel);
|
||||||
connect(m_sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolSeamAllowance::UpdatePatternInfo);
|
connect(m_sceneDetails, &VMainGraphicsScene::DimensionsChanged, this, &VToolSeamAllowance::UpdatePatternInfo);
|
||||||
connect(m_sceneDetails, &VMainGraphicsScene::LanguageChanged, this, &VToolSeamAllowance::retranslateUi);
|
connect(m_sceneDetails, &VMainGraphicsScene::LanguageChanged, this, &VToolSeamAllowance::retranslateUi);
|
||||||
|
|
||||||
UpdateLabel();
|
UpdateDetailLabel();
|
||||||
UpdatePatternInfo();
|
UpdatePatternInfo();
|
||||||
UpdateGrainline();
|
UpdateGrainline();
|
||||||
}
|
}
|
||||||
|
@ -1263,7 +1200,7 @@ void VToolSeamAllowance::SaveDialogChange()
|
||||||
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
SavePieceOptions *saveCommand = new SavePieceOptions(oldDet, newDet, doc, id);
|
||||||
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
connect(saveCommand, &SavePieceOptions::NeedLiteParsing, doc, &VAbstractPattern::LiteParseTree);
|
||||||
qApp->getUndoStack()->push(saveCommand);
|
qApp->getUndoStack()->push(saveCommand);
|
||||||
UpdateLabel();
|
UpdateDetailLabel();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -1585,3 +1522,54 @@ void VToolSeamAllowance::ToolCreation(const Source &typeCreation)
|
||||||
RefreshDataInFile();
|
RefreshDataInFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
bool VToolSeamAllowance::PrepareLabelData(const VPatternLabelData &labelData, VTextGraphicsItem *labelItem,
|
||||||
|
QPointF &pos, qreal &labelAngle)
|
||||||
|
{
|
||||||
|
SCASSERT(labelItem != nullptr)
|
||||||
|
|
||||||
|
qreal labelWidth = 0;
|
||||||
|
qreal labelHeight = 0;
|
||||||
|
const VTextGraphicsItem::MoveTypes type = FindLabelGeometry(labelData, labelAngle, labelWidth, labelHeight, pos);
|
||||||
|
if (type & VGrainlineItem::Error)
|
||||||
|
{
|
||||||
|
labelItem->hide();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
labelItem->SetMoveType(type);
|
||||||
|
|
||||||
|
QFont fnt = QApplication::font();
|
||||||
|
{
|
||||||
|
const int iFS = labelData.GetFontSize();
|
||||||
|
iFS < MIN_FONT_SIZE ? fnt.setPixelSize(MIN_FONT_SIZE) : fnt.setPixelSize(iFS);
|
||||||
|
}
|
||||||
|
labelItem->SetFont(fnt);
|
||||||
|
labelItem->SetSize(ToPixel(labelWidth, *VDataTool::data.GetPatternUnit()),
|
||||||
|
ToPixel(labelHeight, *VDataTool::data.GetPatternUnit()));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VToolSeamAllowance::UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle)
|
||||||
|
{
|
||||||
|
SCASSERT(labelItem != nullptr)
|
||||||
|
|
||||||
|
QRectF rectBB;
|
||||||
|
rectBB.setTopLeft(pos);
|
||||||
|
rectBB.setWidth(labelItem->boundingRect().width());
|
||||||
|
rectBB.setHeight(labelItem->boundingRect().height());
|
||||||
|
qreal dX;
|
||||||
|
qreal dY;
|
||||||
|
if (labelItem->IsContained(rectBB, labelAngle, dX, dY) == false)
|
||||||
|
{
|
||||||
|
pos.setX(pos.x() + dX);
|
||||||
|
pos.setY(pos.y() + dY);
|
||||||
|
}
|
||||||
|
|
||||||
|
labelItem->setPos(pos);
|
||||||
|
labelItem->setRotation(-labelAngle);// expects clockwise direction
|
||||||
|
labelItem->Update();
|
||||||
|
labelItem->GetTextLines() > 0 ? labelItem->show() : labelItem->hide();
|
||||||
|
}
|
||||||
|
|
|
@ -103,18 +103,18 @@ public slots:
|
||||||
virtual void retranslateUi();
|
virtual void retranslateUi();
|
||||||
void Highlight(quint32 id);
|
void Highlight(quint32 id);
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void UpdateLabel();
|
void UpdateDetailLabel();
|
||||||
virtual void UpdatePatternInfo();
|
void UpdatePatternInfo();
|
||||||
virtual void UpdateGrainline();
|
void UpdateGrainline();
|
||||||
virtual void SaveMoveDetail(const QPointF &ptPos);
|
void SaveMoveDetail(const QPointF &ptPos);
|
||||||
virtual void SaveResizeDetail(qreal dLabelW, int iFontSize);
|
void SaveResizeDetail(qreal dLabelW, int iFontSize);
|
||||||
virtual void SaveRotationDetail(qreal dRot);
|
void SaveRotationDetail(qreal dRot);
|
||||||
virtual void SaveMovePattern(const QPointF& ptPos);
|
void SaveMovePattern(const QPointF& ptPos);
|
||||||
virtual void SaveResizePattern(qreal dLabelW, int iFontSize);
|
void SaveResizePattern(qreal dLabelW, int iFontSize);
|
||||||
virtual void SaveRotationPattern(qreal dRot);
|
void SaveRotationPattern(qreal dRot);
|
||||||
virtual void SaveMoveGrainline(const QPointF& ptPos);
|
void SaveMoveGrainline(const QPointF& ptPos);
|
||||||
virtual void SaveResizeGrainline(qreal dLength);
|
void SaveResizeGrainline(qreal dLength);
|
||||||
virtual void SaveRotateGrainline(qreal dRot, const QPointF& ptPos);
|
void SaveRotateGrainline(qreal dRot, const QPointF& ptPos);
|
||||||
protected:
|
protected:
|
||||||
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
|
||||||
QWidget *widget) Q_DECL_OVERRIDE;
|
QWidget *widget) Q_DECL_OVERRIDE;
|
||||||
|
@ -163,6 +163,10 @@ private:
|
||||||
void InitCSAPaths(const VPiece &detail);
|
void InitCSAPaths(const VPiece &detail);
|
||||||
void InitInternalPaths(const VPiece &detail);
|
void InitInternalPaths(const VPiece &detail);
|
||||||
void InitPins(const VPiece &detail);
|
void InitPins(const VPiece &detail);
|
||||||
|
|
||||||
|
bool PrepareLabelData(const VPatternLabelData &labelData, VTextGraphicsItem *labelItem, QPointF &pos,
|
||||||
|
qreal &labelAngle);
|
||||||
|
void UpdateLabelItem(VTextGraphicsItem *labelItem, QPointF pos, qreal labelAngle);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // VTOOLSEAMALLOWANCE_H
|
#endif // VTOOLSEAMALLOWANCE_H
|
||||||
|
|
Loading…
Reference in New Issue
Block a user