@raven-worx
You're correct. I am now inserting a nullptr in the insertRows() function, and then later in setData I use the QList::replace() function to actually put a shape into that index.
The reason it didn't work is that I used the pre-compiled Qt binaries. On the binaries, for some reason (probably that I don't know how to set it up properly), putting a breakpoint on any function that is defined in the source code does not trigger the debugger to stop there at all.
I fixed that by deleting Qt, compiling it from the sources (with some headache), installing Qt Creator again and pointing it to the kit. Now I can put breakpoints into the source code and the debugger will actually stop on them, revealing that the call to setData actually does happen when dropping rows.
After all this I came upon a solution that seems to work, I'd just like an opinion if this is a good way to go about it, it might need some polish.
I figured I didn't want to reimplement the whole drag and drop system just to be able to pass some indexes through it, when I am already displaying the shape's names in the view, so I thought... to determine the index, I can just iterate through my list and find the shape that has the same name as the one that I clicked on. Here's what I do in setData:
bool ShapeListModel::setData(const QModelIndex& index, const QVariant& value, int role) { //This role is used when double-clicking on an item if (index.isValid() && role == Qt::EditRole) { if (value.toString() != shapeList.at(index.row())->getName() && !value.toString().isEmpty()) { shapeList[index.row()]->setName(value.toString()); emit dataChanged(index, index); return true; } } //And this one when drag and dropping else if (role == Qt::DisplayRole) { Shape* shape {nullptr}; for (int i = 0; i < shapeList.size(); i++) { if (i == index.row()) { //do nothing } else { if (shapeList.at(i)->getName() == value.toString()) { shape = shapeList.at(i); if (shape) { shapeList.replace(index.row(), shape); return true; } } } } } return false; }So basically, I do a for loop on my shapeList to find the shape which has the name displayed in the QVariant "value" (the name that I clicked on in the view). Once I found it, I set a pointer to its address. Then I simply replace the contents of the empty row (the one with the nullptr) with the shape that I clicked on. Afterwards the call to removeRows takes care of the shape's original index. This works fine. The only requirement is that each shape has a unique name, which is probably a good idea to do anyways. The only thing I'm not sure about is the "else if (role == Qt::DisplayRole)", but according to the debugger that is the set role when drag and dropping.
What do you think of this implementation?