File indexing completed on 2024-09-08 10:59:26
0001 #include "undoCmd/dupplicatevmapitem.h" 0002 0003 #include "model/vmapitemmodel.h" 0004 #include "utils/logcategories.h" 0005 #include "worker/vectorialmapmessagehelper.h" 0006 #include <QList> 0007 #include <QUuid> 0008 0009 DupplicateVMapItem::DupplicateVMapItem(const QList<vmap::VisualItemController*>& vitem, VectorialMapController* ctrl) 0010 : m_vitem{vitem}, m_ctrl{ctrl} 0011 { 0012 m_itemData= VectorialMapMessageHelper::itemsToHash(vitem); 0013 auto keys= m_itemData.keys(); 0014 for(auto& k : keys) 0015 { 0016 auto p= m_itemData[k]; 0017 auto map= p.toMap().toStdMap(); 0018 auto id= QUuid::createUuid().toString(QUuid::WithoutBraces); 0019 m_ids << id; 0020 map[Core::vmapkeys::KEY_UUID]= id; 0021 qDebug() << map; 0022 m_itemData.insert(k, QVariant::fromValue(map)); 0023 } 0024 } 0025 0026 void DupplicateVMapItem::redo() 0027 { 0028 if(m_ctrl.isNull()) 0029 return; 0030 0031 qDebug() << m_itemData; 0032 VectorialMapMessageHelper::fetchModelFromMap(m_itemData, m_ctrl, false); 0033 } 0034 0035 void DupplicateVMapItem::undo() 0036 { 0037 if(m_ctrl.isNull()) 0038 return; 0039 0040 auto model= m_ctrl->model(); 0041 0042 if(!model) 0043 return; 0044 0045 if(!model->removeItemController(m_ids)) 0046 { 0047 qCWarning(logCategory::map) 0048 << QString("Failed to remove item - %1").arg(QStringList{m_ids.begin(), m_ids.end()}.join(", ")); 0049 } 0050 }