Dialogue Sub-Views

Involved development of the OpenMW construction set.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Dialogue Sub-Views

Post by sirherrbatka »

After experimentating with delegates i think that QDataWidgetMapper will work. In fact i made it work, though only for viewing (editing wouldn't be harder).

But we would want to reuse command delegates (that is, qstyledelegate subclass) and i can't find how to use this delegate with widget mapper. Should i create widgets with the QStyledItemDelegate::createEditor, place it in the layout and than map it?
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Dialogue Sub-Views

Post by Zini »

Sounds like an option.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Dialogue Sub-Views

Post by sirherrbatka »

Ok, if it does not sound insane it may just as well work. :geek:
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Dialogue Sub-Views

Post by sirherrbatka »

Ah, one more thing: i still need to retrive data from the model. At the moment i noticed that…

Code: Select all

void CSVWorld::EnumDelegate::setEditorData (QWidget *editor, const QModelIndex& index) const
{
    if (QComboBox *comboBox = dynamic_cast<QComboBox *> (editor))
    {
        int value = index.data (Qt::EditRole).toInt();

        std::size_t size = mValues.size();

        for (std::size_t i=0; i<size; ++i)
            if (mValues[i].first==value)
            {
                comboBox->setCurrentIndex (i);
                break;
            }
    }
}
But index.data (Qt::EditRole).toInt(); will return empty QVariant if index is for reading, right? Can i mess with those setEditorData to pass alternative roles as argument? Qt::EditRole will be default.
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Dialogue Sub-Views

Post by Zini »

But index.data (Qt::EditRole).toInt(); will return empty QVariant if index is for reading, right?
Why should it?
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Dialogue Sub-Views

Post by sirherrbatka »

because that's what CSMWorld::IdTable::data do?
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Dialogue Sub-Views

Post by Zini »

Nope. It does not. You only get an empty QVariant for the EditRole when the column is not editable. Is there an enum type column that is not editable? I am not aware of any.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Dialogue Sub-Views

Post by sirherrbatka »

So is it only id field that does matter? I'm tempted to simply get id from universalid and insert it into qlabel.

Anyway: this is how it looks with delegates from table (and the widgets from the table):
http://wstaw.org/m/2014/03/07/zrzut88_1.png

ID is empty because we can't retrive data. Also: setModelData is not called so it is not functional right now (trying to work on it).
User avatar
Zini
Posts: 5538
Joined: 06 Aug 2011, 15:16

Re: Dialogue Sub-Views

Post by Zini »

I went through the column classes (should have done that right at the beginning of this discussion) and this is what I found:

For the regular (single record type) tables we only have ID and type (the later is not used in dialogue mode).

For referenceables the situation is a bit more complicated:

First there is a bug. The modification column is flagged as not editable, which is clearly wrong.

But then we also have the record type there, which is answering my own question a few posts above. Apparently we do have a non-editable enum type. Kinda surprised myself.

This is a bit tricky. I don't think it is a good idea to replace the EditRole with the DisplayRole in setEditorData, because in some situations the difference may matter eventually (colour, probably, maybe, just guessing here). However what we could do is to check if data (Qt::EditRole) returns an empty QVariant and if it does try Qt::DisplayRole instead.
User avatar
sirherrbatka
Posts: 2159
Joined: 07 Aug 2011, 17:21

Re: Dialogue Sub-Views

Post by sirherrbatka »

This sounds like the fastest and simplest way.
Post Reply