File indexing completed on 2024-06-23 05:33:18
0001 #include "setpropertyonallcharacters.h" 0002 0003 SetPropertyOnCharactersCommand::SetPropertyOnCharactersCommand(QString idProperty, QString value, QString formula, CharacterSheetModel* model,QUndoCommand *parent) 0004 : QUndoCommand(parent),m_model(model), m_value(value),m_formula(formula),m_propertyId(idProperty) 0005 { 0006 for(int i = 0 ; i < m_model->getCharacterSheetCount();++i) 0007 { 0008 auto charact = m_model->getCharacterSheet(i); 0009 if(nullptr != charact) 0010 { 0011 m_oldValues << charact->getValue(m_propertyId,Qt::DisplayRole).toString(); 0012 m_oldFormula << charact->getValue(m_propertyId,Qt::UserRole).toString(); 0013 } 0014 } 0015 setText(QObject::tr("Set property on all characters: %1").arg(idProperty)); 0016 } 0017 0018 void SetPropertyOnCharactersCommand::undo() 0019 { 0020 for(int i = 0 ; i < m_model->getCharacterSheetCount();++i) 0021 { 0022 auto charact = m_model->getCharacterSheet(i); 0023 if(nullptr != charact) 0024 { 0025 charact->setValue(m_propertyId,m_oldValues.at(i),m_oldFormula.at(i)); 0026 } 0027 } 0028 } 0029 0030 void SetPropertyOnCharactersCommand::redo() 0031 { 0032 for(int i = 0 ; i < m_model->getCharacterSheetCount();++i) 0033 { 0034 auto charact = m_model->getCharacterSheet(i); 0035 if(nullptr != charact) 0036 { 0037 charact->setValue(m_propertyId,m_value,m_formula); 0038 } 0039 } 0040 }