Compatibility issues.

This commit is contained in:
Roman Telezhynskyi 2022-01-29 10:59:02 +02:00
parent a6f0ab2b3f
commit 1b188bf414
38 changed files with 137 additions and 124 deletions

View File

@ -117,7 +117,7 @@ void VPCarrouselPieceList::mouseMoveEvent(QMouseEvent *event)
if (((event->buttons() & Qt::LeftButton) != 0U) &&
((event->pos() - m_dragStart).manhattanLength() >= QApplication::startDragDistance()) &&
(selectedItems().count() > 0) &&
(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr)) // only if it's from unplaced pieces
(not m_pieceList.isEmpty() && ConstFirst(m_pieceList)->Sheet() == nullptr)) // only if it's from unplaced pieces
{
startDrag(Qt::MoveAction);
}
@ -229,13 +229,13 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
QAction *removeAction = menu.addAction(tr("Remove from Sheet"));
removeAction->setVisible(false);
if(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() == nullptr)
if(not m_pieceList.isEmpty() && ConstFirst(m_pieceList)->Sheet() == nullptr)
{
moveAction->setVisible(true);
deleteAction->setVisible(true);
}
if(not m_pieceList.isEmpty() && m_pieceList.first()->Sheet() != nullptr)
if(not m_pieceList.isEmpty() && ConstFirst(m_pieceList)->Sheet() != nullptr)
{
removeAction->setVisible(true);
}

View File

@ -185,7 +185,7 @@ auto VPLayout::IsSheetsUniform() const -> bool
return true;
}
VPSheetPtr sheet = sheets.first();
const VPSheetPtr &sheet = ConstFirst(sheets);
if (sheet.isNull())
{
return false;
@ -299,7 +299,7 @@ void VPLayout::SetFocusedSheet(const VPSheetPtr &focusedSheet)
}
else
{
m_focusedSheet = focusedSheet.isNull() ? m_sheets.first() : focusedSheet;
m_focusedSheet = focusedSheet.isNull() ? ConstFirst(m_sheets) : focusedSheet;
}
emit ActiveSheetChanged(m_focusedSheet);

View File

@ -218,10 +218,10 @@ void VPPiece::RotateToGrainline(const VPTransformationOrigon &origin)
return;
}
QLineF grainline(grainlinePoints.first(), grainlinePoints.last());
QLineF grainline(ConstFirst(grainlinePoints), ConstLast(grainlinePoints));
QLineF canonical(grainlinePoints.first().x(), grainlinePoints.first().y(),
grainlinePoints.first().x()+100, grainlinePoints.first().y());
QLineF canonical(ConstFirst(grainlinePoints).x(), ConstFirst(grainlinePoints).y(),
ConstFirst(grainlinePoints).x()+100, ConstFirst(grainlinePoints).y());
GrainlineType grainlineType = sheet->GrainlineOrientation();

View File

@ -416,7 +416,7 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter)
QVector<QPointF> seamLinePoints = piece->GetMappedContourPoints();
if(!seamLinePoints.isEmpty())
{
m_seamLine.moveTo(seamLinePoints.first());
m_seamLine.moveTo(ConstFirst(seamLinePoints));
for (int i = 1; i < seamLinePoints.size(); i++)
{
m_seamLine.lineTo(seamLinePoints.at(i));
@ -438,7 +438,7 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter)
QVector<QPointF> cuttingLinepoints = piece->GetMappedSeamAllowancePoints();
if(!cuttingLinepoints.isEmpty())
{
m_cuttingLine.moveTo(cuttingLinepoints.first());
m_cuttingLine.moveTo(ConstFirst(cuttingLinepoints));
for (int i = 1; i < cuttingLinepoints.size(); i++)
{
m_cuttingLine.lineTo(cuttingLinepoints.at(i));
@ -460,7 +460,7 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter)
QVector<QPointF> grainLinepoints = piece->GetMappedGrainline();
if(!grainLinepoints.isEmpty())
{
m_grainline.moveTo(grainLinepoints.first());
m_grainline.moveTo(ConstFirst(grainLinepoints));
for (int i = 1; i < grainLinepoints.size(); i++)
{
m_grainline.lineTo(grainLinepoints.at(i));
@ -539,7 +539,7 @@ void VPGraphicsPiece::PaintPiece(QPainter *painter)
if (not m_stickyPoints.isEmpty())
{
m_stickyPath.moveTo(m_stickyPoints.first());
m_stickyPath.moveTo(ConstFirst(m_stickyPoints));
for (int i = 1; i < m_stickyPoints.size(); i++)
{
m_stickyPath.lineTo(m_stickyPoints.at(i));
@ -599,7 +599,7 @@ void VPGraphicsPiece::GroupMove(const QPointF &pos)
if (pieces.size() == 1)
{
VPPiecePtr p = pieces.first();
const VPPiecePtr &p = ConstFirst(pieces);
auto *command = new VPUndoPieceMove(piece, newPos.x(), newPos.y(), allowChangeMerge);
layout->UndoStack()->push(command);

View File

@ -532,7 +532,7 @@ void VPGraphicsPieceControls::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
if (pieces.size() == 1)
{
auto *command = new VPUndoPieceRotate(pieces.first(), rotationOrigin, rotateOn, m_rotationSum,
auto *command = new VPUndoPieceRotate(ConstFirst(pieces), rotationOrigin, rotateOn, m_rotationSum,
allowChangeMerge);
layout->UndoStack()->push(command);
}

View File

@ -357,7 +357,7 @@ void VPMainGraphicsView::keyReleaseEvent(QKeyEvent *event)
QList<VPPiecePtr> pieces = PreparePieces();
if (pieces.size() == 1)
{
VPPiecePtr p = pieces.first();
const VPPiecePtr &p = ConstFirst(pieces);
auto *command = new VPUndoPieceMove(p, m_stickyTranslateX, m_stickyTranslateY,
m_allowChangeMerge);
@ -555,7 +555,7 @@ void VPMainGraphicsView::RotatePiecesByAngle(qreal angle)
if (pieces.size() == 1)
{
auto *command = new VPUndoPieceRotate(pieces.first(), origin, angle, m_rotationSum, m_allowChangeMerge);
auto *command = new VPUndoPieceRotate(ConstFirst(pieces), origin, angle, m_rotationSum, m_allowChangeMerge);
layout->UndoStack()->push(command);
}
else if (pieces.size() > 1)
@ -589,7 +589,7 @@ void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy)
return;
}
VPPiecePtr piece = graphicsPieces.first()->GetPiece();
VPPiecePtr piece = ConstFirst(graphicsPieces)->GetPiece();
if (piece.isNull())
{
return;
@ -614,7 +614,7 @@ void VPMainGraphicsView::TranslatePiecesOn(qreal dx, qreal dy)
QList<VPPiecePtr> pieces = PreparePieces();
if (pieces.size() == 1)
{
VPPiecePtr p = pieces.first();
const VPPiecePtr &p = ConstFirst(pieces);
auto *command = new VPUndoPieceMove(p, dx, dy, m_allowChangeMerge);
layout->UndoStack()->push(command);

View File

@ -166,7 +166,7 @@ auto PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) -> QSh
return QSharedPointer<QPrinter>();
}
tmpInfo = QPrinterInfo::printerInfo(list.first());
tmpInfo = QPrinterInfo::printerInfo(ConstFirst<QString>(list));
}
auto printer = QSharedPointer<QPrinter>(new QPrinter(tmpInfo, mode));
@ -735,7 +735,7 @@ void VPMainWindow::InitPropertyTabCurrentPiece()
QList<VPPiecePtr> selectedPieces = SelectedPieces();
if (selectedPieces.size() == 1)
{
VPPiecePtr selectedPiece = selectedPieces.first();
const VPPiecePtr &selectedPiece = ConstFirst(selectedPieces);
if (not selectedPiece.isNull())
{
selectedPiece->SetHideMainPath(not checked);
@ -751,7 +751,7 @@ void VPMainWindow::InitPropertyTabCurrentPiece()
QList<VPPiecePtr> selectedPieces = SelectedPieces();
if (selectedPieces.size() == 1)
{
VPPiecePtr selectedPiece = selectedPieces.first();
const VPPiecePtr &selectedPiece = ConstFirst(selectedPieces);
if (not selectedPiece.isNull())
{
if (selectedPiece->IsMirror() != checked)
@ -1284,7 +1284,7 @@ void VPMainWindow::SetPropertyTabCurrentPieceData()
ui-> groupBoxCurrentPieceSeamline->setVisible(true);
ui->groupBoxCurrentPieceGeometry->setVisible(true);
VPPiecePtr selectedPiece = selectedPieces.first();
const VPPiecePtr &selectedPiece = ConstFirst(selectedPieces);
// set the value to the current piece
SetLineEditValue(ui->lineEditCurrentPieceName, selectedPiece->GetName());
@ -3749,7 +3749,7 @@ void VPMainWindow::on_ApplyPieceTransformation()
if (selectedPieces.size() == 1)
{
auto *command = new VPUndoPieceMove(selectedPieces.first(), pieceDx, pieceDy);
auto *command = new VPUndoPieceMove(ConstFirst(selectedPieces), pieceDx, pieceDy);
m_layout->UndoStack()->push(command);
}
else
@ -4133,7 +4133,7 @@ void VPMainWindow::on_actionPrintLayout_triggered()
QCoreApplication::applicationVersion());
QList<VPSheetPtr> sheets = m_layout->GetSheets();
VPSheetPtr firstSheet = sheets.first();
const VPSheetPtr &firstSheet = ConstFirst(sheets);
if (firstSheet.isNull())
{
qCritical() << tr("Unable to get sheet page settings");
@ -4184,7 +4184,7 @@ void VPMainWindow::on_actionPrintPreviewLayout_triggered()
QCoreApplication::applicationVersion());
QList<VPSheetPtr> sheets = m_layout->GetSheets();
VPSheetPtr firstSheet = sheets.first();
const VPSheetPtr &firstSheet = ConstFirst(sheets);
if (firstSheet.isNull())
{
qCritical() << tr("Unable to get sheet page settings");
@ -4219,7 +4219,7 @@ void VPMainWindow::on_actionPrintTiledLayout_triggered()
QCoreApplication::applicationVersion());
QList<VPSheetPtr> sheets = m_layout->GetSheets();
VPSheetPtr firstSheet = sheets.first();
const VPSheetPtr &firstSheet = ConstFirst(sheets);
if (firstSheet.isNull())
{
qCritical() << tr("Unable to get sheet page settings");
@ -4258,7 +4258,7 @@ void VPMainWindow::on_actionPrintPreviewTiledLayout_triggered()
QList<VPSheetPtr> sheets = m_layout->GetSheets();
VPSheetPtr firstSheet = sheets.first();
const VPSheetPtr &firstSheet = ConstFirst(sheets);
if (firstSheet.isNull())
{
qCritical() << tr("Unable to get sheet page settings");

View File

@ -30,6 +30,7 @@
#include "ui_dialogmdatabase.h"
#include "../mapplication.h"
#include "../vpatterndb/measurements.h"
#include "../vmisc/compatibility.h"
#include <QKeyEvent>
#include <QMenu>
@ -409,7 +410,7 @@ void DialogMDataBase::FilterMeasurements(const QString &search)
FilterGroup(groupQ, search);
const QList<QTreeWidgetItem *> list = ui->treeWidget->selectedItems();
list.isEmpty() ? ShowDescription(nullptr, -1) : ShowDescription(list.first(), 0);
list.isEmpty() ? ShowDescription(nullptr, -1) : ShowDescription(ConstFirst(list), 0);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -528,7 +528,7 @@ QMap<int, QString> VCommandLine::OptUserMaterials() const
}
bool ok = false;
const int number = parts.first().toInt(&ok);
const int number = ConstFirst<QString>(parts).toInt(&ok);
if (not ok or number < 1 or number > userMaterialPlaceholdersQuantity)
{
@ -537,7 +537,7 @@ QMap<int, QString> VCommandLine::OptUserMaterials() const
const_cast<VCommandLine*>(this)->parser.showHelp(V_EX_USAGE);
}
userMaterials.insert(number, parts.last());
userMaterials.insert(number, ConstLast<QString>(parts));
}
return userMaterials;

View File

@ -3503,7 +3503,7 @@ void MainWindow::on_actionOpen_triggered()
else
{
//Absolute path to last open file
dir = QFileInfo(files.first()).absolutePath();
dir = QFileInfo(ConstFirst<QString>(files)).absolutePath();
}
qCDebug(vMainWindow, "Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir));
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr,
@ -6691,7 +6691,7 @@ void MainWindow::ProcessCMD()
VAbstractValApplication::VApp()->SetUserMaterials(cmd->OptUserMaterials());
const bool loaded = LoadPattern(args.first(), cmd->OptMeasurePath());
const bool loaded = LoadPattern(ConstFirst<QString>(args), cmd->OptMeasurePath());
if (not loaded)
{

View File

@ -269,7 +269,7 @@ void VPattern::setCurrentData()
return;
}
const quint32 id = localHistory.last().getId();
const quint32 id = ConstLast(localHistory).getId();
qCDebug(vXML, "Resoring data from tool with id %u", id);
if (tools.size() > 0)
@ -325,7 +325,7 @@ VContainer VPattern::GetCompleteData() const
return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace()));
}
const quint32 id = (countPP == 1 ? history.last().getId() : LastToolId());
const quint32 id = (countPP == 1 ? ConstLast(history).getId() : LastToolId());
if (id == NULL_ID)
{
@ -360,7 +360,7 @@ VContainer VPattern::GetCompletePPData(const QString &name) const
return (data != nullptr ? *data : VContainer(nullptr, nullptr, VContainer::UniqueNamespace()));
}
const quint32 id = (countPP == 1 ? history.last().getId() : PPLastToolId(name));
const quint32 id = (countPP == 1 ? ConstLast(history).getId() : PPLastToolId(name));
if (id == NULL_ID)
{
@ -3689,7 +3689,7 @@ quint32 VPattern::PPLastToolId(const QString &name) const
{
const QVector<VToolRecord> localHistory = getLocalHistory(name);
return (not localHistory.isEmpty() ? localHistory.last().getId() : NULL_ID);
return (not localHistory.isEmpty() ? ConstLast(localHistory).getId() : NULL_ID);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -35,6 +35,8 @@
#include <QStringList>
#include <QSvgRenderer>
#include "../vmisc/compatibility.h"
//---------------------------------------------------------------------------------------------------------------------
auto IsMimeTypeImage(const QMimeType &mime) -> bool
{
@ -66,7 +68,7 @@ auto MimeTypeFromByteArray(const QByteArray &data) -> QMimeType
{
QMimeType mime = QMimeDatabase().mimeTypeForData(data);
QSet<QString> aliases = mime.aliases().toSet();
QSet<QString> aliases = ConvertToSet<QString>(mime.aliases());
aliases.insert(mime.name());
QSet<QString> gzipMime {"application/gzip", "application/x-gzip"};

View File

@ -28,6 +28,7 @@
#include "vbackgroundpatternimage.h"
#include "utils.h"
#include "../vmisc/compatibility.h"
#include <QMimeType>
#include <QDebug>
@ -131,7 +132,7 @@ auto VBackgroundPatternImage::IsValid() const -> bool
}
QMimeType mime = MimeTypeFromData();
QSet<QString> aliases = mime.aliases().toSet();
QSet<QString> aliases = ConvertToSet<QString>(mime.aliases());
aliases.insert(mime.name());
if (not aliases.contains(m_contentType))

View File

@ -40,6 +40,7 @@
#include <QFile>
#include "utils.h"
#include "../vmisc/compatibility.h"
//---------------------------------------------------------------------------------------------------------------------
@ -110,7 +111,7 @@ auto VPatternImage::IsValid() const -> bool
}
QMimeType mime = MimeTypeFromData();
QSet<QString> aliases = mime.aliases().toSet();
QSet<QString> aliases = ConvertToSet<QString>(mime.aliases());
aliases.insert(mime.name());
if (not aliases.contains(m_contentType))

View File

@ -177,7 +177,7 @@ void VDxfEngine::drawPath(const QPainterPath &path)
poly->lWeight = DRW_LW_Conv::widthByLayer;
poly->lineType = getPenStyle();
if (polygon.size() > 1 && polygon.first() == polygon.last())
if (polygon.size() > 1 && ConstFirst(polygon) == ConstLast(polygon))
{
poly->flags |= 0x1; // closed
}
@ -199,7 +199,7 @@ void VDxfEngine::drawPath(const QPainterPath &path)
poly->color = getPenColor();
poly->lWeight = DRW_LW_Conv::widthByLayer;
poly->lineType = getPenStyle();
if (polygon.size() > 1 && polygon.first() == polygon.last())
if (polygon.size() > 1 && ConstFirst(polygon) == ConstLast(polygon))
{
poly->flags |= 0x1; // closed
}
@ -791,7 +791,7 @@ void VDxfEngine::ExportAAMAGrainline(dx_ifaceBlock *detailBlock, const VLayoutPi
const QVector<QPointF> grainline = detail.GetMappedGrainline();
if (grainline.count() > 1)
{
if (DRW_Entity *e = AAMALine(QLineF(grainline.first(), grainline.last()), QChar('7')))
if (DRW_Entity *e = AAMALine(QLineF(ConstFirst(grainline), ConstLast(grainline)), QChar('7')))
{
detailBlock->ent.push_back(e);
}
@ -1072,22 +1072,22 @@ void VDxfEngine::ExportASTMNotch(dx_ifaceBlock *detailBlock, const VLayoutPiece
}
else if (passmark.type == PassmarkLineType::VMark || passmark.type == PassmarkLineType::VMark2)
{
QLineF boundaryLine = QLineF(passmark.lines.first().p2(), passmark.lines.last().p2());
QLineF boundaryLine(ConstFirst(passmark.lines).p2(), ConstLast(passmark.lines).p2());
notch->thickness = FromPixel(boundaryLine.length(), varInsunits); // width
notch->layer = "4";
}
else if (passmark.type == PassmarkLineType::TMark)
{
qreal width = FromPixel(passmark.lines.last().length(), varInsunits);
qreal width = FromPixel(ConstLast(passmark.lines).length(), varInsunits);
notch->thickness = FromPixel(width, varInsunits);
notch->layer = "80";
}
else if (passmark.type == PassmarkLineType::BoxMark)
{
QPointF start = passmark.lines.first().p1();
QPointF end = passmark.lines.last().p2();
QPointF start = ConstFirst(passmark.lines).p1();
QPointF end = ConstLast(passmark.lines).p2();
notch->layer = "81";
@ -1095,8 +1095,8 @@ void VDxfEngine::ExportASTMNotch(dx_ifaceBlock *detailBlock, const VLayoutPiece
}
else if (passmark.type == PassmarkLineType::UMark)
{
QPointF start = passmark.lines.first().p1();
QPointF end = passmark.lines.last().p2();
QPointF start = ConstFirst(passmark.lines).p1();
QPointF end = ConstLast(passmark.lines).p2();
notch->thickness = FromPixel(QLineF(start, end).length(), varInsunits);
@ -1184,7 +1184,7 @@ P *VDxfEngine::CreateAAMAPolygon(const QVector<QPointF> &polygon, const QString
}
else
{
if (polygon.size() > 1 && polygon.first() == polygon.last())
if (polygon.size() > 1 && ConstFirst(polygon) == ConstLast(polygon))
{
poly->flags |= 0x1; // closed
}

View File

@ -95,8 +95,8 @@ QVector<QPointF> VAbstractCurve::GetSegmentPoints(const QVector<QPointF> &points
if (begin == end)
{
start = segment.first();
finish = segment.last();
start = ConstFirst(segment);
finish = ConstLast(segment);
}
bool ok = false;
@ -157,7 +157,7 @@ QVector<QPointF> VAbstractCurve::FromBegin(const QVector<QPointF> &points, const
{
if (points.count() >= 2)
{
if (points.first().toPoint() == begin.toPoint())
if (ConstFirst(points).toPoint() == begin.toPoint())
{
if (ok != nullptr)
{
@ -258,7 +258,7 @@ qreal VAbstractCurve::GetLengthByPoint(const QPointF &point) const
return -1;
}
if (points.first().toPoint() == point.toPoint())
if (ConstFirst(points).toPoint() == point.toPoint())
{
return 0;
}

View File

@ -37,6 +37,7 @@
#include "vcubicbezierpath_p.h"
#include "vspline.h"
#include "vsplinepoint.h"
#include "../vmisc/compatibility.h"
//---------------------------------------------------------------------------------------------------------------------
VCubicBezierPath::VCubicBezierPath(quint32 idObject, Draw mode)
@ -361,7 +362,7 @@ VPointF VCubicBezierPath::FirstPoint() const
{
if (not d->path.isEmpty())
{
return d->path.first();
return ConstFirst(d->path);
}
else
{

View File

@ -364,7 +364,7 @@ PlaceLabelImg VPlaceLabelItem::LabelShape() const
QPolygonF shape3(arc.GetPoints());
if (not shape3.isClosed() && not shape3.isEmpty())
{
shape3 << shape3.first();
shape3 << ConstFirst(shape3);
}
return PlaceLabelImg({t.map(shape1), t.map(shape2), t.map(shape3)});
@ -378,7 +378,7 @@ PlaceLabelImg VPlaceLabelItem::LabelShape() const
QPolygonF circle(arc.GetPoints());
if (not circle.isClosed() && not circle.isEmpty())
{
circle << circle.first();
circle << ConstFirst(circle);
}
return PlaceLabelImg({t.map(circle)});
@ -428,7 +428,7 @@ QPainterPath VPlaceLabelItem::LabelShapePath(const PlaceLabelImg &shape)
{
if (not p.isEmpty())
{
path.moveTo(p.first());
path.moveTo(ConstFirst(p));
path.addPolygon(p);
}
}

View File

@ -207,7 +207,7 @@ VSplinePath::~VSplinePath()
*/
void VSplinePath::append(const VSplinePoint &point)
{
if (d->path.size() > 0 && static_cast<QPointF>(d->path.last().P()) == static_cast<QPointF>(point.P())) //-V807
if (d->path.size() > 0 && static_cast<QPointF>(ConstLast(d->path).P()) == static_cast<QPointF>(point.P())) //-V807
{
return;
}

View File

@ -607,7 +607,7 @@ QVector<VRawSAPoint> AngleBySecondRightAngle(QVector<VRawSAPoint> points, QPoint
if (success)
{
points = temp;
px = points.last();
px = ConstLast(points);
}
if (countBefore > 0)
@ -747,9 +747,9 @@ bool Rollback(QVector<VRawSAPoint> &points, const QLineF &edge)
if (not points.isEmpty())
{
if (points.last().toPoint() != points.first().toPoint())
if (ConstLast(points).toPoint() != ConstFirst(points).toPoint())
{
points.append(points.first());// Should be always closed
points.append(ConstFirst(points));// Should be always closed
}
}
}
@ -812,7 +812,7 @@ void RollbackByPointsIntersection(QVector<VRawSAPoint> &ekvPoints, const QVector
const QLineF bigLine1 = VAbstractPiece::ParallelLine(points.at(points.size()-2), points.at(0), width);
QVector<VRawSAPoint> temp = ekvPoints;
temp.insert(ekvPoints.size()-1, bigLine1.p2());
bool success = Rollback(temp, QLineF(points.last(), points.at(1)));
bool success = Rollback(temp, QLineF(ConstLast(points), points.at(1)));
if (success)
{
@ -831,7 +831,7 @@ void RollbackBySecondEdgeRightAngle(QVector<VRawSAPoint> &ekvPoints, const QVect
{
if (not ekvPoints.isEmpty())
{
const QLineF edge(points.last(), points.at(1));
const QLineF edge(ConstLast(points), points.at(1));
const QLineF bigLine1 = VAbstractPiece::ParallelLine(points.at(points.size()-2), points.at(0), width);
QPointF px;
@ -843,7 +843,7 @@ void RollbackBySecondEdgeRightAngle(QVector<VRawSAPoint> &ekvPoints, const QVect
{
if (ekvPoints.size() > 3)
{
const QLineF edge1(ekvPoints.at(ekvPoints.size()-2), ekvPoints.last());
const QLineF edge1(ekvPoints.at(ekvPoints.size()-2), ConstLast(ekvPoints));
const QLineF edge2(ekvPoints.at(0), ekvPoints.at(1));
QPointF crosPoint;
@ -868,7 +868,7 @@ void RollbackBySecondEdgeRightAngle(QVector<VRawSAPoint> &ekvPoints, const QVect
if (success)
{
ekvPoints = temp;
px = ekvPoints.last();
px = ConstLast(ekvPoints);
}
QLineF seam(px, points.at(1));
@ -878,15 +878,15 @@ void RollbackBySecondEdgeRightAngle(QVector<VRawSAPoint> &ekvPoints, const QVect
if (not ekvPoints.isEmpty())
{
ekvPoints.append(ekvPoints.first());
ekvPoints.append(ConstFirst(ekvPoints));
}
}
if (not ekvPoints.isEmpty())
{
if (ekvPoints.last().toPoint() != ekvPoints.first().toPoint())
if (ConstLast(ekvPoints).toPoint() != ConstFirst(ekvPoints).toPoint())
{
ekvPoints.append(ekvPoints.first());// Should be always closed
ekvPoints.append(ConstFirst(ekvPoints));// Should be always closed
}
}
}
@ -1081,7 +1081,7 @@ QVector<QPointF> VAbstractPiece::Equidistant(QVector<VSAPoint> points, qreal wid
return QVector<QPointF>();
}
if (points.last().toPoint() != points.first().toPoint())
if (ConstLast(points).toPoint() != ConstFirst(points).toPoint())
{
points.append(points.at(0));// Should be always closed
}
@ -1101,7 +1101,7 @@ QVector<QPointF> VAbstractPiece::Equidistant(QVector<VSAPoint> points, qreal wid
{//last point
if (not ekvPoints.isEmpty())
{
ekvPoints.append(ekvPoints.first());
ekvPoints.append(ConstFirst(ekvPoints));
}
continue;
}
@ -1115,7 +1115,7 @@ QVector<QPointF> VAbstractPiece::Equidistant(QVector<VSAPoint> points, qreal wid
QT_WARNING_DISABLE_GCC("-Wswitch-default")
// This check helps to find missed angle types in the switch
Q_STATIC_ASSERT_X(static_cast<int>(PieceNodeAngle::LAST_ONE_DO_NOT_USE) == 7, "Not all types were handled.");
switch (points.last().GetAngleType())
switch (ConstLast(points).GetAngleType())
{
case PieceNodeAngle::LAST_ONE_DO_NOT_USE:
case PieceNodeAngle::ByFirstEdgeRightAngle:
@ -1229,7 +1229,7 @@ auto VAbstractPiece::CheckLoops(const QVector<VRawSAPoint> &points) -> QVector<Q
{
loopFound = false;
const bool pathClosed = (points.first() == points.last());
const bool pathClosed = (ConstFirst(points) == ConstLast(points));
QVector<VRawSAPoint> ekvPoints;
ekvPoints.reserve(points.size());

View File

@ -222,9 +222,9 @@ QVector<T> VAbstractPiece::CorrectEquidistantPoints(const QVector<T> &points, bo
}
}
if (not buf2.isEmpty() && buf2.first() != buf2.last())
if (not buf2.isEmpty() && ConstFirst(buf2) != ConstLast(buf2))
{
buf2.append(buf2.first());
buf2.append(ConstFirst(buf2));
}
buf2 = RemoveDublicates(buf2, false);
@ -245,7 +245,7 @@ QVector<T> VAbstractPiece::RemoveDublicates(const QVector<T> &points, bool remov
QVector<T> p;
p.reserve(points.size());
p.append(points.first());
p.append(ConstFirst(points));
for (int i = 0; i < points.size(); ++i)
{
@ -266,7 +266,7 @@ QVector<T> VAbstractPiece::RemoveDublicates(const QVector<T> &points, bool remov
{
// Path can't be closed
// See issue #686
if (VFuzzyComparePoints(p.first(), p.last()))
if (VFuzzyComparePoints(ConstFirst(p), ConstLast(p)))
{
p.removeLast();
}

View File

@ -49,7 +49,7 @@ void AppendToContour(QVector<QPointF> &contour, QPointF point)
{
if (not contour.isEmpty())
{
if (not VFuzzyComparePoints(contour.last(), point))
if (not VFuzzyComparePoints(ConstLast(contour), point))
{
contour.append(point);
}
@ -68,7 +68,7 @@ QVector<QPointF> OptimizeCombining(const QVector<QPointF> &contour, const QPoint
return contour;
}
QPointF withdrawFirst = contour.last();
QPointF withdrawFirst = ConstLast(contour);
bool optimize = false;
int count = 0;
int cutIndex = -1;
@ -148,7 +148,7 @@ void VContour::CeateEmptySheetContour()
if (d->globalContour.isEmpty())
{
d->globalContour = CutEmptySheetEdge();
d->globalContour.append(d->globalContour.first()); // Close path
d->globalContour.append(ConstFirst(d->globalContour)); // Close path
ResetAttributes();
}

View File

@ -402,10 +402,11 @@ void VLayoutExporter::PdfToPs(const QStringList &params)
QGuiApplication::restoreOverrideCursor();
#endif
QFile f(params.last());
QFile f(ConstLast<QString>(params));
if (not f.exists())
{
qCritical() << qUtf8Printable(tr("Creating file '%1' failed! %2").arg(params.last(), proc.errorString()));
qCritical() << qUtf8Printable(tr("Creating file '%1' failed! %2")
.arg(ConstLast<QString>(params), proc.errorString()));
}
}

View File

@ -695,7 +695,7 @@ VLayoutPaper VLayoutGenerator::MasterPage() const
{
if (papers.size() < 2)
{
return papers.first();
return ConstFirst(papers);
}
QList<QList<VLayoutPiece> > nDetails;

View File

@ -339,11 +339,11 @@ QVector<VLayoutPassmark> ConvertPassmarks(const VPiece &piece, const VContainer
if (side == PassmarkSide::All || side == PassmarkSide::Right)
{
layoutPassmark.baseLine = baseLines.first();
layoutPassmark.baseLine = ConstFirst(baseLines);
}
else if (side == PassmarkSide::Right)
{
layoutPassmark.baseLine = baseLines.last();
layoutPassmark.baseLine = ConstLast(baseLines);
}
const QVector<QLineF> lines = passmark.SAPassmark(piece, pattern, side);
@ -761,7 +761,7 @@ QPointF VLayoutPiece::GetPieceTextPosition() const
{
if (d->detailLabel.count() > 2)
{
return d->matrix.map(d->detailLabel.first());
return d->matrix.map(ConstFirst(d->detailLabel));
}
else
{
@ -843,7 +843,7 @@ QPointF VLayoutPiece::GetPatternTextPosition() const
{
if (d->patternInfo.count() > 2)
{
return d->matrix.map(d->patternInfo.first());
return d->matrix.map(ConstFirst(d->patternInfo));
}
else
{
@ -1335,7 +1335,7 @@ QPainterPath VLayoutPiece::ContourPath() const
// Draw seam allowance
QVector<QPointF>points = GetSeamAllowancePoints();
if (points.last().toPoint() != points.first().toPoint())
if (ConstLast(points).toPoint() != ConstFirst(points).toPoint())
{
points.append(points.at(0));// Should be always closed
}
@ -1475,7 +1475,7 @@ qreal VLayoutPiece::BiggestEdge() const
//---------------------------------------------------------------------------------------------------------------------
QRectF VLayoutPiece::BoundingRect(QVector<QPointF> points)
{
points.append(points.first());
points.append(ConstFirst(points));
return QPolygonF(points).boundingRect();
}

View File

@ -297,7 +297,7 @@ void VPosition::SaveCandidate(VBestSquare &bestResult, const VLayoutPiece &detai
}
QVector<QPointF> newGContour = m_data.gContour.UniteWithContour(detail, globalI, detJ, type);
newGContour.append(newGContour.first());
newGContour.append(ConstFirst(newGContour));
const QSizeF size = QPolygonF(newGContour).boundingRect().size();
const QRectF boundingRect = detail.MappedDetailBoundingRect();
const qreal depthPosition = m_data.isOriginPaperOrientationPortrait ? boundingRect.y() : boundingRect.x();

View File

@ -51,6 +51,7 @@
#include "../ifc/exception/vexception.h"
#include "../vmisc/vmath.h"
#include "../vpropertyexplorer/checkablemessagebox.h"
#include "../vmisc/compatibility.h"
namespace
{
@ -125,10 +126,10 @@ auto PreparePrinter(const QPrinterInfo &info, QPrinter::PrinterMode mode) -> QSh
const QStringList list = QPrinterInfo::availablePrinterNames();
if(list.isEmpty())
{
return QSharedPointer<QPrinter>();
return {};
}
tmpInfo = QPrinterInfo::printerInfo(list.first());
tmpInfo = QPrinterInfo::printerInfo(ConstFirst<QString>(list));
}
auto printer = QSharedPointer<QPrinter>(new QPrinter(tmpInfo, mode));

View File

@ -35,6 +35,7 @@
#include <Qt>
#include "../vmisc/def.h"
#include "../vmisc/compatibility.h"
const int VTableSearch::MaxHistoryRecords = 10;
@ -161,7 +162,7 @@ auto VTableSearch::FindCurrentMatchIndex() const -> int
return 0;
}
QTableWidgetItem* selectedItem = selectedItems.first();
QTableWidgetItem* selectedItem = ConstFirst(selectedItems);
for (int i=0; i<searchList.size(); ++i)
{

View File

@ -63,14 +63,14 @@ PassmarkStatus GetSeamPassmarkSAPoint(const VPiecePassmarkData &passmarkData, co
if (ekvPoints.size() == 1 || ekvPoints.size() > 2)
{
point = ekvPoints.first();
point = ConstFirst(ekvPoints);
}
else if (ekvPoints.size() == 2)
{
if(passmarkData.passmarkSAPoint.GetAngleType() == PieceNodeAngle::ByFirstEdgeSymmetry ||
passmarkData.passmarkSAPoint.GetAngleType() == PieceNodeAngle::ByFirstEdgeRightAngle)
{
point = ekvPoints.first();
point = ConstFirst(ekvPoints);
}
else
{
@ -135,7 +135,7 @@ bool FixNotchPoint(const QVector<QPointF> &seamAllowance, const QPointF &notchBa
const QVector<QPointF> points = VAbstractCurve::CurveIntersectLine(seamAllowance, axis);
if (points.size() == 1)
{
*notch = points.first();
*notch = ConstFirst(points);
}
}
@ -441,18 +441,18 @@ QVector<QLineF> CreatePassmarkLines(PassmarkLineType lineType, PassmarkAngleType
{
if (angleType == PassmarkAngleType::Straightforward)
{
passmarksLines += (*create)(lines.first(), seamAllowance);
passmarksLines += (*create)(ConstFirst(lines), seamAllowance);
}
else
{
if (side == PassmarkSide::All || side == PassmarkSide::Left)
{
passmarksLines += (*create)(lines.first(), seamAllowance);
passmarksLines += (*create)(ConstFirst(lines), seamAllowance);
}
if (side == PassmarkSide::All || side == PassmarkSide::Right)
{
passmarksLines += (*create)(lines.last(), seamAllowance);
passmarksLines += (*create)(ConstLast(lines), seamAllowance);
}
}
};
@ -461,18 +461,18 @@ QVector<QLineF> CreatePassmarkLines(PassmarkLineType lineType, PassmarkAngleType
{
if (angleType == PassmarkAngleType::Straightforward)
{
passmarksLines += (*create)(lines.first());
passmarksLines += (*create)(ConstFirst(lines));
}
else
{
if (side == PassmarkSide::All || side == PassmarkSide::Left)
{
passmarksLines += (*create)(lines.first());
passmarksLines += (*create)(ConstFirst(lines));
}
if (side == PassmarkSide::All || side == PassmarkSide::Right)
{
passmarksLines += (*create)(lines.last());
passmarksLines += (*create)(ConstLast(lines));
}
}
};
@ -519,7 +519,7 @@ QVector<QLineF> CreatePassmarkLines(PassmarkLineType lineType, PassmarkAngleType
switch (lineType)
{
case PassmarkLineType::TMark:
passmarksLines += CreateTMarkPassmark(lines.first());
passmarksLines += CreateTMarkPassmark(ConstFirst(lines));
break;
case PassmarkLineType::OneLine:
case PassmarkLineType::TwoLines:
@ -529,7 +529,7 @@ QVector<QLineF> CreatePassmarkLines(PassmarkLineType lineType, PassmarkAngleType
case PassmarkLineType::UMark:
case PassmarkLineType::BoxMark:
default:
passmarksLines.append(lines.first());
passmarksLines.append(ConstFirst(lines));
break;
}
}
@ -764,7 +764,7 @@ QLineF VPassmark::FindIntersection(const QLineF &line, const QVector<QPointF> &s
QVector<QPointF> intersections = VAbstractCurve::CurveIntersectLine(seamAllowance, testLine);
if (not intersections.isEmpty())
{
return QLineF(line.p1(), intersections.last());
return QLineF(line.p1(), ConstLast(intersections));
}
return line;
@ -924,9 +924,9 @@ QVector<QLineF> VPassmark::SAPassmarkBaseLine(const QVector<QPointF> &seamAllowa
if (not intersections.isEmpty())
{
if (intersections.last() != m_data.passmarkSAPoint)
if (ConstLast(intersections) != m_data.passmarkSAPoint)
{
line = QLineF(intersections.last(), m_data.passmarkSAPoint);
line = QLineF(ConstLast(intersections), m_data.passmarkSAPoint);
bool ok = false;
const qreal length = PassmarkLength(m_data, width, ok);

View File

@ -933,7 +933,7 @@ bool VPiece::GetPassmarkSAPoint(const QVector<VPieceNode> &path, int index, cons
return false;
}
point = points.first();
point = ConstFirst(points);
return true;
}

View File

@ -76,7 +76,7 @@ VSAPoint CurveStartPoint(VSAPoint candidate, const VContainer *data, const VPiec
if (not points.isEmpty())
{
QPointF end; // Last point for this curve show start of next segment
node.GetReverse() ? end = points.first() : end = points.last();
node.GetReverse() ? end = ConstFirst(points) : end = ConstLast(points);
if (VAbstractCurve::IsPointOnCurve(curvePoints, end))
{
candidate = VSAPoint(end);
@ -103,7 +103,7 @@ VSAPoint CurveEndPoint(VSAPoint candidate, const VContainer *data, const VPieceN
if (not points.isEmpty())
{
QPointF begin;// First point for this curve show finish of previous segment
node.GetReverse() ? begin = points.last() : begin = points.first();
node.GetReverse() ? begin = ConstLast(points) : begin = ConstFirst(points);
if (VAbstractCurve::IsPointOnCurve(curvePoints, begin))
{
candidate = VSAPoint(begin);
@ -155,7 +155,7 @@ qreal FindTipDirection(const QVector<QPointF> &points)
return 0;
}
const QPointF first = points.first();
const QPointF &first = ConstFirst(points);
for(int i = 1; i < points.size(); ++i)
{
@ -179,7 +179,7 @@ bool IntersectionWithCuttingCountour(const QVector<QPointF> &cuttingPath, const
return false;
}
const QPointF first = points.first();
const QPointF &first = ConstFirst(points);
if (VAbstractCurve::IsPointOnCurve(cuttingPath, first))
{ // Point is already part of a cutting countour
@ -552,7 +552,7 @@ VSAPoint VPiecePath::StartSegment(const VContainer *data, const QVector<VPieceNo
}
VSAPoint begin;
reverse ? begin = VSAPoint(points.last()) : begin = VSAPoint(points.first());
reverse ? begin = VSAPoint(ConstLast(points)) : begin = VSAPoint(ConstFirst(points));
if (nodes.size() > 1)
{
@ -583,7 +583,7 @@ VSAPoint VPiecePath::EndSegment(const VContainer *data, const QVector<VPieceNode
}
VSAPoint end;
reverse ? end = VSAPoint(points.first()) : end = VSAPoint(points.last());
reverse ? end = VSAPoint(ConstFirst(points)) : end = VSAPoint(ConstLast(points));
if (nodes.size() > 2)
{

View File

@ -258,7 +258,7 @@ auto VToolSeamAllowance::Duplicate(VToolSeamAllowanceInitData &initData) -> VToo
dupDetail.SetUUID(QUuid::createUuid());
const QMap<quint32, quint32> mappedPins = DuplicatePins(initData.detail.GetPins(), initData);
dupDetail.SetPins(mappedPins.values().toVector());
dupDetail.SetPins(ConvertToVector(mappedPins.values()));
dupDetail.SetPatternPieceData(FixLabelPins(initData.detail.GetPatternPieceData(), mappedPins));
dupDetail.SetPatternInfo(FixLabelPins(initData.detail.GetPatternInfo(), mappedPins));
dupDetail.SetGrainlineGeometry(FixGrainlinePins(initData.detail.GetGrainlineGeometry(), mappedPins));

View File

@ -43,6 +43,7 @@
#include "vispath.h"
#include "../vwidgets/scalesceneitems.h"
#include "../vmisc/vmodifierkey.h"
#include "../vmisc/compatibility.h"
//---------------------------------------------------------------------------------------------------------------------
VisToolCubicBezierPath::VisToolCubicBezierPath(const VContainer *data, QGraphicsItem *parent)
@ -193,7 +194,7 @@ void VisToolCubicBezierPath::Creating(const QVector<VPointF> &pathPoints, int po
{
case 0:
{
const VPointF p1 = pathPoints.last();
const VPointF &p1 = ConstLast(pathPoints);
if (pathPoints.size() >= 4)
{
QLineF p1p2(static_cast<QPointF>(p1), Visualization::scenePos);

View File

@ -88,12 +88,12 @@ void VisToolPiece::RefreshGeometry()
DrawPath(path, m_cachedCurvesPath.at(i), supportColor);
}
DrawLine(m_line1, QLineF(m_cachedMainPathPoints.first(), Visualization::scenePos), supportColor,
DrawLine(m_line1, QLineF(ConstFirst(m_cachedMainPathPoints), Visualization::scenePos), supportColor,
Qt::DashLine);
if (m_cachedMainPathPoints.size() > 1)
{
DrawLine(m_line2, QLineF(m_cachedMainPathPoints.last(), Visualization::scenePos), supportColor,
DrawLine(m_line2, QLineF(ConstLast(m_cachedMainPathPoints), Visualization::scenePos), supportColor,
Qt::DashLine);
}
}

View File

@ -30,6 +30,7 @@
#include "../vwidgets/vsimplepoint.h"
#include "../vgeometry/vpointf.h"
#include "../vwidgets/scalesceneitems.h"
#include "../vmisc/compatibility.h"
#include <QGraphicsSceneMouseEvent>
@ -69,7 +70,7 @@ void VisToolPiecePath::RefreshGeometry()
const QVector<QPointF> points = m_path.PathPoints(Visualization::data);
if (points.size() > 0)
{
DrawLine(m_line, QLineF(points.last(), Visualization::scenePos), supportColor, Qt::DashLine);
DrawLine(m_line, QLineF(ConstLast(points), Visualization::scenePos), supportColor, Qt::DashLine);
}
}
}

View File

@ -29,6 +29,7 @@
#include "global.h"
#include "../vmisc/def.h"
#include "../vmisc/vabstractapplication.h"
#include "../vmisc/compatibility.h"
#include <QGraphicsItem>
#include <QGraphicsScene>
@ -52,7 +53,7 @@ qreal SceneScale(QGraphicsScene *scene)
const QList<QGraphicsView *> views = scene->views();
if (not views.isEmpty())
{
scale = views.first()->transform().m11();
scale = ConstFirst(views)->transform().m11();
}
}

View File

@ -76,7 +76,7 @@ QStringList RecentFiles(const QStringList &paths)
QVector<QStringList> table;
table.reserve(paths.size());
for(auto &path : paths)
for(const auto &path : paths)
{
table.append(SplitFilePaths(path));
}
@ -84,7 +84,7 @@ QStringList RecentFiles(const QStringList &paths)
auto CreateOptimized = [table](int tableRow)
{
QStringList optimized;
QStringList path = table.at(tableRow);
const QStringList& path = table.at(tableRow);
for (int count = 1; count <= path.size(); ++count)
{
bool isUnique = true;
@ -113,7 +113,8 @@ QStringList RecentFiles(const QStringList &paths)
if (optimized.size() >= 3)
{
optimized = QStringList({optimized.first(), QStringLiteral(""), optimized.last()});
optimized = QStringList({ConstFirst<QString>(optimized), QStringLiteral(""),
ConstLast<QString>(optimized)});
}
return optimized;

View File

@ -45,11 +45,11 @@ void PrepareTestCase(const QPointF &center, qreal startAngle, qreal endAngle)
const QString testStartAngle = QString("Test start angel. Arc radius %1, start angle %2, end angle %3")
.arg(radius).arg(startAngle).arg(endAngle);
QTest::newRow(qUtf8Printable(testStartAngle)) << center << startAngle << points << points.first() << true;
QTest::newRow(qUtf8Printable(testStartAngle)) << center << startAngle << points << ConstFirst(points) << true;
const QString testEndAngle = QString("Test end angel. Arc radius %1, start angle %2, end angle %3")
.arg(radius).arg(startAngle).arg(endAngle);
QTest::newRow(qUtf8Printable(testEndAngle)) << center << endAngle << points << points.last() << true;
QTest::newRow(qUtf8Printable(testEndAngle)) << center << endAngle << points << ConstLast(points) << true;
radius += UnitConvertor(5, Unit::Cm, Unit::Px);
}