Project

General

Profile

Availability bug in WTreeView

Added by Ulf Johnsson about 4 years ago

Hi.

There is a bug in the model-view system were items to a disabled view are not disabled.

In the example below the view is initialy disabled and yet the items are enabled.

If you click the toggle button two times (1 enables the treeview and the second one disables it again) the items will become disabled.

If you then click the update button the items will be regenerated, and they will again be enabled.

It seems like when items are created they do not inherit their views availability.

I'm using Wt3 at the moment.

class Application : public Wt::WApplication
{
public:
    Application(const Wt::WEnvironment &env) : Wt::WApplication(env) {}

    void initialize() override
    {
        Wt::WTreeView *view = new Wt::WTreeView(root());
        m_view = view;
        view->resize(300, 300);
        view->setSelectionBehavior(Wt::SelectRows);
        view->setSelectionMode(Wt::SingleSelection);
        view->setDisabled(true);

        view->setModel(m_model = new Wt::WStandardItemModel());

        auto btn = new Wt::WPushButton("update", root());
        btn->clicked().connect(this, &Application::updateData);

        auto btn2 = new Wt::WPushButton("toggle", root());
        btn2->clicked().connect(this, &Application::toggle);

        updateData();
    }

    void updateData()
    {
        m_model->clear();

        for(int row = 0; row < 3; ++row) {
            for(int column = 0; column < 2; ++column) {
                Wt::WStandardItem *item = new Wt::WStandardItem();
                item->setText("Item " + boost::lexical_cast<std::string>(row)
                    + ", " + boost::lexical_cast<std::string>(column));
                m_model->setItem(row, column, item);
            }
        }
    }

    void toggle()
    {
        m_view->setDisabled(!m_view->isDisabled());
    }

private:
    Wt::WStandardItemModel *m_model;
    Wt::WTreeView *m_view;
};

BR, Ulf