Improve the layout option "Auto crop unused width".

This commit is contained in:
Roman Telezhynskyi 2020-12-18 17:01:58 +02:00
parent 58cae6f66c
commit e70e998dc5
5 changed files with 36 additions and 0 deletions

View File

@ -5,6 +5,7 @@
- Fix invalid visualization for tool Point of intersection circles.
- New warning. Warn about empty measurements dimension value when preparing placeholders.
- New option "Don't use the native file dialog".
- Improve the layout option "Auto crop unused width".
# Version 0.7.41 Dec 4, 2020
- Bug fixes.

View File

@ -263,6 +263,11 @@ void VLayoutGenerator::Generate(const QElapsedTimer &timer, qint64 timeout, Layo
GatherPages();
}
if (autoCropWidth)
{
OptimizeWidth();
}
if (IsUnitePages())
{
UnitePages();
@ -506,6 +511,27 @@ void VLayoutGenerator::GatherPages()
papers = nPapers;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::OptimizeWidth()
{
QVector<VLayoutPiece> newDetails;
for (auto &paper : papers)
{
const QRectF rec = paper.DetailsBoundingRect();
QVector<VLayoutPiece> details = paper.GetDetails();
newDetails.resize(0); // resize(0) preserves capacity, unlike QVector::clear()
newDetails.reserve(details.size());
for (auto &d : details)
{
IsPortrait() ? d.Translate(-rec.x()+1, 0) : d.Translate(0, -rec.y()+1);
newDetails.append(d);
}
paper.SetDetails(newDetails);
}
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutGenerator::UnitePages()
{
@ -785,6 +811,7 @@ void VLayoutGenerator::SetAutoCropLength(bool value)
autoCropLength = value;
}
//---------------------------------------------------------------------------------------------------------------------
bool VLayoutGenerator::GetAutoCropWidth() const
{
return autoCropWidth;

View File

@ -169,6 +169,7 @@ private:
int PageHeight() const;
int PageWidth() const;
void OptimizeWidth();
void GatherPages();
void UnitePages();
void UniteDetails(int j, QList<QList<VLayoutPiece> > &nDetails, qreal length, int i) const;

View File

@ -435,6 +435,12 @@ QVector<VLayoutPiece> VLayoutPaper::GetDetails() const
return d->details;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetDetails(const QVector<VLayoutPiece> &details)
{
d->details = details;
}
//---------------------------------------------------------------------------------------------------------------------
void VLayoutPaper::SetDetails(const QList<VLayoutPiece> &details)
{

View File

@ -99,6 +99,7 @@ public:
Q_REQUIRED_RESULT QList<QGraphicsItem *> GetItemDetails(bool textAsPaths) const;
QVector<VLayoutPiece> GetDetails() const;
void SetDetails(const QVector<VLayoutPiece>& details);
void SetDetails(const QList<VLayoutPiece>& details);
QRectF DetailsBoundingRect() const;