drag and drop inside QStandardItemModel
===

I've implemented basic drag and drop inside a QTableView using a QStandardItemModel.  It works well enough when moving things around at the top level, but seems to break if I try to move something out of a nested level.  

For example, if I have a table with two rows, if I drag the second row onto the first, it will nest that it under the first.  However, if I then drag the nested row above the first row to unnest it, it stays nested under the first row.  Or if I drag the second row down to be at the base level again, it will create a third row, which is a duplicate of the second still nested row.  

    Qt::DropActions TreeModel::supportedDropActions() const
    {
        return Qt::MoveAction | Qt::CopyAction;
    }
    
    bool TreeModel::removeRows(int row, int count, const QModelIndex &parent)
    {
        if (parent.isValid())
            return FALSE;
        beginRemoveRows(parent, row, row+count-1);
        for (int i = 0; i < count; ++i) {
            QList<QStandardItem*> items = this->takeRow(row);
            foreach (QStandardItem* item, items) {
                delete item;
            }
        }
        endRemoveRows();
        return TRUE;
    }

I was wondering if it had to do with my removeRows(), where I'm calling takeRow(), which seems like it's always acting on top-level items.  Do I need to modify this function to handle parented items or should beginRemoveRows() take care of that (since it takes a parent attribute)?  Or is the problem elsewhere?  