Refactoring VPuzzleLayer

This commit is contained in:
Ronan Le Tiec 2020-05-23 15:29:57 +02:00
parent 45be7271bb
commit 34b67cc6e3
27 changed files with 253 additions and 356 deletions

View file

@ -14,8 +14,8 @@ SOURCES += \
$$PWD/vpgraphicspiece.cpp \ $$PWD/vpgraphicspiece.cpp \
$$PWD/vpgraphicssheet.cpp \ $$PWD/vpgraphicssheet.cpp \
$$PWD/vpmainwindow.cpp \ $$PWD/vpmainwindow.cpp \
$$PWD/vppiecelist.cpp \
$$PWD/vpuzzlelayout.cpp \ $$PWD/vpuzzlelayout.cpp \
$$PWD/vpuzzlelayer.cpp \
$$PWD/vpuzzlemaingraphicsview.cpp \ $$PWD/vpuzzlemaingraphicsview.cpp \
$$PWD/vpuzzlemimedatapiece.cpp \ $$PWD/vpuzzlemimedatapiece.cpp \
$$PWD/vpuzzlepiece.cpp \ $$PWD/vpuzzlepiece.cpp \
@ -38,9 +38,9 @@ HEADERS += \
$$PWD/vpgraphicspiece.h \ $$PWD/vpgraphicspiece.h \
$$PWD/vpgraphicssheet.h \ $$PWD/vpgraphicssheet.h \
$$PWD/vpmainwindow.h \ $$PWD/vpmainwindow.h \
$$PWD/vppiecelist.h \
$$PWD/vpstable.h \ $$PWD/vpstable.h \
$$PWD/vpuzzlelayout.h \ $$PWD/vpuzzlelayout.h \
$$PWD/vpuzzlelayer.h \
$$PWD/vpuzzlemaingraphicsview.h \ $$PWD/vpuzzlemaingraphicsview.h \
$$PWD/vpuzzlemimedatapiece.h \ $$PWD/vpuzzlemimedatapiece.h \
$$PWD/vpuzzlepiece.h \ $$PWD/vpuzzlepiece.h \

View file

@ -32,7 +32,7 @@
#include <QScrollBar> #include <QScrollBar>
#include "../vmisc/backport/qoverload.h" #include "../vmisc/backport/qoverload.h"
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QMenu> #include <QMenu>
@ -49,8 +49,8 @@ VPCarrousel::VPCarrousel(VPuzzleLayout *layout, QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
// init the combo box // init the combo box
connect(ui->comboBoxLayer, QOverload<int>::of(&QComboBox::currentIndexChanged), this, connect(ui->comboBoxPieceList, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
&VPCarrousel::on_ActiveLayerChanged); &VPCarrousel::on_ActivePieceListChanged);
ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu); ui->listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
@ -68,18 +68,18 @@ void VPCarrousel::Refresh()
// --- add the content saved in the layout to the carrousel. // --- add the content saved in the layout to the carrousel.
// Do not rely on m_layout because we do not control it. // Do not rely on m_layout because we do not control it.
m_layers = m_layout->GetLayers(); m_pieceLists = m_layout->GetPiecesLists();
m_layers.prepend(m_layout->GetUnplacedPiecesLayer()); m_pieceLists.prepend(m_layout->GetUnplacedPieceList());
for (auto layer : m_layers) for (auto pieceList : m_pieceLists)
{ {
// add layer name to combo // add piece list name to combo
ui->comboBoxLayer->blockSignals(true); ui->comboBoxPieceList->blockSignals(true);
ui->comboBoxLayer->addItem(layer->GetName()); ui->comboBoxPieceList->addItem(pieceList->GetName());
ui->comboBoxLayer->blockSignals(false); ui->comboBoxPieceList->blockSignals(false);
} }
on_ActiveLayerChanged(0); on_ActivePieceListChanged(0);
RefreshOrientation(); RefreshOrientation();
} }
@ -88,25 +88,25 @@ void VPCarrousel::Refresh()
void VPCarrousel::Clear() void VPCarrousel::Clear()
{ {
// remove the combobox entries // remove the combobox entries
ui->comboBoxLayer->clear(); ui->comboBoxPieceList->clear();
ui->listWidget->clear(); ui->listWidget->clear();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrousel::on_ActiveLayerChanged(int index) void VPCarrousel::on_ActivePieceListChanged(int index)
{ {
qCDebug(pCarrousel, "index changed %i", index); qCDebug(pCarrousel, "index changed %i", index);
ui->listWidget->clear(); ui->listWidget->clear();
if (index >= 0 && index < m_layers.size()) if (index >= 0 && index < m_pieceLists.size())
{ {
VPuzzleLayer *layer = m_layers.at(index); VPPieceList *pieceList = m_pieceLists.at(index);
if (layer) if (pieceList)
{ {
QList<VPuzzlePiece*> pieces = layer->GetPieces(); QList<VPuzzlePiece*> pieces = pieceList->GetPieces();
for (auto piece : pieces) for (auto piece : pieces)
{ {
@ -129,7 +129,7 @@ void VPCarrousel::RefreshOrientation()
// then update the scrollarea min height / width and scrollbar behaviour // then update the scrollarea min height / width and scrollbar behaviour
if(m_orientation == Qt::Horizontal) if(m_orientation == Qt::Horizontal)
{ {
ui->comboBoxLayer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); ui->comboBoxPieceList->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
// scroll bar policy of scroll area // scroll bar policy of scroll area
ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
@ -139,7 +139,7 @@ void VPCarrousel::RefreshOrientation()
} }
else // Qt::Vertical else // Qt::Vertical
{ {
ui->comboBoxLayer->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); ui->comboBoxPieceList->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
// scroll bar policy of scroll area // scroll bar policy of scroll area
ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); ui->listWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);

View file

@ -80,7 +80,7 @@ private:
Ui::VPCarrousel *ui; Ui::VPCarrousel *ui;
VPuzzleLayout *m_layout; VPuzzleLayout *m_layout;
QList<VPuzzleLayer*> m_layers{}; QList<VPPieceList*> m_pieceLists{};
Qt::Orientation m_orientation{Qt::Vertical}; Qt::Orientation m_orientation{Qt::Vertical};
@ -88,10 +88,10 @@ private:
private slots: private slots:
/** /**
* @brief on_ActiveLayerChanged Called when the active layer is changed * @brief on_ActivePieceListChanged Called when the active piece list is changed
* @param index * @param index
*/ */
void on_ActiveLayerChanged(int index); void on_ActivePieceListChanged(int index);
}; };
#endif // VPCARROUSEL_H #endif // VPCARROUSEL_H

View file

@ -27,7 +27,7 @@
<number>6</number> <number>6</number>
</property> </property>
<item> <item>
<widget class="QComboBox" name="comboBoxLayer"> <widget class="QComboBox" name="comboBoxPieceList">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>

View file

@ -47,9 +47,9 @@ Q_LOGGING_CATEGORY(pCarrouselPiece, "p.carrouselPiece")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPCarrouselPiece::VPCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselLayer) : VPCarrouselPiece::VPCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselPieceList) :
m_piece(piece), m_piece(piece),
m_carrouselPieceList(carrouselLayer), m_carrouselPieceList(carrouselPieceList),
m_dragStart(QPoint()) m_dragStart(QPoint())
{ {
Init(); Init();
@ -196,7 +196,7 @@ void VPCarrouselPiece::mouseMoveEvent(QMouseEvent *event)
return; return;
} }
if(m_piece->GetLayer() != m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer()) if(m_piece->GetPieceList() != m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList())
{ {
return; return;
} }
@ -239,32 +239,32 @@ void VPCarrouselPiece::contextMenuEvent(QContextMenuEvent *event)
{ {
QMenu contextMenu; QMenu contextMenu;
VPuzzleLayer* unplacedLayer = m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer(); VPPieceList* unplacedPieces = m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList();
QList<VPuzzleLayer*> layers = m_piece->GetLayer()->GetLayout()->GetLayers(); QList<VPPieceList*> pieceLists = m_piece->GetPieceList()->GetLayout()->GetPiecesLists();
// move to layer actions -- TODO : To be tested properly when we have several layers // move to piece list actions -- TODO : To be tested properly when we have several piece lists
layers.removeAll(m_piece->GetLayer()); pieceLists.removeAll(m_piece->GetPieceList());
if(layers.count() > 0) if(pieceLists.count() > 0)
{ {
QMenu *moveMenu = contextMenu.addMenu(tr("Move to")); QMenu *moveMenu = contextMenu.addMenu(tr("Move to"));
// TODO order in alphabetical order // TODO order in alphabetical order
for (auto layer : layers) for (auto pieceList : pieceLists)
{ {
QAction* moveToLayer = moveMenu->addAction(layer->GetName()); QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName());
QVariant data = QVariant::fromValue(layer); QVariant data = QVariant::fromValue(pieceList);
moveToLayer->setData(data); moveToPieceList->setData(data);
connect(moveToLayer, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList); connect(moveToPieceList, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
} }
} }
// remove from layout action // remove from piece list action
if(m_piece->GetLayer() != unplacedLayer) if(m_piece->GetPieceList() != unplacedPieces)
{ {
QAction *removeAction = contextMenu.addAction(tr("Remove from Layout")); QAction *removeAction = contextMenu.addAction(tr("Remove from Layout"));
QVariant data = QVariant::fromValue(m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer()); QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList());
removeAction->setData(data); removeAction->setData(data);
connect(removeAction, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList); connect(removeAction, &QAction::triggered, this, &VPCarrouselPiece::on_ActionPieceMovedToPieceList);
} }
@ -277,9 +277,9 @@ void VPCarrouselPiece::on_ActionPieceMovedToPieceList()
{ {
QAction *act = qobject_cast<QAction *>(sender()); QAction *act = qobject_cast<QAction *>(sender());
QVariant v = act->data(); QVariant v = act->data();
VPuzzleLayer *layer = v.value<VPuzzleLayer *>(); VPPieceList *pieceList = v.value<VPPieceList *>();
if(layer != nullptr) if(pieceList != nullptr)
{ {
layer->GetLayout()->MovePieceToLayer(m_piece, layer); pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList);
} }
} }

View file

@ -43,14 +43,15 @@ class VPCarrouselPiece : public QFrame
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit VPCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselLayer); explicit VPCarrouselPiece(VPuzzlePiece *piece, VPCarrouselPieceList *carrouselPieceList);
~VPCarrouselPiece(); ~VPCarrouselPiece();
void Init(); void Init();
void Refresh(); void Refresh();
/** /**
* @brief CleanPiecesPreview fitInView of the qGraphicsView of the pieces works properly * @brief CleanPiecesPreview fitInView of the qGraphicsView of the pieces works properly
* only when the piece is in place in the layer and we call it from the layer. * only when the piece is in place in the piece list and we call it from the piece list.
*/ */
void CleanPreview(); void CleanPreview();

View file

@ -34,11 +34,11 @@
#include <QLoggingCategory> #include <QLoggingCategory>
Q_LOGGING_CATEGORY(pCarrouselLayer, "p.carrouselLayer") Q_LOGGING_CATEGORY(pCarrouselPieceList, "p.carrouselPieceList")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPCarrouselPieceList::VPCarrouselPieceList(VPuzzleLayer *layer, VPCarrousel *carrousel) : VPCarrouselPieceList::VPCarrouselPieceList(VPPieceList *pieceList, VPCarrousel *carrousel) :
m_layer(layer), m_pieceList(pieceList),
m_carrousel(carrousel), m_carrousel(carrousel),
m_carrouselPieces(QList<VPCarrouselPiece*>()) m_carrouselPieces(QList<VPCarrouselPiece*>())
{ {
@ -63,8 +63,8 @@ void VPCarrouselPieceList::Init()
Refresh(); Refresh();
// add the connections // add the connections
connect(m_layer, &VPuzzleLayer::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded); connect(m_pieceList, &VPPieceList::PieceAdded, this, &VPCarrouselPieceList::on_PieceAdded);
connect(m_layer, &VPuzzleLayer::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved); connect(m_pieceList, &VPPieceList::PieceRemoved, this, &VPCarrouselPieceList::on_PieceRemoved);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -73,7 +73,7 @@ void VPCarrouselPieceList::Refresh()
Clear(); Clear();
// Updates the carrousel pieces from the pieces list // Updates the carrousel pieces from the pieces list
QList<VPuzzlePiece*> pieces = m_layer->GetPieces(); QList<VPuzzlePiece*> pieces = m_pieceList->GetPieces();
// sort the pieces in alphabetical order // sort the pieces in alphabetical order
std::sort(pieces.begin(), pieces.end(), std::sort(pieces.begin(), pieces.end(),
@ -96,7 +96,7 @@ void VPCarrouselPieceList::Refresh()
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPCarrouselPieceList::Clear() void VPCarrouselPieceList::Clear()
{ {
// Removes and deletes the carrousel pieces from the layer // Removes and deletes the carrousel pieces from the piece list
while (!m_carrouselPieces.isEmpty()) while (!m_carrouselPieces.isEmpty())
{ {
VPCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast(); VPCarrouselPiece *carrouselPiece = m_carrouselPieces.takeLast();
@ -123,9 +123,9 @@ VPCarrousel* VPCarrouselPieceList::GetCarrousel()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPCarrouselPieceList::GetLayer() VPPieceList* VPCarrouselPieceList::GetPieceList()
{ {
return m_layer; return m_pieceList;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -30,7 +30,7 @@
#define VPCARROUSELPIECELIST_H #define VPCARROUSELPIECELIST_H
#include <QWidget> #include <QWidget>
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "vpcarrouselpiece.h" #include "vpcarrouselpiece.h"
class VPCarrousel; class VPCarrousel;
@ -39,7 +39,7 @@ class VPCarrouselPieceList : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
VPCarrouselPieceList(VPuzzleLayer *layer, VPCarrousel *carrousel); VPCarrouselPieceList(VPPieceList *pieceList, VPCarrousel *carrousel);
~VPCarrouselPieceList(); ~VPCarrouselPieceList();
void Init(); void Init();
@ -55,15 +55,15 @@ public:
VPCarrousel* GetCarrousel(); VPCarrousel* GetCarrousel();
/** /**
* @brief GetPuzzleLayer Returns the corresponding VPuzzleLayer * @brief GetPieceList Returns the corresponding VPPieceList
* @return the VPuzzleLayer * @return the VPPieceList
*/ */
VPuzzleLayer* GetLayer(); VPPieceList* GetPieceList();
private: private:
Q_DISABLE_COPY(VPCarrouselPieceList) Q_DISABLE_COPY(VPCarrouselPieceList)
VPuzzleLayer *m_layer; VPPieceList *m_pieceList;
VPCarrousel *m_carrousel; VPCarrousel *m_carrousel;
QList<VPCarrouselPiece*> m_carrouselPieces; QList<VPCarrouselPiece*> m_carrouselPieces;

View file

@ -40,7 +40,7 @@
#include <QGraphicsScene> #include <QGraphicsScene>
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include <QLoggingCategory> #include <QLoggingCategory>
@ -296,44 +296,44 @@ void VPGraphicsPiece::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{ {
QMenu contextMenu; QMenu contextMenu;
// move to layer actions -- TODO : To be tested properly when we have several layers // move to piece list actions -- TODO : To be tested properly when we have several piece lists
QList<VPuzzleLayer*> layers = m_piece->GetLayer()->GetLayout()->GetLayers(); QList<VPPieceList*> pieceLists = m_piece->GetPieceList()->GetLayout()->GetPiecesLists();
layers.removeAll(m_piece->GetLayer()); pieceLists.removeAll(m_piece->GetPieceList());
if(layers.count() > 0) if(pieceLists.count() > 0)
{ {
QMenu *moveMenu = contextMenu.addMenu(tr("Move to")); QMenu *moveMenu = contextMenu.addMenu(tr("Move to"));
// TODO order in alphabetical order // TODO order in alphabetical order
for (auto layer : layers) for (auto pieceList : pieceLists)
{ {
QAction* moveToLayer = moveMenu->addAction(layer->GetName()); QAction* moveToPieceList = moveMenu->addAction(pieceList->GetName());
QVariant data = QVariant::fromValue(layer); QVariant data = QVariant::fromValue(pieceList);
moveToLayer->setData(data); moveToPieceList->setData(data);
connect(moveToLayer, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToLayer); connect(moveToPieceList, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList);
} }
} }
// remove from layout action // remove from layout action
QAction *removeAction = contextMenu.addAction(tr("Remove from Layout")); QAction *removeAction = contextMenu.addAction(tr("Remove from Layout"));
QVariant data = QVariant::fromValue(m_piece->GetLayer()->GetLayout()->GetUnplacedPiecesLayer()); QVariant data = QVariant::fromValue(m_piece->GetPieceList()->GetLayout()->GetUnplacedPieceList());
removeAction->setData(data); removeAction->setData(data);
connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToLayer); connect(removeAction, &QAction::triggered, this, &VPGraphicsPiece::on_ActionPieceMovedToPieceList);
contextMenu.exec(event->screenPos()); contextMenu.exec(event->screenPos());
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPGraphicsPiece::on_ActionPieceMovedToLayer() void VPGraphicsPiece::on_ActionPieceMovedToPieceList()
{ {
QAction *act = qobject_cast<QAction *>(sender()); QAction *act = qobject_cast<QAction *>(sender());
QVariant v = act->data(); QVariant v = act->data();
VPuzzleLayer *layer = v.value<VPuzzleLayer *>(); VPPieceList *pieceList = v.value<VPPieceList *>();
if(layer != nullptr) if(pieceList != nullptr)
{ {
layer->GetLayout()->MovePieceToLayer(m_piece, layer); pieceList->GetLayout()->MovePieceToPieceList(m_piece, pieceList);
} }
} }

View file

@ -80,10 +80,10 @@ protected:
private slots: private slots:
/** /**
* @brief on_ActionPieceMovedToLayer Slot called when the piece is moved via the * @brief on_ActionPieceMovedToPieceList Slot called when the piece is moved via the
* context menu to anoter layer * context menu to anoter piece list
*/ */
void on_ActionPieceMovedToLayer(); void on_ActionPieceMovedToPieceList();
private: private:
Q_DISABLE_COPY(VPGraphicsPiece) Q_DISABLE_COPY(VPGraphicsPiece)

View file

@ -165,7 +165,7 @@ void VPMainWindow::ImportRawLayouts(const QStringList &rawLayouts)
// TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece() // TODO for feature "Update piece" : CreateOrUpdate() function indstead of CreatePiece()
VPuzzlePiece *piece = CreatePiece(rawPiece); VPuzzlePiece *piece = CreatePiece(rawPiece);
m_layout->GetUnplacedPiecesLayer()->AddPiece(piece); m_layout->GetUnplacedPieceList()->AddPiece(piece);
} }
m_carrousel->Refresh(); m_carrousel->Refresh();
@ -236,7 +236,6 @@ void VPMainWindow::InitProperties()
{ {
InitPropertyTabCurrentPiece(); InitPropertyTabCurrentPiece();
InitPropertyTabLayout(); InitPropertyTabLayout();
InitPropertyTabLayers();
InitPropertyTabTiles(); InitPropertyTabTiles();
} }
@ -312,14 +311,6 @@ void VPMainWindow::InitPropertyTabTiles()
ui->tabWidgetProperties->removeTab(2); // remove tiles ui->tabWidgetProperties->removeTab(2); // remove tiles
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::InitPropertyTabLayers()
{
// for the MVP we don't want the layers tab.
// we remove it. As soon as we need it, update this code
ui->tabWidgetProperties->removeTab(3); // remove layers
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::InitCarrousel() void VPMainWindow::InitCarrousel()
{ {
@ -343,7 +334,6 @@ void VPMainWindow::SetPropertiesData()
SetPropertyTabCurrentPieceData(); SetPropertyTabCurrentPieceData();
SetPropertyTabLayoutData(); SetPropertyTabLayoutData();
SetPropertyTabTilesData(); SetPropertyTabTilesData();
SetPropertyTabLayersData();
} }
} }
@ -443,12 +433,6 @@ void VPMainWindow::SetPropertyTabTilesData()
} }
//---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::SetPropertyTabLayersData()
{
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPMainWindow::InitMainGraphics() void VPMainWindow::InitMainGraphics()
{ {

View file

@ -129,11 +129,6 @@ private:
*/ */
void InitPropertyTabTiles(); void InitPropertyTabTiles();
/**
* @brief InitPropertyTabLayers Inits the layers tab in the properties
*/
void InitPropertyTabLayers();
/** /**
* @brief InitCarrousel Inits the carrousel * @brief InitCarrousel Inits the carrousel
*/ */
@ -168,12 +163,6 @@ private:
*/ */
void SetPropertyTabTilesData(); void SetPropertyTabTilesData();
/**
* @brief SetPropertyTabLayersData Sets the values of UI elements
* in the Layers Tab to the values saved in m_layout
*/
void SetPropertyTabLayersData();
/** /**
* @brief SetDoubleSpinBoxValue sets the given spinbox to the given value. * @brief SetDoubleSpinBoxValue sets the given spinbox to the given value.
* the signals are blocked before changing the value and unblocked after * the signals are blocked before changing the value and unblocked after

View file

@ -172,7 +172,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>2</number>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -955,86 +955,6 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tabLayersProperty">
<attribute name="icon">
<iconset resource="share/resources/puzzleicon.qrc">
<normaloff>:/puzzleicon/64x64/iconLayers.png</normaloff>:/puzzleicon/64x64/iconLayers.png</iconset>
</attribute>
<attribute name="title">
<string/>
</attribute>
<attribute name="toolTip">
<string>Layers properties</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayoutLayersProperty">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QScrollArea" name="scrollAreaLayers">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContentsLayers">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>356</width>
<height>760</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="styleSheet">
<string notr="true">font-weight:bold;</string>
</property>
<property name="text">
<string>Layers</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -1126,7 +1046,6 @@
<tabstop>doubleSpinBoxLayoutMarginLeft</tabstop> <tabstop>doubleSpinBoxLayoutMarginLeft</tabstop>
<tabstop>doubleSpinBoxLayoutMarginRight</tabstop> <tabstop>doubleSpinBoxLayoutMarginRight</tabstop>
<tabstop>doubleSpinBoxLayoutMarginBottom</tabstop> <tabstop>doubleSpinBoxLayoutMarginBottom</tabstop>
<tabstop>scrollAreaLayers</tabstop>
<tabstop>scrollAreaTiles</tabstop> <tabstop>scrollAreaTiles</tabstop>
</tabstops> </tabstops>
<resources> <resources>

View file

@ -1,6 +1,6 @@
/************************************************************************ /************************************************************************
** **
** @file vpuzzlelayer.cpp ** @file vppiecelist.cpp
** @author Ronan Le Tiec ** @author Ronan Le Tiec
** @date 13 4, 2020 ** @date 13 4, 2020
** **
@ -25,42 +25,42 @@
** along with Valentina. If not, see <http://www.gnu.org/licenses/>. ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
** **
*************************************************************************/ *************************************************************************/
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include <QLoggingCategory> #include <QLoggingCategory>
Q_LOGGING_CATEGORY(pLayer, "p.layer") Q_LOGGING_CATEGORY(pPieceList, "p.pieceList")
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer::VPuzzleLayer(VPuzzleLayout *layout): VPPieceList::VPPieceList(VPuzzleLayout *layout):
m_layout(layout) m_layout(layout)
{ {
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer::~VPuzzleLayer() VPPieceList::~VPPieceList()
{ {
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayout* VPuzzleLayer::GetLayout() VPuzzleLayout* VPPieceList::GetLayout()
{ {
return m_layout; return m_layout;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QList<VPuzzlePiece *> VPuzzleLayer::GetPieces() QList<VPuzzlePiece *> VPPieceList::GetPieces()
{ {
return m_pieces; return m_pieces;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayer::ClearSelection() void VPPieceList::ClearSelection()
{ {
for (auto piece: m_pieces) for (auto piece: m_pieces)
{ {
@ -69,45 +69,45 @@ void VPuzzleLayer::ClearSelection()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayer::AddPiece(VPuzzlePiece *piece) void VPPieceList::AddPiece(VPuzzlePiece *piece)
{ {
qCDebug(pLayer(), "piece -- %s -- added to %s", qUtf8Printable(piece->GetName()), qUtf8Printable(this->GetName())); qCDebug(pPieceList(), "piece -- %s -- added to %s", qUtf8Printable(piece->GetName()), qUtf8Printable(this->GetName()));
m_pieces.append(piece); m_pieces.append(piece);
piece->SetLayer(this); piece->SetPieceList(this);
emit PieceAdded(piece); emit PieceAdded(piece);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayer::RemovePiece(VPuzzlePiece *piece) void VPPieceList::RemovePiece(VPuzzlePiece *piece)
{ {
m_pieces.removeAll(piece); m_pieces.removeAll(piece);
piece->SetLayer(nullptr); piece->SetPieceList(nullptr);
emit PieceRemoved(piece); emit PieceRemoved(piece);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QString VPuzzleLayer::GetName() const QString VPPieceList::GetName() const
{ {
return m_name; return m_name;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayer::SetName(const QString &name) void VPPieceList::SetName(const QString &name)
{ {
m_name = name; m_name = name;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayer::SetIsVisible(bool value) void VPPieceList::SetIsVisible(bool value)
{ {
m_isVisible = value; m_isVisible = value;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
bool VPuzzleLayer::GetIsVisible() const bool VPPieceList::GetIsVisible() const
{ {
return m_isVisible; return m_isVisible;
} }

View file

@ -1,6 +1,6 @@
/************************************************************************ /************************************************************************
** **
** @file vpuzzlelayer.h ** @file vppiecelist.h
** @author Ronan Le Tiec ** @author Ronan Le Tiec
** @date 13 4, 2020 ** @date 13 4, 2020
** **
@ -25,20 +25,20 @@
** along with Valentina. If not, see <http://www.gnu.org/licenses/>. ** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
** **
*************************************************************************/ *************************************************************************/
#ifndef VPUZZLELAYER_H #ifndef VPPIECELIST_H
#define VPUZZLELAYER_H #define VPPIECELIST_H
#include <QList> #include <QList>
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
class VPuzzleLayout; class VPuzzleLayout;
class VPuzzleLayer : public QObject class VPPieceList : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
VPuzzleLayer(VPuzzleLayout *layout); VPPieceList(VPuzzleLayout *layout);
~VPuzzleLayer(); ~VPPieceList();
QList<VPuzzlePiece *> GetPieces(); QList<VPuzzlePiece *> GetPieces();
void AddPiece(VPuzzlePiece *piece); void AddPiece(VPuzzlePiece *piece);
@ -54,13 +54,13 @@ public:
bool GetIsVisible() const; bool GetIsVisible() const;
/** /**
* @brief GetLayout Returns the layout in which this layer is * @brief GetLayout Returns the layout in which this piece list is
* @return the layout of this layer * @return the layout of this piece list
*/ */
VPuzzleLayout* GetLayout(); VPuzzleLayout* GetLayout();
/** /**
* @brief ClearSelection Clears the selection of the pieces in this layer * @brief ClearSelection Clears the selection of the pieces in this piece list
*/ */
void ClearSelection(); void ClearSelection();
@ -76,7 +76,7 @@ signals:
void PieceRemoved(VPuzzlePiece *piece); void PieceRemoved(VPuzzlePiece *piece);
private: private:
Q_DISABLE_COPY(VPuzzleLayer) Q_DISABLE_COPY(VPPieceList)
QString m_name{}; QString m_name{};
QList<VPuzzlePiece *> m_pieces{}; QList<VPuzzlePiece *> m_pieces{};
@ -88,4 +88,4 @@ private:
}; };
#endif // VPUZZLELAYER_H #endif // VPPIECELIST_H

View file

@ -26,56 +26,56 @@
** **
*************************************************************************/ *************************************************************************/
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayout::VPuzzleLayout() : VPuzzleLayout::VPuzzleLayout() :
m_unplacedPiecesLayer(new VPuzzleLayer(this)) m_unplacedPieceList(new VPPieceList(this))
{ {
m_unplacedPiecesLayer->SetName(QObject::tr("Unplaced pieces")); m_unplacedPieceList->SetName(QObject::tr("Unplaced pieces"));
// create a standard default layer: // create a standard default piecelist:
VPuzzleLayer *layer = new VPuzzleLayer(this); VPPieceList *pieceList = new VPPieceList(this);
layer->SetName(QObject::tr("Layout")); pieceList->SetName(QObject::tr("Layout"));
AddLayer(layer); AddPieceList(pieceList);
// sets the default active layer // sets the default active piece list
SetFocusedLayer(); SetFocusedPieceList();
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayout::~VPuzzleLayout() VPuzzleLayout::~VPuzzleLayout()
{ {
qDeleteAll(m_layers); qDeleteAll(m_pieceLists);
delete m_unplacedPiecesLayer; delete m_unplacedPieceList;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzleLayout::GetUnplacedPiecesLayer() VPPieceList* VPuzzleLayout::GetUnplacedPieceList()
{ {
return m_unplacedPiecesLayer; return m_unplacedPieceList;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzleLayout::AddLayer() VPPieceList* VPuzzleLayout::AddPieceList()
{ {
VPuzzleLayer *newLayer = new VPuzzleLayer(this); VPPieceList *newPieceList = new VPPieceList(this);
m_layers.append(newLayer); m_pieceLists.append(newPieceList);
return newLayer; return newPieceList;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzleLayout::AddLayer(VPuzzleLayer *layer) VPPieceList* VPuzzleLayout::AddPieceList(VPPieceList *pieceList)
{ {
m_layers.append(layer); m_pieceLists.append(pieceList);
return layer; return pieceList;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
QList<VPuzzleLayer *> VPuzzleLayout::GetLayers() QList<VPPieceList *> VPuzzleLayout::GetPiecesLists()
{ {
return m_layers; return m_pieceLists;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
@ -83,12 +83,12 @@ QList<VPuzzlePiece *> VPuzzleLayout::GetSelectedPieces()
{ {
QList<VPuzzlePiece *> result = QList<VPuzzlePiece *>(); QList<VPuzzlePiece *> result = QList<VPuzzlePiece *>();
QList<VPuzzleLayer *> layers = m_layers; QList<VPPieceList *> pieceLists = m_pieceLists;
layers.prepend(m_unplacedPiecesLayer); pieceLists.prepend(m_unplacedPieceList);
for (auto layer : layers) for (auto pieceList : pieceLists)
{ {
for (auto piece : layer->GetPieces()) for (auto piece : pieceList->GetPieces())
{ {
if(piece->GetIsSelected()) if(piece->GetIsSelected())
{ {
@ -275,44 +275,44 @@ bool VPuzzleLayout::GetStickyEdges() const
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::ClearSelection() void VPuzzleLayout::ClearSelection()
{ {
m_unplacedPiecesLayer->ClearSelection(); m_unplacedPieceList->ClearSelection();
for (auto layer : m_layers) for (auto pieceList : m_pieceLists)
{ {
layer->ClearSelection(); pieceList->ClearSelection();
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::SetFocusedLayer(VPuzzleLayer* focusedLayer) void VPuzzleLayout::SetFocusedPieceList(VPPieceList* focusedPieceList)
{ {
if(focusedLayer == nullptr) if(focusedPieceList == nullptr)
{ {
m_focusedLayer = m_layers.first(); m_focusedPieceList = m_pieceLists.first();
} }
else else
{ {
m_focusedLayer = focusedLayer; m_focusedPieceList = focusedPieceList;
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzleLayout::GetFocusedLayer() VPPieceList* VPuzzleLayout::GetFocusedPieceList()
{ {
return m_focusedLayer; return m_focusedPieceList;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleLayout::MovePieceToLayer(VPuzzlePiece* piece, VPuzzleLayer* layer) void VPuzzleLayout::MovePieceToPieceList(VPuzzlePiece* piece, VPPieceList* pieceList)
{ {
VPuzzleLayer* layerBefore = piece->GetLayer(); VPPieceList* pieceListBefore = piece->GetPieceList();
if(layerBefore != nullptr) if(pieceListBefore != nullptr)
{ {
piece->GetLayer()->RemovePiece(piece); piece->GetPieceList()->RemovePiece(piece);
} }
layer->AddPiece(piece); pieceList->AddPiece(piece);
// signal, that a piece was moved // signal, that a piece was moved
emit PieceMovedToLayer(piece, layerBefore,layer); emit PieceMovedToPieceList(piece, pieceListBefore,pieceList);
} }

View file

@ -34,7 +34,7 @@
#include "def.h" #include "def.h"
class VPuzzleLayer; class VPPieceList;
class VPuzzlePiece; class VPuzzlePiece;
// is this the right place for the definition? // is this the right place for the definition?
@ -47,11 +47,15 @@ public:
VPuzzleLayout(); VPuzzleLayout();
virtual ~VPuzzleLayout(); virtual ~VPuzzleLayout();
VPuzzleLayer* GetUnplacedPiecesLayer(); /**
* @brief GetUnplacedPieceList Returns the piece list of unplaced pieces
* @return the unplaced pieces list
*/
VPPieceList* GetUnplacedPieceList();
VPuzzleLayer* AddLayer(); VPPieceList* AddPieceList();
VPuzzleLayer* AddLayer(VPuzzleLayer *layer); VPPieceList* AddPieceList(VPPieceList *pieceList);
QList<VPuzzleLayer *> GetLayers(); QList<VPPieceList *> GetPiecesLists();
/** /**
* @brief GetSelectedPieces Returns the list of the selected pieces * @brief GetSelectedPieces Returns the list of the selected pieces
@ -196,47 +200,47 @@ public:
bool GetStickyEdges() const; bool GetStickyEdges() const;
/** /**
* @brief ClearSelection goes through the layers & pieces and calls * @brief ClearSelection goes through the piece list and pieces and calls
* SetIsSelected(false) for the pieces that were selected. * SetIsSelected(false) for the pieces that were selected.
*/ */
void ClearSelection(); void ClearSelection();
/** /**
* @brief SetFocusedLayer Sets the focused layer, to which pieces are added from the carrousel via drag * @brief SetFocusedPieceList Sets the focused piece klist, to which pieces are added from the carrousel via drag
* and drop * and drop
* @param focusedLayer the new active layer. If nullptr, then it sets automaticaly the first layer from m_layers * @param focusedPieceList the new active piece list. If nullptr, then it sets automaticaly the first piece list from m_pieceLists
*/ */
void SetFocusedLayer(VPuzzleLayer* focusedLayer = nullptr); void SetFocusedPieceList(VPPieceList* focusedPieceList = nullptr);
/** /**
* @brief GetFocusedLayer Returns the focused layer, to which pieces are added from the carrousel via drag * @brief GetFocusedPieceList Returns the focused piece list, to which pieces are added from the carrousel via drag
* and drop * and drop
* @return the focused layer * @return the focused piece list
*/ */
VPuzzleLayer* GetFocusedLayer(); VPPieceList* GetFocusedPieceList();
/** /**
* @brief MovePieceToLayer Moves the given piece to the given layer * @brief MovePieceToPieceList Moves the given piece to the given piece list
* @param piece the piece to move * @param piece the piece to move
* @param layer the layer to move the piece to * @param pieceList the piece list to move the piece to
*/ */
void MovePieceToLayer(VPuzzlePiece* piece, VPuzzleLayer* layer); void MovePieceToPieceList(VPuzzlePiece* piece, VPPieceList* pieceList);
signals: signals:
void PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleLayer *layerBefore, VPuzzleLayer *layerAfter); void PieceMovedToPieceList(VPuzzlePiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter);
private: private:
Q_DISABLE_COPY(VPuzzleLayout) Q_DISABLE_COPY(VPuzzleLayout)
VPuzzleLayer *m_unplacedPiecesLayer; VPPieceList *m_unplacedPieceList;
QList<VPuzzleLayer *> m_layers{}; QList<VPPieceList *> m_pieceLists{};
/** /**
* @brief m_focusedLayer pointer the the focused layer, to which pieces will be * @brief m_focusedPieceList pointer the the focused piece list, to which pieces will be
* added via drag and drop, or if no layer is defined. * added via drag and drop, or if no piece list is defined.
*/ */
VPuzzleLayer *m_focusedLayer{nullptr}; VPPieceList *m_focusedPieceList{nullptr};
// format // format
Unit m_unit{Unit::Cm}; Unit m_unit{Unit::Cm};

View file

@ -33,7 +33,7 @@
#include <QKeyEvent> #include <QKeyEvent>
#include "vpuzzlemimedatapiece.h" #include "vpuzzlemimedatapiece.h"
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "../vwidgets/vmaingraphicsscene.h" #include "../vwidgets/vmaingraphicsscene.h"
#include <QLoggingCategory> #include <QLoggingCategory>
@ -56,7 +56,7 @@ VPuzzleMainGraphicsView::VPuzzleMainGraphicsView(VPuzzleLayout *layout, QWidget
setAcceptDrops(true); setAcceptDrops(true);
// add the connections // add the connections
connect(m_layout, &VPuzzleLayout::PieceMovedToLayer, this, &VPuzzleMainGraphicsView::on_PieceMovedToLayer); connect(m_layout, &VPuzzleLayout::PieceMovedToPieceList, this, &VPuzzleMainGraphicsView::on_PieceMovedToPieceList);
connect(m_scene, &VMainGraphicsScene::selectionChanged, this, connect(m_scene, &VMainGraphicsScene::selectionChanged, this,
&VPuzzleMainGraphicsView::on_SceneSelectionChanged); &VPuzzleMainGraphicsView::on_SceneSelectionChanged);
} }
@ -122,11 +122,11 @@ void VPuzzleMainGraphicsView::dropEvent(QDropEvent *event)
QPoint point = event->pos(); QPoint point = event->pos();
piece->SetPosition(mapToScene(point)); piece->SetPosition(mapToScene(point));
// change the layer of the piece // change the piecelist of the piece
VPuzzleLayer *focusedLayer = m_layout->GetFocusedLayer(); VPPieceList *focusedPieceList = m_layout->GetFocusedPieceList();
if(focusedLayer != nullptr) if(focusedPieceList != nullptr)
{ {
m_layout->MovePieceToLayer(piece, focusedLayer); m_layout->MovePieceToPieceList(piece, focusedPieceList);
} }
} }
} }
@ -146,16 +146,16 @@ void VPuzzleMainGraphicsView::keyPressEvent(QKeyEvent *event)
if(piece->GetIsSelected()) if(piece->GetIsSelected())
{ {
piece->SetIsSelected(false); piece->SetIsSelected(false);
m_layout->MovePieceToLayer(piece, m_layout->GetUnplacedPiecesLayer()); m_layout->MovePieceToPieceList(piece, m_layout->GetUnplacedPieceList());
} }
} }
} }
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzleMainGraphicsView::on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleLayer *layerBefore, VPuzzleLayer *layerAfter) void VPuzzleMainGraphicsView::on_PieceMovedToPieceList(VPuzzlePiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter)
{ {
Q_UNUSED(layerBefore) Q_UNUSED(pieceListBefore)
VPGraphicsPiece *_graphicsPiece = nullptr; VPGraphicsPiece *_graphicsPiece = nullptr;
for(auto graphicPiece : m_graphicsPieces) for(auto graphicPiece : m_graphicsPieces)
@ -166,12 +166,12 @@ void VPuzzleMainGraphicsView::on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleL
} }
} }
if(layerAfter == m_layout->GetUnplacedPiecesLayer() && _graphicsPiece != nullptr) if(pieceListAfter == m_layout->GetUnplacedPieceList() && _graphicsPiece != nullptr)
{ {
scene()->removeItem(_graphicsPiece); scene()->removeItem(_graphicsPiece);
m_graphicsPieces.removeAll(_graphicsPiece); m_graphicsPieces.removeAll(_graphicsPiece);
} }
else if(layerAfter != m_layout->GetUnplacedPiecesLayer()) else if(pieceListAfter != m_layout->GetUnplacedPieceList())
{ {
if(_graphicsPiece == nullptr) if(_graphicsPiece == nullptr)
{ {
@ -194,5 +194,5 @@ void VPuzzleMainGraphicsView::on_SceneSelectionChanged()
// but we need to make sure that the unplaced pieces are unselected when the scene selection has changed // but we need to make sure that the unplaced pieces are unselected when the scene selection has changed
// because as they are not part of the scene, they are not updated // because as they are not part of the scene, they are not updated
m_layout->GetUnplacedPiecesLayer()->ClearSelection(); m_layout->GetUnplacedPieceList()->ClearSelection();
} }

View file

@ -58,13 +58,13 @@ protected:
private slots: private slots:
/** /**
* @brief on_PieceMovedToLayer The slot is called when the given piece was moved from the given layer to the other * @brief on_PieceMovedToPieceList The slot is called when the given piece was moved from the given piece list to the other
* given layer * given piece list
* @param piece the piece that was moved * @param piece the piece that was moved
* @param layerBefore the layer before the move * @param pieceListBefore the piece list before the move
* @param layerAfter the layer after the move * @param pieceListAfter the piece list after the move
*/ */
void on_PieceMovedToLayer(VPuzzlePiece *piece, VPuzzleLayer *layerBefore, VPuzzleLayer *layerAfter); void on_PieceMovedToPieceList(VPuzzlePiece *piece, VPPieceList *pieceListBefore, VPPieceList *pieceListAfter);
/** /**
* @brief on_SceneSelectionChanged Slot is called when the scene selection has changed * @brief on_SceneSelectionChanged Slot is called when the scene selection has changed

View file

@ -29,7 +29,7 @@
#include <QtMath> #include <QtMath>
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "../vmisc/def.h" #include "../vmisc/def.h"
#include <QIcon> #include <QIcon>
@ -242,17 +242,17 @@ QVector<QPointF> VPuzzlePiece::GetGrainline()
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPuzzleLayer* VPuzzlePiece::GetLayer() VPPieceList* VPuzzlePiece::GetPieceList()
{ {
return m_layer; return m_pieceList;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPuzzlePiece::SetLayer(VPuzzleLayer* layer) void VPuzzlePiece::SetPieceList(VPPieceList* pieceList)
{ {
if(layer != m_layer) if(pieceList != m_pieceList)
{ {
m_layer = layer; m_pieceList = pieceList;
} }
} }

View file

@ -33,7 +33,7 @@
#include <QPoint> #include <QPoint>
#include <QTransform> #include <QTransform>
class VPuzzleLayer; class VPPieceList;
class VPuzzlePiece : public QObject class VPuzzlePiece : public QObject
{ {
@ -187,16 +187,16 @@ public:
bool GetIsSelected(); bool GetIsSelected();
/** /**
* @brief GetLayer Returns the layer in which the piece is. * @brief GetPieceList Returns the piecelist in which the piece is.
* @return layer of the piece * @return pieceList of the piece
*/ */
VPuzzleLayer* GetLayer(); VPPieceList* GetPieceList();
/** /**
* @brief SetLayer Sets the layer of the piece to the given layer * @brief SetPieceList Sets the pieceList of the piece to the given pieceList
* @param layer * @param pieceList
*/ */
void SetLayer(VPuzzleLayer* layer); void SetPieceList(VPPieceList* pieceList);
QIcon PieceIcon(const QSize &size) const; QIcon PieceIcon(const QSize &size) const;
@ -244,7 +244,7 @@ private:
bool m_mirrorPiece{false}; bool m_mirrorPiece{false};
bool m_isSelected{false}; bool m_isSelected{false};
VPuzzleLayer *m_layer{nullptr}; VPPieceList *m_pieceList{nullptr};
}; };
#endif // VPUZZLEPIECE_H #endif // VPUZZLEPIECE_H

View file

@ -70,9 +70,9 @@ void VPLayoutFileReader::ReadLayout(VPuzzleLayout *layout)
{ {
ReadProperties(layout); ReadProperties(layout);
} }
else if (name() == ML::TagLayers) else if (name() == ML::TagPieceLists)
{ {
ReadLayers(layout); ReadPieceLists(layout);
} }
else else
{ {
@ -193,20 +193,20 @@ void VPLayoutFileReader::ReadTiles(VPuzzleLayout *layout)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadLayers(VPuzzleLayout *layout) void VPLayoutFileReader::ReadPieceLists(VPuzzleLayout *layout)
{ {
SCASSERT(isStartElement() && name() == ML::TagLayers); SCASSERT(isStartElement() && name() == ML::TagPieceLists);
while (readNextStartElement()) while (readNextStartElement())
{ {
if (name() == ML::TagUnplacedPiecesLayer) if (name() == ML::TagUnplacedPieceList)
{ {
ReadLayer(layout->GetUnplacedPiecesLayer()); ReadPieceList(layout->GetUnplacedPieceList());
} }
else if (name() == ML::TagLayer) else if (name() == ML::TagPieceList)
{ {
VPuzzleLayer *layer = layout->AddLayer(); VPPieceList *pieceList = layout->AddPieceList();
ReadLayer(layer); ReadPieceList(pieceList);
} }
else else
{ {
@ -217,13 +217,13 @@ void VPLayoutFileReader::ReadLayers(VPuzzleLayout *layout)
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileReader::ReadLayer(VPuzzleLayer *layer) void VPLayoutFileReader::ReadPieceList(VPPieceList *pieceList)
{ {
SCASSERT(isStartElement() && (name() == ML::TagLayer || name() == ML::TagUnplacedPiecesLayer)); SCASSERT(isStartElement() && (name() == ML::TagPieceList || name() == ML::TagUnplacedPieceList));
QXmlStreamAttributes attribs = attributes(); QXmlStreamAttributes attribs = attributes();
layer->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Layer"))); pieceList->SetName(ReadAttributeString(attribs, ML::AttrName, tr("Piece List")));
layer->SetIsVisible(ReadAttributeBool(attribs, ML::AttrVisible, trueStr)); pieceList->SetIsVisible(ReadAttributeBool(attribs, ML::AttrVisible, trueStr));
while (readNextStartElement()) while (readNextStartElement())
{ {
@ -231,7 +231,7 @@ void VPLayoutFileReader::ReadLayer(VPuzzleLayer *layer)
{ {
VPuzzlePiece *piece = new VPuzzlePiece(); VPuzzlePiece *piece = new VPuzzlePiece();
ReadPiece(piece); ReadPiece(piece);
layer->AddPiece(piece); pieceList->AddPiece(piece);
} }
else else
{ {

View file

@ -32,7 +32,7 @@
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include "../ifc/xml/vabstractconverter.h" #include "../ifc/xml/vabstractconverter.h"
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
class VPLayoutFileReader : public QXmlStreamReader class VPLayoutFileReader : public QXmlStreamReader
@ -50,8 +50,8 @@ private:
void ReadLayout(VPuzzleLayout *layout); void ReadLayout(VPuzzleLayout *layout);
void ReadProperties(VPuzzleLayout *layout); void ReadProperties(VPuzzleLayout *layout);
void ReadTiles(VPuzzleLayout *layout); void ReadTiles(VPuzzleLayout *layout);
void ReadLayers(VPuzzleLayout *layout); void ReadPieceLists(VPuzzleLayout *layout);
void ReadLayer(VPuzzleLayer *layer); void ReadPieceList(VPPieceList *pieceList);
void ReadPiece(VPuzzlePiece *piece); void ReadPiece(VPuzzlePiece *piece);
QMarginsF ReadMargins(); QMarginsF ReadMargins();

View file

@ -28,7 +28,7 @@
#include "vplayoutfilewriter.h" #include "vplayoutfilewriter.h"
#include "vpuzzlelayout.h" #include "vpuzzlelayout.h"
#include "vpuzzlelayer.h" #include "vppiecelist.h"
#include "vpuzzlepiece.h" #include "vpuzzlepiece.h"
#include "vplayoutliterals.h" #include "vplayoutliterals.h"
#include "../ifc/xml/vlayoutconverter.h" #include "../ifc/xml/vlayoutconverter.h"
@ -65,7 +65,7 @@ void VPLayoutFileWriter::WriteLayout(VPuzzleLayout *layout)
SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr); SetAttribute(ML::AttrVersion, VLayoutConverter::LayoutMaxVerStr);
WriteProperties(layout); WriteProperties(layout);
WriteLayers(layout); WritePieceLists(layout);
writeEndElement(); //layout writeEndElement(); //layout
} }
@ -116,45 +116,45 @@ void VPLayoutFileWriter::WriteTiles(VPuzzleLayout *layout)
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteLayers(VPuzzleLayout *layout) void VPLayoutFileWriter::WritePieceLists(VPuzzleLayout *layout)
{ {
writeStartElement(ML::TagLayers); writeStartElement(ML::TagPieceLists);
WriteLayer(layout->GetUnplacedPiecesLayer(), ML::TagUnplacedPiecesLayer); WritePieceList(layout->GetUnplacedPieceList(), ML::TagUnplacedPieceList);
QList<VPuzzleLayer*> layers = layout->GetLayers(); QList<VPPieceList*> pieceLists = layout->GetPiecesLists();
for (auto layer : layers) for (auto pieceList : pieceLists)
{ {
WriteLayer(layer); WritePieceList(pieceList);
} }
writeEndElement(); // layers writeEndElement(); // piece list
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteLayer(VPuzzleLayer *layer) void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList)
{ {
WriteLayer(layer, ML::TagLayer); WritePieceList(pieceList, ML::TagPieceList);
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void VPLayoutFileWriter::WriteLayer(VPuzzleLayer *layer, const QString &tagName) void VPLayoutFileWriter::WritePieceList(VPPieceList *pieceList, const QString &tagName)
{ {
writeStartElement(tagName); // layer writeStartElement(tagName); // piece list
SetAttribute(ML::AttrName, layer->GetName()); SetAttribute(ML::AttrName, pieceList->GetName());
SetAttribute(ML::AttrVisible, layer->GetIsVisible()); SetAttribute(ML::AttrVisible, pieceList->GetIsVisible());
// TODO selected info. Not sure how it's saved yet // TODO selected info. Not sure how it's saved yet
//SetAttribute("selected", layer->GetIsSelected()); //SetAttribute("selected", pieceList->GetIsSelected());
QList<VPuzzlePiece*> pieces = layer->GetPieces(); QList<VPuzzlePiece*> pieces = pieceList->GetPieces();
for (auto piece : pieces) for (auto piece : pieces)
{ {
WritePiece(piece); WritePiece(piece);
} }
writeEndElement(); // layer writeEndElement(); // piece list
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View file

@ -35,7 +35,7 @@
#include "../vmisc/literals.h" #include "../vmisc/literals.h"
class VPuzzleLayout; class VPuzzleLayout;
class VPuzzleLayer; class VPPieceList;
class VPuzzlePiece; class VPuzzlePiece;
class QFile; class QFile;
class QMarginsF; class QMarginsF;
@ -53,9 +53,9 @@ private:
void WriteLayout(VPuzzleLayout *layout); void WriteLayout(VPuzzleLayout *layout);
void WriteProperties(VPuzzleLayout *layout); void WriteProperties(VPuzzleLayout *layout);
void WriteTiles(VPuzzleLayout *layout); void WriteTiles(VPuzzleLayout *layout);
void WriteLayers(VPuzzleLayout *layout); void WritePieceLists(VPuzzleLayout *layout);
void WriteLayer(VPuzzleLayer *layer); void WritePieceList(VPPieceList *pieceList);
void WriteLayer(VPuzzleLayer *layer, const QString &tagName); void WritePieceList(VPPieceList *pieceList, const QString &tagName);
void WritePiece(VPuzzlePiece *piece); void WritePiece(VPuzzlePiece *piece);
void WriteMargins(const QMarginsF &margins); void WriteMargins(const QMarginsF &margins);

View file

@ -31,15 +31,15 @@ namespace ML
{ {
const QString TagLayout = QStringLiteral("layout"); const QString TagLayout = QStringLiteral("layout");
const QString TagProperties = QStringLiteral("properties"); const QString TagProperties = QStringLiteral("properties");
const QString TagLayers = QStringLiteral("layers"); const QString TagPieceLists = QStringLiteral("pieceLists");
const QString TagUnit = QStringLiteral("unit"); const QString TagUnit = QStringLiteral("unit");
const QString TagDescription = QStringLiteral("description"); const QString TagDescription = QStringLiteral("description");
const QString TagSize = QStringLiteral("size"); const QString TagSize = QStringLiteral("size");
const QString TagMargin = QStringLiteral("margin"); const QString TagMargin = QStringLiteral("margin");
const QString TagControl = QStringLiteral("control"); const QString TagControl = QStringLiteral("control");
const QString TagTiles = QStringLiteral("tiles"); const QString TagTiles = QStringLiteral("tiles");
const QString TagUnplacedPiecesLayer = QStringLiteral("unplacedPiecesLayer"); const QString TagUnplacedPieceList = QStringLiteral("unplacedPieceList");
const QString TagLayer = QStringLiteral("layer"); const QString TagPieceList = QStringLiteral("pieceList");
const QString TagPiece = QStringLiteral("piece"); const QString TagPiece = QStringLiteral("piece");
const QString AttrVersion = QStringLiteral("version"); const QString AttrVersion = QStringLiteral("version");

View file

@ -36,15 +36,15 @@ namespace ML
{ {
extern const QString TagLayout; extern const QString TagLayout;
extern const QString TagProperties; extern const QString TagProperties;
extern const QString TagLayers; extern const QString TagPieceLists;
extern const QString TagUnit; extern const QString TagUnit;
extern const QString TagDescription; extern const QString TagDescription;
extern const QString TagSize; extern const QString TagSize;
extern const QString TagMargin; extern const QString TagMargin;
extern const QString TagControl; extern const QString TagControl;
extern const QString TagTiles; extern const QString TagTiles;
extern const QString TagUnplacedPiecesLayer; extern const QString TagUnplacedPieceList;
extern const QString TagLayer; extern const QString TagPieceList;
extern const QString TagPiece; extern const QString TagPiece;
extern const QString AttrVersion; extern const QString AttrVersion;