Drag & Drop
Re: Drag & Drop
Using ModifyCommand is correct. That's what it is for.
- sirherrbatka
- Posts: 2159
- Joined: 07 Aug 2011, 17:21
Re: Drag & Drop
Yes, but not sure if I should directly attempt to construct QVariant from id (ala QVariant(record.getId().c_str()) where record is the UniversalId).
Re: Drag & Drop
I think you need to go via a QString. Qt doesn't work well with C++ strings.
- sirherrbatka
- Posts: 2159
- Joined: 07 Aug 2011, 17:21
Re: Drag & Drop
Code: Select all
void CSVWorld::Table::dropEvent(QDropEvent *event)
{
QModelIndex index = indexAt (event->pos());
CSMWorld::ColumnBase::Display display = static_cast<CSMWorld::ColumnBase::Display>
(mModel->headerData(index.column(), Qt::Horizontal, CSMWorld::ColumnBase::Role_Display).toInt());
if (dynamic_cast<const CSMWorld::TableMimeData*>(event->mimeData())->holdsType(display))
{
const CSMWorld::TableMimeData* mime = dynamic_cast<const CSMWorld::TableMimeData*> (event->mimeData());
CSMWorld::UniversalId record (mime->returnMatching (display));
std::auto_ptr<CSMWorld::ModifyCommand> command (new CSMWorld::ModifyCommand
(*mModel, index, QVariant (QString::fromStdString (record.getId()))));
mUndoStack.push (command.release());
}
}
- sirherrbatka
- Posts: 2159
- Joined: 07 Aug 2011, 17:21
Re: Drag & Drop
It works now. Joy.
PS
I guess i could expect some inderection layer here.
PS
I guess i could expect some inderection layer here.
- sirherrbatka
- Posts: 2159
- Joined: 07 Aug 2011, 17:21
Re: Drag & Drop
I need some directions on preventing in between docs drop. Qmimedata is constructed in the table, but table does not have direct access to document or data. Should i fetch pointer somehow or add extra const member variable for the pointer and pass it with the constructor?
Re: Drag & Drop
Can you work with the view? The table is in a subview which sits in a View object, that has a pointer to the document.
- sirherrbatka
- Posts: 2159
- Joined: 07 Aug 2011, 17:21
Re: Drag & Drop
Right. I will pass the pointer with the constructor of the table.
- sirherrbatka
- Posts: 2159
- Joined: 07 Aug 2011, 17:21
Re: Drag & Drop
ok, dragging between documents is prohibited. I also reformatted some code (200 chars long line? c'mon) and I hope that I won't face loathing because of that.
Anyway, now I will work on dragging to the script editor. It seems that i will have to subclass qtextedit to reimplement proper events and read docs. Needless to say it should be ready this evening.
Anyway, now I will work on dragging to the script editor. It seems that i will have to subclass qtextedit to reimplement proper events and read docs. Needless to say it should be ready this evening.