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();
// 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<VPCarrouselPiece *> (_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");
@ -226,7 +226,6 @@ void VPCarrouselPieceList::contextMenuEvent(QContextMenuEvent *event)
}
}
//---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::on_ActionPieceMovedToPieceList()
{

View File

@ -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);
}

View File

@ -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<VPSheet*>())
m_trashPieceList(new VPPieceList(this))
{
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 *>();
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<VPPiece *> 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)
{

View File

@ -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<VPSheet*> m_sheets;
QList<VPSheet*> m_sheets{};
VPSheet *m_focusedSheet{nullptr};
// format

View File

@ -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())
{

View File

@ -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});
}
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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 ...)

View File

@ -168,12 +168,12 @@ signals:
private:
Q_DISABLE_COPY(VPPiece)
QVector<QPointF> m_grainline{QVector<QPointF>()};
QVector<QPointF> 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};