mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-03 23:56:43 +00:00 
			
		
		
		
	Add the ability to add nested values to the Create command
This commit is contained in:
		
							parent
							
								
									5602992b86
								
							
						
					
					
						commit
						0420f21462
					
				
					 2 changed files with 29 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -58,6 +58,25 @@ void CSMWorld::CreateCommand::applyModifications()
 | 
			
		|||
{
 | 
			
		||||
    for (std::map<int, QVariant>::const_iterator iter (mValues.begin()); iter!=mValues.end(); ++iter)
 | 
			
		||||
        mModel.setData (mModel.getModelIndex (mId, iter->first), iter->second);
 | 
			
		||||
 | 
			
		||||
    if (!mNestedValues.empty())
 | 
			
		||||
    {
 | 
			
		||||
        CSMWorld::IdTree *tree = dynamic_cast<CSMWorld::IdTree *>(&mModel);
 | 
			
		||||
        if (tree == NULL)
 | 
			
		||||
        {
 | 
			
		||||
            throw std::logic_error("CSMWorld::CreateCommand: Attempt to add nested values to the non-nested model");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        std::map<int, std::pair<int, QVariant> >::const_iterator current = mNestedValues.begin();
 | 
			
		||||
        std::map<int, std::pair<int, QVariant> >::const_iterator end = mNestedValues.end();
 | 
			
		||||
        for (; current != end; ++current)
 | 
			
		||||
        {
 | 
			
		||||
            QModelIndex index = tree->index(0,
 | 
			
		||||
                                            current->second.first,
 | 
			
		||||
                                            tree->getNestedModelIndex(mId, current->first));
 | 
			
		||||
            tree->setData(index, current->second.second);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CSMWorld::CreateCommand::CreateCommand (IdTable& model, const std::string& id, QUndoCommand* parent)
 | 
			
		||||
| 
						 | 
				
			
			@ -71,6 +90,11 @@ void CSMWorld::CreateCommand::addValue (int column, const QVariant& value)
 | 
			
		|||
    mValues[column] = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CSMWorld::CreateCommand::addNestedValue(int parentColumn, int nestedColumn, const QVariant &value)
 | 
			
		||||
{
 | 
			
		||||
    mNestedValues[parentColumn] = std::make_pair(nestedColumn, value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void CSMWorld::CreateCommand::setType (UniversalId::Type type)
 | 
			
		||||
{
 | 
			
		||||
    mType = type;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,6 +48,9 @@ namespace CSMWorld
 | 
			
		|||
    class CreateCommand : public QUndoCommand
 | 
			
		||||
    {
 | 
			
		||||
            std::map<int, QVariant> mValues;
 | 
			
		||||
            std::map<int, std::pair<int, QVariant> > mNestedValues;
 | 
			
		||||
            ///< Parameter order: a parent column, a nested column, a data.
 | 
			
		||||
            ///< A nested row has index of 0.
 | 
			
		||||
 | 
			
		||||
        protected:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -68,6 +71,8 @@ namespace CSMWorld
 | 
			
		|||
 | 
			
		||||
            void addValue (int column, const QVariant& value);
 | 
			
		||||
 | 
			
		||||
            void addNestedValue(int parentColumn, int nestedColumn, const QVariant &value);
 | 
			
		||||
 | 
			
		||||
            virtual void redo();
 | 
			
		||||
 | 
			
		||||
            virtual void undo();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue