Pieces should disappear from the list when deleted.

--HG--
branch : feature
This commit is contained in:
Roman Telezhynskyi 2017-01-18 12:22:02 +02:00
parent d2ff75dedc
commit ccc8da800f
6 changed files with 38 additions and 4 deletions

View File

@ -544,7 +544,7 @@ void VAbstractPattern::setCursor(const quint32 &value)
* @param id tool id. * @param id tool id.
* @return tool. * @return tool.
*/ */
VDataTool *VAbstractPattern::getTool(const quint32 &id) VDataTool *VAbstractPattern::getTool(quint32 id)
{ {
ToolExists(id); ToolExists(id);
return tools.value(id); return tools.value(id);
@ -556,13 +556,19 @@ VDataTool *VAbstractPattern::getTool(const quint32 &id)
* @param id tool id. * @param id tool id.
* @param tool tool. * @param tool tool.
*/ */
void VAbstractPattern::AddTool(const quint32 &id, VDataTool *tool) void VAbstractPattern::AddTool(quint32 id, VDataTool *tool)
{ {
Q_ASSERT_X(id != 0, Q_FUNC_INFO, "id == 0"); Q_ASSERT_X(id != 0, Q_FUNC_INFO, "id == 0");
SCASSERT(tool != nullptr) SCASSERT(tool != nullptr)
tools.insert(id, tool); tools.insert(id, tool);
} }
//---------------------------------------------------------------------------------------------------------------------
void VAbstractPattern::RemoveTool(quint32 id)
{
tools.remove(id);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
VPiecePath VAbstractPattern::ParsePieceNodes(const QDomElement &domElement) VPiecePath VAbstractPattern::ParsePieceNodes(const QDomElement &domElement)
{ {

View File

@ -92,8 +92,9 @@ public:
virtual void UpdateToolData(const quint32 &id, VContainer *data)=0; virtual void UpdateToolData(const quint32 &id, VContainer *data)=0;
static VDataTool* getTool(const quint32 &id); static VDataTool* getTool(quint32 id);
static void AddTool(const quint32 &id, VDataTool *tool); static void AddTool(quint32 id, VDataTool *tool);
static void RemoveTool(quint32 id);
static VPiecePath ParsePieceNodes(const QDomElement &domElement); static VPiecePath ParsePieceNodes(const QDomElement &domElement);
static QVector<CustomSARecord> ParsePieceCSARecords(const QDomElement &domElement); static QVector<CustomSARecord> ParsePieceCSARecords(const QDomElement &domElement);

View File

@ -519,6 +519,12 @@ void VContainer::RemoveVariable(const QString &name)
d->variables.remove(name); d->variables.remove(name);
} }
//---------------------------------------------------------------------------------------------------------------------
void VContainer::RemovePiece(quint32 id)
{
d->pieces->remove(id);
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
/** /**
* @brief AddObject add object to container * @brief AddObject add object to container

View File

@ -168,6 +168,7 @@ public:
template <typename T> template <typename T>
void AddVariable(const QString& name, T *var); void AddVariable(const QString& name, T *var);
void RemoveVariable(const QString& name); void RemoveVariable(const QString& name);
void RemovePiece(quint32 id);
void UpdateGObject(quint32 id, VGObject* obj); void UpdateGObject(quint32 id, VGObject* obj);
void UpdateDetail(quint32 id, const VDetail &detail); void UpdateDetail(quint32 id, const VDetail &detail);

View File

@ -1140,6 +1140,23 @@ void VToolSeamAllowance::DeleteTool(bool ask)
/* If UnionDetails tool delete detail no need emit FullParsing.*/ /* If UnionDetails tool delete detail no need emit FullParsing.*/
connect(delDet, &DeletePiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing); connect(delDet, &DeletePiece::NeedFullParsing, doc, &VAbstractPattern::NeedFullParsing);
} }
// If UnionDetails tool delete the detail this object will be deleted only after full parse.
// Deleting inside UnionDetails cause crash.
// Because this object should be inactive from no one we disconnect all signals that may cause a crash
// KEEP THIS LIST ACTUALL!!!
disconnect(doc, 0, this, 0);
if (QGraphicsScene *toolScene = scene())
{
disconnect(toolScene, 0, this, 0);
}
disconnect(m_dataLabel, 0, this, 0);
disconnect(m_patternInfo, 0, this, 0);
disconnect(m_grainLine, 0, this, 0);
disconnect(m_sceneDetails, 0, this, 0);
hide();// User shouldn't see this object
qApp->getUndoStack()->push(delDet); qApp->getUndoStack()->push(delDet);
// Throw exception, this will help prevent case when we forget to immediately quit function. // Throw exception, this will help prevent case when we forget to immediately quit function.

View File

@ -1194,6 +1194,9 @@ void CreateUnitedDetail(quint32 id, const VToolUnionDetailsInitData &initData, q
SCASSERT(toolDet != nullptr); SCASSERT(toolDet != nullptr);
bool ask = false; bool ask = false;
toolDet->Remove(ask); toolDet->Remove(ask);
// We do not call full parse, so will need more to do more cleaning than usually
initData.doc->RemoveTool(id);
initData.data->RemovePiece(id);
}; };
if (not initData.retainPieces) if (not initData.retainPieces)