File indexing completed on 2025-07-06 05:06:04

0001 /***************************************************************************
0002  *  Copyright (C) 2019 by Renaud Guezennec                                 *
0003  *   http://www.rolisteam.org/contact                                      *
0004  *                                                                         *
0005  *   This software 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 "mindmap/command/removenodecommand.h"
0021 #include "mindmap/data/linkcontroller.h"
0022 #include "mindmap/model/minditemmodel.h"
0023 #include <algorithm>
0024 
0025 namespace mindmap
0026 {
0027 
0028 RemoveNodeCommand::RemoveNodeCommand(const QString& idmap, const std::vector<MindItem*>& selection,
0029                                      MindItemModel* nodeModel)
0030     : m_nodeModel(nodeModel), m_idmap(idmap)
0031 {
0032     std::transform(selection.begin(), selection.end(), std::back_inserter(m_selection),
0033                    [](MindItem* node) -> QPointer<MindItem> { return QPointer<MindItem>(node); });
0034 
0035     std::for_each(selection.begin(), selection.end(),
0036                   [this](MindItem* node)
0037                   {
0038                       auto sublinks= m_nodeModel->sublink(node->id());
0039                       qDebug() << sublinks.size() << "sublink size";
0040                       std::copy(sublinks.begin(), sublinks.end(), std::back_inserter(m_links));
0041                       /*std::copy_if(sublinks.begin(), sublinks.end(), std::back_inserter(m_links),
0042                                    []() {
0043 
0044                                    });*/
0045                   });
0046 }
0047 
0048 void RemoveNodeCommand::undo()
0049 {
0050     std::for_each(m_selection.begin(), m_selection.end(), [this](MindItem* node) { m_nodeModel->appendItem({node}); });
0051     std::for_each(m_links.begin(), m_links.end(), [this](LinkController* link) { m_nodeModel->appendItem({link}); });
0052     /*if(m_updater)
0053     {
0054         m_updater->sendOffAddingMessage(m_idmap, nodes, links);
0055     }*/
0056 }
0057 
0058 void RemoveNodeCommand::redo()
0059 {
0060     std::for_each(m_selection.begin(), m_selection.end(), [this](MindItem* node) { m_nodeModel->removeItem(node); });
0061     std::for_each(m_links.begin(), m_links.end(), [this](LinkController* link) { m_nodeModel->removeItem(link); });
0062     /*if(m_updater)
0063     {
0064         m_updater->sendOffRemoveMessage(m_idmap, allBoxToRemove, allLinkToRemove);
0065     }*/
0066 }
0067 } // namespace mindmap