Drag & Drop

Involved development of the OpenMW construction set.
User avatar
Zini
Posts: 5134
Joined: 06 Aug 2011, 15:16

Re: Drag & Drop

Post by Zini » 13 Feb 2014, 18:34

Using ModifyCommand is correct. That's what it is for.

User avatar
sirherrbatka
Posts: 2121
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka » 13 Feb 2014, 18:55

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).

User avatar
Zini
Posts: 5134
Joined: 06 Aug 2011, 15:16

Re: Drag & Drop

Post by Zini » 13 Feb 2014, 19:02

I think you need to go via a QString. Qt doesn't work well with C++ strings.

User avatar
sirherrbatka
Posts: 2121
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka » 13 Feb 2014, 20:03

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. ;-)

User avatar
Zini
Posts: 5134
Joined: 06 Aug 2011, 15:16

Re: Drag & Drop

Post by Zini » 13 Feb 2014, 20:09

Use mProxyModel instead of mModel.

User avatar
sirherrbatka
Posts: 2121
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka » 13 Feb 2014, 20:19

It works now. Joy. :D

PS
I guess i could expect some inderection layer here.

User avatar
sirherrbatka
Posts: 2121
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka » 14 Feb 2014, 16:14

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?

User avatar
Zini
Posts: 5134
Joined: 06 Aug 2011, 15:16

Re: Drag & Drop

Post by Zini » 14 Feb 2014, 19:52

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.

User avatar
sirherrbatka
Posts: 2121
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka » 14 Feb 2014, 20:12

Right. I will pass the pointer with the constructor of the table.

User avatar
sirherrbatka
Posts: 2121
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka » 15 Feb 2014, 14:04

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest