Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wt/WGlobal>
- #include <Wt/WCompositeWidget>
- #include <Wt/WContainerWidget>
- #include <Wt/WVBoxLayout>
- #include <Wt/WTreeView>
- #include <Wt/WPushButton>
- #include <Wt/WStandardItemModel>
- #include <Wt/WStandardItem>
- #include <boost/filesystem.hpp>
- const char* pathToWTDev = "C:\\Wt";
- class __Test_LargeTree : public Wt::WCompositeWidget {
- Wt::WTreeView* tree;
- bool toogle;
- void DoFolder (const boost::filesystem::path& path, Wt::WStandardItem* parent);
- void Toogle ();
- public:
- __Test_LargeTree (Wt::WContainerWidget* parent = nullptr);
- };
- __Test_LargeTree::__Test_LargeTree (Wt::WContainerWidget* parent)
- : WCompositeWidget(parent), tree(nullptr), toogle(false)
- {
- auto impl = new Wt::WContainerWidget;
- setImplementation(impl);
- auto layout = new Wt::WVBoxLayout(impl);
- tree = new Wt::WTreeView;
- layout->addWidget(tree, 1);
- auto model = new Wt::WStandardItemModel(0, 1, tree);
- model->setHeaderData(0, Wt::Horizontal, "name");
- tree->setAlternatingRowColors(true);
- tree->setModel(model);
- auto btnToogle = new Wt::WPushButton("Toogle");;
- layout->addWidget(btnToogle, 0, Wt::AlignCenter);
- btnToogle->clicked().connect(this, &__Test_LargeTree::Toogle);
- DoFolder(boost::filesystem::path(pathToWTDev), model->invisibleRootItem());
- }
- void __Test_LargeTree::DoFolder (const boost::filesystem::path& path, Wt::WStandardItem* parent)
- {
- boost::filesystem::directory_iterator end;
- for (auto it = boost::filesystem::directory_iterator(path); it != end; ++it) {
- if (boost::filesystem::is_directory(it->path())) {
- auto row = new Wt::WStandardItem(it->path().string());
- parent->appendRow(row);
- DoFolder(*it, row);
- }
- else {
- parent->appendRow(new Wt::WStandardItem(it->path().string()));
- }
- }
- }
- static void ExpandNodeRecursive (Wt::WTreeView* tree, const Wt::WModelIndex& index, bool expand)
- {
- int rowCount = tree->model()->rowCount(index);
- // ignore invisible root item
- if (index.isValid() && rowCount > 0) tree->setExpanded(index, expand);
- for (int i = 0; i < rowCount; ++i) {
- ExpandNodeRecursive(tree, tree->model()->index(i, 0, index), expand);
- }
- }
- void __Test_LargeTree::Toogle ()
- {
- toogle = !toogle;
- ExpandNodeRecursive(tree, Wt::WModelIndex(), toogle);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement