File indexing completed on 2024-06-09 05:33:25
0001 /*************************************************************************** 0002 * Copyright (C) 2017 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #include "deletefieldcommand.h" 0021 0022 DeleteFieldCommand::DeleteFieldCommand(FieldController* field, Canvas* canvas, FieldModel* model, int currentPage, 0023 QUndoCommand* parent) 0024 : QUndoCommand(parent), m_model(model) 0025 { 0026 m_fields.append(field); 0027 m_canvas.append(canvas); 0028 m_currentPage.append(currentPage); 0029 0030 init(); 0031 } 0032 DeleteFieldCommand::DeleteFieldCommand(QList<CSItem *> fields, QList<Canvas*> canvas, FieldModel* model, 0033 QList<int> currentPage, QUndoCommand* parent) 0034 : QUndoCommand(parent), m_canvas(canvas), m_model(model), m_currentPage(currentPage) 0035 { 0036 for(auto item : fields) 0037 { 0038 m_fields.append(dynamic_cast<FieldController*>(item)); 0039 } 0040 init(); 0041 } 0042 0043 void DeleteFieldCommand::init() 0044 { 0045 for(auto field : m_fields) 0046 { 0047 /*if(nullptr != field->getCanvasField()) 0048 { 0049 auto parent= field->getParent(); 0050 m_parent.append(field->getParent()); 0051 m_points.append(field->getCanvasField()->pos()); 0052 if(nullptr != parent) 0053 m_posInModel.append(parent->indexOfChild(field)); 0054 }*/ 0055 } 0056 0057 setText(QObject::tr("Delete %n Field(s)", "", m_fields.size())); 0058 } 0059 0060 void DeleteFieldCommand::undo() 0061 { 0062 for(int i= 0; i < m_fields.size(); ++i) 0063 { 0064 /* m_canvas[i]->addItem(m_fields[i]->getCanvasField()); 0065 m_fields[i]->getCanvasField()->setPos(m_points[i]); 0066 m_model->insertField(m_fields[i], m_parent[i], m_posInModel[i]);*/ 0067 } 0068 } 0069 0070 void DeleteFieldCommand::redo() 0071 { 0072 for(int i= 0; i < m_fields.size(); ++i) 0073 { 0074 // m_canvas[i]->removeItem(m_fields[i]->getCanvasField()); 0075 m_model->removeField(m_fields[i]); 0076 } 0077 }