diff --git a/src/app/puzzle/vpcarrouselpiecelist.cpp b/src/app/puzzle/vpcarrouselpiecelist.cpp index 00ca57d9d..c9ee011eb 100644 --- a/src/app/puzzle/vpcarrouselpiecelist.cpp +++ b/src/app/puzzle/vpcarrouselpiecelist.cpp @@ -80,10 +80,10 @@ void VPCarrouselPieceList::Refresh() QList pieces = m_pieceList->GetPieces(); // create the corresponding carrousel pieces - for (auto piece : pieces) + for (auto *piece : pieces) { // update the label of the piece - VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this); + auto* carrouselpiece = new VPCarrouselPiece(piece, this); carrouselpiece->setSelected(piece->GetIsSelected()); connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); } @@ -120,7 +120,7 @@ void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event) if (!(event->modifiers() & Qt::ControlModifier)) { // clearSelection doesn't work properly here so we go through the elements. - for(auto item: selectedItems()) + for(auto *item: selectedItems()) { item->setSelected(false); } @@ -157,8 +157,8 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions) VPCarrouselPiece *pieceItem = static_cast (_item); // starts the dragging - QDrag *drag = new QDrag(this); - VPMimeDataPiece *mimeData = new VPMimeDataPiece(); + auto *drag = new QDrag(this); + auto *mimeData = new VPMimeDataPiece(); VPPiece* piece = pieceItem->GetPiece(); mimeData->SetPiecePtr(piece); mimeData->setObjectName("piecePointer"); @@ -179,8 +179,8 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions) //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e) { - qCDebug(pCarrouselPieceList, "drag move"); - e->acceptProposedAction(); + qCDebug(pCarrouselPieceList, "drag move"); + e->acceptProposedAction(); } //--------------------------------------------------------------------------------------------------------------------- @@ -226,7 +226,6 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event) } } - //--------------------------------------------------------------------------------------------------------------------- void VPCarrouselPieceList::on_ActionPieceMovedToPieceList() { diff --git a/src/app/puzzle/vpgraphicspiece.cpp b/src/app/puzzle/vpgraphicspiece.cpp index c0973ce34..073fb75b8 100644 --- a/src/app/puzzle/vpgraphicspiece.cpp +++ b/src/app/puzzle/vpgraphicspiece.cpp @@ -284,7 +284,7 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event) // change the cursor when clicking the left button if((event->button() == Qt::LeftButton)) { - if(event->modifiers() & Qt::AltModifier) + if((event->modifiers() & Qt::AltModifier) != 0U) { setCursor(m_rotateCursor); } diff --git a/src/app/puzzle/vplayout.cpp b/src/app/puzzle/vplayout.cpp index 539bc9e0c..cf4dc79b0 100644 --- a/src/app/puzzle/vplayout.cpp +++ b/src/app/puzzle/vplayout.cpp @@ -38,10 +38,9 @@ Q_LOGGING_CATEGORY(pLayout, "p.layout") //--------------------------------------------------------------------------------------------------------------------- VPLayout::VPLayout() : m_unplacedPieceList(new VPPieceList(this)), - m_trashPieceList(new VPPieceList(this)), - m_sheets(QList()) + m_trashPieceList(new VPPieceList(this)) { - m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces")); + m_unplacedPieceList->SetName(tr("Unplaced pieces")); } //--------------------------------------------------------------------------------------------------------------------- @@ -92,14 +91,14 @@ QList VPLayout::GetSelectedPieces() QList pieceLists = QList(); pieceLists.append(m_unplacedPieceList); - for (auto sheet : m_sheets) + for (auto *sheet : m_sheets) { pieceLists.append(sheet->GetPieceList()); } - for (auto pieceList : pieceLists) + for (auto *pieceList : pieceLists) { - for (auto piece : pieceList->GetPieces()) + for (auto *piece : pieceList->GetPieces()) { if(piece->GetIsSelected()) { @@ -111,7 +110,6 @@ QList VPLayout::GetSelectedPieces() return result; } - //--------------------------------------------------------------------------------------------------------------------- void VPLayout::SetUnit(Unit unit) { @@ -124,7 +122,6 @@ Unit VPLayout::GetUnit() const return m_unit; } - //--------------------------------------------------------------------------------------------------------------------- void VPLayout::SetWarningSuperpositionOfPieces(bool state) { @@ -150,7 +147,7 @@ bool VPLayout::GetWarningPiecesOutOfBound() const } //--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetTitle(QString title) +void VPLayout::SetTitle(const QString &title) { m_title = title; } @@ -162,7 +159,7 @@ QString VPLayout::GetTitle() const } //--------------------------------------------------------------------------------------------------------------------- -void VPLayout::SetDescription(QString description) +void VPLayout::SetDescription(const QString &description) { m_description = description; } @@ -179,7 +176,7 @@ void VPLayout::ClearSelection() { m_unplacedPieceList->ClearSelection(); - for (auto sheet : m_sheets) + for (auto *sheet : m_sheets) { sheet->ClearSelection(); } @@ -193,7 +190,7 @@ void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList) m_unplacedPieceList->ClearSelection(); } - for (auto sheet : m_sheets) + for (auto *sheet : m_sheets) { if(sheet->GetPieceList() != pieceList) { @@ -202,8 +199,6 @@ void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList) } } - - //--------------------------------------------------------------------------------------------------------------------- void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) { diff --git a/src/app/puzzle/vplayout.h b/src/app/puzzle/vplayout.h index fa742434d..bbf875af9 100644 --- a/src/app/puzzle/vplayout.h +++ b/src/app/puzzle/vplayout.h @@ -88,7 +88,7 @@ public: * @brief SetTitle Sets the title of the layout to the given value * @param title the title of the layout */ - void SetTitle(QString title); + void SetTitle(const QString &title); /** * @brief GetTitle Returns the title of the layout @@ -100,7 +100,7 @@ public: * @brief SetDescription Sets the description of the layout to the given value * @param description the description of the layout */ - void SetDescription(QString description); + void SetDescription(const QString &description); /** * @brief GetDescription Returns the description of the layout. @@ -276,7 +276,7 @@ private: */ VPPieceList *m_trashPieceList; - QList m_sheets; + QList m_sheets{}; VPSheet *m_focusedSheet{nullptr}; // format diff --git a/src/app/puzzle/vpmaingraphicsview.cpp b/src/app/puzzle/vpmaingraphicsview.cpp index 94cdcdb81..76d1dfa68 100644 --- a/src/app/puzzle/vpmaingraphicsview.cpp +++ b/src/app/puzzle/vpmaingraphicsview.cpp @@ -205,7 +205,7 @@ void VPMainGraphicsView::on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *p Q_UNUSED(pieceListBefore) VPGraphicsPiece *_graphicsPiece = nullptr; - for(auto graphicPiece : m_graphicsPieces) + for(auto *graphicPiece : m_graphicsPieces) { if(graphicPiece->GetPiece() == piece) { @@ -245,9 +245,9 @@ void VPMainGraphicsView::on_SceneSelectionChanged() // make sure, that the selected items are on top // FIXME: maybe there is a more proper way to do it - for(auto graphicPiece : m_graphicsPieces) + for(auto *graphicPiece : m_graphicsPieces) { - if(!graphicPiece->GetPiece()->GetIsSelected()) + if((graphicPiece != nullptr) && not graphicPiece->GetPiece()->GetIsSelected()) { if(!m_scene->selectedItems().isEmpty()) { diff --git a/src/app/puzzle/vpmainwindow.cpp b/src/app/puzzle/vpmainwindow.cpp index 232c8a6b6..4ef285f01 100644 --- a/src/app/puzzle/vpmainwindow.cpp +++ b/src/app/puzzle/vpmainwindow.cpp @@ -272,17 +272,13 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts) { VRawLayout rawLayoutReader; - for(auto &path : rawLayouts) + for(const auto &path : rawLayouts) { VRawLayoutData data; if (rawLayoutReader.ReadFile(path, data)) { - for (int i = 0; i < data.pieces.size(); ++i) + for (const auto& rawPiece : data.pieces) { - VLayoutPiece rawPiece = data.pieces.at(i); - - - // TODO / FIXME: make a few tests, on the data to check for validity. If not // // If seam allowance enabled, but the path is empty — invalid. @@ -321,7 +317,7 @@ void VPMainWindow::InitZoom() //--------------------------------------------------------------------------------------------------------------------- VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece) { - VPPiece *piece = new VPPiece(rawPiece); + auto *piece = new VPPiece(rawPiece); // cutting line : GetMappedSeamAllowancePoints(); @@ -735,6 +731,8 @@ void VPMainWindow::SetPropertyTabLayoutData() void VPMainWindow::InitMainGraphics() { m_graphicsView = new VPMainGraphicsView(m_layout, m_tileFactory, this); + m_graphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + m_graphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); ui->centralWidget->layout()->addWidget(m_graphicsView); m_graphicsView->RefreshLayout(); @@ -1322,30 +1320,15 @@ bool VPMainWindow::on_actionSaveAs_triggered() //--------------------------------------------------------------------------------------------------------------------- void VPMainWindow::on_actionImportRawLayout_triggered() { - // TODO: here the code is probably just bad, to be edited - - QString dir; - if (true) - { - dir = QDir::homePath(); - } - else - { - // TODO / FIXME get the default path for raw layouts - } - const QString filter(tr("Raw Layout files") + QLatin1String(" (*.rld)")); - qCDebug(pWindow, "Run QFileDialog::getOpenFileName: dir = %s.", qUtf8Printable(dir)); - const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr); - - QStringList rawLayouts = QStringList(); - rawLayouts.append(filePath); - - ImportRawLayouts(rawLayouts); - - // TODO / FIXME : better error handling + const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), QDir::homePath(), filter, nullptr, + VAbstractApplication::VApp()->NativeFileDialog()); + if (not filePath.isEmpty()) + { + ImportRawLayouts({filePath}); + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpmainwindow.h b/src/app/puzzle/vpmainwindow.h index e43cb833b..6d7d62c30 100644 --- a/src/app/puzzle/vpmainwindow.h +++ b/src/app/puzzle/vpmainwindow.h @@ -441,7 +441,7 @@ private: * @brief CreatePiece creates a piece from the given VLayoutPiece data * @param rawPiece the raw piece data */ - VPPiece* CreatePiece(const VLayoutPiece &rawPiece); + Q_REQUIRED_RESULT VPPiece* CreatePiece(const VLayoutPiece &rawPiece); /** * @brief InitMenuBar Inits the menu bar (File, Edit, Help ...) diff --git a/src/app/puzzle/vppiece.h b/src/app/puzzle/vppiece.h index 638805a6f..d68955108 100644 --- a/src/app/puzzle/vppiece.h +++ b/src/app/puzzle/vppiece.h @@ -168,12 +168,12 @@ signals: private: Q_DISABLE_COPY(VPPiece) - QVector m_grainline{QVector()}; + QVector m_grainline{}; bool m_isGrainlineEnabled{false}; // for now separate the position of the piece to the matrix coming from vlayoutpiece // because it's difficult to have the origin of the piece by (0,0) - QTransform m_transform{QTransform()}; + QTransform m_transform{}; // use a separate value for now because it's not easy to get the angle from the transform matrix qreal m_pieceAngle{0};