Project

General

Profile

Bug #164 ยป 0001-Let-WTableView-clear-its-WTable-member-when-setting.patch

Anonymous, 10/31/2009 02:47 AM

View differences:

src/Wt/WTableView.C
WTableView::WTableView(WContainerWidget *parent)
: WCompositeWidget(parent)
{
{
setImplementation(table_ = new WTable());
itemDelegate_ = new WItemDelegate();
model_ = 0;
}
WTableView::~WTableView()
{ }
{}
WTable* WTableView::table()
{
......
void WTableView::setModel(WAbstractItemModel* model)
{
/* Allow the view to be attached to another model by clearing the internal
* WTable, which was filled by the previous model.
*/
table_->clear();
if (!model)
return;
......
for (int r = 0; r < model_->rowCount(); r++) {
table_->insertRow(r);
}
for (int c = 0; c < model->columnCount(); c++) {
table_->insertColumn(c);
}
......
boost::any header = model->headerData(c);
table_->elementAt(0, c)->addWidget(new WText(asString(header)));
}
table_->setHeaderCount(1);
for (int r = 0; r < model->rowCount(); r++) {
for (int c = 0; c < model->columnCount(); c++) {
WWidget* w = getWidget(r, c);
if (w)
table_->elementAt(r + table_->headerCount(), c)->addWidget(w);
WWidget* w = getWidget(r, c);
if (w) {
table_->elementAt(r + table_->headerCount(), c)->addWidget(w);
}
}
}
......
model_->dataChanged().connect(SLOT(this, WTableView::dataChanged));
model_->headerDataChanged()
.connect(SLOT(this, WTableView::headerDataChanged));
.connect(SLOT(this, WTableView::headerDataChanged));
}
void WTableView::columnsInserted(const WModelIndex& index,
const int firstColumn,
const int lastColumn)
const int firstColumn,
const int lastColumn)
{
for (int i = firstColumn; i <= lastColumn; i++) {
table_->insertColumn(i);
......
}
void WTableView::columnsRemoved(const WModelIndex& index,
const int firstColumn,
const int lastColumn)
const int firstColumn,
const int lastColumn)
{
for (int i = lastColumn; i >= firstColumn; i--) {
table_->deleteColumn(i);
......
}
void WTableView::rowsInserted(const WModelIndex& index,
const int firstRow,
const int lastRow)
const int firstRow,
const int lastRow)
{
for (int i = firstRow; i <= lastRow; i++) {
table_->insertRow(i + table_->headerCount());
}
}
void WTableView::rowsRemoved(const WModelIndex& index,
const int firstRow,
const int lastRow)
const int firstRow,
const int lastRow)
{
for (int i = lastRow; i >= firstRow; i--) {
table_->deleteRow(i - table_->headerCount());
......
}
void WTableView::dataChanged(const WModelIndex& topLeft,
const WModelIndex& bottomRight)
const WModelIndex& bottomRight)
{
for (int i = topLeft.row();
i <= bottomRight.row();
i++) {
i <= bottomRight.row();
i++) {
for (int j = topLeft.column(); j <= bottomRight.column(); j++) {
table_->elementAt(i + table_->headerCount(),j)->clear();
WWidget* w = getWidget(i, j);
if (w)
table_->elementAt(i + table_->headerCount(),j)->addWidget(w);
table_->elementAt(i + table_->headerCount(),j)->clear();
WWidget* w = getWidget(i, j);
if (w)
table_->elementAt(i + table_->headerCount(),j)->addWidget(w);
}
}
}
void WTableView::headerDataChanged(const Orientation& orientation,
const int first,
const int last)
const int first,
const int last)
{
for (int c = first; c <= last; c++) {
boost::any header = model_->headerData(c);
table_->elementAt(0, c)->clear();
if (!header.empty())
table_->elementAt(0, c)->addWidget(new WText(asString(header)));
table_->elementAt(0, c)->addWidget(new WText(asString(header)));
}
}
WTableView::ColumnInfo::ColumnInfo(const WTableView *view,
WApplication *app,
int column)
WApplication *app,
int column)
: itemDelegate_(0)
{
......
}
void WTableView::setItemDelegateForColumn(int column,
WAbstractItemDelegate *delegate)
WAbstractItemDelegate *delegate)
{
columnInfo(column).itemDelegate_ = delegate;
}
......
{
while (column >= (int)columns_.size())
columns_.push_back(ColumnInfo(this, WApplication::instance(),
column));
column));
return columns_[column];
}
......
WAbstractItemDelegate *itemDelegate = itemDelegateForColumn(column);
if (!itemDelegate)
itemDelegate = itemDelegate_;
return itemDelegate->update(0, model_->index(row, column), 0);
}
}
    (1-1/1)