File indexing completed on 2024-09-08 10:59:26
0001 /*************************************************************************** 0002 * Copyright (C) 2017 by Renaud Guezennec * 0003 * https://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 0021 #include "undoCmd/addvmapitem.h" 0022 #include <QDebug> 0023 0024 #include "controller/item_controllers/vmapitemfactory.h" 0025 #include "controller/view_controller/vectorialmapcontroller.h" 0026 #include "model/vmapitemmodel.h" 0027 0028 0029 AddVmapItemCommand::AddVmapItemCommand(vmap::VmapItemModel* model, Core::SelectableTool tool, 0030 VectorialMapController* mapCtrl, const std::map<QString, QVariant>& args, 0031 QUndoCommand* parent) 0032 : QUndoCommand(parent), m_model(model), m_mapCtrl(mapCtrl), m_params(args), m_tool(tool) 0033 { 0034 QHash<Core::SelectableTool, QString> data({{Core::SelectableTool::LINE, QObject::tr("Line")}, 0035 {Core::SelectableTool::FILLEDELLIPSE, QObject::tr("Filled Ellipse")}, 0036 {Core::SelectableTool::EMPTYELLIPSE, QObject::tr("Empty Ellipse")}, 0037 {Core::SelectableTool::EMPTYRECT, QObject::tr("Empty Rectangle")}, 0038 {Core::SelectableTool::FILLRECT, QObject::tr("Filled Rectangle")}, 0039 {Core::SelectableTool::TEXT, QObject::tr("Text")}, 0040 {Core::SelectableTool::TEXTBORDER, QObject::tr("Text with border")}, 0041 {Core::SelectableTool::NonPlayableCharacter, QObject::tr("NPC Token")}, 0042 {Core::SelectableTool::PlayableCharacter, QObject::tr("PC Token")}, 0043 {Core::SelectableTool::IMAGE, QObject::tr("Image")}, 0044 {Core::SelectableTool::PEN, QObject::tr("Pen")}, 0045 {Core::SelectableTool::PATH, QObject::tr("Path")}}); 0046 auto string= data.value(tool); 0047 0048 setText(QObject::tr("add %1 item").arg(string)); 0049 } 0050 0051 void AddVmapItemCommand::undo() 0052 { 0053 if(m_model.isNull()) 0054 return; 0055 m_model->removeItemController({m_uuid}); 0056 } 0057 void AddVmapItemCommand::redo() 0058 { 0059 #ifndef UNIT_TEST 0060 qInfo() << QStringLiteral("Redo command AddVmapItemCommand: %1 ").arg(text()); 0061 #endif 0062 if(m_model.isNull()) 0063 return; 0064 0065 auto item= vmap::VmapItemFactory::createVMapItem(m_mapCtrl, m_tool, m_params); 0066 if(!item) 0067 return; 0068 0069 auto id= item->uuid(); 0070 if(m_model->appendItemController(item)) 0071 m_uuid= id; 0072 }