Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The implementation of item_belongs_to_model has problem. #346

Open
incity opened this issue Aug 20, 2024 · 0 comments
Open

The implementation of item_belongs_to_model has problem. #346

incity opened this issue Aug 20, 2024 · 0 comments

Comments

@incity
Copy link

incity commented Aug 20, 2024

in ViewModelBase.cpp:

struct ViewModelBase::ViewModelBaseImpl {
    ViewModelBase* model{nullptr};
    std::unique_ptr<ViewItem> root;
    ViewModelBaseImpl(ViewModelBase* model) : model(model) {}

    bool item_belongs_to_model(ViewItem* item)
    {
        return model->indexFromItem(item).isValid() || item == model->rootItem();
    }
};

QModelIndex ViewModelBase::indexFromItem(const ViewItem* item) const
{
    return item && item->parent()
               ? createIndex(item->row(), item->column(), const_cast<ViewItem*>(item))
               : QModelIndex();
}

How can we prove that an item(ViewItem) belongs to the current model(ViewModelBase).

if item is from another model, indexFromItem also return valid QModelIndex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant