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 // do nothing
} }
//---------------------------------------------------------------------------------------------------------------------
void TMainWindow::UpdateGroups()
{
// do nothing
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void TMainWindow::FileNew() void TMainWindow::FileNew()
{ {

View File

@ -65,7 +65,6 @@ public:
public slots: public slots:
virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE; virtual void ShowToolTip(const QString &toolTip) Q_DECL_OVERRIDE;
virtual void UpdateGroups() Q_DECL_OVERRIDE;
protected: protected:
virtual void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; 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())) if(doc->GroupIsEmpty(i.key()))
{ {
QFont font; QFont font = item->font();
font.setStrikeOut(true); font.setStrikeOut(true);
item->setFont(font); item->setFont(font);
} }

View File

@ -444,7 +444,7 @@ protected:
QVector<VToolRecord> getLocalHistory(const QString &draw) const; 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: private:
Q_DISABLE_COPY(VAbstractPattern) Q_DISABLE_COPY(VAbstractPattern)

View File

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

View File

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

View File

@ -1,7 +1,7 @@
/************************************************************************ /************************************************************************
** **
** @file removeitemfromgroup.cpp ** @file removeitemfromgroup.cpp
** @author Roman Telezhynskyi <dismine(at)gmail.com> ** @author Ronan Le Tiec
** @date 1 4, 2018 ** @date 1 4, 2018
** **
** @brief ** @brief
@ -48,59 +48,37 @@ RemoveItemFromGroup::RemoveItemFromGroup(const QDomElement &xml, VAbstractPatter
nodeId = groupId; nodeId = groupId;
} }
//---------------------------------------------------------------------------------------------------------------------
RemoveItemFromGroup::~RemoveItemFromGroup()
{
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void RemoveItemFromGroup::undo() void RemoveItemFromGroup::undo()
{ {
qCDebug(vUndo, "Undo the remove item from group"); qCDebug(vUndo, "Undo the remove item from group");
doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change performUndoRedo(true);
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
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void RemoveItemFromGroup::redo() void RemoveItemFromGroup::redo()
{ {
qCDebug(vUndo, "Redo the add item to group"); 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 doc->ChangeActivPP(nameActivDraw);//Without this user will not see this change
QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup); QDomElement group = doc->elementById(nodeId, VAbstractPattern::TagGroup);
if (group.isElement()) 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()) if (group.removeChild(xml).isNull())
{ {
@ -108,15 +86,16 @@ void RemoveItemFromGroup::redo()
return; 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 unvisibile and it's not in any group after the
// undo, it stays unvisible until the entire drawing is completly rerendered. // undo, it stays unvisible until the entire drawing is completly rerendered.
quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR); quint32 objectId = doc->GetParametrUInt(xml,QString("object"),NULL_ID_STR);
quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR); quint32 toolId = doc->GetParametrUInt(xml,QString("tool"),NULL_ID_STR);
VDataTool* tool = doc->getTool(toolId); VDataTool* tool = doc->getTool(toolId);
tool->GroupVisibility(objectId,true); tool->GroupVisibility(objectId,true);
}
doc->SetModified(true);
emit qApp->getCurrentDocument()->patternChanged(false);
QDomElement groups = doc->CreateGroups(); QDomElement groups = doc->CreateGroups();
if (not groups.isNull()) 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 #ifndef REMOVEITEMFROMGROUP_H
#define REMOVEITEMFROMGROUP_H #define REMOVEITEMFROMGROUP_H
@ -15,11 +43,13 @@ class RemoveItemFromGroup : public VUndoCommand
Q_OBJECT Q_OBJECT
public: public:
RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr); RemoveItemFromGroup(const QDomElement &xml, VAbstractPattern *doc, quint32 groupId, QUndoCommand *parent = nullptr);
virtual ~RemoveItemFromGroup(); virtual ~RemoveItemFromGroup()=default;
virtual void undo() Q_DECL_OVERRIDE; virtual void undo() Q_DECL_OVERRIDE;
virtual void redo() Q_DECL_OVERRIDE; virtual void redo() Q_DECL_OVERRIDE;
signals: signals:
void UpdateGroups(); void UpdateGroups();
protected:
void performUndoRedo(bool isUndo);
private: private:
Q_DISABLE_COPY(RemoveItemFromGroup) Q_DISABLE_COPY(RemoveItemFromGroup)
const QString nameActivDraw; const QString nameActivDraw;

View File

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

View File

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