File indexing completed on 2024-09-08 10:59:26
0001 /*************************************************************************** 0002 * Copyright (C) 2017 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * rolisteam 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 "undoCmd/removemediacontrollercommand.h" 0021 0022 #include <QDebug> 0023 0024 #include "controller/contentcontroller.h" 0025 #include "controller/view_controller/mediacontrollerbase.h" 0026 #include "media/mediafactory.h" 0027 #include "model/contentmodel.h" 0028 #include "worker/iohelper.h" 0029 0030 RemoveMediaControllerCommand::RemoveMediaControllerCommand(MediaControllerBase* ctrl, ContentModel* model, 0031 QUndoCommand* parent) 0032 : QUndoCommand(parent), m_ctrl(ctrl), m_model(model) 0033 { 0034 if(m_ctrl) 0035 { 0036 m_uuid= m_ctrl->uuid(); 0037 m_title= m_ctrl->title(); 0038 m_color= m_ctrl->localColor(); 0039 m_contentType= ctrl->contentType(); 0040 setText(QObject::tr("Close %1").arg(m_ctrl->name())); 0041 m_data= IOHelper::saveController(m_ctrl); 0042 m_localIsGM= ctrl->localGM(); 0043 } 0044 } 0045 0046 RemoveMediaControllerCommand::~RemoveMediaControllerCommand()= default; 0047 0048 void RemoveMediaControllerCommand::redo() 0049 { 0050 qInfo() << QStringLiteral("redo command RemoveMediaControllerCommand: %1 ").arg(text()); 0051 if(nullptr == m_ctrl) 0052 return; 0053 0054 m_model->removeMedia(m_ctrl->uuid()); 0055 } 0056 0057 void RemoveMediaControllerCommand::undo() 0058 { 0059 qInfo() << QStringLiteral("undo command RemoveMediaControllerCommand: %1 ").arg(text()); 0060 if(nullptr == m_ctrl) 0061 return; 0062 0063 auto media= Media::MediaFactory::createLocalMedia(m_uuid, m_contentType, {{"serializedData", m_data}}, m_color, 0064 m_localIsGM); 0065 m_model->appendMedia(media); 0066 }