Here is the code, I think it's better than a description 
	
	- void Script::moveAction(int startLine, int endLine) 
- { 
-     if(startLine < 0 || startLine >= mActions.count() || 
-        endLine < 0 || startLine == endLine) 
- 	return; 
-   
-     if(endLine >= mActions.count()) 
- 	mActions.append(mActions.takeAt(startLine)); 
-     else 
- 	mActions.move(startLine, endLine); 
- } 
        void Script::moveAction(int startLine, int endLine)
{
    if(startLine < 0 || startLine >= mActions.count() ||
       endLine < 0 || startLine == endLine)
	return;
    
    if(endLine >= mActions.count())
	mActions.append(mActions.takeAt(startLine));
    else
	mActions.move(startLine, endLine);
}
To copy to clipboard, switch view to plain text mode 
  
	
	- QList<Action *> mActions; 
        QList<Action *> mActions;
To copy to clipboard, switch view to plain text mode 
  
	
	- bool-  ScriptModel ::dropMimeData(const QMimeData *- data, Qt ::DropAction-  action,  int-  row,  int-  column,  const QModelIndex &- parent )
 
- { 
-     if(action == Qt::IgnoreAction) 
-         return true; 
-   
-     if(column > 3 || parent.isValid()) 
-         return false; 
-   
-     int position; 
-   
-     if(row != -1) 
-         position = row; 
-     else 
-   
- 	QByteArray-  encodedData  =-  data -- >data ("application/act.action")- ; 
 
-   
- 	QList<int> rowIdList; 
- 	while(!stream.atEnd()) 
- 	{ 
- 	    stream >> text; 
- 	    rowIdList << text.toInt(); 
- 	} 
-   
- 	foreach(int rowId, rowIdList) 
- 	{ 
- 	    Action *originalAction = mScript->actionAt(rowId); 
- 	    if(!originalAction) 
- 		continue; 
-   
- 	    if(rowId == position) 
- 		continue; 
-   
- 		continue; 
- 	    mScript->moveAction(rowId, position); 
- 	    endMoveRows(); 
- 	    } 
- 	return true; 
- } 
        bool ScriptModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
    if(action == Qt::IgnoreAction)
        return true;
    
    if(column > 3 || parent.isValid())
        return false;
 
    int position;
 
    if(row != -1)
        position = row;
    else
        position = rowCount(QModelIndex());
	QByteArray encodedData = data->data("application/act.action");
	QDataStream stream(&encodedData, QIODevice::ReadOnly);
	
	QList<int> rowIdList;
	while(!stream.atEnd())
	{
	    QString text;
	    stream >> text;
	    rowIdList << text.toInt();
	}
	foreach(int rowId, rowIdList)
	{
	    Action *originalAction = mScript->actionAt(rowId);
	    if(!originalAction)
		continue;
	    
	    if(rowId == position)
		continue;
	    
	    if(!beginMoveRows(QModelIndex(), rowId, rowId, QModelIndex(), position))
		continue;
	    mScript->moveAction(rowId, position);
	    endMoveRows();
	    }
	return true;
}
To copy to clipboard, switch view to plain text mode 
  
I know this would probably fail when moving multiple items because if the lower item is moved before the row ids will not be valid any more. But this asserts even for the first one so that is probably not the problem.
				
			
Bookmarks