Page 4 of 6

Re: Drag & Drop

Posted: 13 Feb 2014, 18:34
by Zini
Using ModifyCommand is correct. That's what it is for.

Re: Drag & Drop

Posted: 13 Feb 2014, 18:55
by sirherrbatka
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

Posted: 13 Feb 2014, 19:02
by Zini
I think you need to go via a QString. Qt doesn't work well with C++ strings.

Re: Drag & Drop

Posted: 13 Feb 2014, 20:03
by sirherrbatka

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());
    }
}
That's excatly my code. But it won't produce visible change, just marks file as changed (i guess simply because undo stack is not empty). I'm kinda lost here, and in the moments like this usually it turns that I had a wrong idea how things work. ;-)

Re: Drag & Drop

Posted: 13 Feb 2014, 20:09
by Zini
Use mProxyModel instead of mModel.

Re: Drag & Drop

Posted: 13 Feb 2014, 20:19
by sirherrbatka
It works now. Joy. :D

PS
I guess i could expect some inderection layer here.

Re: Drag & Drop

Posted: 14 Feb 2014, 16:14
by sirherrbatka
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

Posted: 14 Feb 2014, 19:52
by Zini
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.

Re: Drag & Drop

Posted: 14 Feb 2014, 20:12
by sirherrbatka
Right. I will pass the pointer with the constructor of the table.

Re: Drag & Drop

Posted: 15 Feb 2014, 14:04
by sirherrbatka
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.