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 "deletepagecommand.h"
0021 #include "controllers/editorcontroller.h"
0022 
0023 DeletePageCommand::DeletePageCommand(EditorController* ctrl, FieldModel* model, QUndoCommand* parent)
0024     : QUndoCommand(parent), m_pageId(ctrl->currentPage()), m_ctrl(ctrl), m_model(model)
0025 {
0026     // m_canvas = m_list[m_currentPage];
0027 
0028     m_model->getFieldFromPage(m_pageId, m_subField);
0029     for(auto item : m_subField)
0030     {
0031         auto field= dynamic_cast<FieldController*>(item);
0032         //      m_subCanvas.append(dynamic_cast<Canvas*>(field->getCanvasField()->scene()));
0033         //    m_subCurrentPage.append(field->getPage());
0034     }
0035     m_deleteField= new DeleteFieldCommand(m_subField, m_subCanvas, m_model, m_subCurrentPage, this);
0036 
0037     setText(QObject::tr("Delete Page #%1").arg(m_pageId + 1));
0038 }
0039 void DeletePageCommand::undo()
0040 {
0041     m_ctrl->insertPage(m_pageId, m_canvas.release());
0042     /*m_list.insert(m_currentPage,m_canvas);
0043     QStringList str = m_pagesModel->stringList();
0044     str.insert(m_currentPage,QObject::tr("Page %1").arg(m_currentPage+1));
0045     m_pagesModel->setStringList(str);*/
0046 
0047     QUndoCommand::undo();
0048 }
0049 
0050 void DeletePageCommand::redo()
0051 {
0052     Q_ASSERT(!m_canvas);
0053     m_canvas.reset(m_ctrl->removePage(m_pageId));
0054     /*m_list.removeOne(m_canvas);
0055     QStringList str = m_pagesModel->stringList();
0056     str.removeAt(m_currentPage);
0057     m_pagesModel->setStringList(str);*/
0058 
0059     QUndoCommand::redo();
0060 }
0061 
0062 /*Canvas* DeletePageCommand::canvas() const
0063 {
0064     return m_canvas;
0065 }
0066 
0067 QStringListModel* DeletePageCommand::getPagesModel()
0068 {
0069     return m_pagesModel;
0070 }
0071 
0072 void DeletePageCommand::setPagesModel(QStringListModel* pagesModel)
0073 {
0074     m_pagesModel = pagesModel;
0075 
0076 }*/