Improve code style.

This commit is contained in:
Roman Telezhynskyi 2021-05-27 11:35:39 +03:00
parent a907ab03ce
commit f233e7dcba
8 changed files with 37 additions and 60 deletions

View file

@ -80,10 +80,10 @@ void VPCarrouselPieceList::Refresh()
QList<VPPiece*> pieces = m_pieceList->GetPieces(); QList<VPPiece*> pieces = m_pieceList->GetPieces();
// create the corresponding carrousel pieces // create the corresponding carrousel pieces
for (auto piece : pieces) for (auto *piece : pieces)
{ {
// update the label of the piece // update the label of the piece
VPCarrouselPiece* carrouselpiece = new VPCarrouselPiece(piece,this); auto* carrouselpiece = new VPCarrouselPiece(piece, this);
carrouselpiece->setSelected(piece->GetIsSelected()); carrouselpiece->setSelected(piece->GetIsSelected());
connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal); connect(piece, &VPPiece::SelectionChanged, this, &VPCarrouselPieceList::on_SelectionChangedExternal);
} }
@ -120,7 +120,7 @@ void VPCarrouselPieceList::mousePressEvent(QMouseEvent *event)
if (!(event->modifiers() & Qt::ControlModifier)) if (!(event->modifiers() & Qt::ControlModifier))
{ {
// clearSelection doesn't work properly here so we go through the elements. // clearSelection doesn't work properly here so we go through the elements.
for(auto item: selectedItems()) for(auto *item: selectedItems())
{ {
item->setSelected(false); item->setSelected(false);
} }
@ -157,8 +157,8 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (_item); VPCarrouselPiece *pieceItem = static_cast<VPCarrouselPiece *> (_item);
// starts the dragging // starts the dragging
QDrag *drag = new QDrag(this); auto *drag = new QDrag(this);
VPMimeDataPiece *mimeData = new VPMimeDataPiece(); auto *mimeData = new VPMimeDataPiece();
VPPiece* piece = pieceItem->GetPiece(); VPPiece* piece = pieceItem->GetPiece();
mimeData->SetPiecePtr(piece); mimeData->SetPiecePtr(piece);
mimeData->setObjectName("piecePointer"); mimeData->setObjectName("piecePointer");
@ -179,8 +179,8 @@ void VPCarrouselPieceList::startDrag(Qt::DropActions supportedActions)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e) void VPCarrouselPieceList::dragMoveEvent(QDragMoveEvent* e)
{ {
qCDebug(pCarrouselPieceList, "drag move"); qCDebug(pCarrouselPieceList, "drag move");
e->acceptProposedAction(); e->acceptProposedAction();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -226,7 +226,6 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_ActionPieceMovedToPieceList() void VPCarrouselPieceList::on_ActionPieceMovedToPieceList()
{ {

View file

@ -284,7 +284,7 @@ void VPGraphicsPiece::mousePressEvent(QGraphicsSceneMouseEvent *event)
// change the cursor when clicking the left button // change the cursor when clicking the left button
if((event->button() == Qt::LeftButton)) if((event->button() == Qt::LeftButton))
{ {
if(event->modifiers() & Qt::AltModifier) if((event->modifiers() & Qt::AltModifier) != 0U)
{ {
setCursor(m_rotateCursor); setCursor(m_rotateCursor);
} }

View file

@ -38,10 +38,9 @@ Q_LOGGING_CATEGORY(pLayout, "p.layout")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPLayout::VPLayout() : VPLayout::VPLayout() :
m_unplacedPieceList(new VPPieceList(this)), m_unplacedPieceList(new VPPieceList(this)),
m_trashPieceList(new VPPieceList(this)), m_trashPieceList(new VPPieceList(this))
m_sheets(QList<VPSheet*>())
{ {
m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces")); m_unplacedPieceList->SetName(tr("Unplaced pieces"));
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -92,14 +91,14 @@ QList<VPPiece *> VPLayout::GetSelectedPieces()
QList<VPPieceList *> pieceLists = QList<VPPieceList *>(); QList<VPPieceList *> pieceLists = QList<VPPieceList *>();
pieceLists.append(m_unplacedPieceList); pieceLists.append(m_unplacedPieceList);
for (auto sheet : m_sheets) for (auto *sheet : m_sheets)
{ {
pieceLists.append(sheet->GetPieceList()); 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()) if(piece->GetIsSelected())
{ {
@ -111,7 +110,6 @@ QList<VPPiece *> VPLayout::GetSelectedPieces()
return result; return result;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetUnit(Unit unit) void VPLayout::SetUnit(Unit unit)
{ {
@ -124,7 +122,6 @@ Unit VPLayout::GetUnit() const
return m_unit; return m_unit;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayout::SetWarningSuperpositionOfPieces(bool state) 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; 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; m_description = description;
} }
@ -179,7 +176,7 @@ void VPLayout::ClearSelection()
{ {
m_unplacedPieceList->ClearSelection(); m_unplacedPieceList->ClearSelection();
for (auto sheet : m_sheets) for (auto *sheet : m_sheets)
{ {
sheet->ClearSelection(); sheet->ClearSelection();
} }
@ -193,7 +190,7 @@ void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList)
m_unplacedPieceList->ClearSelection(); m_unplacedPieceList->ClearSelection();
} }
for (auto sheet : m_sheets) for (auto *sheet : m_sheets)
{ {
if(sheet->GetPieceList() != pieceList) if(sheet->GetPieceList() != pieceList)
{ {
@ -202,8 +199,6 @@ void VPLayout::ClearSelectionExceptForGivenPieceList(VPPieceList* pieceList)
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList) void VPLayout::MovePieceToPieceList(VPPiece* piece, VPPieceList* pieceList)
{ {

View file

@ -88,7 +88,7 @@ public:
* @brief SetTitle Sets the title of the layout to the given value * @brief SetTitle Sets the title of the layout to the given value
* @param title the title of the layout * @param title the title of the layout
*/ */
void SetTitle(QString title); void SetTitle(const QString &title);
/** /**
* @brief GetTitle Returns the title of the layout * @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 * @brief SetDescription Sets the description of the layout to the given value
* @param description the description of the layout * @param description the description of the layout
*/ */
void SetDescription(QString description); void SetDescription(const QString &description);
/** /**
* @brief GetDescription Returns the description of the layout. * @brief GetDescription Returns the description of the layout.
@ -276,7 +276,7 @@ private:
*/ */
VPPieceList *m_trashPieceList; VPPieceList *m_trashPieceList;
QList<VPSheet*> m_sheets; QList<VPSheet*> m_sheets{};
VPSheet *m_focusedSheet{nullptr}; VPSheet *m_focusedSheet{nullptr};
// format // format

View file

@ -205,7 +205,7 @@ void VPMainGraphicsView::on_PieceMovedToPieceList(VPPiece *piece, VPPieceList *p
Q_UNUSED(pieceListBefore) Q_UNUSED(pieceListBefore)
VPGraphicsPiece *_graphicsPiece = nullptr; VPGraphicsPiece *_graphicsPiece = nullptr;
for(auto graphicPiece : m_graphicsPieces) for(auto *graphicPiece : m_graphicsPieces)
{ {
if(graphicPiece->GetPiece() == piece) if(graphicPiece->GetPiece() == piece)
{ {
@ -245,9 +245,9 @@ void VPMainGraphicsView::on_SceneSelectionChanged()
// make sure, that the selected items are on top // make sure, that the selected items are on top
// FIXME: maybe there is a more proper way to do it // 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()) if(!m_scene->selectedItems().isEmpty())
{ {

View file

@ -272,17 +272,13 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
{ {
VRawLayout rawLayoutReader; VRawLayout rawLayoutReader;
for(auto &path : rawLayouts) for(const auto &path : rawLayouts)
{ {
VRawLayoutData data; VRawLayoutData data;
if (rawLayoutReader.ReadFile(path, 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 // 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. // If seam allowance enabled, but the path is empty — invalid.
@ -321,7 +317,7 @@ void VPMainWindow::InitZoom()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece) VPPiece* VPMainWindow::CreatePiece(const VLayoutPiece &rawPiece)
{ {
VPPiece *piece = new VPPiece(rawPiece); auto *piece = new VPPiece(rawPiece);
// cutting line : GetMappedSeamAllowancePoints(); // cutting line : GetMappedSeamAllowancePoints();
@ -735,6 +731,8 @@ void VPMainWindow::SetPropertyTabLayoutData()
void VPMainWindow::InitMainGraphics() void VPMainWindow::InitMainGraphics()
{ {
m_graphicsView = new VPMainGraphicsView(m_layout, m_tileFactory, this); 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); ui->centralWidget->layout()->addWidget(m_graphicsView);
m_graphicsView->RefreshLayout(); m_graphicsView->RefreshLayout();
@ -1322,30 +1320,15 @@ bool VPMainWindow::on_actionSaveAs_triggered()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::on_actionImportRawLayout_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)")); 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"), QDir::homePath(), filter, nullptr,
const QString filePath = QFileDialog::getOpenFileName(this, tr("Open file"), dir, filter, nullptr); VAbstractApplication::VApp()->NativeFileDialog());
QStringList rawLayouts = QStringList();
rawLayouts.append(filePath);
ImportRawLayouts(rawLayouts);
// TODO / FIXME : better error handling
if (not filePath.isEmpty())
{
ImportRawLayouts({filePath});
}
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -441,7 +441,7 @@ private:
* @brief CreatePiece creates a piece from the given VLayoutPiece data * @brief CreatePiece creates a piece from the given VLayoutPiece data
* @param rawPiece the raw piece 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 ...) * @brief InitMenuBar Inits the menu bar (File, Edit, Help ...)

View file

@ -168,12 +168,12 @@ signals:
private: private:
Q_DISABLE_COPY(VPPiece) Q_DISABLE_COPY(VPPiece)
QVector<QPointF> m_grainline{QVector<QPointF>()}; QVector<QPointF> m_grainline{};
bool m_isGrainlineEnabled{false}; bool m_isGrainlineEnabled{false};
// for now separate the position of the piece to the matrix coming from vlayoutpiece // 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) // 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 // use a separate value for now because it's not easy to get the angle from the transform matrix
qreal m_pieceAngle{0}; qreal m_pieceAngle{0};