onamatic
7th November 2008, 12:09
I have a QTreeView with a QStandardItemModel implementing a simple "notebook" type of application (ie: a bunch of notes inside a bunch of folders).
Everything is fine except for internally drag/dropping a folder in the treeview when all the notes in the dragged folder get lost.
This is a known bug and is detailed here: Drag and drop in QTreeView with QStandardItemModel and InternalMove loses children (http://trolltech.com/developer/task-tracker/index_html?method=entry&id=227426)
Without this functionality I'm truly stuck, so I'm now subclassing QStandardItemModel
class QNotesStandardItemModel : public QStandardItemModel
and trying to manually sort things out in:
bool QNotesStandardItemModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ){
QStringList list = data->formats();
if (!data->hasFormat("application/x-qabstractitemmodeldatalist")) return false;
QByteArray encodedData = data->data("application/x-qabstractitemmodeldatalist");
And now I'm stuck!
QUESTION 1: encodedData contains a QList<QModelIndex> but how do I get at it? I want a kind of "qobject_cast<QModelIndexList>(encodedData)" type of thing! Just can't see how though.
QUESTION 2: Is there an easy way of working round the "lost children" problem? I really wanted to keep this application as simple as possible and not have to subclass standard classes which generally work fine out of the box.
Everything is fine except for internally drag/dropping a folder in the treeview when all the notes in the dragged folder get lost.
This is a known bug and is detailed here: Drag and drop in QTreeView with QStandardItemModel and InternalMove loses children (http://trolltech.com/developer/task-tracker/index_html?method=entry&id=227426)
Without this functionality I'm truly stuck, so I'm now subclassing QStandardItemModel
class QNotesStandardItemModel : public QStandardItemModel
and trying to manually sort things out in:
bool QNotesStandardItemModel::dropMimeData ( const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent ){
QStringList list = data->formats();
if (!data->hasFormat("application/x-qabstractitemmodeldatalist")) return false;
QByteArray encodedData = data->data("application/x-qabstractitemmodeldatalist");
And now I'm stuck!
QUESTION 1: encodedData contains a QList<QModelIndex> but how do I get at it? I want a kind of "qobject_cast<QModelIndexList>(encodedData)" type of thing! Just can't see how though.
QUESTION 2: Is there an easy way of working round the "lost children" problem? I really wanted to keep this application as simple as possible and not have to subclass standard classes which generally work fine out of the box.