Drag & Drop

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

Re: Drag & Drop

Post by Zini »

Using ModifyCommand is correct. That's what it is for.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post 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).
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Drag & Drop

Post by Zini »

I think you need to go via a QString. Qt doesn't work well with C++ strings.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post 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. ;-)
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Drag & Drop

Post by Zini »

Use mProxyModel instead of mModel.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka »

It works now. Joy. :D

PS
I guess i could expect some inderection layer here.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post 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?
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Drag & Drop

Post 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.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post by sirherrbatka »

Right. I will pass the pointer with the constructor of the table.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Drag & Drop

Post 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.
Post Reply