Project

General

Profile

enable/disable a WTreeTable and all of its subnodes ยป TestTreeTable.cpp

Michael Leitman, 04/17/2012 04:56 PM

 
#include "TestTreeTable.h"

#include <Wt/WPushButton>

using namespace Wt;

PanelTreeTable::PanelTreeTable (Wt::WContainerWidget *parent)
:WContainerWidget(parent)
{
this->m_disabled = true;
this->createUI();
}

PanelTreeTable::~PanelTreeTable ()
{
}

void PanelTreeTable::createUI ()
{
m_layout = new WGridLayout();
m_layout->setHorizontalSpacing(0);
m_layout->setVerticalSpacing(0);
m_layout->setContentsMargins(0, 0, 0, 0);

this->m_treeTable = this->createTreeTable();
m_layout->addWidget(this->m_treeTable, 0, 0, AlignLeft | AlignTop);
this->m_treeTable->disable();

this->m_treeView = this->createTreeView();
m_layout->addWidget(this->m_treeView, 0, 1, AlignLeft | AlignTop);
this->m_treeView->disable();

WPushButton *button = new WPushButton("toggle enabled/diabled");
//button->resize(WLength::Auto, 28);
button->clicked().connect(this, &PanelTreeTable::btnClick);
m_layout->addWidget(button, 0, 2);

this->setLayout(m_layout, AlignLeft);
}

WTreeTable * PanelTreeTable::createTreeTable ()
{
WTreeTable *treeTable = new WTreeTable();
treeTable->tree()->setSelectionMode(SingleSelection); // default NoSelection
treeTable->addColumn("", 10); // for edited *
treeTable->addColumn("", 5); // for error and selected img
treeTable->resize(250, WLength::Auto);

Wt::WTreeTableNode *rootNode = new Wt::WTreeTableNode("root");
treeTable->setTreeRoot(rootNode, "TreeTable");
rootNode->setLoadPolicy(WTreeNode::PreLoading);

createTableEntry("single entry", 0, rootNode);

// first visible expandable node
Wt::WTreeTableNode *entry = createTableEntry("expandable entry", 0, rootNode);
createTableEntry("sub entry", 0, entry);

entry = createTableEntry("another entry", 0, rootNode);
createTableEntry("sub1", 0, entry);
createTableEntry("sub2", 0, entry);

createTableEntry("last one", 0, rootNode);

// after populating, expand root and make it invisible
rootNode->expand();
rootNode->setStyleClass("treeGreen");
rootNode->setNodeVisible(false);
//rootNode->setChildrenDecorated(false); // to remove +/-/no-expand icons

return treeTable;
}

WTreeTableNode * PanelTreeTable::createTableEntry (const WString &i_name, WIconPair *i_icon, WTreeTableNode *i_parent)
{
return new Wt::WTreeTableNode(i_name, i_icon, i_parent);
}

WTreeView * PanelTreeTable::createTreeView ()
{
WTreeView *treeView = new WTreeView();
treeView->setSelectionMode(ExtendedSelection);
treeView->resize(250, 150);
treeView->setRowHeight(25);
//treeView->setHeaderHeight(20);

// TreeView Model!
WStandardItemModel *model = new WStandardItemModel(0, 1);
// Headers ...
model->setHeaderData(0, Horizontal, WString::tr("Title"));

std::vector<WStandardItem *> list;
WStandardItem *level1;

model->appendRow(createViewEntry("View entry1"));
list = createViewEntry("View entry2");
level1 = list[0];
model->appendRow(list);

level1->appendRow(createViewEntry("View entry2.1"));
level1->appendRow(createViewEntry("View entry2.2"));
level1->appendRow(createViewEntry("View entry2.3"));

model->appendRow(createViewEntry("View entry3"));

treeView->setModel(model);

return treeView;
}

std::vector<WStandardItem *> PanelTreeTable::createViewEntry (const WString &name)
{
std::vector<WStandardItem *> list;
WStandardItem *result = new WStandardItem(name);
list.push_back(result);
return list;
}

void PanelTreeTable::btnClick ()
{
if (this->m_disabled)
{
this->m_treeTable->enable();
this->m_treeView->enable();
}
else
{
this->m_treeTable->disable();
this->m_treeView->disable();
}
this->m_disabled = !this->m_disabled;
}
    (1-1/1)