Coder Social home page Coder Social logo

Comments (2)

ogoffart avatar ogoffart commented on June 16, 2024 1

Indeed, all the reset function were having a problem. #4969 fixes it.

from slint.

mous16 avatar mous16 commented on June 16, 2024

Thanks @ogoffart.

Analogous behavior is triggered by custom filter model.

Here the example code:

// appwindow.slint

import {  ListView, VerticalBox, Switch } from "std-widgets.slint";

export component AppWindow inherits Window {
    in property <[int]> model;
    in-out property only-evens <=> only-evens-switch.checked;
    callback only-evens-changed <=> only-evens-switch.toggled;

    VerticalBox {
        only-evens-switch := Switch {
            text: "Only evens";
        }

        ListView {
            for item in root.model: Text {
                text: item;
            }
        }
    }
}
// main.cpp

#include <memory>
#include <utility>

#include "appwindow.h"
#include "slint.h"

class MyFilterModel: public slint::FilterModel<int>
{
    bool onlyEvens{false};

    [[nodiscard]] auto filter(const int& element) const -> bool { return !onlyEvens || element % 2 == 0; }

  public:
    MyFilterModel(std::shared_ptr<Model<int>> source_model):
      slint::FilterModel<int>{std::move(source_model), [this](const int& element) { return filter(element); }}
    { }

    [[nodiscard]] auto getOnlyEvens() const -> bool { return onlyEvens; }

    void setOnlyEvens(bool value)
    {
        onlyEvens = value;
        // Perform some kind of magic to force filtering re-evaluation
    }
};

auto main([[maybe_unused]] int argc, [[maybe_unused]] char** argv) -> int
{
    auto appWindow{AppWindow::create()};

    const auto model{std::make_shared<slint::VectorModel<int>>(std::vector<int>{1, 2, 3, 4, 5})};
    const auto filterModel{std::make_shared<MyFilterModel>(model)};

    appWindow->set_only_evens(filterModel->getOnlyEvens());
    appWindow->set_model(filterModel);
    appWindow->on_only_evens_changed([appWindow, filterModel]() {
        filterModel->setOnlyEvens(appWindow->get_only_evens());
    });

    appWindow->run();

    return 0;
}

Similar, calling FilterModel::reset() triggers a call loop between FilterModel::reset() and FilterModelInner::reset(), that with my current toolchain ends with an exception in std::vector implementation, after some iterations.

I don't know if a different issue should be filled for FilterModel.

from slint.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.