resolves #826 code refactoring and corrections

--HG--
branch : develop
This commit is contained in:
Ronan Le Tiec 2018-04-06 23:08:09 +02:00
parent 02ce8b2cad
commit f09adc22ab
10 changed files with 102 additions and 115 deletions

View File

@ -348,13 +348,6 @@ void TMainWindow::ShowToolTip(const QString &toolTip)
// do nothing
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::UpdateGroups()
{
// do nothing
}
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::FileNew()
{

View File

@ -65,7 +65,6 @@ public:
public slots:
virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE;
virtual void UpdateGroups() Q_DECL_OVERRIDE;
protected:
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;

View File

@ -177,7 +177,7 @@ void VWidgetGroups::FillTable(const QMap<quint32, QPair<QString, bool> > &groups
if(doc->GroupIsEmpty(i.key()))
{
QFont font;
QFont font = item->font();
font.setStrikeOut(true);
item->setFont(font);
}

View File

@ -444,7 +444,7 @@ protected:
QVector<VToolRecord> getLocalHistory(const QString &draw) const;
bool GroupHasItem(const QDomElement &domElement, quint32 toolId, quint32 objectId);
bool GroupHasItem(const QDomElement &groupDomElement, quint32 toolId, quint32 objectId);
private:
Q_DISABLE_COPY(VAbstractPattern)

View File

@ -1,7 +1,7 @@
/************************************************************************
**
** @file addgroup.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @author Ronan Le Tiec
** @date 31 3, 2018
**
** @brief
@ -47,20 +47,29 @@ AddItemToGroup::AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, qu
nodeId = groupId;
}
//---------------------------------------------------------------------------------------------------------------------
AddItemToGroup::~AddItemToGroup()
{
}
//---------------------------------------------------------------------------------------------------------------------
void AddItemToGroup::undo()
{
qCDebug(vUndo, "Undo the add item to group");
performUndoRedo(true);
}
//---------------------------------------------------------------------------------------------------------------------
void AddItemToGroup::redo()
{
qCDebug(vUndo, "Redo the add item to group");
performUndoRedo(false);
}
//---------------------------------------------------------------------------------------------------------------------
void AddItemToGroup::performUndoRedo(bool isUndo)
{
doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change
QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
if (group.isElement())
{
if(isUndo)
{
if (group.removeChild(xml).isNull())
{
@ -68,52 +77,22 @@ void AddItemToGroup::undo()
return;
}
doc->SetModified(true);
emit qApp->getCurrentDocument()->patternChanged(false);
// set the item visible. Because if the undo is done when unvisibile and it's not in any group after the
// set the item visible. Because if the undo is done when unvisible and it's not in any group after the
// undo, it stays unvisible until the entire drawing is completly rerendered.
quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR);
quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR);
VDataTool* tool = doc->getTool(toolId);
tool->GroupVisibility(objectId,true);
QDomElement groups = doc->CreateGroups();
if (not groups.isNull())
{
doc->ParseGroups(groups);
} else
{
qCDebug(vUndo, "Can't get tag Groups.");
return;
}
emit UpdateGroups();
}
else
else // is redo
{
qCDebug(vUndo, "Can't get group by id = %u.", nodeId);
return;
}
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
}
//---------------------------------------------------------------------------------------------------------------------
void AddItemToGroup::redo()
{
qCDebug(vUndo, "Redo the add item to group");
doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change
QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
if (group.isElement())
{
if (group.appendChild(xml).isNull())
{
qCDebug(vUndo, "Can't add item.");
return;
}
}
doc->SetModified(true);
emit qApp->getCurrentDocument()->patternChanged(false);

View File

@ -1,7 +1,7 @@
/************************************************************************
**
** @file addgroup.h
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @author Ronan Le Tiec
** @date 31 3, 2018
**
** @brief
@ -43,11 +43,13 @@ class AddItemToGroup : public VUndoCommand
Q_OBJECT
public:
AddItemToGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 nodeId, QUndoCommand *parent = nullptr);
virtual ~AddItemToGroup();
virtual ~AddItemToGroup()=default;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
signals:
void UpdateGroups();
protected:
void performUndoRedo(bool isUndo);
private:
Q_DISABLE_COPY(AddItemToGroup)
const QString nameActivDraw;

View File

@ -1,7 +1,7 @@
/************************************************************************
**
** @file removeitemfromgroup.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com>
** @author Ronan Le Tiec
** @date 1 4, 2018
**
** @brief
@ -48,59 +48,37 @@ RemoveItemFromGroup::RemoveItemFromGroup(const QDomElement &xml, VAbstractPatter
nodeId = groupId;
}
//---------------------------------------------------------------------------------------------------------------------
RemoveItemFromGroup::~RemoveItemFromGroup()
{
}
//---------------------------------------------------------------------------------------------------------------------
void RemoveItemFromGroup::undo()
{
qCDebug(vUndo, "Undo the remove item from group");
doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change
QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
if (group.isElement())
{
if (group.appendChild(xml).isNull())
{
qCDebug(vUndo, "Can't add the item.");
return;
}
doc->SetModified(true);
emit qApp->getCurrentDocument()->patternChanged(false);
QDomElement groups = doc->CreateGroups();
if (not groups.isNull())
{
doc->ParseGroups(groups);
} else
{
qCDebug(vUndo, "Can't get tag Groups.");
return;
}
emit UpdateGroups();
}
else
{
qCDebug(vUndo, "Can't get group by id = %u.", nodeId);
return;
}
VMainGraphicsView::NewSceneRect(qApp->getCurrentScene(), qApp->getSceneView());
emit doc->SetCurrentPP(nameActivDraw);//Return current pattern piece after undo
performUndoRedo(true);
}
//---------------------------------------------------------------------------------------------------------------------
void RemoveItemFromGroup::redo()
{
qCDebug(vUndo, "Redo the add item to group");
performUndoRedo(false);
}
//---------------------------------------------------------------------------------------------------------------------
void RemoveItemFromGroup::performUndoRedo(bool isUndo)
{
doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change
QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
if (group.isElement())
{
if(isUndo)
{
if (group.appendChild(xml).isNull())
{
qCDebug(vUndo, "Can't add the item.");
return;
}
}
else // is redo
{
if (group.removeChild(xml).isNull())
{
@ -108,15 +86,16 @@ void RemoveItemFromGroup::redo()
return;
}
doc->SetModified(true);
emit qApp->getCurrentDocument()->patternChanged(false);
// set the item visible. Because if the undo is done when unvisibile and it's not in any group after the
// undo, it stays unvisible until the entire drawing is completly rerendered.
quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR);
quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR);
VDataTool* tool = doc->getTool(toolId);
tool->GroupVisibility(objectId,true);
}
doc->SetModified(true);
emit qApp->getCurrentDocument()->patternChanged(false);
QDomElement groups = doc->CreateGroups();
if (not groups.isNull())

View File

@ -1,3 +1,31 @@
/************************************************************************
**
** @file removeitemfromgroup.h
** @author Ronan Le Tiec
** @date 31 3, 2018
**
** @brief
** @copyright
** This source code is part of the Valentina project, a pattern making
** program, whose allow create and modeling patterns of clothing.
** Copyright (C) 2016 Valentina project
** <https://bitbucket.org/dismine/valentina> All Rights Reserved.
**
** Valentina is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** Valentina is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Valentina. If not, see <http://www.gnu.org/licenses/>.
**
*************************************************************************/
#ifndef REMOVEITEMFROMGROUP_H
#define REMOVEITEMFROMGROUP_H
@ -15,11 +43,13 @@ class RemoveItemFromGroup : public VUndoCommand
Q_OBJECT
public:
RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr);
virtual ~RemoveItemFromGroup();
virtual ~RemoveItemFromGroup()=default;
virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE;
signals:
void UpdateGroups();
protected:
void performUndoRedo(bool isUndo);
private:
Q_DISABLE_COPY(RemoveItemFromGroup)
const QString nameActivDraw;

View File

@ -153,3 +153,8 @@ void VAbstractMainWindow::ExportDataToCSV()
qApp->Settings()->SetCSVWithHeader(dialog.IsWithHeader());
}
}
//---------------------------------------------------------------------------------------------------------------------
void VAbstractMainWindow::UpdateGroups()
{
}

View File

@ -46,7 +46,7 @@ public:
public slots:
virtual void ShowToolTip(const QString &toolTip)=0;
virtual void UpdateGroups()=0;
virtual void UpdateGroups();
protected slots:
void WindowsLocale();